aboutsummaryrefslogtreecommitdiffstats
path: root/modules/eng_aep
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-18 18:33:19 +0000
committerlloyd <[email protected]>2006-05-18 18:33:19 +0000
commita2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch)
treead3d6c4fcc8dd0f403f8105598943616246fe172 /modules/eng_aep
Initial checkin1.5.6
Diffstat (limited to 'modules/eng_aep')
-rw-r--r--modules/eng_aep/aep_conn.cpp92
-rw-r--r--modules/eng_aep/aep_conn.h38
-rw-r--r--modules/eng_aep/aep_main.cpp191
-rw-r--r--modules/eng_aep/eng_aep.cpp352
-rw-r--r--modules/eng_aep/eng_aep.h51
-rw-r--r--modules/eng_aep/es_aep.h24
-rw-r--r--modules/eng_aep/hw_aep.h48
-rw-r--r--modules/eng_aep/modinfo.txt22
8 files changed, 818 insertions, 0 deletions
diff --git a/modules/eng_aep/aep_conn.cpp b/modules/eng_aep/aep_conn.cpp
new file mode 100644
index 000000000..9293f45fc
--- /dev/null
+++ b/modules/eng_aep/aep_conn.cpp
@@ -0,0 +1,92 @@
+/*************************************************
+* AEP Connection Management Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/aep_conn.h>
+#include <botan/libstate.h>
+#include <botan/parsing.h>
+#include <botan/hw_aep.h>
+
+namespace Botan {
+
+/*************************************************
+* Persistent connection pool *
+*************************************************/
+std::vector<AEP_Connection::Connection_Info> AEP_Connection::pool;
+Mutex* AEP_Connection::guard = 0;
+
+/*************************************************
+* Close all currently open connections *
+*************************************************/
+void AEP_Connection::close_all_connections()
+ {
+ guard->lock();
+ for(u32bit j = 0; j != pool.size(); j++)
+ AEP::AEP_CloseConnection(pool[j].id);
+ pool.clear();
+ guard->unlock();
+ delete guard;
+ guard = 0;
+ }
+
+/*************************************************
+* Get a new connection handle *
+*************************************************/
+AEP_Connection::AEP_Connection()
+ {
+ // FIXME: race condition
+ if(!guard)
+ guard = global_state().get_mutex();
+
+ Mutex_Holder lock(guard);
+
+ this_connection = 0;
+
+ for(u32bit j = 0; j != pool.size(); j++)
+ {
+ if(pool[j].in_use)
+ continue;
+
+ pool[j].in_use = true;
+ this_connection = pool[j].id;
+ }
+
+ if(this_connection == 0)
+ {
+ Connection_Info new_conn;
+
+ u32bit retval = AEP::AEP_OpenConnection(&new_conn.id);
+ if(retval != 0)
+ throw Stream_IO_Error("AEP_OpenConnection failed");
+ new_conn.in_use = true;
+
+ if(pool.size() < MAX_CACHED_CONNECTIONS)
+ pool.push_back(new_conn);
+
+ this_connection = new_conn.id;
+ }
+ }
+
+/*************************************************
+* Free a connection handle *
+*************************************************/
+AEP_Connection::~AEP_Connection()
+ {
+ Mutex_Holder lock(guard);
+
+ for(u32bit j = 0; j != pool.size(); j++)
+ {
+ if(pool[j].id != this_connection)
+ continue;
+
+ pool[j].in_use = false;
+ return;
+ }
+
+ int retval = AEP::AEP_CloseConnection(this_connection);
+ if(retval != 0)
+ throw Exception("AEP_CloseConnection returned " + to_string(retval));
+ }
+
+}
diff --git a/modules/eng_aep/aep_conn.h b/modules/eng_aep/aep_conn.h
new file mode 100644
index 000000000..18b8c76db
--- /dev/null
+++ b/modules/eng_aep/aep_conn.h
@@ -0,0 +1,38 @@
+/*************************************************
+* AEP Connection Management Header File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#ifndef BOTAN_EXT_AEP_CONNECTION_H__
+#define BOTAN_EXT_AEP_CONNECTION_H__
+
+#include <botan/eng_aep.h>
+#include <botan/mutex.h>
+
+namespace Botan {
+
+/*************************************************
+* AEP Connection *
+*************************************************/
+class AEP_Connection
+ {
+ public:
+ operator u32bit () { return this_connection; }
+
+ static void close_all_connections();
+
+ AEP_Connection();
+ ~AEP_Connection();
+ private:
+ struct Connection_Info { u32bit id; bool in_use; };
+
+ static const u32bit MAX_CACHED_CONNECTIONS = 8;
+ static std::vector<Connection_Info> pool;
+ static Mutex* guard;
+
+ u32bit this_connection;
+ };
+
+}
+
+#endif
diff --git a/modules/eng_aep/aep_main.cpp b/modules/eng_aep/aep_main.cpp
new file mode 100644
index 000000000..d941597da
--- /dev/null
+++ b/modules/eng_aep/aep_main.cpp
@@ -0,0 +1,191 @@
+/*************************************************
+* AEP Interface Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/eng_aep.h>
+#include <botan/parsing.h>
+#include <botan/util.h>
+#include <botan/mutex.h>
+#include <botan/aep_conn.h>
+#include <botan/hw_aep.h>
+#include <botan/es_aep.h>
+
+namespace Botan {
+
+namespace {
+
+/*************************************************
+* AEP Exception *
+*************************************************/
+class AEP_Exception : public Exception
+ {
+ public:
+ AEP_Exception(const std::string func, u32bit retval) :
+ Exception(func + " failed; returned " + to_string(retval)) {}
+ };
+
+/*************************************************
+* Return the size in bytes of this BigInt *
+*************************************************/
+u32bit get_bigint_size(void* bigint_ptr, u32bit* bytes)
+ {
+ const BigInt* bigint = static_cast<BigInt*>(bigint_ptr);
+ const u32bit actual_bytes = bigint->bytes();
+ *bytes = round_up(actual_bytes, 4);
+ return 0;
+ }
+
+/*************************************************
+* Store a BigInt into AEP format *
+*************************************************/
+u32bit store_bigint(void* bigint_ptr, u32bit output_size, byte* output)
+ {
+ const BigInt* bigint = static_cast<BigInt*>(bigint_ptr);
+
+ const u32bit leading_zeros = round_up(bigint->bytes(), 4) - bigint->bytes();
+
+ clear_mem(output, output_size);
+ bigint->binary_encode(output + leading_zeros);
+ for(u32bit j = 0; j != output_size / 2; j++)
+ std::swap(output[j], output[output_size-j-1]);
+
+ return 0;
+ }
+
+/*************************************************
+* Read a BigInt from the AEP format *
+*************************************************/
+u32bit create_bigint(void* bigint_ptr, u32bit input_size, byte* input)
+ {
+ BigInt* bigint = static_cast<BigInt*>(bigint_ptr);
+
+ for(u32bit j = 0; j != input_size / 2; j++)
+ std::swap(input[j], input[input_size-j-1]);
+ bigint->binary_decode(input, input_size);
+
+ return 0;
+ }
+
+}
+
+/*************************************************
+* AEP Modular Exponentiation Operation *
+*************************************************/
+BigInt AEP_Engine::pow_mod(const BigInt& i, const BigInt& x, const BigInt& m)
+ {
+ BigInt output;
+
+ AEP_Connection conn;
+ u32bit retval = AEP::AEP_ModExp(conn, &i, &x, &m, &output, 0);
+
+ if(retval != 0)
+ throw AEP_Exception("AEP_ModExp", retval);
+
+ return output;
+ }
+
+/*************************************************
+* AEP Modular Exponentiation with CRT Operation *
+*************************************************/
+BigInt AEP_Engine::pow_mod_crt(const BigInt& i, const BigInt&,
+ const BigInt& p, const BigInt& q,
+ const BigInt& d1, const BigInt& d2,
+ const BigInt& c)
+ {
+ BigInt output;
+
+ AEP_Connection conn;
+ u32bit retval = AEP::AEP_ModExpCrt(conn, &i, &p, &q, &d1, &d2, &c,
+ &output, 0);
+
+ if(retval != 0)
+ throw AEP_Exception("AEP_ModExpCrt", retval);
+ return output;
+ }
+
+/*************************************************
+* AEP RNG Operation *
+*************************************************/
+u32bit AEP_Engine::get_entropy(byte output[], u32bit length) throw()
+ {
+ if(length > 256)
+ length = 256;
+
+ try {
+ AEP_Connection conn;
+ u32bit retval = AEP::AEP_GenRandom(conn, length, 1, output, 0);
+
+ if(retval != 0)
+ return 0;
+ return length;
+ }
+ catch(...)
+ {
+ return 0;
+ }
+ }
+
+/*************************************************
+* AEP usability check *
+*************************************************/
+bool AEP_Engine::ok_to_use(const BigInt& x) throw()
+ {
+ if(daemon_is_up && (x.bits() <= AEP::MAX_MODULO_BITS))
+ return true;
+ return false;
+ }
+
+/*************************************************
+* AEP daemon status flag *
+*************************************************/
+bool AEP_Engine::daemon_is_up = false;
+
+/*************************************************
+* AEP_Engine Constructor *
+*************************************************/
+AEP_Engine::AEP_Engine()
+ {
+ daemon_is_up = false;
+
+ try {
+ u32bit retval = AEP::AEP_Initialize(0);
+
+ if(retval != 0 && retval != AEP::ALREADY_INIT)
+ throw AEP_Exception("AEP_Initialize", retval);
+
+ if(retval == 0)
+ {
+ retval = AEP::AEP_SetBNCallBacks(get_bigint_size, store_bigint,
+ create_bigint);
+ if(retval != 0)
+ throw AEP_Exception("AEP_SetBNCallBacks", retval);
+
+ AEP_Connection conn;
+ daemon_is_up = true;
+ }
+
+ }
+ catch(AEP_Exception&) {}
+ }
+
+/*************************************************
+* AEP_Engine Destructor *
+*************************************************/
+AEP_Engine::~AEP_Engine()
+ {
+ AEP_Connection::close_all_connections();
+ u32bit retval = AEP::AEP_Finalize();
+ if(retval != 0)
+ throw AEP_Exception("AEP_Finalize", retval);
+ }
+
+/*************************************************
+* Gather Entropy from AEP Hardware RNG *
+*************************************************/
+u32bit AEP_EntropySource::slow_poll(byte output[], u32bit length)
+ {
+ return AEP_Engine::get_entropy(output, length);
+ }
+
+}
diff --git a/modules/eng_aep/eng_aep.cpp b/modules/eng_aep/eng_aep.cpp
new file mode 100644
index 000000000..557132b37
--- /dev/null
+++ b/modules/eng_aep/eng_aep.cpp
@@ -0,0 +1,352 @@
+/*************************************************
+* AEP Engine Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/eng_aep.h>
+#include <botan/numthry.h>
+
+namespace Botan {
+
+namespace {
+
+/*************************************************
+* AEP IF Operation *
+*************************************************/
+class AEP_IF_Op : public IF_Operation
+ {
+ public:
+ BigInt public_op(const BigInt&) const;
+ BigInt private_op(const BigInt&) const;
+
+ IF_Operation* clone() const { return new AEP_IF_Op(*this); }
+
+ AEP_IF_Op(const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&);
+ private:
+ const BigInt e, n, p, q, d1, d2, c;
+ };
+
+/*************************************************
+* AEP_IF_Op Constructor *
+*************************************************/
+AEP_IF_Op::AEP_IF_Op(const BigInt& ex, const BigInt& nx, const BigInt&,
+ const BigInt& px, const BigInt& qx,
+ const BigInt& d1x, const BigInt& d2x,
+ const BigInt& cx) :
+ e(ex), n(nx), p(px), q(qx), d1(d1x), d2(d2x), c(cx)
+ {
+ }
+
+/*************************************************
+* AEP IF Public Operation *
+*************************************************/
+BigInt AEP_IF_Op::public_op(const BigInt& i) const
+ {
+ return AEP_Engine::pow_mod(i, e, n);
+ }
+
+/*************************************************
+* AEP IF Private Operation *
+*************************************************/
+BigInt AEP_IF_Op::private_op(const BigInt& i) const
+ {
+ if(p == 0 || q == 0)
+ throw Internal_Error("AEP_IF_Op::private_op: No private key");
+
+ return AEP_Engine::pow_mod_crt(i, n, p, q, d1, d2, c);
+ }
+
+/*************************************************
+* AEP DSA Operation *
+*************************************************/
+class AEP_DSA_Op : public DSA_Operation
+ {
+ public:
+ bool verify(const byte[], u32bit, const byte[], u32bit) const;
+ SecureVector<byte> sign(const byte[], u32bit, const BigInt&) const;
+
+ DSA_Operation* clone() const { return new AEP_DSA_Op(*this); }
+
+ AEP_DSA_Op(const DL_Group&, const BigInt&, const BigInt&);
+ private:
+ const BigInt x, y;
+ const DL_Group group;
+ };
+
+/*************************************************
+* AEP_DSA_Op Constructor *
+*************************************************/
+AEP_DSA_Op::AEP_DSA_Op(const DL_Group& grp, const BigInt& y1,
+ const BigInt& x1) : x(x1), y(y1), group(grp)
+ {
+ }
+
+/*************************************************
+* AEP DSA Verify Operation *
+*************************************************/
+bool AEP_DSA_Op::verify(const byte msg[], u32bit msg_len,
+ const byte sig[], u32bit sig_len) const
+ {
+ const BigInt& g = group.get_g();
+ const BigInt& q = group.get_q();
+ const BigInt& p = group.get_p();
+
+ if(sig_len != 2*q.bytes() || msg_len > q.bytes())
+ return false;
+
+ BigInt r(sig, q.bytes());
+ BigInt s(sig + q.bytes(), q.bytes());
+ BigInt i(msg, msg_len);
+
+ if(r <= 0 || r >= q || s <= 0 || s >= q)
+ return false;
+
+ s = inverse_mod(s, q);
+ s = mul_mod(AEP_Engine::pow_mod(g, mul_mod(s, i, q), p),
+ AEP_Engine::pow_mod(y, mul_mod(s, r, q), p), p);
+
+ return (s % q == r);
+ }
+
+/*************************************************
+* AEP DSA Sign Operation *
+*************************************************/
+SecureVector<byte> AEP_DSA_Op::sign(const byte in[], u32bit length,
+ const BigInt& k) const
+ {
+ if(x == 0)
+ throw Internal_Error("AEP_DSA_Op::sign: No private key");
+
+ const BigInt& g = group.get_g();
+ const BigInt& q = group.get_q();
+ const BigInt& p = group.get_p();
+ BigInt i(in, length);
+
+ BigInt r = AEP_Engine::pow_mod(g, k, p) % q;
+ BigInt s = mul_mod(inverse_mod(k, q), mul_add(x, r, i), q);
+ if(r.is_zero() || s.is_zero())
+ throw Internal_Error("AEP_DSA_Op::sign: r or s was zero");
+
+ SecureVector<byte> output(2*q.bytes());
+ r.binary_encode(output + (output.size() / 2 - r.bytes()));
+ s.binary_encode(output + (output.size() - s.bytes()));
+ return output;
+ }
+
+/*************************************************
+* AEP NR Operation *
+*************************************************/
+class AEP_NR_Op : public NR_Operation
+ {
+ public:
+ SecureVector<byte> verify(const byte[], u32bit) const;
+ SecureVector<byte> sign(const byte[], u32bit, const BigInt&) const;
+
+ NR_Operation* clone() const { return new AEP_NR_Op(*this); }
+
+ AEP_NR_Op(const DL_Group&, const BigInt&, const BigInt&);
+ private:
+ const BigInt x, y;
+ const DL_Group group;
+ };
+
+/*************************************************
+* AEP_NR_Op Constructor *
+*************************************************/
+AEP_NR_Op::AEP_NR_Op(const DL_Group& grp, const BigInt& y1,
+ const BigInt& x1) : x(x1), y(y1), group(grp)
+ {
+ }
+
+/*************************************************
+* AEP NR Verify Operation *
+*************************************************/
+SecureVector<byte> AEP_NR_Op::verify(const byte in[], u32bit length) const
+ {
+ const BigInt& g = group.get_g();
+ const BigInt& q = group.get_q();
+ const BigInt& p = group.get_p();
+
+ if(length != 2*q.bytes())
+ return false;
+
+ BigInt c(in, q.bytes());
+ BigInt d(in + q.bytes(), q.bytes());
+
+ if(c.is_zero() || c >= q || d >= q)
+ throw Invalid_Argument("AEP_NR_Op::verify: Invalid signature");
+
+ BigInt i = mul_mod(AEP_Engine::pow_mod(g, d, p),
+ AEP_Engine::pow_mod(y, c, p), p);
+ return BigInt::encode((c - i) % q);
+ }
+
+/*************************************************
+* AEP NR Sign Operation *
+*************************************************/
+SecureVector<byte> AEP_NR_Op::sign(const byte in[], u32bit length,
+ const BigInt& k) const
+ {
+ if(x == 0)
+ throw Internal_Error("AEP_NR_Op::sign: No private key");
+
+ const BigInt& g = group.get_g();
+ const BigInt& q = group.get_q();
+ const BigInt& p = group.get_p();
+
+ BigInt f(in, length);
+
+ if(f >= q)
+ throw Invalid_Argument("AEP_NR_Op::sign: Input is out of range");
+
+ BigInt c = (AEP_Engine::pow_mod(g, k, p) + f) % q;
+ if(c.is_zero())
+ throw Internal_Error("AEP_NR_Op::sign: c was zero");
+ BigInt d = (k - x * c) % q;
+
+ SecureVector<byte> output(2*q.bytes());
+ c.binary_encode(output + (output.size() / 2 - c.bytes()));
+ d.binary_encode(output + (output.size() - d.bytes()));
+ return output;
+ }
+
+/*************************************************
+* AEP ElGamal Operation *
+*************************************************/
+class AEP_ELG_Op : public ELG_Operation
+ {
+ public:
+ SecureVector<byte> encrypt(const byte[], u32bit, const BigInt&) const;
+ BigInt decrypt(const BigInt&, const BigInt&) const;
+
+ ELG_Operation* clone() const { return new AEP_ELG_Op(*this); }
+
+ AEP_ELG_Op(const DL_Group&, const BigInt&, const BigInt&);
+ private:
+ const BigInt x, y;
+ const DL_Group group;
+ };
+
+/*************************************************
+* AEP_ELG_Op Constructor *
+*************************************************/
+AEP_ELG_Op::AEP_ELG_Op(const DL_Group& grp, const BigInt& y1,
+ const BigInt& x1) : x(x1), y(y1), group(grp)
+ {
+ }
+
+/*************************************************
+* AEP ElGamal Encrypt Operation *
+*************************************************/
+SecureVector<byte> AEP_ELG_Op::encrypt(const byte in[], u32bit length,
+ const BigInt& k) const
+ {
+ const BigInt& g = group.get_g();
+ const BigInt& p = group.get_p();
+
+ BigInt m(in, length);
+ if(m >= p)
+ throw Invalid_Argument("AEP_ELG_Op::encrypt: Input is too large");
+
+ BigInt a = AEP_Engine::pow_mod(g, k, p);
+ BigInt b = mul_mod(m, AEP_Engine::pow_mod(y, k, p), p);
+
+ SecureVector<byte> output(2*p.bytes());
+ a.binary_encode(output + (p.bytes() - a.bytes()));
+ b.binary_encode(output + output.size() / 2 + (p.bytes() - b.bytes()));
+ return output;
+ }
+
+/*************************************************
+* AEP ElGamal Decrypt Operation *
+*************************************************/
+BigInt AEP_ELG_Op::decrypt(const BigInt& a, const BigInt& b) const
+ {
+ if(x == 0)
+ throw Internal_Error("AEP_ELG_Op::decrypt: No private key");
+
+ const BigInt& p = group.get_p();
+
+ if(a >= p || b >= p)
+ throw Invalid_Argument("AEP_ELG_Op: Invalid message");
+
+ return mul_mod(b, inverse_mod(AEP_Engine::pow_mod(a, x, p), p), p);
+ }
+
+/*************************************************
+* AEP DH Operation *
+*************************************************/
+class AEP_DH_Op : public DH_Operation
+ {
+ public:
+ BigInt agree(const BigInt& i) const
+ { return AEP_Engine::pow_mod(i, x, p); }
+ DH_Operation* clone() const { return new AEP_DH_Op(*this); }
+
+ AEP_DH_Op(const DL_Group& group, const BigInt& x1) :
+ x(x1), p(group.get_p()) {}
+ private:
+ const BigInt x, p;
+ };
+
+}
+
+/*************************************************
+* Acquire an IF op *
+*************************************************/
+IF_Operation* AEP_Engine::if_op(const BigInt& e, const BigInt& n,
+ const BigInt& d, const BigInt& p,
+ const BigInt& q, const BigInt& d1,
+ const BigInt& d2, const BigInt& c) const
+ {
+ if(AEP_Engine::ok_to_use(n))
+ return new AEP_IF_Op(e, n, d, p, q, d1, d2, c);
+ return 0;
+ }
+
+/*************************************************
+* Acquire a DSA op *
+*************************************************/
+DSA_Operation* AEP_Engine::dsa_op(const DL_Group& group, const BigInt& y,
+ const BigInt& x) const
+ {
+ if(AEP_Engine::ok_to_use(group.get_p()))
+ return new AEP_DSA_Op(group, y, x);
+ return 0;
+ }
+
+/*************************************************
+* Acquire a NR op *
+*************************************************/
+NR_Operation* AEP_Engine::nr_op(const DL_Group& group, const BigInt& y,
+ const BigInt& x) const
+ {
+ if(AEP_Engine::ok_to_use(group.get_p()))
+ return new AEP_NR_Op(group, y, x);
+ return 0;
+ }
+
+/*************************************************
+* Acquire an ElGamal op *
+*************************************************/
+ELG_Operation* AEP_Engine::elg_op(const DL_Group& group, const BigInt& y,
+ const BigInt& x) const
+ {
+ if(AEP_Engine::ok_to_use(group.get_p()))
+ return new AEP_ELG_Op(group, y, x);
+ return 0;
+ }
+
+/*************************************************
+* Acquire a DH op *
+*************************************************/
+DH_Operation* AEP_Engine::dh_op(const DL_Group& group, const BigInt& x) const
+ {
+ if(AEP_Engine::ok_to_use(group.get_p()))
+ return new AEP_DH_Op(group, x);
+ return 0;
+ }
+
+}
diff --git a/modules/eng_aep/eng_aep.h b/modules/eng_aep/eng_aep.h
new file mode 100644
index 000000000..0b47c7322
--- /dev/null
+++ b/modules/eng_aep/eng_aep.h
@@ -0,0 +1,51 @@
+/*************************************************
+* AEP Engine Header File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#ifndef BOTAN_EXT_AEP_ENGINE_H__
+#define BOTAN_EXT_AEP_ENGINE_H__
+
+#include <botan/engine.h>
+#include <vector>
+
+namespace Botan {
+
+/*************************************************
+* AEP Engine *
+*************************************************/
+class AEP_Engine : public Engine
+ {
+ public:
+ IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&) const;
+
+ DSA_Operation* dsa_op(const DL_Group&, const BigInt&,
+ const BigInt&) const;
+
+ NR_Operation* nr_op(const DL_Group&, const BigInt&, const BigInt&) const;
+
+ ELG_Operation* elg_op(const DL_Group&, const BigInt&,
+ const BigInt&) const;
+
+ DH_Operation* dh_op(const DL_Group&, const BigInt&) const;
+
+ static BigInt pow_mod(const BigInt&, const BigInt&, const BigInt&);
+
+ static BigInt pow_mod_crt(const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&);
+
+ static u32bit get_entropy(byte[], u32bit) throw();
+ static bool ok_to_use(const BigInt&) throw();
+
+ AEP_Engine();
+ ~AEP_Engine();
+ private:
+ static bool daemon_is_up;
+ };
+
+}
+
+#endif
diff --git a/modules/eng_aep/es_aep.h b/modules/eng_aep/es_aep.h
new file mode 100644
index 000000000..bb58a9ef5
--- /dev/null
+++ b/modules/eng_aep/es_aep.h
@@ -0,0 +1,24 @@
+/*************************************************
+* AEP EntropySource Header File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#ifndef BOTAN_EXT_ENTROPY_SRC_AEP_H__
+#define BOTAN_EXT_ENTROPY_SRC_AEP_H__
+
+#include <botan/base.h>
+
+namespace Botan {
+
+/*************************************************
+* AEP Entropy Source *
+*************************************************/
+class AEP_EntropySource : public EntropySource
+ {
+ public:
+ u32bit slow_poll(byte[], u32bit);
+ };
+
+}
+
+#endif
diff --git a/modules/eng_aep/hw_aep.h b/modules/eng_aep/hw_aep.h
new file mode 100644
index 000000000..6e690e4a8
--- /dev/null
+++ b/modules/eng_aep/hw_aep.h
@@ -0,0 +1,48 @@
+/*************************************************
+* AEP Interface Header File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#ifndef BOTAN_EXT_HW_AEP_H__
+#define BOTAN_EXT_HW_AEP_H__
+
+#include <botan/types.h>
+
+namespace Botan {
+
+namespace AEP {
+
+const u32bit MAX_MODULO_BITS = 2048;
+
+const u32bit ALREADY_INIT = 0x10000191;
+
+extern "C" {
+
+u32bit AEP_Initialize(void*);
+u32bit AEP_Finalize();
+
+u32bit AEP_OpenConnection(u32bit*);
+u32bit AEP_CloseConnection(u32bit);
+
+u32bit AEP_ModExp(u32bit, const void*, const void*, const void*, void*,
+ u32bit*);
+u32bit AEP_ModExpCrt(u32bit, const void*, const void*, const void*,
+ const void*, const void*, const void*, void*,
+ u32bit*);
+
+u32bit AEP_GenRandom(u32bit, u32bit, u32bit, void*, u32bit*);
+
+typedef u32bit (*AEP_get_bignum_size_fn)(void*, u32bit*);
+typedef u32bit (*AEP_read_bignum_fn)(void*, u32bit, byte*);
+typedef u32bit (*AEP_write_bignum_fn)(void*, u32bit, byte*);
+
+u32bit AEP_SetBNCallBacks(AEP_get_bignum_size_fn, AEP_read_bignum_fn,
+ AEP_write_bignum_fn);
+
+}
+
+}
+
+}
+
+#endif
diff --git a/modules/eng_aep/modinfo.txt b/modules/eng_aep/modinfo.txt
new file mode 100644
index 000000000..b84790b97
--- /dev/null
+++ b/modules/eng_aep/modinfo.txt
@@ -0,0 +1,22 @@
+realname "AEP Engine"
+
+uses_external_libs
+
+add_file eng_aep.cpp
+add_file aep_main.cpp
+add_file aep_conn.cpp
+
+add_file eng_aep.h
+add_file es_aep.h
+add_file hw_aep.h
+add_file aep_conn.h
+
+local_only aep_conn.h
+local_only hw_aep.h
+
+define ENGINE_AEP
+define ENTROPY_SRC_AEP
+
+<libs>
+all -> aep
+</libs>