diff options
author | Richard Levitte <levitte@openssl.org> | 2020-10-15 07:14:16 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-10-27 15:13:54 +0100 |
commit | 28e1d588f14404d480cc2bd38827ecd587625643 (patch) | |
tree | d694b95a240cf667d496aea5944137b2a770aeed /crypto/dh/dh_key.c | |
parent | 09803e9ce3a8a555e7014ebd11b4c80f9d300cf0 (diff) |
DH: stop setting the private key length arbitrarily
The private key length is supposed to be a user settable parameter.
We do check if it's set or not, and if not, we do apply defaults.
Fixes #12071
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13140)
Diffstat (limited to 'crypto/dh/dh_key.c')
-rw-r--r-- | crypto/dh/dh_key.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 90802633a6..930b33a33b 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -277,7 +277,10 @@ static int generate_key(DH *dh) goto err; #else if (dh->params.q == NULL) { - /* secret exponent length */ + /* secret exponent length, must satisfy 2^(l-1) <= p */ + if (dh->length != 0 + && dh->length >= BN_num_bits(dh->params.p)) + goto err; l = dh->length ? dh->length : BN_num_bits(dh->params.p) - 1; if (!BN_priv_rand_ex(priv_key, l, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY, ctx)) |