/src/botan/build/include/botan/internal/shake_xof.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
18 | | namespace Botan { |
19 | | |
20 | | /** |
21 | | * Base class for SHAKE-based XOFs |
22 | | */ |
23 | | class 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 | 0 | std::string provider() const final { return m_keccak.provider(); } |
34 | | |
35 | 0 | size_t block_size() const final { return m_keccak.byte_rate(); } |
36 | | |
37 | 0 | 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 | | */ |
52 | | class SHAKE_128_XOF final : public SHAKE_XOF { |
53 | | public: |
54 | 0 | SHAKE_128_XOF() : SHAKE_XOF(256) {} |
55 | | |
56 | 0 | std::string name() const final { return "SHAKE-128"; } |
57 | | |
58 | 0 | std::unique_ptr<XOF> copy_state() const final { return std::make_unique<SHAKE_128_XOF>(*this); } |
59 | | |
60 | 0 | 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 | | */ |
66 | | class SHAKE_256_XOF final : public SHAKE_XOF { |
67 | | public: |
68 | 0 | SHAKE_256_XOF() : SHAKE_XOF(512) {} |
69 | | |
70 | 0 | std::string name() const final { return "SHAKE-256"; } |
71 | | |
72 | 0 | std::unique_ptr<XOF> copy_state() const final { return std::make_unique<SHAKE_256_XOF>(*this); } |
73 | | |
74 | 0 | std::unique_ptr<XOF> new_object() const final { return std::make_unique<SHAKE_256_XOF>(); } |
75 | | }; |
76 | | |
77 | | } // namespace Botan |
78 | | |
79 | | #endif |