From 9b141126d4b6f0636bc047e81b846c193ae26611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulf=20M=C3=B6ller?= 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/dh/dh_gen.c | 13 +++++++++---- crypto/dh/dh_key.c | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'crypto/dh') diff --git a/crypto/dh/dh_gen.c b/crypto/dh/dh_gen.c index f0ee43ed87..7a6a38fbb4 100644 --- a/crypto/dh/dh_gen.c +++ b/crypto/dh/dh_gen.c @@ -95,9 +95,10 @@ DH *DH_generate_parameters(int prime_len, int generator, if (ret == NULL) goto err; ctx=BN_CTX_new(); if (ctx == NULL) goto err; - t1= &(ctx->bn[0]); - t2= &(ctx->bn[1]); - ctx->tos=2; + BN_CTX_start(ctx); + t1 = BN_CTX_get(ctx); + t2 = BN_CTX_get(ctx); + if (t1 == NULL || t2 == NULL) goto err; if (generator == DH_GENERATOR_2) { @@ -138,7 +139,11 @@ err: ok=0; } - if (ctx != NULL) BN_CTX_free(ctx); + if (ctx != NULL) + { + BN_CTX_end(ctx); + BN_CTX_free(ctx); + } if (!ok && (ret != NULL)) { DH_free(ret); diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 4e6a0fc0ef..0c7eeaf260 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -161,7 +161,8 @@ static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh) int ret= -1; BN_CTX_init(&ctx); - tmp= &(ctx.bn[ctx.tos++]); + BN_CTX_start(&ctx); + tmp = BN_CTX_get(&ctx); if (dh->priv_key == NULL) { @@ -184,6 +185,7 @@ static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh) ret=BN_bn2bin(tmp,key); err: + BN_CTX_end(&ctx); BN_CTX_free(&ctx); return(ret); } -- cgit v1.2.3