From ff756eedb3b28964ac8e7a7825198ac1b26dfb98 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Fri, 30 Aug 2019 15:36:20 +0200 Subject: [PATCH] More KDF cleanup 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 (Merged from https://github.com/openssl/openssl/pull/9662) --- include/openssl/kdf.h | 10 ---------- test/evp_kdf_test.c | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/include/openssl/kdf.h b/include/openssl/kdf.h index d76b39e65e..a9ea768d1d 100644 --- a/include/openssl/kdf.h +++ b/include/openssl/kdf.h @@ -19,20 +19,10 @@ 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); diff --git a/test/evp_kdf_test.c b/test/evp_kdf_test.c index 852cc46d41..abc4dccd46 100644 --- a/test/evp_kdf_test.c +++ b/test/evp_kdf_test.c @@ -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 -- 2.25.1