From b92861492c903d3eb13a95827fc111e88a0daf10 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 10 Sep 2026 18:45:00 -0700 Subject: [PATCH] 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. --- src/internal.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index a0ca2ab9..a6bfd0fa 100644 --- a/src/internal.c +++ b/src/internal.c @@ -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;