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
11namespace Botan {
12
13namespace {
14
15/*
16* GMP Modular Exponentiator
17*/
18class 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*/
35BigInt 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*/
49 {
50 return new GMP_Modular_Exponentiator(n);
51 }
52
53}
Modular_Exponentiator * mod_exp(const BigInt &, Power_Mod::Usage_Hints) const
Definition gmp_powm.cpp:47