Commit 2f7d830f authored by Niels Möller's avatar Niels Möller
Browse files

(test_main): Rewrote rest of tests to use HMAC_TEST, and added more

tests from Daniel Kahn Gillmor and from RFC 4231.

Rev: nettle/testsuite/hmac-test.c:1.4
parent 16302e13
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
#include "hmac.h" #include "hmac.h"
/* KEY and MSG are supposed to expand to length, data */ /* KEY and MSG are supposed to expand to length, data */
#define HMAC_TEST(alg, length, key, msg, mac) do { \ #define HMAC_TEST(alg, length, key, msg, mac) do { \
hmac_##alg##_set_key(&alg, key); \ hmac_##alg##_set_key(&alg, key); \
hmac_##alg##_update(&alg, msg); \ hmac_##alg##_update(&alg, msg); \
hmac_##alg##_digest(&alg, length, digest); \ digest[length] = 17; \
ASSERT(MEMEQ (length, digest, mac)); \ hmac_##alg##_digest(&alg, length, digest); \
ASSERT(MEMEQ (length, digest, mac)); \
ASSERT(digest[length] == 17); \
} while (0) } while (0)
int int
...@@ -14,11 +16,13 @@ test_main(void) ...@@ -14,11 +16,13 @@ test_main(void)
{ {
struct hmac_md5_ctx md5; struct hmac_md5_ctx md5;
struct hmac_sha1_ctx sha1; struct hmac_sha1_ctx sha1;
struct hmac_sha224_ctx sha224;
struct hmac_sha256_ctx sha256; struct hmac_sha256_ctx sha256;
struct hmac_sha384_ctx sha384;
struct hmac_sha512_ctx sha512; struct hmac_sha512_ctx sha512;
/* sha512's digests are longest */ /* sha512's digests are longest */
uint8_t digest[SHA512_DIGEST_SIZE]; uint8_t digest[SHA512_DIGEST_SIZE+1];
memset(digest, 0, sizeof(digest)); memset(digest, 0, sizeof(digest));
...@@ -57,12 +61,10 @@ test_main(void) ...@@ -57,12 +61,10 @@ test_main(void)
H("697eaf0aca3a3aea 3a75164746ffaa79")); H("697eaf0aca3a3aea 3a75164746ffaa79"));
/* md5 - 5 */ /* md5 - 5 */
memset(digest, 0, MD5_DIGEST_SIZE); HMAC_TEST(md5, 12,
hmac_md5_set_key(&md5, HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c" )); HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"),
hmac_md5_update(&md5, LDATA("Test With Truncation")); LDATA("Test With Truncation"),
hmac_md5_digest(&md5, 12, digest); H("56461ef2342edc00 f9bab995"));
ASSERT(MEMEQ(MD5_DIGEST_SIZE, digest,
H("56461ef2342edc00 f9bab99500000000")));
/* md5 - 6 */ /* md5 - 6 */
HMAC_TEST(md5, MD5_DIGEST_SIZE, HMAC_TEST(md5, MD5_DIGEST_SIZE,
...@@ -160,12 +162,10 @@ test_main(void) ...@@ -160,12 +162,10 @@ test_main(void)
H("4c9007f4026250c6 bc8414f9bf50c86c 2d7235da")); H("4c9007f4026250c6 bc8414f9bf50c86c 2d7235da"));
/* sha1 - 5 */ /* sha1 - 5 */
memset(digest, 0, SHA1_DIGEST_SIZE); HMAC_TEST(sha1, 12,
hmac_sha1_set_key(&sha1, HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c")); HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
hmac_sha1_update(&sha1, LDATA("Test With Truncation")); LDATA("Test With Truncation"),
hmac_sha1_digest(&sha1, 12, digest); H("4c1a03424b55e07f e7f27be1"));
ASSERT(MEMEQ(SHA1_DIGEST_SIZE, digest,
H("4c1a03424b55e07f e7f27be100000000 00000000")));
/* sha1 - 6 */ /* sha1 - 6 */
HMAC_TEST(sha1, SHA1_DIGEST_SIZE, HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
...@@ -229,162 +229,601 @@ test_main(void) ...@@ -229,162 +229,601 @@ test_main(void)
LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
H("939dd45512ee3a594b6654f6b8de27f7")); H("939dd45512ee3a594b6654f6b8de27f7"));
/* Test vectors for sha256, from draft-ietf-ipsec-ciph-sha-256-01.txt */ /* Test vectors for sha224, from RFC 4231 */
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
"0b0b0b0b"),
LDATA("Hi There"),
H("896fb1128abbdf196832107cd49df33f"
"47b4b1169912ba4f53684b22"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("Jefe"),
LDATA("what do ya want for nothing?"),
H("a30e01098bc6dbbf45690f3a7e9e6d0f"
"8bbea2a39e6148008fd05e44"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaa"),
HL("dddddddddddddddddddddddddddddddd"
"dddddddddddddddddddddddddddddddd"
"dddddddddddddddddddddddddddddddd"
"dddd"),
H("7fb3cb3588c6c1f6ffa9694d7d6ad264"
"9365b0c1f65d69d1ec8333ea"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
HL("0102030405060708090a0b0c0d0e0f10"
"111213141516171819"),
HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcd"),
H("6c11506874013cac6a2abc1bb382627c"
"ec6a90d86efc012de7afec5a"));
HMAC_TEST(sha224, 16,
HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
LDATA("Test With Truncation"),
H("0e2aea68a90c8d37c988bcdb9fca6fa8"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaa"),
LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
H("95e9a0db962095adaebe9b2d6f0dbce2"
"d499f112f2d2b7273fa6870e"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaa"),
LDATA("This is a test using a larger than block-size ke"
"y and a larger than block-size data. The key nee"
"ds to be hashed before being used by the HMAC al"
"gorithm."),
H("3a854166ac5d9f023f54d517d0b39dbd"
"946770db9c2b95c9f6f565d1"));
/* Additional test vectors, from Daniel Kahn Gillmor */
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA(""),
H("d12a49ae38177ffeaa548b2148bb5238"
"60849772d9391e675b103d89"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("a"),
H("b04ff8522f904f553970bfa8ad3f0086"
"bce1e8580affd8a12c94e31a"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("38"),
H("afcfb5511f710334f9350f57faec3c08"
"764b4bd126a6840f4347f116"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("abc"),
H("9df9907af127900c909376893565c6cf"
"2d7db244fdc4277da1e0b679"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("message digest"),
H("254ebf6b8ddd7a3271b3d9aca1699b0c"
"0bfb7df61e8a114922c88d27"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("abcdefghijklmnopqrstuvwxyz"),
H("6ec5bffba5880c3234a6cf257816e4d5"
"35ab178a7f12929769e378fb"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
H("5f768179dbb29ca722875d0f461a2e2f"
"597d0210340a84df1a8e9c63"));
HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
H("c7667b0d7e56b2b4f6fcc1d8da9e22da"
"a1556f44c47132a87303c6a2"));
/* Test vectors for sha256, from RFC 4231 */
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
"0b0b0b0b"),
LDATA("Hi There"),
H("b0344c61d8db38535ca8afceaf0bf12b"
"881dc200c9833da726e9376c2e32cff7"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
LDATA("Jefe"),
LDATA("what do ya want for nothing?"),
H("5bdcc146bf60754e6a042426089575c7"
"5a003f089d2739839dec58b964ec3843"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaa"),
HL("dddddddddddddddddddddddddddddddd"
"dddddddddddddddddddddddddddddddd"
"dddddddddddddddddddddddddddddddd"
"dddd"),
H("773ea91e36800e46854db8ebd09181a7"
"2959098b3ef8c122d9635514ced565fe"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
HL("0102030405060708090a0b0c0d0e0f10"
"111213141516171819"),
HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcd"),
H("82558a389a443c0ea4cc819899f2083a"
"85f0faa3e578f8077a2e3ff46729665b"));
HMAC_TEST(sha256, 16,
HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
LDATA("Test With Truncation"),
H("a3b6167473100ee06e0c796c2955552b"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaa"),
LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
H("60e431591ee0b67f0d8a26aacbf5b77f"
"8e0bc6213728c5140546040f0ee37f54"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaa"),
LDATA("This is a test using a larger than block-size ke"
"y and a larger than block-size data. The key nee"
"ds to be hashed before being used by the HMAC al"
"gorithm."),
H("9b09ffa71b942fcb27635fbcd5b0e944"
"bfdc63644f0713938a7f51535c3a35e2"));
/* Additional test vectors for sha256, from
draft-ietf-ipsec-ciph-sha-256-01.txt */
/* Test Case #1: HMAC-SHA-256 with 3-byte input and 32-byte key */ /* Test Case #1: HMAC-SHA-256 with 3-byte input and 32-byte key */
hmac_sha256_set_key(&sha256, HL("0102030405060708 090a0b0c0d0e0f10" HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
"1112131415161718 191a1b1c1d1e1f20")); HL("0102030405060708 090a0b0c0d0e0f10"
hmac_sha256_update(&sha256, LDATA("abc")); "1112131415161718 191a1b1c1d1e1f20"),
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest); LDATA("abc"),
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest, H("a21b1f5d4cf4f73a 4dd939750f7a066a"
H("a21b1f5d4cf4f73a 4dd939750f7a066a" "7f98cc131cb16a66 92759021cfab8181"));
"7f98cc131cb16a66 92759021cfab8181")));
/* Test Case #2: HMAC-SHA-256 with 56-byte input and 32-byte key */ /* Test Case #2: HMAC-SHA-256 with 56-byte input and 32-byte key */
hmac_sha256_set_key(&sha256, HL("0102030405060708 090a0b0c0d0e0f10" HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
"1112131415161718 191a1b1c1d1e1f20")); HL("0102030405060708 090a0b0c0d0e0f10"
hmac_sha256_update(&sha256, LDATA("abcdbcdecdefdefgefghfghighijhijk" "1112131415161718 191a1b1c1d1e1f20"),
"ijkljklmklmnlmnomnopnopq")); LDATA("abcdbcdecdefdefgefghfghighijhijk"
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest); "ijkljklmklmnlmnomnopnopq"),
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest, H("104fdc1257328f08 184ba73131c53cae"
H("104fdc1257328f08 184ba73131c53cae" "e698e36119421149 ea8c712456697d30"));
"e698e36119421149 ea8c712456697d30")));
/* Test Case #3: HMAC-SHA-256 with 112-byte (multi-block) input /* Test Case #3: HMAC-SHA-256 with 112-byte (multi-block) input
and 32-byte key */ and 32-byte key */
hmac_sha256_set_key(&sha256, HL("0102030405060708 090a0b0c0d0e0f10" HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
"1112131415161718 191a1b1c1d1e1f20")); HL("0102030405060708 090a0b0c0d0e0f10"
hmac_sha256_update(&sha256, LDATA("abcdbcdecdefdefgefghfghighijhijk" "1112131415161718 191a1b1c1d1e1f20"),
"ijkljklmklmnlmnomnopnopqabcdbcde" LDATA("abcdbcdecdefdefgefghfghighijhijk"
"cdefdefgefghfghighijhijkijkljklm" "ijkljklmklmnlmnomnopnopqabcdbcde"
"klmnlmnomnopnopq")); "cdefdefgefghfghighijhijkijkljklm"
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest); "klmnlmnomnopnopq"),
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest, H("470305fc7e40fe34 d3eeb3e773d95aab"
H("470305fc7e40fe34 d3eeb3e773d95aab" "73acf0fd060447a5 eb4595bf33a9d1a3"));
"73acf0fd060447a5 eb4595bf33a9d1a3")));
/* Test Case #4: HMAC-SHA-256 with 8-byte input and 32-byte key */ /* Test Case #4: HMAC-SHA-256 with 8-byte input and 32-byte key */
hmac_sha256_set_key(&sha256, HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b" HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
"0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b")); HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"
hmac_sha256_update(&sha256, LDATA("Hi There")); "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"),
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest); LDATA("Hi There"),
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest, H("198a607eb44bfbc6 9903a0f1cf2bbdc5"
H("198a607eb44bfbc6 9903a0f1cf2bbdc5" "ba0aa3f3d9ae3c1c 7a3b1696a0b68cf7"));
"ba0aa3f3d9ae3c1c 7a3b1696a0b68cf7")));
/* Test Case #5: HMAC-SHA-256 with 28-byte input and 4-byte key */
hmac_sha256_set_key(&sha256, LDATA("Jefe"));
hmac_sha256_update(&sha256, LDATA("what do ya want for nothing?"));
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest);
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest,
H("5bdcc146bf60754e 6a042426089575c7"
"5a003f089d273983 9dec58b964ec3843")));
/* Test Case #6: HMAC-SHA-256 with 50-byte input and 32-byte key */ /* Test Case #6: HMAC-SHA-256 with 50-byte input and 32-byte key */
hmac_sha256_set_key(&sha256, HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa")); HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
hmac_sha256_update(&sha256, HL("dddddddddddddddd dddddddddddddddd" "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
"dddddddddddddddd dddddddddddddddd" HL("dddddddddddddddd dddddddddddddddd"
"dddddddddddddddd dddddddddddddddd" "dddddddddddddddd dddddddddddddddd"
"dddd")); "dddddddddddddddd dddddddddddddddd"
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest); "dddd"),
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest, H("cdcb1220d1ecccea 91e53aba3092f962"
H("cdcb1220d1ecccea 91e53aba3092f962" "e549fe6ce9ed7fdc 43191fbde45c30b0"));
"e549fe6ce9ed7fdc 43191fbde45c30b0")));
/* Test Case #7: HMAC-SHA-256 with 50-byte input and 37-byte key */ /* Test Case #7: HMAC-SHA-256 with 50-byte input and 37-byte key */
hmac_sha256_set_key(&sha256, HL("0102030405060708 090a0b0c0d0e0f10" HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
"1112131415161718 191a1b1c1d1e1f20" HL("0102030405060708 090a0b0c0d0e0f10"
"2122232425")); "1112131415161718 191a1b1c1d1e1f20"
hmac_sha256_update(&sha256, HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" "2122232425"),
"cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
"cdcd")); "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest); "cdcd"),
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest, H("d4633c17f6fb8d74 4c66dee0f8f07455"
H("d4633c17f6fb8d74 4c66dee0f8f07455" "6ec4af55ef079985 41468eb49bd2e917"));
"6ec4af55ef079985 41468eb49bd2e917")));
/* Test Case #8: HMAC-SHA-256 with 20-byte input and 32-byte key */ /* Test Case #8: HMAC-SHA-256 with 20-byte input and 32-byte key */
memset(digest, 0, SHA256_DIGEST_SIZE); HMAC_TEST(sha256, 16,
hmac_sha256_set_key(&sha256, HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c" HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"
"0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c")); "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"),
hmac_sha256_update(&sha256, LDATA("Test With Truncation")); LDATA("Test With Truncation"),
hmac_sha256_digest(&sha256, 16, digest); H("7546af01841fc09b 1ab9c3749a5f1c17"));
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest,
H("7546af01841fc09b 1ab9c3749a5f1c17"
"0000000000000000 0000000000000000")));
/* Test Case #9: HMAC-SHA-256 with 54-byte input and 80-byte key */ /* Test Case #9: HMAC-SHA-256 with 54-byte input and 80-byte key */
hmac_sha256_set_key(&sha256, HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa")); "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
hmac_sha256_update(&sha256, LDATA( "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
"Test Using Larger Than Block-Size Key - Hash Key First")); LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest); H("6953025ed96f0c09 f80a96f78e6538db"
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest, "e2e7b820e3dd970e 7ddd39091b32352f"));
H("6953025ed96f0c09 f80a96f78e6538db"
"e2e7b820e3dd970e 7ddd39091b32352f")));
/* Test Case #10: HMAC-SHA-256 with 73-byte (multi-block) input /* Test Case #10: HMAC-SHA-256 with 73-byte (multi-block) input
and 80-byte key */ and 80-byte key */
hmac_sha256_set_key(&sha256, HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa")); "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
hmac_sha256_update(&sha256, LDATA( "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data")); LDATA("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"),
hmac_sha256_digest(&sha256, SHA256_DIGEST_SIZE, digest); H("6355ac22e890d0a3 c8481a5ca4825bc8"
ASSERT(MEMEQ(SHA256_DIGEST_SIZE, digest, "84d3e7a1ff98a2fc 2ac7d8e064c3b2e6"));
H("6355ac22e890d0a3 c8481a5ca4825bc8"
"84d3e7a1ff98a2fc 2ac7d8e064c3b2e6"))); /* Additional test vectors, from Daniel Kahn Gillmor */
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
/* Test vectors for sha512, from draft-kelly-ipsec-ciph-sha2-01.txt */ LDATA("monkey monkey monkey monkey"),
LDATA(""),
H("5c780648c90d121c50091c3a0c3afc1f"
"4ab847528005d99d9821ad3f341b651a"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("a"),
H("6142364c0646b0cfe426866f21d613e0"
"55a136a7d9b45d85685e080a09cec463"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("38"),
H("e49aa7839977e130ad87b63da9d4eb7b"
"263cd5a27c54a7604b6044eb35901171"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("abc"),
H("e5ef49f545c7af933a9d18c7c562bc91"
"08583fd5cf00d9e0db351d6d8f8e41bc"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("message digest"),
H("373b04877180fea27a41a8fb8f88201c"
"a6268411ee3c80b01a424483eb9156e1"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("abcdefghijklmnopqrstuvwxyz"),
H("eb5945d56eefbdb41602946ea6448d53"
"86b08d7d801a87f439fab52f8bb9736e"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
H("3798f363c57afa6edaffe39016ca7bad"
"efd1e670afb0e3987194307dec3197db"));
HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
LDATA("monkey monkey monkey monkey"),
LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
H("c89a7039a62985ff813fe4509b918a43"
"6d7b1ffd8778e2c24dec464849fb6128"));
/* Test vectors for sha384, from RFC 4231 */
HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
"0b0b0b0b"),
LDATA("Hi There"),
H("afd03944d84895626b0825f4ab46907f"
"15f9dadbe4101ec682aa034c7cebc59c"
"faea9ea9076ede7f4af152e8b2fa9cb6"));
HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
LDATA("Jefe"),
LDATA("what do ya want for nothing?"),
H("af45d2e376484031617f78d2b58a6b1b"
"9c7ef464f5a01b47e42ec3736322445e"
"8e2240ca5e69e2c78b3239ecfab21649"));
HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaa"),
HL("dddddddddddddddddddddddddddddddd"
"dddddddddddddddddddddddddddddddd"
"dddddddddddddddddddddddddddddddd"
"dddd"),
H("88062608d3e6ad8a0aa2ace014c8a86f"
"0aa635d947ac9febe83ef4e55966144b"
"2a5ab39dc13814b94e3ab6e101a34f27"));
HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
HL("0102030405060708090a0b0c0d0e0f10"
"111213141516171819"),
HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcd"),
H("3e8a69b7783c25851933ab6290af6ca7"
"7a9981480850009cc5577c6e1f573b4e"
"6801dd23c4a7d679ccf8a386c674cffb"));
HMAC_TEST(sha384, 16,
HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
LDATA("Test With Truncation"),
H("3abf34c3503b2a23a46efc619baef897"));
HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaa"),
LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
H("4ece084485813e9088d2c63a041bc5b4"
"4f9ef1012a2b588f3cd11f05033ac4c6"
"0c2ef6ab4030fe8296248df163f44952"));
HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaa"),
LDATA("This is a test using a larger than block-size ke"
"y and a larger than block-size data. The key nee"
"ds to be hashed before being used by the HMAC al"
"gorithm."),
H("6617178e941f020d351e2f254e8fd32c"
"602420feb0b8fb9adccebb82461e99c5"
"a678cc31e799176d3860e6110c46523e"));
/* Test vectors for sha512, from RFC 4231 */
HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
"0b0b0b0b"),
LDATA("Hi There"),
H("87aa7cdea5ef619d4ff0b4241a1d6cb0"
"2379f4e2ce4ec2787ad0b30545e17cde"
"daa833b7d6b8a702038b274eaea3f4e4"
"be9d914eeb61f1702e696c203a126854"));
HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
LDATA("Jefe"),
LDATA("what do ya want for nothing?"),
H("164b7a7bfcf819e2e395fbe73b56e0a3"
"87bd64222e831fd610270cd7ea250554"
"9758bf75c05a994a6d034f65f8f0e6fd"
"caeab1a34d4a6b4b636e070a38bce737"));
HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaa"),
HL("dddddddddddddddddddddddddddddddd"
"dddddddddddddddddddddddddddddddd"
"dddddddddddddddddddddddddddddddd"
"dddd"),
H("fa73b0089d56a284efb0f0756c890be9"
"b1b5dbdd8ee81a3655f83e33b2279d39"
"bf3e848279a722c806b485a47e67c807"
"b946a337bee8942674278859e13292fb"));
HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
HL("0102030405060708090a0b0c0d0e0f10"
"111213141516171819"),
HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
"cdcd"),
H("b0ba465637458c6990e5a8c5f61d4af7"
"e576d97ff94b872de76f8050361ee3db"
"a91ca5c11aa25eb4d679275cc5788063"
"a5f19741120c4f2de2adebeb10a298dd"));
HMAC_TEST(sha512, 16,
HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
LDATA("Test With Truncation"),
H("415fad6271580a531d4179bc891d87a6"));