summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoland McGrath <[email protected]>2011-07-09 03:17:24 -0700
committerRoland McGrath <[email protected]>2011-07-09 03:17:24 -0700
commit32899ac4f69d4ca4856d5282464c1f9cee928c8a (patch)
tree2b45a22f79f4f3464150d5eba73a89ecab0cee22 /tests
parent02a958bc2662c1c9c2d6b663742b9c8e720e25b2 (diff)
Clean up byte order handling in md5 and sha1 code.
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog10
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/md5-sha1-test.c109
-rw-r--r--tests/sha1-tst.c79
4 files changed, 123 insertions, 83 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index e92b3441..507ac2bc 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,13 @@
+2011-07-09 Roland McGrath <[email protected]>
+
+ * sha1-tst.c: File removed.
+ * Makefile.am (noinst_PROGRAMS, TESTS): Remove it.
+ (sha1_tst_LDADD): Variable removed.
+
+ * md5-sha1-test.c: New file.
+ * Makefile.am [!STANDALONE] (noinst_PROGRAMS, TESTS): Add it.
+ (md5_sha1_test_LDADD): New variable.
+
2011-05-30 Mark Wielaard <[email protected]>
* Makefile.am (EXTRA_DIST): Add run-readelf-twofiles.sh and
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 552942dc..3074c893 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -58,7 +58,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
dwfl-addr-sect dwfl-bug-report early-offscn \
dwfl-bug-getmodules dwarf-getmacros addrcfi \
test-flag-nobits dwarf-getstring rerequest_tag \
- alldts
+ alldts md5-sha1-test
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -90,8 +90,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
# run-show-ciefde.sh
if !STANDALONE
-noinst_PROGRAMS += msg_tst sha1-tst
-TESTS += msg_tst sha1-tst
+noinst_PROGRAMS += msg_tst md5-sha1-test
+TESTS += msg_tst md5-sha1-test
endif
if HAVE_LIBASM
@@ -251,13 +251,13 @@ dwfl_bug_fd_leak_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
dwfl_bug_report_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
dwfl_bug_getmodules_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
dwfl_addr_sect_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
-sha1_tst_LDADD = $(libeu) $(libmudflap)
dwarf_getmacros_LDADD = $(libdw) $(libmudflap)
dwarf_getstring_LDADD = $(libdw) $(libmudflap)
addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
test_flag_nobits_LDADD = $(libelf) $(libmudflap)
rerequest_tag_LDADD = $(libdw) $(libmudflap)
alldts_LDADD = $(libebl) $(libelf) $(libmudflap)
+md5_sha1_test_LDADD = $(libeu)
if GCOV
check: check-am coverage
diff --git a/tests/md5-sha1-test.c b/tests/md5-sha1-test.c
new file mode 100644
index 00000000..af2e80a2
--- /dev/null
+++ b/tests/md5-sha1-test.c
@@ -0,0 +1,109 @@
+/* Copyright (C) 2011 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+
+ Red Hat elfutils 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; version 2 of the License.
+
+ Red Hat elfutils 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 General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <error.h>
+
+#include "md5.h"
+#include "sha1.h"
+
+static const struct expected
+{
+ const char *sample;
+ const char *md5_expected;
+ const char *sha1_expected;
+} tests[] =
+ {
+ {
+ "abc",
+ "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72",
+ "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e"
+ "\x25\x71\x78\x50\xc2\x6c\x9c\xd0\xd8\x9d"
+ },
+ {
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "\x82\x15\xef\x07\x96\xa2\x0b\xca\xaa\xe1\x16\xd3\x87\x6c\x66\x4a",
+ "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e\xba\xae"
+ "\x4a\xa1\xf9\x51\x29\xe5\xe5\x46\x70\xf1"
+ },
+ {
+ "\0a",
+ "\x77\x07\xd6\xae\x4e\x02\x7c\x70\xee\xa2\xa9\x35\xc2\x29\x6f\x21",
+ "\x34\xaa\x97\x3c\xd4\xc4\xda\xa4\xf6\x1e"
+ "\xeb\x2b\xdb\xad\x27\x31\x65\x34\x01\x6f",
+ },
+ {
+ "When in the Course of human events it becomes necessary",
+ "\x62\x6b\x5e\x22\xcd\x3d\x02\xea\x07\xde\xd4\x50\x62\x3d\xb9\x96",
+ "\x66\xc3\xc6\x8d\x62\x91\xc5\x1e\x63\x0c"
+ "\x85\xc8\x6c\xc4\x4b\x3a\x79\x3e\x07\x28",
+ },
+ };
+#define NTESTS (sizeof tests / sizeof tests[0])
+
+#define md5_size 16
+#define sha1_size 20
+
+static const char md5_expected[] =
+ {
+ };
+
+static const char sha1_expected[] =
+ {
+ };
+
+#define TEST_HASH(ALGO, I) \
+ { \
+ struct ALGO##_ctx ctx; \
+ uint32_t result_buffer[(ALGO##_size + 3) / 4]; \
+ ALGO##_init_ctx (&ctx); \
+ if (tests[I].sample[0] == '\0') \
+ { \
+ char input_buffer[1000]; \
+ memset (input_buffer, tests[I].sample[1], sizeof input_buffer); \
+ for (int rept = 0; rept < 1000; ++rept) \
+ ALGO##_process_bytes (input_buffer, sizeof input_buffer, &ctx); \
+ } \
+ else \
+ ALGO##_process_bytes (tests[I].sample, strlen (tests[I].sample), &ctx); \
+ char *result = ALGO##_finish_ctx (&ctx, result_buffer); \
+ if (result != (void *) result_buffer \
+ || memcmp (result, tests[I].ALGO##_expected, ALGO##_size) != 0) \
+ error (0, 0, #ALGO " test %zu failed", 1 + I); \
+ }
+
+int
+main (void)
+{
+ for (size_t i = 0; i < NTESTS; ++i)
+ {
+ TEST_HASH (md5, i);
+ TEST_HASH (sha1, i);
+ }
+ return error_message_count;
+}
diff --git a/tests/sha1-tst.c b/tests/sha1-tst.c
deleted file mode 100644
index 9ff8141b..00000000
--- a/tests/sha1-tst.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* Copyright (C) 2008 Red Hat, Inc.
- This file is part of Red Hat elfutils.
- Written by Ulrich Drepper <[email protected]>, 2008.
-
- Red Hat elfutils 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; version 2 of the License.
-
- Red Hat elfutils 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 General Public License along
- with Red Hat elfutils; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
-
- Red Hat elfutils is an included package of the Open Invention Network.
- An included package of the Open Invention Network is a package for which
- Open Invention Network licensees cross-license their patents. No patent
- license is granted, either expressly or impliedly, by designation as an
- included package. Should you wish to participate in the Open Invention
- Network licensing program, please visit www.openinventionnetwork.com
- <http://www.openinventionnetwork.com>. */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <sha1.h>
-
-
-int
-main (void)
-{
- char buf[1000];
- int result = 0;
-
- struct sha1_ctx ctx;
- sha1_init_ctx (&ctx);
- sha1_process_bytes ("abc", 3, &ctx);
- sha1_finish_ctx (&ctx, buf);
- static const char expected1[SHA1_DIGEST_SIZE] =
- "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e"
- "\x25\x71\x78\x50\xc2\x6c\x9c\xd0\xd8\x9d";
- if (memcmp (buf, expected1, SHA1_DIGEST_SIZE) != 0)
- {
- puts ("test 1 failed");
- result = 1;
- }
-
- sha1_init_ctx (&ctx);
- sha1_process_bytes ("\
-abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56, &ctx);
- sha1_finish_ctx (&ctx, buf);
- static const char expected2[SHA1_DIGEST_SIZE] =
- "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e\xba\xae"
- "\x4a\xa1\xf9\x51\x29\xe5\xe5\x46\x70\xf1";
- if (memcmp (buf, expected2, SHA1_DIGEST_SIZE) != 0)
- {
- puts ("test 2 failed");
- result = 1;
- }
-
- sha1_init_ctx (&ctx);
- memset (buf, 'a', sizeof (buf));
- for (int i = 0; i < 1000; ++i)
- sha1_process_bytes (buf, sizeof (buf), &ctx);
- sha1_finish_ctx (&ctx, buf);
- static const char expected3[SHA1_DIGEST_SIZE] =
- "\x34\xaa\x97\x3c\xd4\xc4\xda\xa4\xf6\x1e"
- "\xeb\x2b\xdb\xad\x27\x31\x65\x34\x01\x6f";
- if (memcmp (buf, expected3, SHA1_DIGEST_SIZE) != 0)
- {
- puts ("test 3 failed");
- result = 1;
- }
-
- return result;
-}