Botan 3.5.0
Crypto and TLS for C&
cshake_xof.h
Go to the documentation of this file.
1/*
2 * cSHAKE-128 and cSHAKE-256 as XOFs
3 *
4 * (C) 2016-2023 Jack Lloyd
5 * 2022-2023 René Meusel - Rohde & Schwarz Cybersecurity
6 *
7 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9
10#ifndef BOTAN_CSHAKE_XOF_H_
11#define BOTAN_CSHAKE_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 cSHAKE-based XOFs
22 */
24 protected:
25 /**
26 * Defines a concrete instance of a cSHAKE XOF.
27 *
28 * @param capacity either 256 or 512
29 * @param function_name a domain separator for Keccak-based functions
30 * derived from cSHAKE
31 */
32 cSHAKE_XOF(size_t capacity, std::vector<uint8_t> function_name);
33 cSHAKE_XOF(size_t capacity, std::span<const uint8_t> function_name);
34 cSHAKE_XOF(size_t capacity, std::string_view function_name);
35
36 public:
37 std::string provider() const final;
38
39 bool valid_salt_length(size_t salt_length) const final;
40
41 size_t block_size() const final;
42
43 bool accepts_input() const final { return !m_output_generated; }
44
45 protected:
46 const std::vector<uint8_t>& function_name() const { return m_function_name; }
47
48 private:
49 /**
50 * @param salt the S value for cSHAKE (see NIST SP.800-185)
51 * @param key not supported, must be an empty buffer
52 */
53 void start_msg(std::span<const uint8_t> salt, std::span<const uint8_t> key) final;
54 void add_data(std::span<const uint8_t> input) final;
55 void generate_bytes(std::span<uint8_t> output) final;
56 void reset() final;
57
58 private:
59 Keccak_Permutation m_keccak;
60 std::vector<uint8_t> m_function_name;
61 bool m_output_generated;
62};
63
64/**
65 * customizable SHAKE-128 as defined in NIST SP.800-185
66 * This class is meant for internal use only and is not exposed via XOF::create().
67 */
69 public:
70 cSHAKE_128_XOF(std::vector<uint8_t> function_name) : cSHAKE_XOF(256, std::move(function_name)) {}
71
72 cSHAKE_128_XOF(std::span<const uint8_t> function_name) : cSHAKE_XOF(256, function_name) {}
73
74 cSHAKE_128_XOF(std::string_view function_name) : cSHAKE_XOF(256, function_name) {}
75
76 std::string name() const final { return "cSHAKE-128"; }
77
78 std::unique_ptr<XOF> copy_state() const final { return std::make_unique<cSHAKE_128_XOF>(*this); }
79
80 std::unique_ptr<XOF> new_object() const final { return std::make_unique<cSHAKE_128_XOF>(function_name()); }
81};
82
83/**
84 * customizable SHAKE-256 as defined in NIST SP.800-185
85 * This class is meant for internal use only and is not exposed via XOF::create().
86 */
88 public:
89 cSHAKE_256_XOF(std::vector<uint8_t> function_name) : cSHAKE_XOF(512, std::move(function_name)) {}
90
91 cSHAKE_256_XOF(std::span<const uint8_t> function_name) : cSHAKE_XOF(512, function_name) {}
92
93 cSHAKE_256_XOF(std::string_view function_name) : cSHAKE_XOF(512, function_name) {}
94
95 std::string name() const final { return "cSHAKE-256"; }
96
97 std::unique_ptr<XOF> copy_state() const final { return std::make_unique<cSHAKE_256_XOF>(*this); }
98
99 std::unique_ptr<XOF> new_object() const final { return std::make_unique<cSHAKE_256_XOF>(function_name()); }
100};
101
102} // namespace Botan
103
104#endif
std::unique_ptr< XOF > new_object() const final
Definition cshake_xof.h:80
std::unique_ptr< XOF > copy_state() const final
Definition cshake_xof.h:78
cSHAKE_128_XOF(std::string_view function_name)
Definition cshake_xof.h:74
std::string name() const final
Definition cshake_xof.h:76
cSHAKE_128_XOF(std::span< const uint8_t > function_name)
Definition cshake_xof.h:72
cSHAKE_128_XOF(std::vector< uint8_t > function_name)
Definition cshake_xof.h:70
std::string name() const final
Definition cshake_xof.h:95
cSHAKE_256_XOF(std::vector< uint8_t > function_name)
Definition cshake_xof.h:89
cSHAKE_256_XOF(std::span< const uint8_t > function_name)
Definition cshake_xof.h:91
std::unique_ptr< XOF > copy_state() const final
Definition cshake_xof.h:97
std::unique_ptr< XOF > new_object() const final
Definition cshake_xof.h:99
cSHAKE_256_XOF(std::string_view function_name)
Definition cshake_xof.h:93
bool accepts_input() const final
Definition cshake_xof.h:43
const std::vector< uint8_t > & function_name() const
Definition cshake_xof.h:46
int(* final)(unsigned char *, CTX *)
#define BOTAN_TEST_API
Definition compiler.h:51