From: Richard Levitte Date: Wed, 10 Jul 2019 20:24:00 +0000 (+0200) Subject: Re-implement EVP_MD_name() and EVP_CIPHER_name() as functions X-Git-Tag: openssl-3.0.0-alpha1~1737 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c750bc08516f1273751ba03fa533e3eb2418b92d;p=oweals%2Fopenssl.git Re-implement EVP_MD_name() and EVP_CIPHER_name() as functions They will do the same as usual for non-provider algorithms implementations, but can handle provider implementations as well. Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/9356) --- diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index 24441ef825..36a6aee690 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -415,6 +415,17 @@ int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx) return ctx->cipher->nid; } +const char *EVP_CIPHER_name(const EVP_CIPHER *cipher) +{ + if (cipher->prov != NULL) + return cipher->name; +#ifndef FIPS_MODE + return OBJ_nid2sn(EVP_CIPHER_nid(cipher)); +#else + return NULL; +#endif +} + int EVP_CIPHER_mode(const EVP_CIPHER *cipher) { int ok, v = EVP_CIPHER_flags(cipher) & EVP_CIPH_MODE; @@ -426,6 +437,17 @@ int EVP_CIPHER_mode(const EVP_CIPHER *cipher) return ok != 0 ? v : 0; } +const char *EVP_MD_name(const EVP_MD *md) +{ + if (md->prov != NULL) + return md->name; +#ifndef FIPS_MODE + return OBJ_nid2sn(EVP_MD_nid(md)); +#else + return NULL; +#endif +} + int EVP_MD_block_size(const EVP_MD *md) { if (md == NULL) { diff --git a/doc/man3/EVP_DigestInit.pod b/doc/man3/EVP_DigestInit.pod index 6f36f0a07b..6c125d2a32 100644 --- a/doc/man3/EVP_DigestInit.pod +++ b/doc/man3/EVP_DigestInit.pod @@ -8,7 +8,9 @@ EVP_MD_CTX_copy_ex, EVP_MD_CTX_ctrl, EVP_MD_CTX_set_params, EVP_MD_CTX_get_param 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_name, 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, EVP_MD_CTX_md_data, EVP_MD_CTX_update_fn, EVP_MD_CTX_set_update_fn, EVP_md_null, @@ -45,6 +47,7 @@ EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx - EVP digest routines int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in); + const char *EVP_MD_name(const EVP_MD *md); int EVP_MD_type(const EVP_MD *md); int EVP_MD_pkey_type(const EVP_MD *md); int EVP_MD_size(const EVP_MD *md); @@ -52,6 +55,7 @@ EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx - EVP digest routines unsigned long EVP_MD_flags(const EVP_MD *md); const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); + const char *EVP_MD_CTX_name(const EVP_MD_CTX *ctx); int EVP_MD_CTX_size(const EVP_MD *ctx); int EVP_MD_CTX_block_size(const EVP_MD *ctx); int EVP_MD_CTX_type(const EVP_MD *ctx); @@ -184,6 +188,11 @@ automatically cleaned up. Similar to EVP_MD_CTX_copy_ex() except the destination B does not have to be initialized. +=item EVP_MD_name(), +EVP_MD_CTX_name() + +Return the name of the given message digest. + =item EVP_MD_size(), EVP_MD_CTX_size() @@ -433,9 +442,9 @@ implementations of digests to be specified. If digest contexts are not cleaned up after use, memory leaks will occur. -EVP_MD_CTX_size(), EVP_MD_CTX_block_size(), EVP_MD_CTX_type(), -EVP_get_digestbynid() and EVP_get_digestbyobj() are defined as -macros. +EVP_MD_CTX_name(), EVP_MD_CTX_size(), EVP_MD_CTX_block_size(), +EVP_MD_CTX_type(), EVP_get_digestbynid() and EVP_get_digestbyobj() are defined +as macros. EVP_MD_CTX_ctrl() sends commands to message digests for additional configuration or control. diff --git a/doc/man3/EVP_EncryptInit.pod b/doc/man3/EVP_EncryptInit.pod index e4fb0c43ca..1bf25ac985 100644 --- a/doc/man3/EVP_EncryptInit.pod +++ b/doc/man3/EVP_EncryptInit.pod @@ -26,6 +26,7 @@ EVP_CipherFinal, EVP_get_cipherbyname, EVP_get_cipherbynid, EVP_get_cipherbyobj, +EVP_CIPHER_name, EVP_CIPHER_nid, EVP_CIPHER_block_size, EVP_CIPHER_key_length, @@ -34,6 +35,7 @@ EVP_CIPHER_flags, EVP_CIPHER_mode, EVP_CIPHER_type, EVP_CIPHER_CTX_cipher, +EVP_CIPHER_CTX_name, EVP_CIPHER_CTX_nid, EVP_CIPHER_CTX_block_size, EVP_CIPHER_CTX_key_length, @@ -101,6 +103,7 @@ EVP_enc_null const EVP_CIPHER *EVP_get_cipherbyobj(const ASN1_OBJECT *a); int EVP_CIPHER_nid(const EVP_CIPHER *e); + const char *EVP_CIPHER_name(const EVP_CIPHER *cipher); int EVP_CIPHER_block_size(const EVP_CIPHER *e); int EVP_CIPHER_key_length(const EVP_CIPHER *e); int EVP_CIPHER_iv_length(const EVP_CIPHER *e); @@ -110,6 +113,7 @@ EVP_enc_null const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx); int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx); + const char *EVP_CIPHER_CTX_name(const EVP_CIPHER_CTX *ctx); int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx); int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx); int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx); @@ -255,6 +259,9 @@ IDENTIFIER as such it ignores the cipher parameters and 40 bit RC2 and identifier or does not have ASN1 support this function will return B. +EVP_CIPHER_name() and EVP_CIPHER_CTX_name() return the name of the passed +cipher or context. + EVP_CIPHER_CTX_cipher() returns the B structure when passed an B structure. diff --git a/include/openssl/evp.h b/include/openssl/evp.h index d014a2e3cf..74dcb1af9d 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -449,7 +449,7 @@ typedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass, int EVP_MD_type(const EVP_MD *md); # define EVP_MD_nid(e) EVP_MD_type(e) -# define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e)) +const char *EVP_MD_name(const EVP_MD *md); int EVP_MD_pkey_type(const EVP_MD *md); int EVP_MD_size(const EVP_MD *md); int EVP_MD_block_size(const EVP_MD *md); @@ -461,6 +461,7 @@ int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx, void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx, int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count)); +# define EVP_MD_CTX_name(e) EVP_MD_name(EVP_MD_CTX_md(e)) # define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) # define EVP_MD_CTX_block_size(e) EVP_MD_block_size(EVP_MD_CTX_md(e)) # define EVP_MD_CTX_type(e) EVP_MD_type(EVP_MD_CTX_md(e)) @@ -469,7 +470,7 @@ void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx); void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx); int EVP_CIPHER_nid(const EVP_CIPHER *cipher); -# define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e)) +const char *EVP_CIPHER_name(const EVP_CIPHER *cipher); int EVP_CIPHER_block_size(const EVP_CIPHER *cipher); int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *cipher); int EVP_CIPHER_key_length(const EVP_CIPHER *cipher); @@ -496,6 +497,7 @@ void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx); void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data); void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx); void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data); +# define EVP_CIPHER_CTX_name(c) EVP_CIPHER_name(EVP_CIPHER_CTX_cipher(c)) # define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) # if !OPENSSL_API_1_1_0 # define EVP_CIPHER_CTX_flags(c) EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(c)) diff --git a/util/libcrypto.num b/util/libcrypto.num index e18fdca5b7..e9e5cfdca1 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4691,3 +4691,5 @@ EVP_KEYMGMT_free 4796 3_0_0 EXIST::FUNCTION: EVP_KEYMGMT_provider 4797 3_0_0 EXIST::FUNCTION: X509_PUBKEY_dup 4798 3_0_0 EXIST::FUNCTION: ERR_put_func_error 4799 3_0_0 EXIST::FUNCTION: +EVP_MD_name 4800 3_0_0 EXIST::FUNCTION: +EVP_CIPHER_name 4801 3_0_0 EXIST::FUNCTION: diff --git a/util/private.num b/util/private.num index 3307e3e239..1e76dfb43c 100644 --- a/util/private.num +++ b/util/private.num @@ -201,6 +201,7 @@ EVP_DigestVerifyUpdate define EVP_KDF_name define EVP_MAC_name define EVP_MD_CTX_block_size define +EVP_MD_CTX_name define EVP_MD_CTX_size define EVP_MD_CTX_type define EVP_OpenUpdate define