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