summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-12-23 04:33:32 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-12-23 04:33:32 +0000
commit240d00ccd27633050d6be0531a777f845b5b5440 (patch)
tree29cb992a046c08dd2cfb239776fcbb1a8c6be710
parent29b88a9674bfc30b4c7a4401f9169584b56e571a (diff)
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
-rw-r--r--include/md4.h6
-rw-r--r--include/md5.h6
-rw-r--r--include/rmd160.h6
-rw-r--r--include/sha1.h36
-rw-r--r--lib/libc/hash/rmd160.c34
-rw-r--r--lib/libc/hash/rmd160hl.c30
-rw-r--r--lib/libc/hash/sha1.c26
-rw-r--r--lib/libc/hash/sha1hl.c28
-rw-r--r--lib/libc/md/md4c.c184
-rw-r--r--lib/libc/md/md5c.c232
-rw-r--r--lib/libc/md/mdXhl.c34
11 files changed, 298 insertions, 324 deletions
diff --git a/include/md4.h b/include/md4.h
index 89cabf7436d..0bd4e4a5a08 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.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 <sys/cdefs.h>
+
+__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/include/md5.h b/include/md5.h
index 8190b176186..958340196eb 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.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 <sys/cdefs.h>
+
+__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/include/rmd160.h b/include/rmd160.h
index b950fd7f393..b31b07f6e87 100644
--- a/include/rmd160.h
+++ b/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 <sys/cdefs.h>
+
+__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/include/sha1.h b/include/sha1.h
index 58733f1632d..613a7140969 100644
--- a/include/sha1.h
+++ b/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 <sys/cdefs.h>
+
+__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/lib/libc/hash/rmd160.c b/lib/libc/hash/rmd160.c
index 2826a62727c..a8c6a409611 100644
--- a/lib/libc/hash/rmd160.c
+++ b/lib/libc/hash/rmd160.c
@@ -32,23 +32,23 @@
#include <rmd160.h>
#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/lib/libc/hash/rmd160hl.c b/lib/libc/hash/rmd160hl.c
index 06511336938..bf0060029be 100644
--- a/lib/libc/hash/rmd160hl.c
+++ b/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 <stdlib.h>
@@ -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/lib/libc/hash/sha1.c b/lib/libc/hash/sha1.c
index 7b11732e925..def87a5b6d9 100644
--- a/lib/libc/hash/sha1.c
+++ b/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 <sys/param.h>
@@ -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/lib/libc/hash/sha1hl.c b/lib/libc/hash/sha1hl.c
index 75d65c1a522..a8f3a732ca1 100644
--- a/lib/libc/hash/sha1hl.c
+++ b/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 <stdlib.h>
@@ -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;
diff --git a/lib/libc/md/md4c.c b/lib/libc/md/md4c.c
index bcfe702b421..968a3dfa815 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.13 2002/02/16 21:27:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: md4c.c,v 1.14 2002/12/23 04:33:31 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <string.h>
@@ -73,27 +73,27 @@ static unsigned char PADDING[64] = {
/* FF, GG and HH are transformations for rounds 1, 2 and 3 */
/* Rotation is separate from addition to prevent recomputation */
-#define FF(a, b, c, d, x, s) { \
- (a) += F ((b), (c), (d)) + (x); \
- (a) = ROTATE_LEFT ((a), (s)); \
- }
-#define GG(a, b, c, d, x, s) { \
- (a) += G ((b), (c), (d)) + (x) + (u_int32_t)0x5a827999; \
- (a) = ROTATE_LEFT ((a), (s)); \
- }
-#define HH(a, b, c, d, x, s) { \
- (a) += H ((b), (c), (d)) + (x) + (u_int32_t)0x6ed9eba1; \
- (a) = ROTATE_LEFT ((a), (s)); \
- }
+#define FF(a, b, c, d, x, s) do { \
+ (a) += F ((b), (c), (d)) + (x); \
+ (a) = ROTATE_LEFT((a), (s)); \
+} while (0)
+
+#define GG(a, b, c, d, x, s) do { \
+ (a) += G ((b), (c), (d)) + (x) + (u_int32_t)0x5a827999; \
+ (a) = ROTATE_LEFT((a), (s)); \
+} while (0)
+
+#define HH(a, b, c, d, x, s) do { \
+ (a) += H ((b), (c), (d)) + (x) + (u_int32_t)0x6ed9eba1; \
+ (a) = ROTATE_LEFT((a), (s)); \
+} while (0)
#if BYTE_ORDER != LITTLE_ENDIAN
/* Encodes input (u_int32_t) into output (unsigned char). Assumes len is
a multiple of 4.
*/
-static void Encode (out, in, len)
-void *out;
-const void *in;
-size_t len;
+static void
+Encode(void *out, const void *in, size_t len)
{
const u_int32_t *input = in;
unsigned char *output = out;
@@ -110,10 +110,8 @@ size_t len;
/* Decodes input (unsigned char) into output (u_int32_t). Assumes len is
a multiple of 4.
*/
-static void Decode (out, in, len)
-void *out;
-const void *in;
-size_t len;
+static void
+Decode(void *out, const void *in, size_t len)
{
u_int32_t *output = out;
const unsigned char *input = in;
@@ -127,8 +125,8 @@ size_t len;
/* MD4 initialization. Begins an MD4 operation, writing a new context.
*/
-void MD4Init (context)
-MD4_CTX *context; /* context */
+void
+MD4Init(MD4_CTX *context)
{
context->count = 0;
@@ -144,10 +142,8 @@ MD4_CTX *context; /* context */
operation, processing another message block, and updating the
context.
*/
-void MD4Update (context, input, inputLen)
-MD4_CTX *context; /* context */
-const unsigned char *input; /* input block */
-size_t inputLen; /* length of input block */
+void
+MD4Update(MD4_CTX *context, const unsigned char *input, size_t inputLen)
{
unsigned int i, index, partLen;
@@ -160,12 +156,11 @@ size_t inputLen; /* length of input block */
partLen = 64 - index;
/* Transform as many times as possible. */
if (inputLen >= partLen) {
- memcpy
- ((POINTER)&context->buffer[index], (POINTER)input, partLen);
- MD4Transform (context->state, context->buffer);
+ memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen);
+ MD4Transform(context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
- MD4Transform (context->state, &input[i]);
+ MD4Transform(context->state, &input[i]);
index = 0;
}
@@ -173,17 +168,14 @@ size_t inputLen; /* length of input block */
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);
}
/* MD4 finalization. Ends an MD4 message-digest operation, writing the
the message digest and zeroizing the context.
*/
-void MD4Final (digest, context)
-unsigned char digest[16]; /* message digest */
-MD4_CTX *context; /* context */
+void
+MD4Final(unsigned char digest[16], MD4_CTX *context)
{
unsigned char bits[8];
unsigned int index, padLen;
@@ -192,92 +184,90 @@ MD4_CTX *context; /* context */
/* Save number of bits */
hi = context->count >> 32;
lo = (u_int32_t)context->count & 0xffffffff;
- Encode (bits, &lo, 4);
- Encode (bits + 4, &hi, 4);
+ Encode(bits, &lo, 4);
+ Encode(bits + 4, &hi, 4);
/* Pad out to 56 mod 64.
*/
index = (unsigned int)((context->count >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
- MD4Update (context, PADDING, padLen);
+ MD4Update(context, PADDING, padLen);
/* Append length (before padding) */
- MD4Update (context, bits, 8);
+ MD4Update(context, bits, 8);
if (digest != NULL) {
/* Store state in digest */
- Encode (digest, context->state, 16);
+ Encode(digest, context->state, 16);
/* Zeroize sensitive information.
*/
- memset ((POINTER)context, 0, sizeof (*context));
+ memset((POINTER)context, 0, sizeof (*context));
}
}
/* MD4 basic transformation. Transforms state based on block.
*/
-void MD4Transform (state, block)
-u_int32_t state[4];
-const unsigned char block[64];
+void
+MD4Transform(u_int32_t state[4], const unsigned char block[64])
{
u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
- Decode (x, block, 64);
+ Decode(x, block, 64);
/* Round 1 */
- FF (a, b, c, d, x[ 0], S11); /* 1 */
- FF (d, a, b, c, x[ 1], S12); /* 2 */
- FF (c, d, a, b, x[ 2], S13); /* 3 */
- FF (b, c, d, a, x[ 3], S14); /* 4 */
- FF (a, b, c, d, x[ 4], S11); /* 5 */
- FF (d, a, b, c, x[ 5], S12); /* 6 */
- FF (c, d, a, b, x[ 6], S13); /* 7 */
- FF (b, c, d, a, x[ 7], S14); /* 8 */
- FF (a, b, c, d, x[ 8], S11); /* 9 */
- FF (d, a, b, c, x[ 9], S12); /* 10 */
- FF (c, d, a, b, x[10], S13); /* 11 */
- FF (b, c, d, a, x[11], S14); /* 12 */
- FF (a, b, c, d, x[12], S11); /* 13 */
- FF (d, a, b, c, x[13], S12); /* 14 */
- FF (c, d, a, b, x[14], S13); /* 15 */
- FF (b, c, d, a, x[15], S14); /* 16 */
+ FF(a, b, c, d, x[ 0], S11); /* 1 */
+ FF(d, a, b, c, x[ 1], S12); /* 2 */
+ FF(c, d, a, b, x[ 2], S13); /* 3 */
+ FF(b, c, d, a, x[ 3], S14); /* 4 */
+ FF(a, b, c, d, x[ 4], S11); /* 5 */
+ FF(d, a, b, c, x[ 5], S12); /* 6 */
+ FF(c, d, a, b, x[ 6], S13); /* 7 */
+ FF(b, c, d, a, x[ 7], S14); /* 8 */
+ FF(a, b, c, d, x[ 8], S11); /* 9 */
+ FF(d, a, b, c, x[ 9], S12); /* 10 */
+ FF(c, d, a, b, x[10], S13); /* 11 */
+ FF(b, c, d, a, x[11], S14); /* 12 */
+ FF(a, b, c, d, x[12], S11); /* 13 */
+ FF(d, a, b, c, x[13], S12); /* 14 */
+ FF(c, d, a, b, x[14], S13); /* 15 */
+ FF(b, c, d, a, x[15], S14); /* 16 */
/* Round 2 */
- GG (a, b, c, d, x[ 0], S21); /* 17 */
- GG (d, a, b, c, x[ 4], S22); /* 18 */
- GG (c, d, a, b, x[ 8], S23); /* 19 */
- GG (b, c, d, a, x[12], S24); /* 20 */
- GG (a, b, c, d, x[ 1], S21); /* 21 */
- GG (d, a, b, c, x[ 5], S22); /* 22 */
- GG (c, d, a, b, x[ 9], S23); /* 23 */
- GG (b, c, d, a, x[13], S24); /* 24 */
- GG (a, b, c, d, x[ 2], S21); /* 25 */
- GG (d, a, b, c, x[ 6], S22); /* 26 */
- GG (c, d, a, b, x[10], S23); /* 27 */
- GG (b, c, d, a, x[14], S24); /* 28 */
- GG (a, b, c, d, x[ 3], S21); /* 29 */
- GG (d, a, b, c, x[ 7], S22); /* 30 */
- GG (c, d, a, b, x[11], S23); /* 31 */
- GG (b, c, d, a, x[15], S24); /* 32 */
+ GG(a, b, c, d, x[ 0], S21); /* 17 */
+ GG(d, a, b, c, x[ 4], S22); /* 18 */
+ GG(c, d, a, b, x[ 8], S23); /* 19 */
+ GG(b, c, d, a, x[12], S24); /* 20 */
+ GG(a, b, c, d, x[ 1], S21); /* 21 */
+ GG(d, a, b, c, x[ 5], S22); /* 22 */
+ GG(c, d, a, b, x[ 9], S23); /* 23 */
+ GG(b, c, d, a, x[13], S24); /* 24 */
+ GG(a, b, c, d, x[ 2], S21); /* 25 */
+ GG(d, a, b, c, x[ 6], S22); /* 26 */
+ GG(c, d, a, b, x[10], S23); /* 27 */
+ GG(b, c, d, a, x[14], S24); /* 28 */
+ GG(a, b, c, d, x[ 3], S21); /* 29 */
+ GG(d, a, b, c, x[ 7], S22); /* 30 */
+ GG(c, d, a, b, x[11], S23); /* 31 */
+ GG(b, c, d, a, x[15], S24); /* 32 */
/* Round 3 */
- HH (a, b, c, d, x[ 0], S31); /* 33 */
- HH (d, a, b, c, x[ 8], S32); /* 34 */
- HH (c, d, a, b, x[ 4], S33); /* 35 */
- HH (b, c, d, a, x[12], S34); /* 36 */
- HH (a, b, c, d, x[ 2], S31); /* 37 */
- HH (d, a, b, c, x[10], S32); /* 38 */
- HH (c, d, a, b, x[ 6], S33); /* 39 */
- HH (b, c, d, a, x[14], S34); /* 40 */
- HH (a, b, c, d, x[ 1], S31); /* 41 */
- HH (d, a, b, c, x[ 9], S32); /* 42 */
- HH (c, d, a, b, x[ 5], S33); /* 43 */
- HH (b, c, d, a, x[13], S34); /* 44 */
- HH (a, b, c, d, x[ 3], S31); /* 45 */
- HH (d, a, b, c, x[11], S32); /* 46 */
- HH (c, d, a, b, x[ 7], S33); /* 47 */
- HH (b, c, d, a, x[15], S34); /* 48 */
-
+ HH(a, b, c, d, x[ 0], S31); /* 33 */
+ HH(d, a, b, c, x[ 8], S32); /* 34 */
+ HH(c, d, a, b, x[ 4], S33); /* 35 */
+ HH(b, c, d, a, x[12], S34); /* 36 */
+ HH(a, b, c, d, x[ 2], S31); /* 37 */
+ HH(d, a, b, c, x[10], S32); /* 38 */
+ HH(c, d, a, b, x[ 6], S33); /* 39 */
+ HH(b, c, d, a, x[14], S34); /* 40 */
+ HH(a, b, c, d, x[ 1], S31); /* 41 */
+ HH(d, a, b, c, x[ 9], S32); /* 42 */
+ HH(c, d, a, b, x[ 5], S33); /* 43 */
+ HH(b, c, d, a, x[13], S34); /* 44 */
+ HH(a, b, c, d, x[ 3], S31); /* 45 */
+ HH(d, a, b, c, x[11], S32); /* 46 */
+ HH(c, d, a, b, x[ 7], S33); /* 47 */
+ HH(b, c, d, a, x[15], S34); /* 48 */
state[0] += a;
state[1] += b;
state[2] += c;
@@ -285,5 +275,5 @@ const unsigned char block[64];
/* Zeroize sensitive information.
*/
- memset ((POINTER)x, 0, sizeof (x));
+ memset((POINTER)x, 0, sizeof (x));
}
diff --git a/lib/libc/md/md5c.c b/lib/libc/md/md5c.c
index a14c42d153c..563aec85146 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.13 2002/02/16 21:27:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: md5c.c,v 1.14 2002/12/23 04:33:31 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <string.h>
@@ -80,39 +80,40 @@ static unsigned char PADDING[64] = {
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/
-#define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
+#define FF(a, b, c, d, x, s, ac) do { \
+ (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
+ (a) = ROTATE_LEFT((a), (s)); \
+ (a) += (b); \
+} while (0)
+
+#define GG(a, b, c, d, x, s, ac) do { \
+ (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
+ (a) = ROTATE_LEFT((a), (s)); \
+ (a) += (b); \
+} while (0)
+
+#define HH(a, b, c, d, x, s, ac) do { \
+ (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
+ (a) = ROTATE_LEFT((a), (s)); \
+ (a) += (b); \
+} while (0)
+
+#define II(a, b, c, d, x, s, ac) do { \
+ (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
+ (a) = ROTATE_LEFT((a), (s)); \
+ (a) += (b); \
+} while (0)
#if BYTE_ORDER != LITTLE_ENDIAN
/* Encodes input (u_int32_t) into output (unsigned char). Assumes len is
a multiple of 4.
*/
-static void Encode (out, in, len)
-void *out;
-const void *in;
-size_t len;
+static void
+Encode(void *out, const void *in, size_t len)
{
unsigned char *output = out;
- size_t i, j;
const u_int32_t *input = in;
+ size_t i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char)(input[i] & 0xff);
@@ -125,14 +126,11 @@ size_t len;
/* Decodes input (unsigned char) into output (u_int32_t). Assumes len is
a multiple of 4.
*/
-static void Decode (out, in, len)
-void *out;
-const void *in;
-size_t len;
+static void
+Decode(u_int32_t *output, const u_char *input, size_t len)
{
u_int32_t *output = out;
const unsigned char *input = in;
- 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) |
@@ -142,8 +140,8 @@ size_t len;
/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
-void MD5Init (context)
-MD5_CTX *context; /* context */
+void
+MD5Init(MD5_CTX *context)
{
context->count = 0;
/* Load magic initialization constants. */
@@ -157,10 +155,8 @@ MD5_CTX *context; /* context */
operation, processing another message block, and updating the
context.
*/
-void MD5Update (context, input, inputLen)
-MD5_CTX *context; /* context */
-const unsigned char *input; /* input block */
-size_t inputLen; /* length of input block */
+void
+MD5Update(MD5_CTX *context, const u_char *input, size_t inputLen)
{
unsigned int i, index, partLen;
@@ -174,11 +170,11 @@ size_t inputLen; /* length of input block */
/* 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]);
+ MD5Transform(context->state, &input[i]);
index = 0;
}
@@ -186,15 +182,14 @@ size_t inputLen; /* length of input block */
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
the message digest and zeroizing the context.
*/
-void MD5Final (digest, context)
-unsigned char digest[16]; /* message digest */
-MD5_CTX *context; /* context */
+void
+MD5Final(u_char digest[16], MD5_CTX *context)
{
unsigned char bits[8];
unsigned int index;
@@ -204,107 +199,106 @@ MD5_CTX *context; /* context */
/* Save number of bits */
hi = context->count >> 32;
lo = (u_int32_t)context->count & 0xffffffff;
- Encode (bits, &lo, 4);
- Encode (bits + 4, &hi, 4);
+ Encode(bits, &lo, 4);
+ Encode(bits + 4, &hi, 4);
/* Pad out to 56 mod 64. */
index = (unsigned int)((context->count >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
- MD5Update (context, PADDING, padLen);
+ MD5Update(context, PADDING, padLen);
/* Append length (before padding) */
- MD5Update (context, bits, 8);
+ MD5Update(context, bits, 8);
if (digest != NULL) {
/* Store state in digest */
- Encode (digest, context->state, 16);
+ Encode(digest, context->state, 16);
/* Zeroize sensitive information. */
- memset ((POINTER)context, 0, sizeof (*context));
+ memset((POINTER)context, 0, sizeof (*context));
}
}
/* MD5 basic transformation. Transforms state based on block.
*/
-void MD5Transform (state, block)
-u_int32_t state[4];
-const unsigned char block[64];
+void
+MD5Transform(u_int32_t state[4], const u_char block[64])
{
u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
- Decode (x, block, 64);
+ Decode(x, block, 64);
/* Round 1 */
- FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
- FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
- FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
- FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
- FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
- FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
- FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
- FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
- FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
- FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
- FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
- FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
- FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
- FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
- FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
- FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+ FF(a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+ FF(d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+ FF(c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+ FF(b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+ FF(a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+ FF(d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+ FF(c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+ FF(b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+ FF(a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+ FF(d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+ FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
- GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
- GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
- GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
- GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
- GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
- GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
- GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
- GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
- GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
- GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
- GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
- GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
- GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
- GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
- GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
- GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+ GG(a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+ GG(d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+ GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG(b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+ GG(a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+ GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG(b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+ GG(a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+ GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG(c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+ GG(b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+ GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG(d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+ GG(c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+ GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
- HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
- HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
- HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
- HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
- HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
- HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
- HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
- HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
- HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
- HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
- HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
- HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
- HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
- HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
- HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
- HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+ HH(a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+ HH(d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+ HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH(a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+ HH(d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+ HH(c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+ HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH(d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+ HH(c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+ HH(b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
+ HH(a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+ HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH(b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
- II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
- II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
- II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
- II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
- II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
- II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
- II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
- II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
- II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
- II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
- II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
- II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
- II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
- II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
- II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
- II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+ II(a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+ II(d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+ II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II(b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+ II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II(d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+ II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II(b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+ II(a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+ II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II(c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+ II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II(a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+ II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II(c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+ II(b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
@@ -312,6 +306,6 @@ const unsigned char block[64];
state[3] += d;
/* Zeroize sensitive information. */
- memset ((POINTER)x, 0, sizeof (x));
+ memset((POINTER)x, 0, sizeof (x));
}
diff --git a/lib/libc/md/mdXhl.c b/lib/libc/md/mdXhl.c
index 3e0de52567c..ae2f7fe9441 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.9 1999/08/17 09:13:12 millert Exp $";
+static char rcsid[] = "$OpenBSD: mdXhl.c,v 1.10 2002/12/23 04:33:31 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
@@ -22,32 +22,25 @@ static char rcsid[] = "$OpenBSD: mdXhl.c,v 1.9 1999/08/17 09:13:12 millert Exp $
/* ARGSUSED */
char *
-MDXEnd(ctx, buf)
- MDX_CTX *ctx;
- char *buf;
+MDXEnd(MDX_CTX *ctx, char *buf)
{
int i;
- char *p = buf;
unsigned char digest[16];
static const char hex[]="0123456789abcdef";
- if (!p)
- p = malloc(33);
- if (!p)
- return 0;
+ if (buf == NULL && (buf = malloc(33)) == NULL)
+ return(NULL);
MDXFinal(digest,ctx);
for (i=0;i<16;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 *
-MDXFile (filename, buf)
- char *filename;
- char *buf;
+MDXFile(char *filename, char *buf)
{
unsigned char buffer[BUFSIZ];
MDX_CTX ctx;
@@ -63,18 +56,15 @@ MDXFile (filename, buf)
close(f);
errno = j;
if (i < 0) return 0;
- return MDXEnd(&ctx, buf);
+ return(MDXEnd(&ctx, buf));
}
char *
-MDXData (data, len, buf)
- const unsigned char *data;
- size_t len;
- char *buf;
+MDXData(const u_char *data, size_t len, char *buf)
{
MDX_CTX ctx;
MDXInit(&ctx);
MDXUpdate(&ctx,data,len);
- return MDXEnd(&ctx, buf);
+ return(MDXEnd(&ctx, buf));
}