diff options
author | lloyd <[email protected]> | 2008-09-28 19:29:24 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 19:29:24 +0000 |
commit | 9bcfe627321ddc81691b835dffaa6324ac4684a4 (patch) | |
tree | fe5e8ae9813b853549558b59833022e87e83981b /src/engine/gnump/gmp_powm.cpp | |
parent | 9822a701516396b7de4e41339faecd48ff8dc8ff (diff) |
Move all modules into src/ directory
Diffstat (limited to 'src/engine/gnump/gmp_powm.cpp')
-rw-r--r-- | src/engine/gnump/gmp_powm.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/engine/gnump/gmp_powm.cpp b/src/engine/gnump/gmp_powm.cpp new file mode 100644 index 000000000..a5e3d1c0d --- /dev/null +++ b/src/engine/gnump/gmp_powm.cpp @@ -0,0 +1,51 @@ +/************************************************* +* GMP Modular Exponentiation Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include <botan/eng_gmp.h> +#include <botan/gmp_wrap.h> + +namespace Botan { + +namespace { + +/************************************************* +* GMP Modular Exponentiator * +*************************************************/ +class GMP_Modular_Exponentiator : public Modular_Exponentiator + { + public: + void set_base(const BigInt& b) { base = b; } + void set_exponent(const BigInt& e) { exp = e; } + BigInt execute() const; + Modular_Exponentiator* copy() const + { return new GMP_Modular_Exponentiator(*this); } + + GMP_Modular_Exponentiator(const BigInt& n) : mod(n) {} + private: + GMP_MPZ base, exp, mod; + }; + +/************************************************* +* Compute the result * +*************************************************/ +BigInt GMP_Modular_Exponentiator::execute() const + { + GMP_MPZ r; + mpz_powm(r.value, base.value, exp.value, mod.value); + return r.to_bigint(); + } + +} + +/************************************************* +* Return the GMP-based modular exponentiator * +*************************************************/ +Modular_Exponentiator* GMP_Engine::mod_exp(const BigInt& n, + Power_Mod::Usage_Hints) const + { + return new GMP_Modular_Exponentiator(n); + } + +} |