/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/fmt.h> |
12 | | #include <botan/internal/keccak_perm.h> |
13 | | #include <botan/internal/loadstor.h> |
14 | | |
15 | | namespace Botan { |
16 | | |
17 | 42 | SHA_3::SHA_3(size_t output_bits) : m_keccak(2 * output_bits, 2, 2), m_output_length(output_bits / 8) { |
18 | | // We only support the parameters for SHA-3 in this constructor |
19 | | |
20 | 42 | if(output_bits != 224 && output_bits != 256 && output_bits != 384 && output_bits != 512) { |
21 | 0 | throw Invalid_Argument(fmt("SHA_3: Invalid output length {}", output_bits)); |
22 | 0 | } |
23 | 42 | } |
24 | | |
25 | 0 | std::string SHA_3::name() const { |
26 | 0 | return fmt("SHA-3({})", m_output_length * 8); |
27 | 0 | } |
28 | | |
29 | 0 | std::string SHA_3::provider() const { |
30 | 0 | return m_keccak.provider(); |
31 | 0 | } |
32 | | |
33 | 0 | std::unique_ptr<HashFunction> SHA_3::copy_state() const { |
34 | 0 | return std::make_unique<SHA_3>(*this); |
35 | 0 | } |
36 | | |
37 | 0 | std::unique_ptr<HashFunction> SHA_3::new_object() const { |
38 | 0 | return std::make_unique<SHA_3>(m_output_length * 8); |
39 | 0 | } |
40 | | |
41 | 0 | void SHA_3::clear() { |
42 | 0 | m_keccak.clear(); |
43 | 0 | } |
44 | | |
45 | 0 | void SHA_3::add_data(std::span<const uint8_t> input) { |
46 | 0 | m_keccak.absorb(input); |
47 | 0 | } |
48 | | |
49 | 0 | void SHA_3::final_result(std::span<uint8_t> output) { |
50 | 0 | m_keccak.finish(); |
51 | 0 | m_keccak.squeeze(output); |
52 | 0 | m_keccak.clear(); |
53 | 0 | } |
54 | | |
55 | | } // namespace Botan |