From 3f7b562cd6a51cd796f3cb1c0151c45f2b24e2b0 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Aug 2012 14:13:49 +0000 Subject: Remove BigInt::operator[] returning a mutable word reference --- src/math/bigint/bigint.h | 7 ------- src/math/bigint/divide.cpp | 13 ++++++++----- src/math/numbertheory/powm_mnt.cpp | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h index f026e67f1..6efe53e71 100644 --- a/src/math/bigint/bigint.h +++ b/src/math/bigint/bigint.h @@ -123,13 +123,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 - */ - word& operator[](size_t i) { return m_reg[i]; } - /** * [] operator (array access) * @param i a word index diff --git a/src/math/bigint/divide.cpp b/src/math/bigint/divide.cpp index df72ec3a1..e6d768b1c 100644 --- a/src/math/bigint/divide.cpp +++ b/src/math/bigint/divide.cpp @@ -66,6 +66,9 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r) throw Internal_Error("BigInt division word sizes"); q.grow_to(n - t + 1); + + word* q_words = q.mutable_data(); + if(n <= t) { while(r > y) { r -= y; ++q; } @@ -76,7 +79,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r) BigInt temp = y << (MP_WORD_BITS * (n-t)); - while(r >= temp) { r -= temp; ++q[n-t]; } + while(r >= temp) { r -= temp; q_words[n-t] += 1; } for(size_t j = n; j != t; --j) { @@ -85,19 +88,19 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r) const word y_t = y.word_at(t); if(x_j0 == y_t) - q[j-t-1] = MP_WORD_MAX; + q_words[j-t-1] = MP_WORD_MAX; else - q[j-t-1] = bigint_divop(x_j0, x_j1, y_t); + 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), x_j0, x_j1, r.word_at(j-2))) - --q[j-t-1]; + q_words[j-t-1] -= 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)); - --q[j-t-1]; + q_words[j-t-1] -= 1; } } r >>= shifts; diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp index e565d9368..4ca0083a8 100644 --- a/src/math/numbertheory/powm_mnt.cpp +++ b/src/math/numbertheory/powm_mnt.cpp @@ -153,7 +153,7 @@ BigInt Montgomery_Exponentiator::execute() const x.grow_to(2*m_mod_words + 1); - bigint_monty_redc(&x[0], x.size(), + bigint_monty_redc(x.mutable_data(), x.size(), m_modulus.data(), m_mod_words, m_mod_prime, &workspace[0]); -- cgit v1.2.3