summaryrefslogtreecommitdiffstats
path: root/crypto/dh
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2011-11-14 14:16:09 +0000
committerDr. Stephen Henson <steve@openssl.org>2011-11-14 14:16:09 +0000
commit5999d45a5d390c610ff5acf13b81bd0d1797ecd8 (patch)
tree7cc66cedd865e5ac5ac82247f6c965995a897efb /crypto/dh
parentf69e5d6a1950b69fcae6ba1cc2b1c3a3b0171989 (diff)
DH keys have an (until now) unused 'q' parameter. When creating from DSA copy
q across and if q present generate DH key in the correct range. (from HEAD)
Diffstat (limited to 'crypto/dh')
-rw-r--r--crypto/dh/dh_key.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c
index dd4cd6b593..89a74db4e6 100644
--- a/crypto/dh/dh_key.c
+++ b/crypto/dh/dh_key.c
@@ -154,8 +154,21 @@ static int generate_key(DH *dh)
if (generate_new_key)
{
- l = dh->length ? dh->length : BN_num_bits(dh->p)-1; /* secret exponent length */
- if (!BN_rand(priv_key, l, 0, 0)) goto err;
+ if (dh->q)
+ {
+ do
+ {
+ if (!BN_rand_range(priv_key, dh->q))
+ goto err;
+ }
+ while (BN_is_zero(priv_key) || BN_is_one(priv_key));
+ }
+ else
+ {
+ /* secret exponent length */
+ l = dh->length ? dh->length : BN_num_bits(dh->p)-1;
+ if (!BN_rand(priv_key, l, 0, 0)) goto err;
+ }
}
{