Botan  2.4.0
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 Referencefinal

#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 ()=default
 
 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 &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 Exponent Modular Exponentiator Proxy

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

Constructor & Destructor Documentation

◆ Fixed_Exponent_Power_Mod() [1/2]

Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod ( )
default

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

References Botan::Power_Mod::set_exponent().

180  :
181  Power_Mod(n, Usage_Hints(hints | EXP_IS_FIXED | choose_exp_hints(e, n)))
182  {
183  set_exponent(e);
184  }
Power_Mod(const BigInt &modulus=0, Usage_Hints hints=NO_HINTS, bool disable_montgomery_arith=false)
Definition: pow_mod.cpp:16
void set_exponent(const BigInt &exponent) const
Definition: pow_mod.cpp:79

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

Referenced by Botan::power_mod().

93  {
94  if(!m_core)
95  throw Internal_Error("Power_Mod::execute: m_core was NULL");
96  return m_core->execute();
97  }

◆ operator()()

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

Definition at line 107 of file pow_mod.h.

108  { set_base(b); return execute(); }
BigInt execute() const
Definition: pow_mod.cpp:92
void set_base(const BigInt &base) const
Definition: pow_mod.cpp:66

◆ set_base()

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

Set the base

Definition at line 66 of file pow_mod.cpp.

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

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

67  {
68  if(b.is_zero() || b.is_negative())
69  throw Invalid_Argument("Power_Mod::set_base: arg must be > 0");
70 
71  if(!m_core)
72  throw Internal_Error("Power_Mod::set_base: m_core was NULL");
73  m_core->set_base(b);
74  }

◆ set_exponent()

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

Set the exponent

Definition at line 79 of file pow_mod.cpp.

References Botan::BigInt::is_negative().

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

80  {
81  if(e.is_negative())
82  throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0");
83 
84  if(!m_core)
85  throw Internal_Error("Power_Mod::set_exponent: m_core was NULL");
86  m_core->set_exponent(e);
87  }

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

References Botan::BigInt::is_odd().

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

49  {
50  // Allow set_modulus(0) to mean "drop old state"
51 
52  m_core.reset();
53 
54  if(n != 0)
55  {
56  if(n.is_odd() && disable_monty == false)
57  m_core.reset(new Montgomery_Exponentiator(n, hints));
58  else
59  m_core.reset(new Fixed_Window_Exponentiator(n, hints));
60  }
61  }

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

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

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