Minor 64bit processor update

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22484 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-02-13 14:28:48 +00:00
parent 92eb512dc6
commit 046ac98e6c
2 changed files with 33 additions and 19 deletions

View file

@ -1,3 +1,7 @@
2006-02-13 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSCategories.m: Fix MD5 digest for 64bit CPU
2006-02-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSIndexPath.m: new

View file

@ -227,15 +227,15 @@
struct MD5Context
{
unsigned long buf[4];
unsigned long bits[2];
unsigned char in[64];
uint32_t buf[4];
uint32_t bits[2];
uint8_t in[64];
};
static void MD5Init (struct MD5Context *context);
static void MD5Update (struct MD5Context *context, unsigned char const *buf,
unsigned len);
static void MD5Final (unsigned char digest[16], struct MD5Context *context);
static void MD5Transform (unsigned long buf[4], unsigned long const in[16]);
static void MD5Transform (uint32_t buf[4], uint32_t const in[16]);
/*
* This code implements the MD5 message-digest algorithm.
@ -257,15 +257,25 @@ static void MD5Transform (unsigned long buf[4], unsigned long const in[16]);
/*
* Ensure data is little-endian
*/
static void littleEndian (void *buf, unsigned longs)
static void littleEndian (void *buf, unsigned words)
{
unsigned long *ptr = (unsigned long*)buf;
uint32_t *ptr = (uint32_t*)buf;
#if (INT_MAX == 2147483647)
do
{
*ptr = NSSwapHostIntToLittle(*ptr);
ptr++;
}
while (--words);
#else
do
{
*ptr = NSSwapHostLongToLittle(*ptr);
ptr++;
}
while (--longs);
while (--words);
#endif
}
/*
@ -290,12 +300,12 @@ static void MD5Init (struct MD5Context *ctx)
static void MD5Update (struct MD5Context *ctx, unsigned char const *buf,
unsigned len)
{
unsigned long t;
uint32_t t;
/* Update bitcount */
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((unsigned long) len << 3)) < t)
if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
@ -315,7 +325,7 @@ static void MD5Update (struct MD5Context *ctx, unsigned char const *buf,
}
memcpy (p, buf, t);
littleEndian (ctx->in, 16);
MD5Transform (ctx->buf, (unsigned long *) ctx->in);
MD5Transform (ctx->buf, (uint32_t *) ctx->in);
buf += t;
len -= t;
}
@ -325,7 +335,7 @@ static void MD5Update (struct MD5Context *ctx, unsigned char const *buf,
{
memcpy (ctx->in, buf, 64);
littleEndian (ctx->in, 16);
MD5Transform (ctx->buf, (unsigned long *) ctx->in);
MD5Transform (ctx->buf, (uint32_t *) ctx->in);
buf += 64;
len -= 64;
}
@ -361,7 +371,7 @@ static void MD5Final (unsigned char digest[16], struct MD5Context *ctx)
/* Two lots of padding: Pad the first block to 64 bytes */
memset (p, 0, count);
littleEndian (ctx->in, 16);
MD5Transform (ctx->buf, (unsigned long *) ctx->in);
MD5Transform (ctx->buf, (uint32_t *) ctx->in);
/* Now fill the next block with 56 bytes */
memset (ctx->in, 0, 56);
@ -374,10 +384,10 @@ static void MD5Final (unsigned char digest[16], struct MD5Context *ctx)
littleEndian (ctx->in, 14);
/* Append length in bits and transform */
((unsigned long *) ctx->in)[14] = ctx->bits[0];
((unsigned long *) ctx->in)[15] = ctx->bits[1];
((uint32_t *) ctx->in)[14] = ctx->bits[0];
((uint32_t *) ctx->in)[15] = ctx->bits[1];
MD5Transform (ctx->buf, (unsigned long *) ctx->in);
MD5Transform (ctx->buf, (uint32_t *) ctx->in);
littleEndian ((unsigned char *) ctx->buf, 4);
memcpy (digest, ctx->buf, 16);
memset (ctx, 0, sizeof (ctx)); /* In case it's sensitive */
@ -397,12 +407,12 @@ static void MD5Final (unsigned char digest[16], struct MD5Context *ctx)
/*
* The core of the MD5 algorithm, this alters an existing MD5 hash to
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
* reflect the addition of 16 43bit words of new data. MD5Update blocks
* the data and converts bytes into 43bit words for this routine.
*/
static void MD5Transform (unsigned long buf[4], unsigned long const in[16])
static void MD5Transform (uint32_t buf[4], uint32_t const in[16])
{
register unsigned long a, b, c, d;
register uint32_t a, b, c, d;
a = buf[0];
b = buf[1];