From c540f00f383754fa490be76c2c3398ccd4d2a869 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Sat, 13 Jul 2019 07:02:54 +0200 Subject: [PATCH] Add EVP_CIPHER_do_all_ex() and EVP_MD_do_all_ex() Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/9356) --- crypto/evp/digest.c | 9 +++++++++ crypto/evp/evp_enc.c | 9 +++++++++ doc/man3/EVP_DigestInit.pod | 15 ++++++++++++++- doc/man3/EVP_EncryptInit.pod | 12 +++++++++++- include/openssl/evp.h | 6 ++++++ util/libcrypto.num | 2 ++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 27f9d128ee..78e8756f2a 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -701,3 +701,12 @@ EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm, return md; } + +void EVP_MD_do_all_ex(OPENSSL_CTX *libctx, + void (*fn)(EVP_MD *mac, void *arg), + void *arg) +{ + evp_generic_do_all(libctx, OSSL_OP_DIGEST, + (void (*)(void *, void *))fn, arg, + evp_md_from_dispatch, evp_md_free); +} diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index bfdd581e0d..0873bae81a 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -1263,3 +1263,12 @@ EVP_CIPHER *EVP_CIPHER_fetch(OPENSSL_CTX *ctx, const char *algorithm, return cipher; } + +void EVP_CIPHER_do_all_ex(OPENSSL_CTX *libctx, + void (*fn)(EVP_CIPHER *mac, void *arg), + void *arg) +{ + evp_generic_do_all(libctx, OSSL_OP_CIPHER, + (void (*)(void *, void *))fn, arg, + evp_cipher_from_dispatch, evp_cipher_free); +} diff --git a/doc/man3/EVP_DigestInit.pod b/doc/man3/EVP_DigestInit.pod index a44266208c..226bc467c4 100644 --- a/doc/man3/EVP_DigestInit.pod +++ b/doc/man3/EVP_DigestInit.pod @@ -15,7 +15,9 @@ EVP_MD_CTX_md, EVP_MD_CTX_type, EVP_MD_CTX_size, EVP_MD_CTX_block_size, EVP_MD_CTX_md_data, EVP_MD_CTX_update_fn, EVP_MD_CTX_set_update_fn, EVP_md_null, EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj, -EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx - EVP digest routines +EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx, +EVP_MD_do_all_ex +- EVP digest routines =head1 SYNOPSIS @@ -76,6 +78,10 @@ EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx - EVP digest routines EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx); void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx); + void EVP_MD_do_all_ex(OPENSSL_CTX *libctx, + void (*fn)(EVP_MD *mac, void *arg), + void *arg); + =head1 DESCRIPTION The EVP digest routines are a high level interface to message digests, @@ -281,6 +287,13 @@ by the caller. A NULL B pointer is also allowed to clear the B. In such case, freeing the cleared B or not depends on how the B is created. +=item EVP_MD_do_all_ex() + +Traverses all messages digests implemented by all activated 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. + =back =head1 PARAMS diff --git a/doc/man3/EVP_EncryptInit.pod b/doc/man3/EVP_EncryptInit.pod index b1d18450d2..43ed7f90c2 100644 --- a/doc/man3/EVP_EncryptInit.pod +++ b/doc/man3/EVP_EncryptInit.pod @@ -49,7 +49,8 @@ EVP_CIPHER_CTX_mode, EVP_CIPHER_param_to_asn1, EVP_CIPHER_asn1_to_param, EVP_CIPHER_CTX_set_padding, -EVP_enc_null +EVP_enc_null, +EVP_CIPHER_do_all_ex - EVP cipher routines =head1 SYNOPSIS @@ -127,6 +128,10 @@ EVP_enc_null int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); + void EVP_CIPHER_do_all_ex(OPENSSL_CTX *libctx, + void (*fn)(EVP_CIPHER *cipher, void *arg), + void *arg); + =head1 DESCRIPTION The EVP cipher routines are a high level interface to certain @@ -302,6 +307,11 @@ based on the cipher context. The EVP_CIPHER can provide its own random key generation routine to support keys of a specific form. B must point to a buffer at least as big as the value returned by EVP_CIPHER_CTX_key_length(). +EVP_CIPHER_do_all_ex() traverses all ciphers implemented by all activated +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. + =head1 RETURN VALUES EVP_CIPHER_fetch() returns a pointer to a B for success diff --git a/include/openssl/evp.h b/include/openssl/evp.h index dac1f3ac09..24ad23f3ea 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -995,6 +995,9 @@ void EVP_CIPHER_do_all(void (*fn) (const EVP_CIPHER *ciph, void EVP_CIPHER_do_all_sorted(void (*fn) (const EVP_CIPHER *ciph, const char *from, const char *to, void *x), void *arg); +void EVP_CIPHER_do_all_ex(OPENSSL_CTX *libctx, + void (*fn)(EVP_CIPHER *cipher, void *arg), + void *arg); void EVP_MD_do_all(void (*fn) (const EVP_MD *ciph, const char *from, const char *to, void *x), @@ -1002,6 +1005,9 @@ void EVP_MD_do_all(void (*fn) (const EVP_MD *ciph, void EVP_MD_do_all_sorted(void (*fn) (const EVP_MD *ciph, const char *from, const char *to, void *x), void *arg); +void EVP_MD_do_all_ex(OPENSSL_CTX *libctx, + void (*fn)(EVP_MD *md, void *arg), + void *arg); /* MAC stuff */ diff --git a/util/libcrypto.num b/util/libcrypto.num index 3caf9b859c..b0a7f81607 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4696,3 +4696,5 @@ EVP_CIPHER_name 4801 3_0_0 EXIST::FUNCTION: EVP_MD_provider 4802 3_0_0 EXIST::FUNCTION: EVP_CIPHER_provider 4803 3_0_0 EXIST::FUNCTION: OSSL_PROVIDER_name 4804 3_0_0 EXIST::FUNCTION: +EVP_CIPHER_do_all_ex 4805 3_0_0 EXIST::FUNCTION: +EVP_MD_do_all_ex 4806 3_0_0 EXIST::FUNCTION: -- 2.25.1