Botan 2.19.5 Crypto and TLS for C&

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Botan::MessageAuthenticationCode Class Referenceabstract

`#include <mac.h>`

Inheritance diagram for Botan::MessageAuthenticationCode:

## Public Member Functions
virtual void | clear ()=0
virtual MessageAuthenticationCode * | clone () const =0
secure_vector< uint8_t > | final ()
template<typename Alloc >
void | final (std::vector< uint8_t, Alloc > &out)
void | final (uint8_t out[])
std::vector< uint8_t > | final_stdvec ()
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 size_t | output_length () const =0
secure_vector< uint8_t > | process (const secure_vector< uint8_t > &in)
secure_vector< uint8_t > | process (const std::string &in)
secure_vector< uint8_t > | process (const std::vector< uint8_t > &in)
secure_vector< uint8_t > | process (const uint8_t in[], size_t length)
virtual std::string | provider () const
template<typename Alloc >
void | set_key (const std::vector< uint8_t, Alloc > &key)
void | set_key (const SymmetricKey &key)
void | set_key (const uint8_t key[], size_t length)
void | start ()
template<typename Alloc >
void | start (const std::vector< uint8_t, Alloc > &nonce)
void | start (const uint8_t nonce[], size_t nonce_len)
virtual void | start_msg (const uint8_t nonce[], size_t nonce_len)
void | update (const secure_vector< uint8_t > &in)
void | update (const std::string &str)
void | update (const std::vector< uint8_t > &in)
void | update (const uint8_t in[], size_t length)
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
virtual bool | verify_mac (const secure_vector< uint8_t > &in)
virtual bool | verify_mac (const std::vector< uint8_t > &in)
virtual bool | verify_mac (const uint8_t in[], size_t length)
virtual | ~MessageAuthenticationCode ()

## Static Public Member Functions
static std::unique_ptr< MessageAuthenticationCode > | create (const std::string &algo_spec, const std::string &provider="")
static std::unique_ptr< MessageAuthenticationCode > | create_or_throw (const std::string &algo_spec, const std::string &provider="")
static std::vector< std::string > | providers (const std::string &algo_spec)

## Protected Member Functions
void | verify_key_set (bool cond) const

## Detailed Description

This class represents Message Authentication Code (MAC) objects.

Definition at line 21 of file mac.h.

## Constructor & Destructor Documentation

## ◆ ~MessageAuthenticationCode()

virtual Botan::MessageAuthenticationCode::~MessageAuthenticationCode | ( |  | ) |
| inline virtual

Definition at line 52 of file mac.h.

52{}

## Member Function Documentation

## ◆ clear()

virtual void Botan::SymmetricAlgorithm::clear | ( |  | ) |
| pure virtual inherited

Reset the state.

Implemented in Botan::AES_128, Botan::AES_192, Botan::AES_256, Botan::ARIA_128, Botan::ARIA_192, Botan::ARIA_256, Botan::Blowfish, Botan::Camellia_128, Botan::Camellia_192, Botan::Camellia_256, Botan::Cascade_Cipher, Botan::CAST_128, Botan::CAST_256, Botan::DES, Botan::TripleDES, Botan::DESX, Botan::GOST_28147_89, Botan::IDEA, Botan::KASUMI, Botan::Lion, Botan::MISTY1, Botan::Noekeon, Botan::SEED, Botan::Serpent, Botan::SHACAL2, Botan::SM4, Botan::Threefish_512, Botan::Twofish, Botan::XTEA, Botan::CBC_MAC, Botan::CMAC, Botan::GMAC, Botan::HMAC, Botan::Poly1305, Botan::SipHash, Botan::ANSI_X919_MAC, Botan::FPE_FE1, Botan::CCM_Mode, Botan::ChaCha20Poly1305_Mode, Botan::EAX_Mode, Botan::GCM_Mode, Botan::OCB_Mode, Botan::SIV_Mode, Botan::CBC_Mode, Botan::XTS_Mode, Botan::ChaCha, Botan::CTR_BE, Botan::OFB, Botan::RC4, Botan::Salsa20, Botan::SHAKE_128_Cipher, Botan::GHASH, Botan::CFB_Mode, and Botan::TLS::TLS_CBC_HMAC_AEAD_Mode.

Referenced by botan_block_cipher_clear(), botan_cipher_clear(), botan_mac_clear(), Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::clear(), and Botan::RC4::~RC4().

## ◆ clone()

virtual MessageAuthenticationCode * Botan::MessageAuthenticationCode::clone | ( |  | ) | const
| pure virtual

Get a new object representing the same algorithm as *this

Implemented in Botan::CBC_MAC, Botan::CMAC, Botan::GMAC, Botan::HMAC, Botan::Poly1305, Botan::SipHash, and Botan::ANSI_X919_MAC.

## ◆ create()

std::unique_ptr< MessageAuthenticationCode > Botan::MessageAuthenticationCode::create | ( | const std::string & | algo_spec,
|  | const std::string & | provider = `""`
| ) |  |
| static

Create an instance based on a name If provider is empty then best available is chosen.

Parameters

  algo_spec | algorithm name
  provider | provider implementation to use

Returns
  a null pointer if the algo/provider combination cannot be found

Definition at line 46 of file mac.cpp.

48 {
49 const SCAN_Name req(algo_spec);
50
51#if defined(BOTAN_HAS_GMAC)
52 if(req.algo_name() == "GMAC" && req.arg_count() == 1)
53 {
54 if(provider.empty() || provider == "base")
55 {
56 if(auto bc = BlockCipher::create(req.arg(0)))
57 return std::unique_ptr<MessageAuthenticationCode>(new GMAC(bc.release()));
58 }
59 }
60#endif
61
62#if defined(BOTAN_HAS_HMAC)
63 if(req.algo_name() == "HMAC" && req.arg_count() == 1)
64 {
65 if(provider.empty() || provider == "base")
66 {
67 if(auto h = HashFunction::create(req.arg(0)))
68 return std::unique_ptr<MessageAuthenticationCode>(new HMAC(h.release()));
69 }
70 }
71#endif
72
73#if defined(BOTAN_HAS_POLY1305)
74 if(req.algo_name() == "Poly1305" && req.arg_count() == 0)
75 {
76 if(provider.empty() || provider == "base")
77 return std::unique_ptr<MessageAuthenticationCode>(new Poly1305);
78 }
79#endif
80
81#if defined(BOTAN_HAS_SIPHASH)
82 if(req.algo_name() == "SipHash")
83 {
84 if(provider.empty() || provider == "base")
85 {
86 return std::unique_ptr<MessageAuthenticationCode>(
87 new SipHash(req.arg_as_integer(0, 2), req.arg_as_integer(1, 4)));
88 }
89 }
90#endif
91
92#if defined(BOTAN_HAS_CMAC)
93 if((req.algo_name() == "CMAC" || req.algo_name() == "OMAC") && req.arg_count() == 1)
94 {
95 if(provider.empty() || provider == "base")
96 {
97 if(auto bc = BlockCipher::create(req.arg(0)))
98 return std::unique_ptr<MessageAuthenticationCode>(new CMAC(bc.release()));
99 }
100 }
101#endif
102
103
104#if defined(BOTAN_HAS_CBC_MAC)
105 if(req.algo_name() == "CBC-MAC" && req.arg_count() == 1)
106 {
107 if(provider.empty() || provider == "base")
108 {
109 if(auto bc = BlockCipher::create(req.arg(0)))
110 return std::unique_ptr<MessageAuthenticationCode>(new CBC_MAC(bc.release()));
111 }
112 }
113#endif
114
115#if defined(BOTAN_HAS_ANSI_X919_MAC)
116 if(req.algo_name() == "X9.19-MAC")
117 {
118 if(provider.empty() || provider == "base")
119 {
120 return std::unique_ptr<MessageAuthenticationCode>(new ANSI_X919_MAC);
121 }
122 }
123#endif
124
125 BOTAN_UNUSED(req);
126 BOTAN_UNUSED(provider);
127
128 return nullptr;
129 }
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::BlockCipher::create
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
Definition: block_cipher.cpp:104
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:102
Botan::MessageAuthenticationCode::provider
virtual std::string provider() const
Definition: mac.h:135

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::PBKDF::create(), Botan::PasswordHashFamily::create(), create_or_throw(), and Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator().

## ◆ create_or_throw()

std::unique_ptr< MessageAuthenticationCode > Botan::MessageAuthenticationCode::create_or_throw | ( | const std::string & | algo_spec,
|  | const std::string & | provider = `""`
| ) |  |
| static

Definition at line 139 of file mac.cpp.

141 {
142 if(auto mac = MessageAuthenticationCode::create(algo, provider))
143 {
144 return mac;
145 }
146 throw Lookup_Error("MAC", algo, provider);
147 }
Botan::MessageAuthenticationCode::create
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
Definition: mac.cpp:46

References create(), and provider().

Referenced by Botan::AutoSeeded_RNG::AutoSeeded_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::TLS::Session::encrypt(), Botan::CryptoBox::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::scrypt().

## ◆ final() [1/3]

secure_vector< uint8_t > Botan::Buffered_Computation::final | ( |  | ) |
| inline inherited

Complete the computation and retrieve the final result.

Returns
  secure_vector holding the result

Definition at line 90 of file buf_comp.h.

91 {
92 secure_vector<uint8_t> output(output_length());
93 final_result(output.data());
94 return output;
95 }
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

## ◆ final() [2/3]

template<typename Alloc >

void Botan::Buffered_Computation::final | ( | std::vector< uint8_t, Alloc > & | out | ) |
| inline inherited

Definition at line 105 of file buf_comp.h.

106 {
107 out.resize(output_length());
108 final_result(out.data());
109 }

## ◆ final() [3/3]

void Botan::Buffered_Computation::final | ( | uint8_t | out[] | ) |
| inline inherited

Complete the computation and retrieve the final result.

Parameters

  out | The byte array to be filled with the result. Must be of length output_length()

Definition at line 83 of file buf_comp.h.

83{ final_result(out); }

Referenced by botan_mac_final(), Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), and Botan::pbkdf2().

## ◆ final_stdvec()

std::vector< uint8_t > Botan::Buffered_Computation::final_stdvec | ( |  | ) |
| inline inherited

Definition at line 97 of file buf_comp.h.

98 {
99 std::vector<uint8_t> output(output_length());
100 final_result(output.data());
101 return output;
102 }

## ◆ key_spec()

virtual Key_Length_Specification Botan::SymmetricAlgorithm::key_spec | ( |  | ) | const
| pure virtual inherited

Returns
  object describing limits on key size

Implemented in Botan::Block_Cipher_Fixed_Params< BS, KMIN, KMAX, KMOD, BaseClass >, Botan::Block_Cipher_Fixed_Params< 16, 16 >, Botan::Block_Cipher_Fixed_Params< 16, 24 >, Botan::Block_Cipher_Fixed_Params< 16, 32 >, Botan::Block_Cipher_Fixed_Params< 8, 1, 56 >, Botan::Block_Cipher_Fixed_Params< 8, 11, 16 >, Botan::Block_Cipher_Fixed_Params< 16, 4, 32, 4 >, Botan::Block_Cipher_Fixed_Params< 8, 8 >, Botan::Block_Cipher_Fixed_Params< 8, 24 >, Botan::Block_Cipher_Fixed_Params< 8, 32 >, Botan::Block_Cipher_Fixed_Params< 8, 16 >, Botan::Block_Cipher_Fixed_Params< 32, 16, 64, 4 >, Botan::Block_Cipher_Fixed_Params< 16, 16, 32, 8 >, Botan::Block_Cipher_Fixed_Params< 64, 64, 0, 1, Tweakable_Block_Cipher >, Botan::Block_Cipher_Fixed_Params< 8, 16, 24, 8 >, Botan::Cascade_Cipher, Botan::Lion, Botan::CBC_MAC, Botan::CMAC, Botan::GMAC, Botan::HMAC, Botan::Poly1305, Botan::SipHash, Botan::ANSI_X919_MAC, Botan::FPE_FE1, Botan::CCM_Mode, Botan::ChaCha20Poly1305_Mode, Botan::EAX_Mode, Botan::GCM_Mode, Botan::OCB_Mode, Botan::SIV_Mode, Botan::CBC_Mode, Botan::XTS_Mode, Botan::ChaCha, Botan::CTR_BE, Botan::OFB, Botan::RC4, Botan::Salsa20, Botan::SHAKE_128_Cipher, Botan::GHASH, Botan::CFB_Mode, and Botan::TLS::TLS_CBC_HMAC_AEAD_Mode.

Referenced by botan_cipher_get_keyspec(), botan_cipher_query_keylen(), Botan::CBC_Mode::key_spec(), Botan::XTS_Mode::key_spec(), and Botan::CFB_Mode::key_spec().

## ◆ maximum_keylength()

size_t Botan::SymmetricAlgorithm::maximum_keylength | ( |  | ) | const
| inline inherited

Returns
  maximum allowed key length

Definition at line 120 of file sym_algo.h.

121 {
122 return key_spec().maximum_keylength();
123 }
Botan::Key_Length_Specification::maximum_keylength
size_t maximum_keylength() const
Definition: sym_algo.h:70
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0

## ◆ minimum_keylength()

size_t Botan::SymmetricAlgorithm::minimum_keylength | ( |  | ) | const
| inline inherited

Returns
  minimum allowed key length

Definition at line 128 of file sym_algo.h.

129 {
130 return key_spec().minimum_keylength();
131 }
Botan::Key_Length_Specification::minimum_keylength
size_t minimum_keylength() const
Definition: sym_algo.h:62

Referenced by botan_block_cipher_get_keyspec(), and botan_mac_get_keyspec().

## ◆ name()

virtual std::string Botan::SymmetricAlgorithm::name | ( |  | ) | const
| pure virtual inherited

Returns
  the algorithm name

Implemented in Botan::AES_128, Botan::AES_192, Botan::AES_256, Botan::ARIA_128, Botan::ARIA_192, Botan::ARIA_256, Botan::Blowfish, Botan::Camellia_128, Botan::Camellia_192, Botan::Camellia_256, Botan::Cascade_Cipher, Botan::CAST_128, Botan::CAST_256, Botan::DES, Botan::TripleDES, Botan::DESX, Botan::GOST_28147_89, Botan::IDEA, Botan::KASUMI, Botan::Lion, Botan::MISTY1, Botan::Noekeon, Botan::SEED, Botan::Serpent, Botan::SHACAL2, Botan::SM4, Botan::Threefish_512, Botan::Twofish, Botan::XTEA, Botan::CBC_MAC, Botan::CMAC, Botan::GMAC, Botan::HMAC, Botan::Poly1305, Botan::SipHash, Botan::ANSI_X919_MAC, Botan::FPE_FE1, Botan::CCM_Mode, Botan::ChaCha20Poly1305_Mode, Botan::EAX_Mode, Botan::GCM_Mode, Botan::OCB_Mode, Botan::SIV_Mode, Botan::CBC_Mode, Botan::XTS_Mode, Botan::ChaCha, Botan::CTR_BE, Botan::OFB, Botan::RC4, Botan::Salsa20, Botan::SHAKE_128_Cipher, Botan::GHASH, Botan::CFB_Mode, and Botan::TLS::TLS_CBC_HMAC_AEAD_Mode.

Referenced by Botan::CBC_Mode::name(), Botan::XTS_Mode::name(), Botan::CFB_Mode::name(), Botan::AEAD_Mode::set_associated_data_n(), Botan::SymmetricAlgorithm::set_key(), and start_msg().

## ◆ output_length()

virtual size_t Botan::Buffered_Computation::output_length | ( |  | ) | const
| pure virtual inherited

Returns
  length of the output of this function in bytes

Implemented in Botan::BLAKE2b, Botan::Adler32, Botan::CRC24, Botan::CRC32, Botan::Comb4P, Botan::GOST_34_11, Botan::Keccak_1600, Botan::MD4, Botan::MD5, Botan::Parallel, Botan::RIPEMD_160, Botan::SHA_160, Botan::SHA_224, Botan::SHA_256, Botan::SHA_384, Botan::SHA_512, Botan::SHA_512_256, Botan::SHA_3, Botan::SHAKE_128, Botan::SHAKE_256, Botan::Skein_512, Botan::SM3, Botan::Streebog, Botan::Tiger, Botan::Whirlpool, Botan::CBC_MAC, Botan::CMAC, Botan::GMAC, Botan::HMAC, Botan::Poly1305, Botan::SipHash, and Botan::ANSI_X919_MAC.

Referenced by botan_mac_output_length(), Botan::Tiger::clone(), Botan::pbkdf2(), Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::TLS_CBC_HMAC_AEAD_Mode(), and Botan::MDx_HashFunction::write_count().

## ◆ process() [1/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process | ( | const secure_vector< uint8_t > & | in | ) |
| inline inherited

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

Parameters

  in | the input to process

Returns
  the result of the call to final()

Definition at line 130 of file buf_comp.h.

131 {
132 add_data(in.data(), in.size());
133 return final();
134 }

## ◆ process() [2/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process | ( | const std::string & | in | ) |
| inline inherited

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

Parameters

  in | the input to process as a string

Returns
  the result of the call to final()

Definition at line 154 of file buf_comp.h.

155 {
156 update(in);
157 return final();
158 }
Botan::Buffered_Computation::update
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:33

References update.

## ◆ process() [3/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process | ( | const std::vector< uint8_t > & | in | ) |
| inline inherited

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

Parameters

  in | the input to process

Returns
  the result of the call to final()

Definition at line 142 of file buf_comp.h.

143 {
144 add_data(in.data(), in.size());
145 return final();
146 }

## ◆ process() [4/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process | ( | const uint8_t | in[],
|  | size_t | length
| ) |  |
| inline inherited

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

Parameters

  in | the input to process as a byte array
  length | the length of the byte array

Returns
  the result of the call to final()

Definition at line 118 of file buf_comp.h.

119 {
120 add_data(in, length);
121 return final();
122 }

## ◆ provider()

virtual std::string Botan::MessageAuthenticationCode::provider | ( |  | ) | const
| inline virtual

Returns
  provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

Definition at line 135 of file mac.h.

135{ return "base"; }

Referenced by create(), and create_or_throw().

## ◆ providers()

std::vector< std::string > Botan::MessageAuthenticationCode::providers | ( | const std::string & | algo_spec | ) |
| static

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

Definition at line 132 of file mac.cpp.

133 {
134 return probe_providers_of<MessageAuthenticationCode>(algo_spec, {"base", "openssl"});
135 }

## ◆ set_key() [1/3]

template<typename Alloc >

void Botan::SymmetricAlgorithm::set_key | ( | const std::vector< uint8_t, Alloc > & | key | ) |
| inline inherited

Definition at line 153 of file sym_algo.h.

154 {
155 set_key(key.data(), key.size());
156 }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:147

## ◆ set_key() [2/3]

void Botan::SymmetricAlgorithm::set_key | ( | const SymmetricKey & | key | ) |
| inline inherited

Set the symmetric key of this object.

Parameters

  key | the SymmetricKey to be set.

Definition at line 147 of file sym_algo.h.

148 {
149 set_key(key.begin(), key.length());
150 }

References Botan::OctetString::begin(), and Botan::OctetString::length().

Referenced by Botan::aont_package(), Botan::aont_unpackage(), botan_block_cipher_set_key(), botan_cipher_set_key(), botan_mac_set_key(), Botan::Sodium::crypto_stream_salsa20(), Botan::Sodium::crypto_stream_salsa20_xor_ic(), Botan::Sodium::crypto_stream_xsalsa20(), Botan::Sodium::crypto_stream_xsalsa20_xor_ic(), Botan::FPE::fe1_decrypt(), Botan::FPE::fe1_encrypt(), and Botan::Sodium::randombytes_buf_deterministic().

## ◆ set_key() [3/3]

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

Set the symmetric key of this object.

Parameters

  key | the to be set as a byte array.
  length | in bytes of key param

Definition at line 17 of file sym_algo.cpp.

18 {
19 if(!valid_keylength(length))
20 throw Invalid_Key_Length(name(), length);
21 key_schedule(key, length);
22 }
Botan::SymmetricAlgorithm::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:138
Botan::SymmetricAlgorithm::name
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 93 of file mac.h.

94 {
95 return start_msg(nullptr, 0);
96 }
Botan::MessageAuthenticationCode::start_msg
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)
Definition: mac.cpp:149

## ◆ start() [2/3]

template<typename Alloc >

void Botan::MessageAuthenticationCode::start | ( | const std::vector< uint8_t, Alloc > & | nonce | ) |
| inline

Begin processing a message with a nonce

Parameters

  nonce | the per message nonce

Definition at line 75 of file mac.h.

76 {
77 start_msg(nonce.data(), nonce.size());
78 }

## ◆ start() [3/3]

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

Begin processing a message.

Parameters

  nonce | the per message nonce
  nonce_len | length of nonce

Definition at line 85 of file mac.h.

86 {
87 start_msg(nonce, nonce_len);
88 }

## ◆ start_msg()

void Botan::MessageAuthenticationCode::start_msg | ( | const uint8_t | nonce[],
|  | size_t | nonce_len
| ) |  |
| virtual

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.

Parameters

  nonce | the message nonce bytes
  nonce_len | the size of len in bytes Default implementation simply rejects all non-empty nonces since most hash/MAC algorithms do not support randomization

Definition at line 149 of file mac.cpp.

150 {
151 BOTAN_UNUSED(nonce);
152 if(nonce_len > 0)
153 throw Invalid_IV_Length(name(), nonce_len);
154 }

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

## ◆ update() [1/5]

void Botan::Buffered_Computation::update | ( | const secure_vector< uint8_t > & | in | ) |
| inline inherited

Add new input to process.

Parameters

  in | the input to process as a secure_vector

Definition at line 39 of file buf_comp.h.

40 {
41 add_data(in.data(), in.size());
42 }

## ◆ update() [2/5]

void Botan::Buffered_Computation::update | ( | const std::string & | str | ) |
| inline inherited

Add new input to process.

Parameters

  str | the input to process as a std::string. Will be interpreted as a byte array based on the strings encoding.

Definition at line 66 of file buf_comp.h.

67 {
68 add_data(cast_char_ptr_to_uint8(str.data()), str.size());
69 }
Botan::cast_char_ptr_to_uint8
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:190

References Botan::cast_char_ptr_to_uint8().

## ◆ update() [3/5]

void Botan::Buffered_Computation::update | ( | const std::vector< uint8_t > & | in | ) |
| inline inherited

Add new input to process.

Parameters

  in | the input to process as a std::vector

Definition at line 48 of file buf_comp.h.

49 {
50 add_data(in.data(), in.size());
51 }

## ◆ update() [4/5]

void Botan::Buffered_Computation::update | ( | const uint8_t | in[],
|  | size_t | length
| ) |  |
| inline inherited

Add new input to process.

Parameters

  in | the input to process as a byte array
  length | of param in in bytes

Definition at line 33 of file buf_comp.h.

33{ add_data(in, length); }

Referenced by botan_mac_update(), Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), and Botan::pbkdf2().

## ◆ update() [5/5]

void Botan::Buffered_Computation::update | ( | uint8_t | in | ) |
| inline inherited

Process a single byte.

Parameters

  in | the byte to process

Definition at line 75 of file buf_comp.h.

75{ add_data(&in, 1); }

## ◆ update_be() [1/3]

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

Definition at line 12 of file buf_comp.cpp.

13 {
14 uint8_t inb[sizeof(val)];
15 store_be(val, inb);
16 add_data(inb, sizeof(inb));
17 }
Botan::store_be
void store_be(uint16_t in, uint8_t out[2])
Definition: loadstor.h:438

References Botan::store_be().

Referenced by 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.

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

References Botan::store_be().

## ◆ update_be() [3/3]

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

Definition at line 26 of file buf_comp.cpp.

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

References Botan::store_be().

## ◆ update_le() [1/3]

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

Definition at line 33 of file buf_comp.cpp.

34 {
35 uint8_t inb[sizeof(val)];
36 store_le(val, inb);
37 add_data(inb, sizeof(inb));
38 }
Botan::store_le
void store_le(uint16_t in, uint8_t out[2])
Definition: loadstor.h:454

References Botan::store_le().

## ◆ update_le() [2/3]

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

Definition at line 40 of file buf_comp.cpp.

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

References Botan::store_le().

## ◆ update_le() [3/3]

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

Definition at line 47 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
| inline inherited

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

Parameters

  length | the key length to be checked.

Returns
  true if the key length is valid.

Definition at line 138 of file sym_algo.h.

139 {
140 return key_spec().valid_keylength(length);
141 }
Botan::Key_Length_Specification::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:52

Referenced by Botan::aont_package(), Botan::aont_unpackage(), and Botan::SymmetricAlgorithm::set_key().

## ◆ verify_key_set()

void Botan::SymmetricAlgorithm::verify_key_set | ( | bool | cond | ) | const
| inline protected inherited

Definition at line 171 of file sym_algo.h.

172 {
173 if(cond == false)
174 throw_key_not_set_error();
175 }

Referenced by Botan::ChaCha::cipher(), Botan::CTR_BE::cipher(), Botan::RC4::cipher(), Botan::Salsa20::cipher(), Botan::SHAKE_128_Cipher::cipher(), 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::CAST_256::decrypt_n(), Botan::DES::decrypt_n(), Botan::TripleDES::decrypt_n(), Botan::DESX::decrypt_n(), Botan::GOST_28147_89::decrypt_n(), Botan::IDEA::decrypt_n(), Botan::KASUMI::decrypt_n(), Botan::Lion::decrypt_n(), Botan::MISTY1::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::Twofish::decrypt_n(), Botan::XTEA::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::CAST_256::encrypt_n(), Botan::DES::encrypt_n(), Botan::TripleDES::encrypt_n(), Botan::DESX::encrypt_n(), Botan::GOST_28147_89::encrypt_n(), Botan::IDEA::encrypt_n(), Botan::KASUMI::encrypt_n(), Botan::Lion::encrypt_n(), Botan::MISTY1::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::Twofish::encrypt_n(), Botan::XTEA::encrypt_n(), Botan::OCB_Encryption::finish(), Botan::OCB_Decryption::finish(), Botan::GHASH::ghash_update(), Botan::CFB_Encryption::process(), Botan::CFB_Decryption::process(), Botan::ChaCha::seek(), Botan::CTR_BE::seek(), Botan::Salsa20::seek(), Botan::OCB_Mode::set_associated_data(), Botan::ChaCha::set_iv(), Botan::Salsa20::set_iv(), Botan::GHASH::update(), Botan::GHASH::update_associated_data(), and Botan::ChaCha::write_keystream().

## ◆ verify_mac() [1/3]

virtual bool Botan::MessageAuthenticationCode::verify_mac | ( | const secure_vector< uint8_t > & | in | ) |
| inline virtual

Verify a MAC.

Parameters

  in | the MAC to verify as a byte array

Returns
  true if the MAC is valid, false otherwise

Definition at line 121 of file mac.h.

122 {
123 return verify_mac(in.data(), in.size());
124 }
Botan::MessageAuthenticationCode::verify_mac
virtual bool verify_mac(const uint8_t in[], size_t length)
Definition: mac.cpp:159

## ◆ verify_mac() [2/3]

virtual bool Botan::MessageAuthenticationCode::verify_mac | ( | const std::vector< uint8_t > & | in | ) |
| inline virtual

Verify a MAC.

Parameters

  in | the MAC to verify as a byte array

Returns
  true if the MAC is valid, false otherwise

Definition at line 111 of file mac.h.

112 {
113 return verify_mac(in.data(), in.size());
114 }

## ◆ verify_mac() [3/3]

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

Verify a MAC.

Parameters

  in | the MAC to verify as a byte array
  length | the length of param in

Returns
  true if the MAC is valid, false otherwise

Definition at line 159 of file mac.cpp.

160 {
161 secure_vector<uint8_t> our_mac = final();
162
163 if(our_mac.size() != length)
164 return false;
165
166 return constant_time_compare(our_mac.data(), mac, length);
167 }
Botan::constant_time_compare
bool constant_time_compare(const uint8_t x[], const uint8_t y[], size_t len)
Definition: mem_ops.h:82

References Botan::constant_time_compare().

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

- src/lib/mac/mac.h
- src/lib/mac/mac.cpp