Botan: Botan::MessageAuthenticationCode Class Reference

Botan 1.10.16

Public 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
void | final (byte out[])
SecureVector< byte > | final ()
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
SecureVector< byte > | process (const byte in[], size_t length)
SecureVector< byte > | process (const MemoryRegion< byte > &in)
SecureVector< byte > | process (const std::string &in)
void | set_key (const SymmetricKey &key)
void | set_key (const byte key[], size_t length)
void | update (const byte in[], size_t length)
void | update (const MemoryRegion< byte > &in)
void | update (const std::string &str)
void | update (byte in)
template<typename T >
void | update_be (const T in)
bool | valid_keylength (size_t length) const
virtual bool | verify_mac (const byte in[], size_t length)

## Detailed Description

This class represents Message Authentication Code (MAC) objects.

Definition at line 20 of file mac.h.

## Member Function Documentation

## ◆ clear()

virtual void Botan::Algorithm::clear | ( |  | ) |
| pure virtualinherited

Zeroize internal state

Implemented in Botan::KDF, Botan::AES_256, Botan::AES_256_NI, Botan::AES_256_SSSE3, Botan::Camellia_256, Botan::GOST_28147_89, Botan::AES_192, Botan::AES_192_NI, Botan::Comb4P, Botan::SHA_256, Botan::SHA_512, Botan::AES_192_SSSE3, Botan::TripleDES, Botan::MDx_HashFunction, Botan::Camellia_192, Botan::CTR_BE, Botan::OFB, Botan::Lion, Botan::Skein_512, Botan::Keccak_1600, Botan::WiderWake_41_BE, Botan::Salsa20, Botan::Cascade_Cipher, Botan::LubyRackoff, Botan::Turing, Botan::RC2, Botan::Blowfish, Botan::PBKDF, Botan::Tiger, Botan::GOST_34_11, Botan::AES_128, Botan::AES_128_NI, Botan::HAS_160, Botan::MD2, Botan::SHA_224, Botan::CMAC, Botan::SSL3_MAC, Botan::Adler32, Botan::CRC24, Botan::CRC32, Botan::BMW_512, Botan::MD4, Botan::MD5, Botan::RIPEMD_128, Botan::RIPEMD_160, Botan::SHA_160, Botan::SHA_384, Botan::Whirlpool, Botan::CBC_MAC, Botan::AES_128_SSSE3, Botan::Camellia_128, Botan::CAST_128, Botan::CAST_256, Botan::DES, Botan::DESX, Botan::IDEA, Botan::KASUMI, Botan::MARS, Botan::MISTY1, Botan::Noekeon, Botan::SAFER_SK, Botan::SEED, Botan::Serpent, Botan::Skipjack, Botan::Square, Botan::TEA, Botan::Twofish, Botan::XTEA, Botan::ARC4, Botan::Parallel, Botan::HMAC, and Botan::ANSI_X919_MAC.

Referenced by Botan::HMAC::clear(), Botan::ANSI_X919_MAC::clear(), Botan::ANSI_X931_RNG::clear(), Botan::CBC_MAC::clear(), Botan::SSL3_MAC::clear(), Botan::Randpool::clear(), Botan::CMAC::clear(), Botan::Cascade_Cipher::clear(), Botan::HMAC_RNG::clear(), Botan::LubyRackoff::clear(), Botan::Lion::clear(), Botan::OFB::clear(), Botan::CTR_BE::clear(), Botan::Comb4P::clear(), and Botan::OpenPGP_S2K::derive_key().

## ◆ clone()

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

Get a new object representing the same algorithm as *this

Implemented in Botan::ANSI_X919_MAC, Botan::CMAC, Botan::HMAC, Botan::SSL3_MAC, and Botan::CBC_MAC.

Referenced by Botan::Algorithm_Factory::make_mac().

## ◆ final() [1/2]

void Botan::Buffered_Computation::final | ( | byte | out[] | ) |
| inlineinherited

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

Referenced by Botan::Comb4P::clear(), Botan::LubyRackoff::decrypt_n(), Botan::Lion::decrypt_n(), Botan::X942_PRF::derive(), Botan::KDF1::derive(), Botan::KDF2::derive(), Botan::PKCS5_PBKDF2::derive_key(), Botan::OpenPGP_S2K::derive_key(), Botan::PKCS5_PBKDF1::derive_key(), Botan::EAX_Decryption::EAX_Decryption(), Botan::EMSA2::EMSA2(), Botan::LubyRackoff::encrypt_n(), Botan::Lion::encrypt_n(), Botan::Hash_Filter::end_msg(), Botan::MAC_Filter::end_msg(), Botan::HandshakeHash::final(), Botan::HandshakeHash::final_ssl3(), Botan::Record_Writer::flush(), Botan::Record_Reader::get_record(), Botan::MGF1::mask(), Botan::EAX_Base::name(), Botan::Randpool::randomize(), Botan::EMSA3::raw_data(), Botan::Randpool::reseed(), Botan::HMAC_RNG::reseed(), Botan::DLIES_Decryptor::~DLIES_Decryptor(), and Botan::DLIES_Encryptor::~DLIES_Encryptor().

80 { final_result(out); }

## ◆ final() [2/2]

SecureVector<byte> Botan::Buffered_Computation::final | ( |  | ) |
| inlineinherited

Complete the computation and retrieve the final result.

Returns
  SecureVector holding the result

Definition at line 87 of file buf_comp.h.

88 {
89 SecureVector<byte> output(output_length());
90 final_result(&output[0]);
91 return output;
92 }
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

## ◆ key_spec()

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

Returns
  object describing limits on key size

Implemented in Botan::Block_Cipher_Fixed_Params< BS, KMIN, KMAX, KMOD >, Botan::Block_Cipher_Fixed_Params< 16, 32 >, Botan::Block_Cipher_Fixed_Params< 8, 10 >, Botan::Block_Cipher_Fixed_Params< 16, 16, 32, 4 >, Botan::Block_Cipher_Fixed_Params< 8, 1, 56 >, Botan::Block_Cipher_Fixed_Params< 8, 32 >, Botan::Block_Cipher_Fixed_Params< 16, 16 >, Botan::Block_Cipher_Fixed_Params< 8, 11, 16 >, Botan::Block_Cipher_Fixed_Params< 8, 16, 24, 8 >, Botan::Block_Cipher_Fixed_Params< 16, 16, 32, 8 >, Botan::Block_Cipher_Fixed_Params< 16, 4, 32, 4 >, Botan::Block_Cipher_Fixed_Params< 8, 1, 32 >, Botan::Block_Cipher_Fixed_Params< 16, 24 >, Botan::Block_Cipher_Fixed_Params< 8, 16 >, Botan::Block_Cipher_Fixed_Params< 8, 8 >, Botan::Block_Cipher_Fixed_Params< 8, 24 >, Botan::Lion, Botan::WiderWake_41_BE, Botan::ARC4, Botan::CTR_BE, Botan::OFB, Botan::CMAC, Botan::HMAC, Botan::SSL3_MAC, Botan::Salsa20, Botan::LubyRackoff, Botan::CBC_MAC, Botan::ANSI_X919_MAC, Botan::Turing, and Botan::Cascade_Cipher.

## ◆ maximum_keylength()

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

Returns
  minimum allowed key length

Definition at line 33 of file sym_algo.h.

Referenced by Botan::Cascade_Cipher::decrypt_n(), and Botan::ANSI_X931_RNG::randomize().

34 {
35 return key_spec().maximum_keylength();
36 }
Botan::Key_Length_Specification::maximum_keylength
size_t maximum_keylength() const
Definition: key_spec.h:69
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0

## ◆ minimum_keylength()

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

Returns
  maxmium allowed key length

Definition at line 41 of file sym_algo.h.

42 {
43 return key_spec().minimum_keylength();
44 }
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0
Botan::Key_Length_Specification::minimum_keylength
size_t minimum_keylength() const
Definition: key_spec.h:61

## ◆ name()

virtual std::string Botan::MessageAuthenticationCode::name | ( |  | ) | const
| pure virtual

Get the name of this algorithm.

Returns
  name of this algorithm

Implements Botan::Algorithm.

Implemented in Botan::HMAC, Botan::ANSI_X919_MAC, Botan::CBC_MAC, Botan::CMAC, and Botan::SSL3_MAC.

Referenced by Botan::HMAC_RNG::HMAC_RNG(), Botan::Randpool::name(), and Botan::HMAC_RNG::name().

## ◆ output_length()

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

Returns
  length of the output of this function in bytes

Implemented in Botan::SHA_256, Botan::SHA_512, Botan::Comb4P, Botan::Skein_512, Botan::Keccak_1600, Botan::Parallel, Botan::HMAC, Botan::CBC_MAC, Botan::ANSI_X919_MAC, Botan::GOST_34_11, Botan::HAS_160, Botan::SHA_224, Botan::CMAC, Botan::SSL3_MAC, Botan::Adler32, Botan::CRC24, Botan::CRC32, Botan::BMW_512, Botan::MD2, Botan::MD4, Botan::MD5, Botan::RIPEMD_128, Botan::RIPEMD_160, Botan::SHA_160, Botan::SHA_384, Botan::Tiger, and Botan::Whirlpool.

Referenced by Botan::Comb4P::Comb4P(), Botan::LubyRackoff::decrypt_n(), Botan::PKCS5_PBKDF2::derive_key(), Botan::OpenPGP_S2K::derive_key(), Botan::PKCS5_PBKDF1::derive_key(), Botan::EMSA3::encoding_of(), Botan::LubyRackoff::encrypt_n(), Botan::HMAC_RNG::HMAC_RNG(), Botan::Randpool::Randpool(), Botan::Record_Writer::set_keys(), Botan::Record_Reader::set_keys(), Botan::EMSA3::verify(), Botan::MDx_HashFunction::write_count(), Botan::DLIES_Decryptor::~DLIES_Decryptor(), and Botan::DLIES_Encryptor::~DLIES_Encryptor().

## ◆ process() [1/3]

SecureVector<byte> Botan::Buffered_Computation::process | ( | const byte | in[],
|  | size_t | length
| ) |  |
| inlineinherited

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

Referenced by Botan::Randpool::add_entropy(), Botan::EME1::EME1(), and Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID().

102 {
103 add_data(in, length);
104 return final();
105 }

## ◆ process() [2/3]

SecureVector<byte> Botan::Buffered_Computation::process | ( | const MemoryRegion< byte > & | in | ) |
| inlineinherited

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

References Botan::MemoryRegion< T >::size().

114 {
115 add_data(&in[0], in.size());
116 return final();
117 }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ process() [3/3]

SecureVector<byte> Botan::Buffered_Computation::process | ( | const std::string & | in | ) |
| inlineinherited

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

126 {
127 update(in);
128 return final();
129 }
Botan::Buffered_Computation::update
void update(const byte in[], size_t length)
Definition: buf_comp.h:33

## ◆ set_key() [1/2]

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

Set the symmetric key of this object.

Parameters

  key | the SymmetricKey to be set.

Definition at line 60 of file sym_algo.h.

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

Referenced by Botan::aont_unpackage(), Botan::CTR_BE::clear(), Botan::OFB::clear(), Botan::DESX::decrypt_n(), Botan::Cascade_Cipher::decrypt_n(), Botan::Lion::decrypt_n(), Botan::PKCS5_PBKDF2::derive_key(), Botan::ECB_Decryption::ECB_Decryption(), Botan::ECB_Encryption::ECB_Encryption(), Botan::Lion::encrypt_n(), Botan::HMAC_RNG::HMAC_RNG(), Botan::MAC_Filter::MAC_Filter(), Botan::ANSI_X931_RNG::randomize(), Botan::Randpool::randomize(), Botan::HMAC_RNG::reseed(), Botan::XTS_Encryption::set_key(), Botan::EAX_Base::set_key(), Botan::XTS_Decryption::set_key(), Botan::Record_Writer::set_keys(), Botan::Record_Reader::set_keys(), Botan::StreamCipher_Filter::StreamCipher_Filter(), Botan::DLIES_Decryptor::~DLIES_Decryptor(), and Botan::DLIES_Encryptor::~DLIES_Encryptor().

61 { set_key(key.begin(), key.length()); }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:60

## ◆ set_key() [2/2]

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

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

69 {
70 if(!valid_keylength(length))
71 throw Invalid_Key_Length(name(), length);
72 key_schedule(key, length);
73 }
Botan::SymmetricAlgorithm::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:51
Botan::Algorithm::name
virtual std::string name() const =0

## ◆ update() [1/4]

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

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.

Referenced by Botan::HMAC_RNG::add_entropy(), Botan::Comb4P::clear(), Botan::LubyRackoff::decrypt_n(), Botan::Lion::decrypt_n(), Botan::X942_PRF::derive(), Botan::KDF1::derive(), Botan::KDF2::derive(), Botan::PKCS5_PBKDF2::derive_key(), Botan::OpenPGP_S2K::derive_key(), Botan::PKCS5_PBKDF1::derive_key(), Botan::EAX_Decryption::EAX_Decryption(), Botan::LubyRackoff::encrypt_n(), Botan::Lion::encrypt_n(), Botan::HandshakeHash::final(), Botan::HandshakeHash::final_ssl3(), Botan::Record_Writer::flush(), Botan::Record_Reader::get_record(), Botan::MGF1::mask(), Botan::EAX_Base::name(), Botan::Randpool::randomize(), Botan::HMAC_RNG::reseed(), Botan::EAX_Base::start_msg(), Botan::EMSA3::update(), Botan::DLIES_Decryptor::~DLIES_Decryptor(), and Botan::DLIES_Encryptor::~DLIES_Encryptor().

33 { add_data(in, length); }

## ◆ update() [2/4]

void Botan::Buffered_Computation::update | ( | const MemoryRegion< byte > & | in | ) |
| inlineinherited

Add new input to process.

Parameters

  in | the input to process as a MemoryRegion

Definition at line 39 of file buf_comp.h.

References Botan::MemoryRegion< T >::size().

40 {
41 add_data(&in[0], in.size());
42 }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ update() [3/4]

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

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

64 {
65 add_data(reinterpret_cast<const byte*>(str.data()), str.size());
66 }

## ◆ update() [4/4]

void Botan::Buffered_Computation::update | ( | byte | in | ) |
| inlineinherited

Process a single byte.

Parameters

  in | the byte to process

Definition at line 72 of file buf_comp.h.

72 { add_data(&in, 1); }

## ◆ update_be()

template<typename T >

void Botan::Buffered_Computation::update_be | ( | const T | in | ) |
| inlineinherited

Add an integer in big-endian order

Parameters

  in | the value

Definition at line 48 of file buf_comp.h.

References Botan::get_byte().

Referenced by Botan::KDF2::derive(), Botan::PKCS5_PBKDF2::derive_key(), Botan::Record_Writer::flush(), Botan::Record_Reader::get_record(), and Botan::MGF1::mask().

49 {
50 for(size_t i = 0; i != sizeof(T); ++i)
51 {
52 byte b = get_byte(i, in);
53 add_data(&b, 1);
54 }
55 }
Botan::get_byte
byte get_byte(size_t byte_num, T input)
Definition: get_byte.h:21
Botan::byte
unsigned char byte
Definition: types.h:22

## ◆ valid_keylength()

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

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

Referenced by Botan::aont_unpackage(), Botan::HMAC_RNG::HMAC_RNG(), Botan::Lion::Lion(), and Botan::Randpool::Randpool().

52 {
53 return key_spec().valid_keylength(length);
54 }
Botan::Key_Length_Specification::valid_keylength
bool valid_keylength(size_t length) const
Definition: key_spec.h:51
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0

## ◆ verify_mac()

bool Botan::MessageAuthenticationCode::verify_mac | ( | const byte | 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 16 of file mac.cpp.

17 {
18 SecureVector<byte> our_mac = final();
19
20 if(our_mac.size() != length)
21 return false;
22
23 return same_mem(&our_mac[0], &mac[0], length);
24 }
Botan::same_mem
bool same_mem(const T *p1, const T *p2, size_t n)
Definition: mem_ops.h:57

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

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