aboutsummaryrefslogtreecommitdiff
path: root/crypto/bn/bn_ctx.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2019-05-29 17:03:53 +0100
committerMatt Caswell <matt@openssl.org>2019-06-12 09:16:43 +0100
commit7bc081dda349a3473154d31f6094ee34545c4980 (patch)
treee33161063ffaa3dfe74c878191fa71800e968532 /crypto/bn/bn_ctx.c
parentf35819d1b7e195af9a41d991db00655f6f2c0af3 (diff)
downloadopenssl-7bc081dda349a3473154d31f6094ee34545c4980.zip
openssl-7bc081dda349a3473154d31f6094ee34545c4980.tar.gz
openssl-7bc081dda349a3473154d31f6094ee34545c4980.tar.bz2
Create BN_CTX_new_ex() and BN_CTX_secure_new_ex()
These variants of BN_CTX_new() and BN_CTX_secure_new() enable passing an OPENSSL_CTX so that we can access this where needed throughout the BIGNUM sub library. Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/9130)
Diffstat (limited to 'crypto/bn/bn_ctx.c')
-rw-r--r--crypto/bn/bn_ctx.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/crypto/bn/bn_ctx.c b/crypto/bn/bn_ctx.c
index 62e29b5..4857661 100644
--- a/crypto/bn/bn_ctx.c
+++ b/crypto/bn/bn_ctx.c
@@ -86,6 +86,8 @@ struct bignum_ctx {
int too_many;
/* Flags. */
int flags;
+ /* The library context */
+ OPENSSL_CTX *libctx;
};
/* Debugging functionality */
@@ -121,30 +123,40 @@ static void ctxdbg(BIO *channel, const char *text, BN_CTX *ctx)
ctxdbg(trc_out, str, ctx); \
} OSSL_TRACE_END(BN_CTX)
-
-BN_CTX *BN_CTX_new(void)
+BN_CTX *BN_CTX_new_ex(OPENSSL_CTX *ctx)
{
BN_CTX *ret;
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
- BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);
+ BNerr(BN_F_BN_CTX_NEW_EX, ERR_R_MALLOC_FAILURE);
return NULL;
}
/* Initialise the structure */
BN_POOL_init(&ret->pool);
BN_STACK_init(&ret->stack);
+ ret->libctx = ctx;
return ret;
}
-BN_CTX *BN_CTX_secure_new(void)
+BN_CTX *BN_CTX_new(void)
{
- BN_CTX *ret = BN_CTX_new();
+ return BN_CTX_new_ex(NULL);
+}
+
+BN_CTX *BN_CTX_secure_new_ex(OPENSSL_CTX *ctx)
+{
+ BN_CTX *ret = BN_CTX_new_ex(ctx);
if (ret != NULL)
ret->flags = BN_FLG_SECURE;
return ret;
}
+BN_CTX *BN_CTX_secure_new(void)
+{
+ return BN_CTX_secure_new_ex(NULL);
+}
+
void BN_CTX_free(BN_CTX *ctx)
{
if (ctx == NULL)