X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=test%2Fnamemap_internal_test.c;h=9c94440f9185e46110fc317a25c8ef377137c832;hb=437e36aed578f0a3213cc87b34abecb36bf1bde5;hp=16bc571265d8925fdb2070b9b8cae2825398e42d;hpb=eee5f32f37764ffb94e7989536e7022c9a800986;p=oweals%2Fopenssl.git diff --git a/test/namemap_internal_test.c b/test/namemap_internal_test.c index 16bc571265..9c94440f91 100644 --- a/test/namemap_internal_test.c +++ b/test/namemap_internal_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -18,15 +18,15 @@ static int test_namemap(OSSL_NAMEMAP *nm) { - int num1 = ossl_namemap_add(nm, 0, NAME1); - int num2 = ossl_namemap_add(nm, 0, NAME2); - int num3 = ossl_namemap_add(nm, num1, ALIAS1); - int num4 = ossl_namemap_add(nm, 0, ALIAS1_UC); + int num1 = ossl_namemap_add_name(nm, 0, NAME1); + int num2 = ossl_namemap_add_name(nm, 0, NAME2); + int num3 = ossl_namemap_add_name(nm, num1, ALIAS1); + int num4 = ossl_namemap_add_name(nm, 0, ALIAS1_UC); int check1 = ossl_namemap_name2num(nm, NAME1); int check2 = ossl_namemap_name2num(nm, NAME2); int check3 = ossl_namemap_name2num(nm, ALIAS1); int check4 = ossl_namemap_name2num(nm, ALIAS1_UC); - int false1 = ossl_namemap_name2num(nm, "foo"); + int false1 = ossl_namemap_name2num(nm, "cookie"); return TEST_int_ne(num1, 0) && TEST_int_ne(num2, 0) @@ -66,10 +66,10 @@ static int test_digestbyname(void) OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL); const EVP_MD *sha256, *foo; - id = ossl_namemap_add(nm, 0, "SHA256"); + id = ossl_namemap_add_name(nm, 0, "SHA256"); if (!TEST_int_ne(id, 0)) return 0; - if (!TEST_int_eq(ossl_namemap_add(nm, id, "foo"), id)) + if (!TEST_int_eq(ossl_namemap_add_name(nm, id, "foo"), id)) return 0; sha256 = EVP_get_digestbyname("SHA256"); @@ -92,10 +92,10 @@ static int test_cipherbyname(void) OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL); const EVP_CIPHER *aes128, *bar; - id = ossl_namemap_add(nm, 0, "AES-128-CBC"); + id = ossl_namemap_add_name(nm, 0, "AES-128-CBC"); if (!TEST_int_ne(id, 0)) return 0; - if (!TEST_int_eq(ossl_namemap_add(nm, id, "bar"), id)) + if (!TEST_int_eq(ossl_namemap_add_name(nm, id, "bar"), id)) return 0; aes128 = EVP_get_cipherbyname("AES-128-CBC"); @@ -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; }