summaryrefslogtreecommitdiffstats
path: root/test/dhtest.c
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2023-07-25 15:23:43 +0200
committerTodd Short <todd.short@me.com>2023-07-27 09:48:22 -0400
commitad5d35572695d7b5748b2bd4fb1afaa189b29e28 (patch)
tree3167aa6d7238e72af2e33b97241131752560acb4 /test/dhtest.c
parent1c16253f3c3a8d1e25918c3f404aae6a5b0893de (diff)
dhtest.c: Add test of DH_check() with q = p + 1
This must fail with DH_CHECK_INVALID_Q_VALUE and with DH_CHECK_Q_NOT_PRIME unset. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Todd Short <todd.short@me.com> (Merged from https://github.com/openssl/openssl/pull/21550)
Diffstat (limited to 'test/dhtest.c')
-rw-r--r--test/dhtest.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/dhtest.c b/test/dhtest.c
index 9ebc7c4e59..14b00f0d3d 100644
--- a/test/dhtest.c
+++ b/test/dhtest.c
@@ -124,6 +124,15 @@ static int dh_test(void)
/* We'll have a stale error on the queue from the above test so clear it */
ERR_clear_error();
+ if (!TEST_ptr(BN_copy(q, p)) || !TEST_true(BN_add(q, q, BN_value_one())))
+ goto err3;
+
+ if (!TEST_true(DH_check(dh, &i)))
+ goto err3;
+ if (!TEST_true(i & DH_CHECK_INVALID_Q_VALUE)
+ || !TEST_false(i & DH_CHECK_Q_NOT_PRIME))
+ goto err3;
+
/* 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)))
@@ -135,6 +144,9 @@ static int dh_test(void)
if (!TEST_false(DH_check(dh, &i)))
goto err3;
+ /* We'll have a stale error on the queue from the above test so clear it */
+ ERR_clear_error();
+
/*
* II) key generation
*/