Botan 3.6.1
Crypto and TLS for C&
Botan::MessageAuthenticationCode Class Referenceabstract

#include <mac.h>

Inheritance diagram for Botan::MessageAuthenticationCode:
Botan::Buffered_Computation Botan::SymmetricAlgorithm Botan::ANSI_X919_MAC Botan::BLAKE2bMAC Botan::CMAC Botan::GMAC Botan::HMAC Botan::KMAC Botan::Poly1305 Botan::SipHash

Public Member Functions

virtual void clear ()=0
 
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
 
virtual bool has_keying_material () const =0
 
virtual Key_Length_Specification key_spec () const =0
 
size_t maximum_keylength () const
 
size_t minimum_keylength () const
 
virtual std::string name () const =0
 
virtual std::unique_ptr< MessageAuthenticationCodenew_object () const =0
 
virtual size_t output_length () const =0
 
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)
 
virtual std::string provider () const
 
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)
 
 ~MessageAuthenticationCode () override=default
 

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 void start_msg (std::span< const uint8_t > nonce)
 
virtual bool verify_mac_result (std::span< const uint8_t > in)
 

Detailed Description

This class represents Message Authentication Code (MAC) objects.

Definition at line 22 of file mac.h.

Constructor & Destructor Documentation

◆ ~MessageAuthenticationCode()

Botan::MessageAuthenticationCode::~MessageAuthenticationCode ( )
overridedefault

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

◆ clone()

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

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 = "" )
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
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 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 = "" )
static

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 create(), and 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

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

◆ key_spec()

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

◆ new_object()

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

Implemented in Botan::ANSI_X919_MAC, Botan::BLAKE2bMAC, Botan::CMAC, Botan::GMAC, Botan::HMAC, Botan::KMAC128, Botan::KMAC256, Botan::Poly1305, and Botan::SipHash.

◆ output_length()

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

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

Reimplemented in Botan::KMAC.

Definition at line 108 of file mac.h.

108{ return "base"; }

Referenced by create(), and create_or_throw().

◆ providers()

std::vector< std::string > Botan::MessageAuthenticationCode::providers ( std::string_view algo_spec)
static
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 ( )
inline

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 )
inline

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)
inline

Prepare for processing a message under the specified nonce

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

65{ start_msg(nonce); }

◆ start_msg()

void Botan::MessageAuthenticationCode::start_msg ( std::span< const uint8_t > nonce)
protectedvirtual

Prepare for processing a message under the specified nonce

If the MAC does not support nonces, it should not override the default implementation.

Definition at line 156 of file mac.cpp.

156 {
157 BOTAN_UNUSED(nonce);
158 if(!nonce.empty()) {
159 throw Invalid_IV_Length(name(), nonce.size());
160 }
161}

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

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

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

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 )
inline

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)
inline

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)
protectedvirtual

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