Botan 3.6.1
Crypto and TLS for C&
shake_xof.h
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#ifndef BOTAN_SHAKE_XOF_H_
11#define BOTAN_SHAKE_XOF_H_
12
13#include <botan/xof.h>
14#include <botan/internal/keccak_perm.h>
15
16#include <vector>
17
18namespace Botan {
19
20/**
21 * Base class for SHAKE-based XOFs
22 */
23class SHAKE_XOF : public XOF {
24 protected:
25 /**
26 * Defines a concrete instance of a SHAKE XOF.
27 *
28 * @param capacity either 256 or 512
29 */
30 SHAKE_XOF(size_t capacity);
31
32 public:
33 std::string provider() const final { return m_keccak.provider(); }
34
35 size_t block_size() const final { return m_keccak.byte_rate(); }
36
37 bool accepts_input() const final { return !m_output_generated; }
38
39 private:
40 void add_data(std::span<const uint8_t> input) final;
41 void generate_bytes(std::span<uint8_t> output) final;
42 void reset() final;
43
44 private:
45 Keccak_Permutation m_keccak;
46 bool m_output_generated;
47};
48
49/**
50 * SHAKE-128 as defined in FIPS Pub.202 Section 6.2
51 */
53 public:
55
56 std::string name() const final { return "SHAKE-128"; }
57
58 std::unique_ptr<XOF> copy_state() const final { return std::make_unique<SHAKE_128_XOF>(*this); }
59
60 std::unique_ptr<XOF> new_object() const final { return std::make_unique<SHAKE_128_XOF>(); }
61};
62
63/**
64 * SHAKE-256 as defined in FIPS Pub.202 Section 6.2
65 */
67 public:
69
70 std::string name() const final { return "SHAKE-256"; }
71
72 std::unique_ptr<XOF> copy_state() const final { return std::make_unique<SHAKE_256_XOF>(*this); }
73
74 std::unique_ptr<XOF> new_object() const final { return std::make_unique<SHAKE_256_XOF>(); }
75};
76
77} // namespace Botan
78
79#endif
size_t byte_rate() const
Definition keccak_perm.h:55
std::string provider() const
std::string name() const final
Definition shake_xof.h:56
std::unique_ptr< XOF > copy_state() const final
Definition shake_xof.h:58
std::unique_ptr< XOF > new_object() const final
Definition shake_xof.h:60
std::unique_ptr< XOF > copy_state() const final
Definition shake_xof.h:72
std::string name() const final
Definition shake_xof.h:70
std::unique_ptr< XOF > new_object() const final
Definition shake_xof.h:74
size_t block_size() const final
Definition shake_xof.h:35
SHAKE_XOF(size_t capacity)
Definition shake_xof.cpp:14
bool accepts_input() const final
Definition shake_xof.h:37
std::string provider() const final
Definition shake_xof.h:33
std::array< uint8_t, count > output()
Definition xof.h:165
int(* final)(unsigned char *, CTX *)