Coverage Report

Created: 2026-04-08 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/botan/src/lib/pubkey/blinding/blinding.cpp
Line
Count
Source
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
namespace Botan {
11
12
Blinder::Blinder(const Barrett_Reduction& reducer,
13
                 RandomNumberGenerator& rng,
14
                 std::function<BigInt(const BigInt&)> fwd,
15
                 std::function<BigInt(const BigInt&)> inv) :
16
50
      m_reducer(reducer),
17
50
      m_rng(rng),
18
50
      m_fwd_fn(std::move(fwd)),
19
50
      m_inv_fn(std::move(inv)),
20
50
      m_modulus_bits(reducer.modulus_bits()),
21
50
      m_counter{} {
22
50
   const BigInt k = blinding_nonce();
23
50
   m_e = m_fwd_fn(k);
24
50
   m_d = m_inv_fn(k);
25
50
}
26
27
50
BigInt Blinder::blinding_nonce() const {
28
50
   return BigInt(m_rng, m_modulus_bits - 1);
29
50
}
30
31
50
BigInt Blinder::blind(const BigInt& i) const {
32
50
   ++m_counter;
33
34
50
   if((ReinitInterval > 0) && (m_counter > ReinitInterval)) {
35
0
      const BigInt k = blinding_nonce();
36
0
      m_e = m_fwd_fn(k);
37
0
      m_d = m_inv_fn(k);
38
0
      m_counter = 0;
39
50
   } else {
40
50
      m_e = m_reducer.square(m_e);
41
50
      m_d = m_reducer.square(m_d);
42
50
   }
43
44
50
   return m_reducer.multiply(i, m_e);
45
50
}
46
47
50
BigInt Blinder::unblind(const BigInt& i) const {
48
50
   return m_reducer.multiply(i, m_d);
49
50
}
50
51
}  // namespace Botan