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
13namespace Botan {
14
15/**
16* Modular Exponentiator Interface
17*/
18class 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;
26 };
27
28/**
29* Modular Exponentiator Proxy
30*/
31class BOTAN_DLL Power_Mod
32 {
33 public:
34
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,
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*/
73class 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
81 Usage_Hints = NO_HINTS);
82 };
83
84/**
85* Fixed Base Modular Exponentiator Proxy
86*/
87class 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
94 Fixed_Base_Power_Mod(const BigInt&, const BigInt&,
95 Usage_Hints = NO_HINTS);
96 };
97
98}
99
100#endif
BigInt operator()(const BigInt &e) const
Definition pow_mod.h:90
BigInt operator()(const BigInt &b) const
Definition pow_mod.h:76
virtual ~Modular_Exponentiator()
Definition pow_mod.h:25
virtual void set_exponent(const BigInt &)=0
virtual BigInt execute() const =0
virtual Modular_Exponentiator * copy() const =0
virtual void set_base(const BigInt &)=0
void set_exponent(const BigInt &) const
Definition pow_mod.cpp:96
BigInt execute() const
Definition pow_mod.cpp:109
void set_base(const BigInt &) const
Definition pow_mod.cpp:83
Power_Mod(const BigInt &=0, Usage_Hints=NO_HINTS)
Definition pow_mod.cpp:17