curve25519: fix big-endian public-key order check operand

wc_curve25519_check_public's BIG_ENDIAN branch checked pub[i] != 0 in its
top-order boundary loop where the mirrored LITTLE_ENDIAN branch checks
pub[i] != 0xff. The field prime p = 2^255 - 19 has 0xff middle bytes, so
the != 0 test broke out on the first non-0xff byte and the near-prime
rejection was effectively non-functional for big-endian inputs. Match the
little-endian branch so out-of-range big-endian public keys are rejected.
This commit is contained in:
Daniele Lacamera
2026-07-10 08:37:02 +02:00
parent 69bf010918
commit 600880a0a4
+1 -1
View File
@@ -977,7 +977,7 @@ int wc_curve25519_check_public(const byte* pub, word32 pubSz, int endian)
/* Check for order-1 or higher. */
if (pub[0] == 0x7f) {
for (i = 1; i < CURVE25519_KEYSIZE - 1; i++) {
if (pub[i] != 0)
if (pub[i] != 0xff)
break;
}
if (i == CURVE25519_KEYSIZE - 1 && (pub[i] >= 0xec))