Botan 3.14.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
10#include <botan/internal/ct_utils.h>
11
12namespace Botan {
13
16 std::function<BigInt(const BigInt&)> fwd,
17 std::function<BigInt(const BigInt&)> inv) :
18 m_reducer(reducer),
19 m_rng(rng),
20 m_fwd_fn(std::move(fwd)),
21 m_inv_fn(std::move(inv)),
22 m_modulus_bits(reducer.modulus_bits()),
23 m_counter{} {
24 const BigInt k = blinding_nonce();
25 m_e = m_fwd_fn(k);
26 m_d = m_inv_fn(k);
28}
29
30BigInt Blinder::blinding_nonce() const {
31 return CT::driveby_poison(BigInt(m_rng, m_modulus_bits - 1));
32}
33
34BigInt Blinder::blind(const BigInt& i) const {
35 ++m_counter;
36
37 if((ReinitInterval > 0) && (m_counter > ReinitInterval)) {
38 const BigInt k = blinding_nonce();
39 m_e = m_fwd_fn(k);
40 m_d = m_inv_fn(k);
41 m_counter = 0;
42 } else {
43 m_e = m_reducer.square(m_e);
44 m_d = m_reducer.square(m_d);
45 }
46
47 return m_reducer.multiply(i, m_e);
48}
49
51 return m_reducer.multiply(i, m_d);
52}
53
54} // namespace Botan
BigInt blind(const BigInt &x) const
Definition blinding.cpp:34
static constexpr size_t ReinitInterval
Definition blinding.h:38
RandomNumberGenerator & rng() const
Definition blinding.h:87
void _const_time_unpoison() const
Definition blinding.h:63
BigInt unblind(const BigInt &x) const
Definition blinding.cpp:50
Blinder(const Barrett_Reduction &reducer, RandomNumberGenerator &rng, std::function< BigInt(const BigInt &)> fwd_func, std::function< BigInt(const BigInt &)> inv_func)
Definition blinding.cpp:14
constexpr decltype(auto) driveby_poison(T &&v)
Definition ct_utils.h:232