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