diff options
author | Karel Zak <kzak@redhat.com> | 2006-12-07 00:26:14 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2006-12-07 00:26:14 +0100 |
commit | d03dd60840f0a08464d5266539ad356aefe24b03 (patch) | |
tree | 0a9ad240a7a88eb6b11b152974a7a51a0df79b75 /lib | |
parent | a21409f54e0d600a5e40dc4f176eddac3f7172ee (diff) | |
download | util-linux-d03dd60840f0a08464d5266539ad356aefe24b03.tar.gz |
Imported from util-linux-2.12a tarball.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/md5.c | 27 | ||||
-rw-r--r-- | lib/md5.h | 13 |
2 files changed, 21 insertions, 19 deletions
@@ -15,6 +15,7 @@ * will fill a supplied 16-byte array with the digest. */ #include <string.h> /* for memcpy() */ + #include "md5.h" #ifndef HIGHFIRST @@ -28,11 +29,11 @@ void byteReverse(unsigned char *buf, unsigned longs); */ 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); } @@ -60,12 +61,12 @@ void MD5Init(struct MD5Context *ctx) */ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) { - uint32 t; + 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; @@ -83,7 +84,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) } memcpy(p, buf, t); byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); buf += t; len -= t; } @@ -92,7 +93,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) while (len >= 64) { memcpy(ctx->in, buf, 64); byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); buf += 64; len -= 64; } @@ -127,7 +128,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx) /* 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); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); /* Now fill the next block with 56 bytes */ memset(ctx->in, 0, 56); @@ -138,10 +139,10 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx) byteReverse(ctx->in, 14); /* Append length in bits and transform */ - ((uint32 *) ctx->in)[14] = ctx->bits[0]; - ((uint32 *) ctx->in)[15] = ctx->bits[1]; + ((uint32_t *) ctx->in)[14] = ctx->bits[0]; + ((uint32_t *) ctx->in)[15] = ctx->bits[1]; - MD5Transform(ctx->buf, (uint32 *) ctx->in); + MD5Transform(ctx->buf, (uint32_t *) ctx->in); byteReverse((unsigned char *) ctx->buf, 4); memcpy(digest, ctx->buf, 16); memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ @@ -166,9 +167,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]; @@ -1,15 +1,16 @@ #ifndef MD5_H #define MD5_H -#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) -typedef unsigned int uint32; +#include "../defines.h" +#ifdef HAVE_stdint_h +#include <stdint.h> #else -typedef unsigned long uint32; +typedef unsigned int uint32_t; #endif struct MD5Context { - uint32 buf[4]; - uint32 bits[2]; + uint32_t buf[4]; + uint32_t bits[2]; unsigned char in[64]; }; @@ -17,7 +18,7 @@ void MD5Init(struct MD5Context *context); void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len); void MD5Final(unsigned char digest[16], struct MD5Context *context); -void MD5Transform(uint32 buf[4], uint32 const in[16]); +void MD5Transform(uint32_t buf[4], uint32_t const in[16]); /* * This is needed to make RSAREF happy on some MS-DOS compilers. |