Botan 3.6.1
Crypto and TLS for C&
sha3.cpp
Go to the documentation of this file.
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
16namespace Botan {
17
18SHA_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 if(output_bits != 224 && output_bits != 256 && output_bits != 384 && output_bits != 512) {
22 throw Invalid_Argument(fmt("SHA_3: Invalid output length {}", output_bits));
23 }
24}
25
26std::string SHA_3::name() const {
27 return fmt("SHA-3({})", m_output_length * 8);
28}
29
30std::string SHA_3::provider() const {
31 return m_keccak.provider();
32}
33
34std::unique_ptr<HashFunction> SHA_3::copy_state() const {
35 return std::make_unique<SHA_3>(*this);
36}
37
38std::unique_ptr<HashFunction> SHA_3::new_object() const {
39 return std::make_unique<SHA_3>(m_output_length * 8);
40}
41
43 m_keccak.clear();
44}
45
46void SHA_3::add_data(std::span<const uint8_t> input) {
47 m_keccak.absorb(input);
48}
49
50void SHA_3::final_result(std::span<uint8_t> output) {
51 m_keccak.finish();
52 m_keccak.squeeze(output);
53 m_keccak.clear();
54}
55
56} // namespace Botan
void squeeze(std::span< uint8_t > output)
Expand output data from the current Keccak state.
std::string provider() const
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.
void clear() override
Definition sha3.cpp:42
SHA_3(size_t output_bits)
Definition sha3.cpp:18
std::unique_ptr< HashFunction > new_object() const override
Definition sha3.cpp:38
std::string provider() const override
Definition sha3.cpp:30
std::string name() const override
Definition sha3.cpp:26
std::unique_ptr< HashFunction > copy_state() const override
Definition sha3.cpp:34
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53