aboutsummaryrefslogtreecommitdiff
path: root/crypto/rsa
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/rsa
parent7e708ebee066d0308a335579b546326220dc8317 (diff)
downloadopenssl-9b141126d4b6f0636bc047e81b846c193ae26611.zip
openssl-9b141126d4b6f0636bc047e81b846c193ae26611.tar.gz
openssl-9b141126d4b6f0636bc047e81b846c193ae26611.tar.bz2
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/rsa')
-rw-r--r--crypto/rsa/rsa_gen.c12
-rw-r--r--crypto/rsa/rsa_lib.c6
2 files changed, 10 insertions, 8 deletions
diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c
index 3ed6edd..95e636d 100644
--- a/crypto/rsa/rsa_gen.c
+++ b/crypto/rsa/rsa_gen.c
@@ -74,11 +74,12 @@ RSA *RSA_generate_key(int bits, unsigned long e_value,
if (ctx == NULL) goto err;
ctx2=BN_CTX_new();
if (ctx2 == NULL) goto err;
- r0= &(ctx->bn[0]);
- r1= &(ctx->bn[1]);
- r2= &(ctx->bn[2]);
- r3= &(ctx->bn[3]);
- ctx->tos+=4;
+ BN_CTX_start(ctx);
+ r0 = BN_CTX_get(ctx);
+ r1 = BN_CTX_get(ctx);
+ r2 = BN_CTX_get(ctx);
+ r3 = BN_CTX_get(ctx);
+ if (r3 == NULL) goto err;
bitsp=(bits+1)/2;
bitsq=bits-bitsp;
@@ -181,6 +182,7 @@ err:
RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
ok=0;
}
+ BN_CTX_end(ctx);
BN_CTX_free(ctx);
BN_CTX_free(ctx2);
diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c
index c6b1a59..074a4f5 100644
--- a/crypto/rsa/rsa_lib.c
+++ b/crypto/rsa/rsa_lib.c
@@ -269,19 +269,19 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
if (rsa->blinding != NULL)
BN_BLINDING_free(rsa->blinding);
- A= &(ctx->bn[0]);
- ctx->tos++;
+ BN_CTX_start(ctx);
+ A = BN_CTX_get(ctx);
if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
goto err;
rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n);
- ctx->tos--;
rsa->flags|=RSA_FLAG_BLINDING;
BN_free(Ai);
ret=1;
err:
+ BN_CTX_end(ctx);
if (ctx != p_ctx) BN_CTX_free(ctx);
return(ret);
}