aboutsummaryrefslogtreecommitdiffstats
path: root/src/pk/if_algo
diff options
context:
space:
mode:
Diffstat (limited to 'src/pk/if_algo')
-rw-r--r--src/pk/if_algo/if_core.cpp85
-rw-r--r--src/pk/if_algo/if_core.h44
-rw-r--r--src/pk/if_algo/info.txt4
3 files changed, 132 insertions, 1 deletions
diff --git a/src/pk/if_algo/if_core.cpp b/src/pk/if_algo/if_core.cpp
new file mode 100644
index 000000000..97cacf9d8
--- /dev/null
+++ b/src/pk/if_algo/if_core.cpp
@@ -0,0 +1,85 @@
+/*************************************************
+* IF Algorithm Core Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/if_core.h>
+#include <botan/numthry.h>
+#include <botan/engine.h>
+#include <botan/parsing.h>
+#include <algorithm>
+
+namespace Botan {
+
+namespace {
+
+const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS;
+
+}
+
+/*************************************************
+* IF_Core Constructor *
+*************************************************/
+IF_Core::IF_Core(const BigInt& e, const BigInt& n)
+ {
+ op = Engine_Core::if_op(e, n, 0, 0, 0, 0, 0, 0);
+ }
+
+
+/*************************************************
+* IF_Core Constructor *
+*************************************************/
+IF_Core::IF_Core(RandomNumberGenerator& rng,
+ const BigInt& e, const BigInt& n, const BigInt& d,
+ const BigInt& p, const BigInt& q,
+ const BigInt& d1, const BigInt& d2, const BigInt& c)
+ {
+ op = Engine_Core::if_op(e, n, d, p, q, d1, d2, c);
+
+ if(BLINDING_BITS)
+ {
+ BigInt k(rng, std::min(n.bits()-1, BLINDING_BITS));
+ blinder = Blinder(power_mod(k, e, n), inverse_mod(k, n), n);
+ }
+ }
+
+/*************************************************
+* IF_Core Copy Constructor *
+*************************************************/
+IF_Core::IF_Core(const IF_Core& core)
+ {
+ op = 0;
+ if(core.op)
+ op = core.op->clone();
+ blinder = core.blinder;
+ }
+
+/*************************************************
+* IF_Core Assignment Operator *
+*************************************************/
+IF_Core& IF_Core::operator=(const IF_Core& core)
+ {
+ delete op;
+ if(core.op)
+ op = core.op->clone();
+ blinder = core.blinder;
+ return (*this);
+ }
+
+/*************************************************
+* IF Public Operation *
+*************************************************/
+BigInt IF_Core::public_op(const BigInt& i) const
+ {
+ return op->public_op(i);
+ }
+
+/*************************************************
+* IF Private Operation *
+*************************************************/
+BigInt IF_Core::private_op(const BigInt& i) const
+ {
+ return blinder.unblind(op->private_op(blinder.blind(i)));
+ }
+
+}
diff --git a/src/pk/if_algo/if_core.h b/src/pk/if_algo/if_core.h
new file mode 100644
index 000000000..b6afad950
--- /dev/null
+++ b/src/pk/if_algo/if_core.h
@@ -0,0 +1,44 @@
+/*************************************************
+* IF Algorithm Core Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_IF_CORE_H__
+#define BOTAN_IF_CORE_H__
+
+#include <botan/bigint.h>
+#include <botan/blinding.h>
+#include <botan/pk_ops.h>
+
+namespace Botan {
+
+/*************************************************
+* IF Core *
+*************************************************/
+class BOTAN_DLL IF_Core
+ {
+ public:
+ BigInt public_op(const BigInt&) const;
+ BigInt private_op(const BigInt&) const;
+
+ IF_Core& operator=(const IF_Core&);
+
+ IF_Core() { op = 0; }
+ IF_Core(const IF_Core&);
+
+ IF_Core(const BigInt&, const BigInt&);
+
+ IF_Core(RandomNumberGenerator& rng,
+ const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&,
+ const BigInt&, const BigInt&, const BigInt&);
+
+ ~IF_Core() { delete op; }
+ private:
+ IF_Operation* op;
+ Blinder blinder;
+ };
+
+}
+
+#endif
diff --git a/src/pk/if_algo/info.txt b/src/pk/if_algo/info.txt
index e8d582c00..af1726414 100644
--- a/src/pk/if_algo/info.txt
+++ b/src/pk/if_algo/info.txt
@@ -2,11 +2,13 @@ realname "Integer Factorization Algorithms"
define IF_PUBLIC_KEY_FAMILY
-load_on auto
+load_on required
<add>
if_algo.cpp
if_algo.h
+if_core.cpp
+if_core.h
</add>
<requires>