From f651c727f85813085355bb207cf913288108ed79 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 23 Sep 2019 10:56:13 +0200 Subject: [PATCH] EVP: add name traversal functions to all fetchable types The following new functions all do the same thing; they traverse the set of names assigned to implementations of each algorithm type: EVP_MD_names_do_all(), EVP_CIPHER_names_do_all(), EVP_MAC_names_do_all(), EVP_KEYMGMT_names_do_all(), EVP_KEYEXCH_names_do_all(), EVP_KDF_names_do_all(), EVP_SIGNATURE_names_do_all() We add a warning to the documentation of EVP_CIPHER_name() and EVP_MD_name(), as they aren't suitable to use with multiple-name implementation. We also remove EVP_MAC_name() and evp_KDF_name(), as they serve no useful purpose. Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/9979) --- crypto/evp/digest.c | 2 +- crypto/evp/evp_enc.c | 2 +- crypto/evp/evp_fetch.c | 6 +++--- crypto/evp/evp_lib.c | 16 ++++++++++++++++ crypto/evp/evp_local.h | 6 +++--- crypto/evp/exchange.c | 8 ++++++++ crypto/evp/kdf_lib.c | 13 ++++++++----- crypto/evp/keymgmt_meth.c | 8 ++++++++ crypto/evp/mac_lib.c | 8 ++++++++ crypto/evp/mac_meth.c | 5 ----- crypto/evp/pmeth_fn.c | 9 +++++++++ doc/man3/EVP_DigestInit.pod | 13 +++++++++++-- doc/man3/EVP_EncryptInit.pod | 11 ++++++++++- doc/man3/EVP_KDF.pod | 13 +++++++------ doc/man3/EVP_KEYEXCH_free.pod | 8 +++++++- doc/man3/EVP_KEYMGMT.pod | 7 +++++++ doc/man3/EVP_MAC.pod | 14 +++++++------- doc/man3/EVP_SIGNATURE_free.pod | 9 ++++++++- include/openssl/evp.h | 19 ++++++++++++++++++- include/openssl/kdf.h | 4 +++- test/evp_test.c | 7 +++++-- util/libcrypto.num | 11 +++++++++-- 22 files changed, 157 insertions(+), 42 deletions(-) diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index a8e8326237..11c334cc5e 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -760,7 +760,7 @@ static void *evp_md_from_dispatch(int name_id, #ifndef FIPS_MODE /* TODO(3.x) get rid of the need for legacy NIDs */ md->type = NID_undef; - evp_doall_names(prov, name_id, set_legacy_nid, &md->type); + evp_names_do_all(prov, name_id, set_legacy_nid, &md->type); if (md->type == -1) { ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); EVP_MD_free(md); diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 4406b7f032..efcb7e509a 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -1365,7 +1365,7 @@ static void *evp_cipher_from_dispatch(const int name_id, #ifndef FIPS_MODE /* TODO(3.x) get rid of the need for legacy NIDs */ cipher->nid = NID_undef; - evp_doall_names(prov, name_id, set_legacy_nid, &cipher->nid); + evp_names_do_all(prov, name_id, set_legacy_nid, &cipher->nid); if (cipher->nid == -1) { ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR); EVP_CIPHER_free(cipher); diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c index 2404dfca30..e2039df3ef 100644 --- a/crypto/evp/evp_fetch.c +++ b/crypto/evp/evp_fetch.c @@ -468,9 +468,9 @@ int evp_is_a(OSSL_PROVIDER *prov, int number, const char *name) return ossl_namemap_name2num(namemap, name) == number; } -void evp_doall_names(OSSL_PROVIDER *prov, int number, - void (*fn)(const char *name, void *data), - void *data) +void evp_names_do_all(OSSL_PROVIDER *prov, int number, + void (*fn)(const char *name, void *data), + void *data) { OPENSSL_CTX *libctx = ossl_provider_library_context(prov); OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx); diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index f87793d3ed..f5e2505e0a 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -556,6 +556,14 @@ const char *EVP_CIPHER_name(const EVP_CIPHER *cipher) #endif } +void EVP_CIPHER_names_do_all(const EVP_CIPHER *cipher, + void (*fn)(const char *name, void *data), + void *data) +{ + if (cipher->prov != NULL) + evp_names_do_all(cipher->prov, cipher->name_id, fn, data); +} + const OSSL_PROVIDER *EVP_CIPHER_provider(const EVP_CIPHER *cipher) { return cipher->prov; @@ -589,6 +597,14 @@ const char *EVP_MD_name(const EVP_MD *md) #endif } +void EVP_MD_names_do_all(const EVP_MD *md, + void (*fn)(const char *name, void *data), + void *data) +{ + if (md->prov != NULL) + evp_names_do_all(md->prov, md->name_id, fn, data); +} + const OSSL_PROVIDER *EVP_MD_provider(const EVP_MD *md) { return md->prov; diff --git a/crypto/evp/evp_local.h b/crypto/evp/evp_local.h index b14d27c8ba..9b208190fb 100644 --- a/crypto/evp/evp_local.h +++ b/crypto/evp/evp_local.h @@ -261,6 +261,6 @@ void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX *ctx); /* OSSL_PROVIDER * is only used to get the library context */ const char *evp_first_name(OSSL_PROVIDER *prov, int name_id); int evp_is_a(OSSL_PROVIDER *prov, int number, const char *name); -void evp_doall_names(OSSL_PROVIDER *prov, int number, - void (*fn)(const char *name, void *data), - void *data); +void evp_names_do_all(OSSL_PROVIDER *prov, int number, + void (*fn)(const char *name, void *data), + void *data); diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c index 437d6a5cd6..e9d7c6d1fb 100644 --- a/crypto/evp/exchange.c +++ b/crypto/evp/exchange.c @@ -405,3 +405,11 @@ void EVP_KEYEXCH_do_all_provided(OPENSSL_CTX *libctx, evp_keyexch_from_dispatch, &keymgmt_data, (void (*)(void *))EVP_KEYEXCH_free); } + +void EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch, + void (*fn)(const char *name, void *data), + void *data) +{ + if (keyexch->prov != NULL) + evp_names_do_all(keyexch->prov, keyexch->name_id, fn, data); +} diff --git a/crypto/evp/kdf_lib.c b/crypto/evp/kdf_lib.c index b85f0e0eb8..90c43e984a 100644 --- a/crypto/evp/kdf_lib.c +++ b/crypto/evp/kdf_lib.c @@ -83,11 +83,6 @@ EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src) return dst; } -const char *EVP_KDF_name(const EVP_KDF *kdf) -{ - return evp_first_name(kdf->prov, kdf->name_id); -} - int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name) { return evp_is_a(kdf->prov, kdf->name_id, name); @@ -164,3 +159,11 @@ int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]) return ctx->meth->set_ctx_params(ctx->data, params); return 1; } + +void EVP_KDF_names_do_all(const EVP_KDF *kdf, + void (*fn)(const char *name, void *data), + void *data) +{ + if (kdf->prov != NULL) + evp_names_do_all(kdf->prov, kdf->name_id, fn, data); +} diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index 990f899159..6a1c15ae24 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -214,3 +214,11 @@ void EVP_KEYMGMT_do_all_provided(OPENSSL_CTX *libctx, keymgmt_from_dispatch, NULL, (void (*)(void *))EVP_KEYMGMT_free); } + +void EVP_KEYMGMT_names_do_all(const EVP_KEYMGMT *keymgmt, + void (*fn)(const char *name, void *data), + void *data) +{ + if (keymgmt->prov != NULL) + evp_names_do_all(keymgmt->prov, keymgmt->name_id, fn, data); +} diff --git a/crypto/evp/mac_lib.c b/crypto/evp/mac_lib.c index b6df6a594b..8581853802 100644 --- a/crypto/evp/mac_lib.c +++ b/crypto/evp/mac_lib.c @@ -162,3 +162,11 @@ int EVP_MAC_is_a(const EVP_MAC *mac, const char *name) { return evp_is_a(mac->prov, mac->name_id, name); } + +void EVP_MAC_names_do_all(const EVP_MAC *mac, + void (*fn)(const char *name, void *data), + void *data) +{ + if (mac->prov != NULL) + evp_names_do_all(mac->prov, mac->name_id, fn, data); +} diff --git a/crypto/evp/mac_meth.c b/crypto/evp/mac_meth.c index 86f5434654..2c124aef6a 100644 --- a/crypto/evp/mac_meth.c +++ b/crypto/evp/mac_meth.c @@ -168,11 +168,6 @@ void EVP_MAC_free(EVP_MAC *mac) evp_mac_free(mac); } -const char *EVP_MAC_name(const EVP_MAC *mac) -{ - return evp_first_name(mac->prov, mac->name_id); -} - const OSSL_PROVIDER *EVP_MAC_provider(const EVP_MAC *mac) { return mac->prov; diff --git a/crypto/evp/pmeth_fn.c b/crypto/evp/pmeth_fn.c index 2b4bca5727..685b6886c0 100644 --- a/crypto/evp/pmeth_fn.c +++ b/crypto/evp/pmeth_fn.c @@ -332,6 +332,15 @@ void EVP_SIGNATURE_do_all_provided(OPENSSL_CTX *libctx, (void (*)(void *))EVP_SIGNATURE_free); } + +void EVP_SIGNATURE_names_do_all(const EVP_SIGNATURE *signature, + void (*fn)(const char *name, void *data), + void *data) +{ + if (signature->prov != NULL) + evp_names_do_all(signature->prov, signature->name_id, fn, data); +} + static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature, int operation) { diff --git a/doc/man3/EVP_DigestInit.pod b/doc/man3/EVP_DigestInit.pod index 6a9100b583..c00a07671c 100644 --- a/doc/man3/EVP_DigestInit.pod +++ b/doc/man3/EVP_DigestInit.pod @@ -12,7 +12,7 @@ EVP_MD_CTX_settable_params, EVP_MD_CTX_gettable_params, EVP_MD_CTX_set_flags, EVP_MD_CTX_clear_flags, EVP_MD_CTX_test_flags, EVP_Digest, EVP_DigestInit_ex, EVP_DigestInit, EVP_DigestUpdate, EVP_DigestFinal_ex, EVP_DigestFinalXOF, EVP_DigestFinal, -EVP_MD_is_a, EVP_MD_name, EVP_MD_provider, +EVP_MD_is_a, EVP_MD_name, EVP_MD_names_do_all, EVP_MD_provider, EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, EVP_MD_block_size, EVP_MD_flags, EVP_MD_CTX_name, EVP_MD_CTX_md, EVP_MD_CTX_type, EVP_MD_CTX_size, EVP_MD_CTX_block_size, @@ -63,6 +63,9 @@ EVP_MD_do_all_provided const char *EVP_MD_name(const EVP_MD *md); int EVP_MD_is_a(const EVP_MD *md, const char *name); + void EVP_MD_names_do_all(const EVP_MD *md, + void (*fn)(const char *name, void *data), + void *data); const OSSL_PROVIDER *EVP_MD_provider(const EVP_MD *md); int EVP_MD_type(const EVP_MD *md); int EVP_MD_pkey_type(const EVP_MD *md); @@ -248,7 +251,13 @@ identifiable with I, otherwise 0. EVP_MD_CTX_name() Return the name of the given message digest. For fetched message -digests with multiple names, only one of them is returned. +digests with multiple names, only one of them is returned; it's +recommended to use EVP_MD_names_do_all() instead. + +=item EVP_MD_names_do_all() + +Traverses all names for the I, and calls I with each name and +I. This is only useful with fetched Bs. =item EVP_MD_provider() diff --git a/doc/man3/EVP_EncryptInit.pod b/doc/man3/EVP_EncryptInit.pod index c5c2c5ab39..0b6d4eba44 100644 --- a/doc/man3/EVP_EncryptInit.pod +++ b/doc/man3/EVP_EncryptInit.pod @@ -31,6 +31,7 @@ EVP_get_cipherbynid, EVP_get_cipherbyobj, EVP_CIPHER_is_a, EVP_CIPHER_name, +EVP_CIPHER_names_do_all, EVP_CIPHER_provider, EVP_CIPHER_nid, EVP_CIPHER_get_params, @@ -122,6 +123,9 @@ EVP_CIPHER_do_all_provided int EVP_CIPHER_nid(const EVP_CIPHER *e); int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name); + void EVP_CIPHER_names_do_all(const EVP_CIPHER *cipher, + void (*fn)(const char *name, void *data), + void *data); const char *EVP_CIPHER_name(const EVP_CIPHER *cipher); const OSSL_PROVIDER *EVP_CIPHER_provider(const EVP_CIPHER *cipher); int EVP_CIPHER_block_size(const EVP_CIPHER *e); @@ -335,7 +339,12 @@ algorithm that's identifiable with I, otherwise 0. EVP_CIPHER_name() and EVP_CIPHER_CTX_name() return the name of the passed cipher or context. For fetched ciphers with multiple names, only one -of them is returned. +of them is returned; it's recommended to use EVP_CIPHER_names_do_all() +instead. + +EVP_CIPHER_names_do_all() traverses all names for the I, and +calls I with each name and I. This is only useful with +fetched Bs. EVP_CIPHER_provider() returns an B pointer to the provider that implements the given B. diff --git a/doc/man3/EVP_KDF.pod b/doc/man3/EVP_KDF.pod index 306961f3f1..61c7a562e5 100644 --- a/doc/man3/EVP_KDF.pod +++ b/doc/man3/EVP_KDF.pod @@ -6,6 +6,7 @@ EVP_KDF, EVP_KDF_fetch, EVP_KDF_free, EVP_KDF_up_ref, EVP_KDF_CTX, EVP_KDF_CTX_new, EVP_KDF_CTX_free, EVP_KDF_CTX_dup, EVP_KDF_reset, EVP_KDF_derive, EVP_KDF_size, EVP_KDF_provider, EVP_KDF_CTX_kdf, EVP_KDF_is_a, +EVP_KDF_names_do_all, EVP_KDF_CTX_get_params, EVP_KDF_CTX_set_params, EVP_KDF_do_all_provided, EVP_KDF_get_params, EVP_KDF_gettable_ctx_params, EVP_KDF_settable_ctx_params, EVP_KDF_gettable_params - EVP KDF routines @@ -24,7 +25,6 @@ EVP_KDF_gettable_params - EVP KDF routines void EVP_KDF_reset(EVP_KDF_CTX *ctx); size_t EVP_KDF_size(EVP_KDF_CTX *ctx); int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen); - const char *EVP_KDF_name(const EVP_KDF *kdf); 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, @@ -34,6 +34,9 @@ EVP_KDF_gettable_params - EVP KDF routines void EVP_KDF_do_all_provided(OPENSSL_CTX *libctx, void (*fn)(EVP_KDF *kdf, void *arg), void *arg); + void EVP_KDF_names_do_all(const EVP_KDF *kdf, + void (*fn)(const char *name, void *data), + void *data); int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]); int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]); int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]); @@ -130,8 +133,6 @@ of output and B otherwise. If an error occurs then 0 is returned. For some algorithms an error may result if input parameters necessary to calculate a fixed output size have not yet been supplied. -EVP_KDF_name() returns the name of the given KDF implementation. - EVP_KDF_is_a() returns 1 if I is an implementation of an algorithm that's identifiable with I, otherwise 0. @@ -143,6 +144,9 @@ providers in the given library context I, and for each of the implementations, calls the given function I with the implementation method and the given I as argument. +EVP_KDF_names_do_all() traverses all names for I, and calls +I with each name and I. + =head1 PARAMETERS The standard parameter names are: @@ -219,9 +223,6 @@ The memory size must never exceed what can be given with a B. EVP_KDF_fetch() returns a pointer to a newly fetched B, or NULL if allocation failed. -EVP_KDF_name() returns the name for the given I, if it has been -added to the object database. - EVP_KDF_provider() returns a pointer to the provider for the KDF, or NULL on error. diff --git a/doc/man3/EVP_KEYEXCH_free.pod b/doc/man3/EVP_KEYEXCH_free.pod index 5e81d249e2..d9b36a495a 100644 --- a/doc/man3/EVP_KEYEXCH_free.pod +++ b/doc/man3/EVP_KEYEXCH_free.pod @@ -3,7 +3,7 @@ =head1 NAME EVP_KEYEXCH_fetch, EVP_KEYEXCH_free, EVP_KEYEXCH_up_ref, EVP_KEYEXCH_provider, -EVP_KEYEXCH_is_a, EVP_KEYEXCH_do_all_provided, +EVP_KEYEXCH_is_a, EVP_KEYEXCH_do_all_provided, EVP_KEYEXCH_names_do_all - Functions to manage EVP_KEYEXCH algorithm objects =head1 SYNOPSIS @@ -19,6 +19,9 @@ EVP_KEYEXCH_is_a, EVP_KEYEXCH_do_all_provided, void EVP_KEYEXCH_do_all_provided(OPENSSL_CTX *libctx, void (*fn)(EVP_KEYEXCH *exchange, void *arg), void *arg); + void EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *exchange, + void (*fn)(const char *name, void *data), + void *data); =head1 DESCRIPTION @@ -42,6 +45,9 @@ EVP_KEYEXCH_provider() returns the provider that I was fetched from. EVP_KEYEXCH_is_a() checks if I is an implementation of an algorithm that's identifiable with I. +EVP_KEYEXCH_names_do_all() traverses all names for the I, and +calls I with each name and I. + EVP_KEYEXCH_do_all_provided() traverses all key exchange implementations by all activated providers in the library context I, and for each of the implementations, calls I with the implementation method and diff --git a/doc/man3/EVP_KEYMGMT.pod b/doc/man3/EVP_KEYMGMT.pod index 3b5a1c5763..2115d29e5e 100644 --- a/doc/man3/EVP_KEYMGMT.pod +++ b/doc/man3/EVP_KEYMGMT.pod @@ -9,6 +9,7 @@ EVP_KEYMGMT_free, EVP_KEYMGMT_provider, EVP_KEYMGMT_is_a, EVP_KEYMGMT_do_all_provided, +EVP_KEYMGMT_names_do_all - EVP key management routines =head1 SYNOPSIS @@ -26,6 +27,9 @@ EVP_KEYMGMT_do_all_provided, void EVP_KEYMGMT_do_all_provided(OPENSSL_CTX *libctx, void (*fn)(EVP_KEYMGMT *keymgmt, void *arg), void *arg); + void EVP_KEYMGMT_names_do_all(const EVP_KEYMGMT *keymgmt, + void (*fn)(const char *name, void *data), + void *data); =head1 DESCRIPTION @@ -54,6 +58,9 @@ implementation. EVP_KEYMGMT_is_a() checks if I is an implementation of an algorithm that's identifiable with I. +EVP_KEYMGMT_names_do_all() traverses all names for the I, and +calls I with each name and I. + EVP_KEYMGMT_do_all_provided() traverses all key keymgmt implementations by all activated providers in the library context I, and for each of the implementations, calls I with the implementation method and diff --git a/doc/man3/EVP_MAC.pod b/doc/man3/EVP_MAC.pod index ab2e1e7334..cd3755d8ef 100644 --- a/doc/man3/EVP_MAC.pod +++ b/doc/man3/EVP_MAC.pod @@ -3,7 +3,7 @@ =head1 NAME EVP_MAC, EVP_MAC_fetch, EVP_MAC_up_ref, EVP_MAC_free, -EVP_MAC_is_a, EVP_MAC_name, +EVP_MAC_is_a, EVP_MAC_names_do_all, EVP_MAC_provider, EVP_MAC_get_params, EVP_MAC_gettable_params, EVP_MAC_CTX, EVP_MAC_CTX_new, EVP_MAC_CTX_free, EVP_MAC_CTX_dup, EVP_MAC_CTX_mac, EVP_MAC_CTX_get_params, EVP_MAC_CTX_set_params, @@ -23,7 +23,9 @@ EVP_MAC_do_all_provided - EVP MAC routines int EVP_MAC_up_ref(EVP_MAC *mac); void EVP_MAC_free(EVP_MAC *mac); int EVP_MAC_is_a(const EVP_MAC *mac, const char *name); - const char *EVP_MAC_name(const EVP_MAC *mac); + void EVP_MAC_names_do_all(const EVP_MAC *mac, + void (*fn)(const char *name, void *data), + void *data); const OSSL_PROVIDER *EVP_MAC_provider(const EVP_MAC *mac); int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]); @@ -157,8 +159,6 @@ See L for the use of B as parameter descriptor. EVP_MAC_size() returns the MAC output size for the given context. -EVP_MAC_name() returns the name of the given MAC implementation. - EVP_MAC_is_a() checks if the given I is an implementation of an algorithm that's identifiable with I. @@ -170,6 +170,9 @@ providers in the given library context I, and for each of the implementations, calls the given function I with the implementation method and the given I as argument. +EVP_MAC_names_do_all() traverses all names for I, and calls +I with each name and I. + =head1 PARAMETERS Parameters are identified by name as strings, and have an expected @@ -254,9 +257,6 @@ EVP_MAC_up_ref() returns 1 on success, 0 on error. EVP_MAC_free() returns nothing at all. -EVP_MAC_name() returns the name of the MAC, or NULL if NULL was -passed. - EVP_MAC_is_a() returns 1 if the given method can be identified with the given name, otherwise 0. diff --git a/doc/man3/EVP_SIGNATURE_free.pod b/doc/man3/EVP_SIGNATURE_free.pod index 3fb741622d..fa2106aeb8 100644 --- a/doc/man3/EVP_SIGNATURE_free.pod +++ b/doc/man3/EVP_SIGNATURE_free.pod @@ -3,7 +3,8 @@ =head1 NAME EVP_SIGNATURE_fetch, EVP_SIGNATURE_free, EVP_SIGNATURE_up_ref, -EVP_SIGNATURE_is_a, EVP_SIGNATURE_provider, EVP_SIGNATURE_do_all_provided +EVP_SIGNATURE_is_a, EVP_SIGNATURE_provider, EVP_SIGNATURE_do_all_provided, +EVP_SIGNATURE_names_do_all - Functions to manage EVP_SIGNATURE algorithm objects =head1 SYNOPSIS @@ -20,6 +21,9 @@ EVP_SIGNATURE_is_a, EVP_SIGNATURE_provider, EVP_SIGNATURE_do_all_provided void (*fn)(EVP_SIGNATURE *signature, void *arg), void *arg); + void EVP_SIGNATURE_names_do_all(const EVP_SIGNATURE *signature, + void (*fn)(const char *name, void *data), + void *data); =head1 DESCRIPTION @@ -50,6 +54,9 @@ activated roviders in the given library context I, and for each of the implementations, calls the given function I with the implementation method and the given I as argument. +EVP_SIGNATURE_names_do_all() traverses all names for I, and calls +I with each name and I. + =head1 RETURN VALUES EVP_SIGNATURE_fetch() returns a pointer to an B for success diff --git a/include/openssl/evp.h b/include/openssl/evp.h index 8e452443ff..0ff5b6536f 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -463,6 +463,9 @@ int EVP_MD_type(const EVP_MD *md); # define EVP_MD_nid(e) EVP_MD_type(e) const char *EVP_MD_name(const EVP_MD *md); int EVP_MD_is_a(const EVP_MD *md, const char *name); +void EVP_MD_names_do_all(const EVP_MD *md, + void (*fn)(const char *name, void *data), + void *data); const OSSL_PROVIDER *EVP_MD_provider(const EVP_MD *md); int EVP_MD_pkey_type(const EVP_MD *md); int EVP_MD_size(const EVP_MD *md); @@ -486,6 +489,9 @@ void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx); int EVP_CIPHER_nid(const EVP_CIPHER *cipher); const char *EVP_CIPHER_name(const EVP_CIPHER *cipher); int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name); +void EVP_CIPHER_names_do_all(const EVP_CIPHER *cipher, + void (*fn)(const char *name, void *data), + void *data); const OSSL_PROVIDER *EVP_CIPHER_provider(const EVP_CIPHER *cipher); int EVP_CIPHER_block_size(const EVP_CIPHER *cipher); int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *cipher); @@ -1052,7 +1058,6 @@ EVP_MAC *EVP_MAC_fetch(OPENSSL_CTX *libctx, const char *algorithm, const char *properties); int EVP_MAC_up_ref(EVP_MAC *mac); void EVP_MAC_free(EVP_MAC *mac); -const char *EVP_MAC_name(const EVP_MAC *mac); int EVP_MAC_is_a(const EVP_MAC *mac, const char *name); const OSSL_PROVIDER *EVP_MAC_provider(const EVP_MAC *mac); int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]); @@ -1076,6 +1081,9 @@ const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac); void EVP_MAC_do_all_provided(OPENSSL_CTX *libctx, void (*fn)(EVP_MAC *mac, void *arg), void *arg); +void EVP_MAC_names_do_all(const EVP_MAC *mac, + void (*fn)(const char *name, void *data), + void *data); /* PKEY stuff */ int EVP_PKEY_decrypt_old(unsigned char *dec_key, @@ -1443,6 +1451,9 @@ int EVP_KEYMGMT_is_a(const EVP_KEYMGMT *keymgmt, const char *name); void EVP_KEYMGMT_do_all_provided(OPENSSL_CTX *libctx, void (*fn)(EVP_KEYMGMT *keymgmt, void *arg), void *arg); +void EVP_KEYMGMT_names_do_all(const EVP_KEYMGMT *keymgmt, + void (*fn)(const char *name, void *data), + void *data); EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); @@ -1505,6 +1516,9 @@ void EVP_SIGNATURE_do_all_provided(OPENSSL_CTX *libctx, void (*fn)(EVP_SIGNATURE *signature, void *data), void *data); +void EVP_SIGNATURE_names_do_all(const EVP_SIGNATURE *signature, + void (*fn)(const char *name, void *data), + void *data); int EVP_PKEY_sign_init_ex(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *signature); int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); @@ -1769,6 +1783,9 @@ int EVP_KEYEXCH_is_a(const EVP_KEYEXCH *keyexch, const char *name); void EVP_KEYEXCH_do_all_provided(OPENSSL_CTX *libctx, void (*fn)(EVP_KEYEXCH *keyexch, void *data), void *data); +void EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch, + void (*fn)(const char *name, void *data), + void *data); void EVP_add_alg_module(void); diff --git a/include/openssl/kdf.h b/include/openssl/kdf.h index 4a53b4c30e..1b9cada649 100644 --- a/include/openssl/kdf.h +++ b/include/openssl/kdf.h @@ -33,7 +33,6 @@ EVP_KDF *EVP_KDF_fetch(OPENSSL_CTX *libctx, const char *algorithm, EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf); void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx); EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src); -const char *EVP_KDF_name(const EVP_KDF *kdf); int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name); const OSSL_PROVIDER *EVP_KDF_provider(const EVP_KDF *kdf); const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx); @@ -51,6 +50,9 @@ const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf); void EVP_KDF_do_all_provided(OPENSSL_CTX *libctx, void (*fn)(EVP_KDF *kdf, void *arg), void *arg); +void EVP_KDF_names_do_all(const EVP_KDF *kdf, + void (*fn)(const char *name, void *data), + void *data); # define EVP_KDF_CTRL_SET_PASS 0x01 /* unsigned char *, size_t */ # define EVP_KDF_CTRL_SET_SALT 0x02 /* unsigned char *, size_t */ diff --git a/test/evp_test.c b/test/evp_test.c index d6f852913c..b68ad3b9c4 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -938,6 +938,7 @@ static const EVP_TEST_METHOD cipher_test_method = { typedef struct mac_data_st { /* MAC type in one form or another */ + char *mac_name; EVP_MAC *mac; /* for mac_test_run_mac */ int type; /* for mac_test_run_pkey */ /* Algorithm string for this MAC */ @@ -1021,6 +1022,7 @@ static int mac_test_init(EVP_TEST *t, const char *alg) mdat = OPENSSL_zalloc(sizeof(*mdat)); mdat->type = type; + mdat->mac_name = OPENSSL_strdup(alg); mdat->mac = mac; mdat->controls = sk_OPENSSL_STRING_new_null(); t->data = mdat; @@ -1038,6 +1040,7 @@ static void mac_test_cleanup(EVP_TEST *t) MAC_DATA *mdat = t->data; EVP_MAC_free(mdat->mac); + OPENSSL_free(mdat->mac_name); sk_OPENSSL_STRING_pop_free(mdat->controls, openssl_free); OPENSSL_free(mdat->alg); OPENSSL_free(mdat->key); @@ -1198,10 +1201,10 @@ static int mac_test_run_mac(EVP_TEST *t) EVP_MAC_settable_ctx_params(expected->mac); if (expected->alg == NULL) - TEST_info("Trying the EVP_MAC %s test", EVP_MAC_name(expected->mac)); + TEST_info("Trying the EVP_MAC %s test", expected->mac_name); else TEST_info("Trying the EVP_MAC %s test with %s", - EVP_MAC_name(expected->mac), expected->alg); + expected->mac_name, expected->alg); #ifdef OPENSSL_NO_DES if (expected->alg != NULL && strstr(expected->alg, "DES") != NULL) { diff --git a/util/libcrypto.num b/util/libcrypto.num index 7b04958baa..1fd7de9b09 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4718,7 +4718,7 @@ EVP_MAC_CTX_get_params 4834 3_0_0 EXIST::FUNCTION: EVP_MAC_gettable_ctx_params 4835 3_0_0 EXIST::FUNCTION: EVP_MAC_free 4836 3_0_0 EXIST::FUNCTION: EVP_MAC_up_ref 4837 3_0_0 EXIST::FUNCTION: -EVP_MAC_name 4838 3_0_0 EXIST::FUNCTION: +EVP_MAC_name 4838 3_0_0 NOEXIST::FUNCTION: EVP_MAC_get_params 4839 3_0_0 EXIST::FUNCTION: EVP_MAC_gettable_params 4840 3_0_0 EXIST::FUNCTION: EVP_MAC_provider 4841 3_0_0 EXIST::FUNCTION: @@ -4729,7 +4729,7 @@ EVP_KDF_up_ref 4845 3_0_0 EXIST::FUNCTION: EVP_KDF_free 4846 3_0_0 EXIST::FUNCTION: EVP_KDF_fetch 4847 3_0_0 EXIST::FUNCTION: EVP_KDF_CTX_dup 4848 3_0_0 EXIST::FUNCTION: -EVP_KDF_name 4849 3_0_0 EXIST::FUNCTION: +EVP_KDF_name 4849 3_0_0 NOEXIST::FUNCTION: EVP_KDF_provider 4850 3_0_0 EXIST::FUNCTION: EVP_KDF_get_params 4851 3_0_0 EXIST::FUNCTION: EVP_KDF_CTX_get_params 4852 3_0_0 EXIST::FUNCTION: @@ -4836,3 +4836,10 @@ EVP_KDF_is_a 4952 3_0_0 EXIST::FUNCTION: EVP_MD_is_a 4953 3_0_0 EXIST::FUNCTION: EVP_SIGNATURE_is_a 4954 3_0_0 EXIST::FUNCTION: EVP_SIGNATURE_do_all_provided 4955 3_0_0 EXIST::FUNCTION: +EVP_MD_names_do_all 4956 3_0_0 EXIST::FUNCTION: +EVP_CIPHER_names_do_all 4957 3_0_0 EXIST::FUNCTION: +EVP_MAC_names_do_all 4958 3_0_0 EXIST::FUNCTION: +EVP_KEYMGMT_names_do_all 4959 3_0_0 EXIST::FUNCTION: +EVP_KEYEXCH_names_do_all 4960 3_0_0 EXIST::FUNCTION: +EVP_KDF_names_do_all 4961 3_0_0 EXIST::FUNCTION: +EVP_SIGNATURE_names_do_all 4962 3_0_0 EXIST::FUNCTION: -- 2.25.1