diff options
author | Richard Levitte <levitte@openssl.org> | 2020-01-15 01:04:37 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-01-17 08:59:41 +0100 |
commit | e4a1d0230016d090ba78bc7092384315f85b0e72 (patch) | |
tree | 518e1155d0185622e42d10918b9b0ca9a2317c3a /test/namemap_internal_test.c | |
parent | 9bb3e5fd87905e3e9f5f7edcc2e22d98360510ab (diff) | |
download | openssl-new-e4a1d0230016d090ba78bc7092384315f85b0e72.tar.gz |
Modify EVP_CIPHER_is_a() and EVP_MD_is_a() to handle legacy methods too
These functions would only handle provided methods, but there are
cases where the caller just passes along a received method without
knowing the underlying method tech, so might pass along a legacy
method. We therefore need to have them handle this case as well so
they don't cause any unnecessary surprises.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10845)
Diffstat (limited to 'test/namemap_internal_test.c')
-rw-r--r-- | test/namemap_internal_test.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/namemap_internal_test.c b/test/namemap_internal_test.c index 263364adbd..1d4a657ac6 100644 --- a/test/namemap_internal_test.c +++ b/test/namemap_internal_test.c @@ -108,6 +108,49 @@ static int test_cipherbyname(void) return 1; } +/* + * Test that EVP_CIPHER_is_a() responds appropriately, even for ciphers that + * are entirely legacy. + */ +static int test_cipher_is_a(void) +{ + EVP_CIPHER *fetched = EVP_CIPHER_fetch(NULL, "AES-256-CCM", NULL); + int rv = 1; + + if (!TEST_ptr_ne(fetched, NULL)) + return 0; + if (!TEST_true(EVP_CIPHER_is_a(fetched, "id-aes256-CCM")) + || !TEST_false(EVP_CIPHER_is_a(fetched, "AES-128-GCM"))) + rv = 0; + if (!TEST_true(EVP_CIPHER_is_a(EVP_aes_256_gcm(), "AES-256-GCM")) + || !TEST_false(EVP_CIPHER_is_a(EVP_aes_256_gcm(), "AES-128-CCM"))) + rv = 0; + + EVP_CIPHER_free(fetched); + return rv; +} + +/* + * Test that EVP_MD_is_a() responds appropriately, even for MDs that are + * entirely legacy. + */ +static int test_digest_is_a(void) +{ + EVP_MD *fetched = EVP_MD_fetch(NULL, "SHA2-512", NULL); + int rv = 1; + + if (!TEST_ptr_ne(fetched, NULL)) + return 0; + if (!TEST_true(EVP_MD_is_a(fetched, "SHA512")) + || !TEST_false(EVP_MD_is_a(fetched, "SHA1"))) + rv = 0; + if (!TEST_true(EVP_MD_is_a(EVP_sha256(), "SHA2-256")) + || !TEST_false(EVP_MD_is_a(EVP_sha256(), "SHA3-256"))) + rv = 0; + + EVP_MD_free(fetched); + return rv; +} int setup_tests(void) { @@ -115,5 +158,7 @@ int setup_tests(void) ADD_TEST(test_namemap_stored); ADD_TEST(test_digestbyname); ADD_TEST(test_cipherbyname); + ADD_TEST(test_digest_is_a); + ADD_TEST(test_cipher_is_a); return 1; } |