Coverage Report

Created: 2025-11-24 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Botan-3.4.0/src/lib/hash/sha3/sha3.cpp
Line
Count
Source
1
/*
2
* SHA-3
3
* (C) 2010,2016 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/internal/sha3.h>
9
10
#include <botan/exceptn.h>
11
#include <botan/internal/cpuid.h>
12
#include <botan/internal/fmt.h>
13
#include <botan/internal/keccak_perm.h>
14
#include <botan/internal/loadstor.h>
15
16
namespace Botan {
17
18
39.0k
SHA_3::SHA_3(size_t output_bits) : m_keccak(2 * output_bits, 2, 2), m_output_length(output_bits / 8) {
19
   // We only support the parameters for SHA-3 in this constructor
20
21
39.0k
   if(output_bits != 224 && output_bits != 256 && output_bits != 384 && output_bits != 512) {
22
0
      throw Invalid_Argument(fmt("SHA_3: Invalid output length {}", output_bits));
23
0
   }
24
39.0k
}
25
26
12.6k
std::string SHA_3::name() const {
27
12.6k
   return fmt("SHA-3({})", m_output_length * 8);
28
12.6k
}
29
30
0
std::string SHA_3::provider() const {
31
0
   return m_keccak.provider();
32
0
}
33
34
0
std::unique_ptr<HashFunction> SHA_3::copy_state() const {
35
0
   return std::make_unique<SHA_3>(*this);
36
0
}
37
38
0
std::unique_ptr<HashFunction> SHA_3::new_object() const {
39
0
   return std::make_unique<SHA_3>(m_output_length * 8);
40
0
}
41
42
0
void SHA_3::clear() {
43
0
   m_keccak.clear();
44
0
}
45
46
286k
void SHA_3::add_data(std::span<const uint8_t> input) {
47
286k
   m_keccak.absorb(input);
48
286k
}
49
50
20.8k
void SHA_3::final_result(std::span<uint8_t> output) {
51
20.8k
   m_keccak.finish();
52
20.8k
   m_keccak.squeeze(output);
53
20.8k
   m_keccak.clear();
54
20.8k
}
55
56
}  // namespace Botan