From bd747228dfabff0e699c56c6d34b0c41735d06b0 Mon Sep 17 00:00:00 2001 From: millert <> Date: Mon, 23 Dec 2002 04:33:31 +0000 Subject: [PATCH] o Ansi function headers o Add __BEGIN_DECLS/__END_DECLS to include files o Safe macros o Remove useless variable assignment in the End function of *hl.c o Some minor KNF, needs more From Dan Weeks --- src/include/md4.h | 6 +++++- src/include/md5.h | 6 +++++- src/include/rmd160.h | 6 +++++- src/include/sha1.h | 36 ++++++++++++++++++++---------------- src/lib/libc/hash/rmd160.c | 34 +++++++++++++++++----------------- src/lib/libc/hash/rmd160hl.c | 30 +++++++++++------------------- src/lib/libc/hash/sha1.c | 26 +++++++++++++------------- src/lib/libc/hash/sha1hl.c | 28 ++++++++++------------------ 8 files changed, 86 insertions(+), 86 deletions(-) diff --git a/src/include/md4.h b/src/include/md4.h index 89cabf74..0bd4e4a5 100644 --- a/src/include/md4.h +++ b/src/include/md4.h @@ -1,5 +1,5 @@ /* MD4.H - header file for MD4C.C - * $OpenBSD: md4.h,v 1.6 2002/02/16 21:27:17 millert Exp $ + * $OpenBSD: md4.h,v 1.7 2002/12/23 04:33:31 millert Exp $ */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All @@ -33,6 +33,9 @@ typedef struct MD4Context { unsigned char buffer[64]; /* input buffer */ } MD4_CTX; +#include + +__BEGIN_DECLS void MD4Init(MD4_CTX *); void MD4Update(MD4_CTX *, const unsigned char *, size_t); void MD4Final(unsigned char [16], MD4_CTX *); @@ -40,5 +43,6 @@ void MD4Transform(u_int32_t [4], const unsigned char [64]); char * MD4End(MD4_CTX *, char *); char * MD4File(char *, char *); char * MD4Data(const unsigned char *, size_t, char *); +__END_DECLS #endif /* _MD4_H_ */ diff --git a/src/include/md5.h b/src/include/md5.h index 8190b176..95834019 100644 --- a/src/include/md5.h +++ b/src/include/md5.h @@ -1,5 +1,5 @@ /* MD5.H - header file for MD5C.C - * $OpenBSD: md5.h,v 1.6 2002/02/16 21:27:17 millert Exp $ + * $OpenBSD: md5.h,v 1.7 2002/12/23 04:33:31 millert Exp $ */ /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All @@ -34,6 +34,9 @@ typedef struct MD5Context { unsigned char buffer[64]; /* input buffer */ } MD5_CTX; +#include + +__BEGIN_DECLS void MD5Init(MD5_CTX *); void MD5Update(MD5_CTX *, const unsigned char *, size_t); void MD5Final(unsigned char [16], MD5_CTX *); @@ -41,5 +44,6 @@ void MD5Transform(u_int32_t [4], const unsigned char [64]); char * MD5End(MD5_CTX *, char *); char * MD5File(char *, char *); char * MD5Data(const unsigned char *, size_t, char *); +__END_DECLS #endif /* _MD5_H_ */ diff --git a/src/include/rmd160.h b/src/include/rmd160.h index b950fd7f..b31b07f6 100644 --- a/src/include/rmd160.h +++ b/src/include/rmd160.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rmd160.h,v 1.6 2002/02/16 21:27:17 millert Exp $ */ +/* $OpenBSD: rmd160.h,v 1.7 2002/12/23 04:33:31 millert Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. * @@ -32,6 +32,9 @@ typedef struct RMD160Context { u_char buffer[64]; /* input buffer */ } RMD160_CTX; +#include + +__BEGIN_DECLS void RMD160Init(RMD160_CTX *); void RMD160Transform(u_int32_t [5], const u_char [64]); void RMD160Update(RMD160_CTX *, const u_char *, u_int32_t); @@ -39,5 +42,6 @@ void RMD160Final(u_char [20], RMD160_CTX *); char *RMD160End(RMD160_CTX *, char *); char *RMD160File(char *, char *); char *RMD160Data(const u_char *, size_t, char *); +__END_DECLS #endif /* _RMD160_H */ diff --git a/src/include/sha1.h b/src/include/sha1.h index 58733f16..613a7140 100644 --- a/src/include/sha1.h +++ b/src/include/sha1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sha1.h,v 1.10 2002/02/16 21:27:17 millert Exp $ */ +/* $OpenBSD: sha1.h,v 1.11 2002/12/23 04:33:31 millert Exp $ */ /* * SHA-1 in C @@ -11,10 +11,13 @@ typedef struct { u_int32_t state[5]; - u_int32_t count[2]; + u_int32_t count[2]; u_char buffer[64]; } SHA1_CTX; - + +#include + +__BEGIN_DECLS void SHA1Transform(u_int32_t state[5], const u_char buffer[64]); void SHA1Init(SHA1_CTX *context); void SHA1Update(SHA1_CTX *context, const u_char *data, u_int len); @@ -22,21 +25,22 @@ void SHA1Final(u_char digest[20], SHA1_CTX *context); char *SHA1End(SHA1_CTX *, char *); char *SHA1File(char *, char *); char *SHA1Data(const u_char *, size_t, char *); +__END_DECLS #define SHA1_DIGESTSIZE 20 #define SHA1_BLOCKSIZE 64 -#define HTONDIGEST(x) { \ - x[0] = htonl(x[0]); \ - x[1] = htonl(x[1]); \ - x[2] = htonl(x[2]); \ - x[3] = htonl(x[3]); \ - x[4] = htonl(x[4]); } - -#define NTOHDIGEST(x) { \ - x[0] = ntohl(x[0]); \ - x[1] = ntohl(x[1]); \ - x[2] = ntohl(x[2]); \ - x[3] = ntohl(x[3]); \ - x[4] = ntohl(x[4]); } +#define HTONDIGEST(x) do { \ + x[0] = htonl(x[0]); \ + x[1] = htonl(x[1]); \ + x[2] = htonl(x[2]); \ + x[3] = htonl(x[3]); \ + x[4] = htonl(x[4]); } while (0) + +#define NTOHDIGEST(x) do { \ + x[0] = ntohl(x[0]); \ + x[1] = ntohl(x[1]); \ + x[2] = ntohl(x[2]); \ + x[3] = ntohl(x[3]); \ + x[4] = ntohl(x[4]); } while (0) #endif /* _SHA1_H */ diff --git a/src/lib/libc/hash/rmd160.c b/src/lib/libc/hash/rmd160.c index 2826a627..a8c6a409 100644 --- a/src/lib/libc/hash/rmd160.c +++ b/src/lib/libc/hash/rmd160.c @@ -32,23 +32,23 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: rmd160.c,v 1.11 2001/10/01 20:36:17 markus Exp $"; +static char rcsid[] = "$OpenBSD: rmd160.c,v 1.12 2002/12/23 04:33:31 millert Exp $"; #endif /* LIBC_SCCS and not lint */ -#define PUT_64BIT_LE(cp, value) do { \ - (cp)[7] = (value) >> 56; \ - (cp)[6] = (value) >> 48; \ - (cp)[5] = (value) >> 40; \ - (cp)[4] = (value) >> 32; \ - (cp)[3] = (value) >> 24; \ - (cp)[2] = (value) >> 16; \ - (cp)[1] = (value) >> 8; \ +#define PUT_64BIT_LE(cp, value) do { \ + (cp)[7] = (value) >> 56; \ + (cp)[6] = (value) >> 48; \ + (cp)[5] = (value) >> 40; \ + (cp)[4] = (value) >> 32; \ + (cp)[3] = (value) >> 24; \ + (cp)[2] = (value) >> 16; \ + (cp)[1] = (value) >> 8; \ (cp)[0] = (value); } while (0) -#define PUT_32BIT_LE(cp, value) do { \ - (cp)[3] = (value) >> 24; \ - (cp)[2] = (value) >> 16; \ - (cp)[1] = (value) >> 8; \ +#define PUT_32BIT_LE(cp, value) do { \ + (cp)[3] = (value) >> 24; \ + (cp)[2] = (value) >> 16; \ + (cp)[1] = (value) >> 8; \ (cp)[0] = (value); } while (0) #define H0 0x67452301U @@ -78,10 +78,10 @@ static char rcsid[] = "$OpenBSD: rmd160.c,v 1.11 2001/10/01 20:36:17 markus Exp #define F3(x, y, z) (((x) & (z)) | ((y) & (~z))) #define F4(x, y, z) ((x) ^ ((y) | (~z))) -#define R(a, b, c, d, e, Fj, Kj, sj, rj) \ - do { \ - a = ROL(sj, a + Fj(b,c,d) + X(rj) + Kj) + e; \ - c = ROL(10, c); \ +#define R(a, b, c, d, e, Fj, Kj, sj, rj) \ + do { \ + a = ROL(sj, a + Fj(b,c,d) + X(rj) + Kj) + e; \ + c = ROL(10, c); \ } while(0) #define X(i) x[i] diff --git a/src/lib/libc/hash/rmd160hl.c b/src/lib/libc/hash/rmd160hl.c index 06511336..bf006002 100644 --- a/src/lib/libc/hash/rmd160hl.c +++ b/src/lib/libc/hash/rmd160hl.c @@ -8,7 +8,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: rmd160hl.c,v 1.2 1999/08/17 09:13:12 millert Exp $"; +static char rcsid[] = "$OpenBSD: rmd160hl.c,v 1.3 2002/12/23 04:33:31 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -22,31 +22,26 @@ static char rcsid[] = "$OpenBSD: rmd160hl.c,v 1.2 1999/08/17 09:13:12 millert Ex /* ARGSUSED */ char * -RMD160End(ctx, buf) - RMD160_CTX *ctx; - char *buf; +RMD160End(RMD160_CTX *ctx, char *buf) { int i; - char *p = buf; u_char digest[20]; static const char hex[]="0123456789abcdef"; - if (p == NULL && (p = malloc(41)) == NULL) - return 0; + if (buf == NULL && (buf = malloc(41)) == NULL) + return(NULL); - RMD160Final(digest,ctx); + RMD160Final(digest, ctx); for (i = 0; i < 20; i++) { - p[i + i] = hex[digest[i] >> 4]; - p[i + i + 1] = hex[digest[i] & 0x0f]; + buf[i + i] = hex[digest[i] >> 4]; + buf[i + i + 1] = hex[digest[i] & 0x0f]; } - p[i + i] = '\0'; - return(p); + buf[i + i] = '\0'; + return(buf); } char * -RMD160File (filename, buf) - char *filename; - char *buf; +RMD160File (char *filename, char *buf) { u_char buffer[BUFSIZ]; RMD160_CTX ctx; @@ -67,10 +62,7 @@ RMD160File (filename, buf) } char * -RMD160Data (data, len, buf) - const u_char *data; - size_t len; - char *buf; +RMD160Data (const u_char *data, size_t len, char *buf) { RMD160_CTX ctx; diff --git a/src/lib/libc/hash/sha1.c b/src/lib/libc/hash/sha1.c index 7b11732e..def87a5b 100644 --- a/src/lib/libc/hash/sha1.c +++ b/src/lib/libc/hash/sha1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $ */ +/* $OpenBSD: sha1.c,v 1.10 2002/12/23 04:33:31 millert Exp $ */ /* * SHA-1 in C @@ -14,6 +14,10 @@ * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F */ +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: sha1.c,v 1.10 2002/12/23 04:33:31 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + #define SHA1HANDSOFF /* Copies data before messing with it. */ #include @@ -48,9 +52,8 @@ /* * Hash a single 512-bit block. This is the core of the algorithm. */ -void SHA1Transform(state, buffer) - u_int32_t state[5]; - const u_char buffer[64]; +void +SHA1Transform(u_int32_t state[5], const u_char buffer[64]) { u_int32_t a, b, c, d, e; typedef union { @@ -111,8 +114,8 @@ void SHA1Transform(state, buffer) /* * SHA1Init - Initialize new context */ -void SHA1Init(context) - SHA1_CTX *context; +void +SHA1Init(SHA1_CTX *context) { /* SHA1 initialization constants */ @@ -128,10 +131,8 @@ void SHA1Init(context) /* * Run your data through this. */ -void SHA1Update(context, data, len) - SHA1_CTX *context; - const u_char *data; - u_int len; +void +SHA1Update(SHA1_CTX *context, const u_char *data, u_int len) { u_int i, j; @@ -155,9 +156,8 @@ void SHA1Update(context, data, len) /* * Add padding and return the message digest. */ -void SHA1Final(digest, context) - u_char digest[20]; - SHA1_CTX* context; +void +SHA1Final(u_char digest[20], SHA1_CTX *context) { u_int i; u_char finalcount[8]; diff --git a/src/lib/libc/hash/sha1hl.c b/src/lib/libc/hash/sha1hl.c index 75d65c1a..a8f3a732 100644 --- a/src/lib/libc/hash/sha1hl.c +++ b/src/lib/libc/hash/sha1hl.c @@ -8,7 +8,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: sha1hl.c,v 1.2 1999/08/17 09:13:12 millert Exp $"; +static char rcsid[] = "$OpenBSD: sha1hl.c,v 1.3 2002/12/23 04:33:31 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -22,31 +22,26 @@ static char rcsid[] = "$OpenBSD: sha1hl.c,v 1.2 1999/08/17 09:13:12 millert Exp /* ARGSUSED */ char * -SHA1End(ctx, buf) - SHA1_CTX *ctx; - char *buf; +SHA1End(SHA1_CTX *ctx, char *buf) { int i; - char *p = buf; u_char digest[20]; static const char hex[]="0123456789abcdef"; - if (p == NULL && (p = malloc(41)) == NULL) - return 0; + if (buf == NULL && (buf = malloc(41)) == NULL) + return(NULL); SHA1Final(digest,ctx); for (i = 0; i < 20; i++) { - p[i + i] = hex[digest[i] >> 4]; - p[i + i + 1] = hex[digest[i] & 0x0f]; + buf[i + i] = hex[digest[i] >> 4]; + buf[i + i + 1] = hex[digest[i] & 0x0f]; } - p[i + i] = '\0'; - return(p); + buf[i + i] = '\0'; + return(buf); } char * -SHA1File (filename, buf) - char *filename; - char *buf; +SHA1File (char *filename, char *buf) { u_char buffer[BUFSIZ]; SHA1_CTX ctx; @@ -67,10 +62,7 @@ SHA1File (filename, buf) } char * -SHA1Data (data, len, buf) - const u_char *data; - size_t len; - char *buf; +SHA1Data (const u_char *data, size_t len, char *buf) { SHA1_CTX ctx;