Botan 1.10.17

pow_mod.h
Go to the documentation of this file.
1 /*
2 * Modular Exponentiator
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_POWER_MOD_H__
9 #define BOTAN_POWER_MOD_H__
10
11 #include <botan/bigint.h>
12
13 namespace Botan {
14
15 /**
16 * Modular Exponentiator Interface
17 */
18 class BOTAN_DLL Modular_Exponentiator
19 {
20 public:
21 virtual void set_base(const BigInt&) = 0;
22 virtual void set_exponent(const BigInt&) = 0;
23 virtual BigInt execute() const = 0;
24 virtual Modular_Exponentiator* copy() const = 0;
25 virtual ~Modular_Exponentiator() {}
26 };
27
28 /**
29 * Modular Exponentiator Proxy
30 */
31 class BOTAN_DLL Power_Mod
32 {
33 public:
34
35 enum Usage_Hints {
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 };
47
48 /*
49 * Try to choose a good window size
50 */
51 static size_t window_bits(size_t exp_bits, size_t base_bits,
52 Power_Mod::Usage_Hints hints);
53
54 void set_modulus(const BigInt&, Usage_Hints = NO_HINTS) const;
55 void set_base(const BigInt&) const;
56 void set_exponent(const BigInt&) const;
57
58 BigInt execute() const;
59
60 Power_Mod& operator=(const Power_Mod&);
61
62 Power_Mod(const BigInt& = 0, Usage_Hints = NO_HINTS);
63 Power_Mod(const Power_Mod&);
64 virtual ~Power_Mod();
65 private:
66 mutable Modular_Exponentiator* core;
67 Usage_Hints hints;
68 };
69
70 /**
71 * Fixed Exponent Modular Exponentiator Proxy
72 */
73 class BOTAN_DLL Fixed_Exponent_Power_Mod : public Power_Mod
74 {
75 public:
76 BigInt operator()(const BigInt& b) const
77 { set_base(b); return execute(); }
78
79 Fixed_Exponent_Power_Mod() {}
80 Fixed_Exponent_Power_Mod(const BigInt&, const BigInt&,
81 Usage_Hints = NO_HINTS);
82 };
83
84 /**
85 * Fixed Base Modular Exponentiator Proxy
86 */
87 class BOTAN_DLL Fixed_Base_Power_Mod : public Power_Mod
88 {
89 public:
90 BigInt operator()(const BigInt& e) const
91 { set_exponent(e); return execute(); }
92
93 Fixed_Base_Power_Mod() {}
94 Fixed_Base_Power_Mod(const BigInt&, const BigInt&,
95 Usage_Hints = NO_HINTS);
96 };
97
98 }
99
100 #endif
Botan::Fixed_Base_Power_Mod
Definition: pow_mod.h:87
Botan::BigInt
Definition: bigint.h:22
Botan::Modular_Exponentiator::~Modular_Exponentiator
virtual ~Modular_Exponentiator()
Definition: pow_mod.h:25
Botan::Fixed_Exponent_Power_Mod::operator()
BigInt operator()(const BigInt &b) const
Definition: pow_mod.h:76
Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod
Fixed_Exponent_Power_Mod()
Definition: pow_mod.h:79
Botan::Power_Mod
Definition: pow_mod.h:31
Botan
Definition: algo_base.h:14
Botan::Power_Mod::Usage_Hints
Usage_Hints
Definition: pow_mod.h:35
Botan::Fixed_Exponent_Power_Mod
Definition: pow_mod.h:73
Botan::Fixed_Base_Power_Mod::operator()
BigInt operator()(const BigInt &e) const
Definition: pow_mod.h:90
Botan::Fixed_Base_Power_Mod::Fixed_Base_Power_Mod
Fixed_Base_Power_Mod()
Definition: pow_mod.h:93
Botan::Modular_Exponentiator
Definition: pow_mod.h:18