Botan  2.11.0
Crypto and TLS for C++11
Public Member Functions | Protected Member Functions | List of all members
Botan::TLS::TLS_CBC_HMAC_AEAD_Mode Class Reference

#include <tls_cbc.h>

Inheritance diagram for Botan::TLS::TLS_CBC_HMAC_AEAD_Mode:
Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption

Public Member Functions

void clear () override final
 
size_t default_nonce_length () const override final
 
Key_Length_Specification key_spec () const override final
 
std::string name () const override final
 
size_t process (uint8_t buf[], size_t sz) override final
 
void reset () override final
 
void set_associated_data (const uint8_t ad[], size_t ad_len) override
 
size_t tag_size () const override final
 
size_t update_granularity () const override final
 
bool valid_nonce_length (size_t nl) const override final
 

Protected Member Functions

std::vector< uint8_t > & assoc_data ()
 
std::vector< uint8_t > assoc_data_with_len (uint16_t len)
 
size_t block_size () const
 
Cipher_Mode & cbc () const
 
secure_vector< uint8_t > & cbc_state ()
 
size_t cipher_keylen () const
 
bool is_datagram_protocol () const
 
size_t iv_size () const
 
MessageAuthenticationCode & mac () const
 
size_t mac_keylen () const
 
secure_vector< uint8_t > & msg ()
 
 TLS_CBC_HMAC_AEAD_Mode (Cipher_Dir direction, std::unique_ptr< BlockCipher > cipher, std::unique_ptr< MessageAuthenticationCode > mac, size_t cipher_keylen, size_t mac_keylen, Protocol_Version version, bool use_encrypt_then_mac)
 
bool use_encrypt_then_mac () const
 

Detailed Description

TLS CBC+HMAC AEAD base class (GenericBlockCipher in TLS spec) This is the weird TLS-specific mode, not for general consumption.

Definition at line 25 of file tls_cbc.h.

Constructor & Destructor Documentation

◆ TLS_CBC_HMAC_AEAD_Mode()

Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::TLS_CBC_HMAC_AEAD_Mode ( Cipher_Dir  direction,
std::unique_ptr< BlockCipher >  cipher,
std::unique_ptr< MessageAuthenticationCode >  mac,
size_t  cipher_keylen,
size_t  mac_keylen,
Protocol_Version  version,
bool  use_encrypt_then_mac 
)
protected

Definition at line 26 of file tls_cbc.cpp.

32  :
33  m_cipher_name(cipher->name()),
34  m_mac_name(mac->name()),
35  m_cipher_keylen(cipher_keylen),
36  m_mac_keylen(mac_keylen),
37  m_use_encrypt_then_mac(use_encrypt_then_mac)
38  {
39  m_tag_size = mac->output_length();
40  m_block_size = cipher->block_size();
41 
42  m_iv_size = version.supports_explicit_cbc_ivs() ? m_block_size : 0;
43 
44  m_is_datagram = version.is_datagram_protocol();
45 
46  m_mac = std::move(mac);
47 
48  if(dir == ENCRYPTION)
49  m_cbc.reset(new CBC_Encryption(cipher.release(), new Null_Padding));
50  else
51  m_cbc.reset(new CBC_Decryption(cipher.release(), new Null_Padding));
52  }
MessageAuthenticationCode & mac() const
Definition: tls_cbc.h:68
void BlockCipher * cipher
Definition: package.h:29

References Botan::cipher, Botan::ENCRYPTION, and mac().

Member Function Documentation

◆ assoc_data()

std::vector<uint8_t>& Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::assoc_data ( )
inlineprotected

◆ assoc_data_with_len()

std::vector< uint8_t > Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::assoc_data_with_len ( uint16_t  len)
protected

Definition at line 122 of file tls_cbc.cpp.

123  {
124  std::vector<uint8_t> ad = m_ad;
125  BOTAN_ASSERT(ad.size() == 13, "Expected AAD size");
126  ad[11] = get_byte(0, len);
127  ad[12] = get_byte(1, len);
128  return ad;
129  }
std::string size_t len
Definition: pk_keys.h:305
constexpr uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:39
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:55
class BOTAN_PUBLIC_API(2, 11) Argon2 final class BOTAN_PUBLIC_API(2, 11) Argon2_Family final void size_t const char size_t const uint8_t size_t const uint8_t size_t const uint8_t ad[]
Definition: argon2.h:87

References Botan::ad, BOTAN_ASSERT, Botan::get_byte(), and Botan::len.

Referenced by Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish().

◆ block_size()

size_t Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::block_size ( ) const
inlineprotected

◆ cbc()

Cipher_Mode& Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::cbc ( ) const
inlineprotected

Definition at line 66 of file tls_cbc.h.

66 { return *m_cbc; }

Referenced by clear().

◆ cbc_state()

secure_vector<uint8_t>& Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::cbc_state ( )
inlineprotected

Definition at line 74 of file tls_cbc.h.

74 { return m_cbc_state; }

Referenced by Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), and reset().

◆ cipher_keylen()

size_t Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::cipher_keylen ( ) const
inlineprotected

Definition at line 57 of file tls_cbc.h.

57 { return m_cipher_keylen; }

◆ clear()

void Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::clear ( )
finaloverride

Definition at line 54 of file tls_cbc.cpp.

55  {
56  cbc().clear();
57  mac().clear();
58  reset();
59  }
Cipher_Mode & cbc() const
Definition: tls_cbc.h:66
MessageAuthenticationCode & mac() const
Definition: tls_cbc.h:68
void reset() override final
Definition: tls_cbc.cpp:61

References cbc(), mac(), and reset().

◆ default_nonce_length()

size_t Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::default_nonce_length ( ) const
inlinefinaloverride

Definition at line 42 of file tls_cbc.h.

42 { return m_iv_size; }

◆ is_datagram_protocol()

bool Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::is_datagram_protocol ( ) const
inlineprotected

Definition at line 64 of file tls_cbc.h.

64 { return m_is_datagram; }

Referenced by Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish().

◆ iv_size()

size_t Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::iv_size ( ) const
inlineprotected

◆ key_spec()

Key_Length_Specification Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::key_spec ( ) const
finaloverride

Definition at line 85 of file tls_cbc.cpp.

86  {
87  return Key_Length_Specification(m_cipher_keylen + m_mac_keylen);
88  }

◆ mac()

MessageAuthenticationCode& Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::mac ( ) const
inlineprotected

Definition at line 68 of file tls_cbc.h.

69  {
70  BOTAN_ASSERT_NONNULL(m_mac);
71  return *m_mac;
72  }
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:107

References BOTAN_ASSERT_NONNULL.

Referenced by clear(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), and TLS_CBC_HMAC_AEAD_Mode().

◆ mac_keylen()

size_t Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::mac_keylen ( ) const
inlineprotected

Definition at line 58 of file tls_cbc.h.

58 { return m_mac_keylen; }

◆ msg()

secure_vector<uint8_t>& Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::msg ( )
inlineprotected

Definition at line 76 of file tls_cbc.h.

76 { return m_msg; }

Referenced by Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), and Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish().

◆ name()

std::string Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::name ( ) const
finaloverride

Definition at line 68 of file tls_cbc.cpp.

69  {
70  return "TLS_CBC(" + m_cipher_name + "," + m_mac_name + ")";
71  }

◆ process()

size_t Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::process ( uint8_t  buf[],
size_t  sz 
)
finaloverride

Definition at line 116 of file tls_cbc.cpp.

117  {
118  m_msg.insert(m_msg.end(), buf, buf + sz);
119  return 0;
120  }
const uint8_t * buf
Definition: ffi.h:371

References buf.

◆ reset()

void Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::reset ( )
finaloverride

Definition at line 61 of file tls_cbc.cpp.

62  {
63  cbc_state().clear();
64  m_ad.clear();
65  m_msg.clear();
66  }
secure_vector< uint8_t > & cbc_state()
Definition: tls_cbc.h:74

References cbc_state().

Referenced by clear().

◆ set_associated_data()

void Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::set_associated_data ( const uint8_t  ad[],
size_t  ad_len 
)
override

Definition at line 131 of file tls_cbc.cpp.

132  {
133  if(ad_len != 13)
134  throw Invalid_Argument("Invalid TLS AEAD associated data length");
135  m_ad.assign(ad, ad + ad_len);
136  }
class BOTAN_PUBLIC_API(2, 11) Argon2 final class BOTAN_PUBLIC_API(2, 11) Argon2_Family final void size_t const char size_t const uint8_t size_t const uint8_t size_t const uint8_t size_t ad_len
Definition: argon2.h:87
class BOTAN_PUBLIC_API(2, 11) Argon2 final class BOTAN_PUBLIC_API(2, 11) Argon2_Family final void size_t const char size_t const uint8_t size_t const uint8_t size_t const uint8_t ad[]
Definition: argon2.h:87

References Botan::ad, and Botan::ad_len.

Referenced by Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::set_associated_data().

◆ tag_size()

size_t Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::tag_size ( ) const
inlinefinaloverride

◆ update_granularity()

size_t Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::update_granularity ( ) const
finaloverride

Definition at line 73 of file tls_cbc.cpp.

74  {
75  return 1; // just buffers anyway
76  }

◆ use_encrypt_then_mac()

bool Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::use_encrypt_then_mac ( ) const
inlineprotected

◆ valid_nonce_length()

bool Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::valid_nonce_length ( size_t  nl) const
finaloverride

Definition at line 78 of file tls_cbc.cpp.

79  {
80  if(m_cbc_state.empty())
81  return nl == block_size();
82  return nl == iv_size();
83  }
size_t nl
Definition: ffi.h:445

References block_size(), iv_size(), and nl.


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