summaryrefslogtreecommitdiffstats
path: root/crypto/dh/dh_key.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2014-10-30 23:58:19 +0000
committerMatt Caswell <matt@openssl.org>2014-12-08 21:40:32 +0000
commit829ccf6ab6aab03a3f60f644027b43a5d2035bf8 (patch)
tree69acbd4f87f729876a1ffc069ff89d983dab5dad /crypto/dh/dh_key.c
parent76b2a0227433af6c100aadf9a3df78ea4d52803a (diff)
Implement internally opaque bn access from dh
Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'crypto/dh/dh_key.c')
-rw-r--r--crypto/dh/dh_key.c18
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