Index: kern/md5c.c =================================================================== RCS file: /space/ncvs/src/sys/kern/md5c.c,v retrieving revision 1.18 diff -u -r1.18 md5c.c --- kern/md5c.c 29 Sep 2000 13:34:40 -0000 1.18 +++ kern/md5c.c 24 Jun 2002 13:50:15 -0000 @@ -22,12 +22,16 @@ * These notices must be retained in any copies of any part of this * documentation and/or software. * - * $FreeBSD: src/sys/kern/md5c.c,v 1.18 2000/09/29 13:34:40 dfr Exp $ - * * 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; -{ - 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); - } +Encode (unsigned char *output, u_int32_t *input, unsigned int len) +{ + unsigned int i; + u_int32_t *op = (u_int32_t *)output; + + for (i = 0; i < len / 4; i++) + op[i] = htole32(input[i]); } /* @@ -77,18 +77,15 @@ */ 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 @@ /* MD5 basic transformation. Transforms state based on block. */ -void +static void MD5Transform (state, block) u_int32_t state[4]; const unsigned char block[64]; Index: sys/md5.h =================================================================== RCS file: /space/ncvs/src/sys/sys/md5.h,v retrieving revision 1.15 diff -u -r1.15 md5.h --- sys/md5.h 19 Mar 2002 20:18:40 -0000 1.15 +++ sys/md5.h 24 Jun 2002 13:12:58 -0000 @@ -44,8 +44,5 @@ char * MD5File(const char *, char *); char * MD5FileChunk(const char *, char *, off_t, off_t); char * MD5Data(const unsigned char *, unsigned int, char *); -#ifdef _KERNEL -void MD5Transform(u_int32_t [4], const unsigned char [64]); -#endif __END_DECLS #endif /* _SYS_MD5_H_ */