From 0ddf74bf1c47b554c3d2c086ff2acb18bcc81bc6 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Thu, 31 Oct 2019 12:10:01 +0100 Subject: [PATCH] Final cleanup after move to leaner EVP_PKEY methods Now that KEYMGMT method pointers have moved away from the diverse methods that are used with EVP_PKEY_CTX, we no longer need to pass special argument to evp_generic_fetch() and evp_generic_do_all(). Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/10309) --- crypto/evp/digest.c | 7 +++---- crypto/evp/evp_enc.c | 7 +++---- crypto/evp/evp_fetch.c | 36 ++++++++++-------------------------- crypto/evp/evp_local.h | 12 +++--------- crypto/evp/exchange.c | 17 ++++++----------- crypto/evp/kdf_meth.c | 7 +++---- crypto/evp/keymgmt_meth.c | 9 ++++----- crypto/evp/mac_meth.c | 7 +++---- crypto/evp/pmeth_fn.c | 7 +++---- 9 files changed, 38 insertions(+), 71 deletions(-) diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 11c334cc5e..bbe637e3ce 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -746,7 +746,7 @@ static void set_legacy_nid(const char *name, void *vlegacy_nid) static void *evp_md_from_dispatch(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, void *unused) + OSSL_PROVIDER *prov) { EVP_MD *md = NULL; int fncnt = 0; @@ -873,8 +873,7 @@ EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm, { EVP_MD *md = evp_generic_fetch(ctx, OSSL_OP_DIGEST, algorithm, properties, - evp_md_from_dispatch, NULL, evp_md_up_ref, - evp_md_free); + evp_md_from_dispatch, evp_md_up_ref, evp_md_free); return md; } @@ -908,5 +907,5 @@ void EVP_MD_do_all_provided(OPENSSL_CTX *libctx, { evp_generic_do_all(libctx, OSSL_OP_DIGEST, (void (*)(void *, void *))fn, arg, - evp_md_from_dispatch, NULL, evp_md_free); + evp_md_from_dispatch, evp_md_free); } diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 53bd02d3c4..ec02283b5e 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -1360,8 +1360,7 @@ static void set_legacy_nid(const char *name, void *vlegacy_nid) static void *evp_cipher_from_dispatch(const int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *unused) + OSSL_PROVIDER *prov) { EVP_CIPHER *cipher = NULL; int fnciphcnt = 0, fnctxcnt = 0; @@ -1501,7 +1500,7 @@ EVP_CIPHER *EVP_CIPHER_fetch(OPENSSL_CTX *ctx, const char *algorithm, { EVP_CIPHER *cipher = evp_generic_fetch(ctx, OSSL_OP_CIPHER, algorithm, properties, - evp_cipher_from_dispatch, NULL, evp_cipher_up_ref, + evp_cipher_from_dispatch, evp_cipher_up_ref, evp_cipher_free); return cipher; @@ -1536,5 +1535,5 @@ void EVP_CIPHER_do_all_provided(OPENSSL_CTX *libctx, { evp_generic_do_all(libctx, OSSL_OP_CIPHER, (void (*)(void *, void *))fn, arg, - evp_cipher_from_dispatch, NULL, evp_cipher_free); + evp_cipher_from_dispatch, evp_cipher_free); } diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c index f0432be742..260471a88d 100644 --- a/crypto/evp/evp_fetch.c +++ b/crypto/evp/evp_fetch.c @@ -47,8 +47,7 @@ struct evp_method_data_st { const char *names; /* For get_evp_method_from_store() */ const char *propquery; /* For get_evp_method_from_store() */ void *(*method_from_dispatch)(int name_id, const OSSL_DISPATCH *, - OSSL_PROVIDER *, void *); - void *method_data; + OSSL_PROVIDER *); int (*refcnt_up_method)(void *method); void (*destruct_method)(void *method); }; @@ -254,8 +253,7 @@ static void *construct_evp_method(const char *names, const OSSL_DISPATCH *fns, if (name_id == 0) return NULL; - return methdata->method_from_dispatch(name_id, fns, prov, - methdata->method_data); + return methdata->method_from_dispatch(name_id, fns, prov); } static void destruct_evp_method(void *method, void *data) @@ -271,9 +269,7 @@ inner_evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, const char *properties, void *(*new_method)(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *method_data), - void *method_data, + OSSL_PROVIDER *prov), int (*up_ref_method)(void *), void (*free_method)(void *)) { @@ -335,7 +331,6 @@ inner_evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, mcmdata.destruct_method = free_method; mcmdata.refcnt_up_method = up_ref_method; mcmdata.destruct_method = free_method; - mcmdata.method_data = method_data; if ((method = ossl_method_construct(libctx, operation_id, 0 /* !force_cache */, &mcm, &mcmdata)) != NULL) { @@ -361,16 +356,13 @@ void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, const char *name, const char *properties, void *(*new_method)(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *method_data), - void *method_data, + OSSL_PROVIDER *prov), int (*up_ref_method)(void *), void (*free_method)(void *)) { return inner_evp_generic_fetch(libctx, operation_id, 0, name, properties, - new_method, method_data, - up_ref_method, free_method); + new_method, up_ref_method, free_method); } /* @@ -384,16 +376,13 @@ void *evp_generic_fetch_by_number(OPENSSL_CTX *libctx, int operation_id, int name_id, const char *properties, void *(*new_method)(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *method_data), - void *method_data, + OSSL_PROVIDER *prov), int (*up_ref_method)(void *), void (*free_method)(void *)) { return inner_evp_generic_fetch(libctx, operation_id, name_id, NULL, properties, - new_method, method_data, - up_ref_method, free_method); + new_method, up_ref_method, free_method); } int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq) @@ -410,8 +399,7 @@ struct do_all_data_st { void (*user_fn)(void *method, void *arg); void *user_arg; void *(*new_method)(const int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, void *method_data); - void *method_data; + OSSL_PROVIDER *prov); void (*free_method)(void *); }; @@ -425,8 +413,7 @@ static void do_one(OSSL_PROVIDER *provider, const OSSL_ALGORITHM *algo, void *method = NULL; if (name_id != 0) - method = data->new_method(name_id, algo->implementation, provider, - data->method_data); + method = data->new_method(name_id, algo->implementation, provider); if (method != NULL) { data->user_fn(method, data->user_arg); @@ -439,15 +426,12 @@ void evp_generic_do_all(OPENSSL_CTX *libctx, int operation_id, void *user_arg, void *(*new_method)(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *method_data), - void *method_data, + OSSL_PROVIDER *prov), void (*free_method)(void *)) { struct do_all_data_st data; data.new_method = new_method; - data.method_data = method_data; data.free_method = free_method; data.user_fn = user_fn; data.user_arg = user_arg; diff --git a/crypto/evp/evp_local.h b/crypto/evp/evp_local.h index 259805db80..803f7863a3 100644 --- a/crypto/evp/evp_local.h +++ b/crypto/evp/evp_local.h @@ -176,18 +176,14 @@ void *evp_generic_fetch(OPENSSL_CTX *ctx, int operation_id, const char *name, const char *properties, void *(*new_method)(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *method_data), - void *method_data, + OSSL_PROVIDER *prov), int (*up_ref_method)(void *), void (*free_method)(void *)); void *evp_generic_fetch_by_number(OPENSSL_CTX *ctx, int operation_id, int name_id, const char *properties, void *(*new_method)(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *method_data), - void *method_data, + OSSL_PROVIDER *prov), int (*up_ref_method)(void *), void (*free_method)(void *)); void evp_generic_do_all(OPENSSL_CTX *libctx, int operation_id, @@ -195,9 +191,7 @@ void evp_generic_do_all(OPENSSL_CTX *libctx, int operation_id, void *user_arg, void *(*new_method)(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *method_data), - void *method_data, + OSSL_PROVIDER *prov), void (*free_method)(void *)); /* Internal fetchers for method types that are to be combined with others */ diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c index 6e1372e042..aebfbaf3da 100644 --- a/crypto/evp/exchange.c +++ b/crypto/evp/exchange.c @@ -34,8 +34,7 @@ static EVP_KEYEXCH *evp_keyexch_new(OSSL_PROVIDER *prov) static void *evp_keyexch_from_dispatch(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *unused) + OSSL_PROVIDER *prov) { EVP_KEYEXCH *exchange = NULL; int fncnt = 0, paramfncnt = 0; @@ -148,14 +147,10 @@ OSSL_PROVIDER *EVP_KEYEXCH_provider(const EVP_KEYEXCH *exchange) EVP_KEYEXCH *EVP_KEYEXCH_fetch(OPENSSL_CTX *ctx, const char *algorithm, const char *properties) { - EVP_KEYEXCH *keyexch = NULL; - - keyexch = evp_generic_fetch(ctx, OSSL_OP_KEYEXCH, algorithm, properties, - evp_keyexch_from_dispatch, NULL, - (int (*)(void *))EVP_KEYEXCH_up_ref, - (void (*)(void *))EVP_KEYEXCH_free); - - return keyexch; + return evp_generic_fetch(ctx, OSSL_OP_KEYEXCH, algorithm, properties, + evp_keyexch_from_dispatch, + (int (*)(void *))EVP_KEYEXCH_up_ref, + (void (*)(void *))EVP_KEYEXCH_free); } int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) @@ -378,7 +373,7 @@ void EVP_KEYEXCH_do_all_provided(OPENSSL_CTX *libctx, { evp_generic_do_all(libctx, OSSL_OP_KEYEXCH, (void (*)(void *, void *))fn, arg, - evp_keyexch_from_dispatch, NULL, + evp_keyexch_from_dispatch, (void (*)(void *))EVP_KEYEXCH_free); } diff --git a/crypto/evp/kdf_meth.c b/crypto/evp/kdf_meth.c index 576dde6805..219dbdfa07 100644 --- a/crypto/evp/kdf_meth.c +++ b/crypto/evp/kdf_meth.c @@ -54,8 +54,7 @@ static void *evp_kdf_new(void) static void *evp_kdf_from_dispatch(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *method_data) + OSSL_PROVIDER *prov) { EVP_KDF *kdf = NULL; int fnkdfcnt = 0, fnctxcnt = 0; @@ -152,7 +151,7 @@ EVP_KDF *EVP_KDF_fetch(OPENSSL_CTX *libctx, const char *algorithm, const char *properties) { return evp_generic_fetch(libctx, OSSL_OP_KDF, algorithm, properties, - evp_kdf_from_dispatch, NULL, evp_kdf_up_ref, + evp_kdf_from_dispatch, evp_kdf_up_ref, evp_kdf_free); } @@ -193,5 +192,5 @@ void EVP_KDF_do_all_provided(OPENSSL_CTX *libctx, { evp_generic_do_all(libctx, OSSL_OP_KDF, (void (*)(void *, void *))fn, arg, - evp_kdf_from_dispatch, NULL, evp_kdf_free); + evp_kdf_from_dispatch, evp_kdf_free); } diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index 9c8d482b4d..8091bcadb8 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -35,8 +35,7 @@ static void *keymgmt_new(void) static void *keymgmt_from_dispatch(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *unused) + OSSL_PROVIDER *prov) { EVP_KEYMGMT *keymgmt = NULL; @@ -158,7 +157,7 @@ EVP_KEYMGMT *evp_keymgmt_fetch_by_number(OPENSSL_CTX *ctx, int name_id, { return evp_generic_fetch_by_number(ctx, OSSL_OP_KEYMGMT, name_id, properties, - keymgmt_from_dispatch, NULL, + keymgmt_from_dispatch, (int (*)(void *))EVP_KEYMGMT_up_ref, (void (*)(void *))EVP_KEYMGMT_free); } @@ -167,7 +166,7 @@ EVP_KEYMGMT *EVP_KEYMGMT_fetch(OPENSSL_CTX *ctx, const char *algorithm, const char *properties) { return evp_generic_fetch(ctx, OSSL_OP_KEYMGMT, algorithm, properties, - keymgmt_from_dispatch, NULL, + keymgmt_from_dispatch, (int (*)(void *))EVP_KEYMGMT_up_ref, (void (*)(void *))EVP_KEYMGMT_free); } @@ -216,7 +215,7 @@ void EVP_KEYMGMT_do_all_provided(OPENSSL_CTX *libctx, { evp_generic_do_all(libctx, OSSL_OP_KEYMGMT, (void (*)(void *, void *))fn, arg, - keymgmt_from_dispatch, NULL, + keymgmt_from_dispatch, (void (*)(void *))EVP_KEYMGMT_free); } diff --git a/crypto/evp/mac_meth.c b/crypto/evp/mac_meth.c index 2c124aef6a..b1fadb6ceb 100644 --- a/crypto/evp/mac_meth.c +++ b/crypto/evp/mac_meth.c @@ -48,8 +48,7 @@ static void *evp_mac_new(void) static void *evp_mac_from_dispatch(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *unused) + OSSL_PROVIDER *prov) { EVP_MAC *mac = NULL; int fnmaccnt = 0, fnctxcnt = 0; @@ -154,7 +153,7 @@ EVP_MAC *EVP_MAC_fetch(OPENSSL_CTX *libctx, const char *algorithm, const char *properties) { return evp_generic_fetch(libctx, OSSL_OP_MAC, algorithm, properties, - evp_mac_from_dispatch, NULL, evp_mac_up_ref, + evp_mac_from_dispatch, evp_mac_up_ref, evp_mac_free); } @@ -200,5 +199,5 @@ void EVP_MAC_do_all_provided(OPENSSL_CTX *libctx, { evp_generic_do_all(libctx, OSSL_OP_MAC, (void (*)(void *, void *))fn, arg, - evp_mac_from_dispatch, NULL, evp_mac_free); + evp_mac_from_dispatch, evp_mac_free); } diff --git a/crypto/evp/pmeth_fn.c b/crypto/evp/pmeth_fn.c index 4a8ece5fac..d49d80bffe 100644 --- a/crypto/evp/pmeth_fn.c +++ b/crypto/evp/pmeth_fn.c @@ -34,8 +34,7 @@ static EVP_SIGNATURE *evp_signature_new(OSSL_PROVIDER *prov) static void *evp_signature_from_dispatch(int name_id, const OSSL_DISPATCH *fns, - OSSL_PROVIDER *prov, - void *unused) + OSSL_PROVIDER *prov) { EVP_SIGNATURE *signature = NULL; int ctxfncnt = 0, signfncnt = 0, verifyfncnt = 0, verifyrecfncnt = 0; @@ -277,7 +276,7 @@ EVP_SIGNATURE *EVP_SIGNATURE_fetch(OPENSSL_CTX *ctx, const char *algorithm, const char *properties) { return evp_generic_fetch(ctx, OSSL_OP_SIGNATURE, algorithm, properties, - evp_signature_from_dispatch, NULL, + evp_signature_from_dispatch, (int (*)(void *))EVP_SIGNATURE_up_ref, (void (*)(void *))EVP_SIGNATURE_free); } @@ -299,7 +298,7 @@ void EVP_SIGNATURE_do_all_provided(OPENSSL_CTX *libctx, { evp_generic_do_all(libctx, OSSL_OP_SIGNATURE, (void (*)(void *, void *))fn, arg, - evp_signature_from_dispatch, NULL, + evp_signature_from_dispatch, (void (*)(void *))EVP_SIGNATURE_free); } -- 2.25.1