Botan  1.10.9
blinding.cpp
Go to the documentation of this file.
1 /*
2 * Blinding for public key operations
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #include <botan/blinding.h>
9 #include <botan/numthry.h>
10 
11 namespace Botan {
12 
13 /*
14 * Blinder Constructor
15 */
16 Blinder::Blinder(const BigInt& e, const BigInt& d, const BigInt& n)
17  {
18  if(e < 1 || d < 1 || n < 1)
19  throw Invalid_Argument("Blinder: Arguments too small");
20 
21  reducer = Modular_Reducer(n);
22  this->e = e;
23  this->d = d;
24  }
25 
26 /*
27 * Blind a number
28 */
29 BigInt Blinder::blind(const BigInt& i) const
30  {
31  if(!reducer.initialized())
32  return i;
33 
34  e = reducer.square(e);
35  d = reducer.square(d);
36  return reducer.multiply(i, e);
37  }
38 
39 /*
40 * Unblind a number
41 */
43  {
44  if(!reducer.initialized())
45  return i;
46  return reducer.multiply(i, d);
47  }
48 
49 }
BigInt n
Definition: numthry.cpp:26
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
bool initialized() const
Definition: reducer.h:50
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31
BigInt unblind(const BigInt &x) const
Definition: blinding.cpp:42
BigInt blind(const BigInt &x) const
Definition: blinding.cpp:29
BigInt square(const BigInt &x) const
Definition: reducer.h:39