summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2019-11-01 16:09:21 +0000
committerMatt Caswell <matt@openssl.org>2019-11-06 10:11:31 +0000
commiteee5f32f37764ffb94e7989536e7022c9a800986 (patch)
treef7af00dbb7b3054faef1c5e921bd297ce15105ce
parent7606bed9047935d0e3c0b5ede9d4ce92a136b5e2 (diff)
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 <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/10324)
-rw-r--r--test/namemap_internal_test.c56
1 files changed, 56 insertions, 0 deletions
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 <openssl/evp.h>
#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;
}