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

#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

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

Definition at line 61 of file powm_fw.cpp.

Referenced by copy().

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

Member Function Documentation

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:61
BigInt Botan::Fixed_Window_Exponentiator::execute ( ) const
overridevirtual

Implements Botan::Modular_Exponentiator.

Definition at line 40 of file powm_fw.cpp.

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

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

Implements Botan::Modular_Exponentiator.

Definition at line 25 of file powm_fw.cpp.

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

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

Implements Botan::Modular_Exponentiator.

Definition at line 17 of file powm_fw.cpp.

18  {
19  m_exp = e;
20  }

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