Botan 1.10.17

gmp_powm.cpp
Go to the documentation of this file.
1 /*
2 * GMP Modular Exponentiation
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/internal/gnump_engine.h>
9 #include <botan/internal/gmp_wrap.h>
10
11 namespace Botan {
12
13 namespace {
14
15 /*
16 * GMP Modular Exponentiator
17 */
18 class GMP_Modular_Exponentiator : public Modular_Exponentiator
19 {
20 public:
21 void set_base(const BigInt& b) { base = b; }
22 void set_exponent(const BigInt& e) { exp = e; }
23 BigInt execute() const;
24 Modular_Exponentiator* copy() const
25 { return new GMP_Modular_Exponentiator(*this); }
26
27 GMP_Modular_Exponentiator(const BigInt& n) : mod(n) {}
28 private:
29 GMP_MPZ base, exp, mod;
30 };
31
32 /*
33 * Compute the result
34 */
35 BigInt GMP_Modular_Exponentiator::execute() const
36 {
37 GMP_MPZ r;
38 mpz_powm(r.value, base.value, exp.value, mod.value);
39 return r.to_bigint();
40 }
41
42 }
43
44 /*
45 * Return the GMP-based modular exponentiator
46 */
47 Modular_Exponentiator* GMP_Engine::mod_exp(const BigInt& n,
48 Power_Mod::Usage_Hints) const
49 {
50 return new GMP_Modular_Exponentiator(n);
51 }
52
53 }
Botan::BigInt
Definition: bigint.h:22
Botan
Definition: algo_base.h:14
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22
Botan::GMP_Engine::mod_exp
Modular_Exponentiator * mod_exp(const BigInt &, Power_Mod::Usage_Hints) const
Definition: gmp_powm.cpp:47
Botan::Power_Mod::Usage_Hints
Usage_Hints
Definition: pow_mod.h:35
Botan::Modular_Exponentiator
Definition: pow_mod.h:18