X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmd5.c;h=1908fa820e7513fab8e9ac9a2ea54f64f4fa8042;hb=c57b0256714cb35dcef48b8bc41814ce326d8127;hp=1e988936a480d2bf18f0f9852701381da2169ad4;hpb=0151a413ed4a6045a9d749b03f455fc6873e6fbb;p=gnulib.git diff --git a/lib/md5.c b/lib/md5.c index 1e988936a..1908fa820 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -1,24 +1,24 @@ /* md5.c - Functions to compute MD5 message digest of files or memory blocks -Copyright (C) 1996 Free Software Foundation, Inc. -This file is part of the GNU C Library. -Contributed by Ulrich Drepper , 1996. + according to the definition of MD5 in RFC 1321 from April 1992. + Copyright (C) 1995, 1996 Free Software Foundation, Inc. + NOTE: The canonical source of this file is maintained with the GNU C + Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. + 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 + Free Software Foundation; either version 2, or (at your option) any + later version. -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* Written by Ulrich Drepper . */ +/* Written by Ulrich Drepper , 1995. */ #ifdef HAVE_CONFIG_H # include @@ -72,8 +72,11 @@ md5_init_ctx (ctx) ctx->buflen = 0; } -/* Put result from CTX in first 16 bytes following RESBUF. The result must - be in little endian byte order. */ +/* Put result from CTX in first 16 bytes following RESBUF. The result + must be in little endian byte order. + + IMPORTANT: On some systems it is required that RESBUF is correctly + aligned for a 32 bits value. */ void * md5_read_ctx (ctx, resbuf) const struct md5_ctx *ctx; @@ -88,7 +91,10 @@ md5_read_ctx (ctx, resbuf) } /* Process the remaining bytes in the internal buffer and the usual - prolog according to the standard and write the result to RESBUF. */ + 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. */ void * md5_finish_ctx (ctx, resbuf) struct md5_ctx *ctx; @@ -221,7 +227,7 @@ md5_process_bytes (buffer, len, ctx) ctx->buflen = (left_over + add) & 63; } - buffer += add; + buffer = (const char *) buffer + add; len -= add; } @@ -229,7 +235,7 @@ md5_process_bytes (buffer, len, ctx) if (len > 64) { md5_process_block (buffer, len & ~63, ctx); - buffer += len & ~63; + buffer = (const char *) buffer + (len & ~63); len &= 63; } @@ -298,19 +304,16 @@ md5_process_block (buffer, len, ctx) { \ a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \ ++words; \ - CYCLIC (a, s); \ + a = rol (a, s); \ a += b; \ } \ while (0) - /* It is unfortunate that C does not provide an operator for - cyclic rotation. Hope the C compiler is smart enough. */ -#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s))) - /* Before we start, one word to the strange constants. They are defined in RFC 1321 as - T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 + T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64, or + perl -e 'foreach(1..64){printf "0x%08x\n", int (4294967296 * abs (sin $_))}' */ /* Round 1. */ @@ -339,7 +342,7 @@ md5_process_block (buffer, len, ctx) do \ { \ a += f (b, c, d) + correct_words[k] + T; \ - CYCLIC (a, s); \ + a = rol (a, s); \ a += b; \ } \ while (0)