From: Richard Levitte Date: Fri, 30 Aug 2019 13:36:20 +0000 (+0200) Subject: More KDF cleanup X-Git-Tag: openssl-3.0.0-alpha1~1466 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ff756eedb3b28964ac8e7a7825198ac1b26dfb98;p=oweals%2Fopenssl.git 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) --- 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