Botan 3.8.1
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) : m_keccak(capacity, 0b1111, 4), m_output_generated(false) {
17 BOTAN_ASSERT_NOMSG(capacity == 256 || capacity == 512);
18}
19
20void SHAKE_XOF::reset() {
21 m_keccak.clear();
22 m_output_generated = false;
23}
24
25void SHAKE_XOF::add_data(std::span<const uint8_t> input) {
26 BOTAN_STATE_CHECK(!m_output_generated);
27 m_keccak.absorb(input);
28}
29
30void SHAKE_XOF::generate_bytes(std::span<uint8_t> output) {
31 if(!m_output_generated) {
32 m_output_generated = true;
33 m_keccak.finish();
34 }
35
36 m_keccak.squeeze(output);
37}
38
39} // namespace Botan
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:61
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:43
void absorb(std::span< const uint8_t > input)
Absorb input data into the Keccak sponge.
SHAKE_XOF(size_t capacity)
Definition shake_xof.cpp:16
T output(size_t bytes)
Definition xof.h:155