Mercurial > hg > octave-lyh > gnulib-hg
changeset 9657:267c66b59eec
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.
* lib/md5.h: Doc fix.
author | Simon Josefsson <simon@josefsson.org> |
---|---|
date | Thu, 31 Jan 2008 11:05:46 +0100 |
parents | 9a9b67d137e3 |
children | b704008db267 |
files | ChangeLog lib/md5.c lib/md5.h |
diffstat | 3 files changed, 28 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-01-31 Simon Josefsson <simon@josefsson.org> + + * 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. + * lib/md5.h: Doc fix. + 2008-01-30 Peter Palfrader <weasel@debian.org> sha1: remove the result buffer alignment constraint
--- a/lib/md5.c +++ b/lib/md5.c @@ -1,6 +1,6 @@ /* Functions to compute MD5 message digest of files or memory blocks. according to the definition of MD5 in RFC 1321 from April 1992. - Copyright (C) 1995,1996,1997,1999,2000,2001,2005,2006 + Copyright (C) 1995,1996,1997,1999,2000,2001,2005,2006,2008 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -80,27 +80,31 @@ 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-bit value. */ +/* Put result from CTX in first 16 bytes following RESBUF. The result + must be in little endian byte order. */ void * md5_read_ctx (const struct md5_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-bit value. */ + prolog according to the standard and write the result to RESBUF. */ void * md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) {
--- a/lib/md5.h +++ b/lib/md5.h @@ -1,6 +1,6 @@ /* Declaration of functions and data types used for MD5 sum computing library functions. - Copyright (C) 1995-1997,1999,2000,2001,2004,2005,2006 + Copyright (C) 1995-1997,1999,2000,2001,2004,2005,2006,2008 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -93,19 +93,13 @@ /* 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, RESBUF must be aligned to a 32-bit - boundary. */ + ASCII representation of the message digest. */ extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW; /* 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, RESBUF must be aligned to a 32-bit - boundary. */ + to the wanted ASCII representation of the message digest. */ extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW;