diff options
author | Jack Lloyd <[email protected]> | 2018-03-01 16:43:00 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-01 16:43:00 -0500 |
commit | 03e3d3dac4b50a6da3cfec2971460c1182cebd9d (patch) | |
tree | 138de40cea1cbc886167fbeb41bf0748de5805ba /src | |
parent | 23e248260ea913227a8d224f64cd9ff592ac8b6b (diff) |
Remove BigInt using functions from mp layer
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/math/bigint/big_ops3.cpp | 6 | ||||
-rw-r--r-- | src/lib/math/mp/info.txt | 4 | ||||
-rw-r--r-- | src/lib/math/mp/mp_core.h | 18 | ||||
-rw-r--r-- | src/lib/math/mp/mp_karat.cpp | 12 | ||||
-rw-r--r-- | src/lib/math/mp/mp_monty.cpp | 23 | ||||
-rw-r--r-- | src/lib/math/numbertheory/monty.cpp | 12 | ||||
-rw-r--r-- | src/lib/math/numbertheory/mp_numth.cpp | 15 | ||||
-rw-r--r-- | src/lib/pubkey/ec_group/curve_gfp.cpp | 25 |
8 files changed, 44 insertions, 71 deletions
diff --git a/src/lib/math/bigint/big_ops3.cpp b/src/lib/math/bigint/big_ops3.cpp index 8bff790a6..db11eeea9 100644 --- a/src/lib/math/bigint/big_ops3.cpp +++ b/src/lib/math/bigint/big_ops3.cpp @@ -95,7 +95,11 @@ BigInt operator*(const BigInt& x, const BigInt& y) else if(x_sw && y_sw) { secure_vector<word> workspace(z.size()); - bigint_mul(z, x, y, workspace.data(), workspace.size()); + + bigint_mul(z.mutable_data(), z.size(), + x.data(), x.size(), x_sw, + y.data(), y.size(), y_sw, + workspace.data(), workspace.size()); } if(x_sw && y_sw && x.sign() != y.sign()) diff --git a/src/lib/math/mp/info.txt b/src/lib/math/mp/info.txt index 4d748a495..0f5b075f0 100644 --- a/src/lib/math/mp/info.txt +++ b/src/lib/math/mp/info.txt @@ -11,7 +11,3 @@ mp_core.h mp_madd.h mp_asmi.h </header:internal> - -<requires> -bigint -</requires> diff --git a/src/lib/math/mp/mp_core.h b/src/lib/math/mp/mp_core.h index 9efcec952..877c0cad7 100644 --- a/src/lib/math/mp/mp_core.h +++ b/src/lib/math/mp/mp_core.h @@ -14,8 +14,6 @@ namespace Botan { -class BigInt; - /* * The size of the word type, in bits */ @@ -135,20 +133,6 @@ void bigint_monty_redc(word z[], word workspace[], size_t ws_size); -/* -* Montgomery Multiplication -*/ -void bigint_monty_mul(BigInt& z, const BigInt& x, const BigInt& y, - const word p[], size_t p_size, word p_dash, - word workspace[], size_t ws_size); - -/* -* Montgomery Squaring -*/ -void bigint_monty_sqr(BigInt& z, const BigInt& x, - const word p[], size_t p_size, word p_dash, - word workspace[], size_t ws_size); - /** * Compare x and y */ @@ -183,8 +167,6 @@ void bigint_comba_sqr16(word out[32], const word in[16]); /* * High Level Multiplication/Squaring Interfaces */ -void bigint_mul(BigInt& z, const BigInt& x, const BigInt& y, - word workspace[], size_t ws_size); void bigint_mul(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, diff --git a/src/lib/math/mp/mp_karat.cpp b/src/lib/math/mp/mp_karat.cpp index 4d600efab..6e1414cfa 100644 --- a/src/lib/math/mp/mp_karat.cpp +++ b/src/lib/math/mp/mp_karat.cpp @@ -250,18 +250,6 @@ size_t karatsuba_size(size_t z_size, size_t x_size, size_t x_sw) } -/* -* Multiplication Algorithm Dispatcher -*/ -void bigint_mul(BigInt& z, const BigInt& x, const BigInt& y, - word workspace[], size_t ws_size) - { - return bigint_mul(z.mutable_data(), z.size(), - x.data(), x.size(), x.sig_words(), - y.data(), y.size(), y.sig_words(), - workspace, ws_size); - } - void bigint_mul(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw, diff --git a/src/lib/math/mp/mp_monty.cpp b/src/lib/math/mp/mp_monty.cpp index cc6388f4d..b2b3b5e4e 100644 --- a/src/lib/math/mp/mp_monty.cpp +++ b/src/lib/math/mp/mp_monty.cpp @@ -97,27 +97,4 @@ void bigint_monty_redc(word z[], BOTAN_ASSERT(borrow == 0 || borrow == 1, "Expected borrow"); } -void bigint_monty_mul(BigInt& z, const BigInt& x, const BigInt& y, - const word p[], size_t p_size, word p_dash, - word ws[], size_t ws_size) - { - bigint_mul(z, x, y, ws, ws_size); - - bigint_monty_redc(z.mutable_data(), - p, p_size, p_dash, - ws, ws_size); - } - -void bigint_monty_sqr(BigInt& z, const BigInt& x, const word p[], - size_t p_size, word p_dash, word ws[], size_t ws_size) - { - bigint_sqr(z.mutable_data(), z.size(), - x.data(), x.size(), x.sig_words(), - ws, ws_size); - - bigint_monty_redc(z.mutable_data(), - p, p_size, p_dash, - ws, ws_size); - } - } 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; } diff --git a/src/lib/pubkey/ec_group/curve_gfp.cpp b/src/lib/pubkey/ec_group/curve_gfp.cpp index 1bca04d07..caaca0a9a 100644 --- a/src/lib/pubkey/ec_group/curve_gfp.cpp +++ b/src/lib/pubkey/ec_group/curve_gfp.cpp @@ -89,9 +89,14 @@ void CurveGFp_Montgomery::curve_mul(BigInt& z, const BigInt& x, const BigInt& y, z.grow_to(output_size); z.clear(); - 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()); } void CurveGFp_Montgomery::curve_sqr(BigInt& z, const BigInt& x, @@ -114,8 +119,13 @@ void CurveGFp_Montgomery::curve_sqr(BigInt& z, const BigInt& x, z.grow_to(output_size); z.clear(); - bigint_monty_sqr(z, x, m_p.data(), m_p_words, m_p_dash, - ws.data(), ws.size()); + bigint_sqr(z.mutable_data(), z.size(), + x.data(), x.size(), x_sw, + ws.data(), ws.size()); + + bigint_monty_redc(z.mutable_data(), + m_p.data(), m_p_words, m_p_dash, + ws.data(), ws.size()); } class CurveGFp_NIST : public CurveGFp_Repr @@ -173,7 +183,10 @@ void CurveGFp_NIST::curve_mul(BigInt& z, const BigInt& x, const BigInt& y, z.grow_to(output_size); z.clear(); - bigint_mul(z, x, y, 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()); this->redc(z, ws); } |