Skip to content

Commit

Permalink
Add a test for CVE-2023-3446
Browse files Browse the repository at this point in the history
Confirm that the only errors DH_check() finds with DH parameters with an
excessively long modulus is that the modulus is too large. We should not
be performing time consuming checks using that modulus.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21451)
  • Loading branch information
mattcaswell authored and t8m committed Jul 19, 2023
1 parent 9e0094e commit ede782b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test/dhtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static int dh_test(void)
goto err1;

/* check fails, because p is way too small */
if (!DH_check(dh, &i))
if (!TEST_true(DH_check(dh, &i)))
goto err2;
i ^= DH_MODULUS_TOO_SMALL;
if (!TEST_false(i & DH_CHECK_P_NOT_PRIME)
Expand Down Expand Up @@ -124,6 +124,17 @@ static int dh_test(void)
/* We'll have a stale error on the queue from the above test so clear it */
ERR_clear_error();

/* Modulus of size: dh check max modulus bits + 1 */
if (!TEST_true(BN_set_word(p, 1))
|| !TEST_true(BN_lshift(p, p, OPENSSL_DH_CHECK_MAX_MODULUS_BITS)))
goto err3;

/*
* We expect no checks at all for an excessively large modulus
*/
if (!TEST_false(DH_check(dh, &i)))
goto err3;

/*
* II) key generation
*/
Expand All @@ -138,7 +149,7 @@ static int dh_test(void)
goto err3;

/* ... and check whether it is valid */
if (!DH_check(a, &i))
if (!TEST_true(DH_check(a, &i)))
goto err3;
if (!TEST_false(i & DH_CHECK_P_NOT_PRIME)
|| !TEST_false(i & DH_CHECK_P_NOT_SAFE_PRIME)
Expand Down

0 comments on commit ede782b

Please sign in to comment.