Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

pow_mod.h
Go to the documentation of this file.
1 /*
2 * Modular Exponentiator
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_POWER_MOD_H_
9 #define BOTAN_POWER_MOD_H_
10
11 #include <botan/bigint.h>
12
13 BOTAN_FUTURE_INTERNAL_HEADER(pow_mod.h)
14
15 namespace Botan {
16
17 class Modular_Exponentiator;
18
19 /**
20 * Modular Exponentiator Proxy
21 */
22 class BOTAN_PUBLIC_API(2,0) Power_Mod
23 {
24 public:
25
26 enum Usage_Hints {
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 };
38
39 /*
40 * Try to choose a good window size
41 */
42 static size_t window_bits(size_t exp_bits, size_t base_bits,
43 Power_Mod::Usage_Hints hints);
44
45 /**
46 * @param modulus the modulus
47 * @param hints Passed to set_modulus if modulus > 0
48 * @param disable_montgomery_arith Disables use of Montgomery
49 * representation. Likely only useful for testing.
50 */
51 void set_modulus(const BigInt& modulus,
52 Usage_Hints hints = NO_HINTS,
53 bool disable_montgomery_arith = false) const;
54
55 /**
56 * Set the base
57 */
58 void set_base(const BigInt& base) const;
59
60 /**
61 * Set the exponent
62 */
63 void set_exponent(const BigInt& exponent) const;
64
65 /**
66 * All three of the above functions must have already been called.
67 * @return result of g^x%p
68 */
69 BigInt execute() const;
70
71 Power_Mod& operator=(const Power_Mod&);
72
73 /**
74 * @param modulus Optionally call set_modulus
75 * @param hints Passed to set_modulus if modulus > 0
76 * @param disable_montgomery_arith Disables use of Montgomery
77 * representation. Likely only useful for testing.
78 */
79 Power_Mod(const BigInt& modulus = 0,
80 Usage_Hints hints = NO_HINTS,
81 bool disable_montgomery_arith = false);
82 Power_Mod(const Power_Mod&);
83 virtual ~Power_Mod();
84 private:
85 mutable std::unique_ptr<Modular_Exponentiator> m_core;
86 };
87
88 /**
89 * Fixed Exponent Modular Exponentiator Proxy
90 */
91 class BOTAN_PUBLIC_API(2,0) Fixed_Exponent_Power_Mod final : public Power_Mod
92 {
93 public:
94 BigInt operator()(const BigInt& b) const
95 { set_base(b); return execute(); }
96
97 Fixed_Exponent_Power_Mod() = default;
98
99 Fixed_Exponent_Power_Mod(const BigInt& exponent,
100 const BigInt& modulus,
101 Usage_Hints hints = NO_HINTS);
102 };
103
104 /**
105 * Fixed Base Modular Exponentiator Proxy
106 */
107 class BOTAN_PUBLIC_API(2,0) Fixed_Base_Power_Mod final : public Power_Mod
108 {
109 public:
110 BigInt operator()(const BigInt& e) const
111 { set_exponent(e); return execute(); }
112
113 Fixed_Base_Power_Mod() = default;
114
115 Fixed_Base_Power_Mod(const BigInt& base,
116 const BigInt& modulus,
117 Usage_Hints hints = NO_HINTS);
118 };
119
120 }
121
122 #endif
Botan::Fixed_Base_Power_Mod
Definition: pow_mod.h:107
Botan::BigInt
Definition: bigint.h:24
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::Fixed_Exponent_Power_Mod::operator()
BigInt operator()(const BigInt &b) const
Definition: pow_mod.h:94
Botan::Fixed_Base_Power_Mod::operator()
BigInt operator()(const BigInt &e) const
Definition: pow_mod.h:110
Botan::Power_Mod
Definition: pow_mod.h:22
Botan::Power_Mod::set_exponent
void set_exponent(const BigInt &exponent) const
Definition: pow_mod.cpp:211
Botan
Definition: alg_id.cpp:13
Botan::Power_Mod::Usage_Hints
Usage_Hints
Definition: pow_mod.h:26
Botan::Fixed_Exponent_Power_Mod
Definition: pow_mod.h:91
Botan::Power_Mod::set_base
void set_base(const BigInt &base) const
Definition: pow_mod.cpp:198
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139
Botan::Power_Mod::execute
BigInt execute() const
Definition: pow_mod.cpp:224