From eee5f32f37764ffb94e7989536e7022c9a800986 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Fri, 1 Nov 2019 16:09:21 +0000 Subject: [PATCH] Test EVP_get_[digest|cipher]byname() use the namemap Following on from the previous commit, we test that if an algorithm has a provider supplied alias in the namemap then EVP_get_digestbyname() and EVP_get_cipherbyname() can still find it. Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/10324) --- test/namemap_internal_test.c | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/namemap_internal_test.c b/test/namemap_internal_test.c index 1aee01ed0b..16bc571265 100644 --- a/test/namemap_internal_test.c +++ b/test/namemap_internal_test.c @@ -7,6 +7,7 @@ * https://www.openssl.org/source/license.html */ +#include #include "internal/namemap.h" #include "testutil.h" @@ -55,9 +56,64 @@ static int test_namemap_stored(void) && test_namemap(nm); } +/* + * Test that EVP_get_digestbyname() will use the namemap when it can't find + * entries in the legacy method database. + */ +static int test_digestbyname(void) +{ + int id; + OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL); + const EVP_MD *sha256, *foo; + + id = ossl_namemap_add(nm, 0, "SHA256"); + if (!TEST_int_ne(id, 0)) + return 0; + if (!TEST_int_eq(ossl_namemap_add(nm, id, "foo"), id)) + return 0; + + sha256 = EVP_get_digestbyname("SHA256"); + if (!TEST_ptr(sha256)) + return 0; + foo = EVP_get_digestbyname("foo"); + if (!TEST_ptr_eq(sha256, foo)) + return 0; + + return 1; +} + +/* + * Test that EVP_get_cipherbyname() will use the namemap when it can't find + * entries in the legacy method database. + */ +static int test_cipherbyname(void) +{ + int id; + OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL); + const EVP_CIPHER *aes128, *bar; + + id = ossl_namemap_add(nm, 0, "AES-128-CBC"); + if (!TEST_int_ne(id, 0)) + return 0; + if (!TEST_int_eq(ossl_namemap_add(nm, id, "bar"), id)) + return 0; + + aes128 = EVP_get_cipherbyname("AES-128-CBC"); + if (!TEST_ptr(aes128)) + return 0; + bar = EVP_get_cipherbyname("bar"); + if (!TEST_ptr_eq(aes128, bar)) + return 0; + + return 1; +} + + int setup_tests(void) { ADD_TEST(test_namemap_independent); ADD_TEST(test_namemap_stored); + ADD_TEST(test_digestbyname); + ADD_TEST(test_cipherbyname); return 1; } -- 2.39.2