aboutsummaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-08-01 14:23:20 +0000
committerlloyd <[email protected]>2012-08-01 14:23:20 +0000
commitd23dffe70d1f0b2ef6bd18d1c490fff52b8b401c (patch)
tree2bfc055ea7edbcc023e996121d29526d961dd980 /src/math
parent3f7b562cd6a51cd796f3cb1c0151c45f2b24e2b0 (diff)
Remove BigInt::operator[]. Use BigInt::word_at, which checks sizes
Diffstat (limited to 'src/math')
-rw-r--r--src/math/bigint/bigint.h7
-rw-r--r--src/math/bigint/divide.cpp12
-rw-r--r--src/math/numbertheory/numthry.cpp2
-rw-r--r--src/math/numbertheory/numthry.h5
4 files changed, 12 insertions, 14 deletions
diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h
index 6efe53e71..a74a5c280 100644
--- a/src/math/bigint/bigint.h
+++ b/src/math/bigint/bigint.h
@@ -124,13 +124,6 @@ class BOTAN_DLL BigInt
bool operator !() const { return (!is_nonzero()); }
/**
- * [] operator (array access)
- * @param i a word index
- * @return the word at index i
- */
- const word& operator[](size_t i) const { return m_reg[i]; }
-
- /**
* Zeroize the BigInt. The size of the underlying register is not
* modified.
*/
diff --git a/src/math/bigint/divide.cpp b/src/math/bigint/divide.cpp
index e6d768b1c..c54eb463b 100644
--- a/src/math/bigint/divide.cpp
+++ b/src/math/bigint/divide.cpp
@@ -1,6 +1,6 @@
/*
* Division Algorithm
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2007,2012 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -55,7 +55,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
else if(compare > 0)
{
size_t shifts = 0;
- word y_top = y[y.sig_words()-1];
+ word y_top = y.word_at(y.sig_words()-1);
while(y_top < MP_WORD_TOP_BIT) { y_top <<= 1; ++shifts; }
y <<= shifts;
r <<= shifts;
@@ -92,11 +92,15 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
else
q_words[j-t-1] = bigint_divop(x_j0, x_j1, y_t);
- while(bigint_divcore(q[j-t-1], y_t, y.word_at(t-1),
+ while(bigint_divcore(q_words[j-t-1],
+ y_t, y.word_at(t-1),
x_j0, x_j1, r.word_at(j-2)))
+ {
q_words[j-t-1] -= 1;
+ }
+
+ r -= (q_words[j-t-1] * y) << (MP_WORD_BITS * (j-t-1));
- r -= (q[j-t-1] * y) << (MP_WORD_BITS * (j-t-1));
if(r.is_negative())
{
r += y << (MP_WORD_BITS * (j-t-1));
diff --git a/src/math/numbertheory/numthry.cpp b/src/math/numbertheory/numthry.cpp
index c431fb63f..38d683f1c 100644
--- a/src/math/numbertheory/numthry.cpp
+++ b/src/math/numbertheory/numthry.cpp
@@ -148,7 +148,7 @@ size_t low_zero_bits(const BigInt& n)
{
for(size_t i = 0; i != n.size(); ++i)
{
- word x = n[i];
+ const word x = n.word_at(i);
if(x)
{
diff --git a/src/math/numbertheory/numthry.h b/src/math/numbertheory/numthry.h
index d21635f34..7d0330ef6 100644
--- a/src/math/numbertheory/numthry.h
+++ b/src/math/numbertheory/numthry.h
@@ -108,9 +108,10 @@ BigInt BOTAN_DLL power_mod(const BigInt& b,
BigInt BOTAN_DLL ressol(const BigInt& x, const BigInt& p);
/**
-* @param x an integer
+* @param x a positive integer
* @return count of the zero bits in x, or, equivalently, the largest
-* value of n such that 2^n divides x evently
+* value of n such that 2^n divides x evenly. Returns zero if
+* n is less than or equal to zero.
*/
size_t BOTAN_DLL low_zero_bits(const BigInt& x);