summaryrefslogtreecommitdiffstats
path: root/test/evp_kdf_test.c
diff options
context:
space:
mode:
authorPauli <ppzgs1@gmail.com>2021-02-08 03:01:20 +0100
committerPauli <ppzgs1@gmail.com>2021-02-12 03:28:55 +0100
commitb5873b31761e68015f4943ab137fc5e63323342e (patch)
tree9adffe7cf91c95852e6cb28d82be9bf57ed70c88 /test/evp_kdf_test.c
parentEVP: fix reference counting for EVP_CIPHER. (diff)
downloadopenssl-b5873b31761e68015f4943ab137fc5e63323342e.tar.xz
openssl-b5873b31761e68015f4943ab137fc5e63323342e.zip
test: fix no-cache problem with the quality comparison for KDFs.
In a caching world, it's fine to compare the pointers directly. In a non-caching world, the names and providers need to be compared. Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14126)
Diffstat (limited to 'test/evp_kdf_test.c')
-rw-r--r--test/evp_kdf_test.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/test/evp_kdf_test.c b/test/evp_kdf_test.c
index b0e8d2b5fb..37d4653577 100644
--- a/test/evp_kdf_test.c
+++ b/test/evp_kdf_test.c
@@ -1260,6 +1260,21 @@ static int test_kdf_sshkdf(void)
return ret;
}
+static int test_kdfs_same( EVP_KDF *kdf1, EVP_KDF *kdf2)
+{
+ /* Fast path in case the two are the same algorithm pointer */
+ if (kdf1 == kdf2)
+ return 1;
+ /*
+ * Compare their names and providers instead.
+ * This is necessary in a non-caching build (or a cache flush during fetch)
+ * because without the algorithm in the cache, fetching it a second time
+ * will result in a different pointer.
+ */
+ return TEST_ptr_eq(EVP_KDF_provider(kdf1), EVP_KDF_provider(kdf2))
+ && TEST_str_eq(EVP_KDF_name(kdf1), EVP_KDF_name(kdf2));
+}
+
static int test_kdf_get_kdf(void)
{
EVP_KDF *kdf1 = NULL, *kdf2 = NULL;
@@ -1270,7 +1285,7 @@ static int test_kdf_get_kdf(void)
|| !TEST_ptr(kdf1 = EVP_KDF_fetch(NULL, OSSL_KDF_NAME_PBKDF2, NULL))
|| !TEST_ptr(kdf2 = EVP_KDF_fetch(NULL, OBJ_nid2sn(OBJ_obj2nid(obj)),
NULL))
- || !TEST_ptr_eq(kdf1, kdf2))
+ || !test_kdfs_same(kdf1, kdf2))
ok = 0;
EVP_KDF_free(kdf1);
kdf1 = NULL;
@@ -1279,14 +1294,14 @@ static int test_kdf_get_kdf(void)
if (!TEST_ptr(kdf1 = EVP_KDF_fetch(NULL, SN_tls1_prf, NULL))
|| !TEST_ptr(kdf2 = EVP_KDF_fetch(NULL, LN_tls1_prf, NULL))
- || !TEST_ptr_eq(kdf1, kdf2))
+ || !test_kdfs_same(kdf1, kdf2))
ok = 0;
/* kdf1 is re-used below, so don't free it here */
EVP_KDF_free(kdf2);
kdf2 = NULL;
if (!TEST_ptr(kdf2 = EVP_KDF_fetch(NULL, OBJ_nid2sn(NID_tls1_prf), NULL))
- || !TEST_ptr_eq(kdf1, kdf2))
+ || !test_kdfs_same(kdf1, kdf2))
ok = 0;
EVP_KDF_free(kdf1);
kdf1 = NULL;