From 3476fcea6f388d9defbb3579158557656f50e8e1 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 15 Mar 2007 18:43:22 +0000 Subject: Change MD5 code to use the standard types used elsewhere in the program. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 858 --- src/md5.c | 29 +++++++++++++++-------------- src/md5.h | 23 ++++++++--------------- 2 files changed, 23 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/md5.c b/src/md5.c index 0b322794..950f647c 100644 --- a/src/md5.c +++ b/src/md5.c @@ -20,6 +20,7 @@ * Still in the public domain. */ +#include "doomdef.h" #include "i_swap.h" #include /* for memcpy() */ @@ -35,12 +36,12 @@ #else -void ByteSwapBlock(UWORD32 *buf, unsigned words) +void ByteSwapBlock(uint32_t *buf, unsigned words) { - md5byte *p = (md5byte *)buf; + byte *p = (byte *)buf; do { - *buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 | + *buf++ = (uint32_t)((unsigned)p[3] << 8 | p[2]) << 16 | ((unsigned)p[1] << 8 | p[0]); p += 4; } while (--words); @@ -69,9 +70,9 @@ MD5_Init(md5_context_t *ctx) * of bytes. */ void -MD5_Update(md5_context_t *ctx, md5byte const *buf, unsigned len) +MD5_Update(md5_context_t *ctx, byte const *buf, unsigned len) { - UWORD32 t; + uint32_t t; /* Update byte count */ @@ -81,11 +82,11 @@ MD5_Update(md5_context_t *ctx, md5byte const *buf, unsigned len) t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ 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); + memcpy((byte *)ctx->in + 64 - t, buf, t); ByteSwapBlock(ctx->in, 16); MD5_Transform(ctx->buf, ctx->in); buf += t; @@ -106,7 +107,7 @@ MD5_Update(md5_context_t *ctx, md5byte const *buf, unsigned len) void MD5_UpdateInt32(md5_context_t *context, unsigned int val) { - md5byte buf[4]; + byte buf[4]; buf[0] = (val >> 24) & 0xff; buf[1] = (val >> 16) & 0xff; @@ -118,7 +119,7 @@ void MD5_UpdateInt32(md5_context_t *context, unsigned int val) void MD5_UpdateString(md5_context_t *context, char *str) { - MD5_Update(context, (md5byte *) str, strlen(str) + 1); + MD5_Update(context, (byte *) str, strlen(str) + 1); } /* @@ -126,10 +127,10 @@ void MD5_UpdateString(md5_context_t *context, char *str) * 1 0* (64-bit count of bits processed, MSB-first) */ void -MD5_Final(md5byte digest[16], md5_context_t *ctx) +MD5_Final(byte digest[16], md5_context_t *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; @@ -141,7 +142,7 @@ MD5_Final(md5byte digest[16], md5_context_t *ctx) memset(p, 0, count + 8); ByteSwapBlock(ctx->in, 16); MD5_Transform(ctx->buf, ctx->in); - p = (md5byte *)ctx->in; + p = (byte *)ctx->in; count = 56; } memset(p, 0, count); @@ -177,9 +178,9 @@ MD5_Final(md5byte digest[16], md5_context_t *ctx) * the data and converts bytes into longwords for this routine. */ void -MD5_Transform(UWORD32 buf[4], UWORD32 const in[16]) +MD5_Transform(uint32_t buf[4], uint32_t const in[16]) { - register UWORD32 a, b, c, d; + register uint32_t a, b, c, d; a = buf[0]; b = buf[1]; diff --git a/src/md5.h b/src/md5.h index aa15b734..5df7f686 100644 --- a/src/md5.h +++ b/src/md5.h @@ -23,30 +23,23 @@ #ifndef MD5_H #define MD5_H -#ifdef _MSC_VER -#define WIN32_LEAN_AND_MEAN -#include -#define UWORD32 DWORD -#else -#include -#define UWORD32 uint32_t -#endif -#define md5byte unsigned char +#include "doomtype.h" typedef struct md5_context_s md5_context_t; -typedef md5byte md5_digest_t[16]; +typedef byte md5_digest_t[16]; struct md5_context_s { - UWORD32 buf[4]; - UWORD32 bytes[2]; - UWORD32 in[16]; + 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, md5byte const *buf, unsigned len); +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(UWORD32 buf[4], UWORD32 const in[16]); +void MD5_Transform(uint32_t buf[4], uint32_t const in[16]); #endif /* !MD5_H */ + -- cgit v1.2.3