aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/math/bigint/big_ops2.cpp8
-rw-r--r--src/lib/math/bigint/big_ops3.cpp8
-rw-r--r--src/lib/math/bigint/bigint.cpp12
-rw-r--r--src/lib/math/bigint/divide.cpp6
-rw-r--r--src/lib/math/mp/mp_core.cpp24
-rw-r--r--src/lib/math/mp/mp_core.h5
-rw-r--r--src/lib/math/numbertheory/nistp_redc.cpp4
-rw-r--r--src/lib/math/numbertheory/reducer.cpp9
8 files changed, 35 insertions, 41 deletions
diff --git a/src/lib/math/bigint/big_ops2.cpp b/src/lib/math/bigint/big_ops2.cpp
index 233a3ed19..9277834ba 100644
--- a/src/lib/math/bigint/big_ops2.cpp
+++ b/src/lib/math/bigint/big_ops2.cpp
@@ -255,8 +255,8 @@ BigInt& BigInt::operator<<=(size_t shift)
{
if(shift)
{
- const size_t shift_words = shift / MP_WORD_BITS,
- shift_bits = shift % MP_WORD_BITS,
+ const size_t shift_words = shift / BOTAN_MP_WORD_BITS,
+ shift_bits = shift % BOTAN_MP_WORD_BITS,
words = sig_words();
/*
@@ -282,8 +282,8 @@ BigInt& BigInt::operator>>=(size_t shift)
{
if(shift)
{
- const size_t shift_words = shift / MP_WORD_BITS,
- shift_bits = shift % MP_WORD_BITS;
+ const size_t shift_words = shift / BOTAN_MP_WORD_BITS,
+ shift_bits = shift % BOTAN_MP_WORD_BITS;
bigint_shr1(mutable_data(), sig_words(), shift_words, shift_bits);
diff --git a/src/lib/math/bigint/big_ops3.cpp b/src/lib/math/bigint/big_ops3.cpp
index db11eeea9..ce9047b15 100644
--- a/src/lib/math/bigint/big_ops3.cpp
+++ b/src/lib/math/bigint/big_ops3.cpp
@@ -169,8 +169,8 @@ BigInt operator<<(const BigInt& x, size_t shift)
if(shift == 0)
return x;
- const size_t shift_words = shift / MP_WORD_BITS,
- shift_bits = shift % MP_WORD_BITS;
+ const size_t shift_words = shift / BOTAN_MP_WORD_BITS,
+ shift_bits = shift % BOTAN_MP_WORD_BITS;
const size_t x_sw = x.sig_words();
@@ -189,8 +189,8 @@ BigInt operator>>(const BigInt& x, size_t shift)
if(x.bits() <= shift)
return 0;
- const size_t shift_words = shift / MP_WORD_BITS,
- shift_bits = shift % MP_WORD_BITS,
+ const size_t shift_words = shift / BOTAN_MP_WORD_BITS,
+ shift_bits = shift % BOTAN_MP_WORD_BITS,
x_sw = x.sig_words();
BigInt y(x.sign(), x_sw - shift_words);
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp
index c21ce89fc..a722e0e4b 100644
--- a/src/lib/math/bigint/bigint.cpp
+++ b/src/lib/math/bigint/bigint.cpp
@@ -30,7 +30,7 @@ BigInt::BigInt(uint64_t n)
m_reg.resize(limbs_needed);
for(size_t i = 0; i != limbs_needed; ++i)
- m_reg[i] = ((n >> (i*MP_WORD_BITS)) & MP_WORD_MASK);
+ m_reg[i] = ((n >> (i*BOTAN_MP_WORD_BITS)) & MP_WORD_MASK);
}
/*
@@ -160,8 +160,8 @@ uint32_t BigInt::to_u32bit() const
*/
void BigInt::set_bit(size_t n)
{
- const size_t which = n / MP_WORD_BITS;
- const word mask = static_cast<word>(1) << (n % MP_WORD_BITS);
+ const size_t which = n / BOTAN_MP_WORD_BITS;
+ const word mask = static_cast<word>(1) << (n % BOTAN_MP_WORD_BITS);
if(which >= size()) grow_to(which + 1);
m_reg[which] |= mask;
}
@@ -171,8 +171,8 @@ void BigInt::set_bit(size_t n)
*/
void BigInt::clear_bit(size_t n)
{
- const size_t which = n / MP_WORD_BITS;
- const word mask = static_cast<word>(1) << (n % MP_WORD_BITS);
+ const size_t which = n / BOTAN_MP_WORD_BITS;
+ const word mask = static_cast<word>(1) << (n % BOTAN_MP_WORD_BITS);
if(which < size())
m_reg[which] &= ~mask;
}
@@ -193,7 +193,7 @@ size_t BigInt::bits() const
return 0;
const size_t full_words = words - 1;
- return (full_words * MP_WORD_BITS + high_bit(word_at(full_words)));
+ return (full_words * BOTAN_MP_WORD_BITS + high_bit(word_at(full_words)));
}
/*
diff --git a/src/lib/math/bigint/divide.cpp b/src/lib/math/bigint/divide.cpp
index 13696d6d3..63326d655 100644
--- a/src/lib/math/bigint/divide.cpp
+++ b/src/lib/math/bigint/divide.cpp
@@ -101,7 +101,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
return;
}
- BigInt temp = y << (MP_WORD_BITS * (n-t));
+ BigInt temp = y << (BOTAN_MP_WORD_BITS * (n-t));
while(r >= temp) { r -= temp; q_words[n-t] += 1; }
@@ -123,11 +123,11 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
q_words[j-t-1] -= 1;
}
- r -= (q_words[j-t-1] * y) << (MP_WORD_BITS * (j-t-1));
+ r -= (q_words[j-t-1] * y) << (BOTAN_MP_WORD_BITS * (j-t-1));
if(r.is_negative())
{
- r += y << (MP_WORD_BITS * (j-t-1));
+ r += y << (BOTAN_MP_WORD_BITS * (j-t-1));
q_words[j-t-1] -= 1;
}
}
diff --git a/src/lib/math/mp/mp_core.cpp b/src/lib/math/mp/mp_core.cpp
index a86bbf3c0..52ad3a4d4 100644
--- a/src/lib/math/mp/mp_core.cpp
+++ b/src/lib/math/mp/mp_core.cpp
@@ -290,7 +290,7 @@ void bigint_shl1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
{
word temp = x[j];
x[j] = (temp << bit_shift) | carry;
- carry = (temp >> (MP_WORD_BITS - bit_shift));
+ carry = (temp >> (BOTAN_MP_WORD_BITS - bit_shift));
}
}
}
@@ -322,19 +322,19 @@ void bigint_shr1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
{
word w = x[top-1];
x[top-1] = (w >> bit_shift) | carry;
- carry = (w << (MP_WORD_BITS - bit_shift));
+ carry = (w << (BOTAN_MP_WORD_BITS - bit_shift));
w = x[top-2];
x[top-2] = (w >> bit_shift) | carry;
- carry = (w << (MP_WORD_BITS - bit_shift));
+ carry = (w << (BOTAN_MP_WORD_BITS - bit_shift));
w = x[top-3];
x[top-3] = (w >> bit_shift) | carry;
- carry = (w << (MP_WORD_BITS - bit_shift));
+ carry = (w << (BOTAN_MP_WORD_BITS - bit_shift));
w = x[top-4];
x[top-4] = (w >> bit_shift) | carry;
- carry = (w << (MP_WORD_BITS - bit_shift));
+ carry = (w << (BOTAN_MP_WORD_BITS - bit_shift));
top -= 4;
}
@@ -343,7 +343,7 @@ void bigint_shr1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
{
word w = x[top-1];
x[top-1] = (w >> bit_shift) | carry;
- carry = (w << (MP_WORD_BITS - bit_shift));
+ carry = (w << (BOTAN_MP_WORD_BITS - bit_shift));
top--;
}
@@ -365,7 +365,7 @@ void bigint_shl2(word y[], const word x[], size_t x_size,
{
word w = y[j];
y[j] = (w << bit_shift) | carry;
- carry = (w >> (MP_WORD_BITS - bit_shift));
+ carry = (w >> (BOTAN_MP_WORD_BITS - bit_shift));
}
}
}
@@ -387,7 +387,7 @@ void bigint_shr2(word y[], const word x[], size_t x_size,
{
word w = y[j-1];
y[j-1] = (w >> bit_shift) | carry;
- carry = (w << (MP_WORD_BITS - bit_shift));
+ carry = (w << (BOTAN_MP_WORD_BITS - bit_shift));
}
}
}
@@ -427,17 +427,17 @@ word bigint_divop(word n1, word n0, word d)
throw Invalid_Argument("bigint_divop divide by zero");
#if defined(BOTAN_HAS_MP_DWORD)
- return ((static_cast<dword>(n1) << MP_WORD_BITS) | n0) / d;
+ return ((static_cast<dword>(n1) << BOTAN_MP_WORD_BITS) | n0) / d;
#else
word high = n1 % d, quotient = 0;
- for(size_t i = 0; i != MP_WORD_BITS; ++i)
+ for(size_t i = 0; i != BOTAN_MP_WORD_BITS; ++i)
{
word high_top_bit = (high & MP_WORD_TOP_BIT);
high <<= 1;
- high |= (n0 >> (MP_WORD_BITS-1-i)) & 1;
+ high |= (n0 >> (BOTAN_MP_WORD_BITS-1-i)) & 1;
quotient <<= 1;
if(high_top_bit || high >= d)
@@ -457,7 +457,7 @@ word bigint_divop(word n1, word n0, word d)
word bigint_modop(word n1, word n0, word d)
{
#if defined(BOTAN_HAS_MP_DWORD)
- return ((static_cast<dword>(n1) << MP_WORD_BITS) | n0) % d;
+ return ((static_cast<dword>(n1) << BOTAN_MP_WORD_BITS) | n0) % d;
#else
word z = bigint_divop(n1, n0, d);
word dummy = 0;
diff --git a/src/lib/math/mp/mp_core.h b/src/lib/math/mp/mp_core.h
index 877c0cad7..f9495c8de 100644
--- a/src/lib/math/mp/mp_core.h
+++ b/src/lib/math/mp/mp_core.h
@@ -15,11 +15,6 @@
namespace Botan {
/*
-* The size of the word type, in bits
-*/
-const size_t MP_WORD_BITS = BOTAN_MP_WORD_BITS;
-
-/*
* If cond == 0, does nothing.
* If cond > 0, swaps x[0:size] with y[0:size]
* Runs in constant time
diff --git a/src/lib/math/numbertheory/nistp_redc.cpp b/src/lib/math/numbertheory/nistp_redc.cpp
index 94a8d2872..36135f891 100644
--- a/src/lib/math/numbertheory/nistp_redc.cpp
+++ b/src/lib/math/numbertheory/nistp_redc.cpp
@@ -21,8 +21,8 @@ const BigInt& prime_p521()
void redc_p521(BigInt& x, secure_vector<word>& ws)
{
- const size_t p_full_words = 521 / MP_WORD_BITS;
- const size_t p_top_bits = 521 % MP_WORD_BITS;
+ const size_t p_full_words = 521 / BOTAN_MP_WORD_BITS;
+ const size_t p_top_bits = 521 % BOTAN_MP_WORD_BITS;
const size_t p_words = p_full_words + 1;
const size_t x_sw = x.sig_words();
diff --git a/src/lib/math/numbertheory/reducer.cpp b/src/lib/math/numbertheory/reducer.cpp
index 1d7c2259a..e9db7753b 100644
--- a/src/lib/math/numbertheory/reducer.cpp
+++ b/src/lib/math/numbertheory/reducer.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/reducer.h>
-#include <botan/internal/mp_core.h>
namespace Botan {
@@ -23,7 +22,7 @@ Modular_Reducer::Modular_Reducer(const BigInt& mod)
m_modulus_2 = Botan::square(m_modulus);
- m_mu = BigInt::power_of_2(2 * MP_WORD_BITS * m_mod_words) / m_modulus;
+ m_mu = BigInt::power_of_2(2 * BOTAN_MP_WORD_BITS * m_mod_words) / m_modulus;
}
/*
@@ -49,16 +48,16 @@ BigInt Modular_Reducer::reduce(const BigInt& x) const
BigInt t1(x.data() + m_mod_words - 1, x_sw - (m_mod_words - 1));
t1.mul(m_mu, ws);
- t1 >>= (MP_WORD_BITS * (m_mod_words + 1));
+ t1 >>= (BOTAN_MP_WORD_BITS * (m_mod_words + 1));
t1.mul(m_modulus, ws);
- t1.mask_bits(MP_WORD_BITS * (m_mod_words + 1));
+ t1.mask_bits(BOTAN_MP_WORD_BITS * (m_mod_words + 1));
t1.rev_sub(x.data(), std::min(x_sw, m_mod_words + 1), ws);
if(t1.is_negative())
{
- t1 += BigInt::power_of_2(MP_WORD_BITS * (m_mod_words + 1));
+ t1 += BigInt::power_of_2(BOTAN_MP_WORD_BITS * (m_mod_words + 1));
}
t1.reduce_below(m_modulus, ws);