X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=md5c.c;h=11a61516e2e335d201dfb4291dde1d2e88b2ab09;hb=b3e0cd2d558b5ccf06c816eed38c883d7462d3d4;hp=22ce9dee3e3e281549fd392c114c08caa3fa0abc;hpb=19d9e9bcd3f2afa2df1bbf6534b88197c3521e07;p=~andy%2Ffetchmail diff --git a/md5c.c b/md5c.c index 22ce9dee..11a61516 100644 --- a/md5c.c +++ b/md5c.c @@ -15,21 +15,24 @@ * will fill a supplied 16-byte array with the digest. */ -/* This code slightly modified to fit into Samba by - abartlet@samba.org Jun 2001 */ +#include "config.h" +#include "fm_md5.h" +#ifdef HAVE_STRING_H +#include /* memmove */ +#endif -#include "md5.h" +#include /* * Note: this code is harmless on little-endian machines. */ static void byteReverse(unsigned char *buf, unsigned longs) { - uint32 t; + uint32_t t; do { - t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | + t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | ((unsigned) buf[1] << 8 | buf[0]); - *(uint32 *) buf = t; + *(uint32_t *) buf = t; buf += 4; } while (--longs); } @@ -53,14 +56,15 @@ void MD5Init(struct MD5Context *ctx) * Update context to reflect the concatenation of another buffer full * of bytes. */ -void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) +void MD5Update(struct MD5Context *ctx, const void *buf_, unsigned len) { - register uint32 t; + const unsigned char *buf = (const unsigned char *)buf_; + register uint32_t t; /* Update bitcount */ t = ctx->bits[0]; - if ((ctx->bits[0] = t + ((uint32) len << 3)) < t) + if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) ctx->bits[1]++; /* Carry from low to high */ ctx->bits[1] += len >> 29; @@ -69,7 +73,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) /* Handle any leading odd-sized chunks */ if (t) { - unsigned char *p = (unsigned char *) ctx->in + t; + unsigned char *p = (unsigned char *) ctx->u.in + t; t = 64 - t; if (len < t) { @@ -77,31 +81,31 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) return; } memmove(p, buf, t); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); + byteReverse(ctx->u.in, 16); + MD5Transform(ctx->buf, ctx->u.in32); buf += t; len -= t; } /* Process data in 64-byte chunks */ while (len >= 64) { - memmove(ctx->in, buf, 64); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); + memmove(ctx->u.in, buf, 64); + byteReverse(ctx->u.in, 16); + MD5Transform(ctx->buf, ctx->u.in32); buf += 64; len -= 64; } /* Handle any remaining bytes of data. */ - memmove(ctx->in, buf, len); + memmove(ctx->u.in, buf, len); } /* * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ -void MD5Final(unsigned char digest[16], struct MD5Context *ctx) +void MD5Final(void *digest, struct MD5Context *ctx) { unsigned int count; unsigned char *p; @@ -111,7 +115,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx) /* Set the first char of padding to 0x80. This is safe since there is always at least one byte free */ - p = ctx->in + count; + p = ctx->u.in + count; *p++ = 0x80; /* Bytes of padding needed to make 64 bytes */ @@ -121,25 +125,25 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx) if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); + byteReverse(ctx->u.in, 16); + MD5Transform(ctx->buf, ctx->u.in32); /* Now fill the next block with 56 bytes */ - memset(ctx->in, 0, 56); + memset(ctx->u.in, 0, 56); } else { /* Pad block to 56 bytes */ memset(p, 0, count - 8); } - byteReverse(ctx->in, 14); + byteReverse(ctx->u.in, 14); /* Append length in bits and transform */ - ((uint32 *) ctx->in)[14] = ctx->bits[0]; - ((uint32 *) ctx->in)[15] = ctx->bits[1]; + ctx->u.in32[14] = ctx->bits[0]; + ctx->u.in32[15] = ctx->bits[1]; - MD5Transform(ctx->buf, (uint32 *) ctx->in); + MD5Transform(ctx->buf, ctx->u.in32); byteReverse((unsigned char *) ctx->buf, 4); memmove(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ + memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ } /* The four core functions - F1 is optimized somewhat */ @@ -159,9 +163,9 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx) * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ -void MD5Transform(uint32 buf[4], uint32 const in[16]) +void MD5Transform(uint32_t buf[4], uint32_t const in[16]) { - register uint32 a, b, c, d; + register uint32_t a, b, c, d; a = buf[0]; b = buf[1];