From: Richard Levitte Date: Fri, 5 Apr 2019 08:46:18 +0000 (+0200) Subject: EVP_set_default_properties(): New function to set global properties X-Git-Tag: openssl-3.0.0-alpha1~2219 X-Git-Url: https://git.openssl.org/?p=openssl.git;a=commitdiff_plain;h=cb92964563a053d5d9c0810912fa6d3ff35c1e16 EVP_set_default_properties(): New function to set global properties EVP_MD_fetch() can be given a property query string. However, there are cases when it won't, for example in implicit fetches. Therefore, we also need a way to set a global property query string to be used in all subsequent fetches. This also applies to all future algorithm fetching functions. Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/8681) --- diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt index 19a418fafc..a3d15c9a5f 100644 --- a/crypto/err/openssl.txt +++ b/crypto/err/openssl.txt @@ -858,6 +858,7 @@ EVP_F_EVP_PKEY_VERIFY:142:EVP_PKEY_verify EVP_F_EVP_PKEY_VERIFY_INIT:143:EVP_PKEY_verify_init EVP_F_EVP_PKEY_VERIFY_RECOVER:144:EVP_PKEY_verify_recover EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT:145:EVP_PKEY_verify_recover_init +EVP_F_EVP_SET_DEFAULT_PROPERTIES:236:EVP_set_default_properties EVP_F_EVP_SIGNFINAL:107:EVP_SignFinal EVP_F_EVP_VERIFYFINAL:108:EVP_VerifyFinal EVP_F_GMAC_CTRL:215:gmac_ctrl diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c index 1a4f3819b2..a9f8800b08 100644 --- a/crypto/evp/evp_err.c +++ b/crypto/evp/evp_err.c @@ -156,6 +156,8 @@ static const ERR_STRING_DATA EVP_str_functs[] = { "EVP_PKEY_verify_recover"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT, 0), "EVP_PKEY_verify_recover_init"}, + {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_SET_DEFAULT_PROPERTIES, 0), + "EVP_set_default_properties"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_SIGNFINAL, 0), "EVP_SignFinal"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_VERIFYFINAL, 0), "EVP_VerifyFinal"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_GMAC_CTRL, 0), "gmac_ctrl"}, diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c index e50dd592db..329129d133 100644 --- a/crypto/evp/evp_fetch.c +++ b/crypto/evp/evp_fetch.c @@ -78,8 +78,7 @@ static void *alloc_tmp_method_store(void) ossl_method_store_free(store); } -static -struct OSSL_METHOD_STORE *get_default_method_store(OPENSSL_CTX *libctx) +static OSSL_METHOD_STORE *get_default_method_store(OPENSSL_CTX *libctx) { if (!RUN_ONCE(&default_method_store_init_flag, do_default_method_store_init)) @@ -195,3 +194,13 @@ void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, return method; } + +int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq) +{ + OSSL_METHOD_STORE *store = get_default_method_store(libctx); + + if (store != NULL) + return ossl_method_store_set_global_properties(store, propq); + EVPerr(EVP_F_EVP_SET_DEFAULT_PROPERTIES, ERR_R_INTERNAL_ERROR); + return 0; +} diff --git a/doc/man3/EVP_MD_fetch.pod b/doc/man3/EVP_MD_fetch.pod index 96536048bc..cba3bc4f0b 100644 --- a/doc/man3/EVP_MD_fetch.pod +++ b/doc/man3/EVP_MD_fetch.pod @@ -39,9 +39,11 @@ algorithm from the default provider. With explicit fetch an application uses the EVP_MD_fetch() function to obtain an algorithm implementation. An implementation with the given name and -satisfying the search criteria specified in the B parameter will be -looked for within the available providers and returned. See L -for information about providers. +satisfying the search criteria specified in the B parameter +combined with the default search criteria will be looked for within the +available providers and returned. +See L for information on default search criteria +and L for information about providers. =item User defined @@ -156,7 +158,8 @@ other providers: =head1 SEE ALSO L, L, L, -L, L, L +L, L, L, +L =head1 HISTORY diff --git a/doc/man3/EVP_set_default_properties.pod b/doc/man3/EVP_set_default_properties.pod new file mode 100644 index 0000000000..077913c281 --- /dev/null +++ b/doc/man3/EVP_set_default_properties.pod @@ -0,0 +1,52 @@ +=pod + +=head1 NAME + +EVP_set_default_properties +- Set default properties for future algorithm fetches + +=head1 SYNOPSIS + + #include + + int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq); + +=head1 DESCRIPTION + +EVP_set_default_properties() sets the default properties for all +future EVP algorithm fetches, implicit as well as explicit. + +=for comment TODO(3.0) We should consider having an EVP document in +section 7 that details everything about implicit vs explicit fetches +and how they relate to properties. + +EVP_set_default_properties stores the properties given with the string +I among the EVP data that's been stored in the library context +given with I (NULL signifies the default library context). + +Any previous default property for the specified library context will +be dropped. + +=head1 RETURN VALUES + +EVP_set_default_properties() returns 1 on success, or 0 on failure. +The latter adds an error on the error stack. + +=head1 SEE ALSO + +L + +=head1 HISTORY + +The functions described here were added in OpenSSL 3.0. + +=head1 COPYRIGHT + +Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the Apache License 2.0 (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/include/openssl/evp.h b/include/openssl/evp.h index db8eec12f2..a903b29ffe 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -69,6 +69,8 @@ extern "C" { #endif +int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq); + # define EVP_PKEY_MO_SIGN 0x0001 # define EVP_PKEY_MO_VERIFY 0x0002 # define EVP_PKEY_MO_ENCRYPT 0x0004 diff --git a/include/openssl/evperr.h b/include/openssl/evperr.h index 5d3c576cb0..e62cfb3b90 100644 --- a/include/openssl/evperr.h +++ b/include/openssl/evperr.h @@ -128,6 +128,7 @@ int ERR_load_EVP_strings(void); # define EVP_F_EVP_PKEY_VERIFY_INIT 143 # define EVP_F_EVP_PKEY_VERIFY_RECOVER 144 # define EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT 145 +# define EVP_F_EVP_SET_DEFAULT_PROPERTIES 236 # define EVP_F_EVP_SIGNFINAL 107 # define EVP_F_EVP_VERIFYFINAL 108 # define EVP_F_GMAC_CTRL 215 diff --git a/util/libcrypto.num b/util/libcrypto.num index 5b488d0e4d..6388973066 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4793,3 +4793,4 @@ X509_get0_sm2_id 4740 3_0_0 EXIST::FUNCTION:SM2 EVP_PKEY_get0_engine 4741 3_0_0 EXIST::FUNCTION:ENGINE EVP_MD_upref 4742 3_0_0 EXIST::FUNCTION: EVP_MD_fetch 4743 3_0_0 EXIST::FUNCTION: +EVP_set_default_properties 4744 3_0_0 EXIST::FUNCTION: