summaryrefslogtreecommitdiff
path: root/crypto/context.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2019-05-28 15:58:08 +0100
committerMatt Caswell <matt@openssl.org>2019-06-17 15:32:54 +0100
commitd4c051cef338eecf092affbb479d1f87c1ea31d9 (patch)
treedf622ee097f1fcb54b324ac672abab3e64207649 /crypto/context.c
parent30478c97837a026ba56718f98d490adf7bce2760 (diff)
downloadopenssl-new-d4c051cef338eecf092affbb479d1f87c1ea31d9.tar.gz
Add the function openssl_ctx_get_concrete()
This adds the ability to take an OPENSSL_CTX parameter and either return it as is (unchanged), or if it is NULL return a pointer to the default ctx. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9040)
Diffstat (limited to 'crypto/context.c')
-rw-r--r--crypto/context.c49
1 files changed, 16 insertions, 33 deletions
diff --git a/crypto/context.c b/crypto/context.c
index 7a976c0270..d441c8b4e5 100644
--- a/crypto/context.c
+++ b/crypto/context.c
@@ -129,6 +129,18 @@ void OPENSSL_CTX_free(OPENSSL_CTX *ctx)
OPENSSL_free(ctx);
}
+OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx)
+{
+#ifndef FIPS_MODE
+ if (ctx == NULL) {
+ if (!RUN_ONCE(&default_context_init, do_default_context_init))
+ return 0;
+ return default_context;
+ }
+#endif
+ return ctx;
+}
+
static void openssl_ctx_generic_new(void *parent_ign, void *ptr_ign,
CRYPTO_EX_DATA *ad, int index,
long argl_ign, void *argp)
@@ -154,13 +166,7 @@ static int openssl_ctx_init_index(OPENSSL_CTX *ctx, int static_index,
{
int idx;
-#ifndef FIPS_MODE
- if (ctx == NULL) {
- if (!RUN_ONCE(&default_context_init, do_default_context_init))
- return 0;
- ctx = default_context;
- }
-#endif
+ ctx = openssl_ctx_get_concrete(ctx);
if (ctx == NULL)
return 0;
@@ -180,13 +186,7 @@ void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,
{
void *data = NULL;
-#ifndef FIPS_MODE
- if (ctx == NULL) {
- if (!RUN_ONCE(&default_context_init, do_default_context_init))
- return NULL;
- ctx = default_context;
- }
-#endif
+ ctx = openssl_ctx_get_concrete(ctx);
if (ctx == NULL)
return NULL;
@@ -210,18 +210,7 @@ void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,
OSSL_EX_DATA_GLOBAL *openssl_ctx_get_ex_data_global(OPENSSL_CTX *ctx)
{
- /*
- * The default context code is not needed in FIPS_MODE and ctx should never
- * be NULL in the FIPS provider. However we compile this code out to ensure
- * we fail immediately if ctx == NULL in FIPS_MODE
- */
-#ifndef FIPS_MODE
- if (ctx == NULL) {
- if (!RUN_ONCE(&default_context_init, do_default_context_init))
- return NULL;
- ctx = default_context;
- }
-#endif
+ ctx = openssl_ctx_get_concrete(ctx);
if (ctx == NULL)
return NULL;
return &ctx->global;
@@ -232,13 +221,7 @@ int openssl_ctx_run_once(OPENSSL_CTX *ctx, unsigned int idx,
{
int done = 0, ret = 0;
-#ifndef FIPS_MODE
- if (ctx == NULL) {
- if (!RUN_ONCE(&default_context_init, do_default_context_init))
- return 0;
- ctx = default_context;
- }
-#endif
+ ctx = openssl_ctx_get_concrete(ctx);
if (ctx == NULL)
return 0;