diff options
author | Stef Walter <stef@thewalter.net> | 2013-07-10 14:28:15 +0200 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2013-07-10 15:07:55 +0200 |
commit | edd04b610c1c83f26ed036569ad95b89a41fc558 (patch) | |
tree | 7ec7040b9ef612b36a399592c018c0a131ddfa75 /common/tests | |
parent | eca5a6e491f5f85ba1f06afcea3177c3442ae557 (diff) |
Add support for using freebl3 for SHA1 and MD5 hashing
Since we don't want to link freebl3 to libp11-kit.so where it isn't
needed, move the SHA-1 and MD5 digest functionality to the trust/
directory.
Diffstat (limited to 'common/tests')
-rw-r--r-- | common/tests/test-hash.c | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/common/tests/test-hash.c b/common/tests/test-hash.c index c679cad..a12d5a4 100644 --- a/common/tests/test-hash.c +++ b/common/tests/test-hash.c @@ -43,95 +43,6 @@ #include "hash.h" -const char *sha1_input[] = { - "abc", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - NULL -}; - -const char *sha1_checksum[] = { - "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D", - "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1", - NULL -}; - -static void -test_sha1 (void) -{ - unsigned char checksum[P11_HASH_SHA1_LEN]; - size_t len; - int i; - - for (i = 0; sha1_input[i] != NULL; i++) { - memset (checksum, 0, sizeof (checksum)); - len = strlen (sha1_input[i]); - - p11_hash_sha1 (checksum, sha1_input[i], len, NULL); - assert (memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0); - - if (len > 6) { - p11_hash_sha1 (checksum, sha1_input[i], 6, sha1_input[i] + 6, len - 6, NULL); - assert (memcmp (sha1_checksum[i], checksum, P11_HASH_SHA1_LEN) == 0); - } - } -} - -static void -test_sha1_long (void) -{ - unsigned char checksum[P11_HASH_SHA1_LEN]; - char *expected = "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F"; - char *input; - - input = malloc (1000000); - assert (input != NULL); - memset (input, 'a', 1000000); - - p11_hash_sha1 (checksum, input, 1000000, NULL); - assert (memcmp (expected, checksum, P11_HASH_SHA1_LEN) == 0); - - free (input); -} - -const char *md5_input[] = { - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - NULL -}; - -const char *md5_checksum[] = { - "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e", - "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8\x31\xc3\x99\xe2\x69\x77\x26\x61", - "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72", - "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0", - "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b", - NULL -}; - -static void -test_md5 (void) -{ - unsigned char checksum[P11_HASH_MD5_LEN]; - size_t len; - int i; - - for (i = 0; md5_input[i] != NULL; i++) { - memset (checksum, 0, sizeof (checksum)); - len = strlen (md5_input[i]); - - p11_hash_md5 (checksum, md5_input[i], len, NULL); - assert (memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0); - - if (len > 5) { - p11_hash_md5 (checksum, md5_input[i], 5, md5_input[i] + 5, len - 5, NULL); - assert (memcmp (md5_checksum[i], checksum, P11_HASH_MD5_LEN) == 0); - } - } -} - static void test_murmur3 (void) { @@ -189,9 +100,6 @@ int main (int argc, char *argv[]) { - p11_test (test_sha1, "/hash/sha1"); - p11_test (test_sha1_long, "/hash/sha1-long"); - p11_test (test_md5, "/hash/md5"); p11_test (test_murmur3, "/hash/murmur3"); p11_test (test_murmur3_incr, "/hash/murmur3-incr"); return p11_test_run (argc, argv); |