summaryrefslogtreecommitdiffstats
path: root/botan/src/math/numbertheory/pow_mod.h
diff options
context:
space:
mode:
authorKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
committerKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
commit9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch)
tree63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/src/math/numbertheory/pow_mod.h
parent619d92cfef29e653bfdf852e83888e50cfc4348f (diff)
parent65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff)
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/src/math/numbertheory/pow_mod.h')
-rw-r--r--botan/src/math/numbertheory/pow_mod.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/botan/src/math/numbertheory/pow_mod.h b/botan/src/math/numbertheory/pow_mod.h
new file mode 100644
index 0000000..6952dcd
--- /dev/null
+++ b/botan/src/math/numbertheory/pow_mod.h
@@ -0,0 +1,93 @@
+/*
+* Modular Exponentiator
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_POWER_MOD_H__
+#define BOTAN_POWER_MOD_H__
+
+#include <botan/bigint.h>
+
+namespace Botan {
+
+/*
+* Modular Exponentiator Interface
+*/
+class BOTAN_DLL Modular_Exponentiator
+ {
+ public:
+ virtual void set_base(const BigInt&) = 0;
+ virtual void set_exponent(const BigInt&) = 0;
+ virtual BigInt execute() const = 0;
+ virtual Modular_Exponentiator* copy() const = 0;
+ virtual ~Modular_Exponentiator() {}
+ };
+
+/*
+* Modular Exponentiator Proxy
+*/
+class BOTAN_DLL Power_Mod
+ {
+ public:
+ 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
+ };
+
+ void set_modulus(const BigInt&, Usage_Hints = NO_HINTS) const;
+ void set_base(const BigInt&) const;
+ void set_exponent(const BigInt&) const;
+
+ BigInt execute() const;
+
+ Power_Mod& operator=(const Power_Mod&);
+
+ Power_Mod(const BigInt& = 0, Usage_Hints = NO_HINTS);
+ Power_Mod(const Power_Mod&);
+ ~Power_Mod();
+ private:
+ mutable Modular_Exponentiator* core;
+ Usage_Hints hints;
+ };
+
+/*
+* Fixed Exponent Modular Exponentiator Proxy
+*/
+class BOTAN_DLL Fixed_Exponent_Power_Mod : public Power_Mod
+ {
+ public:
+ BigInt operator()(const BigInt& b) const
+ { set_base(b); return execute(); }
+
+ Fixed_Exponent_Power_Mod() {}
+ Fixed_Exponent_Power_Mod(const BigInt&, const BigInt&,
+ Usage_Hints = NO_HINTS);
+ };
+
+/*
+* Fixed Base Modular Exponentiator Proxy
+*/
+class BOTAN_DLL Fixed_Base_Power_Mod : public Power_Mod
+ {
+ public:
+ BigInt operator()(const BigInt& e) const
+ { set_exponent(e); return execute(); }
+
+ Fixed_Base_Power_Mod() {}
+ Fixed_Base_Power_Mod(const BigInt&, const BigInt&,
+ Usage_Hints = NO_HINTS);
+ };
+
+}
+
+#endif