summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2012-10-25 20:40:56 +0000
committerSimon Howard2012-10-25 20:40:56 +0000
commit42567795b30ae8e33a90f0fa956204408b419757 (patch)
tree0292112865efc374a42bdaa47b487ce439a4163a
parent933839b0a2a95498c8c935339bb79ade11983dd5 (diff)
downloadchocolate-doom-42567795b30ae8e33a90f0fa956204408b419757.tar.gz
chocolate-doom-42567795b30ae8e33a90f0fa956204408b419757.tar.bz2
chocolate-doom-42567795b30ae8e33a90f0fa956204408b419757.zip
Switch from MD5 to SHA-1 for network digests.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2530
-rw-r--r--src/Makefile.am2
-rw-r--r--src/deh_ammo.c8
-rw-r--r--src/deh_defs.h8
-rw-r--r--src/deh_frame.c6
-rw-r--r--src/deh_main.c12
-rw-r--r--src/deh_main.h4
-rw-r--r--src/deh_mapping.c10
-rw-r--r--src/deh_mapping.h6
-rw-r--r--src/deh_misc.c6
-rw-r--r--src/deh_ptr.c6
-rw-r--r--src/deh_thing.c6
-rw-r--r--src/deh_weapon.c6
-rw-r--r--src/md5.c265
-rw-r--r--src/md5.h45
-rw-r--r--src/net_client.c28
-rw-r--r--src/net_client.h10
-rw-r--r--src/net_gui.c28
-rw-r--r--src/net_server.c26
-rw-r--r--src/net_structrw.c8
-rw-r--r--src/net_structrw.h6
-rw-r--r--src/sha1.c319
-rw-r--r--src/w_checksum.c24
-rw-r--r--src/w_checksum.h2
23 files changed, 425 insertions, 416 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 62cf3544..03942157 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,7 +63,7 @@ m_config.c m_config.h \
m_fixed.c m_fixed.h \
m_menu.c m_menu.h \
m_misc.c m_misc.h \
-md5.c md5.h \
+sha1.c sha1.h \
memio.c memio.h \
m_random.c m_random.h \
p_ceilng.c \
diff --git a/src/deh_ammo.c b/src/deh_ammo.c
index 2c6a9022..952d8df3 100644
--- a/src/deh_ammo.c
+++ b/src/deh_ammo.c
@@ -89,14 +89,14 @@ static void DEH_AmmoParseLine(deh_context_t *context, char *line, void *tag)
}
}
-static void DEH_AmmoMD5Hash(md5_context_t *context)
+static void DEH_AmmoSHA1Hash(sha1_context_t *context)
{
int i;
for (i=0; i<NUMAMMO; ++i)
{
- MD5_UpdateInt32(context, clipammo[i]);
- MD5_UpdateInt32(context, maxammo[i]);
+ SHA1_UpdateInt32(context, clipammo[i]);
+ SHA1_UpdateInt32(context, maxammo[i]);
}
}
@@ -107,6 +107,6 @@ deh_section_t deh_section_ammo =
DEH_AmmoStart,
DEH_AmmoParseLine,
NULL,
- DEH_AmmoMD5Hash,
+ DEH_AmmoSHA1Hash,
};
diff --git a/src/deh_defs.h b/src/deh_defs.h
index e7b76182..2ab65c5d 100644
--- a/src/deh_defs.h
+++ b/src/deh_defs.h
@@ -27,7 +27,7 @@
#ifndef DEH_DEFS_H
#define DEH_DEFS_H
-#include "md5.h"
+#include "sha1.h"
typedef struct deh_context_s deh_context_t;
typedef struct deh_section_s deh_section_t;
@@ -35,7 +35,7 @@ typedef void (*deh_section_init_t)(void);
typedef void *(*deh_section_start_t)(deh_context_t *context, char *line);
typedef void (*deh_section_end_t)(deh_context_t *context, void *tag);
typedef void (*deh_line_parser_t)(deh_context_t *context, char *line, void *tag);
-typedef void (*deh_md5_hash_t)(md5_context_t *context);
+typedef void (*deh_sha1_hash_t)(sha1_context_t *context);
struct deh_section_s
{
@@ -58,9 +58,9 @@ struct deh_section_s
deh_section_end_t end;
- // Called when generating an MD5 sum of the dehacked state
+ // Called when generating an SHA1 sum of the dehacked state
- deh_md5_hash_t md5_hash;
+ deh_sha1_hash_t sha1_hash;
};
#endif /* #ifndef DEH_DEFS_H */
diff --git a/src/deh_frame.c b/src/deh_frame.c
index 398fa014..d504637c 100644
--- a/src/deh_frame.c
+++ b/src/deh_frame.c
@@ -148,13 +148,13 @@ static void DEH_FrameParseLine(deh_context_t *context, char *line, void *tag)
}
}
-static void DEH_FrameMD5Sum(md5_context_t *context)
+static void DEH_FrameSHA1Sum(sha1_context_t *context)
{
int i;
for (i=0; i<NUMSTATES; ++i)
{
- DEH_StructMD5Sum(context, &state_mapping, &states[i]);
+ DEH_StructSHA1Sum(context, &state_mapping, &states[i]);
}
}
@@ -165,6 +165,6 @@ deh_section_t deh_section_frame =
DEH_FrameStart,
DEH_FrameParseLine,
NULL,
- DEH_FrameMD5Sum,
+ DEH_FrameSHA1Sum,
};
diff --git a/src/deh_main.c b/src/deh_main.c
index 20498375..e61933fa 100644
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -89,22 +89,22 @@ static deh_section_t *section_types[] =
&deh_section_weapon,
};
-void DEH_Checksum(md5_digest_t digest)
+void DEH_Checksum(sha1_digest_t digest)
{
- md5_context_t md5_context;
+ sha1_context_t sha1_context;
unsigned int i;
- MD5_Init(&md5_context);
+ SHA1_Init(&sha1_context);
for (i=0; i<arrlen(section_types); ++i)
{
- if (section_types[i]->md5_hash != NULL)
+ if (section_types[i]->sha1_hash != NULL)
{
- section_types[i]->md5_hash(&md5_context);
+ section_types[i]->sha1_hash(&sha1_context);
}
}
- MD5_Final(digest, &md5_context);
+ SHA1_Final(digest, &sha1_context);
}
// Called on startup to call the Init functions
diff --git a/src/deh_main.h b/src/deh_main.h
index 4b58a1ad..ad31af7d 100644
--- a/src/deh_main.h
+++ b/src/deh_main.h
@@ -31,7 +31,7 @@
#include "doomtype.h"
#include "doomfeatures.h"
-#include "md5.h"
+#include "sha1.h"
// These are the limits that dehacked uses (from dheinit.h in the dehacked
// source). If these limits are exceeded, it does not generate an error, but
@@ -47,7 +47,7 @@ int DEH_LoadLumpByName(char *name);
boolean DEH_ParseAssignment(char *line, char **variable_name, char **value);
-void DEH_Checksum(md5_digest_t digest);
+void DEH_Checksum(sha1_digest_t digest);
// deh_text.c:
//
diff --git a/src/deh_mapping.c b/src/deh_mapping.c
index c1466031..d73cda96 100644
--- a/src/deh_mapping.c
+++ b/src/deh_mapping.c
@@ -89,8 +89,8 @@ boolean DEH_SetMapping(deh_context_t *context, deh_mapping_t *mapping,
return false;
}
-void DEH_StructMD5Sum(md5_context_t *context, deh_mapping_t *mapping,
- void *structptr)
+void DEH_StructSHA1Sum(sha1_context_t *context, deh_mapping_t *mapping,
+ void *structptr)
{
int i;
@@ -115,13 +115,13 @@ void DEH_StructMD5Sum(md5_context_t *context, deh_mapping_t *mapping,
switch (entry->size)
{
case 1:
- MD5_UpdateInt32(context, *((uint8_t *) location));
+ SHA1_UpdateInt32(context, *((uint8_t *) location));
break;
case 2:
- MD5_UpdateInt32(context, *((uint16_t *) location));
+ SHA1_UpdateInt32(context, *((uint16_t *) location));
break;
case 4:
- MD5_UpdateInt32(context, *((uint32_t *) location));
+ SHA1_UpdateInt32(context, *((uint32_t *) location));
break;
default:
I_Error("Unknown dehacked mapping field type for '%s' (BUG)",
diff --git a/src/deh_mapping.h b/src/deh_mapping.h
index 4862dec9..31e8aea3 100644
--- a/src/deh_mapping.h
+++ b/src/deh_mapping.h
@@ -31,7 +31,7 @@
#include "doomtype.h"
#include "deh_io.h"
-#include "md5.h"
+#include "sha1.h"
#define DEH_BEGIN_MAPPING(mapping_name, structname) \
static structname deh_mapping_base; \
@@ -83,8 +83,8 @@ struct deh_mapping_s
boolean DEH_SetMapping(deh_context_t *context, deh_mapping_t *mapping,
void *structptr, char *name, int value);
-void DEH_StructMD5Sum(md5_context_t *context, deh_mapping_t *mapping,
- void *structptr);
+void DEH_StructSHA1Sum(sha1_context_t *context, deh_mapping_t *mapping,
+ void *structptr);
#endif /* #ifndef DEH_MAPPING_H */
diff --git a/src/deh_misc.c b/src/deh_misc.c
index c8107858..33faa807 100644
--- a/src/deh_misc.c
+++ b/src/deh_misc.c
@@ -216,13 +216,13 @@ static void DEH_MiscParseLine(deh_context_t *context, char *line, void *tag)
DEH_Warning(context, "Unknown Misc variable '%s'", variable_name);
}
-static void DEH_MiscMD5Sum(md5_context_t *context)
+static void DEH_MiscSHA1Sum(sha1_context_t *context)
{
unsigned int i;
for (i=0; i<arrlen(misc_settings); ++i)
{
- MD5_UpdateInt32(context, *misc_settings[i].value);
+ SHA1_UpdateInt32(context, *misc_settings[i].value);
}
}
@@ -233,6 +233,6 @@ deh_section_t deh_section_misc =
DEH_MiscStart,
DEH_MiscParseLine,
NULL,
- DEH_MiscMD5Sum,
+ DEH_MiscSHA1Sum,
};
diff --git a/src/deh_ptr.c b/src/deh_ptr.c
index 9841e38c..dbec5382 100644
--- a/src/deh_ptr.c
+++ b/src/deh_ptr.c
@@ -129,13 +129,13 @@ static void DEH_PointerParseLine(deh_context_t *context, char *line, void *tag)
}
}
-static void DEH_PointerMD5Sum(md5_context_t *context)
+static void DEH_PointerSHA1Sum(sha1_context_t *context)
{
int i;
for (i=0; i<NUMSTATES; ++i)
{
- MD5_UpdateInt32(context, CodePointerIndex(&states[i].action));
+ SHA1_UpdateInt32(context, CodePointerIndex(&states[i].action));
}
}
@@ -146,6 +146,6 @@ deh_section_t deh_section_pointer =
DEH_PointerStart,
DEH_PointerParseLine,
NULL,
- DEH_PointerMD5Sum,
+ DEH_PointerSHA1Sum,
};
diff --git a/src/deh_thing.c b/src/deh_thing.c
index 4823dc76..87b3c783 100644
--- a/src/deh_thing.c
+++ b/src/deh_thing.c
@@ -118,13 +118,13 @@ static void DEH_ThingParseLine(deh_context_t *context, char *line, void *tag)
DEH_SetMapping(context, &thing_mapping, mobj, variable_name, ivalue);
}
-static void DEH_ThingMD5Sum(md5_context_t *context)
+static void DEH_ThingSHA1Sum(sha1_context_t *context)
{
int i;
for (i=0; i<NUMMOBJTYPES; ++i)
{
- DEH_StructMD5Sum(context, &thing_mapping, &mobjinfo[i]);
+ DEH_StructSHA1Sum(context, &thing_mapping, &mobjinfo[i]);
}
}
@@ -135,6 +135,6 @@ deh_section_t deh_section_thing =
DEH_ThingStart,
DEH_ThingParseLine,
NULL,
- DEH_ThingMD5Sum,
+ DEH_ThingSHA1Sum,
};
diff --git a/src/deh_weapon.c b/src/deh_weapon.c
index cc525ee3..a0d47186 100644
--- a/src/deh_weapon.c
+++ b/src/deh_weapon.c
@@ -88,13 +88,13 @@ static void DEH_WeaponParseLine(deh_context_t *context, char *line, void *tag)
DEH_SetMapping(context, &weapon_mapping, weapon, variable_name, ivalue);
}
-static void DEH_WeaponMD5Sum(md5_context_t *context)
+static void DEH_WeaponSHA1Sum(sha1_context_t *context)
{
int i;
for (i=0; i<NUMWEAPONS ;++i)
{
- DEH_StructMD5Sum(context, &weapon_mapping, &weaponinfo[i]);
+ DEH_StructSHA1Sum(context, &weapon_mapping, &weaponinfo[i]);
}
}
@@ -105,6 +105,6 @@ deh_section_t deh_section_weapon =
DEH_WeaponStart,
DEH_WeaponParseLine,
NULL,
- DEH_WeaponMD5Sum,
+ DEH_WeaponSHA1Sum,
};
diff --git a/src/md5.c b/src/md5.c
deleted file mode 100644
index fb99e2f7..00000000
--- a/src/md5.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * This code implements the MD5 message-digest algorithm.
- * The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
- * This code is in the public domain; do with it what you wish.
- *
- * Equivalent code is available from RSA Data Security, Inc.
- * This code has been tested against that, and is equivalent,
- * except that you don't need to include two pages of legalese
- * with every copy.
- *
- * To compute the message digest of a chunk of bytes, declare an
- * MD5Context structure, pass it to MD5_Init, call MD5_Update as
- * needed on buffers full of bytes, and then call MD5_Final, which
- * will fill a supplied 16-byte array with the digest.
- *
- * Changed so as no longer to depend on Colin Plumb's `usual.h' header
- * definitions; now uses stuff from dpkg's config.h.
- * - Ian Jackson <ian@chiark.greenend.org.uk>.
- * Still in the public domain.
- */
-
-#include "doomdef.h"
-#include "i_swap.h"
-
-#include <string.h> /* for memcpy() */
-#include <sys/types.h> /* for stupid systems */
-
-#include "md5.h"
-
-#ifdef SYS_LITTLE_ENDIAN
-
-// Little endian system - no byte swapping required
-
-#define ByteSwapBlock(x, y)
-
-#else
-
-void ByteSwapBlock(uint32_t *buf, unsigned words)
-{
- byte *p = (byte *)buf;
-
- do {
- *buf++ = (uint32_t)((unsigned)p[3] << 8 | p[2]) << 16 |
- ((unsigned)p[1] << 8 | p[0]);
- p += 4;
- } while (--words);
-}
-
-#endif /* #ifndef SYS_LITTLE_ENDIAN */
-
-/*
- * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
- * initialization constants.
- */
-void
-MD5_Init(md5_context_t *ctx)
-{
- ctx->buf[0] = 0x67452301;
- ctx->buf[1] = 0xefcdab89;
- ctx->buf[2] = 0x98badcfe;
- ctx->buf[3] = 0x10325476;
-
- ctx->bytes[0] = 0;
- ctx->bytes[1] = 0;
-}
-
-/*
- * Update context to reflect the concatenation of another buffer full
- * of bytes.
- */
-void
-MD5_Update(md5_context_t *ctx, byte const *buf, unsigned len)
-{
- uint32_t t;
-
- /* Update byte count */
-
- t = ctx->bytes[0];
- if ((ctx->bytes[0] = t + len) < t)
- ctx->bytes[1]++; /* Carry from low to high */
-
- t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
- if (t > len) {
- memcpy((byte *)ctx->in + 64 - t, buf, len);
- return;
- }
- /* First chunk is an odd size */
- memcpy((byte *)ctx->in + 64 - t, buf, t);
- ByteSwapBlock(ctx->in, 16);
- MD5_Transform(ctx->buf, ctx->in);
- buf += t;
- len -= t;
-
- /* Process data in 64-byte chunks */
- while (len >= 64) {
- memcpy(ctx->in, buf, 64);
- ByteSwapBlock(ctx->in, 16);
- MD5_Transform(ctx->buf, ctx->in);
- buf += 64;
- len -= 64;
- }
-
- /* Handle any remaining bytes of data. */
- memcpy(ctx->in, buf, len);
-}
-
-void MD5_UpdateInt32(md5_context_t *context, unsigned int val)
-{
- byte buf[4];
-
- buf[0] = (val >> 24) & 0xff;
- buf[1] = (val >> 16) & 0xff;
- buf[2] = (val >> 8) & 0xff;
- buf[3] = val & 0xff;
-
- MD5_Update(context, buf, 4);
-}
-
-void MD5_UpdateString(md5_context_t *context, char *str)
-{
- MD5_Update(context, (byte *) str, strlen(str) + 1);
-}
-
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern
- * 1 0* (64-bit count of bits processed, MSB-first)
- */
-void
-MD5_Final(byte digest[16], md5_context_t *ctx)
-{
- int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
- byte *p = (byte *)ctx->in + count;
-
- /* Set the first char of padding to 0x80. There is always room. */
- *p++ = 0x80;
-
- /* Bytes of padding needed to make 56 bytes (-8..55) */
- count = 56 - 1 - count;
-
- if (count < 0) { /* Padding forces an extra block */
- memset(p, 0, count + 8);
- ByteSwapBlock(ctx->in, 16);
- MD5_Transform(ctx->buf, ctx->in);
- p = (byte *)ctx->in;
- count = 56;
- }
- memset(p, 0, count);
- ByteSwapBlock(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;
- MD5_Transform(ctx->buf, ctx->in);
-
- ByteSwapBlock(ctx->buf, 4);
- memcpy(digest, ctx->buf, 16);
- memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
-}
-
-#ifndef ASM_MD5
-
-/* The four core functions - F1 is optimized somewhat */
-
-/* #define F1(x, y, z) (x & y | ~x & z) */
-#define F1(x, y, z) (z ^ (x & (y ^ z)))
-#define F2(x, y, z) F1(z, x, y)
-#define F3(x, y, z) (x ^ y ^ z)
-#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)
-
-/*
- * The core of the MD5 algorithm, this alters an existing MD5 hash to
- * reflect the addition of 16 longwords of new data. MD5_Update blocks
- * the data and converts bytes into longwords for this routine.
- */
-void
-MD5_Transform(uint32_t buf[4], uint32_t const in[16])
-{
- register uint32_t a, b, c, d;
-
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
- MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
- MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
- MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
- MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
- MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
- MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
- MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
- MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
- MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
- MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
- MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
- MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
- MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
- MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
- MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
-
- MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
- MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
- MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
- MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
- MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
- MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
- MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
- MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
- MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
- MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
- MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
- MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
- MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
- MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
- MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
- MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
-
- MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
- MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
- MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
- MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
- MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
- MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
- MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
- MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
- MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
- MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
- MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
- MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
- MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
- MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
- MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
- MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
-
- MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
- MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
- MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
- MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
- MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
- MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
- MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
- MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
- MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
- MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
- MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
- MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
- MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
- MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
- MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
- MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
-}
-
-#endif
-
diff --git a/src/md5.h b/src/md5.h
deleted file mode 100644
index 5df7f686..00000000
--- a/src/md5.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * This is the header file for the MD5 message-digest algorithm.
- * The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
- * This code is in the public domain; do with it what you wish.
- *
- * Equivalent code is available from RSA Data Security, Inc.
- * This code has been tested against that, and is equivalent,
- * except that you don't need to include two pages of legalese
- * with every copy.
- *
- * To compute the message digest of a chunk of bytes, declare an
- * md5_context_s structure, pass it to MD5_Init, call MD5_Update as
- * needed on buffers full of bytes, and then call MD5_Final, which
- * will fill a supplied 16-byte array with the digest.
- *
- * Changed so as no longer to depend on Colin Plumb's `usual.h'
- * header definitions; now uses stuff from dpkg's config.h
- * - Ian Jackson <ian@chiark.greenend.org.uk>.
- * Still in the public domain.
- */
-
-#ifndef MD5_H
-#define MD5_H
-
-#include "doomtype.h"
-
-typedef struct md5_context_s md5_context_t;
-typedef byte md5_digest_t[16];
-
-struct md5_context_s {
- uint32_t buf[4];
- uint32_t bytes[2];
- uint32_t in[16];
-};
-
-void MD5_Init(md5_context_t *context);
-void MD5_Update(md5_context_t *context, byte const *buf, unsigned len);
-void MD5_UpdateInt32(md5_context_t *context, unsigned int val);
-void MD5_UpdateString(md5_context_t *context, char *str);
-void MD5_Final(unsigned char digest[16], md5_context_t *context);
-void MD5_Transform(uint32_t buf[4], uint32_t const in[16]);
-
-#endif /* !MD5_H */
-
diff --git a/src/net_client.c b/src/net_client.c
index b3109ecd..24fb7f6c 100644
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -128,11 +128,11 @@ unsigned int net_drones_in_game;
char net_player_addresses[MAXPLAYERS][MAXPLAYERNAME];
char net_player_names[MAXPLAYERS][MAXPLAYERNAME];
-// MD5 checksums of the wad directory and dehacked data that the server
+// SHA1 checksums of the wad directory and dehacked data that the server
// has sent to us.
-md5_digest_t net_server_wad_md5sum;
-md5_digest_t net_server_deh_md5sum;
+sha1_digest_t net_server_wad_sha1sum;
+sha1_digest_t net_server_deh_sha1sum;
// Is the server a freedoom game?
@@ -172,8 +172,8 @@ static unsigned int gamedata_recv_time;
// Hash checksums of our wad directory and dehacked data.
-md5_digest_t net_local_wad_md5sum;
-md5_digest_t net_local_deh_md5sum;
+sha1_digest_t net_local_wad_sha1sum;
+sha1_digest_t net_local_deh_sha1sum;
// Are we playing with the freedoom IWAD?
@@ -558,7 +558,7 @@ static void NET_CL_ParseWaitingData(net_packet_t *packet)
signed int player_number;
char *player_names[MAXPLAYERS];
char *player_addr[MAXPLAYERS];
- md5_digest_t wad_md5sum, deh_md5sum;
+ sha1_digest_t wad_sha1sum, deh_sha1sum;
unsigned int server_is_freedoom;
size_t i;
@@ -601,8 +601,8 @@ static void NET_CL_ParseWaitingData(net_packet_t *packet)
}
}
- if (!NET_ReadMD5Sum(packet, wad_md5sum)
- || !NET_ReadMD5Sum(packet, deh_md5sum)
+ if (!NET_ReadSHA1Sum(packet, wad_sha1sum)
+ || !NET_ReadSHA1Sum(packet, deh_sha1sum)
|| !NET_ReadInt8(packet, &server_is_freedoom))
{
return;
@@ -621,8 +621,8 @@ static void NET_CL_ParseWaitingData(net_packet_t *packet)
net_player_addresses[i][MAXPLAYERNAME-1] = '\0';
}
- memcpy(net_server_wad_md5sum, wad_md5sum, sizeof(md5_digest_t));
- memcpy(net_server_deh_md5sum, deh_md5sum, sizeof(md5_digest_t));
+ memcpy(net_server_wad_sha1sum, wad_sha1sum, sizeof(sha1_digest_t));
+ memcpy(net_server_deh_sha1sum, deh_sha1sum, sizeof(sha1_digest_t));
net_server_is_freedoom = server_is_freedoom;
net_client_received_wait_data = true;
@@ -1116,8 +1116,8 @@ static void NET_CL_SendSYN(void)
NET_WriteInt16(packet, gamemission);
NET_WriteInt8(packet, lowres_turn);
NET_WriteInt8(packet, drone);
- NET_WriteMD5Sum(packet, net_local_wad_md5sum);
- NET_WriteMD5Sum(packet, net_local_deh_md5sum);
+ NET_WriteSHA1Sum(packet, net_local_wad_sha1sum);
+ NET_WriteSHA1Sum(packet, net_local_deh_sha1sum);
NET_WriteInt8(packet, net_local_is_freedoom);
NET_WriteString(packet, net_player_name);
NET_Conn_SendPacket(&client_connection, packet);
@@ -1142,8 +1142,8 @@ boolean NET_CL_Connect(net_addr_t *addr)
// Read checksums of our WAD directory and dehacked information
- W_Checksum(net_local_wad_md5sum);
- DEH_Checksum(net_local_deh_md5sum);
+ W_Checksum(net_local_wad_sha1sum);
+ DEH_Checksum(net_local_deh_sha1sum);
// Are we playing with the Freedoom IWAD?
diff --git a/src/net_client.h b/src/net_client.h
index 7c124e3f..a752b747 100644
--- a/src/net_client.h
+++ b/src/net_client.h
@@ -27,7 +27,7 @@
#include "doomdef.h"
#include "doomtype.h"
#include "d_ticcmd.h"
-#include "md5.h"
+#include "sha1.h"
#include "net_defs.h"
#define MAXPLAYERNAME 30
@@ -51,11 +51,11 @@ extern char net_player_addresses[MAXPLAYERS][MAXPLAYERNAME];
extern int net_player_number;
extern char *net_player_name;
-extern md5_digest_t net_server_wad_md5sum;
-extern md5_digest_t net_server_deh_md5sum;
+extern sha1_digest_t net_server_wad_sha1sum;
+extern sha1_digest_t net_server_deh_sha1sum;
extern unsigned int net_server_is_freedoom;
-extern md5_digest_t net_local_wad_md5sum;
-extern md5_digest_t net_local_deh_md5sum;
+extern sha1_digest_t net_local_wad_sha1sum;
+extern sha1_digest_t net_local_deh_sha1sum;
extern unsigned int net_local_is_freedoom;
diff --git a/src/net_gui.c b/src/net_gui.c
index 600b6ee8..0ff9e55b 100644
--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -153,13 +153,13 @@ static void UpdateGUI(void)
TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, startgame);
}
-static void PrintMD5Digest(char *s, byte *digest)
+static void PrintSHA1Digest(char *s, byte *digest)
{
unsigned int i;
printf("%s: ", s);
- for (i=0; i<sizeof(md5_digest_t); ++i)
+ for (i=0; i<sizeof(sha1_digest_t); ++i)
{
printf("%02x", digest[i]);
}
@@ -167,7 +167,7 @@ static void PrintMD5Digest(char *s, byte *digest)
printf("\n");
}
-static void CheckMD5Sums(void)
+static void CheckSHA1Sums(void)
{
boolean correct_wad, correct_deh;
boolean same_freedoom;
@@ -178,10 +178,10 @@ static void CheckMD5Sums(void)
return;
}
- correct_wad = memcmp(net_local_wad_md5sum, net_server_wad_md5sum,
- sizeof(md5_digest_t)) == 0;
- correct_deh = memcmp(net_local_deh_md5sum, net_server_deh_md5sum,
- sizeof(md5_digest_t)) == 0;
+ correct_wad = memcmp(net_local_wad_sha1sum, net_server_wad_sha1sum,
+ sizeof(sha1_digest_t)) == 0;
+ correct_deh = memcmp(net_local_deh_sha1sum, net_server_deh_sha1sum,
+ sizeof(sha1_digest_t)) == 0;
same_freedoom = net_server_is_freedoom == net_local_is_freedoom;
if (correct_wad && correct_deh && same_freedoom)
@@ -191,9 +191,9 @@ static void CheckMD5Sums(void)
if (!correct_wad)
{
- printf("Warning: WAD MD5 does not match server:\n");
- PrintMD5Digest("Local", net_local_wad_md5sum);
- PrintMD5Digest("Server", net_server_wad_md5sum);
+ printf("Warning: WAD SHA1 does not match server:\n");
+ PrintSHA1Digest("Local", net_local_wad_sha1sum);
+ PrintSHA1Digest("Server", net_server_wad_sha1sum);
}
if (!same_freedoom)
@@ -206,9 +206,9 @@ static void CheckMD5Sums(void)
if (!correct_deh)
{
- printf("Warning: Dehacked MD5 does not match server:\n");
- PrintMD5Digest("Local", net_local_deh_md5sum);
- PrintMD5Digest("Server", net_server_deh_md5sum);
+ printf("Warning: Dehacked SHA1 does not match server:\n");
+ PrintSHA1Digest("Local", net_local_deh_sha1sum);
+ PrintSHA1Digest("Server", net_server_deh_sha1sum);
}
window = TXT_NewWindow("WARNING");
@@ -274,7 +274,7 @@ void NET_WaitForStart(void)
while (net_waiting_for_start)
{
UpdateGUI();
- CheckMD5Sums();
+ CheckSHA1Sums();
TXT_DispatchEvents();
TXT_DrawDesktop();
diff --git a/src/net_server.c b/src/net_server.c
index 77be7a26..189e824f 100644
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -100,10 +100,10 @@ typedef struct
boolean drone;
- // MD5 hash sums of the client's WAD directory and dehacked data
+ // SHA1 hash sums of the client's WAD directory and dehacked data
- md5_digest_t wad_md5sum;
- md5_digest_t deh_md5sum;
+ sha1_digest_t wad_sha1sum;
+ sha1_digest_t deh_sha1sum;
// Is this client is playing with the Freedoom IWAD?
@@ -481,7 +481,7 @@ static void NET_SV_ParseSYN(net_packet_t *packet,
unsigned int cl_recording_lowres;
unsigned int cl_drone;
unsigned int is_freedoom;
- md5_digest_t deh_md5sum, wad_md5sum;
+ sha1_digest_t deh_sha1sum, wad_sha1sum;
char *player_name;
char *client_version;
int i;
@@ -535,8 +535,8 @@ static void NET_SV_ParseSYN(net_packet_t *packet,
|| !NET_ReadInt16(packet, &cl_gamemission)
|| !NET_ReadInt8(packet, &cl_recording_lowres)
|| !NET_ReadInt8(packet, &cl_drone)
- || !NET_ReadMD5Sum(packet, wad_md5sum)
- || !NET_ReadMD5Sum(packet, deh_md5sum)
+ || !NET_ReadSHA1Sum(packet, wad_sha1sum)
+ || !NET_ReadSHA1Sum(packet, deh_sha1sum)
|| !NET_ReadInt8(packet, &is_freedoom))
{
return;
@@ -628,10 +628,10 @@ static void NET_SV_ParseSYN(net_packet_t *packet,
sv_gamemission = cl_gamemission;
}
- // Save the MD5 checksums
+ // Save the SHA1 checksums
- memcpy(client->wad_md5sum, wad_md5sum, sizeof(md5_digest_t));
- memcpy(client->deh_md5sum, deh_md5sum, sizeof(md5_digest_t));
+ memcpy(client->wad_sha1sum, wad_sha1sum, sizeof(sha1_digest_t));
+ memcpy(client->deh_sha1sum, deh_sha1sum, sizeof(sha1_digest_t));
client->is_freedoom = is_freedoom;
// Check the connecting client is playing the same game as all
@@ -1280,14 +1280,14 @@ static void NET_SV_SendWaitingData(net_client_t *client)
if (controller != NULL)
{
- NET_WriteMD5Sum(packet, controller->wad_md5sum);
- NET_WriteMD5Sum(packet, controller->deh_md5sum);
+ NET_WriteSHA1Sum(packet, controller->wad_sha1sum);
+ NET_WriteSHA1Sum(packet, controller->deh_sha1sum);
NET_WriteInt8(packet, controller->is_freedoom);
}
else
{
- NET_WriteMD5Sum(packet, client->wad_md5sum);
- NET_WriteMD5Sum(packet, client->deh_md5sum);
+ NET_WriteSHA1Sum(packet, client->wad_sha1sum);
+ NET_WriteSHA1Sum(packet, client->deh_sha1sum);
NET_WriteInt8(packet, client->is_freedoom);
}
diff --git a/src/net_structrw.c b/src/net_structrw.c
index c2e878fa..bba08212 100644
--- a/src/net_structrw.c
+++ b/src/net_structrw.c
@@ -321,12 +321,12 @@ void NET_WriteFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean l
}
}
-boolean NET_ReadMD5Sum(net_packet_t *packet, md5_digest_t digest)
+boolean NET_ReadSHA1Sum(net_packet_t *packet, sha1_digest_t digest)
{
unsigned int b;
int i;
- for (i=0; i<16; ++i)
+ for (i=0; i<sizeof(sha1_digest_t); ++i)
{
if (!NET_ReadInt8(packet, &b))
{
@@ -339,11 +339,11 @@ boolean NET_ReadMD5Sum(net_packet_t *packet, md5_digest_t digest)
return true;
}
-void NET_WriteMD5Sum(net_packet_t *packet, md5_digest_t digest)
+void NET_WriteSHA1Sum(net_packet_t *packet, sha1_digest_t digest)
{
int i;
- for (i=0; i<16; ++i)
+ for (i=0; i<sizeof(sha1_digest_t); ++i)
{
NET_WriteInt8(packet, digest[i]);
}
diff --git a/src/net_structrw.h b/src/net_structrw.h
index 13209778..4331074b 100644
--- a/src/net_structrw.h
+++ b/src/net_structrw.h
@@ -22,7 +22,7 @@
#ifndef NET_STRUCTRW_H
#define NET_STRUCTRW_H
-#include "md5.h"
+#include "sha1.h"
#include "net_defs.h"
#include "net_packet.h"
@@ -40,8 +40,8 @@ extern void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest);
boolean NET_ReadFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean lowres_turn);
void NET_WriteFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean lowres_turn);
-boolean NET_ReadMD5Sum(net_packet_t *packet, md5_digest_t digest);
-void NET_WriteMD5Sum(net_packet_t *packet, md5_digest_t digest);
+boolean NET_ReadSHA1Sum(net_packet_t *packet, sha1_digest_t digest);
+void NET_WriteSHA1Sum(net_packet_t *packet, sha1_digest_t digest);
#endif /* #ifndef NET_STRUCTRW_H */
diff --git a/src/sha1.c b/src/sha1.c
new file mode 100644
index 00000000..06ab40ad
--- /dev/null
+++ b/src/sha1.c
@@ -0,0 +1,319 @@
+/* sha1.c - SHA1 hash function
+ * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ *
+ * Please see below for more legal information!
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+/* Test vectors:
+ *
+ * "abc"
+ * A999 3E36 4706 816A BA3E 2571 7850 C26C 9CD0 D89D
+ *
+ * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ * 8498 3E44 1C3B D26E BAAE 4AA1 F951 29E5 E546 70F1
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "i_swap.h"
+#include "sha1.h"
+
+void SHA1_Init(sha1_context_t *hd)
+{
+ hd->h0 = 0x67452301;
+ hd->h1 = 0xefcdab89;
+ hd->h2 = 0x98badcfe;
+ hd->h3 = 0x10325476;
+ hd->h4 = 0xc3d2e1f0;
+ hd->nblocks = 0;
+ hd->count = 0;
+}
+
+
+/****************
+ * Transform the message X which consists of 16 32-bit-words
+ */
+static void Transform(sha1_context_t *hd, byte *data)
+{
+ uint32_t a,b,c,d,e,tm;
+ uint32_t x[16];
+
+ /* get values from the chaining vars */
+ a = hd->h0;
+ b = hd->h1;
+ c = hd->h2;
+ d = hd->h3;
+ e = hd->h4;
+
+#ifdef SYS_BIG_ENDIAN
+ memcpy(x, data, 64);
+#else
+ {
+ int i;
+ byte *p2;
+ for(i=0, p2=(byte*)x; i < 16; i++, p2 += 4 )
+ {
+ p2[3] = *data++;
+ p2[2] = *data++;
+ p2[1] = *data++;
+ p2[0] = *data++;
+ }
+ }
+#endif
+
+
+#define K1 0x5A827999L
+#define K2 0x6ED9EBA1L
+#define K3 0x8F1BBCDCL
+#define K4 0xCA62C1D6L
+#define F1(x,y,z) ( z ^ ( x & ( y ^ z ) ) )
+#define F2(x,y,z) ( x ^ y ^ z )
+#define F3(x,y,z) ( ( x & y ) | ( z & ( x | y ) ) )
+#define F4(x,y,z) ( x ^ y ^ z )
+
+#define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) )
+
+#define M(i) ( tm = x[i&0x0f] ^ x[(i-14)&0x0f] \
+ ^ x[(i-8)&0x0f] ^ x[(i-3)&0x0f] \
+ , (x[i&0x0f] = rol(tm,1)) )
+
+#define R(a,b,c,d,e,f,k,m) do { e += rol( a, 5 ) \
+ + f( b, c, d ) \
+ + k \
+ + m; \
+ b = rol( b, 30 ); \
+ } while(0)
+ R( a, b, c, d, e, F1, K1, x[ 0] );
+ R( e, a, b, c, d, F1, K1, x[ 1] );
+ R( d, e, a, b, c, F1, K1, x[ 2] );
+ R( c, d, e, a, b, F1, K1, x[ 3] );
+ R( b, c, d, e, a, F1, K1, x[ 4] );
+ R( a, b, c, d, e, F1, K1, x[ 5] );
+ R( e, a, b, c, d, F1, K1, x[ 6] );
+ R( d, e, a, b, c, F1, K1, x[ 7] );
+ R( c, d, e, a, b, F1, K1, x[ 8] );
+ R( b, c, d, e, a, F1, K1, x[ 9] );
+ R( a, b, c, d, e, F1, K1, x[10] );
+ R( e, a, b, c, d, F1, K1, x[11] );
+ R( d, e, a, b, c, F1, K1, x[12] );
+ R( c, d, e, a, b, F1, K1, x[13] );
+ R( b, c, d, e, a, F1, K1, x[14] );
+ R( a, b, c, d, e, F1, K1, x[15] );
+ R( e, a, b, c, d, F1, K1, M(16) );
+ R( d, e, a, b, c, F1, K1, M(17) );
+ R( c, d, e, a, b, F1, K1, M(18) );
+ R( b, c, d, e, a, F1, K1, M(19) );
+ R( a, b, c, d, e, F2, K2, M(20) );
+ R( e, a, b, c, d, F2, K2, M(21) );
+ R( d, e, a, b, c, F2, K2, M(22) );
+ R( c, d, e, a, b, F2, K2, M(23) );
+ R( b, c, d, e, a, F2, K2, M(24) );
+ R( a, b, c, d, e, F2, K2, M(25) );
+ R( e, a, b, c, d, F2, K2, M(26) );
+ R( d, e, a, b, c, F2, K2, M(27) );
+ R( c, d, e, a, b, F2, K2, M(28) );
+ R( b, c, d, e, a, F2, K2, M(29) );
+ R( a, b, c, d, e, F2, K2, M(30) );
+ R( e, a, b, c, d, F2, K2, M(31) );
+ R( d, e, a, b, c, F2, K2, M(32) );
+ R( c, d, e, a, b, F2, K2, M(33) );
+ R( b, c, d, e, a, F2, K2, M(34) );
+ R( a, b, c, d, e, F2, K2, M(35) );
+ R( e, a, b, c, d, F2, K2, M(36) );
+ R( d, e, a, b, c, F2, K2, M(37) );
+ R( c, d, e, a, b, F2, K2, M(38) );
+ R( b, c, d, e, a, F2, K2, M(39) );
+ R( a, b, c, d, e, F3, K3, M(40) );
+ R( e, a, b, c, d, F3, K3, M(41) );
+ R( d, e, a, b, c, F3, K3, M(42) );
+ R( c, d, e, a, b, F3, K3, M(43) );
+ R( b, c, d, e, a, F3, K3, M(44) );
+ R( a, b, c, d, e, F3, K3, M(45) );
+ R( e, a, b, c, d, F3, K3, M(46) );
+ R( d, e, a, b, c, F3, K3, M(47) );
+ R( c, d, e, a, b, F3, K3, M(48) );
+ R( b, c, d, e, a, F3, K3, M(49) );
+ R( a, b, c, d, e, F3, K3, M(50) );
+ R( e, a, b, c, d, F3, K3, M(51) );
+ R( d, e, a, b, c, F3, K3, M(52) );
+ R( c, d, e, a, b, F3, K3, M(53) );
+ R( b, c, d, e, a, F3, K3, M(54) );
+ R( a, b, c, d, e, F3, K3, M(55) );
+ R( e, a, b, c, d, F3, K3, M(56) );
+ R( d, e, a, b, c, F3, K3, M(57) );
+ R( c, d, e, a, b, F3, K3, M(58) );
+ R( b, c, d, e, a, F3, K3, M(59) );
+ R( a, b, c, d, e, F4, K4, M(60) );
+ R( e, a, b, c, d, F4, K4, M(61) );
+ R( d, e, a, b, c, F4, K4, M(62) );
+ R( c, d, e, a, b, F4, K4, M(63) );
+ R( b, c, d, e, a, F4, K4, M(64) );
+ R( a, b, c, d, e, F4, K4, M(65) );
+ R( e, a, b, c, d, F4, K4, M(66) );
+ R( d, e, a, b, c, F4, K4, M(67) );
+ R( c, d, e, a, b, F4, K4, M(68) );
+ R( b, c, d, e, a, F4, K4, M(69) );
+ R( a, b, c, d, e, F4, K4, M(70) );
+ R( e, a, b, c, d, F4, K4, M(71) );
+ R( d, e, a, b, c, F4, K4, M(72) );
+ R( c, d, e, a, b, F4, K4, M(73) );
+ R( b, c, d, e, a, F4, K4, M(74) );
+ R( a, b, c, d, e, F4, K4, M(75) );
+ R( e, a, b, c, d, F4, K4, M(76) );
+ R( d, e, a, b, c, F4, K4, M(77) );
+ R( c, d, e, a, b, F4, K4, M(78) );
+ R( b, c, d, e, a, F4, K4, M(79) );
+
+ /* update chainig vars */
+ hd->h0 += a;
+ hd->h1 += b;
+ hd->h2 += c;
+ hd->h3 += d;
+ hd->h4 += e;
+}
+
+
+/* Update the message digest with the contents
+ * of INBUF with length INLEN.
+ */
+void SHA1_Update(sha1_context_t *hd, byte *inbuf, size_t inlen)
+{
+ if (hd->count == 64)
+ {
+ /* flush the buffer */
+ Transform(hd, hd->buf);
+ hd->count = 0;
+ hd->nblocks++;
+ }
+ if (!inbuf)
+ return;
+ if (hd->count)
+ {
+ for (; inlen && hd->count < 64; inlen--)
+ hd->buf[hd->count++] = *inbuf++;
+ SHA1_Update(hd, NULL, 0);
+ if (!inlen)
+ return;
+ }
+
+ while (inlen >= 64)
+ {
+ Transform(hd, inbuf);
+ hd->count = 0;
+ hd->nblocks++;
+ inlen -= 64;
+ inbuf += 64;
+ }
+ for (; inlen && hd->count < 64; inlen--)
+ hd->buf[hd->count++] = *inbuf++;
+}
+
+
+/* The routine final terminates the computation and
+ * returns the digest.
+ * The handle is prepared for a new cycle, but adding bytes to the
+ * handle will the destroy the returned buffer.
+ * Returns: 20 bytes representing the digest.
+ */
+
+void SHA1_Final(sha1_digest_t digest, sha1_context_t *hd)
+{
+ uint32_t t, msb, lsb;
+ byte *p;
+
+ SHA1_Update(hd, NULL, 0); /* flush */;
+
+ t = hd->nblocks;
+ /* multiply by 64 to make a byte count */
+ lsb = t << 6;
+ msb = t >> 26;
+ /* add the count */
+ t = lsb;
+ if ((lsb += hd->count) < t)
+ msb++;
+ /* multiply by 8 to make a bit count */
+ t = lsb;
+ lsb <<= 3;
+ msb <<= 3;
+ msb |= t >> 29;
+
+ if (hd->count < 56)
+ {
+ /* enough room */
+ hd->buf[hd->count++] = 0x80; /* pad */
+ while (hd->count < 56)
+ hd->buf[hd->count++] = 0; /* pad */
+ }
+ else
+ {
+ /* need one extra block */
+ hd->buf[hd->count++] = 0x80; /* pad character */
+ while (hd->count < 64)
+ hd->buf[hd->count++] = 0;
+ SHA1_Update(hd, NULL, 0); /* flush */;
+ memset(hd->buf, 0, 56 ); /* fill next block with zeroes */
+ }
+ /* append the 64 bit count */
+ hd->buf[56] = msb >> 24;
+ hd->buf[57] = msb >> 16;
+ hd->buf[58] = msb >> 8;
+ hd->buf[59] = msb ;
+ hd->buf[60] = lsb >> 24;
+ hd->buf[61] = lsb >> 16;
+ hd->buf[62] = lsb >> 8;
+ hd->buf[63] = lsb ;
+ Transform(hd, hd->buf);
+
+ p = hd->buf;
+#ifdef SYS_BIG_ENDIAN
+#define X(a) do { *(uint32_t*)p = hd->h##a ; p += 4; } while(0)
+#else /* little endian */
+#define X(a) do { *p++ = hd->h##a >> 24; *p++ = hd->h##a >> 16; \
+ *p++ = hd->h##a >> 8; *p++ = hd->h##a; } while(0)
+#endif
+ X(0);
+ X(1);
+ X(2);
+ X(3);
+ X(4);
+#undef X
+
+ memcpy(digest, hd->buf, sizeof(sha1_digest_t));
+}
+
+void SHA1_UpdateInt32(sha1_context_t *context, unsigned int val)
+{
+ byte buf[4];
+
+ buf[0] = (val >> 24) & 0xff;
+ buf[1] = (val >> 16) & 0xff;
+ buf[2] = (val >> 8) & 0xff;
+ buf[3] = val & 0xff;
+
+ SHA1_Update(context, buf, 4);
+}
+
+void SHA1_UpdateString(sha1_context_t *context, char *str)
+{
+ SHA1_Update(context, (byte *) str, strlen(str) + 1);
+}
+
diff --git a/src/w_checksum.c b/src/w_checksum.c
index ceda95d8..28451fda 100644
--- a/src/w_checksum.c
+++ b/src/w_checksum.c
@@ -27,7 +27,7 @@
#include <stdlib.h>
#include <string.h>
-#include "md5.h"
+#include "sha1.h"
#include "w_checksum.h"
#include "w_wad.h"
@@ -60,35 +60,35 @@ static int GetFileNumber(wad_file_t *handle)
return result;
}
-static void ChecksumAddLump(md5_context_t *md5_context, lumpinfo_t *lump)
+static void ChecksumAddLump(sha1_context_t *sha1_context, lumpinfo_t *lump)
{
char buf[9];
strncpy(buf, lump->name, 8);
buf[8] = '\0';
- MD5_UpdateString(md5_context, buf);
- MD5_UpdateInt32(md5_context, GetFileNumber(lump->wad_file));
- MD5_UpdateInt32(md5_context, lump->position);
- MD5_UpdateInt32(md5_context, lump->size);
+ SHA1_UpdateString(sha1_context, buf);
+ SHA1_UpdateInt32(sha1_context, GetFileNumber(lump->wad_file));
+ SHA1_UpdateInt32(sha1_context, lump->position);
+ SHA1_UpdateInt32(sha1_context, lump->size);
}
-void W_Checksum(md5_digest_t digest)
+void W_Checksum(sha1_digest_t digest)
{
- md5_context_t md5_context;
+ sha1_context_t sha1_context;
unsigned int i;
- MD5_Init(&md5_context);
+ SHA1_Init(&sha1_context);
num_open_wadfiles = 0;
// Go through each entry in the WAD directory, adding information
- // about each entry to the MD5 hash.
+ // about each entry to the SHA1 hash.
for (i=0; i<numlumps; ++i)
{
- ChecksumAddLump(&md5_context, &lumpinfo[i]);
+ ChecksumAddLump(&sha1_context, &lumpinfo[i]);
}
- MD5_Final(digest, &md5_context);
+ SHA1_Final(digest, &sha1_context);
}
diff --git a/src/w_checksum.h b/src/w_checksum.h
index b762e9b6..23bcfefa 100644
--- a/src/w_checksum.h
+++ b/src/w_checksum.h
@@ -28,7 +28,7 @@
#include "doomtype.h"
-extern void W_Checksum(md5_digest_t digest);
+extern void W_Checksum(sha1_digest_t digest);
#endif /* #ifndef W_CHECKSUM_H */