Coverage Report

Created: 2023-09-25 06:34

/src/botan/src/lib/hash/keccak/keccak.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Keccak
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/keccak.h>
9
10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12
#include <botan/internal/loadstor.h>
13
#include <botan/internal/sha3.h>
14
15
namespace Botan {
16
17
0
std::unique_ptr<HashFunction> Keccak_1600::copy_state() const {
18
0
   return std::make_unique<Keccak_1600>(*this);
19
0
}
20
21
1.07k
Keccak_1600::Keccak_1600(size_t output_bits) : m_keccak(2 * output_bits, 0, 0), m_output_length(output_bits / 8) {
22
   // We only support the parameters for the SHA-3 proposal
23
24
1.07k
   if(output_bits != 224 && output_bits != 256 && output_bits != 384 && output_bits != 512) {
25
0
      throw Invalid_Argument(fmt("Keccak_1600: Invalid output length {}", output_bits));
26
0
   }
27
1.07k
}
28
29
11
std::string Keccak_1600::name() const {
30
11
   return fmt("Keccak-1600({})", m_output_length * 8);
31
11
}
32
33
474
std::unique_ptr<HashFunction> Keccak_1600::new_object() const {
34
474
   return std::make_unique<Keccak_1600>(m_output_length * 8);
35
474
}
36
37
79.3k
void Keccak_1600::clear() {
38
79.3k
   m_keccak.clear();
39
79.3k
}
40
41
0
std::string Keccak_1600::provider() const {
42
0
   return m_keccak.provider();
43
0
}
44
45
266k
void Keccak_1600::add_data(std::span<const uint8_t> input) {
46
266k
   m_keccak.absorb(input);
47
266k
}
48
49
78.7k
void Keccak_1600::final_result(std::span<uint8_t> output) {
50
78.7k
   m_keccak.finish();
51
78.7k
   m_keccak.squeeze(output);
52
78.7k
   clear();
53
78.7k
}
54
55
}  // namespace Botan