monotone

monotone Mtn Source Tree

Root/botan/pow_mod.h

1/*************************************************
2* Modular Exponentiator Header File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_POWER_MOD_H__
7#define BOTAN_POWER_MOD_H__
8
9#include <botan/bigint.h>
10
11namespace Botan {
12
13/*************************************************
14* Modular Exponentiator Interface *
15*************************************************/
16class Modular_Exponentiator
17 {
18 public:
19 virtual void set_base(const BigInt&) = 0;
20 virtual void set_exponent(const BigInt&) = 0;
21 virtual BigInt execute() const = 0;
22 virtual Modular_Exponentiator* copy() const = 0;
23 virtual ~Modular_Exponentiator() {}
24 };
25
26/*************************************************
27* Modular Exponentiator Proxy *
28*************************************************/
29class Power_Mod
30 {
31 public:
32 enum Usage_Hints {
33 NO_HINTS = 0x0000,
34
35 BASE_IS_FIXED = 0x0001,
36 BASE_IS_SMALL = 0x0002,
37 BASE_IS_LARGE = 0x0004,
38 BASE_IS_2 = 0x0008,
39
40 EXP_IS_FIXED = 0x0100,
41 EXP_IS_SMALL = 0x0200,
42 EXP_IS_LARGE = 0x0400
43 };
44
45 void set_modulus(const BigInt&, Usage_Hints = NO_HINTS) const;
46 void set_base(const BigInt&) const;
47 void set_exponent(const BigInt&) const;
48
49 BigInt execute() const;
50
51 Power_Mod& operator=(const Power_Mod&);
52
53 Power_Mod(const BigInt& = 0, Usage_Hints = NO_HINTS);
54 Power_Mod(const Power_Mod&);
55 ~Power_Mod();
56 private:
57 mutable Modular_Exponentiator* core;
58 Usage_Hints hints;
59 };
60
61/*************************************************
62* Fixed Exponent Modular Exponentiator Proxy *
63*************************************************/
64class Fixed_Exponent_Power_Mod : public Power_Mod
65 {
66 public:
67 BigInt operator()(const BigInt& b) const
68 { set_base(b); return execute(); }
69
70 Fixed_Exponent_Power_Mod() {}
71 Fixed_Exponent_Power_Mod(const BigInt&, const BigInt&,
72 Usage_Hints = NO_HINTS);
73 };
74
75/*************************************************
76* Fixed Base Modular Exponentiator Proxy *
77*************************************************/
78class Fixed_Base_Power_Mod : public Power_Mod
79 {
80 public:
81 BigInt operator()(const BigInt& e) const
82 { set_exponent(e); return execute(); }
83
84 Fixed_Base_Power_Mod() {}
85 Fixed_Base_Power_Mod(const BigInt&, const BigInt&,
86 Usage_Hints = NO_HINTS);
87 };
88
89}
90
91#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status