From 340ee4f3e36ec37baa9748ad7107d90050b8af20 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 5 Dec 2018 08:32:26 -0500 Subject: Remove some conditional branches from division --- src/lib/math/bigint/bigint.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/lib/math/bigint/bigint.cpp') 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& ws) +size_t BigInt::reduce_below(const BigInt& p, secure_vector& 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& 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; } /* -- cgit v1.2.3