diff options
author | Jack Lloyd <[email protected]> | 2018-03-14 08:03:28 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-14 08:03:28 -0400 |
commit | e4487e872877cb13a03974f741744eff847de801 (patch) | |
tree | 9c0e399238a5df614813e7d15a2deb04e0ea4425 /src/lib/math/numbertheory/monty.cpp | |
parent | ea0ce769791640e883ec4b7f73dcbce4b0399783 (diff) |
Add a facility for debug-mode assertions
When we want to check something but it is to expensive to do
so in normal builds.
Diffstat (limited to 'src/lib/math/numbertheory/monty.cpp')
-rw-r--r-- | src/lib/math/numbertheory/monty.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lib/math/numbertheory/monty.cpp b/src/lib/math/numbertheory/monty.cpp index 6ab847ead..503141ada 100644 --- a/src/lib/math/numbertheory/monty.cpp +++ b/src/lib/math/numbertheory/monty.cpp @@ -126,8 +126,13 @@ BigInt Montgomery_Params::sqr(const BigInt& x, secure_vector<word>& ws) const BigInt z(BigInt::Positive, output_size); + // assume x.sig_words() is at most p_words + BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words); + + const size_t x_words = (x.size() >= m_p_words) ? m_p_words : x.sig_words(); + bigint_sqr(z.mutable_data(), z.size(), - x.data(), x.size(), x.sig_words(), + x.data(), x.size(), x_words, ws.data(), ws.size()); bigint_monty_redc(z.mutable_data(), @@ -299,8 +304,7 @@ Montgomery_Int& Montgomery_Int::square_this(secure_vector<word>& ws) Montgomery_Int Montgomery_Int::square(secure_vector<word>& ws) const { - const BigInt v = m_params->sqr(m_v, ws); - return Montgomery_Int(m_params, v, false); + return Montgomery_Int(m_params, m_params->sqr(m_v, ws), false); } Montgomery_Int Montgomery_Int::multiplicative_inverse() const |