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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

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

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

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

35
   ++m_counter;
7,082✔
36

37
   if((BOTAN_BLINDING_REINIT_INTERVAL > 0) && (m_counter > BOTAN_BLINDING_REINIT_INTERVAL)) {
7,082✔
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,075✔
44
      m_d = m_reducer.square(m_d);
14,150✔
45
   }
46

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

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

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

57
}
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