aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate/engine/gnump/gmp_dh.cpp
blob: ef2732626217d7bdbce3bfbd52190353f570ee83 (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 Engine Source File                         *
* (C) 1999-2007 Jack Lloyd                       *
*************************************************/

#include <botan/eng_gmp.h>
#include <botan/gmp_wrap.h>
#include <gmp.h>

namespace Botan {

#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
namespace {

/*************************************************
* GMP DH Operation                               *
*************************************************/
class GMP_DH_Op : public DH_Operation
   {
   public:
      BigInt agree(const BigInt& i) const;
      DH_Operation* clone() const { return new GMP_DH_Op(*this); }

      GMP_DH_Op(const DL_Group& group, const BigInt& x_bn) :
         x(x_bn), p(group.get_p()) {}
   private:
      GMP_MPZ x, p;
   };

/*************************************************
* GMP DH Key Agreement Operation                 *
*************************************************/
BigInt GMP_DH_Op::agree(const BigInt& i_bn) const
   {
   GMP_MPZ i(i_bn);
   mpz_powm(i.value, i.value, x.value, p.value);
   return i.to_bigint();
   }

}

/*************************************************
* Acquire a DH op                                *
*************************************************/
DH_Operation* GMP_Engine::dh_op(const DL_Group& group, const BigInt& x) const
   {
   return new GMP_DH_Op(group, x);
   }
#endif

}