aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/gnump/gmp_dh.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-11 19:20:32 +0000
committerlloyd <[email protected]>2008-11-11 19:20:32 +0000
commit2af6c4499013911d7b01ce3ce1acc5aa8fef15ab (patch)
tree894612d39bbcd50187334c1bedf197c4475c7393 /src/engine/gnump/gmp_dh.cpp
parent25d7b7aa9e9896df45f12fa59db4c44411bc21f0 (diff)
Move most of the remaining libstate code to pk_engine.cpp, move engines
back to the toplevel since most othe dependencies have been removed now (except get_cipher which still needs changes)
Diffstat (limited to 'src/engine/gnump/gmp_dh.cpp')
-rw-r--r--src/engine/gnump/gmp_dh.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/engine/gnump/gmp_dh.cpp b/src/engine/gnump/gmp_dh.cpp
new file mode 100644
index 000000000..ef2732626
--- /dev/null
+++ b/src/engine/gnump/gmp_dh.cpp
@@ -0,0 +1,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
+
+}