This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [BZ #14090] Fix md5/sha512 with large block sizes


On 07/26/2012 10:52 PM, Roland McGrath wrote:
It must be possible to produce a test program that demonstrates the problem
using only the md5 engine itself, like md5test.c does.  Can you try to
reduce the test program to something we can use?

I simplified the test and now it tests up to 10 GB (error starts with sizes >= 8 GB) which means an mmap of 10 GB and RSS of up to 400 MB. But the md5 calculation is rather slow, so it takes on my fast machine nearly a minute.

Should we run this as part of make check - or add it to xcheck
instead?

Andreas

2012-07-27 Andreas Jaeger <aj@suse.de>

	[BZ #14090]
	* crypt/md5test2.c: New test, based on test supplied by Serge
	Belyshev <belyshev@depni.sinp.msu.ru>.
	* crypt/Makefile (tests): Add md5test2.

diff --git a/crypt/Makefile b/crypt/Makefile
index d276092..b87c103 100644
--- a/crypt/Makefile
+++ b/crypt/Makefile
@@ -28,7 +28,7 @@ extra-libs-others := $(extra-libs)
libcrypt-routines := crypt-entry md5-crypt sha256-crypt sha512-crypt crypt \
crypt_util


-tests := cert md5c-test sha256c-test sha512c-test
+tests := cert md5c-test md5test2 sha256c-test sha512c-test

include ../Makeconfig

@@ -47,12 +47,14 @@ libcrypt-routines += md5 sha256 sha512
 tests += md5test sha256test sha512test

 $(objpfx)md5test: $(objpfx)md5.o
+$(objpfx)md5test2: $(objpfx)md5.o
 $(objpfx)sha256test: $(objpfx)sha256.o
 $(objpfx)sha512test: $(objpfx)sha512.o
 endif

include ../Rules

+
 ifeq (yes,$(build-shared))
 $(addprefix $(objpfx),$(tests)): $(objpfx)libcrypt.so
 else
diff --git a/crypt/md5test2.c b/crypt/md5test2.c
new file mode 100644
index 0000000..925cc18
--- /dev/null
+++ b/crypt/md5test2.c
@@ -0,0 +1,106 @@
+/* Testcase for http://sourceware.org/bugzilla/show_bug.cgi?id=14090.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+
+#include "md5.h"
+
+#define CONST_2G  0x080000000
+#define CONST_10G 0x280000000
+
+// MD5 sum values of zero-filled blocks of specified sizes.
+static struct test_data_s
+{
+  const char ref [16];
+  size_t len;
+} test_data [] =
+  {
+    { "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e",
+      0x000000000 },
+    { "\xa9\x81\x13\x0c\xf2\xb7\xe0\x9f\x46\x86\xdc\x27\x3c\xf7\x18\x7e",
+      0x080000000 },
+    { "\xc9\xa5\xa6\x87\x8d\x97\xb4\x8c\xc9\x65\xc1\xe4\x18\x59\xf0\x34",
+      0x100000000 },
+    { "\x58\xcf\x63\x8a\x73\x3f\x91\x90\x07\xb4\x28\x7c\xf5\x39\x6d\x0c",
+      0x180000000 },
+    { "\xb7\x70\x35\x1f\xad\xae\x5a\x96\xbb\xaf\x97\x02\xed\x97\xd2\x8d",
+      0x200000000 },
+    { "\x2d\xd2\x6c\x4d\x47\x99\xeb\xd2\x9f\xa3\x1e\x48\xd4\x9e\x8e\x53",
+      0x280000000 },
+};
+
+static
+int report (const char *id, const char *md5, size_t len, const char *ref)
+{
+  if (memcmp (md5, ref, 16))
+    {
+      printf ("test %s with size %zd failed\n", id, len);
+      return 1;
+    }
+  return 0;
+}
+
+/* test md5 in a single md5_process_bytes call.  */
+static int
+test_single (void *buf, size_t len, const char *ref)
+{
+  char sum [16];
+  struct md5_ctx ctx;
+
+  __md5_init_ctx (&ctx);
+  __md5_process_bytes (buf, len, &ctx);
+  __md5_finish_ctx (&ctx, sum);
+
+  return report ("single", sum, len, ref);
+}
+
+/* test md5 with two md5_process_bytes calls to trigger a
+   different path in md5_process_block for sizes > 2 GB.  */
+static int
+test_double (void *buf, size_t len, const char *ref)
+{
+  char sum [16];
+  struct md5_ctx ctx;
+
+  __md5_init_ctx (&ctx);
+  if (len >= CONST_2G)
+    {
+      __md5_process_bytes (buf, CONST_2G, &ctx);
+      __md5_process_bytes (buf + CONST_2G, len - CONST_2G, &ctx);
+    }
+  else
+      __md5_process_bytes (buf, len, &ctx);
+
+  __md5_finish_ctx (&ctx, sum);
+
+  return report ("double", sum, len, ref);
+}
+
+static int
+do_test (void)
+{
+  void *buf;
+  unsigned j;
+  int result = 0;
+
+  buf = mmap (0, CONST_10G, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  if (!buf)
+    {
+      puts ("Could not allocate 10 GB via mmap, skipping test.\n");
+      return 0;
+    }
+
+  for (j = 0; j < sizeof (test_data) / sizeof (struct test_data_s); j ++)
+    {
+      result += test_single (buf, test_data [j].len, test_data [j].ref);
+      result += test_double (buf, test_data [j].len, test_data [j].ref);
+    }
+
+  return result;
+}
+
+#define TIMEOUT 120
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"

--
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]