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

#include <aes_crystals_xof.h>

Inheritance diagram for Botan::AES_256_CTR_XOF:
Botan::XOF

Public Member Functions

bool accepts_input () const override
 
 AES_256_CTR_XOF ()
 
size_t block_size () const override
 
void clear ()
 
std::unique_ptr< XOFcopy_state () const override
 
Key_Length_Specification key_spec () const override
 
std::string name () const override
 
std::unique_ptr< XOFnew_object () const override
 
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 reset () override
 
void start (std::span< const uint8_t > salt={}, std::span< const uint8_t > key={})
 
void update (std::span< const uint8_t > input)
 
bool valid_salt_length (size_t iv_length) const override
 
 ~AES_256_CTR_XOF () override
 

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

XOF implementation for Kyber/Dilithium 90s-modes based on AES-256 in counter mode.

This is an internal class that is not meant for consumption by library users. It is therefore not registered in XOF::create().

Definition at line 26 of file aes_crystals_xof.h.

Constructor & Destructor Documentation

◆ AES_256_CTR_XOF()

Botan::AES_256_CTR_XOF::AES_256_CTR_XOF ( )

Definition at line 17 of file aes_crystals_xof.cpp.

17: m_stream_cipher(StreamCipher::create_or_throw(name())) {}
std::string name() const override
static std::unique_ptr< StreamCipher > create_or_throw(std::string_view algo_spec, std::string_view provider="")

◆ ~AES_256_CTR_XOF()

Botan::AES_256_CTR_XOF::~AES_256_CTR_XOF ( )
overridedefault

Member Function Documentation

◆ accepts_input()

bool Botan::AES_256_CTR_XOF::accepts_input ( ) const
inlineoverridevirtual

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 47 of file aes_crystals_xof.h.

47{ return false; }

◆ block_size()

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

Implements Botan::XOF.

Definition at line 41 of file aes_crystals_xof.h.

41{ return 16; }

◆ clear()

void Botan::XOF::clear ( )
inlineinherited

Reset the state.

Definition at line 66 of file xof.h.

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

◆ copy_state()

std::unique_ptr< XOF > Botan::AES_256_CTR_XOF::copy_state ( ) const
overridevirtual

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 38 of file aes_crystals_xof.cpp.

38 {
39 throw Not_Implemented(fmt("Copying the state of XOF {} is not implemented", name()));
40}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

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

◆ 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 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 Botan::XOF::provider().

Referenced by Botan::XOF::create_or_throw().

◆ 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 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 Botan::XOF::create(), and Botan::XOF::provider().

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

◆ key_spec()

Key_Length_Specification Botan::AES_256_CTR_XOF::key_spec ( ) const
overridevirtual
Returns
an object describing limits on the key size

Reimplemented from Botan::XOF.

Definition at line 34 of file aes_crystals_xof.cpp.

34 {
35 return m_stream_cipher->key_spec();
36}

◆ name()

std::string Botan::AES_256_CTR_XOF::name ( ) const
inlineoverridevirtual
Returns
the hash function name

Implements Botan::XOF.

Definition at line 33 of file aes_crystals_xof.h.

33{ return "CTR-BE(AES-256)"; }

Referenced by copy_state().

◆ new_object()

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

Implements Botan::XOF.

Definition at line 45 of file aes_crystals_xof.h.

45{ return std::make_unique<AES_256_CTR_XOF>(); }

◆ output() [1/2]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::XOF::output ( size_t bytes)
inlineinherited
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)
inlineinherited

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

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

◆ provider()

std::string Botan::XOF::provider ( ) const
virtualinherited
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 Botan::XOF::create(), and Botan::XOF::create_or_throw().

◆ providers()

std::vector< std::string > Botan::XOF::providers ( std::string_view algo_spec)
staticinherited
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}

◆ reset()

void Botan::AES_256_CTR_XOF::reset ( )
overridevirtual

Clear the XOF's internal state and allow for new input.

Implements Botan::XOF.

Definition at line 21 of file aes_crystals_xof.cpp.

21 {
22 m_stream_cipher->clear();
23}

◆ 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 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

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

◆ 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 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()

bool Botan::AES_256_CTR_XOF::valid_salt_length ( size_t iv_length) const
overridevirtual

Checks that the given iv_length is compatible with this XOF

Reimplemented from Botan::XOF.

Definition at line 30 of file aes_crystals_xof.cpp.

30 {
31 return m_stream_cipher->valid_iv_length(iv_length);
32}

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