diff options
Diffstat (limited to 'crypto/dh/dh_key.c')
-rw-r--r-- | crypto/dh/dh_key.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 584a33fd1e..d8eecde9b4 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -60,9 +60,9 @@ #include <stdio.h> #include "cryptlib.h" -#include <openssl/bn.h> #include <openssl/rand.h> #include <openssl/dh.h> +#include "internal/bn_int.h" static int generate_key(DH *dh); static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh); @@ -173,19 +173,23 @@ static int generate_key(DH *dh) } { - BIGNUM local_prk; + BIGNUM *local_prk = NULL; BIGNUM *prk; if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) { - BN_init(&local_prk); - prk = &local_prk; + local_prk = prk = BN_new(); BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); } else prk = priv_key; - if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) goto err; + if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) + { + if(local_prk) BN_free(local_prk); + goto err; + } + if(local_prk) BN_free(local_prk); } dh->pub_key=pub_key; @@ -269,9 +273,9 @@ static int dh_bn_mod_exp(const DH *dh, BIGNUM *r, /* If a is only one word long and constant time is false, use the faster * exponenentiation function. */ - if (a->top == 1 && ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) != 0)) + if (bn_get_top(a) == 1 && ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) != 0)) { - BN_ULONG A = a->d[0]; + BN_ULONG A = bn_get_words(a)[0]; return BN_mod_exp_mont_word(r,A,p,m,ctx,m_ctx); } else |