diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-11-24 02:26:01 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-11-24 02:26:01 +0000 |
commit | 6388d3d9cf07f4ef99b2149951cb5533a69f8912 (patch) | |
tree | ebc1a9ef18f305b2559289da5f10ca04db7bddb6 | |
parent | 2cc34713ef2a7401726ee17cc4419cee9b170cab (diff) |
64-bit cleanup + pedantic -W flags
-rw-r--r-- | bin/md5/Makefile | 5 | ||||
-rw-r--r-- | bin/md5/md5.c | 14 | ||||
-rw-r--r-- | include/md4.h | 8 | ||||
-rw-r--r-- | include/md5.h | 8 | ||||
-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 |
7 files changed, 63 insertions, 75 deletions
diff --git a/bin/md5/Makefile b/bin/md5/Makefile index 62fccb4c23e..46e59bf216c 100644 --- a/bin/md5/Makefile +++ b/bin/md5/Makefile @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile,v 1.2 1996/11/12 23:33:01 niklas Exp $ +# $OpenBSD: Makefile,v 1.3 1996/11/24 02:26:00 niklas Exp $ PROG= md5 SRCS= md5.c -COPTS+= -Wall +COPTS+= -Wall -Wconversion -Wstrict-prototypes -Wmissing-prototypes -Werror \ + -DPROTOTYPES .include <bsd.prog.mk> diff --git a/bin/md5/md5.c b/bin/md5/md5.c index 5f0d6fbc251..994cbce4df8 100644 --- a/bin/md5/md5.c +++ b/bin/md5/md5.c @@ -1,5 +1,5 @@ /* - * $OpenBSD: md5.c,v 1.2 1996/11/12 23:33:02 niklas Exp $ + * $OpenBSD: md5.c,v 1.3 1996/11/24 02:26:00 niklas Exp $ * * Derived from: */ @@ -38,6 +38,8 @@ static void MDTimeTrial PROTO_LIST((void)); static void MDTestSuite PROTO_LIST((void)); static void MDFilter PROTO_LIST((int)); +int main PROTO_LIST((int, char *[])); + /* Main driver. Arguments (may be any combination): @@ -85,7 +87,7 @@ static void MDString(string) char *string; { - unsigned int len = strlen(string); + size_t len = strlen(string); char buf[33]; printf("MD5 (\"%s\") = %s\n", string, MD5Data(string, len, buf)); @@ -116,7 +118,7 @@ MDTimeTrial() /* Digest blocks */ MD5Init(&context); for (i = 0; i < TEST_BLOCK_COUNT; i++) - MD5Update(&context, block, TEST_BLOCK_LEN); + MD5Update(&context, block, (size_t)TEST_BLOCK_LEN); p = MD5End(&context,buf); /* Stop timer */ @@ -158,13 +160,13 @@ static void MDFilter(int pipe) { MD5_CTX context; - int len; + size_t len; unsigned char buffer[BUFSIZ]; char buf[33]; MD5Init(&context); - while ((len = fread(buffer, 1, BUFSIZ, stdin)) > 0) { - if(pipe && (len != fwrite(buffer, 1, len, stdout))) { + while ((len = fread(buffer, (size_t)1, (size_t)BUFSIZ, stdin)) > 0) { + if(pipe && (len != fwrite(buffer, (size_t)1, len, stdout))) { perror("stdout"); exit(1); } diff --git a/include/md4.h b/include/md4.h index dd81739e343..b8874172fc9 100644 --- a/include/md4.h +++ b/include/md4.h @@ -1,5 +1,5 @@ /* MD4.H - header file for MD4C.C - * $OpenBSD: md4.h,v 1.3 1996/09/30 03:55:47 millert Exp $ + * $OpenBSD: md4.h,v 1.4 1996/11/24 02:25:57 niklas Exp $ */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All @@ -29,15 +29,15 @@ /* MD4 context. */ typedef struct MD4Context { u_int32_t state[4]; /* state (ABCD) */ - u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + u_int64_t count; /* number of bits, modulo 2^64 */ unsigned char buffer[64]; /* input buffer */ } MD4_CTX; void MD4Init __P((MD4_CTX *)); -void MD4Update __P((MD4_CTX *, const unsigned char *, unsigned int)); +void MD4Update __P((MD4_CTX *, const unsigned char *, size_t)); void MD4Final __P((unsigned char [16], MD4_CTX *)); char * MD4End __P((MD4_CTX *, char *)); char * MD4File __P((char *, char *)); -char * MD4Data __P((const unsigned char *, unsigned int, char *)); +char * MD4Data __P((const unsigned char *, size_t, char *)); #endif /* _MD4_H_ */ diff --git a/include/md5.h b/include/md5.h index 2f44e942c56..638371330d3 100644 --- a/include/md5.h +++ b/include/md5.h @@ -1,5 +1,5 @@ /* MD5.H - header file for MD5C.C - * $OpenBSD: md5.h,v 1.3 1996/09/30 03:55:48 millert Exp $ + * $OpenBSD: md5.h,v 1.4 1996/11/24 02:25:57 niklas Exp $ */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All @@ -30,15 +30,15 @@ documentation and/or software. /* MD5 context. */ typedef struct MD5Context { u_int32_t state[4]; /* state (ABCD) */ - u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + u_int64_t count; /* number of bits, modulo 2^64 */ unsigned char buffer[64]; /* input buffer */ } MD5_CTX; void MD5Init __P((MD5_CTX *)); -void MD5Update __P((MD5_CTX *, const unsigned char *, unsigned int)); +void MD5Update __P((MD5_CTX *, const unsigned char *, size_t)); void MD5Final __P((unsigned char [16], MD5_CTX *)); char * MD5End __P((MD5_CTX *, char *)); char * MD5File __P((char *, char *)); -char * MD5Data __P((const unsigned char *, unsigned int, char *)); +char * MD5Data __P((const unsigned char *, size_t, char *)); #endif /* _MD5_H_ */ 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; |