From 9b141126d4b6f0636bc047e81b846c193ae26611 Mon Sep 17 00:00:00 2001 From: Ulf Möller Date: Sat, 5 Feb 2000 14:17:32 +0000 Subject: New functions BN_CTX_start(), BN_CTX_get(), BN_CTX_end() to access temporary BIGNUMs. BN_CTX still uses a fixed number of BIGNUMs, but the BN_CTX implementation could now easily be changed. --- crypto/bn/bn_exp2.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'crypto/bn/bn_exp2.c') diff --git a/crypto/bn/bn_exp2.c b/crypto/bn/bn_exp2.c index 2d7bf8997d..4f4e9e3299 100644 --- a/crypto/bn/bn_exp2.c +++ b/crypto/bn/bn_exp2.c @@ -35,15 +35,19 @@ int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2, BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); return(0); } - d= &(ctx->bn[ctx->tos++]); - r= &(ctx->bn[ctx->tos++]); bits1=BN_num_bits(p1); bits2=BN_num_bits(p2); if ((bits1 == 0) && (bits2 == 0)) { - BN_one(r); + BN_one(rr); return(1); } + + BN_CTX_start(ctx); + d = BN_CTX_get(ctx); + r = BN_CTX_get(ctx); + if (d == NULL || r == NULL) goto err; + bits=(bits1 > bits2)?bits1:bits2; /* If this is not done, things will break in the montgomery @@ -183,7 +187,7 @@ int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2, ret=1; err: if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); - ctx->tos-=2; + BN_CTX_end(ctx); for (i=0; i