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

#include <kmac.h>

Inheritance diagram for Botan::KMAC256:
Botan::KMAC Botan::MessageAuthenticationCode Botan::Buffered_Computation Botan::SymmetricAlgorithm

Public Member Functions

void clear () final
MessageAuthenticationCodeclone () const
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
final ()
void final (std::span< uint8_t > out)
template<concepts::resizable_byte_buffer T>
void final (T &out)
void final (uint8_t out[])
std::vector< uint8_t > final_stdvec ()
virtual bool fresh_key_required_per_message () const
bool has_keying_material () const final
Key_Length_Specification key_spec () const final
 KMAC256 (size_t output_bit_length)
size_t maximum_keylength () const
size_t minimum_keylength () const
std::string name () const override
std::unique_ptr< MessageAuthenticationCodenew_object () const override
size_t output_length () const final
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (const uint8_t in[], size_t length)
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (std::span< const uint8_t > in)
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (std::string_view in)
std::string provider () const final
void set_key (const OctetString &key)
void set_key (const uint8_t key[], size_t length)
void set_key (std::span< const uint8_t > key)
void start ()
void start (const uint8_t nonce[], size_t nonce_len)
void start (std::span< const uint8_t > nonce)
void update (const uint8_t in[], size_t length)
void update (std::span< const uint8_t > in)
void update (std::string_view str)
void update (uint8_t in)
void update_be (uint16_t val)
void update_be (uint32_t val)
void update_be (uint64_t val)
void update_le (uint16_t val)
void update_le (uint32_t val)
void update_le (uint64_t val)
bool valid_keylength (size_t length) const
bool verify_mac (const uint8_t in[], size_t length)
bool verify_mac (std::span< const uint8_t > in)

Static Public Member Functions

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

Protected Member Functions

void assert_key_material_set () const
void assert_key_material_set (bool predicate) const
virtual bool verify_mac_result (std::span< const uint8_t > in)

Detailed Description

KMAC-256 as specified in NIST SP.800-185 Section 4

Definition at line 63 of file kmac.h.

Constructor & Destructor Documentation

◆ KMAC256()

Botan::KMAC256::KMAC256 ( size_t output_bit_length)
explicit

Definition at line 101 of file kmac.cpp.

101: KMAC(std::make_unique<cSHAKE_256_XOF>("KMAC"), output_bit_length) {}
KMAC(std::unique_ptr< cSHAKE_XOF > cshake, size_t output_bit_length)
Definition kmac.cpp:18

References Botan::KMAC::KMAC().

Member Function Documentation

◆ assert_key_material_set() [1/2]

◆ assert_key_material_set() [2/2]

void Botan::SymmetricAlgorithm::assert_key_material_set ( bool predicate) const
inlineprotectedinherited

Throw Key_Not_Set unless the predicate holds

Parameters
predicateif false, a Key_Not_Set exception is thrown

Definition at line 186 of file sym_algo.h.

186 {
187 if(!predicate) {
188 throw_key_not_set_error();
189 }
190 }

◆ clear()

void Botan::KMAC::clear ( )
finalvirtualinherited

Reset the internal state. This includes not just the key, but any partial message that may have been in process.

Implements Botan::SymmetricAlgorithm.

Definition at line 27 of file kmac.cpp.

27 {
28 zap(m_encoded_key);
29 m_message_started = false;
30 m_cshake->clear();
31}
void zap(std::vector< T, Alloc > &vec)
Definition secmem.h:261

References Botan::zap().

◆ clone()

MessageAuthenticationCode * Botan::MessageAuthenticationCode::clone ( ) const
inlineinherited

Get a new object representing the same algorithm as *this

Definition at line 104 of file mac.h.

104{ return this->new_object().release(); }
virtual std::unique_ptr< MessageAuthenticationCode > new_object() const =0

References new_object().

◆ create()

std::unique_ptr< MessageAuthenticationCode > Botan::MessageAuthenticationCode::create ( 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
Returns
a null pointer if the algo/provider combination cannot be found

Definition at line 50 of file mac.cpp.

51 {
52 const SCAN_Name req(algo_spec);
53
54#if defined(BOTAN_HAS_BLAKE2BMAC)
55 if(req.algo_name() == "Blake2b" || req.algo_name() == "BLAKE2b") {
56 if(provider.empty() || provider == "base") {
57 return std::make_unique<BLAKE2bMAC>(req.arg_as_integer(0, 512));
58 }
59 }
60#endif
61
62#if defined(BOTAN_HAS_GMAC)
63 if(req.algo_name() == "GMAC" && req.arg_count() == 1) {
64 if(provider.empty() || provider == "base") {
65 if(auto bc = BlockCipher::create(req.arg(0))) {
66 return std::make_unique<GMAC>(std::move(bc));
67 }
68 }
69 }
70#endif
71
72#if defined(BOTAN_HAS_HMAC)
73 if(req.algo_name() == "HMAC" && req.arg_count() == 1) {
74 if(provider.empty() || provider == "base") {
75 if(auto hash = HashFunction::create(req.arg(0))) {
76 return std::make_unique<HMAC>(std::move(hash));
77 }
78 }
79 }
80#endif
81
82#if defined(BOTAN_HAS_POLY1305)
83 if(req.algo_name() == "Poly1305" && req.arg_count() == 0) {
84 if(provider.empty() || provider == "base") {
85 return std::make_unique<Poly1305>();
86 }
87 }
88#endif
89
90#if defined(BOTAN_HAS_SIPHASH)
91 if(req.algo_name() == "SipHash") {
92 if(provider.empty() || provider == "base") {
93 return std::make_unique<SipHash>(req.arg_as_integer(0, 2), req.arg_as_integer(1, 4));
94 }
95 }
96#endif
97
98#if defined(BOTAN_HAS_CMAC)
99 if((req.algo_name() == "CMAC" || req.algo_name() == "OMAC") && req.arg_count() == 1) {
100 if(provider.empty() || provider == "base") {
101 if(auto bc = BlockCipher::create(req.arg(0))) {
102 return std::make_unique<CMAC>(std::move(bc));
103 }
104 }
105 }
106#endif
107
108#if defined(BOTAN_HAS_ANSI_X919_MAC)
109 if(req.algo_name() == "X9.19-MAC") {
110 if(provider.empty() || provider == "base") {
111 return std::make_unique<ANSI_X919_MAC>();
112 }
113 }
114#endif
115
116#if defined(BOTAN_HAS_KMAC)
117 if(req.algo_name() == "KMAC-128") {
118 if(provider.empty() || provider == "base") {
119 if(req.arg_count() != 1) {
120 throw Invalid_Argument(
121 "invalid algorithm specification for KMAC-128: need exactly one argument for output bit length");
122 }
123 return std::make_unique<KMAC128>(req.arg_as_integer(0));
124 }
125 }
126
127 if(req.algo_name() == "KMAC-256") {
128 if(provider.empty() || provider == "base") {
129 if(req.arg_count() != 1) {
130 throw Invalid_Argument(
131 "invalid algorithm specification for KMAC-256: need exactly one argument for output bit length");
132 }
133 return std::make_unique<KMAC256>(req.arg_as_integer(0));
134 }
135 }
136#endif
137
138 BOTAN_UNUSED(req);
140
141 return nullptr;
142}
#define BOTAN_UNUSED
Definition assert.h:144
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:111
virtual std::string provider() const
Definition mac.h:111

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), BOTAN_UNUSED, Botan::BlockCipher::create(), Botan::HashFunction::create(), and provider().

Referenced by botan_mac_init(), Botan::KDF::create(), Botan::PasswordHashFamily::create(), Botan::PBKDF::create(), and create_or_throw().

◆ create_or_throw()

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

Create an instance based on a name, throwing if it is not available 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 a Lookup_Error if algo/provider combination cannot be found

Definition at line 149 of file mac.cpp.

150 {
151 if(auto mac = MessageAuthenticationCode::create(algo, provider)) {
152 return mac;
153 }
154 throw Lookup_Error("MAC", algo, provider);
155}
static std::unique_ptr< MessageAuthenticationCode > create(std::string_view algo_spec, std::string_view provider="")
Definition mac.cpp:50

References create(), and provider().

Referenced by Botan::ANSI_X919_MAC::ANSI_X919_MAC(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::TLS::Connection_Cipher_State::Connection_Cipher_State(), Botan::ECIES_System_Params::create_mac(), Botan::Sodium::crypto_auth_hmacsha256(), Botan::Sodium::crypto_auth_hmacsha512(), Botan::Sodium::crypto_auth_hmacsha512256(), Botan::Sodium::crypto_onetimeauth_poly1305(), Botan::Sodium::crypto_secretbox_detached(), Botan::Sodium::crypto_secretbox_open_detached(), Botan::Sodium::crypto_secretbox_xsalsa20poly1305(), Botan::Sodium::crypto_secretbox_xsalsa20poly1305_open(), Botan::Sodium::crypto_shorthash_siphash24(), Botan::TLS::Session::decrypt(), Botan::CryptoBox::decrypt_bin(), Botan::Scrypt::derive_key(), Botan::CryptoBox::encrypt(), Botan::TLS::Session::encrypt(), Botan::Encrypted_PSK_Database::Encrypted_PSK_Database(), Botan::PKCS12::export_to(), Botan::FPE_FE1::FPE_FE1(), Botan::TLS::Hello_Verify_Request::Hello_Verify_Request(), Botan::hkdf_expand_label(), Botan::HOTP::HOTP(), and Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator().

◆ final() [1/4]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::final ( )
inlineinherited

Complete the computation and retrieve the final result as a container.

Returns
a contiguous container holding the result

Definition at line 104 of file buf_comp.h.

104 {
105 T output(output_length());
106 final_result(output);
107 return output;
108 }
virtual size_t output_length() const =0

References output_length().

◆ final() [2/4]

void Botan::Buffered_Computation::final ( std::span< uint8_t > out)
inherited

Complete the computation and retrieve the final result

Parameters
outthe buffer to write the result to, must be output_length() bytes

Definition at line 54 of file buf_comp.cpp.

54 {
55 BOTAN_ARG_CHECK(out.size() >= output_length(), "Output buffer has insufficient capacity");
56 // Pass exactly output_length() bytes so that an oversized buffer has the
57 // result written to its leading bytes with the remainder left untouched.
58 final_result(out.first(output_length()));
59}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

References BOTAN_ARG_CHECK, and output_length().

◆ final() [3/4]

template<concepts::resizable_byte_buffer T>
void Botan::Buffered_Computation::final ( T & out)
inlineinherited

Complete the computation and retrieve the final result

Parameters
outa container which is resized to hold the result

Definition at line 127 of file buf_comp.h.

127 {
128 out.resize(output_length());
129 final_result(out);
130 }

References output_length().

◆ final() [4/4]

void Botan::Buffered_Computation::final ( uint8_t out[])
inlineinherited

Complete the computation and retrieve the final result.

Parameters
outThe byte array to be filled with the result, which must be of length output_length()

Definition at line 97 of file buf_comp.h.

97{ final_result({out, output_length()}); }

References output_length().

Referenced by Botan::expand_message_xmd(), final_stdvec(), Botan::PseudorandomKeyGeneration::gen(), Botan::TPM2::Verification_Operation::is_valid_signature(), Botan::mgf1_mask(), Botan::KMAC::operator=(), Botan::pbkdf2(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), process(), process(), process(), Botan::TPM2::Signature_Operation::sign(), and Botan::sm2_compute_za().

◆ final_stdvec()

std::vector< uint8_t > Botan::Buffered_Computation::final_stdvec ( )
inlineinherited

Complete the computation and retrieve the final result

Returns
a std::vector holding the result

Definition at line 114 of file buf_comp.h.

114{ return final<std::vector<uint8_t>>(); }
void final(uint8_t out[])
Definition buf_comp.h:97

References final().

◆ fresh_key_required_per_message()

virtual bool Botan::MessageAuthenticationCode::fresh_key_required_per_message ( ) const
inlinevirtualinherited
Returns
if a fresh key must be set for each message that is processed.

This is required for certain polynomial-based MACs which are insecure if a key is ever reused for two different messages.

Reimplemented in Botan::Poly1305.

Definition at line 119 of file mac.h.

119{ return false; }

◆ has_keying_material()

bool Botan::KMAC::has_keying_material ( ) const
finalvirtualinherited

Test whether a key has been set on this object

Returns
true if a key has been set on this object

Implements Botan::SymmetricAlgorithm.

Definition at line 48 of file kmac.cpp.

48 {
49 return !m_encoded_key.empty();
50}

Referenced by operator=().

◆ key_spec()

Key_Length_Specification Botan::KMAC::key_spec ( ) const
finalvirtualinherited

Return the key lengths supported by this algorithm

Returns
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 37 of file kmac.cpp.

37 {
38 // KMAC supports key lengths from zero up to 2²⁰⁴⁰ (2^(2040)) bits:
39 // https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-185.pdf#page=28
40 //
41 // However, we restrict the key length to 192 bytes in order to avoid allocation of overly
42 // large memory stretches when client code works with the maximal key length. We chose a
43 // boundary that contains the length of the default_salt of the one-step KDM with KMAC128
44 // of 164 bytes. (see NIST SP 800-56C Rev. 2, Section 4.1, Implementation-Dependent Parameters 3.).
45 return Key_Length_Specification(0, 192);
46}

Referenced by operator=().

◆ maximum_keylength()

size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited

Return the largest acceptable key length

Returns
maximum allowed key length

Definition at line 130 of file sym_algo.h.

130{ return key_spec().maximum_keylength(); }
size_t maximum_keylength() const
Definition sym_algo.h:58
virtual Key_Length_Specification key_spec() const =0

References key_spec().

◆ minimum_keylength()

size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited

Return the smallest acceptable key length

Returns
minimum allowed key length

Definition at line 136 of file sym_algo.h.

136{ return key_spec().minimum_keylength(); }
size_t minimum_keylength() const
Definition sym_algo.h:52

References key_spec().

◆ name()

std::string Botan::KMAC256::name ( ) const
overridevirtual

Return the name of this algorithm

Returns
the algorithm name

Implements Botan::SymmetricAlgorithm.

Definition at line 103 of file kmac.cpp.

103 {
104 return fmt("KMAC-256({})", output_length() * 8);
105}
size_t output_length() const final
Definition kmac.cpp:33
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt(), and Botan::KMAC::output_length().

◆ new_object()

std::unique_ptr< MessageAuthenticationCode > Botan::KMAC256::new_object ( ) const
overridevirtual

Create a new uninitialized object of the same type

Returns
new object representing the same algorithm as *this

Implements Botan::MessageAuthenticationCode.

Definition at line 107 of file kmac.cpp.

107 {
108 return std::make_unique<KMAC256>(output_length() * 8);
109}

References Botan::KMAC::output_length().

◆ output_length()

size_t Botan::KMAC::output_length ( ) const
finalvirtualinherited

Return the output length of this function

Returns
length of the output of this function in bytes

Implements Botan::Buffered_Computation.

Definition at line 33 of file kmac.cpp.

33 {
34 return m_output_bit_length / 8;
35}

Referenced by Botan::KMAC128::name(), Botan::KMAC256::name(), Botan::KMAC128::new_object(), Botan::KMAC256::new_object(), and operator=().

◆ process() [1/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::process ( const uint8_t in[],
size_t length )
inlineinherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters
inthe input to process as a byte array
lengththe length of the byte array
Returns
the result of the call to final()

Definition at line 140 of file buf_comp.h.

140 {
141 update(in, length);
142 return final<T>();
143 }
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:35

References final(), and update().

◆ process() [2/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::process ( std::span< const uint8_t > in)
inlineinherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters
inthe input to process as a contiguous container
Returns
the result of the call to final()

Definition at line 164 of file buf_comp.h.

164 {
165 update(in);
166 return final<T>();
167 }

References final(), and update().

◆ process() [3/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::process ( std::string_view in)
inlineinherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters
inthe input to process as a string
Returns
the result of the call to final()

Definition at line 152 of file buf_comp.h.

152 {
153 update(in);
154 return final<T>();
155 }

References final(), and update().

◆ provider()

std::string Botan::KMAC::provider ( ) const
finalvirtualinherited

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::MessageAuthenticationCode.

Definition at line 52 of file kmac.cpp.

52 {
53 return m_cshake->provider();
54}

Referenced by operator=().

◆ providers()

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

List the providers available for a given MAC

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

Definition at line 144 of file mac.cpp.

144 {
146}
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().

◆ set_key() [1/3]

◆ set_key() [2/3]

void Botan::SymmetricAlgorithm::set_key ( const uint8_t key[],
size_t length )
inlineinherited

Set the symmetric key of this object.

Parameters
keythe to be set as a byte array.
lengthin bytes of key param

Definition at line 162 of file sym_algo.h.

162{ set_key(std::span{key, length}); }

References set_key().

Referenced by set_key().

◆ set_key() [3/3]

void Botan::SymmetricAlgorithm::set_key ( std::span< const uint8_t > key)
inherited

Set the symmetric key of this object.

Parameters
keythe contiguous byte range to be set.

Definition at line 22 of file sym_algo.cpp.

22 {
23 if(!valid_keylength(key.size())) {
24 throw Invalid_Key_Length(name(), key.size());
25 }
26 key_schedule(key);
27}
bool valid_keylength(size_t length) const
Definition sym_algo.h:143
virtual std::string name() const =0

References name(), and valid_keylength().

◆ start() [1/3]

void Botan::MessageAuthenticationCode::start ( )
inlineinherited

Begin processing a message.

Definition at line 78 of file mac.h.

78{ return start_msg({}); }
virtual void start_msg(std::span< const uint8_t > nonce)=0

References start_msg().

◆ start() [2/3]

void Botan::MessageAuthenticationCode::start ( const uint8_t nonce[],
size_t nonce_len )
inlineinherited

Begin processing a message.

Parameters
noncethe per message nonce
nonce_lenlength of nonce

Definition at line 73 of file mac.h.

73{ start_msg({nonce, nonce_len}); }

References start_msg().

◆ start() [3/3]

void Botan::MessageAuthenticationCode::start ( std::span< const uint8_t > nonce)
inlineinherited

Prepare for processing a message under the specified nonce Calling start() abandons any partial message and begins a new one.

Most MACs neither require nor support a nonce; for these algorithms calling start() is optional and calling it with anything other than an empty string is an error. One MAC which requires a per-message nonce be specified is GMAC.

Default implementation simply rejects all non-empty nonces since most hash/MAC algorithms do not support randomization

Parameters
noncethe message nonce bytes

Definition at line 66 of file mac.h.

66{ start_msg(nonce); }

References start_msg().

◆ update() [1/4]

void Botan::Buffered_Computation::update ( const uint8_t in[],
size_t length )
inlineinherited

Add new input to process.

Parameters
inthe input to process as a byte array
lengthof param in in bytes

Definition at line 35 of file buf_comp.h.

35{ add_data({in, length}); }

Referenced by Botan::expand_message_xmd(), Botan::PseudorandomKeyGeneration::gen(), Botan::LMOTS_Public_Key::LMOTS_Public_Key(), Botan::mgf1_mask(), Botan::pbkdf2(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), process(), process(), process(), and Botan::sm2_compute_za().

◆ update() [2/4]

void Botan::Buffered_Computation::update ( std::span< const uint8_t > in)
inlineinherited

Add new input to process.

Parameters
inthe input to process as a contiguous data range

Definition at line 41 of file buf_comp.h.

41{ add_data(in); }

◆ update() [3/4]

void Botan::Buffered_Computation::update ( std::string_view str)
inherited

Add new input to process.

Parameters
strthe input to process as a std::string_view. Will be interpreted as a byte array based on the strings encoding.

Definition at line 14 of file buf_comp.cpp.

14 {
15 add_data(as_span_of_bytes(str));
16}
std::span< const uint8_t > as_span_of_bytes(const char *s, size_t len)
Definition mem_utils.h:59

References Botan::as_span_of_bytes().

◆ update() [4/4]

void Botan::Buffered_Computation::update ( uint8_t in)
inlineinherited

Process a single byte.

Parameters
inthe byte to process

Definition at line 90 of file buf_comp.h.

90{ add_data({&in, 1}); }

◆ update_be() [1/3]

void Botan::Buffered_Computation::update_be ( uint16_t val)
inherited

Add new input to process, encoded as a big-endian integer

Parameters
valthe value to process

Definition at line 18 of file buf_comp.cpp.

18 {
19 uint8_t inb[sizeof(val)];
20 store_be(val, inb);
21 add_data({inb, sizeof(inb)});
22}
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

References Botan::store_be().

Referenced by Botan::expand_message_xmd(), Botan::mgf1_mask(), and Botan::pbkdf2().

◆ update_be() [2/3]

void Botan::Buffered_Computation::update_be ( uint32_t val)
inherited

Add new input to process, encoded as a big-endian integer

Parameters
valthe value to process

Definition at line 24 of file buf_comp.cpp.

24 {
25 uint8_t inb[sizeof(val)];
26 store_be(val, inb);
27 add_data({inb, sizeof(inb)});
28}

References Botan::store_be().

◆ update_be() [3/3]

void Botan::Buffered_Computation::update_be ( uint64_t val)
inherited

Add new input to process, encoded as a big-endian integer

Parameters
valthe value to process

Definition at line 30 of file buf_comp.cpp.

30 {
31 uint8_t inb[sizeof(val)];
32 store_be(val, inb);
33 add_data({inb, sizeof(inb)});
34}

References Botan::store_be().

◆ update_le() [1/3]

void Botan::Buffered_Computation::update_le ( uint16_t val)
inherited

Add new input to process, encoded as a little-endian integer

Parameters
valthe value to process

Definition at line 36 of file buf_comp.cpp.

36 {
37 uint8_t inb[sizeof(val)];
38 store_le(val, inb);
39 add_data({inb, sizeof(inb)});
40}
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:736

References Botan::store_le().

◆ update_le() [2/3]

void Botan::Buffered_Computation::update_le ( uint32_t val)
inherited

Add new input to process, encoded as a little-endian integer

Parameters
valthe value to process

Definition at line 42 of file buf_comp.cpp.

42 {
43 uint8_t inb[sizeof(val)];
44 store_le(val, inb);
45 add_data({inb, sizeof(inb)});
46}

References Botan::store_le().

◆ update_le() [3/3]

void Botan::Buffered_Computation::update_le ( uint64_t val)
inherited

Add new input to process, encoded as a little-endian integer

Parameters
valthe value to process

Definition at line 48 of file buf_comp.cpp.

48 {
49 uint8_t inb[sizeof(val)];
50 store_le(val, inb);
51 add_data({inb, sizeof(inb)});
52}

References Botan::store_le().

◆ valid_keylength()

bool Botan::SymmetricAlgorithm::valid_keylength ( size_t length) const
inlineinherited

Check whether a given key length is valid for this algorithm.

Parameters
lengththe key length to be checked.
Returns
true if the key length is valid.

Definition at line 143 of file sym_algo.h.

143{ return key_spec().valid_keylength(length); }
bool valid_keylength(size_t length) const
Definition sym_algo.h:44

References key_spec().

Referenced by set_key().

◆ verify_mac() [1/2]

bool Botan::MessageAuthenticationCode::verify_mac ( const uint8_t in[],
size_t length )
inlineinherited

Verify a MAC.

Parameters
inthe MAC to verify as a byte array
lengththe length of param in
Returns
true if the MAC is valid, false otherwise

Definition at line 86 of file mac.h.

86{ return verify_mac_result({in, length}); }
virtual bool verify_mac_result(std::span< const uint8_t > in)
Definition mac.cpp:160

References verify_mac_result().

◆ verify_mac() [2/2]

bool Botan::MessageAuthenticationCode::verify_mac ( std::span< const uint8_t > in)
inlineinherited

Verify a MAC.

Parameters
inthe MAC to verify as a byte array
Returns
true if the MAC is valid, false otherwise

Definition at line 93 of file mac.h.

93{ return verify_mac_result(in); }

References verify_mac_result().

◆ verify_mac_result()

bool Botan::MessageAuthenticationCode::verify_mac_result ( std::span< const uint8_t > in)
protectedvirtualinherited

Verify the MACs final result

Definition at line 160 of file mac.cpp.

160 {
161 secure_vector<uint8_t> our_mac = final();
162
163 if(our_mac.size() != mac.size()) {
164 return false;
165 }
166
167 return CT::is_equal(our_mac.data(), mac.data(), mac.size()).as_bool();
168}
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:798
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128

References Botan::CT::is_equal().

Referenced by start_msg(), verify_mac(), and verify_mac().


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