Botan 3.13.0
Crypto and TLS for C&
Botan::SHAKE_128_XOF Class Referencefinal

#include <shake_xof.h>

Inheritance diagram for Botan::SHAKE_128_XOF:
Botan::SHAKE_XOF Botan::XOF

Public Member Functions

bool accepts_input () const final
size_t block_size () const final
void clear ()
std::unique_ptr< XOFcopy_state () const final
virtual Key_Length_Specification key_spec () const
std::string name () const final
std::unique_ptr< XOFnew_object () const final
template<size_t count>
std::array< uint8_t, count > output ()
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
output (size_t bytes)
void output (std::span< uint8_t > output)
uint8_t output_next_byte ()
std::vector< uint8_t > output_stdvec (size_t bytes)
std::string provider () const final
 SHAKE_128_XOF ()
void start (std::span< const uint8_t > salt={}, std::span< const uint8_t > key={})
void update (std::span< const uint8_t > input)
virtual bool valid_salt_length (size_t salt_len) const

Static Public Member Functions

static std::unique_ptr< XOFcreate (std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< XOFcreate_or_throw (std::string_view algo_spec, std::string_view provider="")
static std::vector< std::string > providers (std::string_view algo_spec)

Detailed Description

SHAKE-128 as defined in FIPS Pub.202 Section 6.2

Definition at line 50 of file shake_xof.h.

Constructor & Destructor Documentation

◆ SHAKE_128_XOF()

Botan::SHAKE_128_XOF::SHAKE_128_XOF ( )
inline

Definition at line 52 of file shake_xof.h.

52: SHAKE_XOF(256) {}
SHAKE_XOF(size_t capacity)
Definition shake_xof.cpp:16

References Botan::SHAKE_XOF::SHAKE_XOF().

Member Function Documentation

◆ accepts_input()

bool Botan::SHAKE_XOF::accepts_input ( ) const
inlinefinalvirtualinherited

Typically, this is true for new objects and becomes false once output() was called for the first time.

Returns
true iff calling update() is legal in the current object state

Implements Botan::XOF.

Definition at line 35 of file shake_xof.h.

35{ return !m_output_generated; }

◆ block_size()

size_t Botan::SHAKE_XOF::block_size ( ) const
inlinefinalvirtualinherited

Return the internal block size of this XOF

Returns
the intrinsic processing block size of this XOF

Implements Botan::XOF.

Definition at line 33 of file shake_xof.h.

33{ return m_keccak.byte_rate(); }

◆ clear()

◆ copy_state()

std::unique_ptr< XOF > Botan::SHAKE_128_XOF::copy_state ( ) const
inlinefinalvirtual

Return a new XOF object with the same state as *this.

If the XOF is not yet in the output phase, it efficiently allows using several messages with a common prefix. Otherwise, the copied state will produce the same output bit stream as the original object at the time of this invocation.

This function should be called clone but for consistency with other classes it is called copy_state.

Returns
new XOF object

Implements Botan::XOF.

Definition at line 56 of file shake_xof.h.

56{ return std::make_unique<SHAKE_128_XOF>(*this); }

◆ create()

std::unique_ptr< XOF > Botan::XOF::create ( std::string_view algo_spec,
std::string_view provider = "" )
staticinherited

Create an instance based on a name, or return null if the algo/provider combination cannot be found. If provider is empty then best available is chosen.

Definition at line 28 of file xof.cpp.

28 {
29 const SCAN_Name req(algo_spec);
30
31 if(!provider.empty() && provider != "base") {
32 return nullptr; // unknown provider
33 }
34
35#if defined(BOTAN_HAS_SHAKE_XOF)
36 if(req.algo_name() == "SHAKE-128" && req.arg_count() == 0) {
37 return std::make_unique<SHAKE_128_XOF>();
38 }
39 if(req.algo_name() == "SHAKE-256" && req.arg_count() == 0) {
40 return std::make_unique<SHAKE_256_XOF>();
41 }
42#endif
43
44#if defined(BOTAN_HAS_ASCON_XOF128)
45 if(req.algo_name() == "Ascon-XOF128" && req.arg_count() == 0) {
46 return std::make_unique<Ascon_XOF128>();
47 }
48#endif
49
50 return nullptr;
51}
virtual std::string provider() const
Definition xof.cpp:66

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg_count(), and provider().

Referenced by botan_xof_init(), create_or_throw(), and ~XOF().

◆ create_or_throw()

std::unique_ptr< XOF > Botan::XOF::create_or_throw ( std::string_view algo_spec,
std::string_view provider = "" )
staticinherited

Create an instance based on a name If provider is empty then best available is chosen.

Parameters
algo_specalgorithm name
providerprovider implementation to use Throws Lookup_Error if not found.

Definition at line 54 of file xof.cpp.

54 {
55 if(auto xof = XOF::create(algo_spec, provider)) {
56 return xof;
57 }
58 throw Lookup_Error("XOF", algo_spec, provider);
59}
static std::unique_ptr< XOF > create(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:28

References create(), and provider().

Referenced by Botan::AES_256_CTR_XOF::AES_256_CTR_XOF(), Botan::create_pk_from_sk(), Botan::Kyber_Modern_Symmetric_Primitives::create_PRF(), Botan::ML_KEM_Symmetric_Primitives::create_PRF(), Botan::Kyber_Modern_Symmetric_Primitives::create_XOF(), Botan::ML_KEM_Symmetric_Primitives::create_XOF(), Botan::Dilithium_Symmetric_Primitives_Base::H(), Botan::Dilithium_Symmetric_Primitives_Base::H(), Botan::Dilithium_Symmetric_Primitives_Base::H_256(), Botan::Classic_McEliece_Parameters::prg(), Botan::sign_message(), and ~XOF().

◆ key_spec()

virtual Key_Length_Specification Botan::XOF::key_spec ( ) const
inlinevirtualinherited

Return the key lengths supported by this XOF

Returns
an object describing limits on the key size

Reimplemented in Botan::AES_256_CTR_XOF.

Definition at line 102 of file xof.h.

102 {
103 // Keys are not supported by default
104 return Key_Length_Specification(0);
105 }

Referenced by start().

◆ name()

std::string Botan::SHAKE_128_XOF::name ( ) const
inlinefinalvirtual

Return the name of this XOF

Returns
the hash function name

Implements Botan::XOF.

Definition at line 54 of file shake_xof.h.

54{ return "SHAKE-128"; }

◆ new_object()

std::unique_ptr< XOF > Botan::SHAKE_128_XOF::new_object ( ) const
inlinefinalvirtual

Create a new uninitialized object of the same type

Returns
new object representing the same algorithm as *this

Implements Botan::XOF.

Definition at line 58 of file shake_xof.h.

58{ return std::make_unique<SHAKE_128_XOF>(); }

◆ output() [1/3]

template<size_t count>
std::array< uint8_t, count > Botan::XOF::output ( )
inlineinherited

Generate a fixed number of output bytes into a std::array

Returns
the next count output bytes as a std::array<>.

Definition at line 172 of file xof.h.

172 {
173 std::array<uint8_t, count> out; // NOLINT(*-member-init)
174 generate_bytes(out);
175 return out;
176 }

◆ output() [2/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::XOF::output ( size_t bytes)
inlineinherited

Generate output bytes into a newly allocated container

Returns
the next bytes output bytes as the specified container type T.

Definition at line 161 of file xof.h.

161 {
162 T out(bytes);
163 generate_bytes(out);
164 return out;
165 }

Referenced by Botan::FrodoMatrix::make_sample_generator(), output(), and output_stdvec().

◆ output() [3/3]

void Botan::XOF::output ( std::span< uint8_t > output)
inlineinherited

Generate output bytes into a caller provided buffer Fill output with the next output bytes. The number of bytes depends on the size of output.

Definition at line 191 of file xof.h.

191{ generate_bytes(output); }
T output(size_t bytes)
Definition xof.h:161

References output().

◆ output_next_byte()

uint8_t Botan::XOF::output_next_byte ( )
inlineinherited

Generate a single output byte

Returns
the next single output byte

Definition at line 197 of file xof.h.

197 {
198 uint8_t out = 0;
199 generate_bytes({&out, 1});
200 return out;
201 }

◆ output_stdvec()

std::vector< uint8_t > Botan::XOF::output_stdvec ( size_t bytes)
inlineinherited

Convenience overload to generate a std::vector<uint8_t>. Same as calling XOF::output<std::vector<uint8_t>>().

Returns
the next bytes output bytes as a byte vector.

Definition at line 184 of file xof.h.

184{ return output<std::vector<uint8_t>>(bytes); }

References output().

◆ provider()

std::string Botan::SHAKE_XOF::provider ( ) const
inlinefinalvirtualinherited

Return the name of the provider implementing this object

Returns
provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

Reimplemented from Botan::XOF.

Definition at line 31 of file shake_xof.h.

31{ return m_keccak.provider(); }

◆ providers()

std::vector< std::string > Botan::XOF::providers ( std::string_view algo_spec)
staticinherited

List the providers available for a given XOF

Returns
list of available providers for this algorithm, empty if not available
Parameters
algo_specalgorithm name

Definition at line 62 of file xof.cpp.

62 {
63 return probe_providers_of<XOF>(algo_spec, {"base"});
64}
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})
Definition scan_name.h:99

References Botan::probe_providers_of().

Referenced by ~XOF().

◆ start()

void Botan::XOF::start ( std::span< const uint8_t > salt = {},
std::span< const uint8_t > key = {} )
inherited

Some XOFs can be parameterized with a salt and/or key. If required, this must be called before calling XOF::update().

See also
XOF::valid_salt_length()
XOF::key_spec()
Parameters
salta salt value to parameterize the XOF
keya key to parameterize the XOF

Definition at line 70 of file xof.cpp.

70 {
71 if(!key_spec().valid_keylength(key.size())) {
72 throw Invalid_Key_Length(name(), key.size());
73 }
74
75 if(!valid_salt_length(salt.size())) {
76 throw Invalid_Argument(fmt("{} cannot accept a salt length of {}", name(), salt.size()));
77 }
78
79 m_xof_started = true;
80 start_msg(salt, key);
81}
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
virtual std::string name() const =0
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt(), key_spec(), name(), and valid_salt_length().

Referenced by name(), and update().

◆ update()

void Botan::XOF::update ( std::span< const uint8_t > input)
inlineinherited

Add input data to the XOF's internal state

Parameters
inputthe data that shall be

Definition at line 147 of file xof.h.

147 {
148 if(!m_xof_started) {
149 // If the user didn't start() before the first input, we enforce
150 // it with a default value, here.
151 start();
152 }
153 add_data(input);
154 }
void start(std::span< const uint8_t > salt={}, std::span< const uint8_t > key={})
Definition xof.cpp:70

References start().

Referenced by Botan::Kyber_Modern_Symmetric_Primitives::init_PRF(), Botan::ML_KEM_Symmetric_Primitives::init_PRF(), Botan::Kyber_Modern_Symmetric_Primitives::init_XOF(), and Botan::ML_KEM_Symmetric_Primitives::init_XOF().

◆ valid_salt_length()

virtual bool Botan::XOF::valid_salt_length ( size_t salt_len) const
inlinevirtualinherited

Test if a salt length is valid for this XOF

Returns
true if salt length is acceptable, false otherwise

Reimplemented in Botan::AES_256_CTR_XOF, and Botan::cSHAKE_XOF.

Definition at line 93 of file xof.h.

93 {
94 // Salts are not supported by default
95 return salt_len == 0;
96 }

Referenced by start().


The documentation for this class was generated from the following file: