diff options
author | Richard Levitte <levitte@openssl.org> | 2019-04-30 13:41:51 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-04-30 15:34:23 +0200 |
commit | a39eb84006ca68d38d1c7204a6135647d06b5d01 (patch) | |
tree | a39170c4d6ece3fc94ae7fc4e09a97d4b090f00f /crypto/provider_core.c | |
parent | f79858ac4d90a450d0620d1ecb713bc35d7d9f8d (diff) |
Replumbing: give the possibility for the provider to create a context
OSSL_provider_init() gets another output parameter, holding a pointer
to a provider side context. It's entirely up to the provider to
define the context and what it's being used for. This pointer is
passed back to other provider functions, typically the provider global
get_params and set_params functions, and also the diverse algorithm
context creators, and of course, the teardown function.
With this, a provider can be instantiated more than once, or be
re-loaded as the case may be, while maintaining instance state.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8848)
Diffstat (limited to 'crypto/provider_core.c')
-rw-r--r-- | crypto/provider_core.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/crypto/provider_core.c b/crypto/provider_core.c index 9f4c017045..2d74f6dbb3 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -54,6 +54,9 @@ struct ossl_provider_st { OSSL_provider_get_param_types_fn *get_param_types; OSSL_provider_get_params_fn *get_params; OSSL_provider_query_operation_fn *query_operation; + + /* Provider side data */ + void *provctx; }; DEFINE_STACK_OF(OSSL_PROVIDER) @@ -275,7 +278,7 @@ void ossl_provider_free(OSSL_PROVIDER *prov) */ if (ref < 2 && prov->flag_initialized) { if (prov->teardown != NULL) - prov->teardown(); + prov->teardown(prov->provctx); prov->flag_initialized = 0; } @@ -401,7 +404,8 @@ static int provider_activate(OSSL_PROVIDER *prov) } if (prov->init_function == NULL - || !prov->init_function(prov, core_dispatch, &provider_dispatch)) { + || !prov->init_function(prov, core_dispatch, &provider_dispatch, + &prov->provctx)) { CRYPTOerr(CRYPTO_F_PROVIDER_ACTIVATE, ERR_R_INIT_FAIL); ERR_add_error_data(2, "name=", prov->name); DSO_free(prov->module); @@ -448,6 +452,11 @@ int ossl_provider_activate(OSSL_PROVIDER *prov) return 0; } +void *ossl_provider_ctx(const OSSL_PROVIDER *prov) +{ + return prov->provctx; +} + static int provider_forall_loaded(struct provider_store_st *store, int *found_activated, @@ -573,18 +582,20 @@ const char *ossl_provider_module_path(OSSL_PROVIDER *prov) void ossl_provider_teardown(const OSSL_PROVIDER *prov) { if (prov->teardown != NULL) - prov->teardown(); + prov->teardown(prov->provctx); } const OSSL_ITEM *ossl_provider_get_param_types(const OSSL_PROVIDER *prov) { - return prov->get_param_types == NULL ? NULL : prov->get_param_types(prov); + return prov->get_param_types == NULL + ? NULL : prov->get_param_types(prov->provctx); } int ossl_provider_get_params(const OSSL_PROVIDER *prov, const OSSL_PARAM params[]) { - return prov->get_params == NULL ? 0 : prov->get_params(prov, params); + return prov->get_params == NULL + ? 0 : prov->get_params(prov->provctx, params); } @@ -592,7 +603,7 @@ const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov, int operation_id, int *no_cache) { - return prov->query_operation(prov, operation_id, no_cache); + return prov->query_operation(prov->provctx, operation_id, no_cache); } /*- |