Botan 3.14.1
Crypto and TLS for C&
xof.cpp
Go to the documentation of this file.
1/*
2* Extendable Output Function Base Class
3* (C) 2023 Jack Lloyd
4* 2023 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#include <botan/xof.h>
10
11#include <botan/assert.h>
12#include <botan/internal/probe_providers.h>
13
14#if defined(BOTAN_HAS_SHAKE_XOF)
15 #include <botan/internal/shake_xof.h>
16#endif
17
18#if defined(BOTAN_HAS_ASCON_XOF128)
19 #include <botan/internal/ascon_xof128.h>
20#endif
21
22#include <botan/exceptn.h>
23#include <botan/internal/fmt.h>
24
25namespace Botan {
26
27//static
28std::unique_ptr<XOF> XOF::create(std::string_view algo_spec, std::string_view provider) {
29 if(!provider.empty() && provider != "base") {
30 return nullptr; // unknown provider
31 }
32
33#if defined(BOTAN_HAS_SHAKE_XOF)
34 if(algo_spec == "SHAKE-128") {
35 return std::make_unique<SHAKE_128_XOF>();
36 }
37 if(algo_spec == "SHAKE-256") {
38 return std::make_unique<SHAKE_256_XOF>();
39 }
40#endif
41
42#if defined(BOTAN_HAS_ASCON_XOF128)
43 if(algo_spec == "Ascon-XOF128") {
44 return std::make_unique<Ascon_XOF128>();
45 }
46#endif
47
48 return nullptr;
49}
50
51//static
52std::unique_ptr<XOF> XOF::create_or_throw(std::string_view algo_spec, std::string_view provider) {
53 if(auto xof = XOF::create(algo_spec, provider)) {
54 return xof;
55 }
56 throw Lookup_Error("XOF", algo_spec, provider);
57}
58
59// static
60std::vector<std::string> XOF::providers(std::string_view algo_spec) {
61 return probe_providers_of<XOF>(algo_spec, {"base"});
62}
63
64std::string XOF::provider() const {
65 return "base";
66}
67
68void XOF::start(std::span<const uint8_t> salt, std::span<const uint8_t> key) {
69 if(!key_spec().valid_keylength(key.size())) {
70 throw Invalid_Key_Length(name(), key.size());
71 }
72
73 if(!valid_salt_length(salt.size())) {
74 throw Invalid_Argument(fmt("{} cannot accept a salt length of {}", name(), salt.size()));
75 }
76
77 m_xof_started = true;
78 start_msg(salt, key);
79}
80
81void XOF::start_msg(std::span<const uint8_t> salt, std::span<const uint8_t> key) {
82 BOTAN_UNUSED(salt, key);
83}
84
85} // namespace Botan
#define BOTAN_UNUSED
Definition assert.h:151
static std::unique_ptr< XOF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:52
virtual std::string provider() const
Definition xof.cpp:64
virtual bool valid_salt_length(size_t salt_len) const
Definition xof.h:93
virtual Key_Length_Specification key_spec() const
Definition xof.h:102
static std::unique_ptr< XOF > create(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:28
virtual std::string name() const =0
void start(std::span< const uint8_t > salt={}, std::span< const uint8_t > key={})
Definition xof.cpp:68
static std::vector< std::string > providers(std::string_view algo_spec)
Definition xof.cpp:60
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})