From 4592f1a5b418dec7e406acb548ba8e4e820ea48c Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Mon, 23 Jan 2023 10:02:14 +1000 Subject: [PATCH] EC scalar mult with SP Math: fix scalar length check The support curves in SP all have an order length the same as modulus length. The scalar cannot be larger than the order and so fix the check. --- wolfcrypt/src/ecc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 9e34611ee..78e9db37c 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -3465,8 +3465,10 @@ exit: (void)a; - /* k can't have more bits than modulus count plus 1 */ - if (mp_count_bits(k) > mp_count_bits(modulus) + 1) { + /* For supported curves the order is the same length in bits as the modulus. + * Can't have more than order bits for the scalar. + */ + if (mp_count_bits(k) > mp_count_bits(modulus)) { return ECC_OUT_OF_RANGE_E; } if (mp_count_bits(G->x) > mp_count_bits(modulus) ||