aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/math/bigint/big_ops2.cpp2
-rw-r--r--src/math/bigint/bigint.h11
-rw-r--r--src/math/bigint/divide.cpp2
-rw-r--r--src/math/ec_gfp/point_gfp.cpp21
-rw-r--r--src/math/numbertheory/powm_mnt.cpp4
5 files changed, 18 insertions, 22 deletions
diff --git a/src/math/bigint/big_ops2.cpp b/src/math/bigint/big_ops2.cpp
index d00d1995d..ec5197090 100644
--- a/src/math/bigint/big_ops2.cpp
+++ b/src/math/bigint/big_ops2.cpp
@@ -32,7 +32,7 @@ BigInt& BigInt::operator+=(const BigInt& y)
{
secure_vector<word> z(reg_size - 1);
bigint_sub3(&z[0], y.data(), reg_size - 1, data(), x_sw);
- copy_mem(&m_reg[0], &z[0], z.size());
+ std::swap(m_reg, z);
set_sign(y.sign());
}
else if(relative_size == 0)
diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h
index 26cfe91e1..baf2bfc71 100644
--- a/src/math/bigint/bigint.h
+++ b/src/math/bigint/bigint.h
@@ -138,7 +138,8 @@ class BOTAN_DLL BigInt
const word& operator[](size_t i) const { return m_reg[i]; }
/**
- * Zeroize the BigInt
+ * Zeroize the BigInt. The size of the underlying register is not
+ * modified.
*/
void clear() { zeroise(m_reg); }
@@ -324,14 +325,6 @@ class BOTAN_DLL BigInt
const word* data() const { return &m_reg[0]; }
/**
- * return a reference to the internal register containing the value
- * @result a reference to the word-array (secure_vector<word>)
- * with the internal register value (containing the integer
- * value)
- */
- secure_vector<word>& get_reg() { return m_reg; }
-
- /**
* return a const reference to the internal register containing the value
* @result a const reference to the word-array (secure_vector<word>)
* with the internal register value (containing the integer value)
diff --git a/src/math/bigint/divide.cpp b/src/math/bigint/divide.cpp
index ba84aa7d9..df72ec3a1 100644
--- a/src/math/bigint/divide.cpp
+++ b/src/math/bigint/divide.cpp
@@ -65,7 +65,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
if(n < t)
throw Internal_Error("BigInt division word sizes");
- q.get_reg().resize(n - t + 1);
+ q.grow_to(n - t + 1);
if(n <= t)
{
while(r > y) { r -= y; ++q; }
diff --git a/src/math/ec_gfp/point_gfp.cpp b/src/math/ec_gfp/point_gfp.cpp
index 599b6e842..fd42ccd16 100644
--- a/src/math/ec_gfp/point_gfp.cpp
+++ b/src/math/ec_gfp/point_gfp.cpp
@@ -2,7 +2,7 @@
* Point arithmetic on elliptic curves over GF(p)
*
* (C) 2007 Martin Doering, Christoph Ludwig, Falko Strenzke
-* 2008-2011 Jack Lloyd
+* 2008-2011,2012 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -45,11 +45,13 @@ void PointGFp::monty_mult(BigInt& z, const BigInt& x, const BigInt& y) const
const size_t p_size = curve.get_p_words();
const word p_dash = curve.get_p_dash();
- secure_vector<word>& z_reg = z.get_reg();
- z_reg.resize(2*p_size+1);
- zeroise(z_reg);
+ const size_t output_size = 2*p_size + 1;
- bigint_monty_mul(&z_reg[0], z_reg.size(),
+ z.grow_to(output_size);
+ z.clear();
+
+
+ bigint_monty_mul(z.data(), output_size,
x.data(), x.size(), x.sig_words(),
y.data(), y.size(), y.sig_words(),
p.data(), p_size, p_dash,
@@ -71,11 +73,12 @@ void PointGFp::monty_sqr(BigInt& z, const BigInt& x) const
const size_t p_size = curve.get_p_words();
const word p_dash = curve.get_p_dash();
- secure_vector<word>& z_reg = z.get_reg();
- z_reg.resize(2*p_size+1);
- zeroise(z_reg);
+ const size_t output_size = 2*p_size + 1;
+
+ z.grow_to(output_size);
+ z.clear();
- bigint_monty_sqr(&z_reg[0], z_reg.size(),
+ bigint_monty_sqr(z.data(), output_size,
x.data(), x.size(), x.sig_words(),
p.data(), p_size, p_dash,
&ws[0]);
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp
index 39cf690ce..e565d9368 100644
--- a/src/math/numbertheory/powm_mnt.cpp
+++ b/src/math/numbertheory/powm_mnt.cpp
@@ -151,13 +151,13 @@ BigInt Montgomery_Exponentiator::execute() const
}
}
- x.get_reg().resize(2*m_mod_words+1);
+ x.grow_to(2*m_mod_words + 1);
bigint_monty_redc(&x[0], x.size(),
m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- x.get_reg().resize(m_mod_words+1);
+ x.mask_bits(MP_WORD_BITS * (m_mod_words + 1));
return x;
}