From a7ad40c502d3484e0a574e121cfba70631f224bf Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 18 May 2020 12:43:12 +0200 Subject: [PATCH] Add OSSL_PROVIDER_do_all() This allows applications to iterate over all loaded providers. Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/11858) --- crypto/provider.c | 8 ++++++++ doc/man3/OSSL_PROVIDER.pod | 9 ++++++++- include/openssl/provider.h | 3 +++ util/libcrypto.num | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crypto/provider.c b/crypto/provider.c index fe46d31877..09a5e53907 100644 --- a/crypto/provider.c +++ b/crypto/provider.c @@ -85,3 +85,11 @@ const char *OSSL_PROVIDER_name(const OSSL_PROVIDER *prov) { return ossl_provider_name(prov); } + +int OSSL_PROVIDER_do_all(OPENSSL_CTX *ctx, + int (*cb)(OSSL_PROVIDER *provider, + void *cbdata), + void *cbdata) +{ + return ossl_provider_forall_loaded(ctx, cb, cbdata); +} diff --git a/doc/man3/OSSL_PROVIDER.pod b/doc/man3/OSSL_PROVIDER.pod index 3f1a946653..93d6e1421c 100644 --- a/doc/man3/OSSL_PROVIDER.pod +++ b/doc/man3/OSSL_PROVIDER.pod @@ -4,7 +4,7 @@ OSSL_PROVIDER_set_default_search_path, OSSL_PROVIDER, OSSL_PROVIDER_load, OSSL_PROVIDER_unload, -OSSL_PROVIDER_available, +OSSL_PROVIDER_available, OSSL_PROVIDER_do_all, OSSL_PROVIDER_gettable_params, OSSL_PROVIDER_get_params, OSSL_PROVIDER_add_builtin, OSSL_PROVIDER_name - provider routines @@ -20,6 +20,9 @@ OSSL_PROVIDER_add_builtin, OSSL_PROVIDER_name - provider routines OSSL_PROVIDER *OSSL_PROVIDER_load(OPENSSL_CTX *libctx, const char *name); int OSSL_PROVIDER_unload(OSSL_PROVIDER *prov); int OSSL_PROVIDER_available(OPENSSL_CTX *libctx, const char *name); + int OSSL_PROVIDER_do_all(OPENSSL_CTX *ctx, + int (*cb)(OSSL_PROVIDER *provider, void *cbdata), + void *cbdata); const OSSL_PARAM *OSSL_PROVIDER_gettable_params(OSSL_PROVIDER *prov); int OSSL_PROVIDER_get_params(OSSL_PROVIDER *prov, OSSL_PARAM params[]); @@ -66,6 +69,10 @@ runs its teardown function. OSSL_PROVIDER_available() checks if a named provider is available for use. +OSSL_PROVIDER_do_all() iterates over all loaded providers, calling +I for each one, with the current provider in I and the +I that comes from the caller. + OSSL_PROVIDER_gettable_params() is used to get a provider parameter descriptor set as a constant B array. See L for more information. diff --git a/include/openssl/provider.h b/include/openssl/provider.h index f297ea2499..6ce68b16e7 100644 --- a/include/openssl/provider.h +++ b/include/openssl/provider.h @@ -23,6 +23,9 @@ int OSSL_PROVIDER_set_default_search_path(OPENSSL_CTX *, const char *path); OSSL_PROVIDER *OSSL_PROVIDER_load(OPENSSL_CTX *, const char *name); int OSSL_PROVIDER_unload(OSSL_PROVIDER *prov); int OSSL_PROVIDER_available(OPENSSL_CTX *, const char *name); +int OSSL_PROVIDER_do_all(OPENSSL_CTX *ctx, + int (*cb)(OSSL_PROVIDER *provider, void *cbdata), + void *cbdata); const OSSL_PARAM *OSSL_PROVIDER_gettable_params(const OSSL_PROVIDER *prov); int OSSL_PROVIDER_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]); diff --git a/util/libcrypto.num b/util/libcrypto.num index 8882f0480d..12c9f4f9d3 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -5092,3 +5092,4 @@ OSSL_STORE_LOADER_set_attach ? 3_0_0 EXIST::FUNCTION: EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen ? 3_0_0 EXIST::FUNCTION:RSA EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md ? 3_0_0 EXIST::FUNCTION:RSA EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name ? 3_0_0 EXIST::FUNCTION:RSA +OSSL_PROVIDER_do_all ? 3_0_0 EXIST::FUNCTION: -- 2.25.1