From 48b8a20cbe347a377bec362a172d521d9ffee15c Mon Sep 17 00:00:00 2001 From: mux Date: Mon, 24 Jun 2002 14:15:25 +0000 Subject: Bring sys/kern/md5c.c in sync with the userland version. Add a comment so that people don't forget to keep the version in src/lib/libmd/md5c.c in sync with this one. This fixes a warning on sparc64. Reviewed by: phk --- sys/kern/md5c.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'sys/kern/md5c.c') diff --git a/sys/kern/md5c.c b/sys/kern/md5c.c index 258996e..72c970b 100644 --- a/sys/kern/md5c.c +++ b/sys/kern/md5c.c @@ -22,12 +22,16 @@ * These notices must be retained in any copies of any part of this * documentation and/or software. * - * $FreeBSD$ - * * This code is the same as the code published by RSA Inc. It has been * edited for clarity and style only. */ +/* + * This file should be kept in sync with src/lib/libmd/md5c.c + */ +#include +__FBSDID("$FreeBSD$"); + #include #ifdef _KERNEL @@ -36,39 +40,35 @@ #include #endif +#include +#include #include +static void MD5Transform(u_int32_t [4], const unsigned char [64]); #ifdef _KERNEL #define memset(x,y,z) bzero(x,z); #define memcpy(x,y,z) bcopy(y, x, z) #endif -#if defined(__i386__) || defined(__alpha__) || defined(__ia64__) +#if (BYTE_ORDER == LITTLE_ENDIAN) #define Encode memcpy #define Decode memcpy -#else /* __i386__ */ +#else /* * Encodes input (u_int32_t) into output (unsigned char). Assumes len is * a multiple of 4. */ -/* XXX not prototyped, and not compatible with memcpy(). */ static void -Encode (output, input, len) - unsigned char *output; - u_int32_t *input; - unsigned int len; +Encode (unsigned char *output, u_int32_t *input, unsigned int len) { - unsigned int i, j; + unsigned int i; + u_int32_t *op = (u_int32_t *)output; - 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); - } + for (i = 0; i < len / 4; i++) + op[i] = htole32(input[i]); } /* @@ -77,18 +77,15 @@ Encode (output, input, len) */ static void -Decode (output, input, len) - u_int32_t *output; - const unsigned char *input; - unsigned int len; +Decode (u_int32_t *output, const unsigned char *input, unsigned int len) { - unsigned int i, j; + unsigned int i; + const u_int32_t *ip = (const u_int32_t *)input; - 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); + for (i = 0; i < len / 4; i++) + output[i] = le32toh(ip[i]); } -#endif /* i386 */ +#endif 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, @@ -235,7 +232,7 @@ MD5Final (digest, context) /* MD5 basic transformation. Transforms state based on block. */ -void +static void MD5Transform (state, block) u_int32_t state[4]; const unsigned char block[64]; -- cgit v1.1