Botan 3.5.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>>
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>>
T process (const uint8_t in[], size_t length)
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T process (std::span< const uint8_t > in)
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T process (std::string_view in)
 
std::string provider () const final
 
void set_key (const SymmetricKey &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)

Definition at line 97 of file kmac.cpp.

97: 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

Member Function Documentation

◆ assert_key_material_set() [1/2]

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

Definition at line 139 of file sym_algo.h.

virtual bool has_keying_material() const =0
void assert_key_material_set() const
Definition sym_algo.h:139

References Botan::SymmetricAlgorithm::assert_key_material_set().

Referenced by Botan::SymmetricAlgorithm::assert_key_material_set(), Botan::Salsa20::cipher_bytes(), Botan::AES_128::decrypt_n(), Botan::AES_192::decrypt_n(), Botan::AES_256::decrypt_n(), Botan::ARIA_128::decrypt_n(), Botan::ARIA_192::decrypt_n(), Botan::ARIA_256::decrypt_n(), Botan::Blowfish::decrypt_n(), Botan::Camellia_128::decrypt_n(), Botan::Camellia_192::decrypt_n(), Botan::Camellia_256::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::DES::decrypt_n(), Botan::GOST_28147_89::decrypt_n(), Botan::IDEA::decrypt_n(), Botan::Kuznyechik::decrypt_n(), Botan::Lion::decrypt_n(), Botan::Noekeon::decrypt_n(), Botan::SEED::decrypt_n(), Botan::Serpent::decrypt_n(), Botan::SHACAL2::decrypt_n(), Botan::SM4::decrypt_n(), Botan::Threefish_512::decrypt_n(), Botan::TripleDES::decrypt_n(), Botan::Twofish::decrypt_n(), Botan::AES_128::encrypt_n(), Botan::AES_192::encrypt_n(), Botan::AES_256::encrypt_n(), Botan::ARIA_128::encrypt_n(), Botan::ARIA_192::encrypt_n(), Botan::ARIA_256::encrypt_n(), Botan::Blowfish::encrypt_n(), Botan::Camellia_128::encrypt_n(), Botan::Camellia_192::encrypt_n(), Botan::Camellia_256::encrypt_n(), Botan::CAST_128::encrypt_n(), Botan::DES::encrypt_n(), Botan::GOST_28147_89::encrypt_n(), Botan::IDEA::encrypt_n(), Botan::Kuznyechik::encrypt_n(), Botan::Lion::encrypt_n(), Botan::Noekeon::encrypt_n(), Botan::SEED::encrypt_n(), Botan::Serpent::encrypt_n(), Botan::SHACAL2::encrypt_n(), Botan::SM4::encrypt_n(), Botan::Threefish_512::encrypt_n(), Botan::TripleDES::encrypt_n(), Botan::Twofish::encrypt_n(), Botan::GHASH::final(), Botan::GHASH::ghash_update(), Botan::ChaCha::seek(), Botan::CTR_BE::seek(), Botan::Salsa20::seek(), Botan::OCB_Mode::set_associated_data_n(), Botan::Salsa20::set_iv_bytes(), Botan::GHASH::update(), and Botan::GHASH::update_associated_data().

◆ assert_key_material_set() [2/2]

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

Definition at line 141 of file sym_algo.h.

141 {
142 if(!predicate) {
143 throw_key_not_set_error();
144 }
145 }

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

References Botan::zap().

◆ clone()

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

Get a new object representing the same algorithm as *this

Definition at line 102 of file mac.h.

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

◆ 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 51 of file mac.cpp.

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

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

Referenced by botan_mac_init(), Botan::KDF::create(), Botan::PasswordHashFamily::create(), Botan::PBKDF::create(), and Botan::MessageAuthenticationCode::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

Definition at line 148 of file mac.cpp.

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

References Botan::MessageAuthenticationCode::create(), and Botan::MessageAuthenticationCode::provider().

Referenced by 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::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 of your choice.

Returns
a contiguous container holding the result

Definition at line 78 of file buf_comp.h.

78 {
79 T output(output_length());
80 final_result(output);
81 return output;
82 }
virtual size_t output_length() const =0
FE_25519 T
Definition ge.cpp:34

References T.

◆ final() [2/4]

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

Definition at line 86 of file buf_comp.h.

86 {
87 BOTAN_ARG_CHECK(out.size() >= output_length(), "provided output buffer has insufficient capacity");
88 final_result(out);
89 }
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29

References BOTAN_ARG_CHECK.

◆ final() [3/4]

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

Definition at line 92 of file buf_comp.h.

92 {
93 out.resize(output_length());
94 final_result(out);
95 }

◆ 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. Must be of length output_length()

Definition at line 70 of file buf_comp.h.

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

Referenced by Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::PseudorandomKeyGeneration::gen(), Botan::mgf1_mask(), Botan::pbkdf2(), Botan::Dilithium::Polynomial::poly_challenge(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), Botan::Sphincs_Hash_Functions_Shake::PRF_msg(), and Botan::sm2_compute_za().

◆ final_stdvec()

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

Definition at line 84 of file buf_comp.h.

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 116 of file mac.h.

116{ return false; }

◆ has_keying_material()

bool Botan::KMAC::has_keying_material ( ) const
finalvirtualinherited
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}

◆ key_spec()

Key_Length_Specification Botan::KMAC::key_spec ( ) const
finalvirtualinherited
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}

◆ maximum_keylength()

size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited
Returns
maximum allowed key length

Definition at line 95 of file sym_algo.h.

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

◆ minimum_keylength()

size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited
Returns
minimum allowed key length

Definition at line 100 of file sym_algo.h.

100{ return key_spec().minimum_keylength(); }
size_t minimum_keylength() const
Definition sym_algo.h:49

◆ name()

std::string Botan::KMAC256::name ( ) const
overridevirtual
Returns
the algorithm name

Implements Botan::SymmetricAlgorithm.

Definition at line 99 of file kmac.cpp.

99 {
100 return fmt("KMAC-256({})", output_length() * 8);
101}
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
Returns
new object representing the same algorithm as *this

Implements Botan::MessageAuthenticationCode.

Definition at line 103 of file kmac.cpp.

103 {
104 return std::make_unique<KMAC256>(output_length() * 8);
105}

References Botan::KMAC::output_length().

◆ output_length()

size_t Botan::KMAC::output_length ( ) const
finalvirtualinherited
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(), name(), Botan::KMAC128::new_object(), and new_object().

◆ 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 105 of file buf_comp.h.

105 {
106 update(in, length);
107 return final<T>();
108 }
int(* update)(CTX *, const void *, CC_LONG len)

References final, and update.

Referenced by Botan::Dilithium_Symmetric_Primitives::CRH(), Botan::Dilithium_Symmetric_Primitives::H(), Botan::Kyber_Symmetric_Primitives::H(), Botan::Kyber_Symmetric_Primitives::H(), and Botan::Kyber_Symmetric_Primitives::H().

◆ 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 129 of file buf_comp.h.

129 {
130 update(in);
131 return final<T>();
132 }

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 117 of file buf_comp.h.

117 {
118 update(in);
119 return final<T>();
120 }

References final, and update.

◆ provider()

std::string Botan::KMAC::provider ( ) const
finalvirtualinherited
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}

◆ providers()

std::vector< std::string > Botan::MessageAuthenticationCode::providers ( std::string_view algo_spec)
staticinherited
Returns
list of available providers for this algorithm, empty if not available

Definition at line 143 of file mac.cpp.

143 {
145}
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})
Definition scan_name.h:105

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 126 of file sym_algo.h.

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

References Botan::SymmetricAlgorithm::set_key().

Referenced by Botan::SymmetricAlgorithm::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 17 of file sym_algo.cpp.

17 {
18 if(!valid_keylength(key.size())) {
19 throw Invalid_Key_Length(name(), key.size());
20 }
21 key_schedule(key);
22}
bool valid_keylength(size_t length) const
Definition sym_algo.h:107
virtual std::string name() const =0

References Botan::SymmetricAlgorithm::name(), and Botan::SymmetricAlgorithm::valid_keylength().

◆ start() [1/3]

void Botan::MessageAuthenticationCode::start ( )
inlineinherited

Begin processing a message.

Definition at line 77 of file mac.h.

77{ return start_msg({}); }
virtual void start_msg(std::span< const uint8_t > nonce)
Definition mac.cpp:156

◆ 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 72 of file mac.h.

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

◆ start() [3/3]

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

Prepare for processing a message under the specified nonce

Most MACs neither require nor support a nonce; for these algorithms calling start_msg 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 65 of file mac.h.

65{ start_msg(nonce); }

◆ update() [1/4]

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

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

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 56 of file buf_comp.h.

56{ add_data({cast_char_ptr_to_uint8(str.data()), str.size()}); }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition mem_ops.h:273

References Botan::cast_char_ptr_to_uint8().

◆ update() [4/4]

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

Process a single byte.

Parameters
inthe byte to process

Definition at line 62 of file buf_comp.h.

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

◆ update_be() [1/3]

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

Definition at line 13 of file buf_comp.cpp.

13 {
14 uint8_t inb[sizeof(val)];
15 store_be(val, inb);
16 add_data({inb, sizeof(inb)});
17}
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:707

References Botan::store_be().

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

◆ update_be() [2/3]

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

Definition at line 19 of file buf_comp.cpp.

19 {
20 uint8_t inb[sizeof(val)];
21 store_be(val, inb);
22 add_data({inb, sizeof(inb)});
23}

References Botan::store_be().

◆ update_be() [3/3]

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

Definition at line 25 of file buf_comp.cpp.

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

References Botan::store_be().

◆ update_le() [1/3]

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

Definition at line 31 of file buf_comp.cpp.

31 {
32 uint8_t inb[sizeof(val)];
33 store_le(val, inb);
34 add_data({inb, sizeof(inb)});
35}
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:698

References Botan::store_le().

◆ update_le() [2/3]

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

Definition at line 37 of file buf_comp.cpp.

37 {
38 uint8_t inb[sizeof(val)];
39 store_le(val, inb);
40 add_data({inb, sizeof(inb)});
41}

References Botan::store_le().

◆ update_le() [3/3]

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

Definition at line 43 of file buf_comp.cpp.

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

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 107 of file sym_algo.h.

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

Referenced by Botan::SymmetricAlgorithm::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 85 of file mac.h.

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

◆ 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 92 of file mac.h.

92{ return verify_mac_result(in); }

◆ verify_mac_result()

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

Verify the MACs final result

Definition at line 166 of file mac.cpp.

166 {
167 secure_vector<uint8_t> our_mac = final();
168
169 if(our_mac.size() != mac.size()) {
170 return false;
171 }
172
173 return CT::is_equal(our_mac.data(), mac.data(), mac.size()).as_bool();
174}
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:486
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61

References Botan::CT::is_equal().


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