]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/md5.c
Fix Winsock-related warning and/or bugs.
[openldap] / libraries / liblutil / md5.c
index 46857666ec0754e6c215733cccd4a78ab862dd11..6758de02409af77e40adb6296de2dcd71fac60a7 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Modified by Kurt D. Zeilenga for inclusion into OpenLDAP
  * I hereby disclaim copyright in any changes I have made; this
@@ -33,6 +38,9 @@
 
 #include <ac/string.h>
 
+/* include socket.h to get sys/types.h and/or winsock2.h */
+#include <ac/socket.h>
+
 #include <lutil_md5.h>
 
 /* Little-endian byte-swapping routines.  Note that these do not
    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);
@@ -65,8 +70,7 @@ putu32 (data, addr)
  * initialization constants.
  */
 void
-ldap_MD5Init(ctx)
-     struct ldap_MD5Context *ctx;
+lutil_MD5Init( struct lutil_MD5Context *ctx )
 {
        ctx->buf[0] = 0x67452301;
        ctx->buf[1] = 0xefcdab89;
@@ -82,10 +86,11 @@ ldap_MD5Init(ctx)
  * of bytes.
  */
 void
-ldap_MD5Update(ctx, buf, len)
-     struct ldap_MD5Context *ctx;
-     unsigned char const *buf;
-     unsigned len;
+lutil_MD5Update(
+    struct lutil_MD5Context    *ctx,
+    const unsigned char                *buf,
+    unsigned int               len
+)
 {
        uint32 t;
 
@@ -109,7 +114,7 @@ ldap_MD5Update(ctx, buf, len)
                        return;
                }
                memcpy(p, buf, t);
-               ldap_MD5Transform(ctx->buf, ctx->in);
+               lutil_MD5Transform(ctx->buf, ctx->in);
                buf += t;
                len -= t;
        }
@@ -118,7 +123,7 @@ ldap_MD5Update(ctx, buf, len)
 
        while (len >= 64) {
                memcpy(ctx->in, buf, 64);
-               ldap_MD5Transform(ctx->buf, ctx->in);
+               lutil_MD5Transform(ctx->buf, ctx->in);
                buf += 64;
                len -= 64;
        }
@@ -133,9 +138,7 @@ ldap_MD5Update(ctx, buf, len)
  * 1 0* (64-bit count of bits processed, MSB-first)
  */
 void
-ldap_MD5Final(digest, ctx)
-     unsigned char digest[16];
-     struct ldap_MD5Context *ctx;
+lutil_MD5Final( unsigned char *digest, struct lutil_MD5Context *ctx )
 {
        unsigned count;
        unsigned char *p;
@@ -155,7 +158,7 @@ ldap_MD5Final(digest, ctx)
        if (count < 8) {
                /* Two lots of padding:  Pad the first block to 64 bytes */
                memset(p, 0, count);
-               ldap_MD5Transform(ctx->buf, ctx->in);
+               lutil_MD5Transform(ctx->buf, ctx->in);
 
                /* Now fill the next block with 56 bytes */
                memset(ctx->in, 0, 56);
@@ -168,7 +171,7 @@ ldap_MD5Final(digest, ctx)
        putu32(ctx->bits[0], ctx->in + 56);
        putu32(ctx->bits[1], ctx->in + 60);
 
-       ldap_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);
@@ -196,9 +199,7 @@ ldap_MD5Final(digest, ctx)
  * the data and converts bytes into longwords for this routine.
  */
 void
-ldap_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];
@@ -293,9 +294,9 @@ ldap_MD5Transform(buf, inraw)
 #include <stdio.h>
 
 int
-main (int argc, char **argv)
+main (int  argc, char **argv )
 {
-       struct ldap_MD5Context context;
+       struct lutil_MD5Context context;
        unsigned char checksum[16];
        int i;
        int j;
@@ -303,20 +304,20 @@ main (int argc, char **argv)
        if (argc < 2)
        {
                fprintf (stderr, "usage: %s string-to-hash\n", argv[0]);
-               exit (1);
+               return EXIT_FAILURE;
        }
        for (j = 1; j < argc; ++j)
        {
                printf ("MD5 (\"%s\") = ", argv[j]);
-               ldap_MD5Init (&context);
-               ldap_MD5Update (&context, argv[j], strlen (argv[j]));
-               ldap_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]);
                }
                printf ("\n");
        }
-       return 0;
+       return EXIT_SUCCESS;
 }
 #endif /* TEST */