Botan 1.10.17

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 &=0, Usage_Hints=NO_HINTS)
| Power_Mod (const Power_Mod &)
void | set_base (const BigInt &) const
void | set_exponent (const BigInt &) const
void | set_modulus (const BigInt &, Usage_Hints=NO_HINTS) 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 31 of file pow_mod.h.

## Member Enumeration Documentation

## ◆ Usage_Hints

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 35 of file pow_mod.h.

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

## Constructor & Destructor Documentation

## ◆ Power_Mod() [1/2]

Botan::Power_Mod::Power_Mod | ( | const BigInt & | n = `0`,
|  | Usage_Hints | hints = `NO_HINTS`
| ) |  |

Definition at line 17 of file pow_mod.cpp.

18 {
19 core = 0;
20 set_modulus(n, hints);
21 hints = NO_HINTS;
22 }
Botan::Power_Mod::NO_HINTS
Definition: pow_mod.h:36
Botan::Power_Mod::set_modulus
void set_modulus(const BigInt &, Usage_Hints=NO_HINTS) const
Definition: pow_mod.cpp:58

## ◆ Power_Mod() [2/2]

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

Definition at line 27 of file pow_mod.cpp.

References Botan::Modular_Exponentiator::copy().

28 {
29 core = 0;
30 hints = other.hints;
31 if(other.core)
32 core = other.core->copy();
33 }
Botan::Modular_Exponentiator::copy
virtual Modular_Exponentiator * copy() const =0

## ◆ ~Power_Mod()

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

Definition at line 50 of file pow_mod.cpp.

51 {
52 delete core;
53 }

## Member Function Documentation

## ◆ execute()

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

Definition at line 109 of file pow_mod.cpp.

References Botan::Modular_Exponentiator::execute().

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

## ◆ operator=()

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

Definition at line 38 of file pow_mod.cpp.

References Botan::Modular_Exponentiator::copy().

39 {
40 delete core;
41 core = 0;
42 if(other.core)
43 core = other.core->copy();
44 return (*this);
45 }
Botan::Modular_Exponentiator::copy
virtual Modular_Exponentiator * copy() const =0

## ◆ set_base()

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

Definition at line 83 of file pow_mod.cpp.

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

84 {
85 if(b.is_zero() || b.is_negative())
86 throw Invalid_Argument("Power_Mod::set_base: arg must be > 0");
87
88 if(!core)
89 throw Internal_Error("Power_Mod::set_base: core was NULL");
90 core->set_base(b);
91 }
Botan::Modular_Exponentiator::set_base
virtual void set_base(const BigInt &)=0
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20

## ◆ set_exponent()

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

Definition at line 96 of file pow_mod.cpp.

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

97 {
98 if(e.is_negative())
99 throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0");
100
101 if(!core)
102 throw Internal_Error("Power_Mod::set_exponent: core was NULL");
103 core->set_exponent(e);
104 }
Botan::Modular_Exponentiator::set_exponent
virtual void set_exponent(const BigInt &)=0
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20

## ◆ set_modulus()

void Botan::Power_Mod::set_modulus | ( | const BigInt & | n,
|  | Usage_Hints | hints = `NO_HINTS`
| ) |  | const

Definition at line 58 of file pow_mod.cpp.

59 {
60 delete core;
61 core = 0;
62
63 if(n != 0)
64 {
65 Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
66
67 while(const Engine* engine = i.next())
68 {
69 core = engine->mod_exp(n, hints);
70
71 if(core)
72 break;
73 }
74
75 if(!core)
76 throw Lookup_Error("Power_Mod: Unable to find a working engine");
77 }
78 }
Botan::Algorithm_Factory::Engine_Iterator
friend class Engine_Iterator
Definition: algo_factory.h:207
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32

## ◆ window_bits()

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

Definition at line 119 of file pow_mod.cpp.

References BASE_IS_FIXED, and EXP_IS_LARGE.

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

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

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