1
0
mirror of https://github.com/wolfSSL/wolfssl.git synced 2026-10-24 04:09:07 +03:00

asn: bound explicit EC-domain A, B and order in every build

f608a41c56 bounds the explicit-parameter prime to MAX_ECC_BYTES in all
builds but A, B and the order only where WOLFSSL_ECC_CURVE_STATIC holds
them in fixed MAX_ECC_STRING buffers. Apply that bound in the dynamic
build too, so an explicit-parameter key decodes the same way however the
curve set is stored and the per-field regression tests exercise the
check in the default configuration. Field elements never exceed the
prime size, so the only key this refuses that the dynamic build took
before is one whose order is a byte wider than a prime already at
MAX_ECC_BYTES, which the static build refuses as well.
This commit is contained in:
jackctj117
2026-08-25 15:47:23 -06:00
parent 3a45cc02e6
commit eeb4b37cde

View File

@@ -34862,6 +34862,19 @@ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
ret = ASN_PARSE_E;
}
}
/* Parameters A, B and the order are bounded like the prime so decoding
* does not depend on how the curve set is stored (the static hex buffers
* hold at most MAX_ECC_BYTES). */
if ((ret == 0) &&
((dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.length >
(word32)MAX_ECC_BYTES) ||
(dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.length >
(word32)MAX_ECC_BYTES) ||
(dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.length >
(word32)MAX_ECC_BYTES))) {
WOLFSSL_MSG("ECC explicit domain parameter outside MAX_ECC_BYTES");
ret = ASN_PARSE_E;
}
if (ret == 0) {
/* Base point: 0x04 <x> <y> (must be uncompressed). */
GetASN_GetConstRef(&dataASN[ECCSPECIFIEDASN_IDX_BASE], &base,
@@ -34929,16 +34942,6 @@ static int EccSpecifiedECDomainDecode(const byte* input, word32 inSz,
}
#else
/* Hex strings are held in fixed size MAX_ECC_STRING buffers. */
if ((ret == 0) &&
((dataASN[ECCSPECIFIEDASN_IDX_PARAM_A].data.ref.length >
(word32)MAX_ECC_BYTES) ||
(dataASN[ECCSPECIFIEDASN_IDX_PARAM_B].data.ref.length >
(word32)MAX_ECC_BYTES) ||
(dataASN[ECCSPECIFIEDASN_IDX_ORDER].data.ref.length >
(word32)MAX_ECC_BYTES))) {
WOLFSSL_MSG("ECC explicit domain parameter too long for hex buffer");
ret = ASN_PARSE_E;
}
if (ret == 0) {
/* Base X-ordinate */
wc_DataToHexString(base + 1, (word32)curve->size, (char *)curve->Gx);