diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-10-02 03:50:27 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-10-02 03:50:27 +0000 |
commit | 2d0181727eae9dd33e29514e34e5985fd08af1e5 (patch) | |
tree | a294735438c85c2e19ba1d12b68e434120e82b13 /lib/libc/md/md5c.c | |
parent | 3b4a19fe2a7ba832839e12ae75de1c5281a8c079 (diff) |
All the world is not a pc, BYTE_ORDER define.
Diffstat (limited to 'lib/libc/md/md5c.c')
-rw-r--r-- | lib/libc/md/md5c.c | 79 |
1 files changed, 43 insertions, 36 deletions
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) |