diff options
-rw-r--r-- | lib/libc/md/md4c.c | 77 | ||||
-rw-r--r-- | lib/libc/md/md5c.c | 79 |
2 files changed, 85 insertions, 71 deletions
diff --git a/lib/libc/md/md4c.c b/lib/libc/md/md4c.c index 35f3b1ae27e..a65c0e8f15f 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.3 1996/09/29 14:55:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: md4c.c,v 1.4 1996/10/02 03:50:25 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <string.h> @@ -48,10 +48,16 @@ typedef unsigned char *POINTER; #define S34 15 static void MD4Transform __P ((u_int32_t [4], const unsigned char [64])); + +#if BYTE_ORDER == LITTLE_ENDIAN +#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)); +#endif /* LITTLE_ENDIAN */ static unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -84,6 +90,41 @@ static unsigned char PADDING[64] = { (a) = ROTATE_LEFT ((a), (s)); \ } +#if BYTE_ORDER != LITTLE_ENDIAN +/* Encodes input (u_int32_t) into output (unsigned char). Assumes len is + a multiple of 4. + */ +static void Encode (output, input, len) +unsigned char *output; +u_int32_t *input; +unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } +} + +/* Decodes input (unsigned char) into output (u_int32_t). Assumes len is + a multiple of 4. + */ +static void Decode (output, input, len) +u_int32_t *output; +const unsigned char *input; +unsigned int len; +{ + unsigned 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) | + (((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24); +} +#endif /* !LITTLE_ENDIAN */ + /* MD4 initialization. Begins an MD4 operation, writing a new context. */ void MD4Init (context) @@ -242,37 +283,3 @@ const unsigned char block[64]; */ memset ((POINTER)x, 0, sizeof (x)); } - -/* Encodes input (u_int32_t) into output (unsigned char). Assumes len is - a multiple of 4. - */ -static void Encode (output, input, len) -unsigned char *output; -u_int32_t *input; -unsigned int len; -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char)(input[i] & 0xff); - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); - } -} - -/* Decodes input (unsigned char) into output (u_int32_t). Assumes len is - a multiple of 4. - */ -static void Decode (output, input, len) - -u_int32_t *output; -const unsigned char *input; -unsigned int len; -{ - unsigned 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) | - (((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24); -} diff --git a/lib/libc/md/md5c.c b/lib/libc/md/md5c.c index dedb39d8ed0..01796477ca4 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.3 1996/09/29 14:55:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: md5c.c,v 1.4 1996/10/02 03:50:26 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <string.h> @@ -54,43 +54,15 @@ typedef unsigned char *POINTER; static void MD5Transform __P ((u_int32_t [4], const unsigned char [64])); -#ifdef i386 +#if BYTE_ORDER == LITTLE_ENDIAN #define Encode memcpy #define Decode memcpy -#else /* i386 */ -/* Encodes input (u_int32_t) into output (unsigned char). Assumes len is - a multiple of 4. - */ -static void Encode (output, input, len) -unsigned char *output; -u_int32_t *input; -unsigned int len; -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char)(input[i] & 0xff); - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); - } -} - -/* Decodes input (unsigned char) into output (u_int32_t). Assumes len is - a multiple of 4. - */ -static void Decode (output, input, len) -u_int32_t *output; -const unsigned char *input; -unsigned int len; -{ - unsigned 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) | - (((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24); -} -#endif /* i386 */ +#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)); +#endif /* LITTLE_ENDIAN */ static unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -133,6 +105,41 @@ Rotation is separate from addition to prevent recomputation. (a) += (b); \ } +#if BYTE_ORDER != LITTLE_ENDIAN +/* Encodes input (u_int32_t) into output (unsigned char). Assumes len is + a multiple of 4. + */ +static void Encode (output, input, len) +unsigned char *output; +u_int32_t *input; +unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } +} + +/* Decodes input (unsigned char) into output (u_int32_t). Assumes len is + a multiple of 4. + */ +static void Decode (output, input, len) +u_int32_t *output; +const unsigned char *input; +unsigned int len; +{ + unsigned 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) | + (((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24); +} +#endif /* !LITTLE_ENDIAN */ + /* MD5 initialization. Begins an MD5 operation, writing a new context. */ void MD5Init (context) |