From: Simon Josefsson Date: Thu, 31 Jan 2008 10:08:05 +0000 (+0100) Subject: md4: adapt alignment constraint fix from sha1. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b618722db56d8e66d8bff53a27a6c4f804e04d69;p=pspp md4: adapt alignment constraint fix from sha1. * lib/md4.c (set_uint32): New function, from sha1.c (md4_read_ctx): Use it. (md4_finish_ctx): Doc fix. * lib/md4.h: Doc fix. --- diff --git a/ChangeLog b/ChangeLog index 2ac44843b1..c11f9eedc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ 2008-01-31 Simon Josefsson - * md5: adapt alignment constraint fix from sha1. + md4: adapt alignment constraint fix from sha1. + * lib/md4.c (set_uint32): New function, from sha1.c + (md4_read_ctx): Use it. + (md4_finish_ctx): Doc fix. + * lib/md4.h: Doc fix. + +2008-01-31 Simon Josefsson + + md5: adapt alignment constraint fix from sha1. * lib/md5.c (set_uint32): New function, from sha1.c (md5_read_ctx): Use it. (md5_finish_ctx): Doc fix. diff --git a/lib/md4.c b/lib/md4.c index 789cce0d0d..daedaf520b 100644 --- a/lib/md4.c +++ b/lib/md4.c @@ -1,6 +1,6 @@ /* Functions to compute MD4 message digest of files or memory blocks. according to the definition of MD4 in RFC 1320 from April 1992. - Copyright (C) 1995,1996,1997,1999,2000,2001,2002,2003,2005,2006 + Copyright (C) 1995,1996,1997,1999,2000,2001,2002,2003,2005,2006,2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it @@ -64,27 +64,31 @@ md4_init_ctx (struct md4_ctx *ctx) ctx->buflen = 0; } -/* Put result from CTX in first 16 bytes following RESBUF. The result - must be in little endian byte order. +/* Copy the 4 byte value from v into the memory location pointed to by *cp, + If your architecture allows unaligned access this is equivalent to + * (uint32_t *) cp = v */ +static void +set_uint32 (char *cp, uint32_t v) +{ + memcpy (cp, &v, 4); +} - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32 bits value. */ +/* Put result from CTX in first 16 bytes following RESBUF. The result + must be in little endian byte order. */ void * md4_read_ctx (const struct md4_ctx *ctx, void *resbuf) { - ((uint32_t *) resbuf)[0] = SWAP (ctx->A); - ((uint32_t *) resbuf)[1] = SWAP (ctx->B); - ((uint32_t *) resbuf)[2] = SWAP (ctx->C); - ((uint32_t *) resbuf)[3] = SWAP (ctx->D); + char *r = resbuf; + set_uint32 (r + 0*4, SWAP (ctx->A)); + set_uint32 (r + 1*4, SWAP (ctx->B)); + set_uint32 (r + 2*4, SWAP (ctx->C)); + set_uint32 (r + 3*4, SWAP (ctx->D)); return resbuf; } /* Process the remaining bytes in the internal buffer and the usual - prolog according to the standard and write the result to RESBUF. - - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32 bits value. */ + prolog according to the standard and write the result to RESBUF. */ void * md4_finish_ctx (struct md4_ctx *ctx, void *resbuf) { diff --git a/lib/md4.h b/lib/md4.h index 0a54307b4a..937794c3c0 100644 --- a/lib/md4.h +++ b/lib/md4.h @@ -1,6 +1,6 @@ /* Declarations of functions and data types used for MD4 sum library functions. - Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2003, 2005, 2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -58,19 +58,13 @@ extern void md4_process_bytes (const void *buffer, size_t len, /* Process the remaining bytes in the buffer and put result from CTX in first 16 bytes following RESBUF. The result is always in little endian byte order, so that a byte-wise output yields to the wanted - ASCII representation of the message digest. - - IMPORTANT: On some systems it is required that RESBUF be correctly - aligned for a 32 bits value. */ + ASCII representation of the message digest. */ extern void *md4_finish_ctx (struct md4_ctx *ctx, void *resbuf); /* Put result from CTX in first 16 bytes following RESBUF. The result is always in little endian byte order, so that a byte-wise output yields - to the wanted ASCII representation of the message digest. - - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32 bits value. */ + to the wanted ASCII representation of the message digest. */ extern void *md4_read_ctx (const struct md4_ctx *ctx, void *resbuf);