summaryrefslogtreecommitdiffstats
path: root/providers/legacyprov.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2020-05-12 09:02:25 +0200
committerMatt Caswell <matt@openssl.org>2020-05-13 17:22:13 +0100
commit78906fff4a6cfd5857045df770b47ae9ebcf0766 (patch)
tree83d8efcdb711b328c78ea44f842434ca42f33a33 /providers/legacyprov.c
parent05aa8790ac1ef2bb39c15ae241a591704664039c (diff)
PROV: Adapt all our providers to use the new PROV_CTX structure
Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/11803)
Diffstat (limited to 'providers/legacyprov.c')
-rw-r--r--providers/legacyprov.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/providers/legacyprov.c b/providers/legacyprov.c
index 07b505a8ac..9a6ed6d836 100644
--- a/providers/legacyprov.c
+++ b/providers/legacyprov.c
@@ -155,8 +155,15 @@ static const OSSL_ALGORITHM *legacy_query(void *provctx, int operation_id,
return NULL;
}
+static void legacy_teardown(void *provctx)
+{
+ OPENSSL_CTX_free(PROV_LIBRARY_CONTEXT_OF(provctx));
+ PROV_CTX_free(provctx);
+}
+
/* Functions we provide to the core */
static const OSSL_DISPATCH legacy_dispatch_table[] = {
+ { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))legacy_teardown },
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))legacy_gettable_params },
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))legacy_get_params },
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))legacy_query },
@@ -169,6 +176,7 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
void **provctx)
{
OSSL_core_get_library_context_fn *c_get_libctx = NULL;
+ OPENSSL_CTX *libctx = NULL;
for (; in->function_id != 0; in++) {
switch (in->function_id) {
@@ -190,13 +198,17 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
if (c_get_libctx == NULL)
return 0;
+ if ((*provctx = PROV_CTX_new()) == NULL
+ || (libctx = OPENSSL_CTX_new()) == NULL) {
+ OPENSSL_CTX_free(libctx);
+ legacy_teardown(*provctx);
+ *provctx = NULL;
+ return 0;
+ }
+ PROV_CTX_set0_library_context(*provctx, libctx);
+ PROV_CTX_set0_provider(*provctx, provider);
+
*out = legacy_dispatch_table;
- /*
- * We want to make sure that all calls from this provider that requires
- * a library context use the same context as the one used to call our
- * functions. We do that by passing it along as the provider context.
- */
- *provctx = c_get_libctx(provider);
return 1;
}