From e19246dc721a7a57c62d7dd39c70b6c87140b0ec Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 25 Jan 2021 15:24:46 +0100 Subject: [PATCH] EVP: Make evp_pkey_ctx_state() available to all of EVP This will help with transitioning diverse functions to be able to use the ctrl<->OSSL_PARAM translators. Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/13913) --- crypto/evp/pmeth_lib.c | 43 +++++++++++++++++++----------------------- include/crypto/evp.h | 6 ++++++ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 73f44c46cb..fa9dda60c2 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -135,12 +135,26 @@ EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags) return pmeth; } -/* Three possible states: */ -# define EVP_PKEY_STATE_UNKNOWN 0 -# define EVP_PKEY_STATE_LEGACY 1 -# define EVP_PKEY_STATE_PROVIDER 2 +static void help_get_legacy_alg_type_from_keymgmt(const char *keytype, + void *arg) +{ + int *type = arg; + + if (*type == NID_undef) + *type = evp_pkey_name2type(keytype); +} -static int evp_pkey_ctx_state(EVP_PKEY_CTX *ctx) +static int get_legacy_alg_type_from_keymgmt(const EVP_KEYMGMT *keymgmt) +{ + int type = NID_undef; + + EVP_KEYMGMT_names_do_all(keymgmt, help_get_legacy_alg_type_from_keymgmt, + &type); + return type; +} +#endif /* FIPS_MODULE */ + +int evp_pkey_ctx_state(const EVP_PKEY_CTX *ctx) { if (ctx->operation == EVP_PKEY_OP_UNDEFINED) return EVP_PKEY_STATE_UNKNOWN; @@ -160,25 +174,6 @@ static int evp_pkey_ctx_state(EVP_PKEY_CTX *ctx) return EVP_PKEY_STATE_LEGACY; } -static void help_get_legacy_alg_type_from_keymgmt(const char *keytype, - void *arg) -{ - int *type = arg; - - if (*type == NID_undef) - *type = evp_pkey_name2type(keytype); -} - -static int get_legacy_alg_type_from_keymgmt(const EVP_KEYMGMT *keymgmt) -{ - int type = NID_undef; - - EVP_KEYMGMT_names_do_all(keymgmt, help_get_legacy_alg_type_from_keymgmt, - &type); - return type; -} -#endif /* FIPS_MODULE */ - static EVP_PKEY_CTX *int_ctx_new(OSSL_LIB_CTX *libctx, EVP_PKEY *pkey, ENGINE *e, const char *keytype, const char *propquery, diff --git a/include/crypto/evp.h b/include/crypto/evp.h index cc74f11548..2a92a1e533 100644 --- a/include/crypto/evp.h +++ b/include/crypto/evp.h @@ -858,4 +858,10 @@ EVP_PKEY *evp_privatekey_from_binary(int keytype, EVP_PKEY **a, const unsigned char **pp, long length, OSSL_LIB_CTX *libctx, const char *propq); +/* Three possible states: */ +# define EVP_PKEY_STATE_UNKNOWN 0 +# define EVP_PKEY_STATE_LEGACY 1 +# define EVP_PKEY_STATE_PROVIDER 2 +int evp_pkey_ctx_state(const EVP_PKEY_CTX *ctx); + #endif /* OSSL_CRYPTO_EVP_H */ -- 2.34.1