Skip to content

Commit 1c16253

Browse files
t8mtmshort
authored andcommitted
DH_check(): Do not try checking q properties if it is obviously invalid
If |q| >= |p| then the q value is obviously wrong as q is supposed to be a prime divisor of p-1. We check if p is overly large so this added test implies that q is not large either when performing subsequent tests using that q value. Otherwise if it is too large these additional checks of the q value such as the primality test can then trigger DoS by doing overly long computations. Fixes CVE-2023-3817 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 #21550)
1 parent 81d10e6 commit 1c16253

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

crypto/dh/dh_check.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int DH_check(const DH *dh, int *ret)
143143
#ifdef FIPS_MODULE
144144
return DH_check_params(dh, ret);
145145
#else
146-
int ok = 0, r;
146+
int ok = 0, r, q_good = 0;
147147
BN_CTX *ctx = NULL;
148148
BIGNUM *t1 = NULL, *t2 = NULL;
149149
int nid = DH_get_nid((DH *)dh);
@@ -172,6 +172,13 @@ int DH_check(const DH *dh, int *ret)
172172
goto err;
173173

174174
if (dh->params.q != NULL) {
175+
if (BN_ucmp(dh->params.p, dh->params.q) > 0)
176+
q_good = 1;
177+
else
178+
*ret |= DH_CHECK_INVALID_Q_VALUE;
179+
}
180+
181+
if (q_good) {
175182
if (BN_cmp(dh->params.g, BN_value_one()) <= 0)
176183
*ret |= DH_NOT_SUITABLE_GENERATOR;
177184
else if (BN_cmp(dh->params.g, dh->params.p) >= 0)

0 commit comments

Comments
 (0)