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
This commit is contained in:
Maxime Henrion 2002-06-24 14:15:25 +00:00
parent 265056cbaa
commit 0ae037eb45

View File

@ -22,12 +22,16 @@
* These notices must be retained in any copies of any part of this * These notices must be retained in any copies of any part of this
* documentation and/or software. * documentation and/or software.
* *
* $FreeBSD$
*
* This code is the same as the code published by RSA Inc. It has been * This code is the same as the code published by RSA Inc. It has been
* edited for clarity and style only. * edited for clarity and style only.
*/ */
/*
* This file should be kept in sync with src/lib/libmd/md5c.c
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/types.h> #include <sys/types.h>
#ifdef _KERNEL #ifdef _KERNEL
@ -36,39 +40,35 @@
#include <string.h> #include <string.h>
#endif #endif
#include <machine/endian.h>
#include <sys/endian.h>
#include <sys/md5.h> #include <sys/md5.h>
static void MD5Transform(u_int32_t [4], const unsigned char [64]);
#ifdef _KERNEL #ifdef _KERNEL
#define memset(x,y,z) bzero(x,z); #define memset(x,y,z) bzero(x,z);
#define memcpy(x,y,z) bcopy(y, x, z) #define memcpy(x,y,z) bcopy(y, x, z)
#endif #endif
#if defined(__i386__) || defined(__alpha__) || defined(__ia64__) #if (BYTE_ORDER == LITTLE_ENDIAN)
#define Encode memcpy #define Encode memcpy
#define Decode memcpy #define Decode memcpy
#else /* __i386__ */ #else
/* /*
* Encodes input (u_int32_t) into output (unsigned char). Assumes len is * Encodes input (u_int32_t) into output (unsigned char). Assumes len is
* a multiple of 4. * a multiple of 4.
*/ */
/* XXX not prototyped, and not compatible with memcpy(). */
static void static void
Encode (output, input, len) Encode (unsigned char *output, u_int32_t *input, unsigned int len)
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) { for (i = 0; i < len / 4; i++)
output[j] = (unsigned char)(input[i] & 0xff); op[i] = htole32(input[i]);
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);
}
} }
/* /*
@ -77,18 +77,15 @@ Encode (output, input, len)
*/ */
static void static void
Decode (output, input, len) Decode (u_int32_t *output, const unsigned char *input, unsigned int len)
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) for (i = 0; i < len / 4; i++)
output[i] = ((u_int32_t)input[j]) | (((u_int32_t)input[j+1]) << 8) | output[i] = le32toh(ip[i]);
(((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24);
} }
#endif /* i386 */ #endif
static unsigned char PADDING[64] = { 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, 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. */ /* MD5 basic transformation. Transforms state based on block. */
void static void
MD5Transform (state, block) MD5Transform (state, block)
u_int32_t state[4]; u_int32_t state[4];
const unsigned char block[64]; const unsigned char block[64];