From 08afe6a404b9e94e37b3f0fed46ee28044bb8bc0 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Mon, 30 Jan 2023 08:40:45 +1000 Subject: [PATCH] SP int: div small static code analysis change _sp_div_small: Make it explicit as possible that we only want the bottom digit of the product subtracted from the bottom word of t. Top digit is unnecessary and more cycles used if calculated. --- wolfcrypt/src/sp_int.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index bb2269678..6109bb102 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -6377,7 +6377,7 @@ static void _sp_div_small(const sp_int* a, sp_int_digit d, sp_int* r, /* Get top digit after multipling. */ tt = (t * m) >> SP_WORD_SIZE; /* Subtract trial division. */ - tr = (sp_int_digit)(t - tt * d); + tr = (sp_int_digit)t - (sp_int_digit)(tt * d); #else /* Multiply digit. */ SP_ASM_MUL(l, tt, a->dp[i], m); @@ -6404,7 +6404,7 @@ static void _sp_div_small(const sp_int* a, sp_int_digit d, sp_int* r, /* Get top digit after multipling. */ tt = (t * m) >> SP_WORD_SIZE; /* Subtract trial division. */ - tr = (sp_int_digit)(t - tt * d); + tr = (sp_int_digit)t - (sp_int_digit)(tt * d); #else /* Multiply digit. */ SP_ASM_MUL(l, tt, a->dp[i], m);