From 75288e447e2a659b7c4df915d81c426bda4435c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niels=20M=C3=B6ller?= Date: Sun, 16 Sep 2012 23:29:08 +0200 Subject: [PATCH] Testsuite overhaul, including proper deallocation of storage. --- ChangeLog | 44 + testsuite/aes-test.c | 163 ++-- testsuite/arcfour-test.c | 140 ++- testsuite/arctwo-test.c | 98 +-- testsuite/base16-test.c | 4 +- testsuite/base64-test.c | 4 +- testsuite/bignum-test.c | 44 +- testsuite/blowfish-test.c | 10 +- testsuite/buffer-test.c | 4 +- testsuite/camellia-test.c | 78 +- testsuite/cast128-test.c | 24 +- testsuite/cbc-test.c | 106 ++- testsuite/ctr-test.c | 66 +- testsuite/cxx-test.cxx | 24 +- testsuite/des-compat-test.c | 5 +- testsuite/des-test.c | 123 +-- testsuite/des3-test.c | 14 +- testsuite/dsa-keygen-test.c | 24 +- testsuite/dsa-test.c | 3 +- testsuite/gcm-test.c | 424 +++++----- testsuite/hmac-test.c | 1498 ++++++++++++++++----------------- testsuite/knuth-lfib-test.c | 7 +- testsuite/md2-test.c | 32 +- testsuite/md4-test.c | 48 +- testsuite/md5-compat-test.c | 38 +- testsuite/md5-test.c | 54 +- testsuite/memxor-test.c | 4 +- testsuite/meta-armor-test.c | 3 +- testsuite/meta-cipher-test.c | 3 +- testsuite/meta-hash-test.c | 3 +- testsuite/pkcs1-test.c | 4 +- testsuite/random-prime-test.c | 4 +- testsuite/ripemd160-test.c | 44 +- testsuite/rsa-encrypt-test.c | 3 +- testsuite/rsa-keygen-test.c | 24 +- testsuite/rsa-test.c | 14 +- testsuite/rsa2sexp-test.c | 71 +- testsuite/salsa20-test.c | 243 +++--- testsuite/serpent-test.c | 358 ++++---- testsuite/sexp-format-test.c | 16 +- testsuite/sexp-test.c | 17 +- testsuite/sexp2rsa-test.c | 57 +- testsuite/sha1-huge-test.c | 8 +- testsuite/sha1-test.c | 44 +- testsuite/sha224-test.c | 62 +- testsuite/sha256-test.c | 76 +- testsuite/sha384-test.c | 84 +- testsuite/sha512-test.c | 102 ++- testsuite/testutils.c | 505 ++++++----- testsuite/testutils.h | 121 ++- testsuite/twofish-test.c | 26 +- testsuite/yarrow-test.c | 47 +- 52 files changed, 2477 insertions(+), 2545 deletions(-) diff --git a/ChangeLog b/ChangeLog index 72dcf479..f2a20100 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,49 @@ 2012-09-16 Niels Möller + * testsuite/: Overhaul of testsuite, affecting almost all files. + + Use struct tstring for allocated strings, and deallocate before + exit. + + Changed most test functions to take struct tstring as arguments. + + Made all test_main return on success. + + * testsuite/testutils.h (struct tstring): New struct type. + (H2, HL, MEMEQH, SUCCESS): Deleted macros. + (SHEX, SDATA): New macros. + (H): Redefined to track storage. + + * testsuite/testutils.c (tstring_alloc): New function. + (tstring_clear): New function. + (tstring_data): New function. + (tstring_hex): New function. + (tstring_print_hex): New function. + (decode_hex_length): Made static. + (decode_hex): Made static. No return value, abort on error. + (main): Expect test_main to return, and call tstring_clear before + exit. + (test_dsa_key): Added missing mpz_clear. + (test_mac): Deleted unused function. + + * testsuite/rsa2sexp-test.c (test_main): Added missing + nettle_buffer_clear. + + * testsuite/yarrow-test.c (open_file): Don't leak filename. + (test_main): fclose input file properly. + + * testsuite/sexp-format-test.c (test_main): Added missing calls to + nettle_buffer_clear and mpz_clear. + + * testsuite/serpent-test.c (tstring_hex_reverse): New function, + replacing... + (decode_hex_reverse): ... deleted function. + (RHEX): New macro, replacing... + (RH, RHL): ... deleted macros. + + * testsuite/rsa2sexp-test.c (test_main): Added missing + nettle_buffer_clear. + + * testsuite/random-prime-test.c (test_main): Added missing + mpz_clear. + * realloc.c (nettle_realloc): Only call libc realloc if length > 0, otherwise call free. Fixes a small memory leak. (nettle_xrealloc): Likewise. diff --git a/testsuite/aes-test.c b/testsuite/aes-test.c index 87be8063..ce5fc3ff 100644 --- a/testsuite/aes-test.c +++ b/testsuite/aes-test.c @@ -2,25 +2,28 @@ #include "aes.h" static void -test_invert(unsigned key_length, const uint8_t *key, - unsigned length, const uint8_t *cleartext, - const uint8_t *ciphertext) +test_invert(const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext) { struct aes_ctx encrypt; struct aes_ctx decrypt; - uint8_t *data = xalloc(length); + uint8_t *data = xalloc(cleartext->length); + unsigned length; + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; - aes_set_encrypt_key (&encrypt, key_length, key); - aes_encrypt (&encrypt, length, data, cleartext); + aes_set_encrypt_key (&encrypt, key->length, key->data); + aes_encrypt (&encrypt, length, data, cleartext->data); - if (!MEMEQ(length, data, ciphertext)) + if (!MEMEQ(length, data, ciphertext->data)) { fprintf(stderr, "test_invert: Encrypt failed:\nInput:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\n"); FAIL(); } @@ -28,72 +31,72 @@ test_invert(unsigned key_length, const uint8_t *key, aes_invert_key (&decrypt, &encrypt); aes_decrypt (&decrypt, length, data, data); - if (!MEMEQ(length, data, cleartext)) + if (!MEMEQ(length, data, cleartext->data)) { fprintf(stderr, "test_invert: Decrypt failed:\nInput:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } free (data); } -int +void test_main(void) { /* 128 bit keys */ test_cipher(&nettle_aes128, - HL("0001020305060708 0A0B0C0D0F101112"), - HL("506812A45F08C889 B97F5980038B8359"), - H("D8F532538289EF7D 06B506A4FD5BE9C9")); + SHEX("0001020305060708 0A0B0C0D0F101112"), + SHEX("506812A45F08C889 B97F5980038B8359"), + SHEX("D8F532538289EF7D 06B506A4FD5BE9C9")); test_cipher(&nettle_aes128, - HL("14151617191A1B1C 1E1F202123242526"), - HL("5C6D71CA30DE8B8B 00549984D2EC7D4B"), - H("59AB30F4D4EE6E4F F9907EF65B1FB68C")); + SHEX("14151617191A1B1C 1E1F202123242526"), + SHEX("5C6D71CA30DE8B8B 00549984D2EC7D4B"), + SHEX("59AB30F4D4EE6E4F F9907EF65B1FB68C")); test_cipher(&nettle_aes128, - HL("28292A2B2D2E2F30 323334353738393A"), - HL("53F3F4C64F8616E4 E7C56199F48F21F6"), - H("BF1ED2FCB2AF3FD4 1443B56D85025CB1")); + SHEX("28292A2B2D2E2F30 323334353738393A"), + SHEX("53F3F4C64F8616E4 E7C56199F48F21F6"), + SHEX("BF1ED2FCB2AF3FD4 1443B56D85025CB1")); test_cipher(&nettle_aes128, - HL("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"), - HL("F5F4F7F684878689 A6A7A0A1D2CDCCCF"), - H("CE52AF650D088CA5 59425223F4D32694")); + SHEX("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"), + SHEX("F5F4F7F684878689 A6A7A0A1D2CDCCCF"), + SHEX("CE52AF650D088CA5 59425223F4D32694")); /* 192 bit keys */ test_cipher(&nettle_aes192, - HL("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C"), - HL("2D33EEF2C0430A8A 9EBF45E809C40BB6"), - H("DFF4945E0336DF4C 1C56BC700EFF837F")); + SHEX("0001020305060708 0A0B0C0D0F101112" + "14151617191A1B1C"), + SHEX("2D33EEF2C0430A8A 9EBF45E809C40BB6"), + SHEX("DFF4945E0336DF4C 1C56BC700EFF837F")); /* 256 bit keys */ test_cipher(&nettle_aes256, - HL("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C 1E1F202123242526"), - HL("834EADFCCAC7E1B30664B1ABA44815AB"), - H("1946DABF6A03A2A2 C3D0B05080AED6FC")); + SHEX("0001020305060708 0A0B0C0D0F101112" + "14151617191A1B1C 1E1F202123242526"), + SHEX("834EADFCCAC7E1B30664B1ABA44815AB"), + SHEX("1946DABF6A03A2A2 C3D0B05080AED6FC")); /* This test case has been problematic with the CBC test case */ test_cipher(&nettle_aes256, - HL("8d ae 93 ff fc 78 c9 44" - "2a bd 0c 1e 68 bc a6 c7" - "05 c7 84 e3 5a a9 11 8b" - "d3 16 aa 54 9b 44 08 9e"), - HL("a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"), + SHEX("8d ae 93 ff fc 78 c9 44" + "2a bd 0c 1e 68 bc a6 c7" + "05 c7 84 e3 5a a9 11 8b" + "d3 16 aa 54 9b 44 08 9e"), + SHEX("a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"), /* In the cbc test, I once got the bad value * "b2 a0 6c d2 2f df 7d 2c 26 d2 42 88 8f 20 74 a2" */ - H("1f 94 fc 85 f2 36 21 06" - "4a ea e3 c9 cc 38 01 0e")); + SHEX("1f 94 fc 85 f2 36 21 06" + "4a ea e3 c9 cc 38 01 0e")); /* From draft NIST spec on AES modes. * @@ -102,56 +105,54 @@ test_main(void) */ test_cipher(&nettle_aes128, - HL("2b7e151628aed2a6abf7158809cf4f3c"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("3ad77bb40d7a3660a89ecaf32466ef97" - "f5d3d58503b9699de785895a96fdbaaf" - "43b1cd7f598ece23881b00e3ed030688" - "7b0c785e27e8ad3f8223207104725dd4")); + SHEX("2b7e151628aed2a6abf7158809cf4f3c"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("3ad77bb40d7a3660a89ecaf32466ef97" + "f5d3d58503b9699de785895a96fdbaaf" + "43b1cd7f598ece23881b00e3ed030688" + "7b0c785e27e8ad3f8223207104725dd4")); /* F.1.3 ECB-AES192-Encrypt */ test_cipher(&nettle_aes192, - HL("8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("bd334f1d6e45f25ff712a214571fa5cc" - "974104846d0ad3ad7734ecb3ecee4eef" - "ef7afd2270e2e60adce0ba2face6444e" - "9a4b41ba738d6c72fb16691603c18e0e")); + SHEX("8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("bd334f1d6e45f25ff712a214571fa5cc" + "974104846d0ad3ad7734ecb3ecee4eef" + "ef7afd2270e2e60adce0ba2face6444e" + "9a4b41ba738d6c72fb16691603c18e0e")); /* F.1.5 ECB-AES256-Encrypt */ test_cipher(&nettle_aes256, - HL("603deb1015ca71be2b73aef0857d7781" - "1f352c073b6108d72d9810a30914dff4"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("f3eed1bdb5d2a03c064b5a7e3db181f8" - "591ccb10d410ed26dc5ba74a31362870" - "b6ed21b99ca6f4f9f153e7b1beafed1d" - "23304b7a39f9f3ff067d8d8f9e24ecc7")); + SHEX("603deb1015ca71be2b73aef0857d7781" + "1f352c073b6108d72d9810a30914dff4"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("f3eed1bdb5d2a03c064b5a7e3db181f8" + "591ccb10d410ed26dc5ba74a31362870" + "b6ed21b99ca6f4f9f153e7b1beafed1d" + "23304b7a39f9f3ff067d8d8f9e24ecc7")); /* Test aes_invert_key with src != dst */ - test_invert(HL("0001020305060708 0A0B0C0D0F101112"), - HL("506812A45F08C889 B97F5980038B8359"), - H("D8F532538289EF7D 06B506A4FD5BE9C9")); - test_invert(HL("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C"), - HL("2D33EEF2C0430A8A 9EBF45E809C40BB6"), - H("DFF4945E0336DF4C 1C56BC700EFF837F")); - test_invert(HL("0001020305060708 0A0B0C0D0F101112" - "14151617191A1B1C 1E1F202123242526"), - HL("834EADFCCAC7E1B30664B1ABA44815AB"), - H("1946DABF6A03A2A2 C3D0B05080AED6FC")); - - SUCCESS(); + test_invert(SHEX("0001020305060708 0A0B0C0D0F101112"), + SHEX("506812A45F08C889 B97F5980038B8359"), + SHEX("D8F532538289EF7D 06B506A4FD5BE9C9")); + test_invert(SHEX("0001020305060708 0A0B0C0D0F101112" + "14151617191A1B1C"), + SHEX("2D33EEF2C0430A8A 9EBF45E809C40BB6"), + SHEX("DFF4945E0336DF4C 1C56BC700EFF837F")); + test_invert(SHEX("0001020305060708 0A0B0C0D0F101112" + "14151617191A1B1C 1E1F202123242526"), + SHEX("834EADFCCAC7E1B30664B1ABA44815AB"), + SHEX("1946DABF6A03A2A2 C3D0B05080AED6FC")); } /* Internal state for the first test case: diff --git a/testsuite/arcfour-test.c b/testsuite/arcfour-test.c index 6027c549..c1443a1e 100644 --- a/testsuite/arcfour-test.c +++ b/testsuite/arcfour-test.c @@ -1,97 +1,95 @@ #include "testutils.h" #include "arcfour.h" -int +void test_main(void) { test_cipher_stream(&nettle_arcfour128, - HL("01234567 89ABCDEF 00000000 00000000"), - HL("01234567 89ABCDEF"), - H("69723659 1B5242B1")); + SHEX("01234567 89ABCDEF 00000000 00000000"), + SHEX("01234567 89ABCDEF"), + SHEX("69723659 1B5242B1")); /* More data. This ensures that we get some collisions between the S accesses at index i,j and the access at si + sj. I.e. the cases where the ordering of loads and stores matter. */ test_cipher_stream(&nettle_arcfour128, - HL("aaaaaaaa bbbbbbbb cccccccc dddddddd"), - HL("00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" + SHEX("aaaaaaaa bbbbbbbb cccccccc dddddddd"), + SHEX("00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000"), - H("a2b35dc7 bf95ae1e 1c432d15 f4fb8c1c" - "f264e1d0 bd090831 6caa7d17 5401ae67" - "3cfbd140 fd3dee42 1012d674 2fb69fa3" - "6522631e bb3d4703 535de1ce 4a81ddce" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000"), + SHEX("a2b35dc7 bf95ae1e 1c432d15 f4fb8c1c" + "f264e1d0 bd090831 6caa7d17 5401ae67" + "3cfbd140 fd3dee42 1012d674 2fb69fa3" + "6522631e bb3d4703 535de1ce 4a81ddce" - "5780cfe0 b5fc9fae ebe14c96 26451bd9" - "992f2204 119cbe37 cbdc453c 7afa08c7" - "1380ccf8 48f81e53 a535cdfb 96c64faa" - "c3f759d0 fa1ff920 008d95cf 39d52324" + "5780cfe0 b5fc9fae ebe14c96 26451bd9" + "992f2204 119cbe37 cbdc453c 7afa08c7" + "1380ccf8 48f81e53 a535cdfb 96c64faa" + "c3f759d0 fa1ff920 008d95cf 39d52324" - "d0aac3f9 749b22e2 6a065145 06fb249d" - "ffb8e05e cb0381fe 5346a04a 63dac61c" - "10b6683e 3ab427de d4c6bc60 6366545e" - "77d0e121 96037717 a745d49e e72a70aa" + "d0aac3f9 749b22e2 6a065145 06fb249d" + "ffb8e05e cb0381fe 5346a04a 63dac61c" + "10b6683e 3ab427de d4c6bc60 6366545e" + "77d0e121 96037717 a745d49e e72a70aa" - "a50a612d 879b0580 fd4a89ae 3ee49871" - "2cf6c98d a62dfbc7 d7b2d901 2c3aaf27" - "42b7e089 ef2466ac 450b440c 138daa1a" - "cf9ebef6 f66a7a64 2677b213 06640130" + "a50a612d 879b0580 fd4a89ae 3ee49871" + "2cf6c98d a62dfbc7 d7b2d901 2c3aaf27" + "42b7e089 ef2466ac 450b440c 138daa1a" + "cf9ebef6 f66a7a64 2677b213 06640130" - "de6651df 0065180d 4db366ba 9c377712" - "53d21cac 82ed72a4 c6c4d81e 4375fea3" - "1f935909 95322c83 13c64d8e 829c93a6" - "d540a1b3 20f41541 96800888 1a7afc9b" + "de6651df 0065180d 4db366ba 9c377712" + "53d21cac 82ed72a4 c6c4d81e 4375fea3" + "1f935909 95322c83 13c64d8e 829c93a6" + "d540a1b3 20f41541 96800888 1a7afc9b" - "e39e89fc 3ac78be5 cdbbf774 33c36863" - "da2a3b1b d06e54a9 aa4b7edd 70b34941" - "b886f7db f36c3def f9fc4c80 7ce55ea5" - "98a7257b f68a9e1d caf4bfd6 43bd9853" + "e39e89fc 3ac78be5 cdbbf774 33c36863" + "da2a3b1b d06e54a9 aa4b7edd 70b34941" + "b886f7db f36c3def f9fc4c80 7ce55ea5" + "98a7257b f68a9e1d caf4bfd6 43bd9853" - "c966629d 54e34221 6e140780 d48c69bb" - "5e77e886 86f2ebcb 807732d5 d29bc384" - "a4ca1c31 c7c1b5b9 85dbfcf1 8d845905" - "a0ff487a b4a3f252 a75caebf 857ba48b" + "c966629d 54e34221 6e140780 d48c69bb" + "5e77e886 86f2ebcb 807732d5 d29bc384" + "a4ca1c31 c7c1b5b9 85dbfcf1 8d845905" + "a0ff487a b4a3f252 a75caebf 857ba48b" - "613e3067 92cada3e 0e07f599 2f4794f3" - "af01f15a 491732fb 22aa09a3 d2e1e408" - "fe94bdb4 993c68b1 1bb79eb1 bb7ec446" - "760ef7bf 2caa8713 479760e5 a6e143cd")); - - SUCCESS(); + "613e3067 92cada3e 0e07f599 2f4794f3" + "af01f15a 491732fb 22aa09a3 d2e1e408" + "fe94bdb4 993c68b1 1bb79eb1 bb7ec446" + "760ef7bf 2caa8713 479760e5 a6e143cd")); } diff --git a/testsuite/arctwo-test.c b/testsuite/arctwo-test.c index 4fedfad8..c75bb15e 100644 --- a/testsuite/arctwo-test.c +++ b/testsuite/arctwo-test.c @@ -25,91 +25,91 @@ /* For tests with obscure values of ebk. */ static void test_arctwo(unsigned ekb, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext) + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext) { struct arctwo_ctx ctx; - uint8_t *data = xalloc(length); + uint8_t *data; + unsigned length; - arctwo_set_key_ekb(&ctx, key_length, key, ekb); - arctwo_encrypt(&ctx, length, data, cleartext); + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; + + data = xalloc(length); - if (!MEMEQ(length, data, ciphertext)) - FAIL(); + arctwo_set_key_ekb(&ctx, key->length, key->data, ekb); + arctwo_encrypt(&ctx, length, data, cleartext->data); + + ASSERT(MEMEQ(length, data, ciphertext->data)); arctwo_decrypt(&ctx, length, data, data); - if (!MEMEQ(length, data, cleartext)) - FAIL(); + ASSERT(MEMEQ(length, data, cleartext->data)); free(data); } -int +void test_main(void) { /* Test vectors from Peter Gutmann's paper. */ test_cipher(&nettle_arctwo_gutmann128, - HL("00000000 00000000 00000000 00000000"), - HL("00000000 00000000"), - H ("1c198a83 8df028b7")); + SHEX("00000000 00000000 00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("1c198a83 8df028b7")); test_cipher(&nettle_arctwo_gutmann128, - HL("00010203 04050607 08090a0b 0c0d0e0f"), - HL("00000000 00000000"), - H ("50dc0162 bd757f31")); + SHEX("00010203 04050607 08090a0b 0c0d0e0f"), + SHEX("00000000 00000000"), + SHEX("50dc0162 bd757f31")); /* This one was checked against libmcrypt's RFC2268. */ test_cipher(&nettle_arctwo_gutmann128, - HL("30000000 00000000 00000000 00000000"), - HL("10000000 00000000"), - H ("8fd10389 336bf95e")); + SHEX("30000000 00000000 00000000 00000000"), + SHEX("10000000 00000000"), + SHEX("8fd10389 336bf95e")); /* Test vectors from RFC 2268. */ test_cipher(&nettle_arctwo64, - HL("ffffffff ffffffff"), - HL("ffffffff ffffffff"), - H ("278b27e4 2e2f0d49")); + SHEX("ffffffff ffffffff"), + SHEX("ffffffff ffffffff"), + SHEX("278b27e4 2e2f0d49")); test_cipher(&nettle_arctwo64, - HL("30000000 00000000"), - HL("10000000 00000001"), - H ("30649edf 9be7d2c2")); + SHEX("30000000 00000000"), + SHEX("10000000 00000001"), + SHEX("30649edf 9be7d2c2")); test_cipher(&nettle_arctwo128, - HL("88bca90e 90875a7f 0f79c384 627bafb2"), - HL("00000000 00000000"), - H ("2269552a b0f85ca6")); + SHEX("88bca90e 90875a7f 0f79c384 627bafb2"), + SHEX("00000000 00000000"), + SHEX("2269552a b0f85ca6")); /* More obscure tests from RFC 2286 */ test_arctwo(63, - HL("00000000 00000000"), - HL("00000000 00000000"), - H ("ebb773f9 93278eff")); + SHEX("00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("ebb773f9 93278eff")); test_arctwo(64, - HL("88"), - HL("00000000 00000000"), - H ("61a8a244 adacccf0")); + SHEX("88"), + SHEX("00000000 00000000"), + SHEX("61a8a244 adacccf0")); test_arctwo(64, - HL("88bca90e 90875a"), - HL("00000000 00000000"), - H ("6ccf4308 974c267f")); + SHEX("88bca90e 90875a"), + SHEX("00000000 00000000"), + SHEX("6ccf4308 974c267f")); test_arctwo(64, - HL("88bca90e 90875a7f 0f79c384 627bafb2"), - HL("00000000 00000000"), - H ("1a807d27 2bbe5db1")); + SHEX("88bca90e 90875a7f 0f79c384 627bafb2"), + SHEX("00000000 00000000"), + SHEX("1a807d27 2bbe5db1")); test_arctwo(129, - HL("88bca90e 90875a7f 0f79c384 627bafb2" - "16f80a6f 85920584 c42fceb0 be255daf 1e"), - HL("00000000 00000000"), - H ("5b78d3a4 3dfff1f1")); - - SUCCESS (); + SHEX("88bca90e 90875a7f 0f79c384 627bafb2" + "16f80a6f 85920584 c42fceb0 be255daf 1e"), + SHEX("00000000 00000000"), + SHEX("5b78d3a4 3dfff1f1")); } diff --git a/testsuite/base16-test.c b/testsuite/base16-test.c index fe8fe923..633e1c6d 100644 --- a/testsuite/base16-test.c +++ b/testsuite/base16-test.c @@ -1,7 +1,7 @@ #include "testutils.h" #include "base16.h" -int +void test_main(void) { ASSERT(BASE16_ENCODE_LENGTH(0) == 0); @@ -21,7 +21,5 @@ test_main(void) test_armor(&nettle_base16, 4, "Hell", "48656c6c"); test_armor(&nettle_base16, 5, "Hello", "48656c6c6f"); test_armor(&nettle_base16, 6, "Hello", "48656c6c6f00"); - - SUCCESS(); } diff --git a/testsuite/base64-test.c b/testsuite/base64-test.c index b4d0917c..b2388aee 100644 --- a/testsuite/base64-test.c +++ b/testsuite/base64-test.c @@ -1,7 +1,7 @@ #include "testutils.h" #include "base64.h" -int +void test_main(void) { ASSERT(BASE64_ENCODE_LENGTH(0) == 0); /* At most 4 bits */ @@ -45,6 +45,4 @@ test_main(void) ASSERT(MEMEQ(9, buffer, "HelloG8=x")); } - - SUCCESS(); } diff --git a/testsuite/bignum-test.c b/testsuite/bignum-test.c index 84e0483c..31149304 100644 --- a/testsuite/bignum-test.c +++ b/testsuite/bignum-test.c @@ -11,27 +11,24 @@ #include "bignum.h" static void -test_bignum(const char *hex, unsigned length, const uint8_t *base256) +test_bignum(const char *hex, const struct tstring *base256) { mpz_t a; mpz_t b; uint8_t *buf; mpz_init_set_str(a, hex, 16); - nettle_mpz_init_set_str_256_s(b, length, base256); + nettle_mpz_init_set_str_256_s(b, base256->length, base256->data); - if (mpz_cmp(a, b)) - FAIL(); + ASSERT(mpz_cmp(a, b) == 0); - buf = xalloc(length + 1); - memset(buf, 17, length + 1); + buf = xalloc(base256->length + 1); + memset(buf, 17, base256->length + 1); - nettle_mpz_get_str_256(length, buf, a); - if (!MEMEQ(length, buf, base256)) - FAIL(); + nettle_mpz_get_str_256(base256->length, buf, a); + ASSERT(MEMEQ(base256->length, buf, base256->data)); - if (buf[length] != 17) - FAIL(); + ASSERT(buf[base256->length] == 17); mpz_clear(a); mpz_clear(b); free(buf); @@ -49,7 +46,7 @@ test_size(long x, unsigned size) #endif /* HAVE_LIBGMP */ -int +void test_main(void) { #if HAVE_LIBGMP @@ -78,19 +75,18 @@ test_main(void) test_size(- 0x8000, 2); /* 8000 */ test_size(- 0x8001, 3); /* ff7fff */ - test_bignum("0", HL("00")); - test_bignum("010203040506", HL("010203040506")); - test_bignum("80010203040506", HL("0080010203040506")); - - test_bignum( "-1", HL( "ff")); - test_bignum( "-7f", HL( "81")); - test_bignum( "-80", HL( "80")); - test_bignum( "-81", HL( "ff7f")); - test_bignum("-7fff", HL( "8001")); - test_bignum("-8000", HL( "8000")); - test_bignum("-8001", HL("ff7fff")); + test_bignum("0", SHEX("00")); + test_bignum("010203040506", SHEX("010203040506")); + test_bignum("80010203040506", SHEX("0080010203040506")); + + test_bignum( "-1", SHEX( "ff")); + test_bignum( "-7f", SHEX( "81")); + test_bignum( "-80", SHEX( "80")); + test_bignum( "-81", SHEX( "ff7f")); + test_bignum("-7fff", SHEX( "8001")); + test_bignum("-8000", SHEX( "8000")); + test_bignum("-8001", SHEX("ff7fff")); - SUCCESS(); #else /* !HAVE_LIBGMP */ SKIP(); #endif /* !HAVE_LIBGMP */ diff --git a/testsuite/blowfish-test.c b/testsuite/blowfish-test.c index c4311bb7..2cac994a 100644 --- a/testsuite/blowfish-test.c +++ b/testsuite/blowfish-test.c @@ -2,16 +2,14 @@ #include "nettle-internal.h" #include "blowfish.h" -int +void test_main(void) { /* 208 bit key. Test from GNUPG. */ test_cipher(&nettle_blowfish128, - 26, "abcdefghijklmnopqrstuvwxyz", - BLOWFISH_BLOCK_SIZE, "BLOWFISH", - H("32 4E D0 FE F4 13 A2 03")); - - SUCCESS(); + SDATA("abcdefghijklmnopqrstuvwxyz"), + SDATA("BLOWFISH"), + SHEX("32 4E D0 FE F4 13 A2 03")); } /* FIXME: All values below are bogus. */ #if 0 diff --git a/testsuite/buffer-test.c b/testsuite/buffer-test.c index 3ac4b207..fe2e2224 100644 --- a/testsuite/buffer-test.c +++ b/testsuite/buffer-test.c @@ -1,7 +1,7 @@ #include "testutils.h" #include "buffer.h" -int +void test_main(void) { struct nettle_buffer buffer; @@ -24,6 +24,4 @@ test_main(void) ASSERT(buffer.size == 3); ASSERT(!nettle_buffer_write(&buffer, LDATA("bar"))); - - SUCCESS(); } diff --git a/testsuite/camellia-test.c b/testsuite/camellia-test.c index 4f1d118b..b7d6eaf6 100644 --- a/testsuite/camellia-test.c +++ b/testsuite/camellia-test.c @@ -2,25 +2,30 @@ #include "camellia.h" static void -test_invert(unsigned key_length, const uint8_t *key, - unsigned length, const uint8_t *cleartext, - const uint8_t *ciphertext) +test_invert(const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext) { struct camellia_ctx encrypt; struct camellia_ctx decrypt; - uint8_t *data = xalloc(length); + uint8_t *data; + unsigned length; - camellia_set_encrypt_key (&encrypt, key_length, key); - camellia_crypt (&encrypt, length, data, cleartext); + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; + + data = xalloc(length); + + camellia_set_encrypt_key (&encrypt, key->length, key->data); + camellia_crypt (&encrypt, length, data, cleartext->data); - if (!MEMEQ(length, data, ciphertext)) + if (!MEMEQ(length, data, ciphertext->data)) { - fprintf(stderr, "test_invert: Encrypt failed:\nInput:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\n"); FAIL(); } @@ -28,57 +33,56 @@ test_invert(unsigned key_length, const uint8_t *key, camellia_invert_key (&decrypt, &encrypt); camellia_crypt (&decrypt, length, data, data); - if (!MEMEQ(length, data, cleartext)) + if (!MEMEQ(length, data, cleartext->data)) { fprintf(stderr, "test_invert: Decrypt failed:\nInput:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } free (data); } -int +void test_main(void) { /* Test vectors from RFC 3713 */ /* 128 bit keys */ test_cipher(&nettle_camellia128, - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), - H("67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43")); + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), + SHEX("67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43")); /* 192 bit keys */ test_cipher(&nettle_camellia192, - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10" - "00 11 22 33 44 55 66 77"), - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), - H("b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9")); + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10" + "00 11 22 33 44 55 66 77"), + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), + SHEX("b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9")); /* 256 bit keys */ test_cipher(&nettle_camellia256, - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10" - "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"), - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), - H("9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09")); + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10" + "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"), + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), + SHEX("9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09")); /* Test camellia_invert_key with src != dst */ - test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), - H("67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43")); + test_invert(SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), + SHEX("67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43")); - test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10" - "00 11 22 33 44 55 66 77"), - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), - H("b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9")); + test_invert(SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10" + "00 11 22 33 44 55 66 77"), + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), + SHEX("b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9")); - test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10" - "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"), - HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), - H("9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09")); - SUCCESS(); + test_invert(SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10" + "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"), + SHEX("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"), + SHEX("9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09")); } diff --git a/testsuite/cast128-test.c b/testsuite/cast128-test.c index e4b7830e..60ed30b1 100644 --- a/testsuite/cast128-test.c +++ b/testsuite/cast128-test.c @@ -1,7 +1,7 @@ #include "testutils.h" #include "cast128.h" -int +void test_main(void) { /* Test vectors from B.1. Single Plaintext-Key-Ciphertext Sets, RFC @@ -9,22 +9,20 @@ test_main(void) /* 128 bit key */ test_cipher(&nettle_cast128, - HL("01 23 45 67 12 34 56 78" - "23 45 67 89 34 56 78 9A"), - HL("01 23 45 67 89 AB CD EF"), - H("23 8B 4F E5 84 7E 44 B2")); + SHEX("01 23 45 67 12 34 56 78" + "23 45 67 89 34 56 78 9A"), + SHEX("01 23 45 67 89 AB CD EF"), + SHEX("23 8B 4F E5 84 7E 44 B2")); /* 80 bit key */ test_cipher(&nettle_cast128, - HL("01 23 45 67 12 34 56 78 23 45"), - HL("01 23 45 67 89 AB CD EF"), - H("EB 6A 71 1A 2C 02 27 1B")); + SHEX("01 23 45 67 12 34 56 78 23 45"), + SHEX("01 23 45 67 89 AB CD EF"), + SHEX("EB 6A 71 1A 2C 02 27 1B")); /* 40 bit key */ test_cipher(&nettle_cast128, - HL("01 23 45 67 12"), - HL("01 23 45 67 89 AB CD EF"), - H("7A C8 16 D1 6E 9B 30 2E")); - - SUCCESS(); + SHEX("01 23 45 67 12"), + SHEX("01 23 45 67 89 AB CD EF"), + SHEX("7A C8 16 D1 6E 9B 30 2E")); } diff --git a/testsuite/cbc-test.c b/testsuite/cbc-test.c index b7bd2dd2..6b82e6dc 100644 --- a/testsuite/cbc-test.c +++ b/testsuite/cbc-test.c @@ -35,8 +35,7 @@ test_cbc_bulk(void) CBC_ENCRYPT(&aes, aes_encrypt, CBC_BULK_DATA, cipher, clear); - if (cipher[CBC_BULK_DATA] != 17) - FAIL(); + ASSERT(cipher[CBC_BULK_DATA] == 17); if (verbose) { @@ -45,16 +44,14 @@ test_cbc_bulk(void) printf("\n"); } - if (!MEMEQ(AES_BLOCK_SIZE, aes.iv, end_iv)) - FAIL(); + ASSERT(MEMEQ(AES_BLOCK_SIZE, aes.iv, end_iv)); /* Decrypt, in place */ aes_set_decrypt_key(&aes.ctx, 32, key); CBC_SET_IV(&aes, start_iv); CBC_DECRYPT(&aes, aes_decrypt, CBC_BULK_DATA, cipher, cipher); - if (cipher[CBC_BULK_DATA] != 17) - FAIL(); + ASSERT(cipher[CBC_BULK_DATA] == 17); if (verbose) { @@ -63,18 +60,13 @@ test_cbc_bulk(void) printf("\n"); } - if (!MEMEQ(AES_BLOCK_SIZE, aes.iv, end_iv)) - FAIL(); - - if (!MEMEQ(CBC_BULK_DATA, clear, cipher)) - FAIL(); + ASSERT (MEMEQ(AES_BLOCK_SIZE, aes.iv, end_iv)); + ASSERT (MEMEQ(CBC_BULK_DATA, clear, cipher)); } -int +void test_main(void) { - static const uint8_t msg[2 * AES_BLOCK_SIZE] = "Listen, I'll say this only once!"; - /* Intermediate values: * iv XOR first message block: * "a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37" @@ -87,16 +79,16 @@ test_main(void) */ test_cipher_cbc(&nettle_aes256, - HL("8d ae 93 ff fc 78 c9 44" - "2a bd 0c 1e 68 bc a6 c7" - "05 c7 84 e3 5a a9 11 8b" - "d3 16 aa 54 9b 44 08 9e"), - 2 * AES_BLOCK_SIZE, msg, - H("1f 94 fc 85 f2 36 21 06" - "4a ea e3 c9 cc 38 01 0e" - "7b f6 5f c5 02 59 2e 71" - "af bf 34 87 c0 36 2a 16"), - H("e9 a7 26 a0 44 7b 8d e6 03 83 60 de ea d5 b0 4e")); + SHEX("8d ae 93 ff fc 78 c9 44" + "2a bd 0c 1e 68 bc a6 c7" + "05 c7 84 e3 5a a9 11 8b" + "d3 16 aa 54 9b 44 08 9e"), + SDATA("Listen, I'll say this only once!"), + SHEX("1f 94 fc 85 f2 36 21 06" + "4a ea e3 c9 cc 38 01 0e" + "7b f6 5f c5 02 59 2e 71" + "af bf 34 87 c0 36 2a 16"), + SHEX("e9 a7 26 a0 44 7b 8d e6 03 83 60 de ea d5 b0 4e")); /* From NIST spec 800-38a on AES modes. * @@ -112,16 +104,16 @@ test_main(void) * 8521f2fd3c8eef2cdc3da7e5c44ea206 */ test_cipher_cbc(&nettle_aes128, - HL("2b7e151628aed2a6abf7158809cf4f3c"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("7649abac8119b246cee98e9b12e9197d" - "5086cb9b507219ee95db113a917678b2" - "73bed6b8e3c1743b7116e69e22229516" - "3ff1caa1681fac09120eca307586e1a7"), - H("000102030405060708090a0b0c0d0e0f")); + SHEX("2b7e151628aed2a6abf7158809cf4f3c"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("7649abac8119b246cee98e9b12e9197d" + "5086cb9b507219ee95db113a917678b2" + "73bed6b8e3c1743b7116e69e22229516" + "3ff1caa1681fac09120eca307586e1a7"), + SHEX("000102030405060708090a0b0c0d0e0f")); /* F.2.3 CBC-AES192.Encrypt */ @@ -134,17 +126,17 @@ test_main(void) */ test_cipher_cbc(&nettle_aes192, - HL("8e73b0f7da0e6452c810f32b809079e5" - "62f8ead2522c6b7b"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("4f021db243bc633d7178183a9fa071e8" - "b4d9ada9ad7dedf4e5e738763f69145a" - "571b242012fb7ae07fa9baac3df102e0" - "08b0e27988598881d920a9e64f5615cd"), - H("000102030405060708090a0b0c0d0e0f")); + SHEX("8e73b0f7da0e6452c810f32b809079e5" + "62f8ead2522c6b7b"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("4f021db243bc633d7178183a9fa071e8" + "b4d9ada9ad7dedf4e5e738763f69145a" + "571b242012fb7ae07fa9baac3df102e0" + "08b0e27988598881d920a9e64f5615cd"), + SHEX("000102030405060708090a0b0c0d0e0f")); /* F.2.5 CBC-AES256.Encrypt */ @@ -157,21 +149,19 @@ test_main(void) */ test_cipher_cbc(&nettle_aes256, - HL("603deb1015ca71be2b73aef0857d7781" - "1f352c073b6108d72d9810a30914dff4"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("f58c4c04d6e5f1ba779eabfb5f7bfbd6" - "9cfc4e967edb808d679f777bc6702c7d" - "39f23369a9d9bacfa530e26304231461" - "b2eb05e2c39be9fcda6c19078c6a9d1b"), - H("000102030405060708090a0b0c0d0e0f")); + SHEX("603deb1015ca71be2b73aef0857d7781" + "1f352c073b6108d72d9810a30914dff4"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("f58c4c04d6e5f1ba779eabfb5f7bfbd6" + "9cfc4e967edb808d679f777bc6702c7d" + "39f23369a9d9bacfa530e26304231461" + "b2eb05e2c39be9fcda6c19078c6a9d1b"), + SHEX("000102030405060708090a0b0c0d0e0f")); test_cbc_bulk(); - - SUCCESS(); } /* diff --git a/testsuite/ctr-test.c b/testsuite/ctr-test.c index 15c74d55..b47b8aef 100644 --- a/testsuite/ctr-test.c +++ b/testsuite/ctr-test.c @@ -2,7 +2,7 @@ #include "aes.h" #include "ctr.h" -int +void test_main(void) { /* From NIST spec 800-38a on AES modes, @@ -14,45 +14,43 @@ test_main(void) /* F.5.1 CTR-AES128.Encrypt */ test_cipher_ctr(&nettle_aes128, - HL("2b7e151628aed2a6abf7158809cf4f3c"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("874d6191b620e3261bef6864990db6ce" - "9806f66b7970fdff8617187bb9fffdff" - "5ae4df3edbd5d35e5b4f09020db03eab" - "1e031dda2fbe03d1792170a0f3009cee"), - H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); + SHEX("2b7e151628aed2a6abf7158809cf4f3c"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("874d6191b620e3261bef6864990db6ce" + "9806f66b7970fdff8617187bb9fffdff" + "5ae4df3edbd5d35e5b4f09020db03eab" + "1e031dda2fbe03d1792170a0f3009cee"), + SHEX("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); /* F.5.3 CTR-AES192.Encrypt */ test_cipher_ctr(&nettle_aes192, - HL("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("1abc932417521ca24f2b0459fe7e6e0b" - "090339ec0aa6faefd5ccc2c6f4ce8e94" - "1e36b26bd1ebc670d1bd1d665620abf7" - "4f78a7f6d29809585a97daec58c6b050"), - H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); + SHEX("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("1abc932417521ca24f2b0459fe7e6e0b" + "090339ec0aa6faefd5ccc2c6f4ce8e94" + "1e36b26bd1ebc670d1bd1d665620abf7" + "4f78a7f6d29809585a97daec58c6b050"), + SHEX("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); /* F.5.5 CTR-AES256.Encrypt */ test_cipher_ctr(&nettle_aes256, - HL("603deb1015ca71be2b73aef0857d7781" - "1f352c073b6108d72d9810a30914dff4"), - HL("6bc1bee22e409f96e93d7e117393172a" - "ae2d8a571e03ac9c9eb76fac45af8e51" - "30c81c46a35ce411e5fbc1191a0a52ef" - "f69f2445df4f9b17ad2b417be66c3710"), - H("601ec313775789a5b7a7f504bbf3d228" - "f443e3ca4d62b59aca84e990cacaf5c5" - "2b0930daa23de94ce87017ba2d84988d" - "dfc9c58db67aada613c2dd08457941a6"), - H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); - - SUCCESS(); + SHEX("603deb1015ca71be2b73aef0857d7781" + "1f352c073b6108d72d9810a30914dff4"), + SHEX("6bc1bee22e409f96e93d7e117393172a" + "ae2d8a571e03ac9c9eb76fac45af8e51" + "30c81c46a35ce411e5fbc1191a0a52ef" + "f69f2445df4f9b17ad2b417be66c3710"), + SHEX("601ec313775789a5b7a7f504bbf3d228" + "f443e3ca4d62b59aca84e990cacaf5c5" + "2b0930daa23de94ce87017ba2d84988d" + "dfc9c58db67aada613c2dd08457941a6"), + SHEX("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); } /* diff --git a/testsuite/cxx-test.cxx b/testsuite/cxx-test.cxx index b5635fbf..b0235666 100644 --- a/testsuite/cxx-test.cxx +++ b/testsuite/cxx-test.cxx @@ -5,7 +5,7 @@ #include "md5.h" /* Test C++ linkage */ -int +void test_main(void) { struct md5_ctx md5; @@ -15,9 +15,8 @@ test_main(void) md5_update (&md5, 14, reinterpret_cast ("message digest")); md5_digest (&md5, MD5_DIGEST_SIZE, digest); - if (!MEMEQH (MD5_DIGEST_SIZE, digest, - "F96B697D7CB7938D 525A2F31AAF161D0")) - FAIL(); + ASSERT (MEMEQ (MD5_DIGEST_SIZE, digest, + H("F96B697D7CB7938D 525A2F31AAF161D0"))); #if WITH_PUBLIC_KEY @@ -40,8 +39,7 @@ test_main(void) "e545fbb4cf", 16); mpz_set_str(pub.e, "0db2ad57", 16); - if (!rsa_public_key_prepare(&pub)) - FAIL(); + ASSERT (rsa_public_key_prepare(&pub)); mpz_set_str(key.p, "0a66399919be4b4d" "e5a78c5ea5c85bf9" "aba8c013cb4a8732" @@ -68,11 +66,9 @@ test_main(void) "e2df9607cee95fa8" "daec7a389a7d9afc" "8dd21fef9d83805a" "40d46f49676a2f6b" "2926f70c572c00", 16); - if (!rsa_private_key_prepare(&key)) - FAIL(); + ASSERT (rsa_private_key_prepare(&key)); - if (pub.size != key.size) - FAIL(); + ASSERT (pub.size == key.size); mpz_set_str(expected, "53bf517009fa956e" "3daa6adc95e8663d" "3759002f488bbbad" @@ -93,16 +89,12 @@ test_main(void) /* Verify it */ md5_update (&md5, 39, reinterpret_cast ("The magic words are squeamish ossifrage")); - if (!rsa_md5_verify (&pub, &md5, signature)) - FAIL(); + ASSERT (rsa_md5_verify (&pub, &md5, signature)); /* Try bad data */ md5_update (&md5, 39, reinterpret_cast ("The magik words are squeamish ossifrage")); - if (rsa_md5_verify (&pub, &md5, signature)) - FAIL(); + ASSERT (!rsa_md5_verify (&pub, &md5, signature)); #endif /* WITH_PUBLIC_KEY */ - - SUCCESS(); } diff --git a/testsuite/des-compat-test.c b/testsuite/des-compat-test.c index 257c343d..282a7428 100644 --- a/testsuite/des-compat-test.c +++ b/testsuite/des-compat-test.c @@ -299,7 +299,7 @@ static int cfb64_test(); static int ede_cfb64_test(); #endif -int +void test_main(void) { int i,j,err=0; @@ -741,8 +741,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); } printf("\n"); #endif - exit(err); - return(0); + ASSERT (err == 0); } static char *pt(p) diff --git a/testsuite/des-test.c b/testsuite/des-test.c index 244e5aa2..574193dc 100644 --- a/testsuite/des-test.c +++ b/testsuite/des-test.c @@ -3,44 +3,49 @@ #include "des.h" static void -test_des(const uint8_t *key, int expected_parity, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext) +test_des(const struct tstring *key, int expected_parity, + const struct tstring *cleartext, + const struct tstring *ciphertext) { struct des_ctx ctx; - uint8_t *data = xalloc(length); + uint8_t *data; + unsigned length; - if (des_check_parity(8, key) != expected_parity) - FAIL(); + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; - if (!des_set_key(&ctx, key)) - FAIL(); + ASSERT (key->length == DES_KEY_SIZE); + + data = xalloc(length); - des_encrypt(&ctx, length, data, cleartext); + ASSERT (des_check_parity(8, key->data) == expected_parity); - if (!MEMEQ(length, data, ciphertext)) + ASSERT (des_set_key(&ctx, key->data)); + + des_encrypt(&ctx, length, data, cleartext->data); + + if (!MEMEQ(length, data, ciphertext->data)) { fprintf(stderr, "Encrypt failed:\nInput:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\n"); FAIL(); } des_decrypt(&ctx, length, data, data); - if (!MEMEQ(length, data, cleartext)) + if (!MEMEQ(length, data, cleartext->data)) { fprintf(stderr, "Decrypt failed:\nInput:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } @@ -49,74 +54,74 @@ test_des(const uint8_t *key, int expected_parity, } static void -test_weak(const uint8_t *key) +test_weak(const struct tstring *key) { struct des_ctx ctx; - if (des_set_key(&ctx, key)) - FAIL(); + ASSERT (key->length == DES_KEY_SIZE); + ASSERT (des_set_key(&ctx, key->data) == 0); } -int +void test_main(void) { /* From Applied Cryptography */ - test_des(H("01234567 89ABCDEF"), 1, - HL("01234567 89ABCDE7"), - H("C9574425 6A5ED31D")); + test_des(SHEX("01234567 89ABCDEF"), 1, + SHEX("01234567 89ABCDE7"), + SHEX("C9574425 6A5ED31D")); - test_des(H("01 01 01 01 01 01 01 80"), 1, - HL("00 00 00 00 00 00 00 00"), - H("9C C6 2D F4 3B 6E ED 74")); + test_des(SHEX("01 01 01 01 01 01 01 80"), 1, + SHEX("00 00 00 00 00 00 00 00"), + SHEX("9C C6 2D F4 3B 6E ED 74")); - test_des(H("80 01 01 01 01 01 01 01"), 1, - HL("00 00 00 00 00 00 00 40"), - H("A3 80 E0 2A 6B E5 46 96")); + test_des(SHEX("80 01 01 01 01 01 01 01"), 1, + SHEX("00 00 00 00 00 00 00 40"), + SHEX("A3 80 E0 2A 6B E5 46 96")); - test_des(H("08 19 2A 3B 4C 5D 6E 7F"), 1, - HL("00 00 00 00 00 00 00 00"), - H("25 DD AC 3E 96 17 64 67")); + test_des(SHEX("08 19 2A 3B 4C 5D 6E 7F"), 1, + SHEX("00 00 00 00 00 00 00 00"), + SHEX("25 DD AC 3E 96 17 64 67")); - test_des(H("01 23 45 67 89 AB CD EF"), 1, - DES_BLOCK_SIZE, "Now is t", - H("3F A4 0E 8A 98 4D 48 15")); + test_des(SHEX("01 23 45 67 89 AB CD EF"), 1, + SDATA("Now is t"), + SHEX("3F A4 0E 8A 98 4D 48 15")); /* Same key, but with one bad parity bit, */ - test_des(H("01 23 45 66 89 AB CD EF"), 0, - DES_BLOCK_SIZE, "Now is t", - H("3F A4 0E 8A 98 4D 48 15")); + test_des(SHEX("01 23 45 66 89 AB CD EF"), 0, + SDATA("Now is t"), + SHEX("3F A4 0E 8A 98 4D 48 15")); /* Parity check */ - if (des_check_parity(HL("01 01 01 01 01 01 01 00"))) - FAIL(); + { + const struct tstring *s = SHEX("01 01 01 01 01 01 01 00"); + ASSERT (des_check_parity(s->length, s->data) == 0); + } /* The four weak keys */ - test_weak(H("01 01 01 01 01 01 01 01")); - test_weak(H("FE FE FE FE FE FE FE FE")); - test_weak(H("1F 1F 1F 1F 0E 0E 0E 0E")); - test_weak(H("E0 E0 E0 E0 F1 F1 F1 F1")); + test_weak(SHEX("01 01 01 01 01 01 01 01")); + test_weak(SHEX("FE FE FE FE FE FE FE FE")); + test_weak(SHEX("1F 1F 1F 1F 0E 0E 0E 0E")); + test_weak(SHEX("E0 E0 E0 E0 F1 F1 F1 F1")); /* Same weak key, but different parity. */ - test_weak(H("E0 E0 E0 E0 F0 F1 F1 F1")); + test_weak(SHEX("E0 E0 E0 E0 F0 F1 F1 F1")); /* The six pairs of semiweak keys */ - test_weak(H("01 FE 01 FE 01 FE 01 FE")); - test_weak(H("FE 01 FE 01 FE 01 FE 01")); - - test_weak(H("1F E0 1F E0 0E F1 0E F1")); - test_weak(H("E0 1F E0 1F F1 0E F1 0E")); + test_weak(SHEX("01 FE 01 FE 01 FE 01 FE")); + test_weak(SHEX("FE 01 FE 01 FE 01 FE 01")); - test_weak(H("01 E0 01 E0 01 F1 01 F1")); - test_weak(H("E0 01 E0 01 F1 01 F1 01")); + test_weak(SHEX("1F E0 1F E0 0E F1 0E F1")); + test_weak(SHEX("E0 1F E0 1F F1 0E F1 0E")); - test_weak(H("1F FE 1F FE 0E FE 0E FE")); - test_weak(H("FE 1F FE 1F FE 0E FE 0E")); + test_weak(SHEX("01 E0 01 E0 01 F1 01 F1")); + test_weak(SHEX("E0 01 E0 01 F1 01 F1 01")); - test_weak(H("01 1F 01 1F 01 0E 01 0E")); - test_weak(H("1F 01 1F 01 0E 01 0E 01")); + test_weak(SHEX("1F FE 1F FE 0E FE 0E FE")); + test_weak(SHEX("FE 1F FE 1F FE 0E FE 0E")); - test_weak(H("E0 FE E0 FE F1 FE F1 FE")); - test_weak(H("FE E0 FE E0 FE F1 FE F1")); + test_weak(SHEX("01 1F 01 1F 01 0E 01 0E")); + test_weak(SHEX("1F 01 1F 01 0E 01 0E 01")); - SUCCESS(); + test_weak(SHEX("E0 FE E0 FE F1 FE F1 FE")); + test_weak(SHEX("FE E0 FE E0 FE F1 FE F1")); } diff --git a/testsuite/des3-test.c b/testsuite/des3-test.c index 678a235e..f0437ff4 100644 --- a/testsuite/des3-test.c +++ b/testsuite/des3-test.c @@ -2,7 +2,7 @@ #include "nettle-internal.h" #include "des.h" -int +void test_main(void) { /* Intermediate values: @@ -11,11 +11,9 @@ test_main(void) */ test_cipher(&nettle_des3, - HL("3e 0b 10 b0 5d 49 c2 54" - "6b 46 e0 75 8a 91 61 85" - "cb 04 07 d3 20 16 cb a2"), - DES_BLOCK_SIZE, "Now is t", - H("0a 5d b5 2d 85 74 d1 c9")); - - SUCCESS(); + SHEX("3e 0b 10 b0 5d 49 c2 54" + "6b 46 e0 75 8a 91 61 85" + "cb 04 07 d3 20 16 cb a2"), + SDATA("Now is t"), + SHEX("0a 5d b5 2d 85 74 d1 c9")); } diff --git a/testsuite/dsa-keygen-test.c b/testsuite/dsa-keygen-test.c index 12dc3096..a4db5994 100644 --- a/testsuite/dsa-keygen-test.c +++ b/testsuite/dsa-keygen-test.c @@ -8,7 +8,7 @@ progress(void *ctx UNUSED, int c) fputc(c, stderr); } -int +void test_main(void) { struct dsa_public_key pub; @@ -21,26 +21,24 @@ test_main(void) knuth_lfib_init(&lfib, 13); - if (!dsa_generate_keypair(&pub, &key, - &lfib, (nettle_random_func *) knuth_lfib_random, - NULL, verbose ? progress : NULL, - 1024, 160)) - FAIL(); + ASSERT (dsa_generate_keypair(&pub, &key, + &lfib, + (nettle_random_func *) knuth_lfib_random, + NULL, verbose ? progress : NULL, + 1024, 160)); test_dsa_key(&pub, &key, 160); test_dsa160(&pub, &key, NULL); - if (!dsa_generate_keypair(&pub, &key, - &lfib, (nettle_random_func *) knuth_lfib_random, - NULL, verbose ? progress : NULL, - 2048, 256)) - FAIL(); + ASSERT (dsa_generate_keypair(&pub, &key, + &lfib, + (nettle_random_func *) knuth_lfib_random, + NULL, verbose ? progress : NULL, + 2048, 256)); test_dsa_key(&pub, &key, 256); test_dsa256(&pub, &key, NULL); dsa_public_key_clear(&pub); dsa_private_key_clear(&key); - - SUCCESS(); } diff --git a/testsuite/dsa-test.c b/testsuite/dsa-test.c index 3698d1bb..e3b9d66e 100644 --- a/testsuite/dsa-test.c +++ b/testsuite/dsa-test.c @@ -1,6 +1,6 @@ #include "testutils.h" -int +void test_main(void) { struct dsa_public_key pub; @@ -101,5 +101,4 @@ test_main(void) dsa_public_key_clear(&pub); dsa_private_key_clear(&key); dsa_signature_clear(&expected); - SUCCESS(); } diff --git a/testsuite/gcm-test.c b/testsuite/gcm-test.c index a1cf9644..f0d4421c 100644 --- a/testsuite/gcm-test.c +++ b/testsuite/gcm-test.c @@ -2,7 +2,7 @@ #include "aes.h" #include "nettle-internal.h" -int +void test_main(void) { /* @@ -12,268 +12,266 @@ test_main(void) /* Test case 1 */ test_aead(&nettle_gcm_aes128, - /* key */HL("00000000000000000000000000000000"), - /* auth data */ HL(""), - /* plaintext */HL(""), - /* ciphertext*/H(""), - /* IV */HL("000000000000000000000000"), - /* tag */H("58e2fccefa7e3061367f1d57a4e7455a")); + SHEX("00000000000000000000000000000000"), /* key */ + SHEX(""), /* auth data */ + SHEX(""), /* plaintext */ + SHEX(""), /* ciphertext*/ + SHEX("000000000000000000000000"), /* IV */ + SHEX("58e2fccefa7e3061367f1d57a4e7455a")); /* tag */ /* Test case 2 */ test_aead(&nettle_gcm_aes128, - HL("00000000000000000000000000000000"), - HL(""), - HL("00000000000000000000000000000000"), - H("0388dace60b6a392f328c2b971b2fe78"), - HL("000000000000000000000000"), - H("ab6e47d42cec13bdf53a67b21257bddf")); + SHEX("00000000000000000000000000000000"), + SHEX(""), + SHEX("00000000000000000000000000000000"), + SHEX("0388dace60b6a392f328c2b971b2fe78"), + SHEX("000000000000000000000000"), + SHEX("ab6e47d42cec13bdf53a67b21257bddf")); /* Test case 3 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308"), - HL(""), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b391aafd255"), - H("42831ec2217774244b7221b784d0d49c" - "e3aa212f2c02a4e035c17e2329aca12e" - "21d514b25466931c7d8f6a5aac84aa05" - "1ba30b396a0aac973d58e091473f5985"), - HL("cafebabefacedbaddecaf888"), - H("4d5c2af327cd64a62cf35abd2ba6fab4")); + SHEX("feffe9928665731c6d6a8f9467308308"), + SHEX(""), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b391aafd255"), + SHEX("42831ec2217774244b7221b784d0d49c" + "e3aa212f2c02a4e035c17e2329aca12e" + "21d514b25466931c7d8f6a5aac84aa05" + "1ba30b396a0aac973d58e091473f5985"), + SHEX("cafebabefacedbaddecaf888"), + SHEX("4d5c2af327cd64a62cf35abd2ba6fab4")); /* Test case 4 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("42831ec2217774244b7221b784d0d49c" - "e3aa212f2c02a4e035c17e2329aca12e" - "21d514b25466931c7d8f6a5aac84aa05" - "1ba30b396a0aac973d58e091"), - HL("cafebabefacedbaddecaf888"), - H("5bc94fbc3221a5db94fae95ae7121a47")); + SHEX("feffe9928665731c6d6a8f9467308308"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("42831ec2217774244b7221b784d0d49c" + "e3aa212f2c02a4e035c17e2329aca12e" + "21d514b25466931c7d8f6a5aac84aa05" + "1ba30b396a0aac973d58e091"), + SHEX("cafebabefacedbaddecaf888"), + SHEX("5bc94fbc3221a5db94fae95ae7121a47")); /* Test case 5 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("61353b4c2806934a777ff51fa22a4755" - "699b2a714fcdc6f83766e5f97b6c7423" - "73806900e49f24b22b097544d4896b42" - "4989b5e1ebac0f07c23f4598"), - HL("cafebabefacedbad"), - H("3612d2e79e3b0785561be14aaca2fccb")); + SHEX("feffe9928665731c6d6a8f9467308308"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("61353b4c2806934a777ff51fa22a4755" + "699b2a714fcdc6f83766e5f97b6c7423" + "73806900e49f24b22b097544d4896b42" + "4989b5e1ebac0f07c23f4598"), + SHEX("cafebabefacedbad"), + SHEX("3612d2e79e3b0785561be14aaca2fccb")); /* Test case 6 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("8ce24998625615b603a033aca13fb894" - "be9112a5c3a211a8ba262a3cca7e2ca7" - "01e4a9a4fba43c90ccdcb281d48c7c6f" - "d62875d2aca417034c34aee5"), - HL("9313225df88406e555909c5aff5269aa" - "6a7a9538534f7da1e4c303d2a318a728" - "c3c0c95156809539fcf0e2429a6b5254" - "16aedbf5a0de6a57a637b39b"), - H("619cc5aefffe0bfa462af43c1699d050")); + SHEX("feffe9928665731c6d6a8f9467308308"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("8ce24998625615b603a033aca13fb894" + "be9112a5c3a211a8ba262a3cca7e2ca7" + "01e4a9a4fba43c90ccdcb281d48c7c6f" + "d62875d2aca417034c34aee5"), + SHEX("9313225df88406e555909c5aff5269aa" + "6a7a9538534f7da1e4c303d2a318a728" + "c3c0c95156809539fcf0e2429a6b5254" + "16aedbf5a0de6a57a637b39b"), + SHEX("619cc5aefffe0bfa462af43c1699d050")); /* Test case 7 */ test_aead(&nettle_gcm_aes128, - HL("00000000000000000000000000000000" - "0000000000000000"), - HL(""), - HL(""), - H(""), - HL("000000000000000000000000"), - H("cd33b28ac773f74ba00ed1f312572435")); + SHEX("00000000000000000000000000000000" + "0000000000000000"), + SHEX(""), + SHEX(""), + SHEX(""), + SHEX("000000000000000000000000"), + SHEX("cd33b28ac773f74ba00ed1f312572435")); /* Test case 8 */ test_aead(&nettle_gcm_aes128, - HL("00000000000000000000000000000000" - "0000000000000000"), - HL(""), - HL("00000000000000000000000000000000"), - H("98e7247c07f0fe411c267e4384b0f600"), - HL("000000000000000000000000"), - H("2ff58d80033927ab8ef4d4587514f0fb")); + SHEX("00000000000000000000000000000000" + "0000000000000000"), + SHEX(""), + SHEX("00000000000000000000000000000000"), + SHEX("98e7247c07f0fe411c267e4384b0f600"), + SHEX("000000000000000000000000"), + SHEX("2ff58d80033927ab8ef4d4587514f0fb")); /* Test case 9 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308" - "feffe9928665731c"), - HL(""), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b391aafd255"), - H("3980ca0b3c00e841eb06fac4872a2757" - "859e1ceaa6efd984628593b40ca1e19c" - "7d773d00c144c525ac619d18c84a3f47" - "18e2448b2fe324d9ccda2710acade256"), - HL("cafebabefacedbaddecaf888"), - H("9924a7c8587336bfb118024db8674a14")); + SHEX("feffe9928665731c6d6a8f9467308308" + "feffe9928665731c"), + SHEX(""), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b391aafd255"), + SHEX("3980ca0b3c00e841eb06fac4872a2757" + "859e1ceaa6efd984628593b40ca1e19c" + "7d773d00c144c525ac619d18c84a3f47" + "18e2448b2fe324d9ccda2710acade256"), + SHEX("cafebabefacedbaddecaf888"), + SHEX("9924a7c8587336bfb118024db8674a14")); /* Test case 10 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308" - "feffe9928665731c"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("3980ca0b3c00e841eb06fac4872a2757" - "859e1ceaa6efd984628593b40ca1e19c" - "7d773d00c144c525ac619d18c84a3f47" - "18e2448b2fe324d9ccda2710"), - HL("cafebabefacedbaddecaf888"), - H("2519498e80f1478f37ba55bd6d27618c")); + SHEX("feffe9928665731c6d6a8f9467308308" + "feffe9928665731c"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("3980ca0b3c00e841eb06fac4872a2757" + "859e1ceaa6efd984628593b40ca1e19c" + "7d773d00c144c525ac619d18c84a3f47" + "18e2448b2fe324d9ccda2710"), + SHEX("cafebabefacedbaddecaf888"), + SHEX("2519498e80f1478f37ba55bd6d27618c")); /* Test case 11 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308" - "feffe9928665731c"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("0f10f599ae14a154ed24b36e25324db8" - "c566632ef2bbb34f8347280fc4507057" - "fddc29df9a471f75c66541d4d4dad1c9" - "e93a19a58e8b473fa0f062f7"), - HL("cafebabefacedbad"), - H("65dcc57fcf623a24094fcca40d3533f8")); + SHEX("feffe9928665731c6d6a8f9467308308" + "feffe9928665731c"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("0f10f599ae14a154ed24b36e25324db8" + "c566632ef2bbb34f8347280fc4507057" + "fddc29df9a471f75c66541d4d4dad1c9" + "e93a19a58e8b473fa0f062f7"), + SHEX("cafebabefacedbad"), + SHEX("65dcc57fcf623a24094fcca40d3533f8")); /* Test case 12 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308" - "feffe9928665731c"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("d27e88681ce3243c4830165a8fdcf9ff" - "1de9a1d8e6b447ef6ef7b79828666e45" - "81e79012af34ddd9e2f037589b292db3" - "e67c036745fa22e7e9b7373b"), - HL("9313225df88406e555909c5aff5269aa" - "6a7a9538534f7da1e4c303d2a318a728" - "c3c0c95156809539fcf0e2429a6b5254" - "16aedbf5a0de6a57a637b39b"), - H("dcf566ff291c25bbb8568fc3d376a6d9")); + SHEX("feffe9928665731c6d6a8f9467308308" + "feffe9928665731c"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("d27e88681ce3243c4830165a8fdcf9ff" + "1de9a1d8e6b447ef6ef7b79828666e45" + "81e79012af34ddd9e2f037589b292db3" + "e67c036745fa22e7e9b7373b"), + SHEX("9313225df88406e555909c5aff5269aa" + "6a7a9538534f7da1e4c303d2a318a728" + "c3c0c95156809539fcf0e2429a6b5254" + "16aedbf5a0de6a57a637b39b"), + SHEX("dcf566ff291c25bbb8568fc3d376a6d9")); /* Test case 13 */ test_aead(&nettle_gcm_aes128, - HL("00000000000000000000000000000000" - "00000000000000000000000000000000"), - HL(""), - HL(""), - H(""), - HL("000000000000000000000000"), - H("530f8afbc74536b9a963b4f1c4cb738b")); + SHEX("00000000000000000000000000000000" + "00000000000000000000000000000000"), + SHEX(""), + SHEX(""), + SHEX(""), + SHEX("000000000000000000000000"), + SHEX("530f8afbc74536b9a963b4f1c4cb738b")); /* Test case 14 */ test_aead(&nettle_gcm_aes128, - HL("00000000000000000000000000000000" - "00000000000000000000000000000000"), - HL(""), - HL("00000000000000000000000000000000"), - H("cea7403d4d606b6e074ec5d3baf39d18"), - HL("000000000000000000000000"), - H("d0d1c8a799996bf0265b98b5d48ab919")); + SHEX("00000000000000000000000000000000" + "00000000000000000000000000000000"), + SHEX(""), + SHEX("00000000000000000000000000000000"), + SHEX("cea7403d4d606b6e074ec5d3baf39d18"), + SHEX("000000000000000000000000"), + SHEX("d0d1c8a799996bf0265b98b5d48ab919")); /* Test case 15 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308" - "feffe9928665731c6d6a8f9467308308"), - HL(""), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b391aafd255"), - H("522dc1f099567d07f47f37a32a84427d" - "643a8cdcbfe5c0c97598a2bd2555d1aa" - "8cb08e48590dbb3da7b08b1056828838" - "c5f61e6393ba7a0abcc9f662898015ad"), - HL("cafebabefacedbaddecaf888"), - H("b094dac5d93471bdec1a502270e3cc6c")); + SHEX("feffe9928665731c6d6a8f9467308308" + "feffe9928665731c6d6a8f9467308308"), + SHEX(""), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b391aafd255"), + SHEX("522dc1f099567d07f47f37a32a84427d" + "643a8cdcbfe5c0c97598a2bd2555d1aa" + "8cb08e48590dbb3da7b08b1056828838" + "c5f61e6393ba7a0abcc9f662898015ad"), + SHEX("cafebabefacedbaddecaf888"), + SHEX("b094dac5d93471bdec1a502270e3cc6c")); /* Test case 16 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308" - "feffe9928665731c6d6a8f9467308308"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("522dc1f099567d07f47f37a32a84427d" - "643a8cdcbfe5c0c97598a2bd2555d1aa" - "8cb08e48590dbb3da7b08b1056828838" - "c5f61e6393ba7a0abcc9f662"), - HL("cafebabefacedbaddecaf888"), - H("76fc6ece0f4e1768cddf8853bb2d551b")); + SHEX("feffe9928665731c6d6a8f9467308308" + "feffe9928665731c6d6a8f9467308308"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("522dc1f099567d07f47f37a32a84427d" + "643a8cdcbfe5c0c97598a2bd2555d1aa" + "8cb08e48590dbb3da7b08b1056828838" + "c5f61e6393ba7a0abcc9f662"), + SHEX("cafebabefacedbaddecaf888"), + SHEX("76fc6ece0f4e1768cddf8853bb2d551b")); /* Test case 17 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308" - "feffe9928665731c6d6a8f9467308308"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("c3762df1ca787d32ae47c13bf19844cb" - "af1ae14d0b976afac52ff7d79bba9de0" - "feb582d33934a4f0954cc2363bc73f78" - "62ac430e64abe499f47c9b1f"), - HL("cafebabefacedbad"), - H("3a337dbf46a792c45e454913fe2ea8f2")); + SHEX("feffe9928665731c6d6a8f9467308308" + "feffe9928665731c6d6a8f9467308308"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("c3762df1ca787d32ae47c13bf19844cb" + "af1ae14d0b976afac52ff7d79bba9de0" + "feb582d33934a4f0954cc2363bc73f78" + "62ac430e64abe499f47c9b1f"), + SHEX("cafebabefacedbad"), + SHEX("3a337dbf46a792c45e454913fe2ea8f2")); /* Test case 18 */ test_aead(&nettle_gcm_aes128, - HL("feffe9928665731c6d6a8f9467308308" - "feffe9928665731c6d6a8f9467308308"), - HL("feedfacedeadbeeffeedfacedeadbeef" - "abaddad2"), - HL("d9313225f88406e5a55909c5aff5269a" - "86a7a9531534f7da2e4c303d8a318a72" - "1c3c0c95956809532fcf0e2449a6b525" - "b16aedf5aa0de657ba637b39"), - H("5a8def2f0c9e53f1f75d7853659e2a20" - "eeb2b22aafde6419a058ab4f6f746bf4" - "0fc0c3b780f244452da3ebf1c5d82cde" - "a2418997200ef82e44ae7e3f"), - HL("9313225df88406e555909c5aff5269aa" - "6a7a9538534f7da1e4c303d2a318a728" - "c3c0c95156809539fcf0e2429a6b5254" - "16aedbf5a0de6a57a637b39b"), - H("a44a8266ee1c8eb0c8b5d4cf5ae9f19a")); - - SUCCESS(); + SHEX("feffe9928665731c6d6a8f9467308308" + "feffe9928665731c6d6a8f9467308308"), + SHEX("feedfacedeadbeeffeedfacedeadbeef" + "abaddad2"), + SHEX("d9313225f88406e5a55909c5aff5269a" + "86a7a9531534f7da2e4c303d8a318a72" + "1c3c0c95956809532fcf0e2449a6b525" + "b16aedf5aa0de657ba637b39"), + SHEX("5a8def2f0c9e53f1f75d7853659e2a20" + "eeb2b22aafde6419a058ab4f6f746bf4" + "0fc0c3b780f244452da3ebf1c5d82cde" + "a2418997200ef82e44ae7e3f"), + SHEX("9313225df88406e555909c5aff5269aa" + "6a7a9538534f7da1e4c303d2a318a728" + "c3c0c95156809539fcf0e2429a6b5254" + "16aedbf5a0de6a57a637b39b"), + SHEX("a44a8266ee1c8eb0c8b5d4cf5ae9f19a")); } diff --git a/testsuite/hmac-test.c b/testsuite/hmac-test.c index 0f149346..9156cc40 100644 --- a/testsuite/hmac-test.c +++ b/testsuite/hmac-test.c @@ -1,27 +1,21 @@ #include "testutils.h" #include "hmac.h" -/* KEY and MSG are supposed to expand to length, data */ -#define HMAC_TEST(alg, length, key, msg, mac) do { \ - hmac_##alg##_set_key(&alg, key); \ - hmac_##alg##_update(&alg, msg); \ - digest[length] = 17; \ - hmac_##alg##_digest(&alg, length, digest); \ - ASSERT(MEMEQ (length, digest, mac)); \ - ASSERT(digest[length] == 17); \ -} while (0) - -int +#define HMAC_TEST(alg, key, msg, mac) \ + do { \ + struct hmac_##alg##_ctx ctx; \ + \ + hmac_##alg##_set_key(&ctx, key->length, key->data); \ + hmac_##alg##_update(&ctx, msg->length, msg->data); \ + digest[mac->length] = 17; \ + hmac_##alg##_digest(&ctx, mac->length, digest); \ + ASSERT(MEMEQ (mac->length, digest, mac->data)); \ + ASSERT(digest[mac->length] == 17); \ + } while (0) + +void test_main(void) { - struct hmac_md5_ctx md5; - struct hmac_sha1_ctx sha1; - struct hmac_ripemd160_ctx ripemd160; - struct hmac_sha224_ctx sha224; - struct hmac_sha256_ctx sha256; - struct hmac_sha384_ctx sha384; - struct hmac_sha512_ctx sha512; - /* sha512's digests are longest */ uint8_t digest[SHA512_DIGEST_SIZE+1]; @@ -30,876 +24,874 @@ test_main(void) /* Test vectors for md5, from RFC-2202 */ /* md5 - 1 */ - HMAC_TEST(md5, MD5_DIGEST_SIZE, - HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"), - LDATA("Hi There"), - H("9294727a3638bb1c 13f48ef8158bfc9d")); + HMAC_TEST(md5, + SHEX("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"), + SDATA("Hi There"), + SHEX("9294727a3638bb1c 13f48ef8158bfc9d")); /* md5 - 2 */ - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("Jefe"), - LDATA("what do ya want for nothing?"), - H("750c783e6ab0b503 eaa86e310a5db738")); + HMAC_TEST(md5, + SDATA("Jefe"), + SDATA("what do ya want for nothing?"), + SHEX("750c783e6ab0b503 eaa86e310a5db738")); /* md5 - 3 */ - HMAC_TEST(md5, MD5_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), - HL("dddddddddddddddd dddddddddddddddd" - "dddddddddddddddd dddddddddddddddd" - "dddddddddddddddd dddddddddddddddd" - "dddd"), - H("56be34521d144c88 dbb8c733f0e8b3f6")); + HMAC_TEST(md5, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), + SHEX("dddddddddddddddd dddddddddddddddd" + "dddddddddddddddd dddddddddddddddd" + "dddddddddddddddd dddddddddddddddd" + "dddd"), + SHEX("56be34521d144c88 dbb8c733f0e8b3f6")); /* md5 - 4 */ - HMAC_TEST(md5, MD5_DIGEST_SIZE, - HL("0102030405060708 090a0b0c0d0e0f10" - "1112131415161718 19"), - HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcd"), - H("697eaf0aca3a3aea 3a75164746ffaa79")); + HMAC_TEST(md5, + SHEX("0102030405060708 090a0b0c0d0e0f10" + "1112131415161718 19"), + SHEX("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcd"), + SHEX("697eaf0aca3a3aea 3a75164746ffaa79")); /* md5 - 5 */ - HMAC_TEST(md5, 12, - HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"), - LDATA("Test With Truncation"), - H("56461ef2342edc00 f9bab995")); + HMAC_TEST(md5, + SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"), + SDATA("Test With Truncation"), + SHEX("56461ef2342edc00 f9bab995")); /* md5 - 6 */ - HMAC_TEST(md5, MD5_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), - LDATA("Test Using Larger Than Block-Size Key - Hash Key First"), - H("6b1ab7fe4bd7bf8f 0b62e6ce61b9d0cd")); + HMAC_TEST(md5, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), + SDATA("Test Using Larger Than Block-Size Key - Hash Key First"), + SHEX("6b1ab7fe4bd7bf8f 0b62e6ce61b9d0cd")); /* md5 - 7 */ - HMAC_TEST(md5, MD5_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), - LDATA("Test Using Larger Than Block-Size Key and Larger " + HMAC_TEST(md5, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), + SDATA("Test Using Larger Than Block-Size Key and Larger " "Than One Block-Size Data"), - H("6f630fad67cda0ee 1fb1f562db3aa53e")); + SHEX("6f630fad67cda0ee 1fb1f562db3aa53e")); /* Additional test vectors, from Daniel Kahn Gillmor */ - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA(""), - H("e84db42a188813f30a15e611d64c7869")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA(""), + SHEX("e84db42a188813f30a15e611d64c7869")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("a"), - H("123662062e67c2aab371cc49db0df134")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("a"), + SHEX("123662062e67c2aab371cc49db0df134")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("38"), - H("0a46cc10a49d4b7025c040c597bf5d76")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("38"), + SHEX("0a46cc10a49d4b7025c040c597bf5d76")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("abc"), - H("d1f4d89f0e8b2b6ed0623c99ec298310")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("abc"), + SHEX("d1f4d89f0e8b2b6ed0623c99ec298310")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("message digest"), - H("1627207b9bed5009a4f6e9ca8d2ca01e")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("message digest"), + SHEX("1627207b9bed5009a4f6e9ca8d2ca01e")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("abcdefghijklmnopqrstuvwxyz"), - H("922aae6ab3b3a29202e21ce5f916ae9a")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("922aae6ab3b3a29202e21ce5f916ae9a")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), - H("ede9cb83679ba82d88fbeae865b3f8fc")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("ede9cb83679ba82d88fbeae865b3f8fc")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), - H("939dd45512ee3a594b6654f6b8de27f7")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), + SHEX("939dd45512ee3a594b6654f6b8de27f7")); /* Test vectors for ripemd160, from http://homes.esat.kuleuven.be/~bosselae/ripemd160.html */ - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("00112233445566778899aabbccddeeff01234567"), - LDATA(""), - H("cf387677bfda8483e63b57e06c3b5ecd8b7fc055")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("00112233445566778899aabbccddeeff01234567"), - LDATA("a"), - H("0d351d71b78e36dbb7391c810a0d2b6240ddbafc")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("00112233445566778899aabbccddeeff01234567"), - LDATA("abc"), - H("f7ef288cb1bbcc6160d76507e0a3bbf712fb67d6")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("00112233445566778899aabbccddeeff01234567"), - LDATA("message digest"), - H("f83662cc8d339c227e600fcd636c57d2571b1c34")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("00112233445566778899aabbccddeeff01234567"), - LDATA("abcdefghijklmnopqrstuvwxyz"), - H("843d1c4eb880ac8ac0c9c95696507957d0155ddb")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("00112233445566778899aabbccddeeff01234567"), - LDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), - H("60f5ef198a2dd5745545c1f0c47aa3fb5776f881")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("00112233445566778899aabbccddeeff01234567"), - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), - H("e49c136a9e5627e0681b808a3b97e6a6e661ae79")); + HMAC_TEST(ripemd160, + SHEX("00112233445566778899aabbccddeeff01234567"), + SDATA(""), + SHEX("cf387677bfda8483e63b57e06c3b5ecd8b7fc055")); + + HMAC_TEST(ripemd160, + SHEX("00112233445566778899aabbccddeeff01234567"), + SDATA("a"), + SHEX("0d351d71b78e36dbb7391c810a0d2b6240ddbafc")); + + HMAC_TEST(ripemd160, + SHEX("00112233445566778899aabbccddeeff01234567"), + SDATA("abc"), + SHEX("f7ef288cb1bbcc6160d76507e0a3bbf712fb67d6")); + + HMAC_TEST(ripemd160, + SHEX("00112233445566778899aabbccddeeff01234567"), + SDATA("message digest"), + SHEX("f83662cc8d339c227e600fcd636c57d2571b1c34")); + + HMAC_TEST(ripemd160, + SHEX("00112233445566778899aabbccddeeff01234567"), + SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("843d1c4eb880ac8ac0c9c95696507957d0155ddb")); + + HMAC_TEST(ripemd160, + SHEX("00112233445566778899aabbccddeeff01234567"), + SDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), + SHEX("60f5ef198a2dd5745545c1f0c47aa3fb5776f881")); + + HMAC_TEST(ripemd160, + SHEX("00112233445566778899aabbccddeeff01234567"), + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("e49c136a9e5627e0681b808a3b97e6a6e661ae79")); /* Other key */ - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("0123456789abcdeffedcba987654321000112233"), - LDATA(""), - H("fe69a66c7423eea9c8fa2eff8d9dafb4f17a62f5")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("0123456789abcdeffedcba987654321000112233"), - LDATA("a"), - H("85743e899bc82dbfa36faaa7a25b7cfd372432cd")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("0123456789abcdeffedcba987654321000112233"), - LDATA("abc"), - H("6e4afd501fa6b4a1823ca3b10bd9aa0ba97ba182")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("0123456789abcdeffedcba987654321000112233"), - LDATA("message digest"), - H("2e066e624badb76a184c8f90fba053330e650e92")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("0123456789abcdeffedcba987654321000112233"), - LDATA("abcdefghijklmnopqrstuvwxyz"), - H("07e942aa4e3cd7c04dedc1d46e2e8cc4c741b3d9")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("0123456789abcdeffedcba987654321000112233"), - LDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), - H("b6582318ddcfb67a53a67d676b8ad869aded629a")); - - HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE, - HL("0123456789abcdeffedcba987654321000112233"), - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), - H("f1be3ee877703140d34f97ea1ab3a07c141333e2")); + HMAC_TEST(ripemd160, + SHEX("0123456789abcdeffedcba987654321000112233"), + SDATA(""), + SHEX("fe69a66c7423eea9c8fa2eff8d9dafb4f17a62f5")); + + HMAC_TEST(ripemd160, + SHEX("0123456789abcdeffedcba987654321000112233"), + SDATA("a"), + SHEX("85743e899bc82dbfa36faaa7a25b7cfd372432cd")); + + HMAC_TEST(ripemd160, + SHEX("0123456789abcdeffedcba987654321000112233"), + SDATA("abc"), + SHEX("6e4afd501fa6b4a1823ca3b10bd9aa0ba97ba182")); + + HMAC_TEST(ripemd160, + SHEX("0123456789abcdeffedcba987654321000112233"), + SDATA("message digest"), + SHEX("2e066e624badb76a184c8f90fba053330e650e92")); + + HMAC_TEST(ripemd160, + SHEX("0123456789abcdeffedcba987654321000112233"), + SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("07e942aa4e3cd7c04dedc1d46e2e8cc4c741b3d9")); + + HMAC_TEST(ripemd160, + SHEX("0123456789abcdeffedcba987654321000112233"), + SDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), + SHEX("b6582318ddcfb67a53a67d676b8ad869aded629a")); + + HMAC_TEST(ripemd160, + SHEX("0123456789abcdeffedcba987654321000112233"), + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("f1be3ee877703140d34f97ea1ab3a07c141333e2")); /* Test vectors for sha1, from RFC-2202 */ /* sha1 - 1 */ - HMAC_TEST(sha1, SHA1_DIGEST_SIZE, - HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b 0b0b0b0b"), - LDATA("Hi There"), - H("b617318655057264 e28bc0b6fb378c8e f146be00")); + HMAC_TEST(sha1, + SHEX("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b 0b0b0b0b"), + SDATA("Hi There"), + SHEX("b617318655057264 e28bc0b6fb378c8e f146be00")); /* sha1 - 2 */ - HMAC_TEST(sha1, SHA1_DIGEST_SIZE, - LDATA("Jefe"), - LDATA("what do ya want for nothing?"), - H("effcdf6ae5eb2fa2 d27416d5f184df9c 259a7c79")); + HMAC_TEST(sha1, + SDATA("Jefe"), + SDATA("what do ya want for nothing?"), + SHEX("effcdf6ae5eb2fa2 d27416d5f184df9c 259a7c79")); /* sha1 - 3 */ - HMAC_TEST(sha1, SHA1_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaa"), - HL("dddddddddddddddd dddddddddddddddd" - "dddddddddddddddd dddddddddddddddd" - "dddddddddddddddd dddddddddddddddd" - "dddd"), - H("125d7342b9ac11cd 91a39af48aa17b4f 63f175d3")); + HMAC_TEST(sha1, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaa"), + SHEX("dddddddddddddddd dddddddddddddddd" + "dddddddddddddddd dddddddddddddddd" + "dddddddddddddddd dddddddddddddddd" + "dddd"), + SHEX("125d7342b9ac11cd 91a39af48aa17b4f 63f175d3")); /* sha1 - 4 */ - HMAC_TEST(sha1, SHA1_DIGEST_SIZE, - HL("0102030405060708 090a0b0c0d0e0f10" - "1112131415161718 19"), - HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcd"), - H("4c9007f4026250c6 bc8414f9bf50c86c 2d7235da")); + HMAC_TEST(sha1, + SHEX("0102030405060708 090a0b0c0d0e0f10" + "1112131415161718 19"), + SHEX("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcd"), + SHEX("4c9007f4026250c6 bc8414f9bf50c86c 2d7235da")); /* sha1 - 5 */ - HMAC_TEST(sha1, 12, - HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"), - LDATA("Test With Truncation"), - H("4c1a03424b55e07f e7f27be1")); + HMAC_TEST(sha1, + SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"), + SDATA("Test With Truncation"), + SHEX("4c1a03424b55e07f e7f27be1")); /* sha1 - 6 */ - HMAC_TEST(sha1, SHA1_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), - LDATA("Test Using Larger Than Block-Size Key - Hash Key First"), - H("aa4ae5e15272d00e 95705637ce8a3b55 ed402112")); + HMAC_TEST(sha1, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), + SDATA("Test Using Larger Than Block-Size Key - Hash Key First"), + SHEX("aa4ae5e15272d00e 95705637ce8a3b55 ed402112")); /* sha1 - 7 */ - HMAC_TEST(sha1, SHA1_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), - LDATA("Test Using Larger Than Block-Size Key and Larger " + HMAC_TEST(sha1, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), + SDATA("Test Using Larger Than Block-Size Key and Larger " "Than One Block-Size Data"), - H("e8e99d0f45237d78 6d6bbaa7965c7808 bbff1a91")); + SHEX("e8e99d0f45237d78 6d6bbaa7965c7808 bbff1a91")); /* Additional test vectors, from Daniel Kahn Gillmor */ - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA(""), - H("e84db42a188813f30a15e611d64c7869")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA(""), + SHEX("e84db42a188813f30a15e611d64c7869")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("a"), - H("123662062e67c2aab371cc49db0df134")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("a"), + SHEX("123662062e67c2aab371cc49db0df134")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("38"), - H("0a46cc10a49d4b7025c040c597bf5d76")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("38"), + SHEX("0a46cc10a49d4b7025c040c597bf5d76")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("abc"), - H("d1f4d89f0e8b2b6ed0623c99ec298310")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("abc"), + SHEX("d1f4d89f0e8b2b6ed0623c99ec298310")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("message digest"), - H("1627207b9bed5009a4f6e9ca8d2ca01e")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("message digest"), + SHEX("1627207b9bed5009a4f6e9ca8d2ca01e")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("abcdefghijklmnopqrstuvwxyz"), - H("922aae6ab3b3a29202e21ce5f916ae9a")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("922aae6ab3b3a29202e21ce5f916ae9a")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), - H("ede9cb83679ba82d88fbeae865b3f8fc")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("ede9cb83679ba82d88fbeae865b3f8fc")); - HMAC_TEST(md5, MD5_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), - H("939dd45512ee3a594b6654f6b8de27f7")); + HMAC_TEST(md5, + SDATA("monkey monkey monkey monkey"), + SDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), + SHEX("939dd45512ee3a594b6654f6b8de27f7")); /* 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" + HMAC_TEST(sha224, + SHEX("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" + "0b0b0b0b"), + SDATA("Hi There"), + SHEX("896fb1128abbdf196832107cd49df33f" + "47b4b1169912ba4f53684b22")); + + HMAC_TEST(sha224, + SDATA("Jefe"), + SDATA("what do ya want for nothing?"), + SHEX("a30e01098bc6dbbf45690f3a7e9e6d0f" + "8bbea2a39e6148008fd05e44")); + + HMAC_TEST(sha224, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaa"), + SHEX("dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddd"), + SHEX("7fb3cb3588c6c1f6ffa9694d7d6ad264" + "9365b0c1f65d69d1ec8333ea")); + + HMAC_TEST(sha224, + SHEX("0102030405060708090a0b0c0d0e0f10" + "111213141516171819"), + SHEX("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcd"), + SHEX("6c11506874013cac6a2abc1bb382627c" + "ec6a90d86efc012de7afec5a")); + + HMAC_TEST(sha224, + SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"), + SDATA("Test With Truncation"), + SHEX("0e2aea68a90c8d37c988bcdb9fca6fa8")); + + HMAC_TEST(sha224, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaa"), + SDATA("Test Using Larger Than Block-Size Key - Hash Key First"), + SHEX("95e9a0db962095adaebe9b2d6f0dbce2" + "d499f112f2d2b7273fa6870e")); + + HMAC_TEST(sha224, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaa"), + SDATA("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")); + SHEX("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, + SDATA("monkey monkey monkey monkey"), + SDATA(""), + SHEX("d12a49ae38177ffeaa548b2148bb5238" + "60849772d9391e675b103d89")); - HMAC_TEST(sha224, SHA224_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("a"), - H("b04ff8522f904f553970bfa8ad3f0086" - "bce1e8580affd8a12c94e31a")); + HMAC_TEST(sha224, + SDATA("monkey monkey monkey monkey"), + SDATA("a"), + SHEX("b04ff8522f904f553970bfa8ad3f0086" + "bce1e8580affd8a12c94e31a")); - HMAC_TEST(sha224, SHA224_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("38"), - H("afcfb5511f710334f9350f57faec3c08" - "764b4bd126a6840f4347f116")); + HMAC_TEST(sha224, + SDATA("monkey monkey monkey monkey"), + SDATA("38"), + SHEX("afcfb5511f710334f9350f57faec3c08" + "764b4bd126a6840f4347f116")); - HMAC_TEST(sha224, SHA224_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("abc"), - H("9df9907af127900c909376893565c6cf" - "2d7db244fdc4277da1e0b679")); + HMAC_TEST(sha224, + SDATA("monkey monkey monkey monkey"), + SDATA("abc"), + SHEX("9df9907af127900c909376893565c6cf" + "2d7db244fdc4277da1e0b679")); - HMAC_TEST(sha224, SHA224_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("message digest"), - H("254ebf6b8ddd7a3271b3d9aca1699b0c" - "0bfb7df61e8a114922c88d27")); + HMAC_TEST(sha224, + SDATA("monkey monkey monkey monkey"), + SDATA("message digest"), + SHEX("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")); + HMAC_TEST(sha224, + SDATA("monkey monkey monkey monkey"), + SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("6ec5bffba5880c3234a6cf257816e4d5" + "35ab178a7f12929769e378fb")); + + HMAC_TEST(sha224, + SDATA("monkey monkey monkey monkey"), + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("5f768179dbb29ca722875d0f461a2e2f" + "597d0210340a84df1a8e9c63")); + + HMAC_TEST(sha224, + SDATA("monkey monkey monkey monkey"), + SDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), + SHEX("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" + HMAC_TEST(sha256, + SHEX("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" + "0b0b0b0b"), + SDATA("Hi There"), + SHEX("b0344c61d8db38535ca8afceaf0bf12b" + "881dc200c9833da726e9376c2e32cff7")); + + HMAC_TEST(sha256, + SDATA("Jefe"), + SDATA("what do ya want for nothing?"), + SHEX("5bdcc146bf60754e6a042426089575c7" + "5a003f089d2739839dec58b964ec3843")); + + HMAC_TEST(sha256, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaa"), + SHEX("dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddd"), + SHEX("773ea91e36800e46854db8ebd09181a7" + "2959098b3ef8c122d9635514ced565fe")); + + HMAC_TEST(sha256, + SHEX("0102030405060708090a0b0c0d0e0f10" + "111213141516171819"), + SHEX("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcd"), + SHEX("82558a389a443c0ea4cc819899f2083a" + "85f0faa3e578f8077a2e3ff46729665b")); + + HMAC_TEST(sha256, + SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"), + SDATA("Test With Truncation"), + SHEX("a3b6167473100ee06e0c796c2955552b")); + + HMAC_TEST(sha256, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaa"), + SDATA("Test Using Larger Than Block-Size Key - Hash Key First"), + SHEX("60e431591ee0b67f0d8a26aacbf5b77f" + "8e0bc6213728c5140546040f0ee37f54")); + + HMAC_TEST(sha256, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaa"), + SDATA("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")); + SHEX("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 */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - HL("0102030405060708 090a0b0c0d0e0f10" - "1112131415161718 191a1b1c1d1e1f20"), - LDATA("abc"), - H("a21b1f5d4cf4f73a 4dd939750f7a066a" + HMAC_TEST(sha256, + SHEX("0102030405060708 090a0b0c0d0e0f10" + "1112131415161718 191a1b1c1d1e1f20"), + SDATA("abc"), + SHEX("a21b1f5d4cf4f73a 4dd939750f7a066a" "7f98cc131cb16a66 92759021cfab8181")); /* Test Case #2: HMAC-SHA-256 with 56-byte input and 32-byte key */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - HL("0102030405060708 090a0b0c0d0e0f10" - "1112131415161718 191a1b1c1d1e1f20"), - LDATA("abcdbcdecdefdefgefghfghighijhijk" + HMAC_TEST(sha256, + SHEX("0102030405060708 090a0b0c0d0e0f10" + "1112131415161718 191a1b1c1d1e1f20"), + SDATA("abcdbcdecdefdefgefghfghighijhijk" "ijkljklmklmnlmnomnopnopq"), - H("104fdc1257328f08 184ba73131c53cae" + SHEX("104fdc1257328f08 184ba73131c53cae" "e698e36119421149 ea8c712456697d30")); /* Test Case #3: HMAC-SHA-256 with 112-byte (multi-block) input and 32-byte key */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - HL("0102030405060708 090a0b0c0d0e0f10" - "1112131415161718 191a1b1c1d1e1f20"), - LDATA("abcdbcdecdefdefgefghfghighijhijk" + HMAC_TEST(sha256, + SHEX("0102030405060708 090a0b0c0d0e0f10" + "1112131415161718 191a1b1c1d1e1f20"), + SDATA("abcdbcdecdefdefgefghfghighijhijk" "ijkljklmklmnlmnomnopnopqabcdbcde" "cdefdefgefghfghighijhijkijkljklm" "klmnlmnomnopnopq"), - H("470305fc7e40fe34 d3eeb3e773d95aab" - "73acf0fd060447a5 eb4595bf33a9d1a3")); + SHEX("470305fc7e40fe34 d3eeb3e773d95aab" + "73acf0fd060447a5 eb4595bf33a9d1a3")); /* Test Case #4: HMAC-SHA-256 with 8-byte input and 32-byte key */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b" - "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"), - LDATA("Hi There"), - H("198a607eb44bfbc6 9903a0f1cf2bbdc5" - "ba0aa3f3d9ae3c1c 7a3b1696a0b68cf7")); + HMAC_TEST(sha256, + SHEX("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b" + "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"), + SDATA("Hi There"), + SHEX("198a607eb44bfbc6 9903a0f1cf2bbdc5" + "ba0aa3f3d9ae3c1c 7a3b1696a0b68cf7")); /* Test Case #6: HMAC-SHA-256 with 50-byte input and 32-byte key */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), - HL("dddddddddddddddd dddddddddddddddd" - "dddddddddddddddd dddddddddddddddd" - "dddddddddddddddd dddddddddddddddd" - "dddd"), - H("cdcb1220d1ecccea 91e53aba3092f962" - "e549fe6ce9ed7fdc 43191fbde45c30b0")); + HMAC_TEST(sha256, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), + SHEX("dddddddddddddddd dddddddddddddddd" + "dddddddddddddddd dddddddddddddddd" + "dddddddddddddddd dddddddddddddddd" + "dddd"), + SHEX("cdcb1220d1ecccea 91e53aba3092f962" + "e549fe6ce9ed7fdc 43191fbde45c30b0")); /* Test Case #7: HMAC-SHA-256 with 50-byte input and 37-byte key */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - HL("0102030405060708 090a0b0c0d0e0f10" - "1112131415161718 191a1b1c1d1e1f20" - "2122232425"), - HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" - "cdcd"), - H("d4633c17f6fb8d74 4c66dee0f8f07455" - "6ec4af55ef079985 41468eb49bd2e917")); + HMAC_TEST(sha256, + SHEX("0102030405060708 090a0b0c0d0e0f10" + "1112131415161718 191a1b1c1d1e1f20" + "2122232425"), + SHEX("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd" + "cdcd"), + SHEX("d4633c17f6fb8d74 4c66dee0f8f07455" + "6ec4af55ef079985 41468eb49bd2e917")); /* Test Case #8: HMAC-SHA-256 with 20-byte input and 32-byte key */ - HMAC_TEST(sha256, 16, - HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c" - "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"), - LDATA("Test With Truncation"), - H("7546af01841fc09b 1ab9c3749a5f1c17")); + HMAC_TEST(sha256, + SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c" + "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"), + SDATA("Test With Truncation"), + SHEX("7546af01841fc09b 1ab9c3749a5f1c17")); /* Test Case #9: HMAC-SHA-256 with 54-byte input and 80-byte key */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), - LDATA("Test Using Larger Than Block-Size Key - Hash Key First"), - H("6953025ed96f0c09 f80a96f78e6538db" - "e2e7b820e3dd970e 7ddd39091b32352f")); + HMAC_TEST(sha256, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), + SDATA("Test Using Larger Than Block-Size Key - Hash Key First"), + SHEX("6953025ed96f0c09 f80a96f78e6538db" + "e2e7b820e3dd970e 7ddd39091b32352f")); /* Test Case #10: HMAC-SHA-256 with 73-byte (multi-block) input and 80-byte key */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), - LDATA("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"), - H("6355ac22e890d0a3 c8481a5ca4825bc8" - "84d3e7a1ff98a2fc 2ac7d8e064c3b2e6")); + HMAC_TEST(sha256, + SHEX("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"), + SDATA("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"), + SHEX("6355ac22e890d0a3 c8481a5ca4825bc8" + "84d3e7a1ff98a2fc 2ac7d8e064c3b2e6")); /* Additional test vectors, from Daniel Kahn Gillmor */ - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA(""), - H("5c780648c90d121c50091c3a0c3afc1f" - "4ab847528005d99d9821ad3f341b651a")); + HMAC_TEST(sha256, + SDATA("monkey monkey monkey monkey"), + SDATA(""), + SHEX("5c780648c90d121c50091c3a0c3afc1f" + "4ab847528005d99d9821ad3f341b651a")); - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("a"), - H("6142364c0646b0cfe426866f21d613e0" - "55a136a7d9b45d85685e080a09cec463")); + HMAC_TEST(sha256, + SDATA("monkey monkey monkey monkey"), + SDATA("a"), + SHEX("6142364c0646b0cfe426866f21d613e0" + "55a136a7d9b45d85685e080a09cec463")); - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("38"), - H("e49aa7839977e130ad87b63da9d4eb7b" - "263cd5a27c54a7604b6044eb35901171")); + HMAC_TEST(sha256, + SDATA("monkey monkey monkey monkey"), + SDATA("38"), + SHEX("e49aa7839977e130ad87b63da9d4eb7b" + "263cd5a27c54a7604b6044eb35901171")); - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("abc"), - H("e5ef49f545c7af933a9d18c7c562bc91" - "08583fd5cf00d9e0db351d6d8f8e41bc")); + HMAC_TEST(sha256, + SDATA("monkey monkey monkey monkey"), + SDATA("abc"), + SHEX("e5ef49f545c7af933a9d18c7c562bc91" + "08583fd5cf00d9e0db351d6d8f8e41bc")); - HMAC_TEST(sha256, SHA256_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("message digest"), - H("373b04877180fea27a41a8fb8f88201c" - "a6268411ee3c80b01a424483eb9156e1")); + HMAC_TEST(sha256, + SDATA("monkey monkey monkey monkey"), + SDATA("message digest"), + SHEX("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")); + HMAC_TEST(sha256, + SDATA("monkey monkey monkey monkey"), + SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("eb5945d56eefbdb41602946ea6448d53" + "86b08d7d801a87f439fab52f8bb9736e")); + + HMAC_TEST(sha256, + SDATA("monkey monkey monkey monkey"), + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("3798f363c57afa6edaffe39016ca7bad" + "efd1e670afb0e3987194307dec3197db")); + + HMAC_TEST(sha256, + SDATA("monkey monkey monkey monkey"), + SDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), + SHEX("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" + HMAC_TEST(sha384, + SHEX("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" + "0b0b0b0b"), + SDATA("Hi There"), + SHEX("afd03944d84895626b0825f4ab46907f" + "15f9dadbe4101ec682aa034c7cebc59c" + "faea9ea9076ede7f4af152e8b2fa9cb6")); + + HMAC_TEST(sha384, + SDATA("Jefe"), + SDATA("what do ya want for nothing?"), + SHEX("af45d2e376484031617f78d2b58a6b1b" + "9c7ef464f5a01b47e42ec3736322445e" + "8e2240ca5e69e2c78b3239ecfab21649")); + + HMAC_TEST(sha384, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaa"), + SHEX("dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddd"), + SHEX("88062608d3e6ad8a0aa2ace014c8a86f" + "0aa635d947ac9febe83ef4e55966144b" + "2a5ab39dc13814b94e3ab6e101a34f27")); + + HMAC_TEST(sha384, + SHEX("0102030405060708090a0b0c0d0e0f10" + "111213141516171819"), + SHEX("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcd"), + SHEX("3e8a69b7783c25851933ab6290af6ca7" + "7a9981480850009cc5577c6e1f573b4e" + "6801dd23c4a7d679ccf8a386c674cffb")); + + HMAC_TEST(sha384, + SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"), + SDATA("Test With Truncation"), + SHEX("3abf34c3503b2a23a46efc619baef897")); + + HMAC_TEST(sha384, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaa"), + SDATA("Test Using Larger Than Block-Size Key - Hash Key First"), + SHEX("4ece084485813e9088d2c63a041bc5b4" + "4f9ef1012a2b588f3cd11f05033ac4c6" + "0c2ef6ab4030fe8296248df163f44952")); + + HMAC_TEST(sha384, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaa"), + SDATA("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")); + SHEX("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")); - - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaa"), - LDATA("Test Using Larger Than Block-Size Key - Hash Key First"), - H("80b24263c7c1a3ebb71493c1dd7be8b4" - "9b46d1f41b4aeec1121b013783f8f352" - "6b56d037e05f2598bd0fd2215d6a1e52" - "95e64f73f63f0aec8b915a985d786598")); - - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaa"), - LDATA("This is a test using a larger than block-size ke" + HMAC_TEST(sha512, + SHEX("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" + "0b0b0b0b"), + SDATA("Hi There"), + SHEX("87aa7cdea5ef619d4ff0b4241a1d6cb0" + "2379f4e2ce4ec2787ad0b30545e17cde" + "daa833b7d6b8a702038b274eaea3f4e4" + "be9d914eeb61f1702e696c203a126854")); + + HMAC_TEST(sha512, + SDATA("Jefe"), + SDATA("what do ya want for nothing?"), + SHEX("164b7a7bfcf819e2e395fbe73b56e0a3" + "87bd64222e831fd610270cd7ea250554" + "9758bf75c05a994a6d034f65f8f0e6fd" + "caeab1a34d4a6b4b636e070a38bce737")); + + HMAC_TEST(sha512, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaa"), + SHEX("dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddd"), + SHEX("fa73b0089d56a284efb0f0756c890be9" + "b1b5dbdd8ee81a3655f83e33b2279d39" + "bf3e848279a722c806b485a47e67c807" + "b946a337bee8942674278859e13292fb")); + + HMAC_TEST(sha512, + SHEX("0102030405060708090a0b0c0d0e0f10" + "111213141516171819"), + SHEX("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" + "cdcd"), + SHEX("b0ba465637458c6990e5a8c5f61d4af7" + "e576d97ff94b872de76f8050361ee3db" + "a91ca5c11aa25eb4d679275cc5788063" + "a5f19741120c4f2de2adebeb10a298dd")); + + HMAC_TEST(sha512, + SHEX("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"), + SDATA("Test With Truncation"), + SHEX("415fad6271580a531d4179bc891d87a6")); + + HMAC_TEST(sha512, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaa"), + SDATA("Test Using Larger Than Block-Size Key - Hash Key First"), + SHEX("80b24263c7c1a3ebb71493c1dd7be8b4" + "9b46d1f41b4aeec1121b013783f8f352" + "6b56d037e05f2598bd0fd2215d6a1e52" + "95e64f73f63f0aec8b915a985d786598")); + + HMAC_TEST(sha512, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaa"), + SDATA("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("e37b6a775dc87dbaa4dfa9f96e5e3ffd" - "debd71f8867289865df5a32d20cdc944" - "b6022cac3c4982b10d5eeb55c3e4de15" - "134676fb6de0446065c97440fa8c6a58")); + SHEX("e37b6a775dc87dbaa4dfa9f96e5e3ffd" + "debd71f8867289865df5a32d20cdc944" + "b6022cac3c4982b10d5eeb55c3e4de15" + "134676fb6de0446065c97440fa8c6a58")); /* Additional test vectors, from Daniel Kahn Gillmor */ - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA(""), - H("34316413c2d6940572d0bbbf099d529d" - "148b424533cf562bc1b365f530e21a31" - "799fc51cef78060cc6f448a8e5d780c2" - "6cdf20d4c3e6f27fe5ef576bbd05e855")); + HMAC_TEST(sha512, + SDATA("monkey monkey monkey monkey"), + SDATA(""), + SHEX("34316413c2d6940572d0bbbf099d529d" + "148b424533cf562bc1b365f530e21a31" + "799fc51cef78060cc6f448a8e5d780c2" + "6cdf20d4c3e6f27fe5ef576bbd05e855")); - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("a"), - H("cf1948507378bc3ab58cb6ec87f4d456" - "b90d3298395c29873f1ded1e111b50fe" - "c336ed24684bf19716efc309212f37aa" - "715cfb9ecccf3af13691ded167b4b336")); + HMAC_TEST(sha512, + SDATA("monkey monkey monkey monkey"), + SDATA("a"), + SHEX("cf1948507378bc3ab58cb6ec87f4d456" + "b90d3298395c29873f1ded1e111b50fe" + "c336ed24684bf19716efc309212f37aa" + "715cfb9ecccf3af13691ded167b4b336")); - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("38"), - H("b8201784216ce01b83cdd282616c6e89" - "644c6dfd1269ed8580bbc39b92add364" - "c2b2a2018cffb1915e8625e473b67d0f" - "e54a50e475dfa0e2b1a97bac1383792c")); + HMAC_TEST(sha512, + SDATA("monkey monkey monkey monkey"), + SDATA("38"), + SHEX("b8201784216ce01b83cdd282616c6e89" + "644c6dfd1269ed8580bbc39b92add364" + "c2b2a2018cffb1915e8625e473b67d0f" + "e54a50e475dfa0e2b1a97bac1383792c")); - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("abc"), - H("f097ee08b8c44e847a384f9fd645e35e" - "4816baa9791ba39d3dc611210500b044" - "873ee296bf1047dc06daa201a5767192" - "5b73b4ea59c60114881c8287d0699c83")); + HMAC_TEST(sha512, + SDATA("monkey monkey monkey monkey"), + SDATA("abc"), + SHEX("f097ee08b8c44e847a384f9fd645e35e" + "4816baa9791ba39d3dc611210500b044" + "873ee296bf1047dc06daa201a5767192" + "5b73b4ea59c60114881c8287d0699c83")); - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("message digest"), - H("921a441a884b83c76a8526da8e60d60d" - "17ded4eee5c29375e0d93717669a4c3e" - "eba7473e95f7c1a2a85afc24a0adbc4d" - "6c2bdd6ca6cab8b18d19f82d4a6c51bc")); + HMAC_TEST(sha512, + SDATA("monkey monkey monkey monkey"), + SDATA("message digest"), + SHEX("921a441a884b83c76a8526da8e60d60d" + "17ded4eee5c29375e0d93717669a4c3e" + "eba7473e95f7c1a2a85afc24a0adbc4d" + "6c2bdd6ca6cab8b18d19f82d4a6c51bc")); - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("abcdefghijklmnopqrstuvwxyz"), - H("640054c96f35815095617d0a8c956066" - "1a6ff46bfb39110333b2c52c8866abfb" - "59d9152c9b0948c1ed65c3fd72a8fb82" - "190acc8830770afe5b0c5b6414c75a77")); - - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), - H("835a4f5b3750b4c1fccfa88da2f746a4" - "900160c9f18964309bb736c13b59491b" - "8e32d37b724cc5aebb0f554c6338a3b5" - "94c4ba26862b2dadb59b7ede1d08d53e")); - - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("monkey monkey monkey monkey"), - LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), - H("fdf83dc879e3476c8e8aceff2bf6fece" - "2e4f39c7e1a167845465bb549dfa5ffe" - "997e6c7cf3720eae51ed2b00ad2a8225" - "375092290edfa9d48ec7e4bc8e276088")); + HMAC_TEST(sha512, + SDATA("monkey monkey monkey monkey"), + SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("640054c96f35815095617d0a8c956066" + "1a6ff46bfb39110333b2c52c8866abfb" + "59d9152c9b0948c1ed65c3fd72a8fb82" + "190acc8830770afe5b0c5b6414c75a77")); + + HMAC_TEST(sha512, + SDATA("monkey monkey monkey monkey"), + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("835a4f5b3750b4c1fccfa88da2f746a4" + "900160c9f18964309bb736c13b59491b" + "8e32d37b724cc5aebb0f554c6338a3b5" + "94c4ba26862b2dadb59b7ede1d08d53e")); + + HMAC_TEST(sha512, + SDATA("monkey monkey monkey monkey"), + SDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), + SHEX("fdf83dc879e3476c8e8aceff2bf6fece" + "2e4f39c7e1a167845465bb549dfa5ffe" + "997e6c7cf3720eae51ed2b00ad2a8225" + "375092290edfa9d48ec7e4bc8e276088")); /* Additional test vectors, from draft-kelly-ipsec-ciph-sha2-01.txt */ /* Test case AUTH512-1: */ - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" - "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"), - LDATA("Hi There"), - H("637edc6e01dce7e6742a99451aae82df" - "23da3e92439e590e43e761b33e910fb8" - "ac2878ebd5803f6f0b61dbce5e251ff8" - "789a4722c1be65aea45fd464e89f8f5b")); + HMAC_TEST(sha512, + SHEX("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" + "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" + "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" + "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"), + SDATA("Hi There"), + SHEX("637edc6e01dce7e6742a99451aae82df" + "23da3e92439e590e43e761b33e910fb8" + "ac2878ebd5803f6f0b61dbce5e251ff8" + "789a4722c1be65aea45fd464e89f8f5b")); /* Test case AUTH512-2: */ - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - LDATA("JefeJefeJefeJefe" + HMAC_TEST(sha512, + SDATA("JefeJefeJefeJefe" "JefeJefeJefeJefe" "JefeJefeJefeJefe" "JefeJefeJefeJefe"), - LDATA("what do ya want for nothing?"), - H("cb370917ae8a7ce28cfd1d8f4705d614" - "1c173b2a9362c15df235dfb251b15454" - "6aa334ae9fb9afc2184932d8695e397b" - "fa0ffb93466cfcceaae38c833b7dba38")); + SDATA("what do ya want for nothing?"), + SHEX("cb370917ae8a7ce28cfd1d8f4705d614" + "1c173b2a9362c15df235dfb251b15454" + "6aa334ae9fb9afc2184932d8695e397b" + "fa0ffb93466cfcceaae38c833b7dba38")); /* Test case AUTH512-3: */ - HMAC_TEST(sha512, SHA512_DIGEST_SIZE, - HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), - HL("dddddddddddddddddddddddddddddddd" - "dddddddddddddddddddddddddddddddd" - "dddddddddddddddddddddddddddddddd" - "dddd"), - H("2ee7acd783624ca9398710f3ee05ae41" - "b9f9b0510c87e49e586cc9bf961733d8" - "623c7b55cebefccf02d5581acc1c9d5f" - "b1ff68a1de45509fbe4da9a433922655")); + HMAC_TEST(sha512, + SHEX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), + SHEX("dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddd" + "dddd"), + SHEX("2ee7acd783624ca9398710f3ee05ae41" + "b9f9b0510c87e49e586cc9bf961733d8" + "623c7b55cebefccf02d5581acc1c9d5f" + "b1ff68a1de45509fbe4da9a433922655")); /* Test case AUTH512-3 from same document seems broken. */ - - SUCCESS(); } diff --git a/testsuite/knuth-lfib-test.c b/testsuite/knuth-lfib-test.c index 218894f0..3e8bfdd5 100644 --- a/testsuite/knuth-lfib-test.c +++ b/testsuite/knuth-lfib-test.c @@ -1,7 +1,7 @@ #include "testutils.h" #include "knuth-lfib.h" -int +void test_main(void) { struct knuth_lfib_ctx ctx; @@ -15,8 +15,5 @@ test_main(void) knuth_lfib_get_array(&ctx, 1009, a); x = knuth_lfib_get(&ctx); - if (x != 461390032) - FAIL(); - - SUCCESS(); + ASSERT (x == 461390032); } diff --git a/testsuite/md2-test.c b/testsuite/md2-test.c index 8ab45c17..af148577 100644 --- a/testsuite/md2-test.c +++ b/testsuite/md2-test.c @@ -1,27 +1,25 @@ #include "testutils.h" #include "md2.h" -int +void test_main(void) { /* Testcases from RFC 1319 */ - test_hash(&nettle_md2, 0, "", - H("8350e5a3e24c153df2275c9f80692773")); - test_hash(&nettle_md2, LDATA("a"), - H("32ec01ec4a6dac72c0ab96fb34c0b5d1")); - test_hash(&nettle_md2, LDATA("abc"), - H("da853b0d3f88d99b30283a69e6ded6bb")); - test_hash(&nettle_md2, LDATA("message digest"), - H("ab4f496bfb2a530b219ff33031fe06b0")); - test_hash(&nettle_md2, LDATA("abcdefghijklmnopqrstuvwxyz"), - H("4e8ddff3650292ab5a4108c3aa47940b")); + test_hash(&nettle_md2, SDATA(""), + SHEX("8350e5a3e24c153df2275c9f80692773")); + test_hash(&nettle_md2, SDATA("a"), + SHEX("32ec01ec4a6dac72c0ab96fb34c0b5d1")); + test_hash(&nettle_md2, SDATA("abc"), + SHEX("da853b0d3f88d99b30283a69e6ded6bb")); + test_hash(&nettle_md2, SDATA("message digest"), + SHEX("ab4f496bfb2a530b219ff33031fe06b0")); + test_hash(&nettle_md2, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("4e8ddff3650292ab5a4108c3aa47940b")); test_hash(&nettle_md2, - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789"), - H("da33def2a42df13975352846c30338cd")); - test_hash(&nettle_md2, LDATA("1234567890123456789012345678901234567890" + SHEX("da33def2a42df13975352846c30338cd")); + test_hash(&nettle_md2, SDATA("1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890"), - H("d5976f79d83d3a0dc9806c3c66f3efd8")); - - SUCCESS(); + SHEX("d5976f79d83d3a0dc9806c3c66f3efd8")); } diff --git a/testsuite/md4-test.c b/testsuite/md4-test.c index 208456d0..d46693d6 100644 --- a/testsuite/md4-test.c +++ b/testsuite/md4-test.c @@ -1,38 +1,36 @@ #include "testutils.h" #include "md4.h" -int +void test_main(void) { /* Testcases from RFC 1320 */ - test_hash(&nettle_md4, LDATA(""), - H("31d6cfe0d16ae931b73c59d7e0c089c0")); - test_hash(&nettle_md4, LDATA("a"), - H("bde52cb31de33e46245e05fbdbd6fb24")); - test_hash(&nettle_md4, LDATA("abc"), - H("a448017aaf21d8525fc10ae87aa6729d")); - test_hash(&nettle_md4, LDATA("message digest"), - H("d9130a8164549fe818874806e1c7014b")); - test_hash(&nettle_md4, LDATA("abcdefghijklmnopqrstuvwxyz"), - H("d79e1c308aa5bbcdeea8ed63df412da9")); + test_hash(&nettle_md4, SDATA(""), + SHEX("31d6cfe0d16ae931b73c59d7e0c089c0")); + test_hash(&nettle_md4, SDATA("a"), + SHEX("bde52cb31de33e46245e05fbdbd6fb24")); + test_hash(&nettle_md4, SDATA("abc"), + SHEX("a448017aaf21d8525fc10ae87aa6729d")); + test_hash(&nettle_md4, SDATA("message digest"), + SHEX("d9130a8164549fe818874806e1c7014b")); + test_hash(&nettle_md4, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("d79e1c308aa5bbcdeea8ed63df412da9")); test_hash(&nettle_md4, - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789"), - H("043f8582f241db351ce627e153e7f0e4")); + SHEX("043f8582f241db351ce627e153e7f0e4")); test_hash(&nettle_md4, - LDATA("12345678901234567890123456789012345678901234567890" + SDATA("12345678901234567890123456789012345678901234567890" "123456789012345678901234567890"), - H("e33b4ddc9c38f2199c3e7b164fcc0536")); + SHEX("e33b4ddc9c38f2199c3e7b164fcc0536")); /* Additional test vectors, from Daniel Kahn Gillmor */ - test_hash(&nettle_md4, LDATA("38"), - H("ae9c7ebfb68ea795483d270f5934b71d")); - test_hash(&nettle_md4, LDATA("abc"), - H("a448017aaf21d8525fc10ae87aa6729d")); - test_hash(&nettle_md4, LDATA("message digest"), - H("d9130a8164549fe818874806e1c7014b")); - test_hash(&nettle_md4, LDATA("abcdefghijklmnopqrstuvwxyz"), - H("d79e1c308aa5bbcdeea8ed63df412da9")); - - SUCCESS(); + test_hash(&nettle_md4, SDATA("38"), + SHEX("ae9c7ebfb68ea795483d270f5934b71d")); + test_hash(&nettle_md4, SDATA("abc"), + SHEX("a448017aaf21d8525fc10ae87aa6729d")); + test_hash(&nettle_md4, SDATA("message digest"), + SHEX("d9130a8164549fe818874806e1c7014b")); + test_hash(&nettle_md4, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("d79e1c308aa5bbcdeea8ed63df412da9")); } diff --git a/testsuite/md5-compat-test.c b/testsuite/md5-compat-test.c index bffb6232..c7c1112a 100644 --- a/testsuite/md5-compat-test.c +++ b/testsuite/md5-compat-test.c @@ -1,7 +1,7 @@ #include "testutils.h" #include "md5-compat.h" -int +void test_main(void) { MD5_CTX ctx; @@ -9,52 +9,44 @@ test_main(void) MD5Init(&ctx); MD5Final(digest, &ctx); - if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("D41D8CD98F00B204 E9800998ECF8427E"))) - FAIL(); + ASSERT(MEMEQ(MD5_DIGEST_SIZE, digest, + H("D41D8CD98F00B204 E9800998ECF8427E"))); MD5Init(&ctx); MD5Update(&ctx, "a", 1); MD5Final(digest, &ctx); - - if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("0CC175B9C0F1B6A8 31C399E269772661"))) - FAIL(); + ASSERT(MEMEQ(MD5_DIGEST_SIZE, digest, + H("0CC175B9C0F1B6A8 31C399E269772661"))); MD5Init(&ctx); MD5Update(&ctx, "abc", 3); MD5Final(digest, &ctx); - - if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("900150983cd24fb0 D6963F7D28E17F72"))) - FAIL(); + ASSERT(MEMEQ(MD5_DIGEST_SIZE, digest, + H("900150983cd24fb0 D6963F7D28E17F72"))); MD5Init(&ctx); MD5Update(&ctx, "message digest", 14); MD5Final(digest, &ctx); - - if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("F96B697D7CB7938D 525A2F31AAF161D0"))) - FAIL(); + ASSERT(MEMEQ(MD5_DIGEST_SIZE, digest, + H("F96B697D7CB7938D 525A2F31AAF161D0"))); MD5Init(&ctx); MD5Update(&ctx, "abcdefghijklmnopqrstuvwxyz", 26); MD5Final(digest, &ctx); - - if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("C3FCD3D76192E400 7DFB496CCA67E13B"))) - FAIL(); + ASSERT(MEMEQ(MD5_DIGEST_SIZE, digest, + H("C3FCD3D76192E400 7DFB496CCA67E13B"))); MD5Init(&ctx); MD5Update(&ctx, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62); MD5Final(digest, &ctx); - - if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("D174AB98D277D9F5 A5611C2C9F419D9F"))) - FAIL(); + ASSERT(MEMEQ(MD5_DIGEST_SIZE, digest, + H("D174AB98D277D9F5 A5611C2C9F419D9F"))); MD5Init(&ctx); MD5Update(&ctx, "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890", 80); MD5Final(digest, &ctx); - - if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("57EDF4A22BE3C955 AC49DA2E2107B67A"))) - FAIL(); - - SUCCESS(); + ASSERT(MEMEQ(MD5_DIGEST_SIZE, digest, + H("57EDF4A22BE3C955 AC49DA2E2107B67A"))); } diff --git a/testsuite/md5-test.c b/testsuite/md5-test.c index 995f304c..37c2fb15 100644 --- a/testsuite/md5-test.c +++ b/testsuite/md5-test.c @@ -1,38 +1,38 @@ #include "testutils.h" #include "md5.h" -int +void test_main(void) { - test_hash(&nettle_md5, 0, "", - H("D41D8CD98F00B204 E9800998ECF8427E")); + test_hash(&nettle_md5, SDATA(""), + SHEX("D41D8CD98F00B204 E9800998ECF8427E")); - test_hash(&nettle_md5, 1, "a", - H("0CC175B9C0F1B6A8 31C399E269772661")); + test_hash(&nettle_md5, SDATA("a"), + SHEX("0CC175B9C0F1B6A8 31C399E269772661")); - test_hash(&nettle_md5, 3, "abc", - H("900150983cd24fb0 D6963F7D28E17F72")); + test_hash(&nettle_md5, SDATA("abc"), + SHEX("900150983cd24fb0 D6963F7D28E17F72")); - test_hash(&nettle_md5, 14, "message digest", - H("F96B697D7CB7938D 525A2F31AAF161D0")); + test_hash(&nettle_md5, SDATA("message digest"), + SHEX("F96B697D7CB7938D 525A2F31AAF161D0")); - test_hash(&nettle_md5, 26, "abcdefghijklmnopqrstuvwxyz", - H("C3FCD3D76192E400 7DFB496CCA67E13B")); + test_hash(&nettle_md5, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("C3FCD3D76192E400 7DFB496CCA67E13B")); - test_hash(&nettle_md5, 62, - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789", - H("D174AB98D277D9F5 A5611C2C9F419D9F")); + test_hash(&nettle_md5, + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789"), + SHEX("D174AB98D277D9F5 A5611C2C9F419D9F")); - test_hash(&nettle_md5, 80, - "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890", - H("57EDF4A22BE3C955 AC49DA2E2107B67A")); + test_hash(&nettle_md5, + SDATA("1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890"), + SHEX("57EDF4A22BE3C955 AC49DA2E2107B67A")); /* Additional test vector, from Daniel Kahn Gillmor */ - test_hash(&nettle_md5, LDATA("38"), - H("a5771bce93e200c3 6f7cd9dfd0e5deaa")); + test_hash(&nettle_md5, SDATA("38"), + SHEX("a5771bce93e200c3 6f7cd9dfd0e5deaa")); /* Collisions, reported by Xiaoyun Wang1, Dengguo Feng2, Xuejia Lai3, Hongbo Yu1, http://eprint.iacr.org/2004/199. */ @@ -83,18 +83,16 @@ test_main(void) #define H1 "79054025 255fb1a2 6e4bc422 aef54eb4" test_hash(&nettle_md5, - HL(M0 N0), H(H0)); + SHEX(M0 N0), SHEX(H0)); test_hash(&nettle_md5, - HL(M1 N1), H(H0)); + SHEX(M1 N1), SHEX(H0)); test_hash(&nettle_md5, - HL(M0 N2), H(H1)); + SHEX(M0 N2), SHEX(H1)); test_hash(&nettle_md5, - HL(M1 N3), H(H1)); - - SUCCESS(); + SHEX(M1 N3), SHEX(H1)); } /* Intermediate values for the single _nettle_md5_compress call for diff --git a/testsuite/memxor-test.c b/testsuite/memxor-test.c index 8c191f3b..33194330 100644 --- a/testsuite/memxor-test.c +++ b/testsuite/memxor-test.c @@ -75,7 +75,7 @@ test_memxor3 (const uint8_t *ain, const uint8_t *bin, const uint8_t *c, ASSERT (dst[size] == 17); } -int +void test_main(void) { const uint8_t *a = H("ecc8737f 38f2f9e8 86b9d84c 42a9c7ef" @@ -144,6 +144,4 @@ test_main(void) for (align_b = 0; align_b < ALIGN_SIZE; align_b++) test_memxor3 (a, b, c, size[i], align_dst, align_a, align_b); } - - SUCCESS(); } diff --git a/testsuite/meta-armor-test.c b/testsuite/meta-armor-test.c index a99064b9..368ac2e3 100644 --- a/testsuite/meta-armor-test.c +++ b/testsuite/meta-armor-test.c @@ -6,7 +6,7 @@ const char* armors[] = { "base64" }; -int +void test_main(void) { int i,j; @@ -22,6 +22,5 @@ test_main(void) while (NULL != nettle_armors[j]) j++; ASSERT(j == count); /* we are not missing testing any armors */ - SUCCESS(); } diff --git a/testsuite/meta-cipher-test.c b/testsuite/meta-cipher-test.c index 1bb74d86..e252addd 100644 --- a/testsuite/meta-cipher-test.c +++ b/testsuite/meta-cipher-test.c @@ -22,7 +22,7 @@ const char* ciphers[] = { "twofish256" }; -int +void test_main(void) { int i,j; @@ -38,6 +38,5 @@ test_main(void) while (NULL != nettle_ciphers[j]) j++; ASSERT(j == count); /* we are not missing testing any ciphers */ - SUCCESS(); } diff --git a/testsuite/meta-hash-test.c b/testsuite/meta-hash-test.c index 6db279b2..d3dba642 100644 --- a/testsuite/meta-hash-test.c +++ b/testsuite/meta-hash-test.c @@ -13,7 +13,7 @@ const char* hashes[] = { "sha512" }; -int +void test_main(void) { int i,j; @@ -29,6 +29,5 @@ test_main(void) while (NULL != nettle_hashes[j]) j++; ASSERT(j == count); /* we are not missing testing any hashes */ - SUCCESS(); } diff --git a/testsuite/pkcs1-test.c b/testsuite/pkcs1-test.c index 131c0b0a..8e4e6981 100644 --- a/testsuite/pkcs1-test.c +++ b/testsuite/pkcs1-test.c @@ -2,7 +2,7 @@ #include "pkcs1.h" -int +void test_main(void) { uint8_t buffer[16]; @@ -13,6 +13,4 @@ test_main(void) 3, "abc", 0); ASSERT(MEMEQ(sizeof(buffer), buffer, expected)); - - SUCCESS(); } diff --git a/testsuite/random-prime-test.c b/testsuite/random-prime-test.c index 6fdb449e..73eead08 100644 --- a/testsuite/random-prime-test.c +++ b/testsuite/random-prime-test.c @@ -2,7 +2,7 @@ #include "knuth-lfib.h" -int +void test_main(void) { struct knuth_lfib_ctx lfib; @@ -24,5 +24,5 @@ test_main(void) ASSERT (mpz_probab_prime_p(p, 25)); } - SUCCESS(); + mpz_clear(p); } diff --git a/testsuite/ripemd160-test.c b/testsuite/ripemd160-test.c index 1237b70a..85518e6b 100644 --- a/testsuite/ripemd160-test.c +++ b/testsuite/ripemd160-test.c @@ -1,37 +1,35 @@ #include "testutils.h" #include "ripemd160.h" -int +void test_main(void) { - test_hash(&nettle_ripemd160, 0, "", - H("9c1185a5c5e9fc54612808977ee8f548b2258d31")); + test_hash(&nettle_ripemd160, SDATA(""), + SHEX("9c1185a5c5e9fc54612808977ee8f548b2258d31")); - test_hash(&nettle_ripemd160, 1, "a", - H("0bdc9d2d256b3ee9daae347be6f4dc835a467ffe")); + test_hash(&nettle_ripemd160, SDATA("a"), + SHEX("0bdc9d2d256b3ee9daae347be6f4dc835a467ffe")); - test_hash(&nettle_ripemd160, 3, "abc", - H("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc")); + test_hash(&nettle_ripemd160, SDATA("abc"), + SHEX("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc")); - test_hash(&nettle_ripemd160, 26, "abcdefghijklmnopqrstuvwxyz", - H("f71c27109c692c1b56bbdceb5b9d2865b3708dbc")); + test_hash(&nettle_ripemd160, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("f71c27109c692c1b56bbdceb5b9d2865b3708dbc")); - test_hash(&nettle_ripemd160, 14, "message digest", - H("5d0689ef49d2fae572b881b123a85ffa21595f36")); + test_hash(&nettle_ripemd160, SDATA("message digest"), + SHEX("5d0689ef49d2fae572b881b123a85ffa21595f36")); - test_hash(&nettle_ripemd160, 62, - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz0123456789", - H("b0e20b6e3116640286ed3a87a5713079b21f5189")); + test_hash(&nettle_ripemd160, + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("b0e20b6e3116640286ed3a87a5713079b21f5189")); - test_hash(&nettle_ripemd160, 80, - "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890", - H("9b752e45573d4b39f4dbd3323cab82bf63326bfb")); + test_hash(&nettle_ripemd160, + SDATA("1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890"), + SHEX("9b752e45573d4b39f4dbd3323cab82bf63326bfb")); /* Additional test vector, from Daniel Kahn Gillmor */ - test_hash(&nettle_ripemd160, LDATA("38"), - H("6b2d075b1cd34cd1c3e43a995f110c55649dad0e")); - - SUCCESS(); + test_hash(&nettle_ripemd160, SDATA("38"), + SHEX("6b2d075b1cd34cd1c3e43a995f110c55649dad0e")); } diff --git a/testsuite/rsa-encrypt-test.c b/testsuite/rsa-encrypt-test.c index 29e57cf0..c7b616c9 100644 --- a/testsuite/rsa-encrypt-test.c +++ b/testsuite/rsa-encrypt-test.c @@ -3,7 +3,7 @@ #include "rsa.h" #include "knuth-lfib.h" -int +void test_main(void) { struct rsa_public_key pub; @@ -82,6 +82,5 @@ test_main(void) rsa_public_key_clear(&pub); mpz_clear(gibberish); free(decrypted); - SUCCESS(); } diff --git a/testsuite/rsa-keygen-test.c b/testsuite/rsa-keygen-test.c index 84b151e5..5d6211cb 100644 --- a/testsuite/rsa-keygen-test.c +++ b/testsuite/rsa-keygen-test.c @@ -8,7 +8,7 @@ progress(void *ctx UNUSED, int c) fputc(c, stderr); } -int +void test_main(void) { struct rsa_public_key pub; @@ -26,11 +26,11 @@ test_main(void) /* Generate a 1024 bit key with random e */ knuth_lfib_init(&lfib, 13); - if (!rsa_generate_keypair(&pub, &key, - &lfib, (nettle_random_func *) knuth_lfib_random, - NULL, verbose ? progress : NULL, - 1024, 50)) - FAIL(); + ASSERT (rsa_generate_keypair(&pub, &key, + &lfib, + (nettle_random_func *) knuth_lfib_random, + NULL, verbose ? progress : NULL, + 1024, 50)); test_rsa_key(&pub, &key); @@ -48,11 +48,11 @@ test_main(void) knuth_lfib_init(&lfib, 17); mpz_set_ui(pub.e, 17); - if (!rsa_generate_keypair(&pub, &key, - &lfib, (nettle_random_func *) knuth_lfib_random, - NULL, verbose ? progress : NULL, - 2000, 0)) - FAIL(); + ASSERT (rsa_generate_keypair(&pub, &key, + &lfib, + (nettle_random_func *) knuth_lfib_random, + NULL, verbose ? progress : NULL, + 2000, 0)); test_rsa_key(&pub, &key); @@ -74,6 +74,4 @@ test_main(void) rsa_private_key_clear(&key); rsa_public_key_clear(&pub); mpz_clear(expected); - - SUCCESS(); } diff --git a/testsuite/rsa-test.c b/testsuite/rsa-test.c index 8fc37b5a..e9b1c030 100644 --- a/testsuite/rsa-test.c +++ b/testsuite/rsa-test.c @@ -1,6 +1,6 @@ #include "testutils.h" -int +void test_main(void) { struct rsa_public_key pub; @@ -102,8 +102,7 @@ test_main(void) mpz_set_str(pub.e, "3f1a012d", 16); - if (!rsa_public_key_prepare(&pub)) - FAIL(); + ASSERT (rsa_public_key_prepare(&pub)); mpz_set_str(key.p, "0b73c990eeda0a2a" "2c26416052c85560" "0c5c0f5ce86a8326" @@ -130,11 +129,8 @@ test_main(void) "05e1831619db2f10" "bb9b6a8fd5c95df2" "eb78f303ea0c0cc8" "06", 16); - if (!rsa_private_key_prepare(&key)) - FAIL(); - - if (pub.size != key.size) - FAIL(); + ASSERT (rsa_private_key_prepare(&key)); + ASSERT (pub.size == key.size); /* Test md5 signatures */ mpz_set_str(expected, @@ -177,6 +173,4 @@ test_main(void) rsa_private_key_clear(&key); rsa_public_key_clear(&pub); mpz_clear(expected); - - SUCCESS(); } diff --git a/testsuite/rsa2sexp-test.c b/testsuite/rsa2sexp-test.c index 596a9786..b4f38a90 100644 --- a/testsuite/rsa2sexp-test.c +++ b/testsuite/rsa2sexp-test.c @@ -2,7 +2,7 @@ #include "buffer.h" -int +void test_main(void) { struct rsa_public_key pub; @@ -57,31 +57,31 @@ test_main(void) print_hex(buffer.size, buffer.contents); } - ASSERT(MEMEQH(buffer.size, buffer.contents, - "2831313a707269766174652d6b657928" - "333a72736128313a6e36333a085c3408" - "989acae4faec3cbbad91c90d34c1d259" - "cd74121a36f38b0b51424a9b2be514a0" - "4377113a6cdafe79dd7d5f2ecc8b5e96" - "61189b86a7b22239907c252928313a65" - "343a36ad4b1d2928313a6436333a06ee" - "6d4ff3c239e408150daf8117abfa36a4" - "0ad4455d9059a86d52f33a2de07418a0" - "a699594588c64810248c9412d554f74a" - "f947c73c32007e87c92f0937ed292831" - "3a7033323a03259879b24315e9cf1425" - "4824c7935d807cdb6990f414a0f65e60" - "65130a611f2928313a7133323a02a81b" - "a73bad45fc73b36deffce52d1b73e074" - "7f4d8a82648cecd310448ea63b292831" - "3a6133323a026cbdad5dd0046e093f06" - "0ecd5b4ac918e098b0278bb752b7cadd" - "6a8944f0b92928313a6233323a014875" - "1e622d6d58e3bb094afd6edacf737035" - "1d068e2ce9f565c5528c4a7473292831" - "3a6333323a00f8a458ea73a018dc6fa5" - "6863e3bc6de405f364f77dee6f096267" - "9ea1a8282e292929")); + ASSERT(MEMEQ(buffer.size, buffer.contents, + H("2831313a707269766174652d6b657928" + "333a72736128313a6e36333a085c3408" + "989acae4faec3cbbad91c90d34c1d259" + "cd74121a36f38b0b51424a9b2be514a0" + "4377113a6cdafe79dd7d5f2ecc8b5e96" + "61189b86a7b22239907c252928313a65" + "343a36ad4b1d2928313a6436333a06ee" + "6d4ff3c239e408150daf8117abfa36a4" + "0ad4455d9059a86d52f33a2de07418a0" + "a699594588c64810248c9412d554f74a" + "f947c73c32007e87c92f0937ed292831" + "3a7033323a03259879b24315e9cf1425" + "4824c7935d807cdb6990f414a0f65e60" + "65130a611f2928313a7133323a02a81b" + "a73bad45fc73b36deffce52d1b73e074" + "7f4d8a82648cecd310448ea63b292831" + "3a6133323a026cbdad5dd0046e093f06" + "0ecd5b4ac918e098b0278bb752b7cadd" + "6a8944f0b92928313a6233323a014875" + "1e622d6d58e3bb094afd6edacf737035" + "1d068e2ce9f565c5528c4a7473292831" + "3a6333323a00f8a458ea73a018dc6fa5" + "6863e3bc6de405f364f77dee6f096267" + "9ea1a8282e292929"))); nettle_buffer_clear(&buffer); ASSERT(rsa_keypair_to_sexp(&buffer, NULL, &pub, NULL)); @@ -91,17 +91,16 @@ test_main(void) printf("public:"); print_hex(buffer.size, buffer.contents); } - ASSERT(MEMEQH(buffer.size, buffer.contents, - "2831303a7075626c69632d6b65792839" - "3a7273612d706b63733128313a6e3633" - "3a085c3408989acae4faec3cbbad91c9" - "0d34c1d259cd74121a36f38b0b51424a" - "9b2be514a04377113a6cdafe79dd7d5f" - "2ecc8b5e9661189b86a7b22239907c25" - "2928313a65343a36ad4b1d292929")); + ASSERT(MEMEQ(buffer.size, buffer.contents, + H("2831303a7075626c69632d6b65792839" + "3a7273612d706b63733128313a6e3633" + "3a085c3408989acae4faec3cbbad91c9" + "0d34c1d259cd74121a36f38b0b51424a" + "9b2be514a04377113a6cdafe79dd7d5f" + "2ecc8b5e9661189b86a7b22239907c25" + "2928313a65343a36ad4b1d292929"))); + nettle_buffer_clear(&buffer); rsa_public_key_clear(&pub); rsa_private_key_clear(&priv); - - SUCCESS(); } diff --git a/testsuite/salsa20-test.c b/testsuite/salsa20-test.c index 7a246b9f..d742ce45 100644 --- a/testsuite/salsa20-test.c +++ b/testsuite/salsa20-test.c @@ -14,16 +14,15 @@ memzero_p (const uint8_t *p, size_t n) } /* The ecrypt testcases encrypt 512 zero bytes (8 blocks), then give - the xor of all blocks, and the data for block 0 (0-43), 3,4 + the xor of all blocks, and the data for block 0 (0-63), 3,4 (192-319), 7 (448-511) */ #define STREAM_LENGTH 512 static void -test_salsa20_stream(unsigned key_length, - const uint8_t *key, - const uint8_t *iv, - const uint8_t *ciphertext, - const uint8_t *xor_ref) +test_salsa20_stream(const struct tstring *key, + const struct tstring *iv, + const struct tstring *ciphertext, + const struct tstring *xor_ref) { struct salsa20_ctx ctx; uint8_t data[STREAM_LENGTH + 1]; @@ -31,8 +30,12 @@ test_salsa20_stream(unsigned key_length, uint8_t xor[SALSA20_BLOCK_SIZE]; unsigned j; - salsa20_set_key(&ctx, key_length, key); - salsa20_set_iv(&ctx, iv); + ASSERT (iv->length == SALSA20_IV_SIZE); + ASSERT (ciphertext->length == 4*SALSA20_BLOCK_SIZE); + ASSERT (xor_ref->length == SALSA20_BLOCK_SIZE); + + salsa20_set_key(&ctx, key->length, key->data); + salsa20_set_iv(&ctx, iv->data); memset(stream, 0, STREAM_LENGTH + 1); salsa20_crypt(&ctx, STREAM_LENGTH, stream, stream); if (stream[STREAM_LENGTH]) @@ -40,33 +43,33 @@ test_salsa20_stream(unsigned key_length, fprintf(stderr, "Stream of %d bytes wrote too much!\n", STREAM_LENGTH); FAIL(); } - if (!MEMEQ (64, stream, ciphertext)) + if (!MEMEQ (64, stream, ciphertext->data)) { fprintf(stderr, "Error failed, offset 0:\n"); fprintf(stderr, "\nOutput: "); print_hex(64, stream); fprintf(stderr, "\nExpected:"); - print_hex(64, ciphertext); + print_hex(64, ciphertext->data); fprintf(stderr, "\n"); FAIL(); } - if (!MEMEQ (128, stream + 192, ciphertext + 64)) + if (!MEMEQ (128, stream + 192, ciphertext->data + 64)) { fprintf(stderr, "Error failed, offset 192:\n"); fprintf(stderr, "\nOutput: "); print_hex(128, stream + 192); fprintf(stderr, "\nExpected:"); - print_hex(64, ciphertext + 64); + print_hex(64, ciphertext->data + 64); fprintf(stderr, "\n"); FAIL(); } - if (!MEMEQ (64, stream + 448, ciphertext + 192)) + if (!MEMEQ (64, stream + 448, ciphertext->data + 192)) { fprintf(stderr, "Error failed, offset 448:\n"); fprintf(stderr, "\nOutput: "); print_hex(64, stream + 448); fprintf(stderr, "\nExpected:"); - print_hex(64, ciphertext + 192); + print_hex(64, ciphertext->data + 192); fprintf(stderr, "\n"); FAIL(); } @@ -75,13 +78,13 @@ test_salsa20_stream(unsigned key_length, for (j = 2*SALSA20_BLOCK_SIZE; j < STREAM_LENGTH; j += SALSA20_BLOCK_SIZE) memxor (xor, stream + j, SALSA20_BLOCK_SIZE); - if (!MEMEQ (SALSA20_BLOCK_SIZE, xor, xor_ref)) + if (!MEMEQ (SALSA20_BLOCK_SIZE, xor, xor_ref->data)) { fprintf(stderr, "Error failed, bad xor 448:\n"); fprintf(stderr, "\nOutput: "); print_hex(SALSA20_BLOCK_SIZE, xor); fprintf(stderr, "\nExpected:"); - print_hex(SALSA20_BLOCK_SIZE, xor_ref); + print_hex(SALSA20_BLOCK_SIZE, xor_ref->data); fprintf(stderr, "\n"); FAIL(); } @@ -89,7 +92,7 @@ test_salsa20_stream(unsigned key_length, for (j = 1; j <= STREAM_LENGTH; j++) { memset(data, 0, STREAM_LENGTH + 1); - salsa20_set_iv(&ctx, iv); + salsa20_set_iv(&ctx, iv->data); salsa20_crypt(&ctx, j, data, data); if (!MEMEQ(j, data, stream)) @@ -114,50 +117,56 @@ test_salsa20_stream(unsigned key_length, } static void -test_salsa20(unsigned key_length, - const uint8_t *key, - const uint8_t *iv, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext) +test_salsa20(const struct tstring *key, + const struct tstring *iv, + const struct tstring *cleartext, + const struct tstring *ciphertext) { struct salsa20_ctx ctx; - uint8_t *data = xalloc(length + 1); + uint8_t *data; + unsigned length; + + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; + + ASSERT (iv->length == SALSA20_IV_SIZE); - salsa20_set_key(&ctx, key_length, key); - salsa20_set_iv(&ctx, iv); + data = xalloc(length + 1); + + salsa20_set_key(&ctx, key->length, key->data); + salsa20_set_iv(&ctx, iv->data); data[length] = 17; - salsa20_crypt(&ctx, length, data, cleartext); + salsa20_crypt(&ctx, length, data, cleartext->data); if (data[length] != 17) { fprintf(stderr, "Encrypt of %u bytes wrote too much!\nInput:", length); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } - if (!MEMEQ(length, data, ciphertext)) + if (!MEMEQ(length, data, ciphertext->data)) { fprintf(stderr, "Encrypt failed:\nInput:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\n"); FAIL(); } - salsa20_set_key(&ctx, key_length, key); - salsa20_set_iv(&ctx, iv); + salsa20_set_key(&ctx, key->length, key->data); + salsa20_set_iv(&ctx, iv->data); salsa20_crypt(&ctx, length, data, data); - if (!MEMEQ(length, data, cleartext)) + if (!MEMEQ(length, data, cleartext->data)) { fprintf(stderr, "Decrypt failed:\nInput:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } @@ -165,90 +174,88 @@ test_salsa20(unsigned key_length, free(data); } -int +void test_main(void) { /* http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/full/verified.test-vectors?logsort=rev&rev=210&view=markup */ - test_salsa20(HL("80000000 00000000 00000000 00000000"), - H("00000000 00000000"), - HL("00000000 00000000"), - H("4DFA5E48 1DA23EA0")); - - test_salsa20(HL("00000000 00000000 00000000 00000000"), - H("80000000 00000000"), - HL("00000000 00000000"), - H("B66C1E44 46DD9557")); - - test_salsa20(HL("0053A6F94C9FF24598EB3E91E4378ADD"), - H("0D74DB42A91077DE"), - HL("00000000 00000000"), - H("05E1E7BE B697D999")); - - test_salsa20(HL("80000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000"), - H("00000000 00000000"), - HL("00000000 00000000"), - H("E3BE8FDD 8BECA2E3")); - - test_salsa20(HL("00000000 00000000 00000000 00000000" - "00000000 00000000 00000000 00000000"), - H("80000000 00000000"), - HL("00000000 00000000"), - H("2ABA3DC45B494700")); - - test_salsa20(HL("0053A6F94C9FF24598EB3E91E4378ADD" - "3083D6297CCF2275C81B6EC11467BA0D"), - H("0D74DB42A91077DE"), - HL("00000000 00000000"), - H("F5FAD53F 79F9DF58")); - - test_salsa20_stream(HL("80000000000000000000000000000000"), - H("00000000 00000000"), - H("4DFA5E481DA23EA09A31022050859936" - "DA52FCEE218005164F267CB65F5CFD7F" - "2B4F97E0FF16924A52DF269515110A07" - "F9E460BC65EF95DA58F740B7D1DBB0AA" - "DA9C1581F429E0A00F7D67E23B730676" - "783B262E8EB43A25F55FB90B3E753AEF" - "8C6713EC66C51881111593CCB3E8CB8F" - "8DE124080501EEEB389C4BCB6977CF95" - "7D5789631EB4554400E1E025935DFA7B" - "3E9039D61BDC58A8697D36815BF1985C" - "EFDF7AE112E5BB81E37ECF0616CE7147" - "FC08A93A367E08631F23C03B00A8DA2F" - "B375703739DACED4DD4059FD71C3C47F" - "C2F9939670FAD4A46066ADCC6A564578" - "3308B90FFB72BE04A6B147CBE38CC0C3" - "B9267C296A92A7C69873F9F263BE9703"), - H("F7A274D268316790A67EC058F45C0F2A" - "067A99FCDE6236C0CEF8E056349FE54C" - "5F13AC74D2539570FD34FEAB06C57205" - "3949B59585742181A5A760223AFA22D4")); - - test_salsa20_stream(HL("48494A4B4C4D4E4F5051525354555657" - "58595A5B5C5D5E5F6061626364656667"), - H("0000000000000000"), - H("53AD3698A011F779AD71030F3EFBEBA0" - "A7EE3C55789681B1591EF33A7BE521ED" - "68FC36E58F53FFD6E1369B00E390E973" - "F656ACB097E0D603BE59A0B8F7975B98" - "A04698274C6AC6EC03F66ED3F94C08B7" - "9FFDBF2A1610E6F5814905E73AD6D0D2" - "8164EEB8450D8ED0BB4B644761B43512" - "52DD5DDF00C31E3DABA0BC17691CCFDC" - "B826C7F071E796D34E3BFFB3C96E76A1" - "209388392806947C7F19B86D379FA3AE" - "DFCD19EBF49803DACC6E577E5B97B0F6" - "D2036B6624D8196C96FCF02C865D30C1" - "B505D41E2C207FA1C0A0E93413DDCFFC" - "9BECA8030AFFAC2466E56482DA0EF428" - "E63880B5021D3051F18679505A2B9D4F" - "9B2C5A2D271D276DE3F51DBEBA934436"), - H("7849651A820B1CDFE36D5D6632716534" - "E0635EDEFD538122D80870B60FB055DB" - "637C7CA2B78B116F83AFF46E40F8F71D" - "4CD6D2E1B750D5E011D1DF2E80F7210A")); - - SUCCESS(); + test_salsa20(SHEX("80000000 00000000 00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("4DFA5E48 1DA23EA0")); + + test_salsa20(SHEX("00000000 00000000 00000000 00000000"), + SHEX("80000000 00000000"), + SHEX("00000000 00000000"), + SHEX("B66C1E44 46DD9557")); + + test_salsa20(SHEX("0053A6F94C9FF24598EB3E91E4378ADD"), + SHEX("0D74DB42A91077DE"), + SHEX("00000000 00000000"), + SHEX("05E1E7BE B697D999")); + + test_salsa20(SHEX("80000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("E3BE8FDD 8BECA2E3")); + + test_salsa20(SHEX("00000000 00000000 00000000 00000000" + "00000000 00000000 00000000 00000000"), + SHEX("80000000 00000000"), + SHEX("00000000 00000000"), + SHEX("2ABA3DC45B494700")); + + test_salsa20(SHEX("0053A6F94C9FF24598EB3E91E4378ADD" + "3083D6297CCF2275C81B6EC11467BA0D"), + SHEX("0D74DB42A91077DE"), + SHEX("00000000 00000000"), + SHEX("F5FAD53F 79F9DF58")); + + test_salsa20_stream(SHEX("80000000000000000000000000000000"), + SHEX("00000000 00000000"), + SHEX("4DFA5E481DA23EA09A31022050859936" + "DA52FCEE218005164F267CB65F5CFD7F" + "2B4F97E0FF16924A52DF269515110A07" + "F9E460BC65EF95DA58F740B7D1DBB0AA" + "DA9C1581F429E0A00F7D67E23B730676" + "783B262E8EB43A25F55FB90B3E753AEF" + "8C6713EC66C51881111593CCB3E8CB8F" + "8DE124080501EEEB389C4BCB6977CF95" + "7D5789631EB4554400E1E025935DFA7B" + "3E9039D61BDC58A8697D36815BF1985C" + "EFDF7AE112E5BB81E37ECF0616CE7147" + "FC08A93A367E08631F23C03B00A8DA2F" + "B375703739DACED4DD4059FD71C3C47F" + "C2F9939670FAD4A46066ADCC6A564578" + "3308B90FFB72BE04A6B147CBE38CC0C3" + "B9267C296A92A7C69873F9F263BE9703"), + SHEX("F7A274D268316790A67EC058F45C0F2A" + "067A99FCDE6236C0CEF8E056349FE54C" + "5F13AC74D2539570FD34FEAB06C57205" + "3949B59585742181A5A760223AFA22D4")); + + test_salsa20_stream(SHEX("48494A4B4C4D4E4F5051525354555657" + "58595A5B5C5D5E5F6061626364656667"), + SHEX("0000000000000000"), + SHEX("53AD3698A011F779AD71030F3EFBEBA0" + "A7EE3C55789681B1591EF33A7BE521ED" + "68FC36E58F53FFD6E1369B00E390E973" + "F656ACB097E0D603BE59A0B8F7975B98" + "A04698274C6AC6EC03F66ED3F94C08B7" + "9FFDBF2A1610E6F5814905E73AD6D0D2" + "8164EEB8450D8ED0BB4B644761B43512" + "52DD5DDF00C31E3DABA0BC17691CCFDC" + "B826C7F071E796D34E3BFFB3C96E76A1" + "209388392806947C7F19B86D379FA3AE" + "DFCD19EBF49803DACC6E577E5B97B0F6" + "D2036B6624D8196C96FCF02C865D30C1" + "B505D41E2C207FA1C0A0E93413DDCFFC" + "9BECA8030AFFAC2466E56482DA0EF428" + "E63880B5021D3051F18679505A2B9D4F" + "9B2C5A2D271D276DE3F51DBEBA934436"), + SHEX("7849651A820B1CDFE36D5D6632716534" + "E0635EDEFD538122D80870B60FB055DB" + "637C7CA2B78B116F83AFF46E40F8F71D" + "4CD6D2E1B750D5E011D1DF2E80F7210A")); } diff --git a/testsuite/serpent-test.c b/testsuite/serpent-test.c index d9e193bf..9f40c3fc 100644 --- a/testsuite/serpent-test.c +++ b/testsuite/serpent-test.c @@ -1,14 +1,15 @@ #include "testutils.h" #include "serpent.h" -static uint8_t * -decode_hex_reverse (const char *hex) +static const struct tstring * +tstring_hex_reverse (const char *hex) { - unsigned length = decode_hex_length (hex); - uint8_t *p = xalloc(length); - unsigned i; + struct tstring *s = tstring_hex (hex); + uint8_t *p; + unsigned length, i; - decode_hex(p, hex); + length = s->length; + p = s->data; for (i = 0; i < (length+1)/2; i++) { @@ -16,34 +17,33 @@ decode_hex_reverse (const char *hex) p[i] = p[length - 1 - i]; p[length - 1 - i] = t; } - return p; + return s; } -#define RH(x) decode_hex_reverse(x) -#define RHL(x) decode_hex_length(x), decode_hex_reverse(x) +#define RHEX(x) tstring_hex_reverse(x) -int +void test_main(void) { /* From libgcrypt */ test_cipher(&nettle_serpent128, - HL("0000000000000000 0000000000000000"), - HL("D29D576FCEA3A3A7 ED9099F29273D78E"), - H("B2288B968AE8B086 48D1CE9606FD992D")); + SHEX("0000000000000000 0000000000000000"), + SHEX("D29D576FCEA3A3A7 ED9099F29273D78E"), + SHEX("B2288B968AE8B086 48D1CE9606FD992D")); test_cipher(&nettle_serpent192, - HL("0000000000000000 0000000000000000 0000000000000000"), - HL("D29D576FCEABA3A7 ED9899F2927BD78E"), - H("130E353E1037C224 05E8FAEFB2C3C3E9")); + SHEX("0000000000000000 0000000000000000 0000000000000000"), + SHEX("D29D576FCEABA3A7 ED9899F2927BD78E"), + SHEX("130E353E1037C224 05E8FAEFB2C3C3E9")); test_cipher(&nettle_serpent256, - HL("0000000000000000 0000000000000000" - "0000000000000000 0000000000000000"), - HL("D095576FCEA3E3A7 ED98D9F29073D78E"), - H("B90EE5862DE69168 F2BDD5125B45472B")); + SHEX("0000000000000000 0000000000000000" + "0000000000000000 0000000000000000"), + SHEX("D095576FCEA3E3A7 ED98D9F29073D78E"), + SHEX("B90EE5862DE69168 F2BDD5125B45472B")); test_cipher(&nettle_serpent256, - HL("0000000000000000 0000000000000000" - "0000000000000000 0000000000000000"), - HL("0000000001000000 0200000003000000"), - H("2061A42782BD52EC 691EC383B03BA77C")); + SHEX("0000000000000000 0000000000000000" + "0000000000000000 0000000000000000"), + SHEX("0000000001000000 0200000003000000"), + SHEX("2061A42782BD52EC 691EC383B03BA77C")); /* The first test for each key size from the ecb_vk.txt and ecb_vt.txt * files in the serpent package. */ @@ -54,47 +54,47 @@ test_main(void) /* vk, 1 */ test_cipher(&nettle_serpent128, - RHL("8000000000000000 0000000000000000"), - RHL("0000000000000000 0000000000000000"), - RH("49AFBFAD9D5A3405 2CD8FFA5986BD2DD")); + RHEX("8000000000000000 0000000000000000"), + RHEX("0000000000000000 0000000000000000"), + RHEX("49AFBFAD9D5A3405 2CD8FFA5986BD2DD")); /* vt, 1 */ test_cipher(&nettle_serpent128, - RHL("0000000000000000 0000000000000000"), - RHL("8000000000000000 0000000000000000"), - RH("10B5FFB720B8CB90 02A1142B0BA2E94A")); + RHEX("0000000000000000 0000000000000000"), + RHEX("8000000000000000 0000000000000000"), + RHEX("10B5FFB720B8CB90 02A1142B0BA2E94A")); /* 192 bit key */ /* vk, 1 */ test_cipher(&nettle_serpent192, - RHL("8000000000000000 0000000000000000" - "0000000000000000"), - RHL("0000000000000000 0000000000000000"), - RH("E78E5402C7195568 AC3678F7A3F60C66")); + RHEX("8000000000000000 0000000000000000" + "0000000000000000"), + RHEX("0000000000000000 0000000000000000"), + RHEX("E78E5402C7195568 AC3678F7A3F60C66")); /* vt, 1 */ test_cipher(&nettle_serpent192, - RHL("0000000000000000 0000000000000000" - "0000000000000000"), - RHL("8000000000000000 0000000000000000"), - RH("B10B271BA25257E1 294F2B51F076D0D9")); + RHEX("0000000000000000 0000000000000000" + "0000000000000000"), + RHEX("8000000000000000 0000000000000000"), + RHEX("B10B271BA25257E1 294F2B51F076D0D9")); /* 256 bit key */ /* vk, 1 */ test_cipher(&nettle_serpent256, - RHL("8000000000000000 0000000000000000" - "0000000000000000 0000000000000000"), - RHL("0000000000000000 0000000000000000"), - RH("ABED96E766BF28CB C0EBD21A82EF0819")); + RHEX("8000000000000000 0000000000000000" + "0000000000000000 0000000000000000"), + RHEX("0000000000000000 0000000000000000"), + RHEX("ABED96E766BF28CB C0EBD21A82EF0819")); /* vt, 1 */ test_cipher(&nettle_serpent256, - RHL("0000000000000000 0000000000000000" - "0000000000000000 0000000000000000"), - RHL("8000000000000000 0000000000000000"), - RH("DA5A7992B1B4AE6F 8C004BC8A7DE5520")); + RHEX("0000000000000000 0000000000000000" + "0000000000000000 0000000000000000"), + RHEX("8000000000000000 0000000000000000"), + RHEX("DA5A7992B1B4AE6F 8C004BC8A7DE5520")); /* Test vectors from http://www.cs.technion.ac.il/~biham/Reports/Serpent/ */ @@ -102,190 +102,188 @@ test_main(void) /* serpent128 */ /* Set 4, vector# 0 */ test_cipher(&nettle_serpent128, - HL("000102030405060708090A0B0C0D0E0F"), - HL("00112233445566778899AABBCCDDEEFF"), - H("563E2CF8740A27C164804560391E9B27")); + SHEX("000102030405060708090A0B0C0D0E0F"), + SHEX("00112233445566778899AABBCCDDEEFF"), + SHEX("563E2CF8740A27C164804560391E9B27")); /* Set 4, vector# 1 */ test_cipher(&nettle_serpent128, - HL("2BD6459F82C5B300952C49104881FF48"), - HL("EA024714AD5C4D84EA024714AD5C4D84"), - H("92D7F8EF2C36C53409F275902F06539F")); + SHEX("2BD6459F82C5B300952C49104881FF48"), + SHEX("EA024714AD5C4D84EA024714AD5C4D84"), + SHEX("92D7F8EF2C36C53409F275902F06539F")); /* serpent192 */ /* Set 4, vector# 0 */ test_cipher(&nettle_serpent192, - HL("000102030405060708090A0B0C0D0E0F1011121314151617"), - HL("00112233445566778899AABBCCDDEEFF"), - H("6AB816C82DE53B93005008AFA2246A02")); + SHEX("000102030405060708090A0B0C0D0E0F1011121314151617"), + SHEX("00112233445566778899AABBCCDDEEFF"), + SHEX("6AB816C82DE53B93005008AFA2246A02")); /* Set 4, vector# 1 */ test_cipher(&nettle_serpent192, - HL("2BD6459F82C5B300952C49104881FF482BD6459F82C5B300"), - HL("EA024714AD5C4D84EA024714AD5C4D84"), - H("827B18C2678A239DFC5512842000E204")); + SHEX("2BD6459F82C5B300952C49104881FF482BD6459F82C5B300"), + SHEX("EA024714AD5C4D84EA024714AD5C4D84"), + SHEX("827B18C2678A239DFC5512842000E204")); /* serpent256 */ /* Set 4, vector# 0 */ test_cipher(&nettle_serpent256, - HL("000102030405060708090A0B0C0D0E0F" - "101112131415161718191A1B1C1D1E1F"), - HL("00112233445566778899AABBCCDDEEFF"), - H("2868B7A2D28ECD5E4FDEFAC3C4330074")); + SHEX("000102030405060708090A0B0C0D0E0F" + "101112131415161718191A1B1C1D1E1F"), + SHEX("00112233445566778899AABBCCDDEEFF"), + SHEX("2868B7A2D28ECD5E4FDEFAC3C4330074")); /* Set 4, vector# 1 */ test_cipher(&nettle_serpent256, - HL("2BD6459F82C5B300952C49104881FF48" - "2BD6459F82C5B300952C49104881FF48"), - HL("EA024714AD5C4D84EA024714AD5C4D84"), - H("3E507730776B93FDEA661235E1DD99F0")); + SHEX("2BD6459F82C5B300952C49104881FF48" + "2BD6459F82C5B300952C49104881FF48"), + SHEX("EA024714AD5C4D84EA024714AD5C4D84"), + SHEX("3E507730776B93FDEA661235E1DD99F0")); /* Test key padding. We use nettle_serpent256, which actually works also with key sizes smaller than 32 bytes. */ test_cipher(&nettle_serpent256, - HL("00112233440100000000000000000000" - "00000000000000000000000000000000"), - HL("0000000001000000 0200000003000000"), - H("C1415AC653FD7C7F D917482EE8EBFE25")); + SHEX("00112233440100000000000000000000" + "00000000000000000000000000000000"), + SHEX("0000000001000000 0200000003000000"), + SHEX("C1415AC653FD7C7F D917482EE8EBFE25")); /* Currrently, key sizes smaller than SERPENT_MIN_KEY_SIZE bytes (128 bits) are not supported. */ test_cipher(&nettle_serpent256, - HL("0011223344"), - HL("0000000001000000 0200000003000000"), - H("C1415AC653FD7C7F D917482EE8EBFE25")); + SHEX("0011223344"), + SHEX("0000000001000000 0200000003000000"), + SHEX("C1415AC653FD7C7F D917482EE8EBFE25")); test_cipher(&nettle_serpent256, - HL("00112233445566778899aabbccddeeff" - "00010000000000000000000000000000"), - HL("0000000001000000 0200000003000000"), - H("8EB9C958EAFFDF42 009755D7B6458838")); + SHEX("00112233445566778899aabbccddeeff" + "00010000000000000000000000000000"), + SHEX("0000000001000000 0200000003000000"), + SHEX("8EB9C958EAFFDF42 009755D7B6458838")); test_cipher(&nettle_serpent256, - HL("00112233445566778899aabbccddeeff" - "00"), - HL("0000000001000000 0200000003000000"), - H("8EB9C958EAFFDF42 009755D7B6458838")); + SHEX("00112233445566778899aabbccddeeff" + "00"), + SHEX("0000000001000000 0200000003000000"), + SHEX("8EB9C958EAFFDF42 009755D7B6458838")); test_cipher(&nettle_serpent256, - HL("00112233445566778899aabbccddeeff" - "00112201000000000000000000000000"), - HL("0000000001000000 0200000003000000"), - H("C8A078D8212AC96D 9060E30EC5CBB5C7")); + SHEX("00112233445566778899aabbccddeeff" + "00112201000000000000000000000000"), + SHEX("0000000001000000 0200000003000000"), + SHEX("C8A078D8212AC96D 9060E30EC5CBB5C7")); test_cipher(&nettle_serpent256, - HL("00112233445566778899aabbccddeeff" - "001122"), - HL("0000000001000000 0200000003000000"), - H("C8A078D8212AC96D 9060E30EC5CBB5C7")); + SHEX("00112233445566778899aabbccddeeff" + "001122"), + SHEX("0000000001000000 0200000003000000"), + SHEX("C8A078D8212AC96D 9060E30EC5CBB5C7")); /* Test with multiple blocks. */ test_cipher(&nettle_serpent128, - HL("e87450aa0fd87293fd0371483a459bd2"), - HL("a78a7a8d392f629d bd13674c8dce6fa2"), - H("b3d488986c80dea7 c5ebdab4907871c9")); + SHEX("e87450aa0fd87293fd0371483a459bd2"), + SHEX("a78a7a8d392f629d bd13674c8dce6fa2"), + SHEX("b3d488986c80dea7 c5ebdab4907871c9")); test_cipher(&nettle_serpent128, - HL("e87450aa0fd87293fd0371483a459bd2"), - HL("a78a7a8d392f629d bd13674c8dce6fa2" - "930c74dec02a11d8 c80d90b5e5c887a7"), - H("b3d488986c80dea7 c5ebdab4907871c9" - "a4b92b13b79afb37 5518b01bfd706a37")); + SHEX("e87450aa0fd87293fd0371483a459bd2"), + SHEX("a78a7a8d392f629d bd13674c8dce6fa2" + "930c74dec02a11d8 c80d90b5e5c887a7"), + SHEX("b3d488986c80dea7 c5ebdab4907871c9" + "a4b92b13b79afb37 5518b01bfd706a37")); test_cipher(&nettle_serpent128, - HL("e87450aa0fd87293fd0371483a459bd2"), - HL("a78a7a8d392f629d bd13674c8dce6fa2" - "930c74dec02a11d8 c80d90b5e5c887a7" - "83c92a921b5b2028 d9cb313a5f07ab09"), - H("b3d488986c80dea7 c5ebdab4907871c9" - "a4b92b13b79afb37 5518b01bfd706a37" - "8e44c2d463df4531 165461699edbad03")); + SHEX("e87450aa0fd87293fd0371483a459bd2"), + SHEX("a78a7a8d392f629d bd13674c8dce6fa2" + "930c74dec02a11d8 c80d90b5e5c887a7" + "83c92a921b5b2028 d9cb313a5f07ab09"), + SHEX("b3d488986c80dea7 c5ebdab4907871c9" + "a4b92b13b79afb37 5518b01bfd706a37" + "8e44c2d463df4531 165461699edbad03")); test_cipher(&nettle_serpent128, - HL("91c8e949e12f0e38 7b2473238a3df1b6"), - HL("00000000 00000001 00000002 00000003" - "00000004 00000005 00000006 00000007" - "00000008 00000009 0000000a 0000000b" - "0000000c 0000000d 0000000e 0000000f"), - H("2db9f0a39d4f31a4 b1a83cd1032fe1bd" - "3606caa84a220b1b f6f43ff80a831203" - "8c6c8d2793dc10b3 904d30e194f086a6" - "b2f3e932b9b3f8d1 d4d074f7bd1ff7a3")); + SHEX("91c8e949e12f0e38 7b2473238a3df1b6"), + SHEX("00000000 00000001 00000002 00000003" + "00000004 00000005 00000006 00000007" + "00000008 00000009 0000000a 0000000b" + "0000000c 0000000d 0000000e 0000000f"), + SHEX("2db9f0a39d4f31a4 b1a83cd1032fe1bd" + "3606caa84a220b1b f6f43ff80a831203" + "8c6c8d2793dc10b3 904d30e194f086a6" + "b2f3e932b9b3f8d1 d4d074f7bd1ff7a3")); test_cipher(&nettle_serpent128, - HL("e87450aa0fd87293fd0371483a459bd2"), - HL("a78a7a8d392f629d bd13674c8dce6fa2" - "930c74dec02a11d8 c80d90b5e5c887a7" - "83c92a921b5b2028 d9cb313a5f07ab09" - "672eadf1624a2ed0 c42d1b08b076f75a"), - H("b3d488986c80dea7 c5ebdab4907871c9" - "a4b92b13b79afb37 5518b01bfd706a37" - "8e44c2d463df4531 165461699edbad03" - "30ac8c52697102ae 3b725dba79ceb250")); + SHEX("e87450aa0fd87293fd0371483a459bd2"), + SHEX("a78a7a8d392f629d bd13674c8dce6fa2" + "930c74dec02a11d8 c80d90b5e5c887a7" + "83c92a921b5b2028 d9cb313a5f07ab09" + "672eadf1624a2ed0 c42d1b08b076f75a"), + SHEX("b3d488986c80dea7 c5ebdab4907871c9" + "a4b92b13b79afb37 5518b01bfd706a37" + "8e44c2d463df4531 165461699edbad03" + "30ac8c52697102ae 3b725dba79ceb250")); test_cipher(&nettle_serpent128, - HL("e87450aa0fd87293fd0371483a459bd2"), - HL("a78a7a8d392f629d bd13674c8dce6fa2" - "930c74dec02a11d8 c80d90b5e5c887a7" - "83c92a921b5b2028 d9cb313a5f07ab09" - "672eadf1624a2ed0 c42d1b08b076f75a" - "7378272aa57ad7c8 803e326689541266"), - H("b3d488986c80dea7 c5ebdab4907871c9" - "a4b92b13b79afb37 5518b01bfd706a37" - "8e44c2d463df4531 165461699edbad03" - "30ac8c52697102ae 3b725dba79ceb250" - "d308b83478e86dbb 629f18736cca042f")); + SHEX("e87450aa0fd87293fd0371483a459bd2"), + SHEX("a78a7a8d392f629d bd13674c8dce6fa2" + "930c74dec02a11d8 c80d90b5e5c887a7" + "83c92a921b5b2028 d9cb313a5f07ab09" + "672eadf1624a2ed0 c42d1b08b076f75a" + "7378272aa57ad7c8 803e326689541266"), + SHEX("b3d488986c80dea7 c5ebdab4907871c9" + "a4b92b13b79afb37 5518b01bfd706a37" + "8e44c2d463df4531 165461699edbad03" + "30ac8c52697102ae 3b725dba79ceb250" + "d308b83478e86dbb 629f18736cca042f")); test_cipher(&nettle_serpent128, - HL("e87450aa0fd87293fd0371483a459bd2"), - HL("a78a7a8d392f629d bd13674c8dce6fa2" - "930c74dec02a11d8 c80d90b5e5c887a7" - "83c92a921b5b2028 d9cb313a5f07ab09" - "672eadf1624a2ed0 c42d1b08b076f75a" - "7378272aa57ad7c8 803e326689541266" - "b7a2efda5721776f 4113d63a702ac3ae"), - H("b3d488986c80dea7 c5ebdab4907871c9" - "a4b92b13b79afb37 5518b01bfd706a37" - "8e44c2d463df4531 165461699edbad03" - "30ac8c52697102ae 3b725dba79ceb250" - "d308b83478e86dbb 629f18736cca042f" - "006b89e494469adf 0ee78c60684dff86")); + SHEX("e87450aa0fd87293fd0371483a459bd2"), + SHEX("a78a7a8d392f629d bd13674c8dce6fa2" + "930c74dec02a11d8 c80d90b5e5c887a7" + "83c92a921b5b2028 d9cb313a5f07ab09" + "672eadf1624a2ed0 c42d1b08b076f75a" + "7378272aa57ad7c8 803e326689541266" + "b7a2efda5721776f 4113d63a702ac3ae"), + SHEX("b3d488986c80dea7 c5ebdab4907871c9" + "a4b92b13b79afb37 5518b01bfd706a37" + "8e44c2d463df4531 165461699edbad03" + "30ac8c52697102ae 3b725dba79ceb250" + "d308b83478e86dbb 629f18736cca042f" + "006b89e494469adf 0ee78c60684dff86")); test_cipher(&nettle_serpent128, - HL("e87450aa0fd87293fd0371483a459bd2"), - HL("a78a7a8d392f629d bd13674c8dce6fa2" - "930c74dec02a11d8 c80d90b5e5c887a7" - "83c92a921b5b2028 d9cb313a5f07ab09" - "672eadf1624a2ed0 c42d1b08b076f75a" - "7378272aa57ad7c8 803e326689541266" - "b7a2efda5721776f 4113d63a702ac3ae" - "cd1be7bbfad74819 644617f8656e9e5b"), - H("b3d488986c80dea7 c5ebdab4907871c9" - "a4b92b13b79afb37 5518b01bfd706a37" - "8e44c2d463df4531 165461699edbad03" - "30ac8c52697102ae 3b725dba79ceb250" - "d308b83478e86dbb 629f18736cca042f" - "006b89e494469adf 0ee78c60684dff86" - "5f2c99908ee77ffe aea3d30cb78a1ce1")); + SHEX("e87450aa0fd87293fd0371483a459bd2"), + SHEX("a78a7a8d392f629d bd13674c8dce6fa2" + "930c74dec02a11d8 c80d90b5e5c887a7" + "83c92a921b5b2028 d9cb313a5f07ab09" + "672eadf1624a2ed0 c42d1b08b076f75a" + "7378272aa57ad7c8 803e326689541266" + "b7a2efda5721776f 4113d63a702ac3ae" + "cd1be7bbfad74819 644617f8656e9e5b"), + SHEX("b3d488986c80dea7 c5ebdab4907871c9" + "a4b92b13b79afb37 5518b01bfd706a37" + "8e44c2d463df4531 165461699edbad03" + "30ac8c52697102ae 3b725dba79ceb250" + "d308b83478e86dbb 629f18736cca042f" + "006b89e494469adf 0ee78c60684dff86" + "5f2c99908ee77ffe aea3d30cb78a1ce1")); test_cipher(&nettle_serpent128, - HL("e87450aa0fd87293fd0371483a459bd2"), - HL("a78a7a8d392f629d bd13674c8dce6fa2" - "930c74dec02a11d8 c80d90b5e5c887a7" - "83c92a921b5b2028 d9cb313a5f07ab09" - "672eadf1624a2ed0 c42d1b08b076f75a" - "7378272aa57ad7c8 803e326689541266" - "b7a2efda5721776f 4113d63a702ac3ae" - "cd1be7bbfad74819 644617f8656e9e5b" - "34d449409c1f850a 4cb6700d6ef3405f"), - H("b3d488986c80dea7 c5ebdab4907871c9" - "a4b92b13b79afb37 5518b01bfd706a37" - "8e44c2d463df4531 165461699edbad03" - "30ac8c52697102ae 3b725dba79ceb250" - "d308b83478e86dbb 629f18736cca042f" - "006b89e494469adf 0ee78c60684dff86" - "5f2c99908ee77ffe aea3d30cb78a1ce1" - "ebe855dd51532477 4d2d55969e032e6c")); - - SUCCESS(); + SHEX("e87450aa0fd87293fd0371483a459bd2"), + SHEX("a78a7a8d392f629d bd13674c8dce6fa2" + "930c74dec02a11d8 c80d90b5e5c887a7" + "83c92a921b5b2028 d9cb313a5f07ab09" + "672eadf1624a2ed0 c42d1b08b076f75a" + "7378272aa57ad7c8 803e326689541266" + "b7a2efda5721776f 4113d63a702ac3ae" + "cd1be7bbfad74819 644617f8656e9e5b" + "34d449409c1f850a 4cb6700d6ef3405f"), + SHEX("b3d488986c80dea7 c5ebdab4907871c9" + "a4b92b13b79afb37 5518b01bfd706a37" + "8e44c2d463df4531 165461699edbad03" + "30ac8c52697102ae 3b725dba79ceb250" + "d308b83478e86dbb 629f18736cca042f" + "006b89e494469adf 0ee78c60684dff86" + "5f2c99908ee77ffe aea3d30cb78a1ce1" + "ebe855dd51532477 4d2d55969e032e6c")); } diff --git a/testsuite/sexp-format-test.c b/testsuite/sexp-format-test.c index 33c585f4..736922b0 100644 --- a/testsuite/sexp-format-test.c +++ b/testsuite/sexp-format-test.c @@ -7,7 +7,7 @@ # include "bignum.h" #endif -int +void test_main(void) { struct nettle_buffer buffer; @@ -26,6 +26,7 @@ test_main(void) ASSERT(buffer.size == strlen(e)); ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + nettle_buffer_clear(&buffer); } { const uint8_t e[] = "{KDM6Zm9vKDM6YmFyMTc6eHh4eHh4eHh4eHh4eHh4eHgpKQ==}"; @@ -41,6 +42,7 @@ test_main(void) ASSERT(buffer.size == strlen(e)); ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + nettle_buffer_clear(&buffer); } { const uint8_t e[] = "1:\0""1:a2:bc3:def4:ghij5:\x00\xDE\xAD\xBE\xEF"; @@ -52,6 +54,7 @@ test_main(void) ASSERT(buffer.size == LLENGTH(e)); ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + nettle_buffer_clear(&buffer); } { @@ -64,6 +67,7 @@ test_main(void) ASSERT(buffer.size == strlen(e)); ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + nettle_buffer_clear(&buffer); } { @@ -75,6 +79,7 @@ test_main(void) == strlen(e)); ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + nettle_buffer_clear(&buffer); } /* Try literals */ @@ -92,6 +97,7 @@ test_main(void) ASSERT(buffer.size == strlen(e)); ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + nettle_buffer_clear(&buffer); } { const uint8_t e[] = "(3:foo(3:bar17:xxxxxxxxxxxxxxxxx))"; @@ -107,6 +113,7 @@ test_main(void) ASSERT(buffer.size == strlen(e)); ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + nettle_buffer_clear(&buffer); } /* Literal parenthesis */ @@ -122,6 +129,7 @@ test_main(void) ASSERT(buffer.size == strlen(e)); ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + nettle_buffer_clear(&buffer); } #if HAVE_LIBGMP @@ -133,8 +141,6 @@ test_main(void) const uint8_t e[] = "(3:foo(3:bar1:\xff""11:abcdefghijk13:\0\x81""abcdefghijk))"; - nettle_buffer_clear(&buffer); - mpz_init_set_si(x, -1); nettle_mpz_init_set_str_256_u(y, 11, "abcdefghijk"); nettle_mpz_init_set_str_256_u(z, 12, "\x81""abcdefghijk"); @@ -153,8 +159,8 @@ test_main(void) nettle_buffer_clear(&buffer); mpz_clear(x); + mpz_clear(y); + mpz_clear(z); } #endif /* HAVE_LIBGMP */ - - SUCCESS(); } diff --git a/testsuite/sexp-test.c b/testsuite/sexp-test.c index 4e68f569..324d61f0 100644 --- a/testsuite/sexp-test.c +++ b/testsuite/sexp-test.c @@ -1,7 +1,7 @@ #include "testutils.h" #include "sexp.h" -int +void test_main(void) { struct sexp_iterator i; @@ -32,7 +32,7 @@ test_main(void) ASSERT(sexp_iterator_get_uint32(&i, &x) && x == 0x11); ASSERT(sexp_iterator_get_uint32(&i, &x) && x == 0x80); ASSERT(sexp_iterator_get_uint32(&i, &x) && x == 0xaabbccdd); - + ASSERT(sexp_iterator_first(&i, LDATA("3:foo0:[3:bar]12:xxxxxxxxxxxx"))); ASSERT(i.type == SEXP_ATOM && !i.display_length && !i.display @@ -49,9 +49,11 @@ test_main(void) && sexp_iterator_next(&i) && i.type == SEXP_END); /* Same data, transport encoded. */ - - ASSERT(sexp_transport_iterator_first - (&i, LDUP("{Mzpmb28=} {MDo=} {WzM6YmFyXTEyOnh4eHh4eHh4eHh4eA==}"))); + + { + struct tstring *s + = tstring_data(LDATA("{Mzpmb28=} {MDo=} {WzM6YmFyXTEyOnh4eHh4eHh4eHh4eA==}")); + ASSERT(sexp_transport_iterator_first (&i, s->length, s->data)); ASSERT(i.type == SEXP_ATOM && !i.display_length && !i.display && i.atom_length == 3 && MEMEQ(3, "foo", i.atom) @@ -65,7 +67,8 @@ test_main(void) && i.atom_length == 12 && MEMEQ(12, "xxxxxxxxxxxx", i.atom) && sexp_iterator_next(&i) && i.type == SEXP_END); - + + } { static const uint8_t *keys[2] = { "n", "e" }; struct sexp_iterator v[2]; @@ -94,6 +97,4 @@ test_main(void) ASSERT(sexp_iterator_enter_list(&i) && !sexp_iterator_assoc(&i, 2, keys, v)); } - - SUCCESS(); } diff --git a/testsuite/sexp2rsa-test.c b/testsuite/sexp2rsa-test.c index 2e7cd916..9507d3a5 100644 --- a/testsuite/sexp2rsa-test.c +++ b/testsuite/sexp2rsa-test.c @@ -1,46 +1,45 @@ #include "testutils.h" -int +void test_main(void) { struct rsa_public_key pub; struct rsa_private_key priv; - + const struct tstring *sexp; + rsa_public_key_init(&pub); rsa_private_key_init(&priv); + sexp = SHEX("2831313a707269766174652d6b657928" + "333a72736128313a6e36333a085c3408" + "989acae4faec3cbbad91c90d34c1d259" + "cd74121a36f38b0b51424a9b2be514a0" + "4377113a6cdafe79dd7d5f2ecc8b5e96" + "61189b86a7b22239907c252928313a65" + "343a36ad4b1d2928313a6436333a06ee" + "6d4ff3c239e408150daf8117abfa36a4" + "0ad4455d9059a86d52f33a2de07418a0" + "a699594588c64810248c9412d554f74a" + "f947c73c32007e87c92f0937ed292831" + "3a7033323a03259879b24315e9cf1425" + "4824c7935d807cdb6990f414a0f65e60" + "65130a611f2928313a7133323a02a81b" + "a73bad45fc73b36deffce52d1b73e074" + "7f4d8a82648cecd310448ea63b292831" + "3a6133323a026cbdad5dd0046e093f06" + "0ecd5b4ac918e098b0278bb752b7cadd" + "6a8944f0b92928313a6233323a014875" + "1e622d6d58e3bb094afd6edacf737035" + "1d068e2ce9f565c5528c4a7473292831" + "3a6333323a00f8a458ea73a018dc6fa5" + "6863e3bc6de405f364f77dee6f096267" + "9ea1a8282e292929"); ASSERT(rsa_keypair_from_sexp - (&pub, &priv, 0, - HL("2831313a707269766174652d6b657928" - "333a72736128313a6e36333a085c3408" - "989acae4faec3cbbad91c90d34c1d259" - "cd74121a36f38b0b51424a9b2be514a0" - "4377113a6cdafe79dd7d5f2ecc8b5e96" - "61189b86a7b22239907c252928313a65" - "343a36ad4b1d2928313a6436333a06ee" - "6d4ff3c239e408150daf8117abfa36a4" - "0ad4455d9059a86d52f33a2de07418a0" - "a699594588c64810248c9412d554f74a" - "f947c73c32007e87c92f0937ed292831" - "3a7033323a03259879b24315e9cf1425" - "4824c7935d807cdb6990f414a0f65e60" - "65130a611f2928313a7133323a02a81b" - "a73bad45fc73b36deffce52d1b73e074" - "7f4d8a82648cecd310448ea63b292831" - "3a6133323a026cbdad5dd0046e093f06" - "0ecd5b4ac918e098b0278bb752b7cadd" - "6a8944f0b92928313a6233323a014875" - "1e622d6d58e3bb094afd6edacf737035" - "1d068e2ce9f565c5528c4a7473292831" - "3a6333323a00f8a458ea73a018dc6fa5" - "6863e3bc6de405f364f77dee6f096267" - "9ea1a8282e292929"))); + (&pub, &priv, 0, sexp->length, sexp->data)); test_rsa_key(&pub, &priv); rsa_public_key_clear(&pub); rsa_private_key_clear(&priv); - - SUCCESS(); } diff --git a/testsuite/sha1-huge-test.c b/testsuite/sha1-huge-test.c index 4f1b4dce..6557eadc 100644 --- a/testsuite/sha1-huge-test.c +++ b/testsuite/sha1-huge-test.c @@ -1,15 +1,13 @@ #include "testutils.h" #include "sha.h" -int +void test_main(void) { /* Hashes 10 000 000 x 30 000 bytes > 64 * 2^32. This overflows the low word of the block counter. This test vector is not cross checked with any other sha1 implementation. */ test_hash_large(&nettle_sha1, 10000000, 30000, 'a', - H("0ba79364dc64648f 2074fb4bc5c28bcf" - "b7a787b0")); - - SUCCESS(); + SHEX("0ba79364dc64648f 2074fb4bc5c28bcf" + "b7a787b0")); } diff --git a/testsuite/sha1-test.c b/testsuite/sha1-test.c index 8319086e..5f39c0fc 100644 --- a/testsuite/sha1-test.c +++ b/testsuite/sha1-test.c @@ -1,39 +1,37 @@ #include "testutils.h" #include "sha.h" -int +void test_main(void) { - test_hash(&nettle_sha1, 0, "", - H("DA39A3EE5E6B4B0D 3255BFEF95601890 AFD80709")); + test_hash(&nettle_sha1, SDATA(""), + SHEX("DA39A3EE5E6B4B0D 3255BFEF95601890 AFD80709")); - test_hash(&nettle_sha1, 1, "a", - H("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8")); + test_hash(&nettle_sha1, SDATA("a"), + SHEX("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8")); - test_hash(&nettle_sha1, 3, "abc", - H("A9993E364706816A BA3E25717850C26C 9CD0D89D")); + test_hash(&nettle_sha1, SDATA("abc"), + SHEX("A9993E364706816A BA3E25717850C26C 9CD0D89D")); - test_hash(&nettle_sha1, 26, "abcdefghijklmnopqrstuvwxyz", - H("32D10C7B8CF96570 CA04CE37F2A19D84 240D3A89")); + test_hash(&nettle_sha1, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("32D10C7B8CF96570 CA04CE37F2A19D84 240D3A89")); - test_hash(&nettle_sha1, 14, "message digest", - H("C12252CEDA8BE899 4D5FA0290A47231C 1D16AAE3")); + test_hash(&nettle_sha1, SDATA("message digest"), + SHEX("C12252CEDA8BE899 4D5FA0290A47231C 1D16AAE3")); - test_hash(&nettle_sha1, 62, - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz0123456789", - H("761C457BF73B14D2 7E9E9265C46F4B4D DA11F940")); + test_hash(&nettle_sha1, + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789"), + SHEX("761C457BF73B14D2 7E9E9265C46F4B4D DA11F940")); - test_hash(&nettle_sha1, 80, - "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890", - H("50ABF5706A150990 A08B2C5EA40FA0E5 85554732")); + test_hash(&nettle_sha1, + SDATA("1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890"), + SHEX("50ABF5706A150990 A08B2C5EA40FA0E5 85554732")); /* Additional test vector, from Daniel Kahn Gillmor */ - test_hash(&nettle_sha1, LDATA("38"), - H("5b384ce32d8cdef02bc3a139d4cac0a22bb029e8")); - - SUCCESS(); + test_hash(&nettle_sha1, SDATA("38"), + SHEX("5b384ce32d8cdef02bc3a139d4cac0a22bb029e8")); } /* These are intermediate values for the single sha1_compress call diff --git a/testsuite/sha224-test.c b/testsuite/sha224-test.c index cef82aff..8a001007 100644 --- a/testsuite/sha224-test.c +++ b/testsuite/sha224-test.c @@ -1,48 +1,46 @@ #include "testutils.h" #include "sha.h" -int +void test_main(void) { /* From FIPS180-2 addendum (http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf) */ - test_hash(&nettle_sha224, 3, "abc", - H("23097d22 3405d822 8642a477 bda255b3" - "2aadbce4 bda0b3f7 e36c9da7")); + test_hash(&nettle_sha224, SDATA("abc"), + SHEX("23097d22 3405d822 8642a477 bda255b3" + "2aadbce4 bda0b3f7 e36c9da7")); - test_hash(&nettle_sha224, 56, - "abcdbcdecdefdefgefghfghighij" - "hijkijkljklmklmnlmnomnopnopq", - H("75388b16 512776cc 5dba5da1 fd890150" - "b0c6455c b4f58b19 52522525")); + test_hash(&nettle_sha224, + SDATA("abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq"), + SHEX("75388b16 512776cc 5dba5da1 fd890150" + "b0c6455c b4f58b19 52522525")); /* Additional test vectors, from Daniel Kahn Gillmor */ - test_hash(&nettle_sha224, LDATA(""), - H("d14a028c2a3a2bc9 476102bb288234c4" - "15a2b01f828ea62a c5b3e42f")); - test_hash(&nettle_sha224, LDATA("a"), - H("abd37534c7d9a2ef b9465de931cd7055" - "ffdb8879563ae980 78d6d6d5")); - test_hash(&nettle_sha224, LDATA("38"), - H("4cfca6da32da6471 98225460722b7ea1" - "284f98c4b179e8db ae3f93d5")); - test_hash(&nettle_sha224, LDATA("message digest"), - H("2cb21c83ae2f004d e7e81c3c7019cbcb" - "65b71ab656b22d6d 0c39b8eb")); - test_hash(&nettle_sha224, LDATA("abcdefghijklmnopqrstuvwxyz"), - H("45a5f72c39c5cff2 522eb3429799e49e" - "5f44b356ef926bcf 390dccc2")); + test_hash(&nettle_sha224, SDATA(""), + SHEX("d14a028c2a3a2bc9 476102bb288234c4" + "15a2b01f828ea62a c5b3e42f")); + test_hash(&nettle_sha224, SDATA("a"), + SHEX("abd37534c7d9a2ef b9465de931cd7055" + "ffdb8879563ae980 78d6d6d5")); + test_hash(&nettle_sha224, SDATA("38"), + SHEX("4cfca6da32da6471 98225460722b7ea1" + "284f98c4b179e8db ae3f93d5")); + test_hash(&nettle_sha224, SDATA("message digest"), + SHEX("2cb21c83ae2f004d e7e81c3c7019cbcb" + "65b71ab656b22d6d 0c39b8eb")); + test_hash(&nettle_sha224, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("45a5f72c39c5cff2 522eb3429799e49e" + "5f44b356ef926bcf 390dccc2")); test_hash(&nettle_sha224, - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" "ghijklmnopqrstuvwxyz0123456789"), - H("bff72b4fcb7d75e5 632900ac5f90d219" - "e05e97a7bde72e74 0db393d9")); + SHEX("bff72b4fcb7d75e5 632900ac5f90d219" + "e05e97a7bde72e74 0db393d9")); test_hash(&nettle_sha224, - LDATA("12345678901234567890123456789012" + SDATA("12345678901234567890123456789012" "34567890123456789012345678901234" "5678901234567890"), - H("b50aecbe4e9bb0b5 7bc5f3ae760a8e01" - "db24f203fb3cdcd1 3148046e")); - - SUCCESS(); + SHEX("b50aecbe4e9bb0b5 7bc5f3ae760a8e01" + "db24f203fb3cdcd1 3148046e")); } diff --git a/testsuite/sha256-test.c b/testsuite/sha256-test.c index 74995218..43adcc2b 100644 --- a/testsuite/sha256-test.c +++ b/testsuite/sha256-test.c @@ -1,55 +1,53 @@ #include "testutils.h" #include "sha.h" -int +void test_main(void) { /* From FIPS180-2 */ - test_hash(&nettle_sha256, 3, "abc", - H("ba7816bf8f01cfea 414140de5dae2223" - "b00361a396177a9c b410ff61f20015ad")); + test_hash(&nettle_sha256, SDATA("abc"), + SHEX("ba7816bf8f01cfea 414140de5dae2223" + "b00361a396177a9c b410ff61f20015ad")); - test_hash(&nettle_sha256, 56, - "abcdbcdecdefdefgefghfghighij" - "hijkijkljklmklmnlmnomnopnopq", - H("248d6a61d20638b8 e5c026930c3e6039" - "a33ce45964ff2167 f6ecedd419db06c1")); + test_hash(&nettle_sha256, + SDATA("abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq"), + SHEX("248d6a61d20638b8 e5c026930c3e6039" + "a33ce45964ff2167 f6ecedd419db06c1")); - test_hash(&nettle_sha256, 112, - "abcdefghbcdefghicdefghijdefg" - "hijkefghijklfghijklmghijklmn" - "hijklmnoijklmnopjklmnopqklmn" - "opqrlmnopqrsmnopqrstnopqrstu", - H("cf5b16a778af8380 036ce59e7b049237" - "0b249b11e8f07a51 afac45037afee9d1")); + test_hash(&nettle_sha256, + SDATA("abcdefghbcdefghicdefghijdefg" + "hijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmn" + "opqrlmnopqrsmnopqrstnopqrstu"), + SHEX("cf5b16a778af8380 036ce59e7b049237" + "0b249b11e8f07a51 afac45037afee9d1")); /* Additional test vectors, from Daniel Kahn Gillmor */ - test_hash(&nettle_sha256, LDATA(""), - H("e3b0c44298fc1c14 9afbf4c8996fb924" - "27ae41e4649b934c a495991b7852b855")); - test_hash(&nettle_sha256, LDATA("a"), - H("ca978112ca1bbdca fac231b39a23dc4d" - "a786eff8147c4e72 b9807785afee48bb")); - test_hash(&nettle_sha256, LDATA("38"), - H("aea92132c4cbeb26 3e6ac2bf6c183b5d" - "81737f179f21efdc 5863739672f0f470")); - test_hash(&nettle_sha256, LDATA("message digest"), - H("f7846f55cf23e14e ebeab5b4e1550cad" - "5b509e3348fbc4ef a3a1413d393cb650")); - test_hash(&nettle_sha256, LDATA("abcdefghijklmnopqrstuvwxyz"), - H("71c480df93d6ae2f 1efad1447c66c952" - "5e316218cf51fc8d 9ed832f2daf18b73")); + test_hash(&nettle_sha256, SDATA(""), + SHEX("e3b0c44298fc1c14 9afbf4c8996fb924" + "27ae41e4649b934c a495991b7852b855")); + test_hash(&nettle_sha256, SDATA("a"), + SHEX("ca978112ca1bbdca fac231b39a23dc4d" + "a786eff8147c4e72 b9807785afee48bb")); + test_hash(&nettle_sha256, SDATA("38"), + SHEX("aea92132c4cbeb26 3e6ac2bf6c183b5d" + "81737f179f21efdc 5863739672f0f470")); + test_hash(&nettle_sha256, SDATA("message digest"), + SHEX("f7846f55cf23e14e ebeab5b4e1550cad" + "5b509e3348fbc4ef a3a1413d393cb650")); + test_hash(&nettle_sha256, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("71c480df93d6ae2f 1efad1447c66c952" + "5e316218cf51fc8d 9ed832f2daf18b73")); test_hash(&nettle_sha256, - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" "ghijklmnopqrstuvwxyz0123456789"), - H("db4bfcbd4da0cd85 a60c3c37d3fbd880" - "5c77f15fc6b1fdfe 614ee0a7c8fdb4c0")); + SHEX("db4bfcbd4da0cd85 a60c3c37d3fbd880" + "5c77f15fc6b1fdfe 614ee0a7c8fdb4c0")); test_hash(&nettle_sha256, - LDATA("12345678901234567890123456789012" + SDATA("12345678901234567890123456789012" "34567890123456789012345678901234" "5678901234567890"), - H("f371bc4a311f2b00 9eef952dd83ca80e" - "2b60026c8e935592 d0f9c308453c813e")); - - SUCCESS(); + SHEX("f371bc4a311f2b00 9eef952dd83ca80e" + "2b60026c8e935592 d0f9c308453c813e")); } diff --git a/testsuite/sha384-test.c b/testsuite/sha384-test.c index 086e115b..7b94fa48 100644 --- a/testsuite/sha384-test.c +++ b/testsuite/sha384-test.c @@ -1,57 +1,55 @@ #include "testutils.h" #include "sha.h" -int +void test_main(void) { - test_hash(&nettle_sha384, 3, "abc", - H("cb00753f45a35e8b b5a03d699ac65007" - "272c32ab0eded163 1a8b605a43ff5bed" - "8086072ba1e7cc23 58baeca134c825a7")); + test_hash(&nettle_sha384, SDATA("abc"), + SHEX("cb00753f45a35e8b b5a03d699ac65007" + "272c32ab0eded163 1a8b605a43ff5bed" + "8086072ba1e7cc23 58baeca134c825a7")); - test_hash(&nettle_sha384, 112, - "abcdefghbcdefghicdefghijdefg" - "hijkefghijklfghijklmghijklmn" - "hijklmnoijklmnopjklmnopqklmn" - "opqrlmnopqrsmnopqrstnopqrstu", - H("09330c33f71147e8 3d192fc782cd1b47" - "53111b173b3b05d2 2fa08086e3b0f712" - "fcc7c71a557e2db9 66c3e9fa91746039")); + test_hash(&nettle_sha384, + SDATA("abcdefghbcdefghicdefghijdefg" + "hijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmn" + "opqrlmnopqrsmnopqrstnopqrstu"), + SHEX("09330c33f71147e8 3d192fc782cd1b47" + "53111b173b3b05d2 2fa08086e3b0f712" + "fcc7c71a557e2db9 66c3e9fa91746039")); /* Additional test vectors, from Daniel Kahn Gillmor */ - test_hash(&nettle_sha384, LDATA(""), - H("38b060a751ac9638 4cd9327eb1b1e36a" - "21fdb71114be0743 4c0cc7bf63f6e1da" - "274edebfe76f65fb d51ad2f14898b95b")); - test_hash(&nettle_sha384, LDATA("a"), - H("54a59b9f22b0b808 80d8427e548b7c23" - "abd873486e1f035d ce9cd697e8517503" - "3caa88e6d57bc35e fae0b5afd3145f31")); - test_hash(&nettle_sha384, LDATA("38"), - H("c071d202ad950b6a 04a5f15c24596a99" - "3af8b212467958d5 70a3ffd478006063" - "8e3a3d06637691d3 012bd31122071b2c")); - test_hash(&nettle_sha384, LDATA("message digest"), - H("473ed35167ec1f5d 8e550368a3db39be" - "54639f828868e945 4c239fc8b52e3c61" - "dbd0d8b4de1390c2 56dcbb5d5fd99cd5")); - test_hash(&nettle_sha384, LDATA("abcdefghijklmnopqrstuvwxyz"), - H("feb67349df3db6f5 924815d6c3dc133f" - "091809213731fe5c 7b5f4999e463479f" - "f2877f5f2936fa63 bb43784b12f3ebb4")); + test_hash(&nettle_sha384, SDATA(""), + SHEX("38b060a751ac9638 4cd9327eb1b1e36a" + "21fdb71114be0743 4c0cc7bf63f6e1da" + "274edebfe76f65fb d51ad2f14898b95b")); + test_hash(&nettle_sha384, SDATA("a"), + SHEX("54a59b9f22b0b808 80d8427e548b7c23" + "abd873486e1f035d ce9cd697e8517503" + "3caa88e6d57bc35e fae0b5afd3145f31")); + test_hash(&nettle_sha384, SDATA("38"), + SHEX("c071d202ad950b6a 04a5f15c24596a99" + "3af8b212467958d5 70a3ffd478006063" + "8e3a3d06637691d3 012bd31122071b2c")); + test_hash(&nettle_sha384, SDATA("message digest"), + SHEX("473ed35167ec1f5d 8e550368a3db39be" + "54639f828868e945 4c239fc8b52e3c61" + "dbd0d8b4de1390c2 56dcbb5d5fd99cd5")); + test_hash(&nettle_sha384, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("feb67349df3db6f5 924815d6c3dc133f" + "091809213731fe5c 7b5f4999e463479f" + "f2877f5f2936fa63 bb43784b12f3ebb4")); test_hash(&nettle_sha384, - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" "ghijklmnopqrstuvwxyz0123456789"), - H("1761336e3f7cbfe5 1deb137f026f89e0" - "1a448e3b1fafa640 39c1464ee8732f11" - "a5341a6f41e0c202 294736ed64db1a84")); + SHEX("1761336e3f7cbfe5 1deb137f026f89e0" + "1a448e3b1fafa640 39c1464ee8732f11" + "a5341a6f41e0c202 294736ed64db1a84")); test_hash(&nettle_sha384, - LDATA("12345678901234567890123456789012" + SDATA("12345678901234567890123456789012" "34567890123456789012345678901234" "5678901234567890"), - H("b12932b0627d1c06 0942f54477641556" - "55bd4da0c9afa6dd 9b9ef53129af1b8f" - "b0195996d2de9ca0 df9d821ffee67026")); - - SUCCESS(); + SHEX("b12932b0627d1c06 0942f54477641556" + "55bd4da0c9afa6dd 9b9ef53129af1b8f" + "b0195996d2de9ca0 df9d821ffee67026")); } diff --git a/testsuite/sha512-test.c b/testsuite/sha512-test.c index 97bde532..490935b8 100644 --- a/testsuite/sha512-test.c +++ b/testsuite/sha512-test.c @@ -1,66 +1,64 @@ #include "testutils.h" #include "sha.h" -int +void test_main(void) { - test_hash(&nettle_sha512, 3, "abc", - H("ddaf35a193617aba cc417349ae204131" - "12e6fa4e89a97ea2 0a9eeee64b55d39a" - "2192992a274fc1a8 36ba3c23a3feebbd" - "454d4423643ce80e 2a9ac94fa54ca49f")); + test_hash(&nettle_sha512, SDATA("abc"), + SHEX("ddaf35a193617aba cc417349ae204131" + "12e6fa4e89a97ea2 0a9eeee64b55d39a" + "2192992a274fc1a8 36ba3c23a3feebbd" + "454d4423643ce80e 2a9ac94fa54ca49f")); - test_hash(&nettle_sha512, 112, - "abcdefghbcdefghicdefghijdefg" - "hijkefghijklfghijklmghijklmn" - "hijklmnoijklmnopjklmnopqklmn" - "opqrlmnopqrsmnopqrstnopqrstu", - H("8e959b75dae313da 8cf4f72814fc143f" - "8f7779c6eb9f7fa1 7299aeadb6889018" - "501d289e4900f7e4 331b99dec4b5433a" - "c7d329eeb6dd2654 5e96e55b874be909")); + test_hash(&nettle_sha512, + SDATA("abcdefghbcdefghicdefghijdefg" + "hijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmn" + "opqrlmnopqrsmnopqrstnopqrstu"), + SHEX("8e959b75dae313da 8cf4f72814fc143f" + "8f7779c6eb9f7fa1 7299aeadb6889018" + "501d289e4900f7e4 331b99dec4b5433a" + "c7d329eeb6dd2654 5e96e55b874be909")); /* Additional test vectors, from Daniel Kahn Gillmor */ - test_hash(&nettle_sha512, LDATA(""), - H("cf83e1357eefb8bd f1542850d66d8007" - "d620e4050b5715dc 83f4a921d36ce9ce" - "47d0d13c5d85f2b0 ff8318d2877eec2f" - "63b931bd47417a81 a538327af927da3e")); - test_hash(&nettle_sha512, LDATA("a"), - H("1f40fc92da241694 750979ee6cf582f2" - "d5d7d28e18335de0 5abc54d0560e0f53" - "02860c652bf08d56 0252aa5e74210546" - "f369fbbbce8c12cf c7957b2652fe9a75")); - test_hash(&nettle_sha512, LDATA("38"), - H("caae34a5e8103126 8bcdaf6f1d8c04d3" - "7b7f2c349afb705b 575966f63e2ebf0f" - "d910c3b05160ba08 7ab7af35d40b7c71" - "9c53cd8b947c9611 1f64105fd45cc1b2")); - test_hash(&nettle_sha512, LDATA("message digest"), - H("107dbf389d9e9f71 a3a95f6c055b9251" - "bc5268c2be16d6c1 3492ea45b0199f33" - "09e16455ab1e9611 8e8a905d5597b720" - "38ddb372a8982604 6de66687bb420e7c")); - test_hash(&nettle_sha512, LDATA("abcdefghijklmnopqrstuvwxyz"), - H("4dbff86cc2ca1bae 1e16468a05cb9881" - "c97f1753bce36190 34898faa1aabe429" - "955a1bf8ec483d74 21fe3c1646613a59" - "ed5441fb0f321389 f77f48a879c7b1f1")); + test_hash(&nettle_sha512, SDATA(""), + SHEX("cf83e1357eefb8bd f1542850d66d8007" + "d620e4050b5715dc 83f4a921d36ce9ce" + "47d0d13c5d85f2b0 ff8318d2877eec2f" + "63b931bd47417a81 a538327af927da3e")); + test_hash(&nettle_sha512, SDATA("a"), + SHEX("1f40fc92da241694 750979ee6cf582f2" + "d5d7d28e18335de0 5abc54d0560e0f53" + "02860c652bf08d56 0252aa5e74210546" + "f369fbbbce8c12cf c7957b2652fe9a75")); + test_hash(&nettle_sha512, SDATA("38"), + SHEX("caae34a5e8103126 8bcdaf6f1d8c04d3" + "7b7f2c349afb705b 575966f63e2ebf0f" + "d910c3b05160ba08 7ab7af35d40b7c71" + "9c53cd8b947c9611 1f64105fd45cc1b2")); + test_hash(&nettle_sha512, SDATA("message digest"), + SHEX("107dbf389d9e9f71 a3a95f6c055b9251" + "bc5268c2be16d6c1 3492ea45b0199f33" + "09e16455ab1e9611 8e8a905d5597b720" + "38ddb372a8982604 6de66687bb420e7c")); + test_hash(&nettle_sha512, SDATA("abcdefghijklmnopqrstuvwxyz"), + SHEX("4dbff86cc2ca1bae 1e16468a05cb9881" + "c97f1753bce36190 34898faa1aabe429" + "955a1bf8ec483d74 21fe3c1646613a59" + "ed5441fb0f321389 f77f48a879c7b1f1")); test_hash(&nettle_sha512, - LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" + SDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef" "ghijklmnopqrstuvwxyz0123456789"), - H("1e07be23c26a86ea 37ea810c8ec78093" - "52515a970e9253c2 6f536cfc7a9996c4" - "5c8370583e0a78fa 4a90041d71a4ceab" - "7423f19c71b9d5a3 e01249f0bebd5894")); + SHEX("1e07be23c26a86ea 37ea810c8ec78093" + "52515a970e9253c2 6f536cfc7a9996c4" + "5c8370583e0a78fa 4a90041d71a4ceab" + "7423f19c71b9d5a3 e01249f0bebd5894")); test_hash(&nettle_sha512, - LDATA("12345678901234567890123456789012" + SDATA("12345678901234567890123456789012" "34567890123456789012345678901234" "5678901234567890"), - H("72ec1ef1124a45b0 47e8b7c75a932195" - "135bb61de24ec0d1 914042246e0aec3a" - "2354e093d76f3048 b456764346900cb1" - "30d2a4fd5dd16abb 5e30bcb850dee843")); - - SUCCESS(); + SHEX("72ec1ef1124a45b0 47e8b7c75a932195" + "135bb61de24ec0d1 914042246e0aec3a" + "2354e093d76f3048 b456764346900cb1" + "30d2a4fd5dd16abb 5e30bcb850dee843")); } diff --git a/testsuite/testutils.c b/testsuite/testutils.c index d77bb7ef..de9baa43 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -46,7 +46,38 @@ xalloc(size_t size) return p; } -unsigned +static struct tstring *tstring_first = NULL; + +struct tstring * +tstring_alloc (unsigned length) +{ + struct tstring *s = xalloc(sizeof(struct tstring) + length - 1); + s->length = length; + s->next = tstring_first; + tstring_first = s; + return s; +} + +void +tstring_clear(void) +{ + while (tstring_first) + { + struct tstring *s = tstring_first; + tstring_first = s->next; + free(s); + } +} + +struct tstring * +tstring_data(unsigned length, const char *data) +{ + struct tstring *s = tstring_alloc (length); + memcpy (s->data, data, length); + return s; +} + +static unsigned decode_hex_length(const char *h) { const unsigned char *hex = (const unsigned char *) h; @@ -67,7 +98,7 @@ decode_hex_length(const char *h) return count / 2; } -int +static void decode_hex(uint8_t *dst, const char *h) { const unsigned char *hex = (const unsigned char *) h; @@ -81,41 +112,39 @@ decode_hex(uint8_t *dst, const char *h) hex++; if (!*hex) - return 1; + return; high = hex_digits[*hex++]; - if (high < 0) - return 0; + ASSERT (high >= 0); while (*hex && isspace(*hex)) hex++; - if (!*hex) - return 0; + ASSERT (*hex); low = hex_digits[*hex++]; - if (low < 0) - return 0; + ASSERT (low >= 0); dst[i++] = (high << 4) | low; } } -const uint8_t * -decode_hex_dup(const char *hex) +struct tstring * +tstring_hex(const char *hex) { - uint8_t *p; + struct tstring *s; unsigned length = decode_hex_length(hex); - p = xalloc(length); + s = tstring_alloc(length); - if (decode_hex(p, hex)) - return p; - else - { - free(p); - return NULL; - } + decode_hex(s->data, hex); + return s; +} + +void +tstring_print_hex(const struct tstring *s) +{ + print_hex (s->length, s->data); } void @@ -158,45 +187,49 @@ main(int argc, char **argv) } } - return test_main(); + test_main(); + + tstring_clear(); + return EXIT_SUCCESS; } void test_cipher(const struct nettle_cipher *cipher, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext) + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext) { void *ctx = xalloc(cipher->context_size); - uint8_t *data = xalloc(length); + uint8_t *data = xalloc(cleartext->length); + unsigned length; + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; - cipher->set_encrypt_key(ctx, key_length, key); - cipher->encrypt(ctx, length, data, cleartext); + cipher->set_encrypt_key(ctx, key->length, key->data); + cipher->encrypt(ctx, length, data, cleartext->data); - if (!MEMEQ(length, data, ciphertext)) + if (!MEMEQ(length, data, ciphertext->data)) { fprintf(stderr, "Encrypt failed:\nInput:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\n"); FAIL(); } - cipher->set_decrypt_key(ctx, key_length, key); + cipher->set_decrypt_key(ctx, key->length, key->data); cipher->decrypt(ctx, length, data, data); - if (!MEMEQ(length, data, cleartext)) + if (!MEMEQ(length, data, cleartext->data)) { fprintf(stderr, "Decrypt failed:\nInput:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } @@ -207,53 +240,59 @@ test_cipher(const struct nettle_cipher *cipher, void test_cipher_cbc(const struct nettle_cipher *cipher, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext, - const uint8_t *iiv) + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext, + const struct tstring *iiv) { void *ctx = xalloc(cipher->context_size); - uint8_t *data = xalloc(length); + uint8_t *data; uint8_t *iv = xalloc(cipher->block_size); - - cipher->set_encrypt_key(ctx, key_length, key); - memcpy(iv, iiv, cipher->block_size); + unsigned length; + + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; + + ASSERT (iiv->length == cipher->block_size); + + data = xalloc(length); + cipher->set_encrypt_key(ctx, key->length, key->data); + memcpy(iv, iiv->data, cipher->block_size); cbc_encrypt(ctx, cipher->encrypt, cipher->block_size, iv, - length, data, cleartext); + length, data, cleartext->data); - if (!MEMEQ(length, data, ciphertext)) + if (!MEMEQ(length, data, ciphertext->data)) { fprintf(stderr, "CBC encrypt failed:\nInput:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\n"); FAIL(); } - cipher->set_decrypt_key(ctx, key_length, key); - memcpy(iv, iiv, cipher->block_size); + cipher->set_decrypt_key(ctx, key->length, key->data); + memcpy(iv, iiv->data, cipher->block_size); cbc_decrypt(ctx, cipher->decrypt, cipher->block_size, iv, length, data, data); - if (!MEMEQ(length, data, cleartext)) + if (!MEMEQ(length, data, cleartext->data)) { fprintf(stderr, "CBC decrypt failed:\nInput:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } + free(ctx); free(data); free(iv); @@ -261,50 +300,56 @@ test_cipher_cbc(const struct nettle_cipher *cipher, void test_cipher_ctr(const struct nettle_cipher *cipher, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext, - const uint8_t *ictr) + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext, + const struct tstring *ictr) { void *ctx = xalloc(cipher->context_size); - uint8_t *data = xalloc(length); + uint8_t *data; uint8_t *ctr = xalloc(cipher->block_size); + unsigned length; + + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; + + ASSERT (ictr->length == cipher->block_size); - cipher->set_encrypt_key(ctx, key_length, key); - memcpy(ctr, ictr, cipher->block_size); + data = xalloc(length); + + cipher->set_encrypt_key(ctx, key->length, key->data); + memcpy(ctr, ictr->data, cipher->block_size); ctr_crypt(ctx, cipher->encrypt, cipher->block_size, ctr, - length, data, cleartext); + length, data, cleartext->data); - if (!MEMEQ(length, data, ciphertext)) + if (!MEMEQ(length, data, ciphertext->data)) { fprintf(stderr, "CTR encrypt failed:\nInput:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\n"); FAIL(); } - memcpy(ctr, ictr, cipher->block_size); + memcpy(ctr, ictr->data, cipher->block_size); ctr_crypt(ctx, cipher->encrypt, cipher->block_size, ctr, length, data, data); - if (!MEMEQ(length, data, cleartext)) + if (!MEMEQ(length, data, cleartext->data)) { fprintf(stderr, "CTR decrypt failed:\nInput:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } @@ -316,62 +361,63 @@ test_cipher_ctr(const struct nettle_cipher *cipher, void test_cipher_stream(const struct nettle_cipher *cipher, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext) + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext) { unsigned block; void *ctx = xalloc(cipher->context_size); - uint8_t *data = xalloc(length + 1); - + uint8_t *data; + unsigned length; + + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; + + data = xalloc(length + 1); + for (block = 1; block <= length; block++) { unsigned i; memset(data, 0x17, length + 1); - cipher->set_encrypt_key(ctx, key_length, key); + cipher->set_encrypt_key(ctx, key->length, key->data); for (i = 0; i + block < length; i += block) { - cipher->encrypt(ctx, block, data + i, cleartext + i); - if (data[i + block] != 0x17) - FAIL(); + cipher->encrypt(ctx, block, data + i, cleartext->data + i); + ASSERT (data[i + block] == 0x17); } - cipher->encrypt(ctx, length - i, data + i, cleartext + i); - if (data[length] != 0x17) - FAIL(); + cipher->encrypt(ctx, length - i, data + i, cleartext->data + i); + ASSERT (data[length] == 0x17); - if (!MEMEQ(length, data, ciphertext)) + if (!MEMEQ(length, data, ciphertext->data)) { fprintf(stderr, "Encrypt failed, block size %d\nInput:", block); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\n"); FAIL(); } } - cipher->set_decrypt_key(ctx, key_length, key); + cipher->set_decrypt_key(ctx, key->length, key->data); cipher->decrypt(ctx, length, data, data); - if (data[length] != 0x17) - FAIL(); + ASSERT (data[length] == 0x17); - if (!MEMEQ(length, data, cleartext)) + if (!MEMEQ(length, data, cleartext->data)) { fprintf(stderr, "Decrypt failed\nInput:"); - print_hex(length, ciphertext); + tstring_print_hex(ciphertext); fprintf(stderr, "\nOutput: "); print_hex(length, data); fprintf(stderr, "\nExpected:"); - print_hex(length, cleartext); + tstring_print_hex(cleartext); fprintf(stderr, "\n"); FAIL(); } @@ -382,58 +428,56 @@ test_cipher_stream(const struct nettle_cipher *cipher, void test_aead(const struct nettle_aead *aead, - unsigned key_length, - const uint8_t *key, - unsigned auth_length, - const uint8_t *authtext, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext, - unsigned iv_length, - const uint8_t *iv, - const uint8_t *digest) + const struct tstring *key, + const struct tstring *authtext, + const struct tstring *cleartext, + const struct tstring *ciphertext, + const struct tstring *iv, + const struct tstring *digest) { void *ctx = xalloc(aead->context_size); - uint8_t *data = xalloc(length); + uint8_t *data; uint8_t *buffer = xalloc(aead->block_size); + unsigned length; + + ASSERT (cleartext->length == ciphertext->length); + length = cleartext->length; + ASSERT (digest->length == aead->block_size); + + data = xalloc(length); + /* encryption */ memset(buffer, 0, aead->block_size); - aead->set_key(ctx, key_length, key); + aead->set_key(ctx, key->length, key->data); - aead->set_iv(ctx, iv_length, iv); + aead->set_iv(ctx, iv->length, iv->data); - if (auth_length) - aead->update(ctx, auth_length, authtext); + if (authtext->length) + aead->update(ctx, authtext->length, authtext->data); if (length) - aead->encrypt(ctx, length, data, cleartext); + aead->encrypt(ctx, length, data, cleartext->data); aead->digest(ctx, aead->block_size, buffer); - if (!MEMEQ(length, data, ciphertext)) - FAIL(); - - if (!MEMEQ(aead->block_size, buffer, digest)) - FAIL(); + ASSERT(MEMEQ(length, data, ciphertext->data)); + ASSERT(MEMEQ(aead->block_size, buffer, digest->data)); /* decryption */ memset(buffer, 0, aead->block_size); - aead->set_iv(ctx, iv_length, iv); + aead->set_iv(ctx, iv->length, iv->data); - if (auth_length) - aead->update(ctx, auth_length, authtext); + if (authtext->length) + aead->update(ctx, authtext->length, authtext->data); if (length) aead->decrypt(ctx, length, data, data); aead->digest(ctx, aead->block_size, buffer); - if (!MEMEQ(length, data, cleartext)) - FAIL(); - - if (!MEMEQ(aead->block_size, buffer, digest)) - FAIL(); + ASSERT(MEMEQ(length, data, cleartext->data)); + ASSERT(MEMEQ(aead->block_size, buffer, digest->data)); free(ctx); free(data); @@ -442,31 +486,29 @@ test_aead(const struct nettle_aead *aead, void test_hash(const struct nettle_hash *hash, - unsigned length, - const uint8_t *data, - const uint8_t *digest) + const struct tstring *msg, + const struct tstring *digest) { void *ctx = xalloc(hash->context_size); uint8_t *buffer = xalloc(hash->digest_size); + ASSERT (digest->length == hash->digest_size); + hash->init(ctx); - hash->update(ctx, length, data); + hash->update(ctx, msg->length, msg->data); hash->digest(ctx, hash->digest_size, buffer); - if (!MEMEQ(hash->digest_size, digest, buffer)) - FAIL(); + ASSERT(MEMEQ(hash->digest_size, digest->data, buffer)); memset(buffer, 0, hash->digest_size); hash->init(ctx); - hash->update(ctx, length, data); + hash->update(ctx, msg->length, msg->data); hash->digest(ctx, hash->digest_size - 1, buffer); - if (!MEMEQ(hash->digest_size - 1, digest, buffer)) - FAIL(); + ASSERT(MEMEQ(hash->digest_size - 1, digest->data, buffer)); - if (buffer[hash->digest_size - 1]) - FAIL(); + ASSERT(buffer[hash->digest_size - 1] == 0); free(ctx); free(buffer); @@ -476,13 +518,15 @@ void test_hash_large(const struct nettle_hash *hash, unsigned count, unsigned length, uint8_t c, - const uint8_t *digest) + const struct tstring *digest) { void *ctx = xalloc(hash->context_size); uint8_t *buffer = xalloc(hash->digest_size); uint8_t *data = xalloc(length); unsigned i; + ASSERT (digest->length == hash->digest_size); + memset(data, c, length); hash->init(ctx); @@ -492,32 +536,13 @@ test_hash_large(const struct nettle_hash *hash, print_hex(hash->digest_size, buffer); - if (!MEMEQ(hash->digest_size, digest, buffer)) - FAIL(); + ASSERT (MEMEQ(hash->digest_size, digest->data, buffer)); free(ctx); free(buffer); free(data); } -void -test_mac(const struct nettle_mac *mac, - unsigned key_length, const uint8_t *key, - unsigned msg_length, const uint8_t *msg, - const uint8_t *digest) -{ - void *ctx = xalloc(mac->context_size); - uint8_t *buffer = xalloc(mac->digest_size); - - mac->set_key(ctx, key_length, key); - mac->update(ctx, msg_length, msg); - mac->digest(ctx, mac->digest_size, buffer); - ASSERT(MEMEQ(mac->digest_size, digest, buffer)); - - free(ctx); - free(buffer); -} - void test_armor(const struct nettle_armor *armor, unsigned data_length, @@ -544,11 +569,8 @@ test_armor(const struct nettle_armor *armor, done += armor->encode_final(encode, buffer + done); ASSERT(done == ascii_length); - if (!MEMEQ(ascii_length, buffer, ascii)) - FAIL(); - - if (0x33 != buffer[strlen(ascii)]) - FAIL(); + ASSERT (MEMEQ(ascii_length, buffer, ascii)); + ASSERT (0x33 == buffer[strlen(ascii)]); armor->decode_init(decode); done = armor->decode_length(ascii_length); @@ -557,11 +579,8 @@ test_armor(const struct nettle_armor *armor, ASSERT(done == data_length); ASSERT(armor->decode_final(decode)); - if (!MEMEQ(data_length, check, data)) - FAIL(); - - if (0x55 != check[data_length]) - FAIL(); + ASSERT (MEMEQ(data_length, check, data)); + ASSERT (0x55 == check[data_length]); free(buffer); free(check); @@ -582,8 +601,9 @@ mpz_togglebit (mpz_t x, unsigned long int bit) #endif /* HAVE_LIBGMP */ #if WITH_HOGWEED + #define SIGN(key, hash, msg, signature) do { \ - hash##_update(&hash, LDATA(msg)); \ + hash##_update(&hash, LDATA(msg)); \ ASSERT(rsa_##hash##_sign(key, &hash, signature)); \ } while(0) @@ -641,8 +661,7 @@ test_rsa_set_key_1(struct rsa_public_key *pub, "e545fbb4cf", 16); mpz_set_str(pub->e, "0db2ad57", 16); - if (!rsa_public_key_prepare(pub)) - FAIL(); + ASSERT (rsa_public_key_prepare(pub)); /* d is not used */ #if 0 @@ -680,11 +699,8 @@ test_rsa_set_key_1(struct rsa_public_key *pub, "e2df9607cee95fa8" "daec7a389a7d9afc" "8dd21fef9d83805a" "40d46f49676a2f6b" "2926f70c572c00", 16); - if (!rsa_private_key_prepare(key)) - FAIL(); - - if (pub->size != key->size) - FAIL(); + ASSERT (rsa_private_key_prepare(key)); + ASSERT (pub->size == key->size); } void @@ -707,25 +723,20 @@ test_rsa_md5(struct rsa_public_key *pub, fprintf(stderr, "\n"); } - if (mpz_cmp(signature, expected)) - FAIL(); + ASSERT (mpz_cmp(signature, expected) == 0); /* Try bad data */ - if (VERIFY(pub, md5, - "The magick words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (!VERIFY(pub, md5, + "The magick words are squeamish ossifrage", signature)); /* Try correct data */ - if (!VERIFY(pub, md5, - "The magic words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (VERIFY(pub, md5, + "The magic words are squeamish ossifrage", signature)); /* Try bad signature */ mpz_togglebit(signature, 17); - - if (VERIFY(pub, md5, - "The magic words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (!VERIFY(pub, md5, + "The magic words are squeamish ossifrage", signature)); mpz_clear(signature); } @@ -750,25 +761,20 @@ test_rsa_sha1(struct rsa_public_key *pub, fprintf(stderr, "\n"); } - if (mpz_cmp(signature, expected)) - FAIL(); + ASSERT (mpz_cmp(signature, expected) == 0); /* Try bad data */ - if (VERIFY(pub, sha1, - "The magick words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (!VERIFY(pub, sha1, + "The magick words are squeamish ossifrage", signature)); /* Try correct data */ - if (!VERIFY(pub, sha1, - "The magic words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (VERIFY(pub, sha1, + "The magic words are squeamish ossifrage", signature)); /* Try bad signature */ mpz_togglebit(signature, 17); - - if (VERIFY(pub, sha1, - "The magic words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (!VERIFY(pub, sha1, + "The magic words are squeamish ossifrage", signature)); mpz_clear(signature); } @@ -793,25 +799,20 @@ test_rsa_sha256(struct rsa_public_key *pub, fprintf(stderr, "\n"); } - if (mpz_cmp(signature, expected)) - FAIL(); + ASSERT (mpz_cmp(signature, expected) == 0); /* Try bad data */ - if (VERIFY(pub, sha256, - "The magick words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (!VERIFY(pub, sha256, + "The magick words are squeamish ossifrage", signature)); /* Try correct data */ - if (!VERIFY(pub, sha256, - "The magic words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (VERIFY(pub, sha256, + "The magic words are squeamish ossifrage", signature)); /* Try bad signature */ mpz_togglebit(signature, 17); - - if (VERIFY(pub, sha256, - "The magic words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (!VERIFY(pub, sha256, + "The magic words are squeamish ossifrage", signature)); mpz_clear(signature); } @@ -836,25 +837,20 @@ test_rsa_sha512(struct rsa_public_key *pub, fprintf(stderr, "\n"); } - if (mpz_cmp(signature, expected)) - FAIL(); + ASSERT (mpz_cmp(signature, expected) == 0); /* Try bad data */ - if (VERIFY(pub, sha512, - "The magick words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (!VERIFY(pub, sha512, + "The magick words are squeamish ossifrage", signature)); /* Try correct data */ - if (!VERIFY(pub, sha512, - "The magic words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (VERIFY(pub, sha512, + "The magic words are squeamish ossifrage", signature)); /* Try bad signature */ mpz_togglebit(signature, 17); - - if (VERIFY(pub, sha512, - "The magic words are squeamish ossifrage", signature)) - FAIL(); + ASSERT (!VERIFY(pub, sha512, + "The magic words are squeamish ossifrage", signature)); mpz_clear(signature); } @@ -896,14 +892,12 @@ test_rsa_key(struct rsa_public_key *pub, /* Check n = p q */ mpz_mul(tmp, key->p, key->q); - if (mpz_cmp(tmp, pub->n)) - FAIL(); + ASSERT (mpz_cmp(tmp, pub->n)== 0); /* Check c q = 1 mod p */ mpz_mul(tmp, key->c, key->q); mpz_fdiv_r(tmp, tmp, key->p); - if (mpz_cmp_ui(tmp, 1)) - FAIL(); + ASSERT (mpz_cmp_ui(tmp, 1) == 0); /* Check ed = 1 (mod phi) */ mpz_sub_ui(phi, key->p, 1); @@ -913,22 +907,19 @@ test_rsa_key(struct rsa_public_key *pub, mpz_mul(tmp, pub->e, key->d); mpz_fdiv_r(tmp, tmp, phi); - if (mpz_cmp_ui(tmp, 1)) - FAIL(); + ASSERT (mpz_cmp_ui(tmp, 1) == 0); /* Check a e = 1 (mod (p-1) ) */ mpz_sub_ui(phi, key->p, 1); mpz_mul(tmp, pub->e, key->a); mpz_fdiv_r(tmp, tmp, phi); - if (mpz_cmp_ui(tmp, 1)) - FAIL(); + ASSERT (mpz_cmp_ui(tmp, 1) == 0); /* Check b e = 1 (mod (q-1) ) */ mpz_sub_ui(phi, key->q, 1); mpz_mul(tmp, pub->e, key->b); mpz_fdiv_r(tmp, tmp, phi); - if (mpz_cmp_ui(tmp, 1)) - FAIL(); + ASSERT (mpz_cmp_ui(tmp, 1) == 0); mpz_clear(tmp); mpz_clear(phi); } @@ -966,26 +957,24 @@ test_dsa160(const struct dsa_public_key *pub, } if (expected) - if (mpz_cmp (signature.r, expected->r) - || mpz_cmp (signature.s, expected->s)) - FAIL(); + ASSERT (mpz_cmp (signature.r, expected->r) == 0 + && mpz_cmp (signature.s, expected->s) == 0); /* Try bad data */ - if (DSA_VERIFY(pub, sha1, - "The magick words are squeamish ossifrage", &signature)) - FAIL(); + ASSERT (!DSA_VERIFY(pub, sha1, + "The magick words are squeamish ossifrage", + &signature)); /* Try correct data */ - if (!DSA_VERIFY(pub, sha1, - "The magic words are squeamish ossifrage", &signature)) - FAIL(); + ASSERT (DSA_VERIFY(pub, sha1, + "The magic words are squeamish ossifrage", + &signature)); /* Try bad signature */ mpz_togglebit(signature.r, 17); - - if (DSA_VERIFY(pub, sha1, - "The magic words are squeamish ossifrage", &signature)) - FAIL(); + ASSERT (!DSA_VERIFY(pub, sha1, + "The magic words are squeamish ossifrage", + &signature)); dsa_signature_clear(&signature); } @@ -1018,26 +1007,24 @@ test_dsa256(const struct dsa_public_key *pub, } if (expected) - if (mpz_cmp (signature.r, expected->r) - || mpz_cmp (signature.s, expected->s)) - FAIL(); + ASSERT (mpz_cmp (signature.r, expected->r) == 0 + && mpz_cmp (signature.s, expected->s) == 0); /* Try bad data */ - if (DSA_VERIFY(pub, sha256, - "The magick words are squeamish ossifrage", &signature)) - FAIL(); + ASSERT (!DSA_VERIFY(pub, sha256, + "The magick words are squeamish ossifrage", + &signature)); /* Try correct data */ - if (!DSA_VERIFY(pub, sha256, - "The magic words are squeamish ossifrage", &signature)) - FAIL(); + ASSERT (DSA_VERIFY(pub, sha256, + "The magic words are squeamish ossifrage", + &signature)); /* Try bad signature */ mpz_togglebit(signature.r, 17); - - if (DSA_VERIFY(pub, sha256, - "The magic words are squeamish ossifrage", &signature)) - FAIL(); + ASSERT (!DSA_VERIFY(pub, sha256, + "The magic words are squeamish ossifrage", + &signature)); dsa_signature_clear(&signature); } @@ -1069,6 +1056,8 @@ test_dsa_key(struct dsa_public_key *pub, mpz_powm(t, pub->g, key->x, pub->p); ASSERT(0 == mpz_cmp(t, pub->y)); + + mpz_clear(t); }; #endif /* WITH_HOGWEED */ diff --git a/testsuite/testutils.h b/testsuite/testutils.h index d7ced9a8..7519d65b 100644 --- a/testsuite/testutils.h +++ b/testsuite/testutils.h @@ -32,23 +32,34 @@ extern "C" { void * xalloc(size_t size); -/* Decodes a NUL-terminated hex string. */ +struct tstring { + struct tstring *next; + unsigned length; + uint8_t data[1]; +}; + +struct tstring * +tstring_alloc (unsigned length); + +void +tstring_clear(void); + +struct tstring * +tstring_data(unsigned length, const char *data); -unsigned -decode_hex_length(const char *hex); +struct tstring * +tstring_hex(const char *hex); -int -decode_hex(uint8_t *dst, const char *hex); +void +tstring_print_hex(const struct tstring *s); -/* Allocates space */ -const uint8_t * -decode_hex_dup(const char *hex); +/* Decodes a NUL-terminated hex string. */ void print_hex(unsigned length, const uint8_t *data); /* The main program */ -int +void test_main(void); extern int verbose; @@ -81,71 +92,53 @@ struct nettle_mac hmac_##name##_update, \ hmac_##name##_digest, \ } - + +/* Test functions deallocate their inputs when finished.*/ void test_cipher(const struct nettle_cipher *cipher, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext); + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext); void test_cipher_cbc(const struct nettle_cipher *cipher, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext, - const uint8_t *iv); + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext, + const struct tstring *iv); void test_cipher_ctr(const struct nettle_cipher *cipher, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext, - const uint8_t *iv); + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext, + const struct tstring *iv); void test_cipher_stream(const struct nettle_cipher *cipher, - unsigned key_length, - const uint8_t *key, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext); + const struct tstring *key, + const struct tstring *cleartext, + const struct tstring *ciphertext); void test_aead(const struct nettle_aead *aead, - unsigned key_length, - const uint8_t *key, - unsigned auth_length, - const uint8_t *authtext, - unsigned length, - const uint8_t *cleartext, - const uint8_t *ciphertext, - unsigned iv_length, - const uint8_t *iv, - const uint8_t *digest); + const struct tstring *key, + const struct tstring *authtext, + const struct tstring *cleartext, + const struct tstring *ciphertext, + const struct tstring *iv, + const struct tstring *digest); void test_hash(const struct nettle_hash *hash, - unsigned length, - const uint8_t *data, - const uint8_t *digest); + const struct tstring *msg, + const struct tstring *digest); void test_hash_large(const struct nettle_hash *hash, unsigned count, unsigned length, uint8_t c, - const uint8_t *digest); - -void -test_mac(const struct nettle_mac *mac, - unsigned key_length, const uint8_t *key, - unsigned msg_length, const uint8_t *msg, - const uint8_t *digest); + const struct tstring *digest); void test_armor(const struct nettle_armor *armor, @@ -198,28 +191,20 @@ test_dsa_key(struct dsa_public_key *pub, unsigned q_size); #endif /* WITH_HOGWEED */ - -#ifdef __cplusplus -} -#endif - -#define H2(d, s) decode_hex((d), (s)) -#define H(x) decode_hex_dup(x) -#define HL(x) decode_hex_length(x), decode_hex_dup(x) - + /* LDATA needs to handle NUL characters. */ #define LLENGTH(x) (sizeof(x) - 1) -#define LDATA(x) (sizeof(x) - 1), x +#define LDATA(x) LLENGTH(x), x #define LDUP(x) strlen(x), strdup(x) +#define SHEX(x) ((const struct tstring *) tstring_hex(x)) +#define SDATA(x) ((const struct tstring *)tstring_data(LLENGTH(x), x)) +#define H(x) (SHEX(x)->data) + #define MEMEQ(length, a, b) (!memcmp((a), (b), (length))) -#define MEMEQH(length, a, b) \ -((length) == decode_hex_length((b)) \ - && !memcmp((a), decode_hex_dup((b)), (length))) #define FAIL() abort() #define SKIP() exit(77) -#define SUCCESS() return EXIT_SUCCESS #define ASSERT(x) do { \ if (!(x)) \ @@ -229,4 +214,8 @@ test_dsa_key(struct dsa_public_key *pub, } \ } while(0) +#ifdef __cplusplus +} +#endif + #endif /* NETTLE_TESTUTILS_H_INCLUDED */ diff --git a/testsuite/twofish-test.c b/testsuite/twofish-test.c index 65558d37..2bef44cc 100644 --- a/testsuite/twofish-test.c +++ b/testsuite/twofish-test.c @@ -1,28 +1,26 @@ #include "testutils.h" #include "twofish.h" -int +void test_main(void) { /* 128 bit key */ test_cipher(&nettle_twofish128, - HL("0000000000000000 0000000000000000"), - HL("0000000000000000 0000000000000000"), - H("9F589F5CF6122C32 B6BFEC2F2AE8C35A")); + SHEX("0000000000000000 0000000000000000"), + SHEX("0000000000000000 0000000000000000"), + SHEX("9F589F5CF6122C32 B6BFEC2F2AE8C35A")); /* 192 bit key */ test_cipher(&nettle_twofish192, - HL("0123456789ABCDEF FEDCBA9876543210" - "0011223344556677"), - HL("0000000000000000 0000000000000000"), - H("CFD1D2E5A9BE9CDF 501F13B892BD2248")); + SHEX("0123456789ABCDEF FEDCBA9876543210" + "0011223344556677"), + SHEX("0000000000000000 0000000000000000"), + SHEX("CFD1D2E5A9BE9CDF 501F13B892BD2248")); /* 256 bit key */ test_cipher(&nettle_twofish256, - HL("0123456789ABCDEF FEDCBA9876543210" - "0011223344556677 8899AABBCCDDEEFF"), - HL("0000000000000000 0000000000000000"), - H("37527BE0052334B8 9F0CFCCAE87CFA20")); - - SUCCESS(); + SHEX("0123456789ABCDEF FEDCBA9876543210" + "0011223344556677 8899AABBCCDDEEFF"), + SHEX("0000000000000000 0000000000000000"), + SHEX("37527BE0052334B8 9F0CFCCAE87CFA20")); } diff --git a/testsuite/yarrow-test.c b/testsuite/yarrow-test.c index 5f01e762..8112f4a8 100644 --- a/testsuite/yarrow-test.c +++ b/testsuite/yarrow-test.c @@ -45,17 +45,20 @@ open_file(const char *name) const char *srcdir = getenv("srcdir"); if (srcdir && srcdir[0]) { - /* Leaks this name, but that doesn't matter. */ + FILE *f; char *buf = xalloc(strlen(name) + strlen(srcdir) + 10); sprintf(buf, "%s/%s", srcdir, name); - name = buf; + + f = fopen(buf, "r"); + free(buf); + return f; } /* Opens the file in text mode. */ return fopen(name, "r"); } -int +void test_main(void) { FILE *input; @@ -72,16 +75,16 @@ test_main(void) uint8_t seed_file[YARROW256_SEED_FILE_SIZE]; const uint8_t *expected_output - = decode_hex_dup("dd304aacac3dc95e 70d684a642967c89" - "58501f7c8eb88b79 43b2ffccde6f0f79"); + = H("dd304aacac3dc95e 70d684a642967c89" + "58501f7c8eb88b79 43b2ffccde6f0f79"); const uint8_t *expected_input - = decode_hex_dup("e0596cf006025506 65d1195f32a87e4a" - "5c354910dfbd0a31 e2105b262f5ce3d8"); + = H("e0596cf006025506 65d1195f32a87e4a" + "5c354910dfbd0a31 e2105b262f5ce3d8"); const uint8_t *expected_seed_file - = decode_hex_dup("b03518f32b1084dd 983e6a445d47bb6f" - "13bb7b998740d570 503d6aaa62e28901"); + = H("b03518f32b1084dd 983e6a445d47bb6f" + "13bb7b998740d570 503d6aaa62e28901"); unsigned c; unsigned t; @@ -107,7 +110,7 @@ test_main(void) printf("source 0 entropy: %d\n", sources[0].estimate[YARROW_SLOW]); - assert(!yarrow256_is_seeded(&yarrow)); + ASSERT(!yarrow256_is_seeded(&yarrow)); input = open_file("gold-bug.txt"); @@ -115,7 +118,7 @@ test_main(void) { fprintf(stderr, "Couldn't open `gold-bug.txt', errno = %d\n", errno); - return EXIT_FAILURE; + FAIL(); } while (get_event(input, &input_hash, &c, &t)) @@ -155,6 +158,8 @@ test_main(void) } } + fclose(input); + if (verbose) { printf("\n"); @@ -177,11 +182,7 @@ test_main(void) printf("\n"); } - if (memcmp(digest, expected_input, sizeof(digest))) - { - fprintf(stderr, "Failed.\n"); - return EXIT_FAILURE; - } + ASSERT (memcmp(digest, expected_input, sizeof(digest)) == 0); yarrow256_random(&yarrow, sizeof(seed_file), seed_file); if (verbose) @@ -191,11 +192,7 @@ test_main(void) printf("\n"); } - if (memcmp(seed_file, expected_seed_file, sizeof(seed_file))) - { - fprintf(stderr, "Failed.\n"); - return EXIT_FAILURE; - } + ASSERT (memcmp(seed_file, expected_seed_file, sizeof(seed_file)) == 0); if (verbose) { @@ -211,11 +208,5 @@ test_main(void) printf("\n"); } - if (memcmp(digest, expected_output, sizeof(digest))) - { - fprintf(stderr, "Failed.\n"); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; + ASSERT (memcmp(digest, expected_output, sizeof(digest)) == 0); } -- 2.47.2