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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 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,078✔
32
   if(!m_reducer.initialized()) {
7,078✔
33
      throw Invalid_State("Blinder not initialized, cannot blind");
×
34
   }
35

36
   ++m_counter;
7,078✔
37

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

48
   return m_reducer.multiply(i, m_e);
7,077✔
49
}
50

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

56
   return m_reducer.multiply(i, m_d);
7,077✔
57
}
58

59
}  // 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

© 2026 Coveralls, Inc