Botan 3.14.1
Crypto and TLS for C&
Botan::Blinder Class Referencefinal

#include <blinding.h>

Public Member Functions

void _const_time_poison () const
void _const_time_unpoison () const
BigInt blind (const BigInt &x) const
 Blinder (Blinder &&)=default
 Blinder (const Barrett_Reduction &reducer, RandomNumberGenerator &rng, std::function< BigInt(const BigInt &)> fwd_func, std::function< BigInt(const BigInt &)> inv_func)
 Blinder (const Blinder &)=delete
Blinder & operator= (Blinder &&)=delete
Blinder & operator= (const Blinder &)=delete
RandomNumberGenerator & rng () const
BigInt unblind (const BigInt &x) const
 ~Blinder ()=default

Static Public Attributes

static constexpr size_t ReinitInterval = 64

Detailed Description

Blinding Function Object.

Definition at line 23 of file blinding.h.

Constructor & Destructor Documentation

◆ Blinder() [1/3]

Botan::Blinder::Blinder ( const Barrett_Reduction & reducer,
RandomNumberGenerator & rng,
std::function< BigInt(const BigInt &)> fwd_func,
std::function< BigInt(const BigInt &)> inv_func )
Parameters
reducerprecomputed Barrett reduction for the modulus
rngthe RNG to use for generating the nonce
fwd_funca function that calculates the modular exponentiation of the public exponent and the given value (the nonce)
inv_funca function that calculates the modular inverse of the given value (the nonce)
Note
Lifetime: The rng and reducer arguments are captured by reference and must live as long as the Blinder does

Definition at line 14 of file blinding.cpp.

17 :
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}
RandomNumberGenerator & rng() const
Definition blinding.h:87
void _const_time_unpoison() const
Definition blinding.h:63

References _const_time_unpoison(), and rng().

Referenced by Blinder(), Blinder(), operator=(), and operator=().

◆ Blinder() [2/3]

Botan::Blinder::Blinder ( const Blinder & )
delete

References Blinder().

◆ Blinder() [3/3]

Botan::Blinder::Blinder ( Blinder && )
default

References Blinder().

◆ ~Blinder()

Botan::Blinder::~Blinder ( )
default

Member Function Documentation

◆ _const_time_poison()

void Botan::Blinder::_const_time_poison ( ) const
inline

Definition at line 61 of file blinding.h.

61{ CT::poison_all(m_e, m_d); }
constexpr void poison_all(const Ts &... ts)
Definition ct_utils.h:201

References Botan::CT::poison_all().

◆ _const_time_unpoison()

void Botan::Blinder::_const_time_unpoison ( ) const
inline

Definition at line 63 of file blinding.h.

63{ CT::unpoison_all(m_e, m_d); }
constexpr void unpoison_all(const Ts &... ts)
Definition ct_utils.h:207

References Botan::CT::unpoison_all().

Referenced by Blinder().

◆ blind()

BigInt Botan::Blinder::blind ( const BigInt & x) const

Blind a value.

The blinding nonce k is freshly generated after ReinitInterval calls to blind().

ReinitInterval = 0 means a fresh nonce is only generated once. On every other call, the next nonce is derived via modular squaring.

Parameters
xvalue to blind
Returns
blinded value

Definition at line 34 of file blinding.cpp.

34 {
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}
static constexpr size_t ReinitInterval
Definition blinding.h:38

References ReinitInterval.

◆ operator=() [1/2]

Blinder & Botan::Blinder::operator= ( Blinder && )
delete

References Blinder().

◆ operator=() [2/2]

Blinder & Botan::Blinder::operator= ( const Blinder & )
delete

References Blinder().

◆ rng()

RandomNumberGenerator & Botan::Blinder::rng ( ) const
inline

Definition at line 87 of file blinding.h.

87{ return m_rng; }

Referenced by Blinder().

◆ unblind()

BigInt Botan::Blinder::unblind ( const BigInt & x) const

Unblind a value.

Parameters
xvalue to unblind
Returns
unblinded value

Definition at line 50 of file blinding.cpp.

50 {
51 return m_reducer.multiply(i, m_d);
52}

Member Data Documentation

◆ ReinitInterval

size_t Botan::Blinder::ReinitInterval = 64
staticconstexpr

Normally blinding is performed by choosing a random starting point (plus its inverse, of a form appropriate to the algorithm being blinded), and then choosing new blinding operands by successive squaring of both values. This is much faster than computing a new starting point but introduces some possible correlation

To avoid possible leakage problems in long-running processes, the blinder periodically reinitializes the sequence. This value specifies how often a new sequence should be started.

If set to zero, reinitialization is disabled

Definition at line 38 of file blinding.h.

Referenced by blind().


The documentation for this class was generated from the following files: