aboutsummaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-06-15 20:31:18 +0000
committerlloyd <[email protected]>2012-06-15 20:31:18 +0000
commitc0145404db9bb6007f1468a648e483dd9791cced (patch)
tree83235b021fbb496c06e455a631ca616cea4d9cc2 /src/math
parentaab06ec56681823a7f7f724211abb46633e2ef55 (diff)
m_ namespace member vars
Diffstat (limited to 'src/math')
-rw-r--r--src/math/numbertheory/def_powm.h11
-rw-r--r--src/math/numbertheory/powm_mnt.cpp75
2 files changed, 42 insertions, 44 deletions
diff --git a/src/math/numbertheory/def_powm.h b/src/math/numbertheory/def_powm.h
index a93db9b82..6ceee7bb6 100644
--- a/src/math/numbertheory/def_powm.h
+++ b/src/math/numbertheory/def_powm.h
@@ -51,12 +51,11 @@ class Montgomery_Exponentiator : public Modular_Exponentiator
Montgomery_Exponentiator(const BigInt&, Power_Mod::Usage_Hints);
private:
- BigInt exp, modulus;
- BigInt R2, R_mod;
- std::vector<BigInt> g;
- word mod_prime;
- size_t mod_words, exp_bits, window_bits;
- Power_Mod::Usage_Hints hints;
+ BigInt m_exp, m_modulus, m_R_mod, m_R2_mod;
+ word m_mod_prime;
+ size_t m_mod_words, m_exp_bits, m_window_bits;
+ Power_Mod::Usage_Hints m_hints;
+ std::vector<BigInt> m_g;
};
}
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp
index 62df84da5..68c19a2f2 100644
--- a/src/math/numbertheory/powm_mnt.cpp
+++ b/src/math/numbertheory/powm_mnt.cpp
@@ -16,8 +16,8 @@ namespace Botan {
*/
void Montgomery_Exponentiator::set_exponent(const BigInt& exp)
{
- this->exp = exp;
- exp_bits = exp.bits();
+ m_exp = exp;
+ m_exp_bits = exp.bits();
}
/*
@@ -25,39 +25,39 @@ void Montgomery_Exponentiator::set_exponent(const BigInt& exp)
*/
void Montgomery_Exponentiator::set_base(const BigInt& base)
{
- window_bits = Power_Mod::window_bits(exp.bits(), base.bits(), hints);
+ m_window_bits = Power_Mod::window_bits(m_exp.bits(), base.bits(), m_hints);
- g.resize((1 << window_bits) - 1);
+ m_g.resize((1 << m_window_bits) - 1);
- secure_vector<word> z(2 * (mod_words + 1));
+ secure_vector<word> z(2 * (m_mod_words + 1));
secure_vector<word> workspace(z.size());
- g[0] = (base >= modulus) ? (base % modulus) : base;
+ m_g[0] = (base >= m_modulus) ? (base % m_modulus) : base;
bigint_monty_mul(&z[0], z.size(),
- g[0].data(), g[0].size(), g[0].sig_words(),
- R2.data(), R2.size(), R2.sig_words(),
- modulus.data(), mod_words, mod_prime,
+ 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]);
- g[0].assign(&z[0], mod_words + 1);
+ m_g[0].assign(&z[0], m_mod_words + 1);
- const BigInt& x = g[0];
+ const BigInt& x = m_g[0];
const size_t x_sig = x.sig_words();
- for(size_t i = 1; i != g.size(); ++i)
+ for(size_t i = 1; i != m_g.size(); ++i)
{
- const BigInt& y = g[i-1];
+ const BigInt& y = m_g[i-1];
const size_t y_sig = y.sig_words();
zeroise(z);
bigint_monty_mul(&z[0], z.size(),
x.data(), x.size(), x_sig,
y.data(), y.size(), y_sig,
- modulus.data(), mod_words, mod_prime,
+ m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- g[i].assign(&z[0], mod_words + 1);
+ m_g[i].assign(&z[0], m_mod_words + 1);
}
}
@@ -66,48 +66,48 @@ void Montgomery_Exponentiator::set_base(const BigInt& base)
*/
BigInt Montgomery_Exponentiator::execute() const
{
- const size_t exp_nibbles = (exp_bits + window_bits - 1) / window_bits;
+ const size_t exp_nibbles = (m_exp_bits + m_window_bits - 1) / m_window_bits;
- BigInt x = R_mod;
- secure_vector<word> z(2 * (mod_words + 1));
- secure_vector<word> workspace(2 * (mod_words + 1));
+ BigInt x = m_R_mod;
+ secure_vector<word> z(2 * (m_mod_words + 1));
+ secure_vector<word> workspace(2 * (m_mod_words + 1));
for(size_t i = exp_nibbles; i > 0; --i)
{
- for(size_t k = 0; k != window_bits; ++k)
+ for(size_t k = 0; k != m_window_bits; ++k)
{
zeroise(z);
bigint_monty_sqr(&z[0], z.size(),
x.data(), x.size(), x.sig_words(),
- modulus.data(), mod_words, mod_prime,
+ m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- x.assign(&z[0], mod_words + 1);
+ x.assign(&z[0], m_mod_words + 1);
}
- if(u32bit nibble = exp.get_substring(window_bits*(i-1), window_bits))
+ if(u32bit nibble = m_exp.get_substring(m_window_bits*(i-1), m_window_bits))
{
- const BigInt& y = g[nibble-1];
+ const BigInt& y = m_g[nibble-1];
zeroise(z);
bigint_monty_mul(&z[0], z.size(),
x.data(), x.size(), x.sig_words(),
y.data(), y.size(), y.sig_words(),
- modulus.data(), mod_words, mod_prime,
+ m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- x.assign(&z[0], mod_words + 1);
+ x.assign(&z[0], m_mod_words + 1);
}
}
- x.get_reg().resize(2*mod_words+1);
+ x.get_reg().resize(2*m_mod_words+1);
bigint_monty_redc(&x[0], x.size(),
- modulus.data(), mod_words, mod_prime,
+ m_modulus.data(), m_mod_words, m_mod_prime,
&workspace[0]);
- x.get_reg().resize(mod_words+1);
+ x.get_reg().resize(m_mod_words+1);
return x;
}
@@ -122,19 +122,18 @@ Montgomery_Exponentiator::Montgomery_Exponentiator(const BigInt& mod,
if(!mod.is_positive() || mod.is_even())
throw Invalid_Argument("Montgomery_Exponentiator: invalid modulus");
- window_bits = 0;
- this->hints = hints;
- modulus = mod;
+ m_window_bits = 0;
+ m_hints = hints;
+ m_modulus = mod;
- mod_words = modulus.sig_words();
+ m_mod_words = m_modulus.sig_words();
const BigInt b = BigInt(1) << BOTAN_MP_WORD_BITS;
- mod_prime = (b - inverse_mod(modulus.word_at(0), b)).word_at(0);
+ m_mod_prime = (b - inverse_mod(m_modulus.word_at(0), b)).word_at(0);
- const BigInt r(BigInt::Power2, mod_words * BOTAN_MP_WORD_BITS);
- R_mod = r % modulus;
-
- R2 = (R_mod * R_mod) % modulus;
+ const BigInt r(BigInt::Power2, m_mod_words * BOTAN_MP_WORD_BITS);
+ m_R_mod = r % m_modulus;
+ m_R2_mod = (m_R_mod * m_R_mod) % m_modulus;
}
}