From eeb4b37cde6c327e3719fa652dabfe40de57cd10 Mon Sep 17 00:00:00 2001 From: jackctj117 Date: Tue, 25 Aug 2026 15:47:23 -0600 Subject: [PATCH] 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. --- wolfcrypt/src/asn.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 1972d89658..c7ec34b417 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -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 (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);