Botan
1.11.15
|
#include <pow_mod.h>
Public Types | |
enum | Usage_Hints { NO_HINTS = 0x0000, BASE_IS_FIXED = 0x0001, BASE_IS_SMALL = 0x0002, BASE_IS_LARGE = 0x0004, BASE_IS_2 = 0x0008, EXP_IS_FIXED = 0x0100, EXP_IS_SMALL = 0x0200, EXP_IS_LARGE = 0x0400 } |
Public Member Functions | |
BigInt | execute () const |
Fixed_Base_Power_Mod () | |
Fixed_Base_Power_Mod (const BigInt &base, const BigInt &modulus, Usage_Hints hints=NO_HINTS) | |
BigInt | operator() (const BigInt &e) const |
void | set_base (const BigInt &) const |
void | set_exponent (const BigInt &) const |
void | set_modulus (const BigInt &, Usage_Hints=NO_HINTS) const |
Static Public Member Functions | |
static size_t | window_bits (size_t exp_bits, size_t base_bits, Power_Mod::Usage_Hints hints) |
enum Botan::Power_Mod::Usage_Hints [inherited] |
NO_HINTS | |
BASE_IS_FIXED | |
BASE_IS_SMALL | |
BASE_IS_LARGE | |
BASE_IS_2 | |
EXP_IS_FIXED | |
EXP_IS_SMALL | |
EXP_IS_LARGE |
Definition at line 35 of file pow_mod.h.
{ NO_HINTS = 0x0000, BASE_IS_FIXED = 0x0001, BASE_IS_SMALL = 0x0002, BASE_IS_LARGE = 0x0004, BASE_IS_2 = 0x0008, EXP_IS_FIXED = 0x0100, EXP_IS_SMALL = 0x0200, EXP_IS_LARGE = 0x0400 };
Botan::Fixed_Base_Power_Mod::Fixed_Base_Power_Mod | ( | ) | [inline] |
Botan::Fixed_Base_Power_Mod::Fixed_Base_Power_Mod | ( | const BigInt & | base, |
const BigInt & | modulus, | ||
Usage_Hints | hints = NO_HINTS |
||
) |
Definition at line 192 of file pow_mod.cpp.
References Botan::Power_Mod::set_base().
: Power_Mod(n, Usage_Hints(hints | BASE_IS_FIXED | choose_base_hints(b, n))) { set_base(b); }
BigInt Botan::Power_Mod::execute | ( | ) | const [inherited] |
Definition at line 95 of file pow_mod.cpp.
References Botan::Modular_Exponentiator::execute().
Referenced by Botan::power_mod().
{ if(!core) throw Internal_Error("Power_Mod::execute: core was NULL"); return core->execute(); }
Definition at line 91 of file pow_mod.h.
{ set_exponent(e); return execute(); }
void Botan::Power_Mod::set_base | ( | const BigInt & | b | ) | const [inherited] |
Definition at line 69 of file pow_mod.cpp.
References Botan::BigInt::is_negative(), Botan::BigInt::is_zero(), and Botan::Modular_Exponentiator::set_base().
Referenced by Fixed_Base_Power_Mod(), and Botan::power_mod().
{ if(b.is_zero() || b.is_negative()) throw Invalid_Argument("Power_Mod::set_base: arg must be > 0"); if(!core) throw Internal_Error("Power_Mod::set_base: core was NULL"); core->set_base(b); }
void Botan::Power_Mod::set_exponent | ( | const BigInt & | e | ) | const [inherited] |
Definition at line 82 of file pow_mod.cpp.
References Botan::BigInt::is_negative(), and Botan::Modular_Exponentiator::set_exponent().
Referenced by Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod(), and Botan::power_mod().
{ if(e.is_negative()) throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0"); if(!core) throw Internal_Error("Power_Mod::set_exponent: core was NULL"); core->set_exponent(e); }
void Botan::Power_Mod::set_modulus | ( | const BigInt & | n, |
Usage_Hints | hints = NO_HINTS |
||
) | const [inherited] |
Definition at line 56 of file pow_mod.cpp.
References Botan::BigInt::is_odd().
Referenced by Botan::Power_Mod::Power_Mod().
size_t Botan::Power_Mod::window_bits | ( | size_t | exp_bits, |
size_t | base_bits, | ||
Power_Mod::Usage_Hints | hints | ||
) | [static, inherited] |
Definition at line 105 of file pow_mod.cpp.
References Botan::Power_Mod::BASE_IS_FIXED, and Botan::Power_Mod::EXP_IS_LARGE.
Referenced by Botan::Fixed_Window_Exponentiator::set_base(), and Botan::Montgomery_Exponentiator::set_base().
{ static const size_t wsize[][2] = { { 1434, 7 }, { 539, 6 }, { 197, 4 }, { 70, 3 }, { 25, 2 }, { 0, 0 } }; size_t window_bits = 1; if(exp_bits) { for(size_t j = 0; wsize[j][0]; ++j) { if(exp_bits >= wsize[j][0]) { window_bits += wsize[j][1]; break; } } } if(hints & Power_Mod::BASE_IS_FIXED) window_bits += 2; if(hints & Power_Mod::EXP_IS_LARGE) ++window_bits; return window_bits; }