diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2011-10-08 12:43:10 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2011-10-08 12:43:10 +0200 |
commit | 8c6c8b114cd7a5886aa21304ab0fc2ac8de29f8c (patch) | |
tree | 96b0074aba42a724ea3be91e3ea90688a51943f3 /tests | |
parent | 1618e176162d9c60b0a6209d4a2f18d043ed30b4 (diff) | |
download | gnutls-8c6c8b114cd7a5886aa21304ab0fc2ac8de29f8c.tar.gz |
Added more elaborate test of hash functions.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cipher-test.c | 101 |
1 files changed, 90 insertions, 11 deletions
diff --git a/tests/cipher-test.c b/tests/cipher-test.c index 8c989f2ed0..dfb7ae7a73 100644 --- a/tests/cipher-test.c +++ b/tests/cipher-test.c @@ -360,8 +360,23 @@ struct hash_vectors_st .output = (uint8_t *) "\x8f\x82\x03\x94\xf9\x53\x35\x18\x20\x45\xda\x24\xf3\x4d\xe5\x2b\xf8\xbc\x34\x32", - .output_size = 20,} - , + .output_size = 20, + }, + { + .name = "SHA1", + .algorithm = GNUTLS_MAC_SHA1, + .key = NULL, + .plaintext = + (uint8_t *) + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + .plaintext_size = sizeof + ("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") + - 1, + .output = + (uint8_t *) + "\xbe\xae\xd1\x6d\x65\x8e\xc7\x92\x9e\xdf\xd6\x2b\xfa\xfe\xac\x29\x9f\x0d\x74\x4d", + .output_size = 20, + }, { .name = "SHA256", .algorithm = GNUTLS_MAC_SHA256, @@ -378,6 +393,21 @@ struct hash_vectors_st .output_size = 32, }, { + .name = "SHA256", + .algorithm = GNUTLS_MAC_SHA256, + .key = NULL, + .plaintext = + (uint8_t *) + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + .plaintext_size = sizeof + ("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") + - 1, + .output = + (uint8_t *) + "\x50\xea\x82\x5d\x96\x84\xf4\x22\x9c\xa2\x9f\x1f\xec\x51\x15\x93\xe2\x81\xe4\x6a\x14\x0d\x81\xe0\x00\x5f\x8f\x68\x86\x69\xa0\x6c", + .output_size = 32, + }, + { .name = "SHA512", .algorithm = GNUTLS_MAC_SHA512, .key = NULL, @@ -462,13 +492,34 @@ test_hash (void) /* import key */ if (hash_vectors[i].key != NULL) { + gnutls_hmac_hd_t hd; + ret = gnutls_hmac_init( &hd, hash_vectors[i].algorithm, hash_vectors[i].key, hash_vectors[i].key_size); + if (ret < 0) + { + fprintf (stderr, "Error: %s:%d\n", __func__, + __LINE__); + return 1; + } + + ret = gnutls_hmac(hd, hash_vectors[i].plaintext, hash_vectors[i].plaintext_size-1); + if (ret < 0) + { + fprintf (stderr, "Error: %s:%d\n", __func__, + __LINE__); + return 1; + } + + ret = gnutls_hmac(hd, &hash_vectors[i].plaintext[hash_vectors[i].plaintext_size-1], 1); + if (ret < 0) + { + fprintf (stderr, "Error: %s:%d\n", __func__, + __LINE__); + return 1; + } + + gnutls_hmac_output(hd, data); + gnutls_hmac_deinit(hd, NULL); - ret = gnutls_hmac_fast (hash_vectors[i].algorithm, - hash_vectors[i].key, - hash_vectors[i].key_size, - hash_vectors[i].plaintext, - hash_vectors[i].plaintext_size, - data); data_size = gnutls_hmac_get_len (hash_vectors[i].algorithm); if (ret < 0) @@ -480,10 +531,38 @@ test_hash (void) } else { - ret = gnutls_hash_fast (hash_vectors[i].algorithm, + gnutls_hash_hd_t hd; + ret = gnutls_hash_init( &hd, hash_vectors[i].algorithm); + if (ret < 0) + { + fprintf (stderr, "Error: %s:%d\n", __func__, + __LINE__); + return 1; + } + + ret = gnutls_hash (hd, hash_vectors[i].plaintext, - hash_vectors[i].plaintext_size, - data); + 1); + if (ret < 0) + { + fprintf (stderr, "Error: %s:%d\n", __func__, + __LINE__); + return 1; + } + + ret = gnutls_hash (hd, + &hash_vectors[i].plaintext[1], + hash_vectors[i].plaintext_size-1); + if (ret < 0) + { + fprintf (stderr, "Error: %s:%d\n", __func__, + __LINE__); + return 1; + } + + gnutls_hash_output(hd, data); + gnutls_hash_deinit(hd, NULL); + data_size = gnutls_hash_get_len (hash_vectors[i].algorithm); if (ret < 0) |