Botan  2.6.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::Fixed_Window_Exponentiator Class Referencefinal

#include <def_powm.h>

Inheritance diagram for Botan::Fixed_Window_Exponentiator:
Botan::Modular_Exponentiator

Public Member Functions

Modular_Exponentiatorcopy () const override
 
BigInt execute () const override
 
 Fixed_Window_Exponentiator (const BigInt &, Power_Mod::Usage_Hints)
 
void set_base (const BigInt &) override
 
void set_exponent (const BigInt &) override
 

Detailed Description

Fixed Window Exponentiator

Definition at line 20 of file def_powm.h.

Constructor & Destructor Documentation

◆ Fixed_Window_Exponentiator()

Botan::Fixed_Window_Exponentiator::Fixed_Window_Exponentiator ( const BigInt n,
Power_Mod::Usage_Hints  hints 
)

Definition at line 60 of file powm_fw.cpp.

Referenced by copy().

62  : m_reducer{Modular_Reducer(n)}, m_exp{}, m_window_bits{}, m_g{}, m_hints{hints}
63  {}

Member Function Documentation

◆ copy()

Modular_Exponentiator* Botan::Fixed_Window_Exponentiator::copy ( ) const
inlineoverridevirtual

Implements Botan::Modular_Exponentiator.

Definition at line 27 of file def_powm.h.

References Fixed_Window_Exponentiator().

28  { return new Fixed_Window_Exponentiator(*this); }
Fixed_Window_Exponentiator(const BigInt &, Power_Mod::Usage_Hints)
Definition: powm_fw.cpp:60

◆ execute()

BigInt Botan::Fixed_Window_Exponentiator::execute ( ) const
overridevirtual

Implements Botan::Modular_Exponentiator.

Definition at line 39 of file powm_fw.cpp.

References Botan::BigInt::bits(), Botan::BigInt::get_substring(), Botan::Modular_Reducer::multiply(), and Botan::Modular_Reducer::square().

40  {
41  const size_t exp_nibbles = (m_exp.bits() + m_window_bits - 1) / m_window_bits;
42 
43  BigInt x = 1;
44 
45  for(size_t i = exp_nibbles; i > 0; --i)
46  {
47  for(size_t j = 0; j != m_window_bits; ++j)
48  x = m_reducer.square(x);
49 
50  const uint32_t nibble = m_exp.get_substring(m_window_bits*(i-1), m_window_bits);
51 
52  x = m_reducer.multiply(x, m_g[nibble]);
53  }
54  return x;
55  }
size_t bits() const
Definition: bigint.cpp:216
uint32_t get_substring(size_t offset, size_t length) const
Definition: bigint.cpp:152
BigInt square(const BigInt &x) const
Definition: reducer.h:39
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31

◆ set_base()

void Botan::Fixed_Window_Exponentiator::set_base ( const BigInt base)
overridevirtual

Implements Botan::Modular_Exponentiator.

Definition at line 24 of file powm_fw.cpp.

References Botan::BigInt::bits(), Botan::Modular_Reducer::multiply(), and Botan::Power_Mod::window_bits().

25  {
26  m_window_bits = Power_Mod::window_bits(m_exp.bits(), base.bits(), m_hints);
27 
28  m_g.resize(1U << m_window_bits);
29  m_g[0] = 1;
30  m_g[1] = base;
31 
32  for(size_t i = 2; i != m_g.size(); ++i)
33  m_g[i] = m_reducer.multiply(m_g[i-1], m_g[1]);
34  }
size_t bits() const
Definition: bigint.cpp:216
static size_t window_bits(size_t exp_bits, size_t base_bits, Power_Mod::Usage_Hints hints)
Definition: pow_mod.cpp:102
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31

◆ set_exponent()

void Botan::Fixed_Window_Exponentiator::set_exponent ( const BigInt e)
overridevirtual

Implements Botan::Modular_Exponentiator.

Definition at line 16 of file powm_fw.cpp.

17  {
18  m_exp = e;
19  }

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