diff options
Diffstat (limited to 'lib/libc/md')
-rw-r--r-- | lib/libc/md/md4c.c | 33 | ||||
-rw-r--r-- | lib/libc/md/md5c.c | 66 | ||||
-rw-r--r-- | lib/libc/md/mdXhl.c | 4 |
3 files changed, 44 insertions, 59 deletions
diff --git a/lib/libc/md/md4c.c b/lib/libc/md/md4c.c index a65c0e8f15f..4f3f9a7a815 100644 --- a/lib/libc/md/md4c.c +++ b/lib/libc/md/md4c.c @@ -22,7 +22,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: md4c.c,v 1.4 1996/10/02 03:50:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: md4c.c,v 1.5 1996/11/24 02:25:58 niklas Exp $"; #endif /* LIBC_SCCS and not lint */ #include <string.h> @@ -54,9 +54,9 @@ static void MD4Transform __P ((u_int32_t [4], const unsigned char [64])); #define Decode memcpy #else /* BIG_ENDIAN */ static void Encode __P - ((unsigned char *, u_int32_t *, unsigned int)); + ((unsigned char *, u_int32_t *, size_t)); static void Decode __P - ((u_int32_t *, const unsigned char *, unsigned int)); + ((u_int32_t *, const unsigned char *, size_t)); #endif /* LITTLE_ENDIAN */ static unsigned char PADDING[64] = { @@ -97,9 +97,9 @@ static unsigned char PADDING[64] = { static void Encode (output, input, len) unsigned char *output; u_int32_t *input; -unsigned int len; +size_t len; { - unsigned int i, j; + size_t i, j; for (i = 0, j = 0; j < len; i++, j += 4) { output[j] = (unsigned char)(input[i] & 0xff); @@ -115,9 +115,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 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) | @@ -130,7 +130,7 @@ unsigned int len; void MD4Init (context) MD4_CTX *context; /* context */ { - context->count[0] = context->count[1] = 0; + context->count = 0; /* Load magic initialization constants. */ @@ -147,21 +147,18 @@ MD4_CTX *context; /* context */ void MD4Update (context, input, inputLen) MD4_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); @@ -192,11 +189,11 @@ MD4_CTX *context; /* context */ unsigned int index, 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); + index = (unsigned int)((context->count >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); MD4Update (context, PADDING, padLen); 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)); } diff --git a/lib/libc/md/mdXhl.c b/lib/libc/md/mdXhl.c index cda72b02fcf..f44d5940d52 100644 --- a/lib/libc/md/mdXhl.c +++ b/lib/libc/md/mdXhl.c @@ -8,7 +8,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: mdXhl.c,v 1.4 1996/09/29 14:55:26 millert Exp $"; +static char rcsid[] = "$OpenBSD: mdXhl.c,v 1.5 1996/11/24 02:25:59 niklas Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdlib.h> @@ -69,7 +69,7 @@ MDXFile (filename, buf) char * MDXData (data, len, buf) const unsigned char *data; - unsigned int len; + size_t len; char *buf; { MDX_CTX ctx; |