Quash various warnings from higher levels of compiler warnings.
[ircu2.10.12-pk.git] / ircd / ircd_md5.c
index b5b15d46981ad863a7c007bc370284f02fe223c2..0d7d73e23a4d36faf59b9f2721c71376c37337c3 100644 (file)
  * will fill a supplied 16-byte array with the digest.
  *
  * ircuified 2002 by hikari
- *
- * $Id$
-*/
+ */
+/** @file
+ * @brief MD5 implementation for ircu.
+ * @version $Id$
+ */
 
 #include <string.h>
 #include "ircd_md5.h"
 
 #ifndef HIGHFIRST
+/** Bit-reverse bytes in a buffer. */
 #define byteReverse(buf, len)  /* Nothing */
 #else
 static void byteReverse(unsigned char *buf, unsigned longs);
@@ -46,11 +49,10 @@ static void byteReverse(unsigned char *buf, unsigned longs)
 #endif
 #endif
 
-/*
- * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
- * initialization constants.
+/** Iniitalize MD5 context.
+ * @param[out] ctx MD5 context to initialize.
  */
-void MD5Name(MD5Init)(struct MD5Context *ctx)
+void MD5Init(struct MD5Context *ctx)
 {
        ctx->buf[0] = 0x67452301U;
        ctx->buf[1] = 0xefcdab89U;
@@ -61,11 +63,12 @@ void MD5Name(MD5Init)(struct MD5Context *ctx)
        ctx->bits[1] = 0;
 }
 
-/*
- * Update context to reflect the concatenation of another buffer full
- * of bytes.
+/** Update MD5 context with data from a buffer.
+ * @param[in,out] ctx MD5 context to operate on.
+ * @param[in] buf Input buffer.
+ * @param[in] len Number of bytes in input buffer.
  */
-void MD5Name(MD5Update)(struct MD5Context *ctx, unsigned const char *buf, unsigned len)
+void MD5Update(struct MD5Context *ctx, unsigned const char *buf, unsigned len)
 {
        uint32 t;
 
@@ -90,7 +93,7 @@ void MD5Name(MD5Update)(struct MD5Context *ctx, unsigned const char *buf, unsign
                }
                memcpy(p, buf, t);
                byteReverse(ctx->in, 16);
-               MD5Name(MD5Transform)(ctx->buf, (uint32 *) ctx->in);
+               MD5Transform(ctx->buf, (uint32 *) ctx->in);
                buf += t;
                len -= t;
        }
@@ -99,7 +102,7 @@ void MD5Name(MD5Update)(struct MD5Context *ctx, unsigned const char *buf, unsign
        while (len >= 64) {
                memcpy(ctx->in, buf, 64);
                byteReverse(ctx->in, 16);
-               MD5Name(MD5Transform)(ctx->buf, (uint32 *) ctx->in);
+               MD5Transform(ctx->buf, (uint32 *) ctx->in);
                buf += 64;
                len -= 64;
        }
@@ -109,11 +112,11 @@ void MD5Name(MD5Update)(struct MD5Context *ctx, unsigned const char *buf, unsign
        memcpy(ctx->in, buf, len);
 }
 
-/*
- * Final wrapup - pad to 64-byte boundary with the bit pattern 
- * 1 0* (64-bit count of bits processed, MSB-first)
+/** Perform final steps of MD5 hash.
+ * @param[out] digest Receives output hash value.
+ * @param[in,out] ctx MD5 context to finalize.
  */
-void MD5Name(MD5Final)(unsigned char digest[16], struct MD5Context *ctx)
+void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
 {
        unsigned count;
        unsigned char *p;
@@ -134,7 +137,7 @@ void MD5Name(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);
-               MD5Name(MD5Transform)(ctx->buf, (uint32 *) ctx->in);
+               MD5Transform(ctx->buf, (uint32 *) ctx->in);
 
                /* Now fill the next block with 56 bytes */
                memset(ctx->in, 0, 56);
@@ -148,10 +151,10 @@ void MD5Name(MD5Final)(unsigned char digest[16], struct MD5Context *ctx)
        ((uint32 *) ctx->in)[14] = ctx->bits[0];
        ((uint32 *) ctx->in)[15] = ctx->bits[1];
 
-       MD5Name(MD5Transform)(ctx->buf, (uint32 *) ctx->in);
+       MD5Transform(ctx->buf, (uint32 *) ctx->in);
        byteReverse((unsigned char *) ctx->buf, 4);
        memcpy(digest, ctx->buf, 16);
-       memset(ctx, 0, sizeof(ctx));    /* In case it's sensitive */
+       memset(ctx, 0, sizeof(*ctx));   /* In case it's sensitive */
 }
 
 #ifndef ASM_MD5
@@ -159,21 +162,25 @@ void MD5Name(MD5Final)(unsigned char digest[16], struct MD5Context *ctx)
 /* The four core functions - F1 is optimized somewhat */
 
 /* #define F1(x, y, z) (x & y | ~x & z) */
+/** Helper function for first round of MD5. */
 #define F1(x, y, z) (z ^ (x & (y ^ z)))
+/** Helper function for second round of MD5. */
 #define F2(x, y, z) F1(z, x, y)
+/** Helper function for third round of MD5. */
 #define F3(x, y, z) (x ^ y ^ z)
+/** Helper function for fourth round of MD5. */
 #define F4(x, y, z) (y ^ (x | ~z))
 
-/* This is the central step in the MD5 algorithm. */
+/** Step function for each round of MD5 */
 #define MD5STEP(f, w, x, y, z, data, s) \
        ( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )
 
-/*
- * The core of the MD5 algorithm, this alters an existing MD5 hash to
- * reflect the addition of 16 longwords of new data.  MD5Update blocks
- * the data and converts bytes into longwords for this routine.
+/** Perform the core MD5 update steps to update a 128-bit hash value
+ * with 512 bits of input data.
+ * @param[in,out] buf Hash value.
+ * @param[in] in Input buffer.
  */
-void MD5Name(MD5Transform)(uint32 buf[4], uint32 const in[16])
+void MD5Transform(uint32 buf[4], uint32 const in[16])
 {
        register uint32 a, b, c, d;