diff options
author | slontis <shane.lontis@oracle.com> | 2024-07-31 06:56:44 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2024-08-21 15:34:40 +0200 |
commit | 390f00a1e95f241b4a104c323020c7bc90d5e829 (patch) | |
tree | c3236df10f38563b0b15df196e5c8a80a0f21013 /test | |
parent | hashtable.c: Code style fixes (diff) | |
download | openssl-390f00a1e95f241b4a104c323020c7bc90d5e829.tar.xz openssl-390f00a1e95f241b4a104c323020c7bc90d5e829.zip |
Add HMAC FIPS keysize check.
HMAC has been changed to use a FIPS indicator for its key check.
HKDF and Single Step use a salt rather than a key when using HMAC,
so we need a mechanism to bypass this check in HMAC.
A seperate 'internal' query table has been added to the FIPS provider
for MACS. Giving HMAC a seprate dispatch table allows KDF's to ignore
the key check. If a KDF requires the key check then it must do the
check itself. The normal MAC dipatch table is used if the user fetches
HMAC directly.
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/25049)
Diffstat (limited to 'test')
-rw-r--r-- | test/evp_test.c | 6 | ||||
-rw-r--r-- | test/recipes/30-test_evp_data/evpmac_common.txt | 24 |
2 files changed, 29 insertions, 1 deletions
diff --git a/test/evp_test.c b/test/evp_test.c index 4789438846..84e589cc7e 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -1937,8 +1937,12 @@ static int mac_test_run_mac(EVP_TEST *t) t->err = "MAC_CREATE_ERROR"; goto err; } - if (fips_provider_version_gt(libctx, 3, 2, 0)) + if (fips_provider_version_gt(libctx, 3, 2, 0)) { + /* HMAC will put an error on the stack here (digest is not set yet) */ + ERR_set_mark(); size_before_init = EVP_MAC_CTX_get_mac_size(ctx); + ERR_pop_to_mark(); + } if (!EVP_MAC_init(ctx, expected->key, expected->key_len, params)) { t->err = "MAC_INIT_ERROR"; goto err; diff --git a/test/recipes/30-test_evp_data/evpmac_common.txt b/test/recipes/30-test_evp_data/evpmac_common.txt index a7c8426dd7..d2caddbcea 100644 --- a/test/recipes/30-test_evp_data/evpmac_common.txt +++ b/test/recipes/30-test_evp_data/evpmac_common.txt @@ -262,6 +262,30 @@ Input = "Test that SHAKE128 fails" Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f Result = MAC_INIT_ERROR +Title = HMAC FIPS short key test + +# Test HMAC with key < 112 bits is not allowed +Availablein = fips +FIPSversion = >=3.4.0 +MAC = HMAC +Algorithm = SHA256 +Input = "Test Input" +Key = 0001020304 +Result = MAC_INIT_ERROR + +Title = HMAC FIPS short key indicator test + +# Test HMAC with key < 112 bits is unapproved +Availablein = fips +FIPSversion = >=3.4.0 +MAC = HMAC +Algorithm = SHA256 +Unapproved = 1 +Ctrl = key-check:0 +Input = "Test Input" +Key = 0001020304 +Output = db70da6176d87813b059879ccc27bc53e295c6eca74db8bdc4e77d7e951d894b + Title = CMAC tests (from FIPS module) MAC = CMAC |