From 567cd155ea584ed417e8b81d7f379c09e651da39 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Tue, 30 Nov 2021 14:08:07 +1000 Subject: [PATCH] ECC wc_ecc_point_is_on_curve: validate oridinates against prime --- wolfcrypt/src/ecc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index f4c27d5b0..862c98957 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -4349,6 +4349,23 @@ int wc_ecc_point_is_on_curve(ecc_point *p, int curve_idx) ECC_CURVE_FIELD_PRIME | ECC_CURVE_FIELD_AF | ECC_CURVE_FIELD_BF); } + + /* x must be in the range [0, p-1] */ + if (err == MP_OKAY) { + if (mp_cmp(p->x, curve->prime) != MP_LT) + err = ECC_OUT_OF_RANGE_E; + } + /* y must be in the range [0, p-1] */ + if (err == MP_OKAY) { + if (mp_cmp(p->y, curve->prime) != MP_LT) + err = ECC_OUT_OF_RANGE_E; + } + /* z must be 1 */ + if (err == MP_OKAY) { + if (!mp_isone(p->z)) + err = ECC_BAD_ARG_E; + } + if (err == MP_OKAY) { err = wc_ecc_is_point(p, curve->Af, curve->Bf, curve->prime); }