Botan 3.7.1
Crypto and TLS for C&
blinding.cpp
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#include <botan/internal/blinding.h>
9
10namespace Botan {
11
14 std::function<BigInt(const BigInt&)> fwd,
15 std::function<BigInt(const BigInt&)> inv) :
16 m_reducer(reducer),
17 m_rng(rng),
18 m_fwd_fn(std::move(fwd)),
19 m_inv_fn(std::move(inv)),
20 m_modulus_bits(reducer.get_modulus().bits()),
21 m_e{},
22 m_d{},
23 m_counter{} {
24 const BigInt k = blinding_nonce();
25 m_e = m_fwd_fn(k);
26 m_d = m_inv_fn(k);
27}
28
29BigInt Blinder::blinding_nonce() const {
30 return BigInt(m_rng, m_modulus_bits - 1);
31}
32
33BigInt Blinder::blind(const BigInt& i) const {
34 ++m_counter;
35
37 const BigInt k = blinding_nonce();
38 m_e = m_fwd_fn(k);
39 m_d = m_inv_fn(k);
40 m_counter = 0;
41 } else {
42 m_e = m_reducer.square(m_e);
43 m_d = m_reducer.square(m_d);
44 }
45
46 return m_reducer.multiply(i, m_e);
47}
48
50 return m_reducer.multiply(i, m_d);
51}
52
53} // namespace Botan
BigInt blind(const BigInt &x) const
Definition blinding.cpp:33
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
BigInt unblind(const BigInt &x) const
Definition blinding.cpp:49
BigInt square(const BigInt &x) const
Definition reducer.cpp:61
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition reducer.h:32
#define BOTAN_BLINDING_REINIT_INTERVAL
Definition build.h:508