Botan  2.13.0
Crypto and TLS for C++11
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Botan::Fixed_Base_Power_Mod Class Referencefinal

#include <pow_mod.h>

Inheritance diagram for Botan::Fixed_Base_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_Base_Power_Mod ()=default
 
 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 &base) const
 
void set_exponent (const BigInt &exponent) const
 
void set_modulus (const BigInt &modulus, Usage_Hints hints=NO_HINTS, bool disable_montgomery_arith=false) 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 Base Modular Exponentiator Proxy

Definition at line 107 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 26 of file pow_mod.h.

Constructor & Destructor Documentation

◆ Fixed_Base_Power_Mod() [1/2]

Botan::Fixed_Base_Power_Mod::Fixed_Base_Power_Mod ( )
default

◆ Fixed_Base_Power_Mod() [2/2]

Botan::Fixed_Base_Power_Mod::Fixed_Base_Power_Mod ( const BigInt base,
const BigInt modulus,
Usage_Hints  hints = NO_HINTS 
)

Definition at line 321 of file pow_mod.cpp.

References Botan::Power_Mod::set_base().

322  :
323  Power_Mod(n, Usage_Hints(hints | BASE_IS_FIXED | choose_base_hints(b, n)))
324  {
325  set_base(b);
326  }
Power_Mod(const BigInt &modulus=0, Usage_Hints hints=NO_HINTS, bool disable_montgomery_arith=false)
Definition: pow_mod.cpp:146
void set_base(const BigInt &base) const
Definition: pow_mod.cpp:198

Member Function Documentation

◆ execute()

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

All three of the above functions must have already been called.

Returns
result of g^xp

Definition at line 224 of file pow_mod.cpp.

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

225  {
226  if(!m_core)
227  throw Internal_Error("Power_Mod::execute: m_core was NULL");
228  return m_core->execute();
229  }

◆ operator()()

BigInt Botan::Fixed_Base_Power_Mod::operator() ( const BigInt e) const
inline

Definition at line 110 of file pow_mod.h.

References Botan::Power_Mod::execute(), and Botan::Power_Mod::set_exponent().

111  { set_exponent(e); return execute(); }
void set_exponent(const BigInt &exponent) const
Definition: pow_mod.cpp:211
BigInt execute() const
Definition: pow_mod.cpp:224

◆ set_base()

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

Set the base

Definition at line 198 of file pow_mod.cpp.

References Botan::BigInt::is_negative().

Referenced by Fixed_Base_Power_Mod(), and Botan::Fixed_Exponent_Power_Mod::operator()().

199  {
200  if(b.is_negative())
201  throw Invalid_Argument("Power_Mod::set_base: arg must be non-negative");
202 
203  if(!m_core)
204  throw Internal_Error("Power_Mod::set_base: m_core was NULL");
205  m_core->set_base(b);
206  }

◆ set_exponent()

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

Set the exponent

Definition at line 211 of file pow_mod.cpp.

References Botan::BigInt::is_negative().

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

212  {
213  if(e.is_negative())
214  throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0");
215 
216  if(!m_core)
217  throw Internal_Error("Power_Mod::set_exponent: m_core was NULL");
218  m_core->set_exponent(e);
219  }

◆ set_modulus()

void Botan::Power_Mod::set_modulus ( const BigInt modulus,
Usage_Hints  hints = NO_HINTS,
bool  disable_montgomery_arith = false 
) const
inherited
Parameters
modulusthe modulus
hintsPassed to set_modulus if modulus > 0
disable_montgomery_arithDisables use of Montgomery representation. Likely only useful for testing.

Definition at line 180 of file pow_mod.cpp.

References Botan::BigInt::is_odd().

181  {
182  // Allow set_modulus(0) to mean "drop old state"
183 
184  m_core.reset();
185 
186  if(n != 0)
187  {
188  if(n.is_odd() && disable_monty == false)
189  m_core.reset(new Montgomery_Exponentiator(n, hints));
190  else
191  m_core.reset(new Fixed_Window_Exponentiator(n, hints));
192  }
193  }

◆ 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 234 of file pow_mod.cpp.

236  {
237  static const size_t wsize[][2] = {
238  { 1434, 7 },
239  { 539, 6 },
240  { 197, 4 },
241  { 70, 3 },
242  { 17, 2 },
243  { 0, 0 }
244  };
245 
246  size_t window_bits = 1;
247 
248  if(exp_bits)
249  {
250  for(size_t j = 0; wsize[j][0]; ++j)
251  {
252  if(exp_bits >= wsize[j][0])
253  {
254  window_bits += wsize[j][1];
255  break;
256  }
257  }
258  }
259 
260  if(hints & Power_Mod::BASE_IS_FIXED)
261  window_bits += 2;
262  if(hints & Power_Mod::EXP_IS_LARGE)
263  ++window_bits;
264 
265  return window_bits;
266  }
static size_t window_bits(size_t exp_bits, size_t base_bits, Power_Mod::Usage_Hints hints)
Definition: pow_mod.cpp:234

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