Botan 3.10.0
Crypto and TLS for C&
keccak.cpp
Go to the documentation of this file.
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
13namespace Botan {
14
15std::unique_ptr<HashFunction> Keccak_1600::copy_state() const {
16 return std::make_unique<Keccak_1600>(*this);
17}
18
19Keccak_1600::Keccak_1600(size_t output_bits) :
20 m_keccak({.capacity_bits = 2 * output_bits, .padding = KeccakPadding::keccak1600()}),
21 m_output_length(output_bits / 8) {
22 // We only support the parameters for the SHA-3 proposal
23
24 if(output_bits != 224 && output_bits != 256 && output_bits != 384 && output_bits != 512) {
25 throw Invalid_Argument(fmt("Keccak_1600: Invalid output length {}", output_bits));
26 }
27}
28
29std::string Keccak_1600::name() const {
30 return fmt("Keccak-1600({})", m_output_length * 8);
31}
32
33std::unique_ptr<HashFunction> Keccak_1600::new_object() const {
34 return std::make_unique<Keccak_1600>(m_output_length * 8);
35}
36
38 m_keccak.clear();
39}
40
41std::string Keccak_1600::provider() const {
42 return m_keccak.provider();
43}
44
45void Keccak_1600::add_data(std::span<const uint8_t> input) {
46 m_keccak.absorb(input);
47}
48
49void Keccak_1600::final_result(std::span<uint8_t> output) {
50 m_keccak.finish();
51 m_keccak.squeeze(output);
52 clear();
53}
54
55} // namespace Botan
std::string provider() const override
Definition keccak.cpp:41
void clear() override
Definition keccak.cpp:37
std::unique_ptr< HashFunction > new_object() const override
Definition keccak.cpp:33
Keccak_1600(size_t output_bits=512)
Definition keccak.cpp:19
std::string name() const override
Definition keccak.cpp:29
std::unique_ptr< HashFunction > copy_state() const override
Definition keccak.cpp:15
void squeeze(std::span< uint8_t > output)
Expand output data from the current Keccak state.
void absorb(std::span< const uint8_t > input)
Absorb input data into the Keccak sponge.
void finish()
Add final padding (as provided in the constructor) and permute.
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
static constexpr KeccakPadding keccak1600()
Keccak submission, prior to the introduction of an algorithm specific padding.
Definition keccak_perm.h:33