aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/if_algo
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-10-01 15:17:52 +0000
committerlloyd <[email protected]>2008-10-01 15:17:52 +0000
commit92ddf6f0f8f0ef6f5584889481e4a098e280ee40 (patch)
tree4178ad93250da66d0eb18f9dfcce221bbb57bcd7 /src/pubkey/if_algo
parent1034cf44b4ee0948312c11a1b079b8b04c5828e2 (diff)
Move last pieces of algorithm-specific code from general 'pubkey' module
into algorithm-specific directories. (Dependencies still remain on these in core/libstate, though).
Diffstat (limited to 'src/pubkey/if_algo')
-rw-r--r--src/pubkey/if_algo/if_core.h3
-rw-r--r--src/pubkey/if_algo/if_op.cpp83
-rw-r--r--src/pubkey/if_algo/if_op.h27
-rw-r--r--src/pubkey/if_algo/info.txt15
4 files changed, 120 insertions, 8 deletions
diff --git a/src/pubkey/if_algo/if_core.h b/src/pubkey/if_algo/if_core.h
index b6afad950..ae9fb3d09 100644
--- a/src/pubkey/if_algo/if_core.h
+++ b/src/pubkey/if_algo/if_core.h
@@ -6,9 +6,8 @@
#ifndef BOTAN_IF_CORE_H__
#define BOTAN_IF_CORE_H__
-#include <botan/bigint.h>
+#include <botan/if_op.h>
#include <botan/blinding.h>
-#include <botan/pk_ops.h>
namespace Botan {
diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp
new file mode 100644
index 000000000..0b151bf3b
--- /dev/null
+++ b/src/pubkey/if_algo/if_op.cpp
@@ -0,0 +1,83 @@
+/*************************************************
+* IF (RSA/RW) Operation Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/eng_def.h>
+#include <botan/pow_mod.h>
+#include <botan/numthry.h>
+#include <botan/reducer.h>
+
+namespace Botan {
+
+namespace {
+
+/*************************************************
+* Default IF Operation *
+*************************************************/
+class Default_IF_Op : public IF_Operation
+ {
+ public:
+ BigInt public_op(const BigInt& i) const
+ { return powermod_e_n(i); }
+ BigInt private_op(const BigInt&) const;
+
+ IF_Operation* clone() const { return new Default_IF_Op(*this); }
+
+ Default_IF_Op(const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&);
+ private:
+ Fixed_Exponent_Power_Mod powermod_e_n, powermod_d1_p, powermod_d2_q;
+ Modular_Reducer reducer;
+ BigInt c, q;
+ };
+
+/*************************************************
+* Default_IF_Op Constructor *
+*************************************************/
+Default_IF_Op::Default_IF_Op(const BigInt& e, const BigInt& n, const BigInt&,
+ const BigInt& p, const BigInt& q,
+ const BigInt& d1, const BigInt& d2,
+ const BigInt& c)
+ {
+ powermod_e_n = Fixed_Exponent_Power_Mod(e, n);
+
+ if(d1 != 0 && d2 != 0 && p != 0 && q != 0)
+ {
+ powermod_d1_p = Fixed_Exponent_Power_Mod(d1, p);
+ powermod_d2_q = Fixed_Exponent_Power_Mod(d2, q);
+ reducer = Modular_Reducer(p);
+ this->c = c;
+ this->q = q;
+ }
+ }
+
+/*************************************************
+* Default IF Private Operation *
+*************************************************/
+BigInt Default_IF_Op::private_op(const BigInt& i) const
+ {
+ if(q == 0)
+ throw Internal_Error("Default_IF_Op::private_op: No private key");
+
+ BigInt j1 = powermod_d1_p(i);
+ BigInt j2 = powermod_d2_q(i);
+ j1 = reducer.reduce(sub_mul(j1, j2, c));
+ return mul_add(j1, q, j2);
+ }
+
+}
+
+/*************************************************
+* Acquire an IF op *
+*************************************************/
+IF_Operation* Default_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
+ {
+ return new Default_IF_Op(e, n, d, p, q, d1, d2, c);
+ }
+
+}
diff --git a/src/pubkey/if_algo/if_op.h b/src/pubkey/if_algo/if_op.h
new file mode 100644
index 000000000..be9a4581c
--- /dev/null
+++ b/src/pubkey/if_algo/if_op.h
@@ -0,0 +1,27 @@
+/*************************************************
+* IF Operations Header File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_IF_OP_H__
+#define BOTAN_IF_OP_H__
+
+#include <botan/bigint.h>
+
+namespace Botan {
+
+/*************************************************
+* IF Operation *
+*************************************************/
+class BOTAN_DLL IF_Operation
+ {
+ public:
+ virtual BigInt public_op(const BigInt&) const = 0;
+ virtual BigInt private_op(const BigInt&) const = 0;
+ virtual IF_Operation* clone() const = 0;
+ virtual ~IF_Operation() {}
+ };
+
+}
+
+#endif
diff --git a/src/pubkey/if_algo/info.txt b/src/pubkey/if_algo/info.txt
index af1726414..1ee2e3a68 100644
--- a/src/pubkey/if_algo/info.txt
+++ b/src/pubkey/if_algo/info.txt
@@ -4,15 +4,18 @@ define IF_PUBLIC_KEY_FAMILY
load_on required
-<add>
-if_algo.cpp
-if_algo.h
-if_core.cpp
-if_core.h
-</add>
<requires>
asn1
bigint
filters
</requires>
+
+<add>
+if_algo.cpp
+if_algo.h
+if_core.cpp
+if_core.h
+if_op.cpp
+if_op.h
+</add>