Botan 2.13.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::Power_Mod Class Reference

`#include <pow_mod.h>`

Inheritance diagram for 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
Power_Mod & | operator= (const Power_Mod &)
| Power_Mod (const BigInt &modulus=0, Usage_Hints hints=NO_HINTS, bool disable_montgomery_arith=false)
| Power_Mod (const Power_Mod &)
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
virtual | ~Power_Mod ()

## Static Public Member Functions
static size_t | window_bits (size_t exp_bits, size_t base_bits, Power_Mod::Usage_Hints hints)

## Detailed Description

Modular Exponentiator Proxy

Definition at line 22 of file pow_mod.h.

## Member Enumeration Documentation

enum Botan::Power_Mod::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 26 of file pow_mod.h.

26 {
27 NO_HINTS = 0x0000,
28
29 BASE_IS_FIXED = 0x0001,
30 BASE_IS_SMALL = 0x0002,
31 BASE_IS_LARGE = 0x0004,
32 BASE_IS_2 = 0x0008,
33
34 EXP_IS_FIXED = 0x0100,
35 EXP_IS_SMALL = 0x0200,
36 EXP_IS_LARGE = 0x0400
37 };
Botan::Power_Mod::BASE_IS_LARGE
Definition: pow_mod.h:31
Botan::Power_Mod::BASE_IS_SMALL
Definition: pow_mod.h:30
Botan::Power_Mod::EXP_IS_FIXED
Definition: pow_mod.h:34
Botan::Power_Mod::EXP_IS_SMALL
Definition: pow_mod.h:35
Botan::Power_Mod::NO_HINTS
Definition: pow_mod.h:27
Botan::Power_Mod::BASE_IS_2
Definition: pow_mod.h:32
Botan::Power_Mod::BASE_IS_FIXED
Definition: pow_mod.h:29
Botan::Power_Mod::EXP_IS_LARGE
Definition: pow_mod.h:36

## Constructor & Destructor Documentation

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

Parameters

  modulus | Optionally call set_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 146 of file pow_mod.cpp.

147 {
148 set_modulus(n, hints, disable_monty);
149 }
Botan::Power_Mod::set_modulus
void set_modulus(const BigInt &modulus, Usage_Hints hints=NO_HINTS, bool disable_montgomery_arith=false) const
Definition: pow_mod.cpp:180

Botan::Power_Mod::Power_Mod | ( | const Power_Mod & | other | ) |

Definition at line 156 of file pow_mod.cpp.

157 {
158 if(other.m_core.get())
159 m_core.reset(other.m_core->copy());
160 }

Botan::Power_Mod::~Power_Mod | ( |  | ) |
| virtual

Definition at line 151 of file pow_mod.cpp.

151 { /* for ~unique_ptr */ }

## Member Function Documentation

BigInt Botan::Power_Mod::execute | ( |  | ) | const

All three of the above functions must have already been called.

Returns
  result of g^xp

Definition at line 224 of file pow_mod.cpp.

Referenced by Botan::Fixed_Exponent_Power_Mod::operator()(), and Botan::Fixed_Base_Power_Mod::operator()().

225 {
226 if(!m_core)
227 throw Internal_Error("Power_Mod::execute: m_core was NULL");
228 return m_core->execute();
229 }
Botan::OCSP::Response_Status_Code::Internal_Error

Power_Mod & Botan::Power_Mod::operator= | ( | const Power_Mod & | other | ) |

Definition at line 165 of file pow_mod.cpp.

166 {
167 if(this != &other)
168 {
169 if(other.m_core)
170 m_core.reset(other.m_core->copy());
171 else
172 m_core.reset();
173 }
174 return (*this);
175 }

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

Set the base

Definition at line 198 of file pow_mod.cpp.

References Botan::BigInt::is_negative().

Referenced by Botan::Fixed_Base_Power_Mod::Fixed_Base_Power_Mod(), and Botan::Fixed_Exponent_Power_Mod::operator()().

199 {
200 if(b.is_negative())
201 throw Invalid_Argument("Power_Mod::set_base: arg must be non-negative");
202
203 if(!m_core)
204 throw Internal_Error("Power_Mod::set_base: m_core was NULL");
205 m_core->set_base(b);
206 }
Botan::OCSP::Response_Status_Code::Internal_Error

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

Set the exponent

Definition at line 211 of file pow_mod.cpp.

References Botan::BigInt::is_negative().

Referenced by Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod(), and Botan::Fixed_Base_Power_Mod::operator()().

212 {
213 if(e.is_negative())
214 throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0");
215
216 if(!m_core)
217 throw Internal_Error("Power_Mod::set_exponent: m_core was NULL");
218 m_core->set_exponent(e);
219 }
Botan::OCSP::Response_Status_Code::Internal_Error

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

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

References Botan::BigInt::is_odd().

181 {
182 // Allow set_modulus(0) to mean "drop old state"
183
184 m_core.reset();
185
186 if(n != 0)
187 {
188 if(n.is_odd() && disable_monty == false)
189 m_core.reset(new Montgomery_Exponentiator(n, hints));
190 else
191 m_core.reset(new Fixed_Window_Exponentiator(n, hints));
192 }
193 }

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

Definition at line 234 of file pow_mod.cpp.

236 {
237 static const size_t wsize[][2] = {
238 { 1434, 7 },
239 { 539, 6 },
240 { 197, 4 },
241 { 70, 3 },
242 { 17, 2 },
243 { 0, 0 }
244 };
245
246 size_t window_bits = 1;
247
248 if(exp_bits)
249 {
250 for(size_t j = 0; wsize[j][0]; ++j)
251 {
252 if(exp_bits >= wsize[j][0])
253 {
254 window_bits += wsize[j][1];
255 break;
256 }
257 }
258 }
259
260 if(hints & Power_Mod::BASE_IS_FIXED)
261 window_bits += 2;
262 if(hints & Power_Mod::EXP_IS_LARGE)
263 ++window_bits;
264
265 return window_bits;
266 }
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:234
Botan::Power_Mod::BASE_IS_FIXED
Definition: pow_mod.h:29
Botan::Power_Mod::EXP_IS_LARGE
Definition: pow_mod.h:36

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