From: Richard Levitte Date: Tue, 13 Jul 2021 08:40:45 +0000 (+0200) Subject: EVP: Add EVP_PKEY_get0_provider() and EVP_PKEY_CTX_get0_provider() X-Git-Tag: openssl-3.0.0-beta2~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ad0a2c011020268a242737820bc50549e76cd6b8;p=thirdparty%2Fopenssl.git EVP: Add EVP_PKEY_get0_provider() and EVP_PKEY_CTX_get0_provider() Fixes #16058 Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/16063) --- diff --git a/crypto/evp/evp_pkey.c b/crypto/evp/evp_pkey.c index 6f0b3dbda96..8f3f1503756 100644 --- a/crypto/evp/evp_pkey.c +++ b/crypto/evp/evp_pkey.c @@ -237,3 +237,10 @@ const char *EVP_PKEY_get0_type_name(const EVP_PKEY *key) return name; } + +const OSSL_PROVIDER *EVP_PKEY_get0_provider(const EVP_PKEY *key) +{ + if (evp_pkey_is_provided(key)) + return EVP_KEYMGMT_get0_provider(key->keymgmt); + return NULL; +} diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index e5975081e13..7b835a5eb63 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -1531,11 +1531,33 @@ OSSL_LIB_CTX *EVP_PKEY_CTX_get0_libctx(EVP_PKEY_CTX *ctx) return ctx->libctx; } -const char *EVP_PKEY_CTX_get0_propq(EVP_PKEY_CTX *ctx) +const char *EVP_PKEY_CTX_get0_propq(const EVP_PKEY_CTX *ctx) { return ctx->propquery; } +const OSSL_PROVIDER *EVP_PKEY_CTX_get0_provider(const EVP_PKEY_CTX *ctx) +{ + if (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) { + if (ctx->op.sig.signature != NULL) + return EVP_SIGNATURE_get0_provider(ctx->op.sig.signature); + } else if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx)) { + if (ctx->op.kex.exchange != NULL) + return EVP_KEYEXCH_get0_provider(ctx->op.kex.exchange); + } else if (EVP_PKEY_CTX_IS_KEM_OP(ctx)) { + if (ctx->op.encap.kem != NULL) + return EVP_KEM_get0_provider(ctx->op.encap.kem); + } else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) { + if (ctx->op.ciph.cipher != NULL) + return EVP_ASYM_CIPHER_get0_provider(ctx->op.ciph.cipher); + } else if (EVP_PKEY_CTX_IS_GEN_OP(ctx)) { + if (ctx->keymgmt != NULL) + return EVP_KEYMGMT_get0_provider(ctx->keymgmt); + } + + return NULL; +} + /* Utility functions to send a string of hex string to a ctrl */ int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str) diff --git a/doc/man3/EVP_PKEY_CTX_get0_libctx.pod b/doc/man3/EVP_PKEY_CTX_get0_libctx.pod index 33aa418462d..9f84bd96c41 100644 --- a/doc/man3/EVP_PKEY_CTX_get0_libctx.pod +++ b/doc/man3/EVP_PKEY_CTX_get0_libctx.pod @@ -3,28 +3,37 @@ =head1 NAME EVP_PKEY_CTX_get0_libctx, -EVP_PKEY_CTX_get0_propq -- functions for getting OSSL_LIB_CTX and property query data from an EVP_PKEY_CTX +EVP_PKEY_CTX_get0_propq, +EVP_PKEY_CTX_get0_provider +- functions for getting diverse information from an EVP_PKEY_CTX =head1 SYNOPSIS #include OSSL_LIB_CTX *EVP_PKEY_CTX_get0_libctx(EVP_PKEY_CTX *ctx); - const char *EVP_PKEY_CTX_get0_propq(EVP_PKEY_CTX *ctx); + const char *EVP_PKEY_CTX_get0_propq(const EVP_PKEY_CTX *ctx); + const OSSL_PROVIDER *EVP_PKEY_CTX_get0_provider(const EVP_PKEY_CTX *ctx); =head1 DESCRIPTION -The EVP_PKEY_CTX_get0_libctx() and EVP_PKEY_CTX_get0_propq() functions obtain -the OSSL_LIB_CTX and property query string values respectively that were +EVP_PKEY_CTX_get0_libctx() and EVP_PKEY_CTX_get0_propq() obtain the +OSSL_LIB_CTX and property query string values respectively that were associated with the EVP_PKEY_CTX when it was constructed. +EVP_PKEY_CTX_get0_provider() returns the provider associated with the +ongoing B operation. If the operation is performed by +en B, this function returns NULL. + =head1 RETURN VALUES EVP_PKEY_CTX_get0_libctx() and EVP_PKEY_CTX_get0_propq() functions return the OSSL_LIB_CTX and property query string associated with the EVP_PKEY_CTX or NULL if they are not set. The returned values should not be freed by the caller. +EVP_PKEY_CTX_get0_provider() returns a provider if an operation performed by +a provider is ongoing, otherwise NULL. + =head1 SEE ALSO L diff --git a/doc/man3/EVP_PKEY_is_a.pod b/doc/man3/EVP_PKEY_is_a.pod index 58c7ed7f8e0..5a012f78048 100644 --- a/doc/man3/EVP_PKEY_is_a.pod +++ b/doc/man3/EVP_PKEY_is_a.pod @@ -3,7 +3,7 @@ =head1 NAME EVP_PKEY_is_a, EVP_PKEY_can_sign, EVP_PKEY_type_names_do_all, -EVP_PKEY_get0_type_name +EVP_PKEY_get0_type_name, EVP_PKEY_get0_provider - key type and capabilities functions =head1 SYNOPSIS @@ -16,6 +16,7 @@ EVP_PKEY_get0_type_name void (*fn)(const char *name, void *data), void *data); const char *EVP_PKEY_get0_type_name(const EVP_PKEY *key); + const OSSL_PROVIDER *EVP_PKEY_get0_provider(const EVP_PKEY *key); =head1 DESCRIPTION @@ -38,6 +39,9 @@ that holds the key which one will be returned. Ownership of the returned string is retained by the I object and should not be freed by the caller. +EVP_PKEY_get0_provider() returns the provider of the B's +L. + =head1 RETURN VALUES EVP_PKEY_is_a() returns 1 if I has the key type I, @@ -48,6 +52,8 @@ supports signing, otherwise 0. EVP_PKEY_get0_type_name() returns the name that is found or NULL on error. +EVP_PKEY_get0_provider() returns the provider if found or NULL if not. + EVP_PKEY_type_names_do_all() returns 1 if the callback was called for all names. A return value of 0 means that the callback was not called for any names. diff --git a/include/openssl/evp.h b/include/openssl/evp.h index f76c4a26d1a..1c8ce48773a 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -1380,6 +1380,7 @@ int EVP_PKEY_up_ref(EVP_PKEY *pkey); EVP_PKEY *EVP_PKEY_dup(EVP_PKEY *pkey); void EVP_PKEY_free(EVP_PKEY *pkey); const char *EVP_PKEY_get0_description(const EVP_PKEY *pkey); +const OSSL_PROVIDER *EVP_PKEY_get0_provider(const EVP_PKEY *key); EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length); @@ -2160,7 +2161,8 @@ int EVP_PKEY_get_group_name(const EVP_PKEY *pkey, char *name, size_t name_sz, size_t *gname_len); OSSL_LIB_CTX *EVP_PKEY_CTX_get0_libctx(EVP_PKEY_CTX *ctx); -const char *EVP_PKEY_CTX_get0_propq(EVP_PKEY_CTX *ctx); +const char *EVP_PKEY_CTX_get0_propq(const EVP_PKEY_CTX *ctx); +const OSSL_PROVIDER *EVP_PKEY_CTX_get0_provider(const EVP_PKEY_CTX *ctx); # ifdef __cplusplus } diff --git a/util/libcrypto.num b/util/libcrypto.num index c7862c568dd..3d4d7c37df2 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -5423,3 +5423,5 @@ ASN1_item_d2i_fp_ex ? 3_0_0 EXIST::FUNCTION:STDIO ASN1_item_d2i_bio_ex ? 3_0_0 EXIST::FUNCTION: ASN1_item_d2i_ex ? 3_0_0 EXIST::FUNCTION: ASN1_TIME_print_ex ? 3_0_0 EXIST::FUNCTION: +EVP_PKEY_get0_provider ? 3_0_0 EXIST::FUNCTION: +EVP_PKEY_CTX_get0_provider ? 3_0_0 EXIST::FUNCTION: