diff options
author | Cesar Pereida <cesar.pereida@aalto.fi> | 2016-06-07 11:32:23 +0300 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-06-07 15:26:57 +0100 |
commit | 033dc8fad03a23f650e347204446c882bcadcfdf (patch) | |
tree | 6c27a9e2b3400b3157075defdaae6683024a0b59 | |
parent | 35ea640a01e3bdeaf8086aba7f05b40c11538f8f (diff) |
Remove kq and set BN_FLG_CONSTTIME in k for BN_mod_inverse
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
-rw-r--r-- | crypto/dsa/dsa_ossl.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c index ea09afd953..81c5239869 100644 --- a/crypto/dsa/dsa_ossl.c +++ b/crypto/dsa/dsa_ossl.c @@ -135,7 +135,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, const unsigned char *dgst, int dlen) { BN_CTX *ctx = NULL; - BIGNUM *k, *kq, *kinv = NULL, *r = *rp; + BIGNUM *k, *kinv = NULL, *r = *rp; int ret = 0; if (!dsa->p || !dsa->q || !dsa->g) { @@ -144,8 +144,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, } k = BN_new(); - kq = BN_new(); - if (k == NULL || kq == NULL) + if (k == NULL) goto err; if (ctx_in == NULL) { @@ -176,9 +175,6 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, /* Compute r = (g^k mod p) mod q */ - if (!BN_copy(kq, k)) - goto err; - /* * We do not want timing information to leak the length of k, so we * compute g^k using an equivalent exponent of fixed length. (This @@ -186,21 +182,21 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, * let us specify the desired timing behaviour.) */ - if (!BN_add(kq, kq, dsa->q)) + if (!BN_add(k, k, dsa->q)) goto err; - if (BN_num_bits(kq) <= BN_num_bits(dsa->q)) { - if (!BN_add(kq, kq, dsa->q)) + if (BN_num_bits(k) <= BN_num_bits(dsa->q)) { + if (!BN_add(k, k, dsa->q)) goto err; } - BN_set_flags(kq, BN_FLG_CONSTTIME); + BN_set_flags(k, BN_FLG_CONSTTIME); if ((dsa)->meth->bn_mod_exp != NULL) { - if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, kq, dsa->p, ctx, + if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p)) goto err; } else { - if (!BN_mod_exp_mont(r, dsa->g, kq, dsa->p, ctx, dsa->method_mont_p)) + if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p)) goto err; } @@ -222,7 +218,6 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, if (ctx != ctx_in) BN_CTX_free(ctx); BN_clear_free(k); - BN_clear_free(kq); return ret; } |