• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/src/lib/pubkey/blinding.cpp
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 BigInt& modulus,
1,577✔
13
                 RandomNumberGenerator& rng,
14
                 std::function<BigInt(const BigInt&)> fwd,
15
                 std::function<BigInt(const BigInt&)> inv) :
1,577✔
16
      m_reducer(modulus),
1,577✔
17
      m_rng(rng),
1,577✔
18
      m_fwd_fn(std::move(fwd)),
1,577✔
19
      m_inv_fn(std::move(inv)),
1,577✔
20
      m_modulus_bits(modulus.bits()),
1,577✔
21
      m_e{},
1,577✔
22
      m_d{},
1,577✔
23
      m_counter{} {
1,577✔
24
   const BigInt k = blinding_nonce();
3,154✔
25
   m_e = m_fwd_fn(k);
4,731✔
26
   m_d = m_inv_fn(k);
4,731✔
27
}
1,577✔
28

29
BigInt Blinder::blinding_nonce() const { return BigInt(m_rng, m_modulus_bits - 1); }
1,577✔
30

31
BigInt Blinder::blind(const BigInt& i) const {
7,075✔
32
   if(!m_reducer.initialized())
7,075✔
33
      throw Invalid_State("Blinder not initialized, cannot blind");
×
34

35
   ++m_counter;
7,075✔
36

37
   if((BOTAN_BLINDING_REINIT_INTERVAL > 0) && (m_counter > BOTAN_BLINDING_REINIT_INTERVAL)) {
7,075✔
38
      const BigInt k = blinding_nonce();
7✔
39
      m_e = m_fwd_fn(k);
12✔
40
      m_d = m_inv_fn(k);
12✔
41
      m_counter = 0;
6✔
42
   } else {
6✔
43
      m_e = m_reducer.square(m_e);
7,068✔
44
      m_d = m_reducer.square(m_d);
14,136✔
45
   }
46

47
   return m_reducer.multiply(i, m_e);
7,074✔
48
}
49

50
BigInt Blinder::unblind(const BigInt& i) const {
7,074✔
51
   if(!m_reducer.initialized())
7,074✔
52
      throw Invalid_State("Blinder not initialized, cannot unblind");
×
53

54
   return m_reducer.multiply(i, m_d);
7,074✔
55
}
56

57
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc