8 #include <botan/internal/def_powm.h>
9 #include <botan/numthry.h>
10 #include <botan/internal/mp_core.h>
20 exp_bits = exp.
bits();
30 g.resize((1 << window_bits));
38 g[0].data(), g[0].
size(), g[0].sig_words(),
40 modulus.
data(), mod_words, mod_prime,
43 g[0].assign(&z[0], mod_words + 1);
45 g[1] = (base >= modulus) ? (base % modulus) :
base;
48 g[1].data(), g[1].
size(), g[1].sig_words(),
50 modulus.data(), mod_words, mod_prime,
53 g[1].assign(&z[0], mod_words + 1);
58 for(
size_t i = 1; i != g.
size(); ++i)
67 modulus.data(), mod_words, mod_prime,
70 g[i].assign(&z[0], mod_words + 1);
79 const size_t exp_nibbles = (exp_bits + window_bits - 1) / window_bits;
85 for(
size_t i = exp_nibbles; i > 0; --i)
87 for(
size_t k = 0; k != window_bits; ++k)
93 modulus.
data(), mod_words, mod_prime,
96 x.
assign(&z[0], mod_words + 1);
101 const BigInt& y = g[nibble];
107 modulus.
data(), mod_words, mod_prime,
110 x.
assign(&z[0], mod_words + 1);
116 modulus.
data(), mod_words, mod_prime,
146 R2 = (R_mod * R_mod) % modulus;
void assign(const word x[], size_t length)
void set_exponent(const BigInt &)
SecureVector< word > & get_reg()
std::invalid_argument Invalid_Argument
void bigint_monty_sqr(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word p[], size_t p_size, word p_dash, word workspace[])
u32bit get_substring(size_t offset, size_t length) const
void bigint_monty_redc(word z[], size_t z_size, const word p[], size_t p_size, word p_dash, word workspace[])
Montgomery_Exponentiator(const BigInt &, Power_Mod::Usage_Hints)
const word * data() const
static size_t window_bits(size_t exp_bits, size_t base_bits, Power_Mod::Usage_Hints hints)
void bigint_monty_mul(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw, const word p[], size_t p_size, word p_dash, word workspace[])
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
void set_base(const BigInt &)
void zeroise(MemoryRegion< T > &vec)