Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Dec 14, 2023
1 parent 276e182 commit 889d5f5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 49 deletions.
2 changes: 1 addition & 1 deletion releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* “SIGIL” can no longer be selected in the episode menu if *SIGIL* isn’t loaded but *SIGIL II* is.
* The Spider Mastermind’s health in *E6M8: Abyss Of Despair* is now correct.
* [Thorr’s](https://music.apple.com/us/artist/thorr/1325613495) music is now louder.
* If known, the author of the current map is now displayed by the `mapstats` CCMD.
* If the current map is from a supported WAD, its author is now displayed by the `mapstats` CCMD.
* A bug is fixed whereby the corpses of monsters could remain solid, blocking the player’s path, in some rare instances.
* Minor improvements have been made to text autocompleted in the console by pressing the <kbd><b>TAB</b></kbd> key.
* Minor improvements have been made to the parsing of `enterpic` in `MAPINFO` lumps.
Expand Down
14 changes: 7 additions & 7 deletions src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,19 +818,19 @@ bool D_IsSIGILWAD(char *filename)
{
const char *file = leafname(filename);

return (M_StringCompare(file, "SIGIL_v1_21.wad")
|| M_StringCompare(file, "SIGIL_v1_2.wad")
|| M_StringCompare(file, "SIGIL_v1_1.wad")
|| M_StringCompare(file, "SIGIL_v1_0.wad")
|| M_StringCompare(file, "SIGIL.wad"));
return ((M_StringStartsWith(file, "SIGIL_V") && M_StringEndsWith(file, ".WAD"))
|| M_StringCompare(file, "SIGIL.WAD"));
}

bool D_IsSIGIL2WAD(char *filename)
{
const char *file = leafname(filename);

return (M_StringStartsWith(file, "SIGIL_II_MP3_V")
|| M_StringStartsWith(file, "SIGIL_II_V"));
return ((M_StringStartsWith(file, "SIGIL_II_MP3_V") && M_StringEndsWith(file, ".WAD"))
|| (M_StringStartsWith(file, "SIGIL_II_V") && M_StringEndsWith(file, ".WAD"))
|| M_StringCompare(file, "SIGIL2.WAD")
|| M_StringCompare(file, "SIGILII.WAD")
|| M_StringCompare(file, "SIGIL_II.WAD"));
}

bool D_IsDOOM2IWAD(char *filename)
Expand Down
48 changes: 23 additions & 25 deletions src/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,22 @@
#include <string.h>
#include <sys/types.h>

#include "doomtype.h"
#include "m_misc.h"
#include "md5.h"

#ifdef WORDS_BIGENDIAN
void byteSwap(UWORD32 *buf, unsigned words)
void byteswap(uint32_t *buf, unsigned int words)
{
md5byte *p = (md5byte *)buf;
byte *p = (byte *)buf;

do
{
*buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 |
((unsigned)p[1] << 8 | p[0]);
*buf++ = (uint32_t)((unsigned int)p[3] << 8 | p[2]) << 16 | ((unsigned int)p[1] << 8 | p[0]);
p += 4;
} while (--words);
}
#else
#define byteSwap(buf, words)
#define byteswap(buf, words)
#endif

// Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
Expand All @@ -73,9 +71,9 @@ void MD5Init(MD5Context *ctx)

// Update context to reflect the concatenation of another buffer full
// of bytes.
void MD5Update(MD5Context *ctx, md5byte const *buf, unsigned len)
void MD5Update(MD5Context *ctx, byte const *buf, unsigned len)
{
UWORD32 t = ctx->bytes[0];
uint32_t t = ctx->bytes[0];

// Update byte count
if ((ctx->bytes[0] = t + len) < t)
Expand All @@ -85,13 +83,13 @@ void MD5Update(MD5Context *ctx, md5byte const *buf, unsigned len)

if (t > len)
{
memcpy((md5byte *)ctx->in + 64 - t, buf, len);
memcpy((byte *)ctx->in + 64 - t, buf, len);
return;
}

// First chunk is an odd size
memcpy((md5byte *)ctx->in + 64 - t, buf, t);
byteSwap(ctx->in, 16);
memcpy((byte *)ctx->in + 64 - t, buf, t);
byteswap(ctx->in, 16);
MD5Transform(ctx->buf, ctx->in);
buf += t;
len -= t;
Expand All @@ -100,7 +98,7 @@ void MD5Update(MD5Context *ctx, md5byte const *buf, unsigned len)
while (len >= 64)
{
memcpy(ctx->in, buf, 64);
byteSwap(ctx->in, 16);
byteswap(ctx->in, 16);
MD5Transform(ctx->buf, ctx->in);
buf += 64;
len -= 64;
Expand All @@ -113,10 +111,10 @@ void MD5Update(MD5Context *ctx, md5byte const *buf, unsigned len)
// Final wrap-up - pad to 64-byte boundary with the bit pattern
// 1 0* (64-bit count of bits processed, MSB-first)

void MD5Final(md5byte digest[16], MD5Context *ctx)
void MD5Final(byte digest[16], MD5Context *ctx)
{
int count = ctx->bytes[0] & 0x3f; // Number of bytes in ctx->in
md5byte *p = (md5byte *)ctx->in + count;
byte *p = (byte *)ctx->in + count;

// Set the first char of padding to 0x80. There is always room.
*p++ = 0x80;
Expand All @@ -128,21 +126,21 @@ void MD5Final(md5byte digest[16], MD5Context *ctx)
{
// Padding forces an extra block
memset(p, 0, count + 8);
byteSwap(ctx->in, 16);
byteswap(ctx->in, 16);
MD5Transform(ctx->buf, ctx->in);
p = (md5byte *)ctx->in;
p = (byte *)ctx->in;
count = 56;
}

memset(p, 0, count);
byteSwap(ctx->in, 14);
byteswap(ctx->in, 14);

// Append length in bits and transform
ctx->in[14] = ctx->bytes[0] << 3;
ctx->in[15] = (ctx->bytes[1] << 3 | ctx->bytes[0] >> 29);
MD5Transform(ctx->buf, ctx->in);

byteSwap(ctx->buf, 4);
byteswap(ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(*ctx)); // In case it's sensitive
}
Expand All @@ -157,17 +155,17 @@ void MD5Final(md5byte digest[16], MD5Context *ctx)
#define F4(x, y, z) (y ^ (x | ~z))

// This is the central step in the MD5 algorithm.
#define MD5STEP(f,w,x,y,z,in,s) (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
#define MD5STEP(f, w, x, y, z, in, s) (w += f(x, y, z) + in, w = (w << s | w >> (32 - s)) + x)

// The core of the MD5 algorithm, this alters an existing MD5 hash to
// reflect the addition of 16 longwords of new data. MD5Update blocks
// the data and converts bytes into longwords for this routine.
void MD5Transform(UWORD32 buf[4], UWORD32 const in[16])
void MD5Transform(uint32_t buf[4], uint32_t const in[16])
{
UWORD32 a = buf[0];
UWORD32 b = buf[1];
UWORD32 c = buf[2];
UWORD32 d = buf[3];
uint32_t a = buf[0];
uint32_t b = buf[1];
uint32_t c = buf[2];
uint32_t d = buf[3];

MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
Expand Down Expand Up @@ -253,7 +251,7 @@ char *MD5(const char *filename)
{
MD5Context md5;
byte buffer[8192];
size_t len;
size_t len;

MD5Init(&md5);

Expand Down
24 changes: 8 additions & 16 deletions src/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,19 @@

#pragma once

#ifdef _MSC_VER
#include <windows.h>
#include <stdint.h>

#define UWORD32 DWORD
#else
#include <inttypes.h>

#define UWORD32 uint32_t
#endif

#define md5byte unsigned char
#include "doomtype.h"

typedef struct
{
UWORD32 buf[4];
UWORD32 bytes[2];
UWORD32 in[16];
uint32_t buf[4];
uint32_t bytes[2];
uint32_t in[16];
} MD5Context;

void MD5Init(MD5Context *context);
void MD5Update(MD5Context *context, md5byte const *buf, unsigned len);
void MD5Final(md5byte digest[16], MD5Context *context);
void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]);
void MD5Update(MD5Context *context, byte const *buf, unsigned len);
void MD5Final(byte digest[16], MD5Context *context);
void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
char *MD5(const char *filename);

0 comments on commit 889d5f5

Please sign in to comment.