Botan
1.11.15
|
00001 /* 00002 * Modular Exponentiation 00003 * (C) 1999-2007 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_DEFAULT_MODEXP_H__ 00009 #define BOTAN_DEFAULT_MODEXP_H__ 00010 00011 #include <botan/pow_mod.h> 00012 #include <botan/reducer.h> 00013 #include <vector> 00014 00015 namespace Botan { 00016 00017 /** 00018 * Fixed Window Exponentiator 00019 */ 00020 class Fixed_Window_Exponentiator : public Modular_Exponentiator 00021 { 00022 public: 00023 void set_exponent(const BigInt&); 00024 void set_base(const BigInt&); 00025 BigInt execute() const; 00026 00027 Modular_Exponentiator* copy() const 00028 { return new Fixed_Window_Exponentiator(*this); } 00029 00030 Fixed_Window_Exponentiator(const BigInt&, Power_Mod::Usage_Hints); 00031 private: 00032 Modular_Reducer reducer; 00033 BigInt exp; 00034 size_t window_bits; 00035 std::vector<BigInt> g; 00036 Power_Mod::Usage_Hints hints; 00037 }; 00038 00039 /** 00040 * Montgomery Exponentiator 00041 */ 00042 class Montgomery_Exponentiator : public Modular_Exponentiator 00043 { 00044 public: 00045 void set_exponent(const BigInt&); 00046 void set_base(const BigInt&); 00047 BigInt execute() const; 00048 00049 Modular_Exponentiator* copy() const 00050 { return new Montgomery_Exponentiator(*this); } 00051 00052 Montgomery_Exponentiator(const BigInt&, Power_Mod::Usage_Hints); 00053 private: 00054 BigInt m_exp, m_modulus, m_R_mod, m_R2_mod; 00055 word m_mod_prime; 00056 size_t m_mod_words, m_exp_bits, m_window_bits; 00057 Power_Mod::Usage_Hints m_hints; 00058 std::vector<BigInt> m_g; 00059 }; 00060 00061 } 00062 00063 #endif