From 927d0566ded0dff9d6c5abc8a40bb84068446b76 Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Mon, 14 Mar 2022 08:13:12 +0000 Subject: Refactor OSSL_LIB_CTX to avoid using CRYPTO_EX_DATA This refactors OSSL_LIB_CTX to avoid using CRYPTO_EX_DATA. The assorted objects to be managed by OSSL_LIB_CTX are hardcoded and are initialized eagerly rather than lazily, which avoids the need for locking on access in most cases. Fixes #17116. Reviewed-by: Matt Caswell Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/17881) --- crypto/encode_decode/decoder_meth.c | 23 ++--------------------- crypto/encode_decode/encoder_meth.c | 23 ++--------------------- 2 files changed, 4 insertions(+), 42 deletions(-) (limited to 'crypto/encode_decode') diff --git a/crypto/encode_decode/decoder_meth.c b/crypto/encode_decode/decoder_meth.c index c469f84558..2a8b044f78 100644 --- a/crypto/encode_decode/decoder_meth.c +++ b/crypto/encode_decode/decoder_meth.c @@ -17,6 +17,7 @@ #include "internal/provider.h" #include "crypto/decoder.h" #include "encoder_local.h" +#include "crypto/context.h" /* * Decoder can have multiple names, separated with colons in a name string @@ -65,25 +66,6 @@ void OSSL_DECODER_free(OSSL_DECODER *decoder) OPENSSL_free(decoder); } -/* Permanent decoder method store, constructor and destructor */ -static void decoder_store_free(void *vstore) -{ - ossl_method_store_free(vstore); -} - -static void *decoder_store_new(OSSL_LIB_CTX *ctx) -{ - return ossl_method_store_new(ctx); -} - - -static const OSSL_LIB_CTX_METHOD decoder_store_method = { - /* We want decoder_store to be cleaned up before the provider store */ - OSSL_LIB_CTX_METHOD_PRIORITY_2, - decoder_store_new, - decoder_store_free, -}; - /* Data to be passed through ossl_method_construct() */ struct decoder_data_st { OSSL_LIB_CTX *libctx; @@ -120,8 +102,7 @@ static void dealloc_tmp_decoder_store(void *store) /* Get the permanent decoder store */ static OSSL_METHOD_STORE *get_decoder_store(OSSL_LIB_CTX *libctx) { - return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_DECODER_STORE_INDEX, - &decoder_store_method); + return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_DECODER_STORE_INDEX); } /* Get decoder methods from a store, or put one in */ diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c index 57b2f998e2..67bfcc23fe 100644 --- a/crypto/encode_decode/encoder_meth.c +++ b/crypto/encode_decode/encoder_meth.c @@ -17,6 +17,7 @@ #include "internal/provider.h" #include "crypto/encoder.h" #include "encoder_local.h" +#include "crypto/context.h" /* * Encoder can have multiple names, separated with colons in a name string @@ -65,25 +66,6 @@ void OSSL_ENCODER_free(OSSL_ENCODER *encoder) OPENSSL_free(encoder); } -/* Permanent encoder method store, constructor and destructor */ -static void encoder_store_free(void *vstore) -{ - ossl_method_store_free(vstore); -} - -static void *encoder_store_new(OSSL_LIB_CTX *ctx) -{ - return ossl_method_store_new(ctx); -} - - -static const OSSL_LIB_CTX_METHOD encoder_store_method = { - /* We want encoder_store to be cleaned up before the provider store */ - OSSL_LIB_CTX_METHOD_PRIORITY_2, - encoder_store_new, - encoder_store_free, -}; - /* Data to be passed through ossl_method_construct() */ struct encoder_data_st { OSSL_LIB_CTX *libctx; @@ -120,8 +102,7 @@ static void dealloc_tmp_encoder_store(void *store) /* Get the permanent encoder store */ static OSSL_METHOD_STORE *get_encoder_store(OSSL_LIB_CTX *libctx) { - return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_ENCODER_STORE_INDEX, - &encoder_store_method); + return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_ENCODER_STORE_INDEX); } /* Get encoder methods from a store, or put one in */ -- cgit v1.2.1