From af55a0ffaaffeaf95bf078977f2dd5c2d61c4068 Mon Sep 17 00:00:00 2001 From: avp Date: Fri, 7 Jun 2024 16:19:18 +0200 Subject: [PATCH] Fix calculation of carry/borrow when right=0xFFFFFFFF and carry/borrow = 1 --- uECC.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/uECC.c b/uECC.c index a3d502c..9b5c78f 100644 --- a/uECC.c +++ b/uECC.c @@ -340,9 +340,7 @@ uECC_VLI_API uECC_word_t uECC_vli_add(uECC_word_t *result, wordcount_t i; for (i = 0; i < num_words; ++i) { uECC_word_t sum = left[i] + right[i] + carry; - if (sum != left[i]) { - carry = (sum < left[i]); - } + carry = ((sum-carry) < left[i]); result[i] = sum; } return carry; @@ -359,9 +357,7 @@ uECC_VLI_API uECC_word_t uECC_vli_sub(uECC_word_t *result, wordcount_t i; for (i = 0; i < num_words; ++i) { uECC_word_t diff = left[i] - right[i] - borrow; - if (diff != left[i]) { - borrow = (diff > left[i]); - } + borrow = ( (diff+borrow) > left[i]); result[i] = diff; } return borrow;