Botan  1.11.16
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

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

Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod ( )
inline

Definition at line 78 of file pow_mod.h.

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

Definition at line 181 of file pow_mod.cpp.

References Botan::Power_Mod::set_exponent().

183  :
184  Power_Mod(n, Usage_Hints(hints | EXP_IS_FIXED | choose_exp_hints(e, n)))
185  {
186  set_exponent(e);
187  }
const BigInt & n
Definition: rsa.cpp:107
const BigInt & e
Definition: rw.cpp:97
Power_Mod(const BigInt &=0, Usage_Hints=NO_HINTS)
Definition: pow_mod.cpp:16
void set_exponent(const BigInt &) const
Definition: pow_mod.cpp:82

Member Function Documentation

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().

96  {
97  if(!core)
98  throw Internal_Error("Power_Mod::execute: core was NULL");
99  return core->execute();
100  }
virtual BigInt execute() const =0
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(); }
void set_base(const BigInt &) const
Definition: pow_mod.cpp:69
BigInt execute() const
Definition: pow_mod.cpp:95
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 Botan::Fixed_Base_Power_Mod::Fixed_Base_Power_Mod(), and Botan::power_mod().

70  {
71  if(b.is_zero() || b.is_negative())
72  throw Invalid_Argument("Power_Mod::set_base: arg must be > 0");
73 
74  if(!core)
75  throw Internal_Error("Power_Mod::set_base: core was NULL");
76  core->set_base(b);
77  }
virtual void set_base(const BigInt &)=0
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
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 Fixed_Exponent_Power_Mod(), and Botan::power_mod().

83  {
84  if(e.is_negative())
85  throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0");
86 
87  if(!core)
88  throw Internal_Error("Power_Mod::set_exponent: core was NULL");
89  core->set_exponent(e);
90  }
virtual void set_exponent(const BigInt &)=0
const BigInt & e
Definition: rw.cpp:97
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
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().

57  {
58  delete core;
59 
60  if(n.is_odd())
61  core = new Montgomery_Exponentiator(n, hints);
62  else if(n != 0)
63  core = new Fixed_Window_Exponentiator(n, hints);
64  }
const BigInt & n
Definition: rsa.cpp:107
size_t Botan::Power_Mod::window_bits ( size_t  exp_bits,
size_t  base_bits,
Power_Mod::Usage_Hints  hints 
)
staticinherited

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().

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

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