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