9#include <botan/internal/shake_cipher.h>
11#include <botan/exceptn.h>
12#include <botan/mem_ops.h>
17 m_keccak(keccak_capacity, 0xF, 4),
18 m_has_keying_material(false),
19 m_keystream_buffer(buffer_size()),
20 m_bytes_generated(0) {}
22void SHAKE_Cipher::set_iv_bytes(
const uint8_t [],
size_t length) {
38 m_has_keying_material =
false;
40 m_bytes_generated = 0;
43void SHAKE_Cipher::cipher_bytes(
const uint8_t in[], uint8_t out[],
size_t length) {
46 const auto block_size = m_keystream_buffer.size();
48 auto cipher_some = [&](
size_t bytes) {
52 generate_keystream_internal(std::span(m_keystream_buffer).first(bytes));
53 xor_buf(out, m_keystream_buffer.data(), in, bytes);
61 if(length > block_size) {
62 const auto bytes_to_alignment = block_size - m_bytes_generated % block_size;
63 cipher_some(bytes_to_alignment);
67 while(length >= block_size) {
68 cipher_some(block_size);
75void SHAKE_Cipher::generate_keystream(uint8_t out[],
size_t length) {
77 generate_keystream_internal({out, length});
80void SHAKE_Cipher::generate_keystream_internal(std::span<uint8_t> out) {
82 m_bytes_generated += out.size();
85void SHAKE_Cipher::key_schedule(std::span<const uint8_t> key) {
89 m_has_keying_material =
true;
#define BOTAN_ASSERT_NOMSG(expr)
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.
Key_Length_Specification key_spec() const final
SHAKE_Cipher(size_t keccak_capacity)
void seek(uint64_t offset) final
virtual std::string name() const =0
void assert_key_material_set() const
void zeroise(std::vector< T, Alloc > &vec)
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)