Botan  1.11.4
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::EAX_Decryption Class Reference

#include <eax.h>

Inheritance diagram for Botan::EAX_Decryption:
Botan::EAX_Mode Botan::AEAD_Mode Botan::SymmetricAlgorithm Botan::Algorithm

Public Member Functions

void clear ()
 
 EAX_Decryption (BlockCipher *cipher, size_t tag_size=16)
 
void finish (secure_vector< byte > &final_block, size_t offset) override
 
Key_Length_Specification key_spec () const override
 
size_t maximum_keylength () const
 
size_t minimum_final_size () const override
 
size_t minimum_keylength () const
 
std::string name () const override
 
size_t output_length (size_t input_length) const override
 
void set_associated_data (const byte ad[], size_t ad_len) override
 
template<typename Alloc >
void set_associated_data_vec (const std::vector< byte, Alloc > &ad)
 
void set_key (const SymmetricKey &key)
 
void set_key (const byte key[], size_t length)
 
secure_vector< bytestart (const byte nonce[], size_t nonce_len) override
 
template<typename Alloc >
secure_vector< bytestart_vec (const std::vector< byte, Alloc > &nonce)
 
void update (secure_vector< byte > &blocks, size_t offset) override
 
size_t update_granularity () const
 
bool valid_keylength (size_t length) const
 
bool valid_nonce_length (size_t) const override
 

Protected Member Functions

size_t block_size () const
 
void key_schedule (const byte key[], size_t length) override
 
size_t tag_size () const
 

Protected Attributes

secure_vector< bytem_ad_mac
 
std::unique_ptr< BlockCipherm_cipher
 
std::unique_ptr
< MessageAuthenticationCode
m_cmac
 
std::unique_ptr< StreamCipherm_ctr
 
secure_vector< bytem_nonce_mac
 
size_t m_tag_size
 

Detailed Description

EAX Decryption

Definition at line 89 of file eax.h.

Constructor & Destructor Documentation

Botan::EAX_Decryption::EAX_Decryption ( BlockCipher cipher,
size_t  tag_size = 16 
)
inline
Parameters
ciphera 128-bit block cipher
tag_sizeis how big the auth tag will be

Definition at line 96 of file eax.h.

97  :
EAX_Mode(cipher, tag_size) {}

Member Function Documentation

size_t Botan::EAX_Mode::block_size ( ) const
inlineprotectedinherited

Definition at line 50 of file eax.h.

Referenced by Botan::EAX_Mode::key_schedule(), Botan::EAX_Mode::set_associated_data(), and Botan::EAX_Mode::start().

50 { return m_cipher->block_size(); }
void Botan::EAX_Mode::clear ( )
virtualinherited

Zeroize internal state

Implements Botan::Algorithm.

Definition at line 48 of file eax.cpp.

References Botan::EAX_Mode::m_ad_mac, Botan::EAX_Mode::m_cipher, Botan::EAX_Mode::m_cmac, Botan::EAX_Mode::m_ctr, Botan::EAX_Mode::m_nonce_mac, and Botan::zeroise().

49  {
50  m_cipher.reset();
51  m_ctr.reset();
52  m_cmac.reset();
55  }
void Botan::EAX_Decryption::finish ( secure_vector< byte > &  final_block,
size_t  offset 
)
overridevirtual

Complete processing of a message. For decryption, may throw an exception due to authentication failure.

Parameters
final_blockin/out parameter which must be at least minimum_final_size() bytes, and will be set to any final output
offsetan offset into final_block to begin processing

Implements Botan::AEAD_Mode.

Definition at line 142 of file eax.cpp.

References BOTAN_ASSERT, Botan::EAX_Mode::m_ad_mac, Botan::EAX_Mode::m_cmac, Botan::EAX_Mode::m_ctr, Botan::EAX_Mode::m_nonce_mac, Botan::same_mem(), and Botan::EAX_Mode::tag_size().

143  {
144  BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
145  const size_t sz = buffer.size() - offset;
146  byte* buf = &buffer[offset];
147 
148  BOTAN_ASSERT(sz >= tag_size(), "Have the tag as part of final input");
149 
150  const size_t remaining = sz - tag_size();
151 
152  if(remaining)
153  {
154  m_cmac->update(buf, remaining);
155  m_ctr->cipher(buf, buf, remaining);
156  }
157 
158  const byte* included_tag = &buf[remaining];
159 
160  secure_vector<byte> mac = m_cmac->final();
161  mac ^= m_nonce_mac;
162  mac ^= m_ad_mac;
163 
164  if(!same_mem(&mac[0], included_tag, tag_size()))
165  throw Integrity_Failure("EAX tag check failed");
166 
167  buffer.resize(offset + remaining);
168  }
void Botan::EAX_Mode::key_schedule ( const byte  key[],
size_t  length 
)
overrideprotectedvirtualinherited

Run the key schedule

Parameters
keythe key
lengthof key

Implements Botan::SymmetricAlgorithm.

Definition at line 75 of file eax.cpp.

References Botan::EAX_Mode::block_size(), Botan::EAX_Mode::m_ad_mac, Botan::EAX_Mode::m_cmac, and Botan::EAX_Mode::m_ctr.

76  {
77  /*
78  * These could share the key schedule, which is one nice part of EAX,
79  * but it's much easier to ignore that here...
80  */
81  m_ctr->set_key(key, length);
82  m_cmac->set_key(key, length);
83 
84  m_ad_mac = eax_prf(1, block_size(), *m_cmac, nullptr, 0);
85  }
Key_Length_Specification Botan::EAX_Mode::key_spec ( ) const
overridevirtualinherited
Returns
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 67 of file eax.cpp.

References Botan::EAX_Mode::m_cipher.

68  {
69  return m_cipher->key_spec();
70  }
size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited
Returns
minimum allowed key length

Definition at line 33 of file sym_algo.h.

References Botan::Key_Length_Specification::maximum_keylength().

Referenced by Botan::PBE_PKCS5v20::PBE_PKCS5v20(), and Botan::time_algorithm_ops().

34  {
35  return key_spec().maximum_keylength();
36  }
size_t Botan::EAX_Decryption::minimum_final_size ( ) const
inlineoverridevirtual
Returns
required minimium size to finalize() - may be any length larger than this.

Implements Botan::AEAD_Mode.

Definition at line 105 of file eax.h.

105 { return tag_size(); }
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  }
std::string Botan::EAX_Mode::name ( ) const
overridevirtualinherited
Returns
name of this algorithm

Implements Botan::Algorithm.

Definition at line 57 of file eax.cpp.

References Botan::EAX_Mode::m_cipher.

Referenced by Botan::EAX_Mode::EAX_Mode(), and Botan::EAX_Mode::start().

58  {
59  return (m_cipher->name() + "/EAX");
60  }
size_t Botan::EAX_Decryption::output_length ( size_t  input_length) const
inlineoverridevirtual

Returns the size of the output if this mode is used to process a message with input_length bytes. Typically this will be input_length plus or minus the length of the tag.

Implements Botan::AEAD_Mode.

Definition at line 99 of file eax.h.

References BOTAN_ASSERT.

100  {
101  BOTAN_ASSERT(input_length > tag_size(), "Sufficient input");
102  return input_length - tag_size();
103  }
void Botan::EAX_Mode::set_associated_data ( const byte  ad[],
size_t  ad_len 
)
overridevirtualinherited
Returns
Random nonce appropriate for passing to start Set associated data that is not included in the ciphertext but that should be authenticated. Must be called after set_key and before finish.

Unless reset by another call, the associated data is kept between messages. Thus, if the AD does not change, calling once (after set_key) is the optimum.

Parameters
adthe associated data
ad_lenlength of add in bytes

Implements Botan::AEAD_Mode.

Definition at line 90 of file eax.cpp.

References Botan::EAX_Mode::block_size(), Botan::EAX_Mode::m_ad_mac, and Botan::EAX_Mode::m_cmac.

91  {
92  m_ad_mac = eax_prf(1, block_size(), *m_cmac, ad, length);
93  }
template<typename Alloc >
void Botan::AEAD_Mode::set_associated_data_vec ( const std::vector< byte, Alloc > &  ad)
inlineinherited

Definition at line 63 of file aead.h.

References Botan::AEAD_Mode::set_associated_data().

64  {
65  set_associated_data(&ad[0], ad.size());
66  }
void Botan::SymmetricAlgorithm::set_key ( const SymmetricKey key)
inlineinherited

Set the symmetric key of this object.

Parameters
keythe SymmetricKey to be set.

Definition at line 60 of file sym_algo.h.

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

Referenced by Botan::aont_package(), Botan::aont_unpackage(), Botan::Lion::decrypt_n(), Botan::ECB_Decryption::ECB_Decryption(), Botan::ECB_Encryption::ECB_Encryption(), Botan::Lion::encrypt_n(), Botan::HMAC_RNG::HMAC_RNG(), Botan::PKCS5_PBKDF2::key_derivation(), Botan::MAC_Filter::MAC_Filter(), Botan::HMAC_RNG::reseed(), Botan::XTS_Encryption::set_key(), Botan::XTS_Decryption::set_key(), Botan::SymmetricAlgorithm::set_key(), Botan::StreamCipher_Filter::StreamCipher_Filter(), and Botan::time_algorithm_ops().

61  { set_key(key.begin(), key.length()); }
void Botan::SymmetricAlgorithm::set_key ( const byte  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 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  }
secure_vector< byte > Botan::EAX_Mode::start ( const byte  nonce[],
size_t  nonce_len 
)
overridevirtualinherited

Begin processing a message.

Parameters
noncethe per message nonce
nonce_lenlength of nonce

Implements Botan::AEAD_Mode.

Definition at line 95 of file eax.cpp.

References Botan::EAX_Mode::block_size(), Botan::EAX_Mode::m_cmac, Botan::EAX_Mode::m_ctr, Botan::EAX_Mode::m_nonce_mac, Botan::EAX_Mode::name(), and Botan::EAX_Mode::valid_nonce_length().

96  {
97  if(!valid_nonce_length(nonce_len))
98  throw Invalid_IV_Length(name(), nonce_len);
99 
100  m_nonce_mac = eax_prf(0, block_size(), *m_cmac, nonce, nonce_len);
101 
102  m_ctr->set_iv(&m_nonce_mac[0], m_nonce_mac.size());
103 
104  for(size_t i = 0; i != block_size() - 1; ++i)
105  m_cmac->update(0);
106  m_cmac->update(2);
107 
108  return secure_vector<byte>();
109  }
template<typename Alloc >
secure_vector<byte> Botan::AEAD_Mode::start_vec ( const std::vector< byte, Alloc > &  nonce)
inlineinherited

Definition at line 79 of file aead.h.

References Botan::AEAD_Mode::start().

80  {
81  return start(&nonce[0], nonce.size());
82  }
size_t Botan::EAX_Mode::tag_size ( ) const
inlineprotectedinherited

Definition at line 48 of file eax.h.

Referenced by Botan::EAX_Encryption::finish(), and finish().

48 { return m_tag_size; }
void Botan::EAX_Decryption::update ( secure_vector< byte > &  blocks,
size_t  offset 
)
overridevirtual

Update (encrypt or decrypt) some data. Input must be in size update_granularity() byte blocks.

Parameters
blocksin/out paramter which will possibly be resized

Implements Botan::AEAD_Mode.

Definition at line 132 of file eax.cpp.

References BOTAN_ASSERT, Botan::EAX_Mode::m_cmac, and Botan::EAX_Mode::m_ctr.

133  {
134  BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
135  const size_t sz = buffer.size() - offset;
136  byte* buf = &buffer[offset];
137 
138  m_cmac->update(buf, sz);
139  m_ctr->cipher(buf, buf, sz);
140  }
size_t Botan::EAX_Mode::update_granularity ( ) const
virtualinherited
Returns
size of required blocks to update

Implements Botan::AEAD_Mode.

Definition at line 62 of file eax.cpp.

References Botan::EAX_Mode::m_cipher.

63  {
64  return 8 * m_cipher->parallel_bytes();
65  }
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 51 of file sym_algo.h.

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

52  {
53  return key_spec().valid_keylength(length);
54  }
bool Botan::EAX_Mode::valid_nonce_length ( size_t  ) const
inlineoverridevirtualinherited

Implements Botan::AEAD_Mode.

Definition at line 36 of file eax.h.

Referenced by Botan::EAX_Mode::start().

36 { return true; }

Member Data Documentation

secure_vector<byte> Botan::EAX_Mode::m_ad_mac
protectedinherited

Definition at line 58 of file eax.h.

Referenced by Botan::EAX_Mode::clear(), Botan::EAX_Encryption::finish(), finish(), Botan::EAX_Mode::key_schedule(), and Botan::EAX_Mode::set_associated_data().

std::unique_ptr<BlockCipher> Botan::EAX_Mode::m_cipher
protectedinherited

Definition at line 54 of file eax.h.

Referenced by Botan::EAX_Mode::clear(), Botan::EAX_Mode::key_spec(), Botan::EAX_Mode::name(), and Botan::EAX_Mode::update_granularity().

std::unique_ptr<MessageAuthenticationCode> Botan::EAX_Mode::m_cmac
protectedinherited

Definition at line 56 of file eax.h.

Referenced by Botan::EAX_Mode::clear(), Botan::EAX_Mode::EAX_Mode(), Botan::EAX_Encryption::finish(), finish(), Botan::EAX_Mode::key_schedule(), Botan::EAX_Mode::set_associated_data(), Botan::EAX_Mode::start(), Botan::EAX_Encryption::update(), and update().

std::unique_ptr<StreamCipher> Botan::EAX_Mode::m_ctr
protectedinherited

Definition at line 55 of file eax.h.

Referenced by Botan::EAX_Mode::clear(), finish(), Botan::EAX_Mode::key_schedule(), Botan::EAX_Mode::start(), Botan::EAX_Encryption::update(), and update().

secure_vector<byte> Botan::EAX_Mode::m_nonce_mac
protectedinherited

Definition at line 60 of file eax.h.

Referenced by Botan::EAX_Mode::clear(), Botan::EAX_Encryption::finish(), finish(), and Botan::EAX_Mode::start().

size_t Botan::EAX_Mode::m_tag_size
protectedinherited

Definition at line 52 of file eax.h.


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