]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test: fix no-cache problem with the quality comparison for KDFs.
authorPauli <ppzgs1@gmail.com>
Mon, 8 Feb 2021 02:01:20 +0000 (12:01 +1000)
committerPauli <ppzgs1@gmail.com>
Fri, 12 Feb 2021 02:28:55 +0000 (12:28 +1000)
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)

test/evp_kdf_test.c

index b0e8d2b5fbdeac7e5bb25fc71f438f42ea2b2663..37d4653577e5f862ba9268814f8047ef97beb558 100644 (file)
@@ -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;