More KDF cleanup
authorRichard Levitte <levitte@openssl.org>
Fri, 30 Aug 2019 13:36:20 +0000 (15:36 +0200)
committerPauli <paul.dale@oracle.com>
Fri, 6 Sep 2019 09:27:57 +0000 (19:27 +1000)
The EVP_KDF_ definitions are no longer needed, and neither is
EVP_get_kdfbyname()

test/evp_kdf_test.c tried to use a EVP_get_kdfbyname() that was rewritten
to use EVP_KDF_fetch() without ever freeing the resulting KDF method.
It's better to refactor the test to use EVP_KDF_fetch directly.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9662)

include/openssl/kdf.h
test/evp_kdf_test.c

index d76b39e..a9ea768 100644 (file)
 extern "C" {
 # endif
 
-# define EVP_KDF_PBKDF2     NID_id_pbkdf2
-# define EVP_KDF_SCRYPT     NID_id_scrypt
-# define EVP_KDF_TLS1_PRF   NID_tls1_prf
-# define EVP_KDF_HKDF       NID_hkdf
-# define EVP_KDF_SSHKDF     NID_sshkdf
-# define EVP_KDF_SS         NID_sskdf
-# define EVP_KDF_X963       NID_x963kdf
-# define EVP_KDF_X942       NID_x942kdf
-
 int EVP_KDF_up_ref(EVP_KDF *kdf);
 void EVP_KDF_free(EVP_KDF *kdf);
 EVP_KDF *EVP_KDF_fetch(OPENSSL_CTX *libctx, const char *algorithm,
                        const char *properties);
-#define EVP_get_kdfbyname(name) EVP_KDF_fetch(NULL, (name), NULL)
 
 EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf);
 void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
index 852cc46..abc4dcc 100644 (file)
@@ -446,19 +446,38 @@ static int test_kdf_sshkdf(void)
 
 static int test_kdf_get_kdf(void)
 {
-    const EVP_KDF *kdf1, *kdf2;
+    EVP_KDF *kdf1 = NULL, *kdf2 = NULL;
     ASN1_OBJECT *obj;
-
-    return
-        TEST_ptr(obj = OBJ_nid2obj(NID_id_pbkdf2))
-        && TEST_ptr(kdf1 = EVP_get_kdfbyname(LN_id_pbkdf2))
-        && TEST_ptr(kdf2 = EVP_get_kdfbyname(OBJ_nid2sn(OBJ_obj2nid(obj))))
-        && TEST_ptr_eq(kdf1, kdf2)
-        && TEST_ptr(kdf1 = EVP_get_kdfbyname(SN_tls1_prf))
-        && TEST_ptr(kdf2 = EVP_get_kdfbyname(LN_tls1_prf))
-        && TEST_ptr_eq(kdf1, kdf2)
-        && TEST_ptr(kdf2 = EVP_get_kdfbyname(OBJ_nid2sn(NID_tls1_prf)))
-        && TEST_ptr_eq(kdf1, kdf2);
+    int ok = 1;
+
+    if (!TEST_ptr(obj = OBJ_nid2obj(NID_id_pbkdf2))
+        || !TEST_ptr(kdf1 = EVP_KDF_fetch(NULL, LN_id_pbkdf2, NULL))
+        || !TEST_ptr(kdf2 = EVP_KDF_fetch(NULL, OBJ_nid2sn(OBJ_obj2nid(obj)),
+                                          NULL))
+        || !TEST_ptr_eq(kdf1, kdf2))
+        ok = 0;
+    EVP_KDF_free(kdf1);
+    kdf1 = NULL;
+    EVP_KDF_free(kdf2);
+    kdf2 = NULL;
+
+    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))
+        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))
+        ok = 0;
+    EVP_KDF_free(kdf1);
+    kdf1 = NULL;
+    EVP_KDF_free(kdf2);
+    kdf2 = NULL;
+
+    return ok;
 }
 
 #ifndef OPENSSL_NO_CMS