Botan  1.11.34
Crypto and TLS for C++11
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Botan::Fixed_Exponent_Power_Mod Class Reference

#include <pow_mod.h>

Inheritance diagram for Botan::Fixed_Exponent_Power_Mod:
Botan::Power_Mod

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_Exponent_Power_Mod ()
 
 Fixed_Exponent_Power_Mod (const BigInt &exponent, const BigInt &modulus, Usage_Hints hints=NO_HINTS)
 
BigInt operator() (const BigInt &b) 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)
 

Detailed Description

Fixed Exponent Modular Exponentiator Proxy

Definition at line 72 of file pow_mod.h.

Member Enumeration Documentation

§ Usage_Hints

Enumerator
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.

Constructor & Destructor Documentation

§ Fixed_Exponent_Power_Mod() [1/2]

Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod ( )
inline

Definition at line 78 of file pow_mod.h.

78 {}

§ Fixed_Exponent_Power_Mod() [2/2]

Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod ( const BigInt exponent,
const BigInt modulus,
Usage_Hints  hints = NO_HINTS 
)

Definition at line 186 of file pow_mod.cpp.

References Botan::Power_Mod::set_exponent().

188  :
189  Power_Mod(n, Usage_Hints(hints | EXP_IS_FIXED | choose_exp_hints(e, n)))
190  {
191  set_exponent(e);
192  }
void set_exponent(const BigInt &) const
Definition: pow_mod.cpp:87
Power_Mod(const BigInt &=0, Usage_Hints=NO_HINTS)
Definition: pow_mod.cpp:16

Member Function Documentation

§ execute()

BigInt Botan::Power_Mod::execute ( ) const
inherited

Definition at line 100 of file pow_mod.cpp.

References Botan::Modular_Exponentiator::execute().

Referenced by Botan::power_mod().

101  {
102  if(!m_core)
103  throw Internal_Error("Power_Mod::execute: m_core was NULL");
104  return m_core->execute();
105  }
virtual BigInt execute() const =0

§ operator()()

BigInt Botan::Fixed_Exponent_Power_Mod::operator() ( const BigInt b) const
inline

Definition at line 75 of file pow_mod.h.

76  { set_base(b); return execute(); }
BigInt execute() const
Definition: pow_mod.cpp:100
void set_base(const BigInt &) const
Definition: pow_mod.cpp:74

§ set_base()

void Botan::Power_Mod::set_base ( const BigInt b) const
inherited

Definition at line 74 of file pow_mod.cpp.

References Botan::BigInt::is_negative(), Botan::BigInt::is_zero(), and Botan::Modular_Exponentiator::set_base().

Referenced by Botan::Fixed_Base_Power_Mod::Fixed_Base_Power_Mod(), and Botan::power_mod().

75  {
76  if(b.is_zero() || b.is_negative())
77  throw Invalid_Argument("Power_Mod::set_base: arg must be > 0");
78 
79  if(!m_core)
80  throw Internal_Error("Power_Mod::set_base: m_core was NULL");
81  m_core->set_base(b);
82  }
virtual void set_base(const BigInt &)=0

§ set_exponent()

void Botan::Power_Mod::set_exponent ( const BigInt e) const
inherited

Definition at line 87 of file pow_mod.cpp.

References Botan::BigInt::is_negative(), and Botan::Modular_Exponentiator::set_exponent().

Referenced by Fixed_Exponent_Power_Mod(), and Botan::power_mod().

88  {
89  if(e.is_negative())
90  throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0");
91 
92  if(!m_core)
93  throw Internal_Error("Power_Mod::set_exponent: m_core was NULL");
94  m_core->set_exponent(e);
95  }
virtual void set_exponent(const BigInt &)=0

§ set_modulus()

void Botan::Power_Mod::set_modulus ( const BigInt n,
Usage_Hints  hints = NO_HINTS 
) const
inherited

Definition at line 61 of file pow_mod.cpp.

References Botan::BigInt::is_odd().

Referenced by Botan::Power_Mod::Power_Mod().

62  {
63  delete m_core;
64 
65  if(n.is_odd())
66  m_core = new Montgomery_Exponentiator(n, hints);
67  else if(n != 0)
68  m_core = new Fixed_Window_Exponentiator(n, hints);
69  }

§ window_bits()

size_t Botan::Power_Mod::window_bits ( size_t  exp_bits,
size_t  base_bits,
Power_Mod::Usage_Hints  hints 
)
staticinherited

Definition at line 110 of file pow_mod.cpp.

References Botan::Power_Mod::BASE_IS_2, Botan::Power_Mod::BASE_IS_FIXED, Botan::Power_Mod::BASE_IS_LARGE, Botan::Power_Mod::BASE_IS_SMALL, Botan::BigInt::bits(), Botan::Power_Mod::EXP_IS_LARGE, and Botan::Power_Mod::NO_HINTS.

Referenced by Botan::Fixed_Window_Exponentiator::set_base(), and Botan::Montgomery_Exponentiator::set_base().

112  {
113  static const size_t wsize[][2] = {
114  { 1434, 7 },
115  { 539, 6 },
116  { 197, 4 },
117  { 70, 3 },
118  { 25, 2 },
119  { 0, 0 }
120  };
121 
122  size_t window_bits = 1;
123 
124  if(exp_bits)
125  {
126  for(size_t j = 0; wsize[j][0]; ++j)
127  {
128  if(exp_bits >= wsize[j][0])
129  {
130  window_bits += wsize[j][1];
131  break;
132  }
133  }
134  }
135 
136  if(hints & Power_Mod::BASE_IS_FIXED)
137  window_bits += 2;
138  if(hints & Power_Mod::EXP_IS_LARGE)
139  ++window_bits;
140 
141  return window_bits;
142  }
static size_t window_bits(size_t exp_bits, size_t base_bits, Power_Mod::Usage_Hints hints)
Definition: pow_mod.cpp:110

The documentation for this class was generated from the following files: