From 4e88521a90861ba14cb988096d5989c02a783296 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Thu, 27 May 2021 11:08:05 +1000 Subject: [PATCH] SP C ECC: mont sub - always normalize after sub before check for add --- wolfcrypt/src/sp_c32.c | 2 ++ wolfcrypt/src/sp_c64.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/wolfcrypt/src/sp_c32.c b/wolfcrypt/src/sp_c32.c index 510725786..f1d41aafe 100644 --- a/wolfcrypt/src/sp_c32.c +++ b/wolfcrypt/src/sp_c32.c @@ -13693,6 +13693,7 @@ static void sp_256_mont_sub_10(sp_digit* r, const sp_digit* a, const sp_digit* b const sp_digit* m) { (void)sp_256_sub_10(r, a, b); + sp_256_norm_10(r); sp_256_cond_add_10(r, r, m, r[9] >> 22); sp_256_norm_10(r); } @@ -20803,6 +20804,7 @@ static void sp_384_mont_sub_15(sp_digit* r, const sp_digit* a, const sp_digit* b const sp_digit* m) { (void)sp_384_sub_15(r, a, b); + sp_384_norm_15(r); sp_384_cond_add_15(r, r, m, r[14] >> 20); sp_384_norm_15(r); } diff --git a/wolfcrypt/src/sp_c64.c b/wolfcrypt/src/sp_c64.c index 6174a8312..2669c4287 100644 --- a/wolfcrypt/src/sp_c64.c +++ b/wolfcrypt/src/sp_c64.c @@ -13576,6 +13576,7 @@ static void sp_256_mont_sub_5(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m) { (void)sp_256_sub_5(r, a, b); + sp_256_norm_5(r); sp_256_cond_add_5(r, r, m, r[4] >> 48); sp_256_norm_5(r); } @@ -20205,6 +20206,7 @@ static void sp_384_mont_sub_7(sp_digit* r, const sp_digit* a, const sp_digit* b, const sp_digit* m) { (void)sp_384_sub_7(r, a, b); + sp_384_norm_7(r); sp_384_cond_add_7(r, r, m, r[6] >> 54); sp_384_norm_7(r); } @@ -27890,6 +27892,7 @@ static void sp_1024_mont_sub_18(sp_digit* r, const sp_digit* a, const sp_digit* const sp_digit* m) { (void)sp_1024_sub_18(r, a, b); + sp_1024_norm_18(r); sp_1024_cond_add_18(r, r, m, r[17] >> 55); sp_1024_norm_18(r); }