aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/numbertheory
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-01 16:43:00 -0500
committerJack Lloyd <[email protected]>2018-03-01 16:43:00 -0500
commit03e3d3dac4b50a6da3cfec2971460c1182cebd9d (patch)
tree138de40cea1cbc886167fbeb41bf0748de5805ba /src/lib/math/numbertheory
parent23e248260ea913227a8d224f64cd9ff592ac8b6b (diff)
Remove BigInt using functions from mp layer
Diffstat (limited to 'src/lib/math/numbertheory')
-rw-r--r--src/lib/math/numbertheory/monty.cpp12
-rw-r--r--src/lib/math/numbertheory/mp_numth.cpp15
2 files changed, 20 insertions, 7 deletions
diff --git a/src/lib/math/numbertheory/monty.cpp b/src/lib/math/numbertheory/monty.cpp
index 64646a61a..76575a88c 100644
--- a/src/lib/math/numbertheory/monty.cpp
+++ b/src/lib/math/numbertheory/monty.cpp
@@ -52,9 +52,15 @@ BigInt Montgomery_Params::mul(const BigInt& x, const BigInt& y) const
const size_t output_size = 2*m_p_words + 2;
std::vector<word> ws(output_size);
BigInt z(BigInt::Positive, output_size);
- bigint_monty_mul(z, x, y,
- m_p.data(), m_p_words, m_p_dash,
- ws.data(), ws.size());
+ bigint_mul(z.mutable_data(), z.size(),
+ x.data(), x.size(), x.sig_words(),
+ y.data(), y.size(), y.sig_words(),
+ ws.data(), ws.size());
+
+ bigint_monty_redc(z.mutable_data(),
+ m_p.data(), m_p_words, m_p_dash,
+ ws.data(), ws.size());
+
secure_scrub_memory(ws.data(), ws.size() * sizeof(word));
return z;
}
diff --git a/src/lib/math/numbertheory/mp_numth.cpp b/src/lib/math/numbertheory/mp_numth.cpp
index c39c40520..5ad72cd47 100644
--- a/src/lib/math/numbertheory/mp_numth.cpp
+++ b/src/lib/math/numbertheory/mp_numth.cpp
@@ -41,13 +41,20 @@ BigInt mul_add(const BigInt& a, const BigInt& b, const BigInt& c)
if(a.sign() != b.sign())
sign = BigInt::Negative;
- BigInt r(sign, std::max(a.size() + b.size(), c.sig_words()) + 1);
+ const size_t a_sw = a.sig_words();
+ const size_t b_sw = b.sig_words();
+ const size_t c_sw = c.sig_words();
+
+ BigInt r(sign, std::max(a_sw + b_sw, c_sw) + 1);
secure_vector<word> workspace(r.size());
- bigint_mul(r, a, b, workspace.data(), workspace.size());
+ bigint_mul(r.mutable_data(), r.size(),
+ a.data(), a.size(), a_sw,
+ b.data(), b.size(), b_sw,
+ workspace.data(), workspace.size());
- const size_t r_size = std::max(r.sig_words(), c.sig_words());
- bigint_add2(r.mutable_data(), r_size, c.data(), c.sig_words());
+ const size_t r_size = std::max(r.sig_words(), c_sw);
+ bigint_add2(r.mutable_data(), r_size, c.data(), c_sw);
return r;
}