diff options
author | Richard Levitte <levitte@openssl.org> | 2020-05-15 15:56:05 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-05-19 11:02:41 +0200 |
commit | 5a29b6286f8ccafc2ed9a026b0e8d4bd6d0396e6 (patch) | |
tree | 7addeebb9956f0e747bb0c1175e0e79eecb7b762 /crypto/core_fetch.c | |
parent | Use _get0_ functions instead of _get_. (diff) | |
download | openssl-5a29b6286f8ccafc2ed9a026b0e8d4bd6d0396e6.tar.xz openssl-5a29b6286f8ccafc2ed9a026b0e8d4bd6d0396e6.zip |
CORE: query for operations only once per provider (unless no_store is true)
When a desired algorithm wasn't available, we didn't register anywhere
that an attempt had been made, with the result that next time the same
attempt was made, the whole process would be done again.
To avoid this churn, we register a bit for each operation that has
been queried in the libcrypto provider object, and test it before
trying the same query and method construction loop again.
If course, if the provider has told us not to cache, we don't register
this bit.
Fixes #11814
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11842)
Diffstat (limited to 'crypto/core_fetch.c')
-rw-r--r-- | crypto/core_fetch.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/crypto/core_fetch.c b/crypto/core_fetch.c index 7f815a50ac..51ae4011dc 100644 --- a/crypto/core_fetch.c +++ b/crypto/core_fetch.c @@ -24,6 +24,42 @@ struct construct_data_st { void *mcm_data; }; +static int ossl_method_construct_precondition(OSSL_PROVIDER *provider, + int operation_id, void *cbdata, + int *result) +{ + if (!ossl_assert(result != NULL)) { + ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER); + return 0; + } + + if (!ossl_provider_test_operation_bit(provider, operation_id, result)) + return 0; + + /* + * The result we get tells if methods have already been constructed. + * However, we want to tell whether construction should happen (true) + * or not (false), which is the opposite of what we got. + */ + *result = !*result; + + return 1; +} + +static int ossl_method_construct_postcondition(OSSL_PROVIDER *provider, + int operation_id, int no_store, + void *cbdata, int *result) +{ + if (!ossl_assert(result != NULL)) { + ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER); + return 0; + } + + *result = 1; + return no_store != 0 + || ossl_provider_set_operation_bit(provider, operation_id); +} + static void ossl_method_construct_this(OSSL_PROVIDER *provider, const OSSL_ALGORITHM *algo, int no_store, void *cbdata) @@ -86,7 +122,10 @@ void *ossl_method_construct(OPENSSL_CTX *libctx, int operation_id, cbdata.mcm = mcm; cbdata.mcm_data = mcm_data; ossl_algorithm_do_all(libctx, operation_id, NULL, - ossl_method_construct_this, &cbdata); + ossl_method_construct_precondition, + ossl_method_construct_this, + ossl_method_construct_postcondition, + &cbdata); method = mcm->get(libctx, cbdata.store, mcm_data); mcm->dealloc_tmp_store(cbdata.store); |