Coverage Report

Created: 2023-09-25 06:33

/src/botan/src/lib/hash/sha3/sha3.cpp
Line
Count
Source (jump to first uncovered line)
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
143
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
143
   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
143
}
25
26
18
std::string SHA_3::name() const {
27
18
   return fmt("SHA-3({})", m_output_length * 8);
28
18
}
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
40
std::unique_ptr<HashFunction> SHA_3::new_object() const {
39
40
   return std::make_unique<SHA_3>(m_output_length * 8);
40
40
}
41
42
52
void SHA_3::clear() {
43
52
   m_keccak.clear();
44
52
}
45
46
22.4k
void SHA_3::add_data(std::span<const uint8_t> input) {
47
22.4k
   m_keccak.absorb(input);
48
22.4k
}
49
50
6.17k
void SHA_3::final_result(std::span<uint8_t> output) {
51
6.17k
   m_keccak.finish();
52
6.17k
   m_keccak.squeeze(output);
53
6.17k
   m_keccak.clear();
54
6.17k
}
55
56
}  // namespace Botan