Botan 3.6.1
Crypto and TLS for C&
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
15namespace Botan {
16
17class RandomNumberGenerator;
18
19/**
20* Blinding Function Object.
21*/
23 public:
24 /**
25 * Blind a value.
26 * The blinding nonce k is freshly generated after
27 * BOTAN_BLINDING_REINIT_INTERVAL calls to blind().
28 * BOTAN_BLINDING_REINIT_INTERVAL = 0 means a fresh
29 * nonce is only generated once. On every other call,
30 * an updated nonce is used for blinding: k' = k*k mod n.
31 * @param x value to blind
32 * @return blinded value
33 */
34 BigInt blind(const BigInt& x) const;
35
36 /**
37 * Unblind a value.
38 * @param x value to unblind
39 * @return unblinded value
40 */
41 BigInt unblind(const BigInt& x) const;
42
43 /**
44 * @param modulus the modulus
45 * @param rng the RNG to use for generating the nonce
46 * @param fwd_func a function that calculates the modular
47 * exponentiation of the public exponent and the given value (the nonce)
48 * @param inv_func a function that calculates the modular inverse
49 * of the given value (the nonce)
50 */
51 Blinder(const BigInt& modulus,
53 std::function<BigInt(const BigInt&)> fwd_func,
54 std::function<BigInt(const BigInt&)> inv_func);
55
56 Blinder(const Blinder&) = delete;
57
58 Blinder& operator=(const Blinder&) = delete;
59
60 RandomNumberGenerator& rng() const { return m_rng; }
61
62 private:
63 BigInt blinding_nonce() const;
64
65 Modular_Reducer m_reducer;
67 std::function<BigInt(const BigInt&)> m_fwd_fn;
68 std::function<BigInt(const BigInt&)> m_inv_fn;
69 size_t m_modulus_bits = 0;
70
71 mutable BigInt m_e, m_d;
72 mutable size_t m_counter = 0;
73};
74
75} // namespace Botan
76
77#endif
Blinder & operator=(const Blinder &)=delete
BigInt blind(const BigInt &x) const
Definition blinding.cpp:33
Blinder(const Blinder &)=delete
Blinder(const BigInt &modulus, RandomNumberGenerator &rng, std::function< BigInt(const BigInt &)> fwd_func, std::function< BigInt(const BigInt &)> inv_func)
Definition blinding.cpp:12
RandomNumberGenerator & rng() const
Definition blinding.h:60
BigInt unblind(const BigInt &x) const
Definition blinding.cpp:53
int(* final)(unsigned char *, CTX *)