blob: a5e3d1c0da4eabd9fd1b034e4c421d2e2d938f79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
}
}
|