diff options
author | Čestmír Kalina <ckalina@redhat.com> | 2021-09-27 22:42:11 +0200 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2022-10-17 09:45:39 +0100 |
commit | 4574a7fd8dda070b129d76defca07703cab53842 (patch) | |
tree | a6e03446b0f784e550010a2c51efe5b7861e9473 /crypto/context.c | |
parent | b1372197496650c3cb318cade911a3bd6af14adc (diff) |
crypto: add preemptive threading support
Some primitives are designed to be used in a multi-threaded environment,
if supported, e.g., Argon2.
This patch adds support for preemptive threading and basic synchronization
primitives for platforms compliant with POSIX threads or Windows CRT.
Native functions are wrapped to provide a common (internal) API.
Threading support can be disabled at compile time. If enabled, threading
is disabled by default and needs to be explicitly enabled by the user.
Thread enablement requires an explicit limit on the number of threads that
OpenSSL may spawn (non-negative integer/infinity). The limit may be changed.
Signed-off-by: Čestmír Kalina <ckalina@redhat.com>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12255)
Diffstat (limited to 'crypto/context.c')
-rw-r--r-- | crypto/context.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crypto/context.c b/crypto/context.c index aec9ecd4ac..a7b1832cbc 100644 --- a/crypto/context.c +++ b/crypto/context.c @@ -37,6 +37,9 @@ struct ossl_lib_ctx_st { OSSL_METHOD_STORE *store_loader_store; void *self_test_cb; #endif +#if defined(OPENSSL_THREADS) + void *threads; +#endif void *rand_crngt; #ifdef FIPS_MODULE void *thread_event_handler; @@ -171,6 +174,12 @@ static int context_init(OSSL_LIB_CTX *ctx) goto err; #endif +#if defined(OPENSSL_THREADS) + ctx->threads = ossl_threads_ctx_new(ctx); + if (ctx->threads == NULL) + goto err; +#endif + /* Low priority. */ #ifndef FIPS_MODULE ctx->child_provider = ossl_child_prov_ctx_new(ctx); @@ -299,6 +308,13 @@ static void context_deinit_objs(OSSL_LIB_CTX *ctx) } #endif +#if defined(OPENSSL_THREADS) + if (ctx->threads != NULL) { + ossl_threads_ctx_free(ctx->threads); + ctx->threads = NULL; + } +#endif + /* Low priority. */ #ifndef FIPS_MODULE if (ctx->child_provider != NULL) { @@ -526,6 +542,10 @@ void *ossl_lib_ctx_get_data(OSSL_LIB_CTX *ctx, int index) case OSSL_LIB_CTX_SELF_TEST_CB_INDEX: return ctx->self_test_cb; #endif +#if defined(OPENSSL_THREADS) + case OSSL_LIB_CTX_THREAD_INDEX: + return ctx->threads; +#endif case OSSL_LIB_CTX_RAND_CRNGT_INDEX: { |