aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/relnotes/1_11_1.rst6
-rw-r--r--src/math/bigint/bigint.h10
-rw-r--r--src/math/numbertheory/powm_mnt.cpp39
3 files changed, 27 insertions, 28 deletions
diff --git a/doc/relnotes/1_11_1.rst b/doc/relnotes/1_11_1.rst
index 2ef9a672e..655c418a1 100644
--- a/doc/relnotes/1_11_1.rst
+++ b/doc/relnotes/1_11_1.rst
@@ -17,9 +17,9 @@ BigInt Modifications
""""""""""""""""""""""""""""""""""""""""
Several :cpp:class:`BigInt` functions have been removed, including
-``operator[]``, ``get_reg``, and ``grow_reg``. The version of ``data``
-that returns a mutable pointer has been renamed ``mutable_data``.
-Support for octal conversions has been removed.
+``operator[]``, ``assign``, ``get_reg``, and ``grow_reg``. The version
+of ``data`` that returns a mutable pointer has been renamed
+``mutable_data``. Support for octal conversions has been removed.
The constructor ``BigInt(NumberType type, size_t n)`` has been
removed, replaced by ``BigInt::power_of_2``.
diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h
index 4d3e37708..bf1e8bb0e 100644
--- a/src/math/bigint/bigint.h
+++ b/src/math/bigint/bigint.h
@@ -304,15 +304,6 @@ class BOTAN_DLL BigInt
const word* data() const { return &m_reg[0]; }
/**
- * Assign using a plain word array
- */
- void assign(const word x[], size_t length)
- {
- m_reg.resize(length);
- copy_mem(&m_reg[0], x, length);
- }
-
- /**
* Increase internal register buffer to at least n words
* @param n new size of register
*/
@@ -363,7 +354,6 @@ class BOTAN_DLL BigInt
const BigInt& min,
const BigInt& max);
-
/**
* Create a power of two
* @param n the power of two to create
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp
index a8155bbfb..416f430b7 100644
--- a/src/math/numbertheory/powm_mnt.cpp
+++ b/src/math/numbertheory/powm_mnt.cpp
@@ -1,6 +1,6 @@
/*
* Montgomery Exponentiation
-* (C) 1999-2010 Jack Lloyd
+* (C) 1999-2010,2012 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -79,18 +79,19 @@ void Montgomery_Exponentiator::set_base(const BigInt& base)
m_g.resize((1 << m_window_bits) - 1);
- secure_vector<word> z(2 * (m_mod_words + 1));
+ BigInt z(BigInt::Positive, 2 * (m_mod_words + 1));
secure_vector<word> workspace(z.size());
m_g[0] = (base >= m_modulus) ? (base % m_modulus) : base;
- bigint_monty_mul(&z[0], z.size(),
+ bigint_monty_mul(z.mutable_data(), z.size(),
m_g[0].data(), m_g[0].size(), m_g[0].sig_words(),
m_R2_mod.data(), m_R2_mod.size(), m_R2_mod.sig_words(),
m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- m_g[0].assign(&z[0], m_mod_words + 1);
+ z.mask_bits(BOTAN_MP_WORD_BITS * (m_mod_words + 1));
+ m_g[0] = z;
const BigInt& x = m_g[0];
const size_t x_sig = x.sig_words();
@@ -100,14 +101,16 @@ void Montgomery_Exponentiator::set_base(const BigInt& base)
const BigInt& y = m_g[i-1];
const size_t y_sig = y.sig_words();
- zeroise(z);
- bigint_monty_mul(&z[0], z.size(),
+ z.clear();
+
+ bigint_monty_mul(z.mutable_data(), z.size(),
x.data(), x.size(), x_sig,
y.data(), y.size(), y_sig,
m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- m_g[i].assign(&z[0], m_mod_words + 1);
+ z.mask_bits(BOTAN_MP_WORD_BITS * (m_mod_words + 1));
+ m_g[i] = z;
}
}
@@ -119,35 +122,41 @@ BigInt Montgomery_Exponentiator::execute() const
const size_t exp_nibbles = (m_exp_bits + m_window_bits - 1) / m_window_bits;
BigInt x = m_R_mod;
- secure_vector<word> z(2 * (m_mod_words + 1));
- secure_vector<word> workspace(2 * (m_mod_words + 1));
+
+ const size_t z_size = 2*(m_mod_words + 1);
+
+ BigInt z(BigInt::Positive, z_size);
+ secure_vector<word> workspace(z_size);
for(size_t i = exp_nibbles; i > 0; --i)
{
for(size_t k = 0; k != m_window_bits; ++k)
{
- zeroise(z);
+ z.clear();
- bigint_monty_sqr(&z[0], z.size(),
+ bigint_monty_sqr(z.mutable_data(), z_size,
x.data(), x.size(), x.sig_words(),
m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- x.assign(&z[0], m_mod_words + 1);
+ z.mask_bits(BOTAN_MP_WORD_BITS * (m_mod_words + 1));
+ x = z;
}
if(u32bit nibble = m_exp.get_substring(m_window_bits*(i-1), m_window_bits))
{
const BigInt& y = m_g[nibble-1];
- zeroise(z);
- bigint_monty_mul(&z[0], z.size(),
+ z.clear();
+
+ bigint_monty_mul(z.mutable_data(), z_size,
x.data(), x.size(), x.sig_words(),
y.data(), y.size(), y.sig_words(),
m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- x.assign(&z[0], m_mod_words + 1);
+ z.mask_bits(BOTAN_MP_WORD_BITS * (m_mod_words + 1));
+ x = z;
}
}