X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Fmd5.c;h=03777b15d29848fa73604671f132e01f3593c831;hb=c1cef27bda78a361d110bd20b83145b62d01ba25;hp=838ed54ff6e8c3be967681bdd2a7e45bc83b4f8c;hpb=8c5868b5007d8ff735c31f6b798bd39f836aef97;p=openldap diff --git a/libraries/liblutil/md5.c b/libraries/liblutil/md5.c index 838ed54ff6..03777b15d2 100644 --- a/libraries/liblutil/md5.c +++ b/libraries/liblutil/md5.c @@ -29,9 +29,14 @@ copyright in any changes I have made; this code remains in the public domain. */ -#include +#include "portable.h" -#include "lutil_md5.h" +#include + +/* include socket.h to get sys/types.h and/or winsock2.h */ +#include + +#include /* Little-endian byte-swapping routines. Note that these do not depend on the size of datatypes such as uint32, nor do they require @@ -40,17 +45,14 @@ surprised if they were a performance bottleneck for MD5. */ static uint32 -getu32 (addr) - const unsigned char *addr; +getu32( const unsigned char *addr ) { return (((((unsigned long)addr[3] << 8) | addr[2]) << 8) | addr[1]) << 8 | addr[0]; } static void -putu32 (data, addr) - uint32 data; - unsigned char *addr; +putu32( uint32 data, unsigned char *addr ) { addr[0] = (unsigned char)data; addr[1] = (unsigned char)(data >> 8); @@ -63,8 +65,7 @@ putu32 (data, addr) * initialization constants. */ void -MD5Init(ctx) - struct MD5Context *ctx; +lutil_MD5Init( struct lutil_MD5Context *ctx ) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; @@ -80,10 +81,11 @@ MD5Init(ctx) * of bytes. */ void -MD5Update(ctx, buf, len) - struct MD5Context *ctx; - unsigned char const *buf; - unsigned len; +lutil_MD5Update( + struct lutil_MD5Context *ctx, + const unsigned char *buf, + unsigned int len +) { uint32 t; @@ -107,7 +109,7 @@ MD5Update(ctx, buf, len) return; } memcpy(p, buf, t); - MD5Transform(ctx->buf, ctx->in); + lutil_MD5Transform(ctx->buf, ctx->in); buf += t; len -= t; } @@ -116,7 +118,7 @@ MD5Update(ctx, buf, len) while (len >= 64) { memcpy(ctx->in, buf, 64); - MD5Transform(ctx->buf, ctx->in); + lutil_MD5Transform(ctx->buf, ctx->in); buf += 64; len -= 64; } @@ -131,9 +133,7 @@ MD5Update(ctx, buf, len) * 1 0* (64-bit count of bits processed, MSB-first) */ void -MD5Final(digest, ctx) - unsigned char digest[16]; - struct MD5Context *ctx; +lutil_MD5Final( unsigned char *digest, struct lutil_MD5Context *ctx ) { unsigned count; unsigned char *p; @@ -153,7 +153,7 @@ MD5Final(digest, ctx) if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); - MD5Transform(ctx->buf, ctx->in); + lutil_MD5Transform(ctx->buf, ctx->in); /* Now fill the next block with 56 bytes */ memset(ctx->in, 0, 56); @@ -166,7 +166,7 @@ MD5Final(digest, ctx) putu32(ctx->bits[0], ctx->in + 56); putu32(ctx->bits[1], ctx->in + 60); - MD5Transform(ctx->buf, ctx->in); + lutil_MD5Transform(ctx->buf, ctx->in); putu32(ctx->buf[0], digest); putu32(ctx->buf[1], digest + 4); putu32(ctx->buf[2], digest + 8); @@ -194,9 +194,7 @@ MD5Final(digest, ctx) * the data and converts bytes into longwords for this routine. */ void -MD5Transform(buf, inraw) - uint32 buf[4]; - const unsigned char inraw[64]; +lutil_MD5Transform( uint32 *buf, const unsigned char *inraw ) { register uint32 a, b, c, d; uint32 in[16]; @@ -291,9 +289,9 @@ MD5Transform(buf, inraw) #include int -main (int argc, char **argv) +main (int argc, char **argv ) { - struct MD5Context context; + struct lutil_MD5Context context; unsigned char checksum[16]; int i; int j; @@ -306,9 +304,9 @@ main (int argc, char **argv) for (j = 1; j < argc; ++j) { printf ("MD5 (\"%s\") = ", argv[j]); - MD5Init (&context); - MD5Update (&context, argv[j], strlen (argv[j])); - MD5Final (checksum, &context); + lutil_MD5Init (&context); + lutil_MD5Update (&context, argv[j], strlen (argv[j])); + lutil_MD5Final (checksum, &context); for (i = 0; i < 16; i++) { printf ("%02x", (unsigned int) checksum[i]);