aboutsummaryrefslogtreecommitdiffstats
path: root/src/blinding.cpp
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 /src/blinding.cpp
Initial checkin1.5.6
Diffstat (limited to 'src/blinding.cpp')
-rw-r--r--src/blinding.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/blinding.cpp b/src/blinding.cpp
new file mode 100644
index 000000000..816968ae4
--- /dev/null
+++ b/src/blinding.cpp
@@ -0,0 +1,47 @@
+/*************************************************
+* Blinder Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/blinding.h>
+#include <botan/numthry.h>
+
+namespace Botan {
+
+/*************************************************
+* Blinder Constructor *
+*************************************************/
+Blinder::Blinder(const BigInt& e, const BigInt& d, const BigInt& n)
+ {
+ if(e < 1 || d < 1 || n < 1)
+ throw Invalid_Argument("Blinder: Arguments too small");
+
+ reducer = Modular_Reducer(n);
+ this->e = e;
+ this->d = d;
+ }
+
+/*************************************************
+* Blind a number *
+*************************************************/
+BigInt Blinder::blind(const BigInt& i) const
+ {
+ if(!reducer.initialized())
+ return i;
+
+ e = reducer.square(e);
+ d = reducer.square(d);
+ return reducer.multiply(i, e);
+ }
+
+/*************************************************
+* Unblind a number *
+*************************************************/
+BigInt Blinder::unblind(const BigInt& i) const
+ {
+ if(!reducer.initialized())
+ return i;
+ return reducer.multiply(i, d);
+ }
+
+}