Botan  2.4.0
Crypto and TLS for C++11
blinding.h
Go to the documentation of this file.
1 /*
2 * Blinding for public key operations
3 * (C) 1999-2010,2015 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_BLINDER_H_
9 #define BOTAN_BLINDER_H_
10 
11 #include <botan/bigint.h>
12 #include <botan/reducer.h>
13 #include <functional>
14 
15 namespace Botan {
16 
17 class RandomNumberGenerator;
18 
19 /**
20 * Blinding Function Object.
21 */
22 class BOTAN_PUBLIC_API(2,0) Blinder final
23  {
24  public:
25  /**
26  * Blind a value.
27  * The blinding nonce k is freshly generated after
28  * BOTAN_BLINDING_REINIT_INTERVAL calls to blind().
29  * BOTAN_BLINDING_REINIT_INTERVAL = 0 means a fresh
30  * nonce is only generated once. On every other call,
31  * an updated nonce is used for blinding: k' = k*k mod n.
32  * @param x value to blind
33  * @return blinded value
34  */
35  BigInt blind(const BigInt& x) const;
36 
37  /**
38  * Unblind a value.
39  * @param x value to unblind
40  * @return unblinded value
41  */
42  BigInt unblind(const BigInt& x) const;
43 
44  /**
45  * @param modulus the modulus
46  * @param rng the RNG to use for generating the nonce
47  * @param fwd_func a function that calculates the modular
48  * exponentiation of the public exponent and the given value (the nonce)
49  * @param inv_func a function that calculates the modular inverse
50  * of the given value (the nonce)
51  */
52  Blinder(const BigInt& modulus,
54  std::function<BigInt (const BigInt&)> fwd_func,
55  std::function<BigInt (const BigInt&)> inv_func);
56 
57  Blinder(const Blinder&) = delete;
58 
59  Blinder& operator=(const Blinder&) = delete;
60 
61  private:
62  BigInt blinding_nonce() const;
63 
64  Modular_Reducer m_reducer;
65  RandomNumberGenerator& m_rng;
66  std::function<BigInt (const BigInt&)> m_fwd_fn;
67  std::function<BigInt (const BigInt&)> m_inv_fn;
68  size_t m_modulus_bits = 0;
69 
70  mutable BigInt m_e, m_d;
71  mutable size_t m_counter = 0;
72  };
73 
74 }
75 
76 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: alg_id.cpp:13