summaryrefslogtreecommitdiffstats
path: root/crypto/rand
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2022-03-14 08:13:12 +0000
committerPauli <pauli@openssl.org>2022-04-01 10:49:19 +1100
commit927d0566ded0dff9d6c5abc8a40bb84068446b76 (patch)
treec6d898a04aaa2062c9a74cb9c89ce25fa9680a41 /crypto/rand
parent9c140a33663f319ad4000a6a985c3e14297c7389 (diff)
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)
Diffstat (limited to 'crypto/rand')
-rw-r--r--crypto/rand/rand_lib.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c
index c772bcc79c..79f5ce322b 100644
--- a/crypto/rand/rand_lib.c
+++ b/crypto/rand/rand_lib.c
@@ -18,6 +18,7 @@
#include "crypto/rand.h"
#include "crypto/cryptlib.h"
#include "rand_local.h"
+#include "crypto/context.h"
#ifndef FIPS_MODULE
# include <stdio.h>
@@ -434,7 +435,7 @@ typedef struct rand_global_st {
* Initialize the OSSL_LIB_CTX global DRBGs on first use.
* Returns the allocated global data on success or NULL on failure.
*/
-static void *rand_ossl_ctx_new(OSSL_LIB_CTX *libctx)
+void *ossl_rand_ctx_new(OSSL_LIB_CTX *libctx)
{
RAND_GLOBAL *dgbl = OPENSSL_zalloc(sizeof(*dgbl));
@@ -469,7 +470,7 @@ static void *rand_ossl_ctx_new(OSSL_LIB_CTX *libctx)
return NULL;
}
-static void rand_ossl_ctx_free(void *vdgbl)
+void ossl_rand_ctx_free(void *vdgbl)
{
RAND_GLOBAL *dgbl = vdgbl;
@@ -491,16 +492,9 @@ static void rand_ossl_ctx_free(void *vdgbl)
OPENSSL_free(dgbl);
}
-static const OSSL_LIB_CTX_METHOD rand_drbg_ossl_ctx_method = {
- OSSL_LIB_CTX_METHOD_PRIORITY_2,
- rand_ossl_ctx_new,
- rand_ossl_ctx_free,
-};
-
static RAND_GLOBAL *rand_get_global(OSSL_LIB_CTX *libctx)
{
- return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_DRBG_INDEX,
- &rand_drbg_ossl_ctx_method);
+ return ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_DRBG_INDEX);
}
static void rand_delete_thread_state(void *arg)