summaryrefslogtreecommitdiff
path: root/lib/md5.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-09-12 22:05:15 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-09-12 22:05:15 +0000
commitdcbeca4acb90e463e4af5e12a44dfff2cd161fb9 (patch)
tree065a768a7250e59dde2d56370008e2df85fc39eb /lib/md5.c
parent35a32ee9550d22a932f1a71d89653e351405638d (diff)
downloadgnulib-dcbeca4acb90e463e4af5e12a44dfff2cd161fb9.tar.gz
Merge glibc and coreutils changes into gnulib, plus a few
extra fixes. * md5.c: Use #error rather than a string. (CYCLIC): New macro, from glibc source. Use it instead of rol. * md5.h (__GNUC_PREREQ, __THROW): Define if not defined already. (__attribute__): Define to empty for non recent-GCC. (__md5_buffer, __md5_finish_ctx, __md5_init_ctx, __md5_process_block): (__md5_process_bytes, __md5_read_ctx, __md5_stream): Renamed from their non-__ counterparts, with new macros replacing them if not _LIBC. Add __THROW attribute. (rol): Remove. (struct md5_ctx): Align buffer if using GCC. * sha1.h (struct sha1_ctx): Likewise. * sha1.c (SWAP): Renamed from the NOTSWAP. All uses changed. The old name was backwards. (NOTSWAP): Remove; not used. (rol): New macro, moved here from md5.h. (sha1_process_block): Remove a FIXME that doesn't make sense.
Diffstat (limited to 'lib/md5.c')
-rw-r--r--lib/md5.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/md5.c b/lib/md5.c
index 1646676f4f..87db8f956c 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -1,6 +1,6 @@
/* md5.c - 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, 2001, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 2001, 2003, 2004, 2005 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.
@@ -57,10 +57,8 @@
#endif
#define BLOCKSIZE 4096
-/* Ensure that BLOCKSIZE is a multiple of 64. */
#if BLOCKSIZE % 64 != 0
-/* FIXME-someday (soon?): use #error instead of this kludge. */
-"invalid BLOCKSIZE"
+# error "invalid BLOCKSIZE"
#endif
/* This array contains the bytes used to pad the buffer to the next
@@ -335,15 +333,22 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
{ \
a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \
++words; \
- a = rol (a, s); \
+ CYCLIC (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, or
+ T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
+
+ Here is an equivalent invocation using Perl:
+
perl -e 'foreach(1..64){printf "0x%08x\n", int (4294967296 * abs (sin $_))}'
*/
@@ -373,7 +378,7 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
do \
{ \
a += f (b, c, d) + correct_words[k] + T; \
- a = rol (a, s); \
+ CYCLIC (a, s); \
a += b; \
} \
while (0)