Botan 3.7.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 reducer precomputed Barrett reduction for 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 * @note Lifetime: The rng and reducer arguments are captured by
52 * reference and must live as long as the Blinder does
53 */
54 Blinder(const Modular_Reducer& reducer,
56 std::function<BigInt(const BigInt&)> fwd_func,
57 std::function<BigInt(const BigInt&)> inv_func);
58
59 Blinder(const Blinder&) = delete;
60
61 Blinder& operator=(const Blinder&) = delete;
62
63 RandomNumberGenerator& rng() const { return m_rng; }
64
65 private:
66 BigInt blinding_nonce() const;
67
68 const Modular_Reducer& m_reducer;
70 std::function<BigInt(const BigInt&)> m_fwd_fn;
71 std::function<BigInt(const BigInt&)> m_inv_fn;
72 size_t m_modulus_bits = 0;
73
74 mutable BigInt m_e, m_d;
75 mutable size_t m_counter = 0;
76};
77
78} // namespace Botan
79
80#endif
Blinder & operator=(const Blinder &)=delete
BigInt blind(const BigInt &x) const
Definition blinding.cpp:33
Blinder(const Blinder &)=delete
Blinder(const Modular_Reducer &reducer, 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:63
BigInt unblind(const BigInt &x) const
Definition blinding.cpp:49
int(* final)(unsigned char *, CTX *)