about summary refs log tree commit diff
path: root/crypt/md5.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-07-04 18:24:11 +0000
committerUlrich Drepper <drepper@redhat.com>2000-07-04 18:24:11 +0000
commit3248e3a326e04320d0fdecba70be17d4f13bfb27 (patch)
tree3f9337c369fa74bc8f603cd715b53c0f42764f88 /crypt/md5.c
parent83b1b6d8faca6d279867c1c76f75e89786b76f4f (diff)
downloadglibc-3248e3a326e04320d0fdecba70be17d4f13bfb27.tar.gz
glibc-3248e3a326e04320d0fdecba70be17d4f13bfb27.tar.xz
glibc-3248e3a326e04320d0fdecba70be17d4f13bfb27.zip
Update.
2000-07-04  Ulrich Drepper  <drepper@redhat.com>

	* crypt/md5-crypt.c (__md5_crypt_r): If buffers for key and salt
	are not aligned to alignof(md5_uint32) do it before calling
	__md5_process_bytes.
	* crypt/md5.c: Make sure buffers are aligned.
	* crypt/md5.h: Likewise.
	Reported by Solar Designer <solar@false.com>.

	* crypt/Makefile: Add dependencies for test programs.

	* Rules: Define LC_ALL=C in environments of all programs we run.

	* intl/tst-gettext.sh (LC_ALL): Define to C and export.

2000-07-03  H.J. Lu  <hjl@gnu.org>

	* locale/programs/ld-ctype.c (ctype_output): The size of iov
	is 2 + elem + offset, not 2 + elem + offset + 2.

2000-07-04  Ulrich Drepper  <drepper@redhat.com>

	* posix/fnmatch_loop.c: Fix two problems uncovered by the new test
	suite.
	* posix/Makefile (tests): Add tst-fnmatch.
	(tst-fnmatch-ENV): Define.
	* posix/tst-fnmatch.c: New file.
	* posix/tst-fnmatch.sh: New file.
Diffstat (limited to 'crypt/md5.c')
-rw-r--r--crypt/md5.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/crypt/md5.c b/crypt/md5.c
index 478429f8e6..3879ad674c 100644
--- a/crypt/md5.c
+++ b/crypt/md5.c
@@ -1,6 +1,6 @@
-/* md5.c - Functions to compute MD5 message digest of files or memory blocks
+/* 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 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -217,6 +217,8 @@ md5_process_bytes (buffer, len, ctx)
      size_t len;
      struct md5_ctx *ctx;
 {
+  //const void aligned_buffer = buffer;
+
   /* When we already have some bits in our internal buffer concatenate
      both inputs first.  */
   if (ctx->buflen != 0)
@@ -224,16 +226,20 @@ md5_process_bytes (buffer, len, ctx)
       size_t left_over = ctx->buflen;
       size_t add = 128 - left_over > len ? len : 128 - left_over;
 
+      /* Only put full words in the buffer.  */
+      add -= add % __alignof__ (md5_uint32);
+
       memcpy (&ctx->buffer[left_over], buffer, add);
       ctx->buflen += add;
 
-      if (left_over + add > 64)
+      if (ctx->buflen > 64)
 	{
-	  md5_process_block (ctx->buffer, (left_over + add) & ~63, ctx);
+	  md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
+
+	  ctx->buflen &= 63;
 	  /* The regions in the following copy operation cannot overlap.  */
 	  memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
-		  (left_over + add) & 63);
-	  ctx->buflen = (left_over + add) & 63;
+		  ctx->buflen);
 	}
 
       buffer = (const char *) buffer + add;
@@ -251,8 +257,17 @@ md5_process_bytes (buffer, len, ctx)
   /* Move remaining bytes in internal buffer.  */
   if (len > 0)
     {
-      memcpy (ctx->buffer, buffer, len);
-      ctx->buflen = len;
+      size_t left_over = ctx->buflen;
+
+      memcpy (&ctx->buffer[left_over], buffer, len);
+      left_over += len;
+      if (left_over >= 64)
+	{
+	  md5_process_block (ctx->buffer, 64, ctx);
+	  left_over -= 64;
+	  memcpy (ctx->buffer, &ctx->buffer[64], left_over);
+	}
+      ctx->buflen = left_over;
     }
 }