diff options
author | Hugo Landau <hlandau@openssl.org> | 2022-03-14 08:13:12 +0000 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-11-21 10:49:51 +0100 |
commit | 8436ef8bdb96c0a977a15ec707d28404d97c3a6c (patch) | |
tree | 4af422951654f59fbd8e100892ecb21f3475c941 /crypto/property | |
parent | ee246234bf591cd2a9779a4ad3a2ee3c53848213 (diff) | |
download | openssl-8436ef8bdb96c0a977a15ec707d28404d97c3a6c.zip openssl-8436ef8bdb96c0a977a15ec707d28404d97c3a6c.tar.gz openssl-8436ef8bdb96c0a977a15ec707d28404d97c3a6c.tar.bz2 |
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 <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17881)
(cherry picked from commit 927d0566ded0dff9d6c5abc8a40bb84068446b76)
Diffstat (limited to 'crypto/property')
-rw-r--r-- | crypto/property/defn_cache.c | 17 | ||||
-rw-r--r-- | crypto/property/property.c | 20 | ||||
-rw-r--r-- | crypto/property/property_string.c | 19 |
3 files changed, 17 insertions, 39 deletions
diff --git a/crypto/property/defn_cache.c b/crypto/property/defn_cache.c index b4cd67c..c697e6f 100644 --- a/crypto/property/defn_cache.c +++ b/crypto/property/defn_cache.c @@ -15,6 +15,7 @@ #include "internal/property.h" #include "internal/core.h" #include "property_local.h" +#include "crypto/context.h" /* * Implement a property definition cache. @@ -47,7 +48,7 @@ static void property_defn_free(PROPERTY_DEFN_ELEM *elem) OPENSSL_free(elem); } -static void property_defns_free(void *vproperty_defns) +void ossl_property_defns_free(void *vproperty_defns) { LHASH_OF(PROPERTY_DEFN_ELEM) *property_defns = vproperty_defns; @@ -58,24 +59,17 @@ static void property_defns_free(void *vproperty_defns) } } -static void *property_defns_new(OSSL_LIB_CTX *ctx) { +void *ossl_property_defns_new(OSSL_LIB_CTX *ctx) { return lh_PROPERTY_DEFN_ELEM_new(&property_defn_hash, &property_defn_cmp); } -static const OSSL_LIB_CTX_METHOD property_defns_method = { - OSSL_LIB_CTX_METHOD_DEFAULT_PRIORITY, - property_defns_new, - property_defns_free, -}; - OSSL_PROPERTY_LIST *ossl_prop_defn_get(OSSL_LIB_CTX *ctx, const char *prop) { PROPERTY_DEFN_ELEM elem, *r; LHASH_OF(PROPERTY_DEFN_ELEM) *property_defns; property_defns = ossl_lib_ctx_get_data(ctx, - OSSL_LIB_CTX_PROPERTY_DEFN_INDEX, - &property_defns_method); + OSSL_LIB_CTX_PROPERTY_DEFN_INDEX); if (property_defns == NULL || !ossl_lib_ctx_read_lock(ctx)) return NULL; @@ -99,8 +93,7 @@ int ossl_prop_defn_set(OSSL_LIB_CTX *ctx, const char *prop, int res = 1; property_defns = ossl_lib_ctx_get_data(ctx, - OSSL_LIB_CTX_PROPERTY_DEFN_INDEX, - &property_defns_method); + OSSL_LIB_CTX_PROPERTY_DEFN_INDEX); if (property_defns == NULL) return 0; diff --git a/crypto/property/property.c b/crypto/property/property.c index 2c92cb5..fe00815 100644 --- a/crypto/property/property.c +++ b/crypto/property/property.c @@ -23,6 +23,7 @@ #include "crypto/lhash.h" #include "crypto/sparse_array.h" #include "property_local.h" +#include "crypto/context.h" /* * The number of elements in the query cache before we initiate a flush. @@ -107,7 +108,7 @@ static void ossl_method_cache_flush_alg(OSSL_METHOD_STORE *store, static void ossl_method_cache_flush(OSSL_METHOD_STORE *store, int nid); /* Global properties are stored per library context */ -static void ossl_ctx_global_properties_free(void *vglobp) +void ossl_ctx_global_properties_free(void *vglobp) { OSSL_GLOBAL_PROPERTIES *globp = vglobp; @@ -117,17 +118,11 @@ static void ossl_ctx_global_properties_free(void *vglobp) } } -static void *ossl_ctx_global_properties_new(OSSL_LIB_CTX *ctx) +void *ossl_ctx_global_properties_new(OSSL_LIB_CTX *ctx) { return OPENSSL_zalloc(sizeof(OSSL_GLOBAL_PROPERTIES)); } -static const OSSL_LIB_CTX_METHOD ossl_ctx_global_properties_method = { - OSSL_LIB_CTX_METHOD_DEFAULT_PRIORITY, - ossl_ctx_global_properties_new, - ossl_ctx_global_properties_free, -}; - OSSL_PROPERTY_LIST **ossl_ctx_global_properties(OSSL_LIB_CTX *libctx, int loadconfig) { @@ -137,8 +132,7 @@ OSSL_PROPERTY_LIST **ossl_ctx_global_properties(OSSL_LIB_CTX *libctx, if (loadconfig && !OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL)) return NULL; #endif - globp = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_GLOBAL_PROPERTIES, - &ossl_ctx_global_properties_method); + globp = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_GLOBAL_PROPERTIES); return globp != NULL ? &globp->list : NULL; } @@ -147,8 +141,7 @@ OSSL_PROPERTY_LIST **ossl_ctx_global_properties(OSSL_LIB_CTX *libctx, int ossl_global_properties_no_mirrored(OSSL_LIB_CTX *libctx) { OSSL_GLOBAL_PROPERTIES *globp - = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_GLOBAL_PROPERTIES, - &ossl_ctx_global_properties_method); + = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_GLOBAL_PROPERTIES); return globp != NULL && globp->no_mirrored ? 1 : 0; } @@ -156,8 +149,7 @@ int ossl_global_properties_no_mirrored(OSSL_LIB_CTX *libctx) void ossl_global_properties_stop_mirroring(OSSL_LIB_CTX *libctx) { OSSL_GLOBAL_PROPERTIES *globp - = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_GLOBAL_PROPERTIES, - &ossl_ctx_global_properties_method); + = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_GLOBAL_PROPERTIES); if (globp != NULL) globp->no_mirrored = 1; diff --git a/crypto/property/property_string.c b/crypto/property/property_string.c index 5a1f5cd..3f978c0 100644 --- a/crypto/property/property_string.c +++ b/crypto/property/property_string.c @@ -13,6 +13,7 @@ #include <openssl/lhash.h> #include "crypto/lhash.h" #include "property_local.h" +#include "crypto/context.h" /* * Property strings are a consolidation of all strings seen by the property @@ -72,7 +73,7 @@ static void property_table_free(PROP_TABLE **pt) } } -static void property_string_data_free(void *vpropdata) +void ossl_property_string_data_free(void *vpropdata) { PROPERTY_STRING_DATA *propdata = vpropdata; @@ -92,7 +93,7 @@ static void property_string_data_free(void *vpropdata) OPENSSL_free(propdata); } -static void *property_string_data_new(OSSL_LIB_CTX *ctx) { +void *ossl_property_string_data_new(OSSL_LIB_CTX *ctx) { PROPERTY_STRING_DATA *propdata = OPENSSL_zalloc(sizeof(*propdata)); if (propdata == NULL) @@ -114,18 +115,12 @@ static void *property_string_data_new(OSSL_LIB_CTX *ctx) { #endif || propdata->prop_names == NULL || propdata->prop_values == NULL) { - property_string_data_free(propdata); + ossl_property_string_data_free(propdata); return NULL; } return propdata; } -static const OSSL_LIB_CTX_METHOD property_string_data_method = { - OSSL_LIB_CTX_METHOD_DEFAULT_PRIORITY, - property_string_data_new, - property_string_data_free, -}; - static PROPERTY_STRING *new_property_string(const char *s, OSSL_PROPERTY_IDX *pidx) { @@ -151,8 +146,7 @@ static OSSL_PROPERTY_IDX ossl_property_string(OSSL_LIB_CTX *ctx, int name, PROP_TABLE *t; OSSL_PROPERTY_IDX *pidx; PROPERTY_STRING_DATA *propdata - = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_PROPERTY_STRING_INDEX, - &property_string_data_method); + = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_PROPERTY_STRING_INDEX); if (propdata == NULL) return 0; @@ -224,8 +218,7 @@ static const char *ossl_property_str(int name, OSSL_LIB_CTX *ctx, { const char *r; PROPERTY_STRING_DATA *propdata - = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_PROPERTY_STRING_INDEX, - &property_string_data_method); + = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_PROPERTY_STRING_INDEX); if (propdata == NULL) return NULL; |