aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/bigint/bigint.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-12-05 08:32:26 -0500
committerJack Lloyd <[email protected]>2018-12-05 08:32:26 -0500
commit340ee4f3e36ec37baa9748ad7107d90050b8af20 (patch)
tree89a74a624316f38596365cfd8ac3364a231b1b58 /src/lib/math/bigint/bigint.cpp
parent1b8163a7c465cf08f43f2b93db9c64dfb1ced901 (diff)
Remove some conditional branches from division
Diffstat (limited to 'src/lib/math/bigint/bigint.cpp')
-rw-r--r--src/lib/math/bigint/bigint.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp
index a4545e4a1..1a09a92f1 100644
--- a/src/lib/math/bigint/bigint.cpp
+++ b/src/lib/math/bigint/bigint.cpp
@@ -317,7 +317,7 @@ BigInt BigInt::operator-() const
return x;
}
-void BigInt::reduce_below(const BigInt& p, secure_vector<word>& ws)
+size_t BigInt::reduce_below(const BigInt& p, secure_vector<word>& ws)
{
if(p.is_negative())
throw Invalid_Argument("BigInt::reduce_below mod must be positive");
@@ -332,14 +332,19 @@ void BigInt::reduce_below(const BigInt& p, secure_vector<word>& ws)
clear_mem(ws.data(), ws.size());
+ size_t reductions = 0;
+
for(;;)
{
word borrow = bigint_sub3(ws.data(), data(), p_words + 1, p.data(), p_words);
if(borrow)
break;
+ ++reductions;
swap_reg(ws);
}
+
+ return reductions;
}
/*