aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/bn/bn_mont.c
diff options
context:
space:
mode:
authorUlf Möller <ulf@openssl.org>2000-02-05 14:17:32 +0000
committerUlf Möller <ulf@openssl.org>2000-02-05 14:17:32 +0000
commit9b141126d4b6f0636bc047e81b846c193ae26611 (patch)
treec8786c99bfccc8b9899cad5c3aa30f29ada5e1b9 /crypto/bn/bn_mont.c
parent7e708ebee066d0308a335579b546326220dc8317 (diff)
downloadopenssl-9b141126d4b6f0636bc047e81b846c193ae26611.tar.gz
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.
Diffstat (limited to 'crypto/bn/bn_mont.c')
-rw-r--r--crypto/bn/bn_mont.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c
index dd691112c2..35a30a0eeb 100644
--- a/crypto/bn/bn_mont.c
+++ b/crypto/bn/bn_mont.c
@@ -72,9 +72,10 @@ int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
{
BIGNUM *tmp,*tmp2;
- tmp= &(ctx->bn[ctx->tos]);
- tmp2= &(ctx->bn[ctx->tos]);
- ctx->tos+=2;
+ BN_CTX_start(ctx);
+ tmp = BN_CTX_get(ctx);
+ tmp2 = BN_CTX_get(ctx);
+ if (tmp == NULL || tmp2 == NULL) goto err;
bn_check_top(tmp);
bn_check_top(tmp2);
@@ -98,16 +99,20 @@ int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
}
/* reduce from aRR to aR */
if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
- ctx->tos-=2;
+ BN_CTX_end(ctx);
return(1);
err:
return(0);
}
+#define BN_RECURSION_MONT
+
int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
BN_CTX *ctx)
{
int retn=0;
+ BN_CTX_start(ctx);
+
#ifdef BN_RECURSION_MONT
if (mont->use_word)
#endif
@@ -116,7 +121,7 @@ int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
BN_ULONG *ap,*np,*rp,n0,v,*nrp;
int al,nl,max,i,x,ri;
- r= &(ctx->bn[ctx->tos]);
+ if ((r = BN_CTX_get(ctx)) == NULL) goto err;
if (!BN_copy(r,a)) goto err;
n= &(mont->N);
@@ -210,9 +215,9 @@ printf("word BN_from_montgomery %d * %d\n",nl,nl);
{
BIGNUM *t1,*t2;
- t1=&(ctx->bn[ctx->tos]);
- t2=&(ctx->bn[ctx->tos+1]);
- ctx->tos+=2;
+ t1 = BN_CTX_get(ctx);
+ t2 = BN_CTX_get(ctx);
+ if (t1 == NULL || t2 == NULL) goto err;
if (!BN_copy(t1,a)) goto err;
BN_mask_bits(t1,mont->ri);
@@ -226,11 +231,11 @@ printf("word BN_from_montgomery %d * %d\n",nl,nl);
if (BN_ucmp(ret,&mont->N) >= 0)
BN_usub(ret,ret,&mont->N);
- ctx->tos-=2;
retn=1;
}
#endif
err:
+ BN_CTX_end(ctx);
return(retn);
}