Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::XOF Class Referenceabstract

#include <xof.h>

Inheritance diagram for Botan::XOF:
Botan::AES_256_CTR_XOF Botan::SHAKE_XOF Botan::cSHAKE_XOF Botan::SHAKE_128_XOF Botan::SHAKE_256_XOF Botan::cSHAKE_128_XOF Botan::cSHAKE_256_XOF

Public Member Functions

virtual bool accepts_input () const =0
 
virtual size_t block_size () const =0
 
void clear ()
 
virtual std::unique_ptr< XOFcopy_state () const =0
 
virtual Key_Length_Specification key_spec () const
 
virtual std::string name () const =0
 
virtual std::unique_ptr< XOFnew_object () const =0
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
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)
 
virtual std::string provider () const
 
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
 
 XOF ()
 
virtual ~XOF ()=default
 

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

This class represents an eXtendable Output Function (XOF) objects

A XOF transforms an arbitrary length input message into an indefinite stream of output bits. Typically, it is illegal to call update() after the first call to output().

Definition at line 29 of file xof.h.

Constructor & Destructor Documentation

◆ XOF()

Botan::XOF::XOF ( )
inline

Definition at line 31 of file xof.h.

31: m_xof_started(false) {}

◆ ~XOF()

virtual Botan::XOF::~XOF ( )
virtualdefault

Member Function Documentation

◆ accepts_input()

virtual bool Botan::XOF::accepts_input ( ) const
pure virtual

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

Implemented in Botan::cSHAKE_XOF, Botan::SHAKE_XOF, and Botan::AES_256_CTR_XOF.

◆ block_size()

virtual size_t Botan::XOF::block_size ( ) const
pure virtual
Returns
the intrinsic processing block size of this XOF

Implemented in Botan::cSHAKE_XOF, Botan::SHAKE_XOF, and Botan::AES_256_CTR_XOF.

◆ clear()

void Botan::XOF::clear ( )
inline

Reset the state.

Definition at line 66 of file xof.h.

66 {
67 m_xof_started = false;
68 reset();
69 }

◆ copy_state()

virtual std::unique_ptr< XOF > Botan::XOF::copy_state ( ) const
pure virtual

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

Implemented in Botan::cSHAKE_128_XOF, Botan::cSHAKE_256_XOF, Botan::SHAKE_128_XOF, Botan::SHAKE_256_XOF, and Botan::AES_256_CTR_XOF.

◆ create()

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

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 22 of file xof.cpp.

22 {
23 const SCAN_Name req(algo_spec);
24
25 if(!provider.empty() && provider != "base") {
26 return nullptr; // unknown provider
27 }
28
29#if defined(BOTAN_HAS_SHAKE_XOF)
30 if(req.algo_name() == "SHAKE-128" && req.arg_count() == 0) {
31 return std::make_unique<SHAKE_128_XOF>();
32 }
33 if(req.algo_name() == "SHAKE-256" && req.arg_count() == 0) {
34 return std::make_unique<SHAKE_256_XOF>();
35 }
36#endif
37
38 return nullptr;
39}
virtual std::string provider() const
Definition xof.cpp:54

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

Referenced by create_or_throw().

◆ create_or_throw()

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

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 42 of file xof.cpp.

42 {
43 if(auto xof = XOF::create(algo_spec, provider)) {
44 return xof;
45 }
46 throw Lookup_Error("XOF", algo_spec, provider);
47}
static std::unique_ptr< XOF > create(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:22

References create(), and provider().

Referenced by Botan::FrodoKEMConstants::FrodoKEMConstants(), and Botan::Dilithium_Common_Symmetric_Primitives::XOF().

◆ key_spec()

virtual Key_Length_Specification Botan::XOF::key_spec ( ) const
inlinevirtual
Returns
an object describing limits on the key size

Reimplemented in Botan::AES_256_CTR_XOF.

Definition at line 99 of file xof.h.

99 {
100 // Keys are not supported by default
101 return Key_Length_Specification(0);
102 }

Referenced by start().

◆ name()

virtual std::string Botan::XOF::name ( ) const
pure virtual
Returns
the hash function name

Implemented in Botan::cSHAKE_128_XOF, Botan::cSHAKE_256_XOF, Botan::SHAKE_128_XOF, Botan::SHAKE_256_XOF, and Botan::AES_256_CTR_XOF.

Referenced by start().

◆ new_object()

virtual std::unique_ptr< XOF > Botan::XOF::new_object ( ) const
pure virtual
Returns
new object representing the same algorithm as *this

Implemented in Botan::cSHAKE_128_XOF, Botan::cSHAKE_256_XOF, Botan::SHAKE_128_XOF, Botan::SHAKE_256_XOF, and Botan::AES_256_CTR_XOF.

◆ output() [1/2]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::XOF::output ( size_t bytes)
inline
Returns
the next bytes output bytes as the specified container type T.

Definition at line 155 of file xof.h.

155 {
156 T out(bytes);
157 generate_bytes(out);
158 return out;
159 }
FE_25519 T
Definition ge.cpp:34

References T.

◆ output() [2/2]

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

Fill output with the next output bytes. The number of bytes depends on the size of output.

Definition at line 173 of file xof.h.

173{ generate_bytes(output); }
T output(size_t bytes)
Definition xof.h:155

◆ output_next_byte()

uint8_t Botan::XOF::output_next_byte ( )
inline
Returns
the next single output byte

Definition at line 178 of file xof.h.

178 {
179 uint8_t out;
180 generate_bytes({&out, 1});
181 return out;
182 }

◆ output_stdvec()

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

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 167 of file xof.h.

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

◆ provider()

std::string Botan::XOF::provider ( ) const
virtual
Returns
provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

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

Definition at line 54 of file xof.cpp.

54 {
55 return "base";
56}

Referenced by create(), and create_or_throw().

◆ providers()

std::vector< std::string > Botan::XOF::providers ( std::string_view algo_spec)
static
Returns
list of available providers for this algorithm, empty if not available
Parameters
algo_specalgorithm name

Definition at line 50 of file xof.cpp.

50 {
51 return probe_providers_of<XOF>(algo_spec, {"base"});
52}

◆ start()

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

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 58 of file xof.cpp.

58 {
59 if(!key_spec().valid_keylength(key.size())) {
60 throw Invalid_Key_Length(name(), key.size());
61 }
62
63 if(!valid_salt_length(salt.size())) {
64 throw Invalid_Argument(fmt("{} cannot accept a salt length of {}", name(), salt.size()));
65 }
66
67 m_xof_started = true;
68 start_msg(salt, key);
69}
virtual bool valid_salt_length(size_t salt_len) const
Definition xof.h:91
virtual Key_Length_Specification key_spec() const
Definition xof.h:99
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().

◆ update()

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

Add input data to the XOF's internal state

Parameters
inputthe data that shall be

Definition at line 142 of file xof.h.

142 {
143 if(!m_xof_started) {
144 // If the user didn't start() before the first input, we enforce
145 // it with a default value, here.
146 start();
147 }
148 add_data(input);
149 }
void start(std::span< const uint8_t > salt={}, std::span< const uint8_t > key={})
Definition xof.cpp:58

◆ valid_salt_length()

virtual bool Botan::XOF::valid_salt_length ( size_t salt_len) const
inlinevirtual
Returns
true if salt length is acceptable, false otherwise

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

Definition at line 91 of file xof.h.

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

Referenced by start().


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