summaryrefslogtreecommitdiff
path: root/lib/libc/md/md5c.c
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1996-11-24 02:26:01 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1996-11-24 02:26:01 +0000
commit6388d3d9cf07f4ef99b2149951cb5533a69f8912 (patch)
treeebc1a9ef18f305b2559289da5f10ca04db7bddb6 /lib/libc/md/md5c.c
parent2cc34713ef2a7401726ee17cc4419cee9b170cab (diff)
64-bit cleanup + pedantic -W flags
Diffstat (limited to 'lib/libc/md/md5c.c')
-rw-r--r--lib/libc/md/md5c.c66
1 files changed, 27 insertions, 39 deletions
diff --git a/lib/libc/md/md5c.c b/lib/libc/md/md5c.c
index 01796477ca4..0a831fd5e0a 100644
--- a/lib/libc/md/md5c.c
+++ b/lib/libc/md/md5c.c
@@ -23,7 +23,7 @@ documentation and/or software.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: md5c.c,v 1.4 1996/10/02 03:50:26 millert Exp $";
+static char rcsid[] = "$OpenBSD: md5c.c,v 1.5 1996/11/24 02:25:58 niklas Exp $";
#endif /* LIBC_SCCS and not lint */
#include <string.h>
@@ -58,10 +58,8 @@ static void MD5Transform __P ((u_int32_t [4], const unsigned char [64]));
#define Encode memcpy
#define Decode memcpy
#else /* BIG_ENDIAN */
-static void Encode __P
- ((unsigned char *, u_int32_t *, unsigned int));
-static void Decode __P
- ((u_int32_t *, const unsigned char *, unsigned int));
+static void Encode __P((unsigned char *, u_int32_t *, size_t));
+static void Decode __P((u_int32_t *, const unsigned char *, size_t));
#endif /* LITTLE_ENDIAN */
static unsigned char PADDING[64] = {
@@ -112,9 +110,9 @@ Rotation is separate from addition to prevent recomputation.
static void Encode (output, input, len)
unsigned char *output;
u_int32_t *input;
-unsigned int len;
+size_t len;
{
- unsigned int i, j;
+ unsigned size_t i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char)(input[i] & 0xff);
@@ -130,9 +128,9 @@ unsigned int len;
static void Decode (output, input, len)
u_int32_t *output;
const unsigned char *input;
-unsigned int len;
+size_t len;
{
- unsigned int i, j;
+ size_t int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((u_int32_t)input[j]) | (((u_int32_t)input[j+1]) << 8) |
@@ -145,9 +143,8 @@ unsigned int len;
void MD5Init (context)
MD5_CTX *context; /* context */
{
- context->count[0] = context->count[1] = 0;
- /* Load magic initialization constants.
-*/
+ context->count = 0;
+ /* Load magic initialization constants. */
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
@@ -161,40 +158,33 @@ MD5_CTX *context; /* context */
void MD5Update (context, input, inputLen)
MD5_CTX *context; /* context */
const unsigned char *input; /* input block */
-unsigned int inputLen; /* length of input block */
+size_t inputLen; /* length of input block */
{
unsigned int i, index, partLen;
/* Compute number of bytes mod 64 */
- index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ index = (unsigned int)((context->count >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((u_int32_t)inputLen << 3))
- < ((u_int32_t)inputLen << 3))
- context->count[1]++;
- context->count[1] += ((u_int32_t)inputLen >> 29);
+ context->count += (inputLen << 3);
partLen = 64 - index;
- /* Transform as many times as possible.
-*/
+ /* Transform as many times as possible. */
if (inputLen >= partLen) {
- memcpy
- ((POINTER)&context->buffer[index], (POINTER)input, partLen);
- MD5Transform (context->state, context->buffer);
+ memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen);
+ MD5Transform (context->state, context->buffer);
- for (i = partLen; i + 63 < inputLen; i += 64)
- MD5Transform (context->state, &input[i]);
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform (context->state, &input[i]);
- index = 0;
+ index = 0;
}
else
- i = 0;
+ i = 0;
/* Buffer remaining input */
- memcpy
- ((POINTER)&context->buffer[index], (POINTER)&input[i],
- inputLen-i);
+ memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i);
}
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
@@ -205,14 +195,14 @@ unsigned char digest[16]; /* message digest */
MD5_CTX *context; /* context */
{
unsigned char bits[8];
- unsigned int index, padLen;
+ unsigned int index;
+ size_t padLen;
/* Save number of bits */
- Encode (bits, context->count, 8);
+ Encode (bits, &context->count, 8);
- /* Pad out to 56 mod 64.
-*/
- index = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ /* Pad out to 56 mod 64. */
+ index = (unsigned int)((context->count >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
MD5Update (context, PADDING, padLen);
@@ -221,8 +211,7 @@ MD5_CTX *context; /* context */
/* Store state in digest */
Encode (digest, context->state, 16);
- /* Zeroize sensitive information.
-*/
+ /* Zeroize sensitive information. */
memset ((POINTER)context, 0, sizeof (*context));
}
@@ -313,8 +302,7 @@ const unsigned char block[64];
state[2] += c;
state[3] += d;
- /* Zeroize sensitive information.
-*/
+ /* Zeroize sensitive information. */
memset ((POINTER)x, 0, sizeof (x));
}