* src/base/md5.c, src/base/md5.h: Updated to recent version.

* src/base/ftobjs.c: Updated; `md5.c' no longer uses `free'.
This commit is contained in:
Werner Lemberg 2013-10-22 01:10:10 +02:00
parent 75efc2d0bd
commit 604838d5ba
4 changed files with 33 additions and 28 deletions

View File

@ -1,3 +1,9 @@
2013-10-22 Werner Lemberg <wl@gnu.org>
* src/base/md5.c, src/base/md5.h: Updated to recent version.
* src/base/ftobjs.c: Updated; `md5.c' no longer uses `free'.
2013-10-19 Werner Lemberg <wl@gnu.org>
[autofit] s/SMALL_TOP/X_HEIGHT/.

View File

@ -56,9 +56,7 @@
#endif /* _MSC_VER */
/* it's easiest to include `md5.c' directly */
#define free md5_free /* suppress a shadow warning */
#include "md5.c"
#undef free
#if defined( _MSC_VER )
#pragma warning( pop )

View File

@ -50,7 +50,8 @@
*/
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define H(x, y, z) (((x) ^ (y)) ^ (z))
#define H2(x, y, z) ((x) ^ ((y) ^ (z)))
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
/*
@ -89,13 +90,13 @@
* This processes one or more 64-byte data blocks, but does NOT update
* the bit counters. There are no alignment requirements.
*/
static void *body(MD5_CTX *ctx, void *data, unsigned long size)
static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
{
unsigned char *ptr;
const unsigned char *ptr;
MD5_u32plus a, b, c, d;
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
ptr = (unsigned char *)data;
ptr = (const unsigned char *)data;
a = ctx->a;
b = ctx->b;
@ -146,21 +147,21 @@ static void *body(MD5_CTX *ctx, void *data, unsigned long size)
/* Round 3 */
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
/* Round 4 */
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
@ -207,10 +208,10 @@ void MD5_Init(MD5_CTX *ctx)
ctx->hi = 0;
}
void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
{
MD5_u32plus saved_lo;
unsigned long used, free;
unsigned long used, available;
saved_lo = ctx->lo;
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
@ -220,16 +221,16 @@ void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
used = saved_lo & 0x3f;
if (used) {
free = 64 - used;
available = 64 - used;
if (size < free) {
if (size < available) {
memcpy(&ctx->buffer[used], data, size);
return;
}
memcpy(&ctx->buffer[used], data, free);
data = (unsigned char *)data + free;
size -= free;
memcpy(&ctx->buffer[used], data, available);
data = (const unsigned char *)data + available;
size -= available;
body(ctx, ctx->buffer, 64);
}
@ -243,22 +244,22 @@ void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
{
unsigned long used, free;
unsigned long used, available;
used = ctx->lo & 0x3f;
ctx->buffer[used++] = 0x80;
free = 64 - used;
available = 64 - used;
if (free < 8) {
memset(&ctx->buffer[used], 0, free);
if (available < 8) {
memset(&ctx->buffer[used], 0, available);
body(ctx, ctx->buffer, 64);
used = 0;
free = 64;
available = 64;
}
memset(&ctx->buffer[used], 0, free - 8);
memset(&ctx->buffer[used], 0, available - 8);
ctx->lo <<= 3;
ctx->buffer[56] = ctx->lo;

View File

@ -39,7 +39,7 @@ typedef struct {
} MD5_CTX;
extern void MD5_Init(MD5_CTX *ctx);
extern void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size);
extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
#endif