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

randombit / botan / 5230455705

10 Jun 2023 02:30PM UTC coverage: 91.715% (-0.03%) from 91.746%
5230455705

push

github

randombit
Merge GH #3584 Change clang-format AllowShortFunctionsOnASingleLine config from All to Inline

77182 of 84154 relevant lines covered (91.72%)

11975295.43 hits per line

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

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

29
BigInt Blinder::blinding_nonce() const {
1,587✔
30
   return BigInt(m_rng, m_modulus_bits - 1);
1,580✔
31
}
32

33
BigInt Blinder::blind(const BigInt& i) const {
7,078✔
34
   if(!m_reducer.initialized()) {
7,078✔
35
      throw Invalid_State("Blinder not initialized, cannot blind");
×
36
   }
37

38
   ++m_counter;
7,078✔
39

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

50
   return m_reducer.multiply(i, m_e);
7,077✔
51
}
52

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

58
   return m_reducer.multiply(i, m_d);
7,077✔
59
}
60

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