Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | List of all members
Botan::Fixed_Exponent_Power_Mod Class Reference

`#include <pow_mod.h>`

Inheritance diagram for Botan::Fixed_Exponent_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=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

enum Botan::Power_Mod::Usage_Hints
| inherited

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.

39 {
40 NO_HINTS = 0x0000,
41
42 BASE_IS_FIXED = 0x0001,
43 BASE_IS_SMALL = 0x0002,
44 BASE_IS_LARGE = 0x0004,
45 BASE_IS_2 = 0x0008,
46
47 EXP_IS_FIXED = 0x0100,
48 EXP_IS_SMALL = 0x0200,
49 EXP_IS_LARGE = 0x0400
50 };
Botan::Power_Mod::BASE_IS_LARGE
Definition: pow_mod.h:44
Botan::Power_Mod::BASE_IS_SMALL
Definition: pow_mod.h:43
Botan::Power_Mod::EXP_IS_FIXED
Definition: pow_mod.h:47
Botan::Power_Mod::EXP_IS_SMALL
Definition: pow_mod.h:48
Botan::Power_Mod::NO_HINTS
Definition: pow_mod.h:40
Botan::Power_Mod::BASE_IS_2
Definition: pow_mod.h:45
Botan::Power_Mod::BASE_IS_FIXED
Definition: pow_mod.h:42
Botan::Power_Mod::EXP_IS_LARGE
Definition: pow_mod.h:49

## Constructor & Destructor Documentation

Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod | ( |  | ) |
| default

Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod | ( | const BigInt & | exponent,
|  | const BigInt & | modulus,
|  | Usage_Hints | hints = `NO_HINTS`
| ) |  |

Definition at line 193 of file pow_mod.cpp.

References Botan::Power_Mod::set_exponent().

195 :
196 Power_Mod(n, Usage_Hints(hints | EXP_IS_FIXED | choose_exp_hints(e, n)))
197 {
198 set_exponent(e);
199 }
Botan::Power_Mod::EXP_IS_FIXED
Definition: pow_mod.h:47
Botan::Power_Mod::Power_Mod
Power_Mod(const BigInt &modulus=0, Usage_Hints hints=NO_HINTS, bool disable_montgomery_arith=false)
Definition: pow_mod.cpp:16
Botan::Power_Mod::set_exponent
void set_exponent(const BigInt &exponent) const
Definition: pow_mod.cpp:94
Botan::Power_Mod::Usage_Hints
Usage_Hints
Definition: pow_mod.h:39

## Member Function Documentation

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

References Botan::Modular_Exponentiator::execute().

Referenced by Botan::power_mod().

108 {
109 if(!m_core)
110 throw Internal_Error("Power_Mod::execute: m_core was NULL");
111 return m_core->execute();
112 }
Botan::Modular_Exponentiator::execute
virtual BigInt execute() const =0

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(); }
Botan::Power_Mod::set_base
void set_base(const BigInt &base) const
Definition: pow_mod.cpp:81
Botan::Power_Mod::execute
BigInt execute() const
Definition: pow_mod.cpp:107

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

Set the base

Definition at line 81 of file pow_mod.cpp.

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

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

82 {
83 if(b.is_zero() || b.is_negative())
84 throw Invalid_Argument("Power_Mod::set_base: arg must be > 0");
85
86 if(!m_core)
87 throw Internal_Error("Power_Mod::set_base: m_core was NULL");
88 m_core->set_base(b);
89 }
Botan::Modular_Exponentiator::set_base
virtual void set_base(const BigInt &)=0

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

Set the exponent

Definition at line 94 of file pow_mod.cpp.

References Botan::BigInt::is_negative(), and Botan::Modular_Exponentiator::set_exponent().

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

95 {
96 if(e.is_negative())
97 throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0");
98
99 if(!m_core)
100 throw Internal_Error("Power_Mod::set_exponent: m_core was NULL");
101 m_core->set_exponent(e);
102 }
Botan::Modular_Exponentiator::set_exponent
virtual void set_exponent(const BigInt &)=0

void Botan::Power_Mod::set_modulus | ( | const BigInt & | modulus,
|  | Usage_Hints | hints = `NO_HINTS`,
|  | bool | disable_montgomery_arith = `false`
| ) |  | const
| inherited

Parameters

  modulus | the modulus
  hints | Passed to set_modulus if modulus > 0
  disable_montgomery_arith | Disables use of Montgomery representation. Likely only useful for testing.

Definition at line 61 of file pow_mod.cpp.

References Botan::BigInt::is_odd().

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

62 {
63 // Allow set_modulus(0) to mean "drop old state"
64
65 delete m_core;
66 m_core = nullptr;
67
68 if(n != 0)
69 {
70 if(n.is_odd() && disable_monty == false)
71 m_core = new Montgomery_Exponentiator(n, hints);
72
73 if(!m_core)
74 m_core = new Fixed_Window_Exponentiator(n, hints);
75 }
76 }

size_t Botan::Power_Mod::window_bits | ( | size_t | exp_bits,
|  | size_t | base_bits,
|  | Power_Mod::Usage_Hints | hints
| ) |  |
| static inherited

Definition at line 117 of file pow_mod.cpp.

References Botan::Power_Mod::BASE_IS_FIXED, and Botan::Power_Mod::EXP_IS_LARGE.

Referenced by Botan::Fixed_Window_Exponentiator::set_base(), and Botan::Montgomery_Exponentiator::set_base().

119 {
120 static const size_t wsize[][2] = {
121 { 1434, 7 },
122 { 539, 6 },
123 { 197, 4 },
124 { 70, 3 },
125 { 25, 2 },
126 { 0, 0 }
127 };
128
129 size_t window_bits = 1;
130
131 if(exp_bits)
132 {
133 for(size_t j = 0; wsize[j][0]; ++j)
134 {
135 if(exp_bits >= wsize[j][0])
136 {
137 window_bits += wsize[j][1];
138 break;
139 }
140 }
141 }
142
143 if(hints & Power_Mod::BASE_IS_FIXED)
144 window_bits += 2;
145 if(hints & Power_Mod::EXP_IS_LARGE)
146 ++window_bits;
147
148 return window_bits;
149 }
Botan::Power_Mod::window_bits
static size_t window_bits(size_t exp_bits, size_t base_bits, Power_Mod::Usage_Hints hints)
Definition: pow_mod.cpp:117
Botan::Power_Mod::BASE_IS_FIXED
Definition: pow_mod.h:42
Botan::Power_Mod::EXP_IS_LARGE
Definition: pow_mod.h:49

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

- src/lib/math/numbertheory/pow_mod.h
- src/lib/math/numbertheory/pow_mod.cpp