aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-08-01 14:59:50 +0000
committerlloyd <[email protected]>2012-08-01 14:59:50 +0000
commit3a94c309c06537a8f2e07785b1cd3913e92cf44c (patch)
tree3709406bd1726a2c0c8c18bb8c7fe614ae451c25 /src
parent3e4ecea6915f4ceb3c0426cf6d179fcc078dd8df (diff)
Remove BigInt::assign
Diffstat (limited to 'src')
-rw-r--r--src/math/bigint/bigint.h10
-rw-r--r--src/math/numbertheory/powm_mnt.cpp39
2 files changed, 24 insertions, 25 deletions
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;
}
}