Botan  1.10.9
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
 
BigInt execute () const
 
 Fixed_Window_Exponentiator (const BigInt &, Power_Mod::Usage_Hints)
 
void set_base (const BigInt &)
 
void set_exponent (const BigInt &)
 

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  {
64  reducer = Modular_Reducer(n);
65  this->hints = hints;
66  window_bits = 0;
67  }
BigInt n
Definition: numthry.cpp:26

Member Function Documentation

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

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
virtual

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 = (exp.bits() + window_bits - 1) / 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 != window_bits; ++j)
49  x = reducer.square(x);
50 
51  const u32bit nibble = exp.get_substring(window_bits*(i-1), window_bits);
52 
53  x = reducer.multiply(x, g[nibble]);
54  }
55  return x;
56  }
u32bit get_substring(size_t offset, size_t length) const
Definition: bigint.cpp:168
size_t bits() const
Definition: bigint.cpp:253
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31
BigInt square(const BigInt &x) const
Definition: reducer.h:39
unsigned int u32bit
Definition: types.h:32
void Botan::Fixed_Window_Exponentiator::set_base ( const BigInt base)
virtual

Implements Botan::Modular_Exponentiator.

Definition at line 25 of file powm_fw.cpp.

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

26  {
27  window_bits = Power_Mod::window_bits(exp.bits(), base.bits(), hints);
28 
29  g.resize((1 << window_bits));
30  g[0] = 1;
31  g[1] = base;
32 
33  for(size_t i = 2; i != g.size(); ++i)
34  g[i] = reducer.multiply(g[i-1], g[0]);
35  }
size_t bits() const
Definition: bigint.cpp:253
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:119
GMP_MPZ base
Definition: gmp_powm.cpp:29
void Botan::Fixed_Window_Exponentiator::set_exponent ( const BigInt e)
virtual

Implements Botan::Modular_Exponentiator.

Definition at line 17 of file powm_fw.cpp.

18  {
19  exp = e;
20  }

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