From 2ac0ac8776140ea27300af0abefd8f03d8de1418 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Mon, 25 Nov 2019 09:14:14 +1000 Subject: [PATCH] Fix for sp_div when a > d but same bit length --- wolfcrypt/src/sp_int.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index d384375b2..137f75f16 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -672,6 +672,14 @@ static int sp_div(sp_int* a, sp_int* d, sp_int* r, sp_int* rem) } done = 1; } + else if (sp_count_bits(a) == sp_count_bits(d)) { + /* a is greater than d but same bit length */ + sp_sub(a, d, rem); + if (r != NULL) { + sp_set(r, 1); + } + done = 1; + } #ifdef WOLFSSL_SMALL_STACK if (!done && err == MP_OKAY) {