Skip to content

Commit 3984ef0

Browse files
guidovrankenmattcaswell
authored andcommitted
Reject excessively large primes in DH key generation.
CVE-2018-0732 Signed-off-by: Guido Vranken <guidovranken@gmail.com> (cherry picked from commit 91f7361) Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from #6457)
1 parent bd45a8d commit 3984ef0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crypto/dh/dh_key.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,15 @@ static int generate_key(DH *dh)
130130
int ok = 0;
131131
int generate_new_key = 0;
132132
unsigned l;
133-
BN_CTX *ctx;
133+
BN_CTX *ctx = NULL;
134134
BN_MONT_CTX *mont = NULL;
135135
BIGNUM *pub_key = NULL, *priv_key = NULL;
136136

137+
if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
138+
DHerr(DH_F_GENERATE_KEY, DH_R_MODULUS_TOO_LARGE);
139+
return 0;
140+
}
141+
137142
ctx = BN_CTX_new();
138143
if (ctx == NULL)
139144
goto err;

0 commit comments

Comments
 (0)