From a20db0b8ad3ea088188c2229fbb6ed82e92730af Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Thu, 21 Nov 2019 09:26:36 +1000 Subject: [PATCH] Fix sp_add to handle carries properly --- wolfcrypt/src/sp_int.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index 063d10c17..9e9b99530 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -569,7 +569,7 @@ int sp_sub(sp_int* a, sp_int* b, sp_int* r) } for (; i < a->used; i++) { r->dp[i] = a->dp[i] - c; - c = r->dp[i] == (sp_int_digit)-1; + c = (a->dp[i] == 0) && (r->dp[i] == (sp_int_digit)-1); } r->used = i; sp_clamp(r); @@ -829,11 +829,11 @@ int sp_add(sp_int* a, sp_int* b, sp_int* r) } for (; i < a->used; i++) { r->dp[i] = a->dp[i] + c; - c = r->dp[i] == 0; + c = (a->dp[i] != 0) && (r->dp[i] == 0); } for (; i < b->used; i++) { r->dp[i] = b->dp[i] + c; - c = r->dp[i] == 0; + c = (b->dp[i] != 0) && (r->dp[i] == 0); } r->dp[i] = c; r->used = (int)(i + c);