Botan 3.9.0
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.modulus_bits()),
21 m_counter{} {
22 const BigInt k = blinding_nonce();
23 m_e = m_fwd_fn(k);
24 m_d = m_inv_fn(k);
25}
26
27BigInt Blinder::blinding_nonce() const {
28 return BigInt(m_rng, m_modulus_bits - 1);
29}
30
31BigInt Blinder::blind(const BigInt& i) const {
32 ++m_counter;
33
34 if((ReinitInterval > 0) && (m_counter > ReinitInterval)) {
35 const BigInt k = blinding_nonce();
36 m_e = m_fwd_fn(k);
37 m_d = m_inv_fn(k);
38 m_counter = 0;
39 } else {
40 m_e = m_reducer.square(m_e);
41 m_d = m_reducer.square(m_d);
42 }
43
44 return m_reducer.multiply(i, m_e);
45}
46
48 return m_reducer.multiply(i, m_d);
49}
50
51} // namespace Botan
BigInt blind(const BigInt &x) const
Definition blinding.cpp:31
static constexpr size_t ReinitInterval
Definition blinding.h:37
RandomNumberGenerator & rng() const
Definition blinding.h:82
BigInt unblind(const BigInt &x) const
Definition blinding.cpp:47
Blinder(const Barrett_Reduction &reducer, RandomNumberGenerator &rng, std::function< BigInt(const BigInt &)> fwd_func, std::function< BigInt(const BigInt &)> inv_func)
Definition blinding.cpp:12