Botan 3.4.0
Crypto and TLS for C&
shake_cipher.h
Go to the documentation of this file.
1/*
2 * SHAKE-128 and SHAKE-256 as a stream ciphers
3 * (C) 2016 Jack Lloyd
4 * 2022 René Meusel, Michael Boric - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_SHAKE_CIPHER_H_
10#define BOTAN_SHAKE_CIPHER_H_
11
12#include <botan/stream_cipher.h>
13#include <botan/internal/keccak_perm.h>
14
15namespace Botan {
16
17/**
18* Base class for SHAKE-based XOFs presented as a stream cipher
19*/
20class SHAKE_Cipher : public StreamCipher {
21 protected:
22 explicit SHAKE_Cipher(size_t keccak_capacity);
23
24 public:
25 /**
26 * Seeking is not supported, this function will throw
27 */
28 void seek(uint64_t offset) final;
29
30 void clear() final;
31
33
34 bool has_keying_material() const final { return m_has_keying_material; }
35
36 size_t buffer_size() const final { return m_keccak.byte_rate(); }
37
38 private:
39 void key_schedule(std::span<const uint8_t> key) final;
40 /**
41 * Produce more XOF output
42 */
43 void cipher_bytes(const uint8_t in[], uint8_t out[], size_t length) final;
44 void generate_keystream(uint8_t out[], size_t length) override;
45
46 void generate_keystream_internal(std::span<uint8_t> out);
47
48 /**
49 * IV not supported, this function will throw unless iv_len == 0
50 */
51 void set_iv_bytes(const uint8_t iv[], size_t iv_len) final;
52
53 private:
54 Keccak_Permutation m_keccak;
55 bool m_has_keying_material;
56 secure_vector<uint8_t> m_keystream_buffer;
57 size_t m_bytes_generated;
58};
59
61 public:
63
64 std::string name() const override { return "SHAKE-128"; }
65
66 std::unique_ptr<StreamCipher> new_object() const override { return std::make_unique<SHAKE_128_Cipher>(); }
67};
68
70 public:
72
73 std::string name() const override { return "SHAKE-256"; }
74
75 std::unique_ptr<StreamCipher> new_object() const override { return std::make_unique<SHAKE_256_Cipher>(); }
76};
77
78} // namespace Botan
79
80#endif
size_t byte_rate() const
Definition keccak_perm.h:55
std::unique_ptr< StreamCipher > new_object() const override
std::string name() const override
std::unique_ptr< StreamCipher > new_object() const override
std::string name() const override
bool has_keying_material() const final
Key_Length_Specification key_spec() const final
size_t buffer_size() const final
SHAKE_Cipher(size_t keccak_capacity)
void seek(uint64_t offset) final
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61