Coverage Report

Created: 2024-11-21 07:03

/src/botan/src/lib/hash/shake/shake.cpp
Line
Count
Source (jump to first uncovered line)
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
302
SHAKE_128::SHAKE_128(size_t output_bits) : m_keccak(256, 0xF, 4), m_output_bits(output_bits) {
16
302
   if(output_bits % 8 != 0) {
17
0
      throw Invalid_Argument(fmt("SHAKE_128: Invalid output length {}", output_bits));
18
0
   }
19
302
}
20
21
24
std::string SHAKE_128::name() const {
22
24
   return fmt("SHAKE-128({})", m_output_bits);
23
24
}
24
25
106
std::unique_ptr<HashFunction> SHAKE_128::new_object() const {
26
106
   return std::make_unique<SHAKE_128>(m_output_bits);
27
106
}
28
29
0
std::unique_ptr<HashFunction> SHAKE_128::copy_state() const {
30
0
   return std::make_unique<SHAKE_128>(*this);
31
0
}
32
33
35.8k
void SHAKE_128::add_data(std::span<const uint8_t> input) {
34
35.8k
   m_keccak.absorb(input);
35
35.8k
}
36
37
6.16k
void SHAKE_128::final_result(std::span<uint8_t> output) {
38
6.16k
   m_keccak.finish();
39
6.16k
   m_keccak.squeeze(output);
40
6.16k
   clear();
41
6.16k
}
42
43
292
SHAKE_256::SHAKE_256(size_t output_bits) : m_keccak(512, 0xF, 4), m_output_bits(output_bits) {
44
292
   if(output_bits % 8 != 0) {
45
0
      throw Invalid_Argument(fmt("SHAKE_256: Invalid output length {}", output_bits));
46
0
   }
47
292
}
48
49
32
std::string SHAKE_256::name() const {
50
32
   return fmt("SHAKE-256({})", m_output_bits);
51
32
}
52
53
108
std::unique_ptr<HashFunction> SHAKE_256::new_object() const {
54
108
   return std::make_unique<SHAKE_256>(m_output_bits);
55
108
}
56
57
0
std::unique_ptr<HashFunction> SHAKE_256::copy_state() const {
58
0
   return std::make_unique<SHAKE_256>(*this);
59
0
}
60
61
39.9k
void SHAKE_256::add_data(std::span<const uint8_t> input) {
62
39.9k
   m_keccak.absorb(input);
63
39.9k
}
64
65
8.18k
void SHAKE_256::final_result(std::span<uint8_t> output) {
66
8.18k
   m_keccak.finish();
67
8.18k
   m_keccak.squeeze(output);
68
8.18k
   clear();
69
8.18k
}
70
71
}  // namespace Botan