diff options
author | Pauli <pauli@openssl.org> | 2021-05-24 14:16:44 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-05-25 17:23:50 +1000 |
commit | 36b6db08fe3dbb58ba2a45a6170f21b5149dfe26 (patch) | |
tree | d690d037fa6ce1a0149f714a0782d41a4da398a2 | |
parent | edc9ce8ef42308c316452875a17578744ed94556 (diff) |
test: add evp_tests for the MAC size and block size
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15427)
-rw-r--r-- | test/evp_test.c | 44 | ||||
-rw-r--r-- | test/recipes/30-test_evp_data/evpmac_blake.txt | 8 | ||||
-rw-r--r-- | test/recipes/30-test_evp_data/evpmac_common.txt | 28 |
3 files changed, 78 insertions, 2 deletions
diff --git a/test/evp_test.c b/test/evp_test.c index abb0485459..bf4777eb56 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -1033,6 +1033,10 @@ typedef struct mac_data_st { int xof; /* Collection of controls */ STACK_OF(OPENSSL_STRING) *controls; + /* Output size */ + int output_size; + /* Block size */ + int block_size; } MAC_DATA; static int mac_test_init(EVP_TEST *t, const char *alg) @@ -1076,6 +1080,7 @@ static int mac_test_init(EVP_TEST *t, const char *alg) mdat->mac_name = OPENSSL_strdup(alg); mdat->mac = mac; mdat->controls = sk_OPENSSL_STRING_new_null(); + mdat->output_size = mdat->block_size = -1; t->data = mdat; return 1; } @@ -1130,6 +1135,18 @@ static int mac_test_parse(EVP_TEST *t, if (strcmp(keyword, "Ctrl") == 0) return sk_OPENSSL_STRING_push(mdata->controls, OPENSSL_strdup(value)) != 0; + if (strcmp(keyword, "OutputSize") == 0) { + mdata->output_size = atoi(value); + if (mdata->output_size < 0) + return -1; + return 1; + } + if (strcmp(keyword, "BlockSize") == 0) { + mdata->block_size = atoi(value); + if (mdata->block_size < 0) + return -1; + return 1; + } return 0; } @@ -1271,8 +1288,8 @@ static int mac_test_run_mac(EVP_TEST *t) EVP_MAC_CTX *ctx = NULL; unsigned char *got = NULL; size_t got_len; - int i; - OSSL_PARAM params[21]; + int i, block_size = -1, output_size = -1; + OSSL_PARAM params[21], sizes[3], *psizes = sizes; size_t params_n = 0; size_t params_n_allocstart = 0; const OSSL_PARAM *defined_params = @@ -1364,6 +1381,29 @@ static int mac_test_run_mac(EVP_TEST *t) t->err = "MAC_INIT_ERROR"; goto err; } + if (expected->output_size >= 0) + *psizes++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_SIZE, + &output_size); + if (expected->block_size >= 0) + *psizes++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_BLOCK_SIZE, + &block_size); + if (psizes != sizes) { + *psizes = OSSL_PARAM_construct_end(); + if (!TEST_true(EVP_MAC_CTX_get_params(ctx, sizes))) { + t->err = "INTERNAL_ERROR"; + goto err; + } + if (expected->output_size >= 0 + && !TEST_int_eq(output_size, expected->output_size)) { + t->err = "TEST_FAILURE"; + goto err; + } + if (expected->block_size >= 0 + && !TEST_int_eq(block_size, expected->block_size)) { + t->err = "TEST_FAILURE"; + goto err; + } + } if (!EVP_MAC_update(ctx, expected->input, expected->input_len)) { t->err = "MAC_UPDATE_ERROR"; goto err; diff --git a/test/recipes/30-test_evp_data/evpmac_blake.txt b/test/recipes/30-test_evp_data/evpmac_blake.txt index cd9a75e82e..13cb22fff3 100644 --- a/test/recipes/30-test_evp_data/evpmac_blake.txt +++ b/test/recipes/30-test_evp_data/evpmac_blake.txt @@ -17,16 +17,20 @@ MAC = BLAKE2BMAC Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f Input = Output = 10ebb67700b1868efb4417987acf4690ae9d972fb7a590c2f02871799aaa4786b5e996e8f0f4eb981fc214b005f42d2ff4233499391653df7aefcbc13fc51568 +OutputSize = 64 +BlockSize = 128 MAC = BLAKE2BMAC Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f Input = 00 Output = 961f6dd1e4dd30f63901690c512e78e4b45e4742ed197c3c5e45c549fd25f2e4187b0bc9fe30492b16b0d0bc4ef9b0f34c7003fac09a5ef1532e69430234cebd +BlockSize = 128 MAC = BLAKE2BMAC Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f Input = 0001 Output = da2cfbe2d8409a0f38026113884f84b50156371ae304c4430173d08a99d9fb1b983164a3770706d537f49e0c916d9f32b95cc37a95b99d857436f0232c88a965 +OutputSize = 64 MAC = BLAKE2BMAC Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f @@ -77,16 +81,20 @@ MAC = BLAKE2SMAC Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f Input = Output = 48a8997da407876b3d79c0d92325ad3b89cbb754d86ab71aee047ad345fd2c49 +OutputSize = 32 +BlockSize = 64 MAC = BLAKE2SMAC Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f Input = 00 Output = 40d15fee7c328830166ac3f918650f807e7e01e177258cdc0a39b11f598066f1 +BlockSize = 64 MAC = BLAKE2SMAC Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f Input = 0001 Output = 6bb71300644cd3991b26ccd4d274acd1adeab8b1d7914546c1198bbe9fc9d803 +OutputSize = 32 MAC = BLAKE2SMAC Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f diff --git a/test/recipes/30-test_evp_data/evpmac_common.txt b/test/recipes/30-test_evp_data/evpmac_common.txt index 0229659807..e2fbfac414 100644 --- a/test/recipes/30-test_evp_data/evpmac_common.txt +++ b/test/recipes/30-test_evp_data/evpmac_common.txt @@ -20,6 +20,8 @@ Algorithm = MD5 Key = 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b Input = "Hi There" Output = 9294727a3638bb1c13f48ef8158bfc9d +OutputSize = 16 +BlockSize = 64 Availablein = default MAC = HMAC @@ -27,6 +29,7 @@ Algorithm = MD5 Key = "Jefe" Input = "what do ya want for nothing?" Output = 750c783e6ab0b503eaa86e310a5db738 +OutputSize = 16 Availablein = default MAC = HMAC @@ -34,6 +37,7 @@ Algorithm = MD5 Key = AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Input = DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD Output = 56be34521d144c88dbb8c733f0e8b3f6 +BlockSize = 64 Title = SHA1 @@ -44,18 +48,22 @@ Algorithm = SHA1 Input = "Sample message for keylen=blocklen" Key = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F Output = 5FD596EE78D5553C8FF4E72D266DFD192366DA29 +OutputSize = 20 +BlockSize = 64 MAC = HMAC Algorithm = SHA1 Input = "Sample message for keylen<blocklen" Key = 000102030405060708090A0B0C0D0E0F10111213 Output = 4C99FF0CB1B31BD33F8431DBAF4D17FCD356A807 +OutputSize = 20 MAC = HMAC Algorithm = SHA1 Input = "Sample message for keylen=blocklen" Key = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F60616263 Output = 2D51B2F7750E410584662E38F133435F4C4FD42A +BlockSize = 64 Title = SHA2 @@ -64,6 +72,8 @@ Algorithm = SHA224 Input = "Sample message for keylen=blocklen" Key = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F Output = C7405E3AE058E8CD30B08B4140248581ED174CB34E1224BCC1EFC81B +OutputSize = 28 +BlockSize = 64 MAC = HMAC Algorithm = SHA224 @@ -82,6 +92,8 @@ Algorithm = SHA256 Input = "Sample message for keylen=blocklen" Key = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F Output = 8BB9A1DB9806F20DF7F77B82138C7914D174D59E13DC4D0169C9057B133E1D62 +OutputSize = 32 +BlockSize = 64 MAC = HMAC Algorithm = SHA256 @@ -100,6 +112,8 @@ Algorithm = SHA384 Input = "Sample message for keylen=blocklen" Key = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F Output = 63C5DAA5E651847CA897C95814AB830BEDEDC7D25E83EEF9195CD45857A37F448947858F5AF50CC2B1B730DDF29671A9 +OutputSize = 48 +BlockSize = 128 MAC = HMAC Algorithm = SHA384 @@ -118,6 +132,8 @@ Algorithm = SHA512 Input = "Sample message for keylen=blocklen" Key = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F Output = FC25E240658CA785B7A811A8D3F7B4CA48CFA26A8A366BF2CD1F836B05FCB024BD36853081811D6CEA4216EBAD79DA1CFCB95EA4586B8A0CE356596A55FB1347 +OutputSize = 64 +BlockSize = 128 MAC = HMAC Algorithm = SHA512 @@ -140,6 +156,8 @@ Algorithm = SHA3-224 Input = "Sample message for keylen<blocklen" Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b Output = 332cfd59347fdb8e576e77260be4aba2d6dc53117b3bfb52c6d18c04 +OutputSize = 28 +BlockSize = 144 MAC = HMAC Algorithm = SHA3-224 @@ -158,6 +176,8 @@ Algorithm = SHA3-256 Input = "Sample message for keylen<blocklen" Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f Output = 4fe8e202c4f058e8dddc23d8c34e467343e23555e24fc2f025d598f558f67205 +OutputSize = 32 +BlockSize = 136 MAC = HMAC Algorithm = SHA3-256 @@ -176,6 +196,8 @@ Algorithm = SHA3-384 Input = "Sample message for keylen<blocklen" Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f Output = d588a3c51f3f2d906e8298c1199aa8ff6296218127f6b38a90b6afe2c5617725bc99987f79b22a557b6520db710b7f42 +OutputSize = 48 +BlockSize = 104 MAC = HMAC Algorithm = SHA3-384 @@ -194,6 +216,8 @@ Algorithm = SHA3-512 Input = "Sample message for keylen<blocklen" Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f Output = 4efd629d6c71bf86162658f29943b1c308ce27cdfa6db0d9c3ce81763f9cbce5f7ebe9868031db1a8f8eb7b6b95e5c5e3f657a8996c86a2f6527e307f0213196 +OutputSize = 64 +BlockSize = 72 MAC = HMAC Algorithm = SHA3-512 @@ -311,6 +335,8 @@ Input = 00010203 Custom = "" Output = E5780B0D3EA6F7D3A429C5706AA43A00FADBD7D49628839E3187243F456EE14E Ctrl = xof:0 +OutputSize = 32 +BlockSize = 168 MAC = KMAC128 Key = 404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F @@ -330,6 +356,8 @@ Key = 404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F Input = 00010203 Custom = "My Tagged Application" Output = 20C570C31346F703C9AC36C61C03CB64C3970D0CFC787E9B79599D273A68D2F7F69D4CC3DE9D104A351689F27CF6F5951F0103F33F4F24871024D9C27773A8DD +OutputSize = 64 +BlockSize = 136 MAC = KMAC256 Key = 404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F |