internal: shift, not divide, in the GEX check

mp_div_2() maps to sp_div_2(), which SP math compiles only for ECC, so
the safe-prime check in ValidateKexDhGexGroup() fails to link when RSA
and ECC are both off. mp_rshb() is unconditional and q is positive here,
so the two do the same thing.
pull/1257/head
John Safranek 2026-09-10 18:45:00 -07:00
parent f92bf647df
commit b92861492c
1 changed files with 6 additions and 2 deletions

View File

@ -9228,10 +9228,14 @@ static int ValidateKexDhGexGroup(const byte* primeGroup, word32 primeGroupSz,
}
}
/* Safe prime check: q = (p - 1) / 2 must also be prime. */
/* Safe prime check: q = (p - 1) / 2 must also be prime. mp_rshb() rather
* than mp_div_2(): the latter is an ECC-only entry point in SP math, and
* q is positive here, so the shift is the same operation. */
if (ret == WS_SUCCESS) {
if (mp_sub_d(&p, 1, &q) != MP_OKAY || mp_div_2(&q, &q) != MP_OKAY)
if (mp_sub_d(&p, 1, &q) != MP_OKAY)
ret = WS_CRYPTO_FAILED;
else
mp_rshb(&q, 1);
}
if (ret == WS_SUCCESS) {
isPrime = MP_NO;