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

randombit / botan / 17517838244

06 Sep 2025 06:09PM UTC coverage: 90.671% (+0.004%) from 90.667%
17517838244

Pull #5097

github

web-flow
Merge 68a3e539f into ce0eeaec5
Pull Request #5097: Refactor: Clarify Padding Specification in Keccak-based Functions

100386 of 110714 relevant lines covered (90.67%)

12145542.39 hits per line

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

94.74
/src/lib/hash/shake/shake.cpp
1
/*
2
* SHAKE-128/256 as a hash
3
* (C) 2016 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/shake.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12

13
namespace Botan {
14

15
// NIST FIPS 202 Section 6.2
16
constexpr auto shake_padding = KeccakPaddingBits<1, 1, 1, 1>;
17

18
SHAKE_128::SHAKE_128(size_t output_bits) :
2,135✔
19
      m_keccak({.capacity_bits = 256, .padding = shake_padding}), m_output_bits(output_bits) {
2,135✔
20
   if(output_bits % 8 != 0) {
2,135✔
21
      throw Invalid_Argument(fmt("SHAKE_128: Invalid output length {}", output_bits));
×
22
   }
23
}
2,135✔
24

25
std::string SHAKE_128::name() const {
726✔
26
   return fmt("SHAKE-128({})", m_output_bits);
726✔
27
}
28

29
std::unique_ptr<HashFunction> SHAKE_128::new_object() const {
1,158✔
30
   return std::make_unique<SHAKE_128>(m_output_bits);
1,158✔
31
}
32

33
std::unique_ptr<HashFunction> SHAKE_128::copy_state() const {
207✔
34
   return std::make_unique<SHAKE_128>(*this);
207✔
35
}
36

37
void SHAKE_128::add_data(std::span<const uint8_t> input) {
84,668,533✔
38
   m_keccak.absorb(input);
84,668,533✔
39
}
84,668,533✔
40

41
void SHAKE_128::final_result(std::span<uint8_t> output) {
21,179,225✔
42
   m_keccak.finish();
21,179,225✔
43
   m_keccak.squeeze(output);
21,179,225✔
44
   clear();
21,179,225✔
45
}
21,179,225✔
46

47
SHAKE_256::SHAKE_256(size_t output_bits) :
6,068✔
48
      m_keccak({.capacity_bits = 512, .padding = shake_padding}), m_output_bits(output_bits) {
6,068✔
49
   if(output_bits % 8 != 0) {
6,068✔
50
      throw Invalid_Argument(fmt("SHAKE_256: Invalid output length {}", output_bits));
×
51
   }
52
}
6,068✔
53

54
std::string SHAKE_256::name() const {
12✔
55
   return fmt("SHAKE-256({})", m_output_bits);
12✔
56
}
57

58
std::unique_ptr<HashFunction> SHAKE_256::new_object() const {
2,332✔
59
   return std::make_unique<SHAKE_256>(m_output_bits);
2,332✔
60
}
61

62
std::unique_ptr<HashFunction> SHAKE_256::copy_state() const {
3✔
63
   return std::make_unique<SHAKE_256>(*this);
3✔
64
}
65

66
void SHAKE_256::add_data(std::span<const uint8_t> input) {
494,329,696✔
67
   m_keccak.absorb(input);
494,329,696✔
68
}
494,329,696✔
69

70
void SHAKE_256::final_result(std::span<uint8_t> output) {
140,943,251✔
71
   m_keccak.finish();
140,943,251✔
72
   m_keccak.squeeze(output);
140,943,251✔
73
   clear();
140,943,251✔
74
}
140,943,251✔
75

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