Botan 3.10.0
Crypto and TLS for C&
shake_xof.cpp
Go to the documentation of this file.
1/*
2 * SHAKE-128 and SHAKE-256 as XOFs
3 *
4 * (C) 2016-2023 Jack Lloyd
5 * 2022-2023 Fabian Albert, Michael Boric, René Meusel - Rohde & Schwarz Cybersecurity
6 *
7 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9
10#include <botan/internal/shake_xof.h>
11
12#include <botan/assert.h>
13
14namespace Botan {
15
16SHAKE_XOF::SHAKE_XOF(size_t capacity) :
17 m_keccak({.capacity_bits = capacity, .padding = KeccakPadding::shake()}), m_output_generated(false) {
18 BOTAN_ASSERT_NOMSG(capacity == 256 || capacity == 512);
19}
20
21void SHAKE_XOF::reset() {
22 m_keccak.clear();
23 m_output_generated = false;
24}
25
26void SHAKE_XOF::add_data(std::span<const uint8_t> input) {
27 BOTAN_STATE_CHECK(!m_output_generated);
28 m_keccak.absorb(input);
29}
30
31void SHAKE_XOF::generate_bytes(std::span<uint8_t> output) {
32 if(!m_output_generated) {
33 m_output_generated = true;
34 m_keccak.finish();
35 }
36
37 m_keccak.squeeze(output);
38}
39
40} // namespace Botan
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
SHAKE_XOF(size_t capacity)
Definition shake_xof.cpp:16
T output(size_t bytes)
Definition xof.h:153
static constexpr KeccakPadding shake()
NIST FIPS 202 Section 6.2.
Definition keccak_perm.h:27