Botan  1.10.9
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::EAX_Base Class Referenceabstract

#include <eax.h>

Inheritance diagram for Botan::EAX_Base:
Botan::Keyed_Filter Botan::Filter Botan::EAX_Decryption Botan::EAX_Encryption

Public Member Functions

virtual bool attachable ()
 
virtual void end_msg ()
 
std::string name () const
 
void set_header (const byte header[], size_t header_len)
 
void set_iv (const InitializationVector &iv)
 
void set_key (const SymmetricKey &key)
 
bool valid_iv_length (size_t) const
 
bool valid_keylength (size_t key_len) const
 
virtual void write (const byte input[], size_t length)=0
 
 ~EAX_Base ()
 

Protected Member Functions

 EAX_Base (BlockCipher *cipher, size_t tag_size)
 
void send (const byte in[], size_t length)
 
void send (byte in)
 
void send (const MemoryRegion< byte > &in)
 
void send (const MemoryRegion< byte > &in, size_t length)
 
void start_msg ()
 

Protected Attributes

const size_t BLOCK_SIZE
 
std::string cipher_name
 
MessageAuthenticationCodecmac
 
StreamCipherctr
 
SecureVector< bytectr_buf
 
SecureVector< byteheader_mac
 
SecureVector< bytenonce_mac
 
const size_t TAG_SIZE
 

Detailed Description

EAX Base Class

Definition at line 21 of file eax.h.

Constructor & Destructor Documentation

Botan::EAX_Base::~EAX_Base ( )
inline

Definition at line 47 of file eax.h.

47 { delete ctr; delete cmac; }
StreamCipher * ctr
Definition: eax.h:74
MessageAuthenticationCode * cmac
Definition: eax.h:79
Botan::EAX_Base::EAX_Base ( BlockCipher cipher,
size_t  tag_size 
)
protected
Parameters
cipherthe cipher to use
tag_sizeis how big the auth tag will be

Definition at line 38 of file eax.cpp.

References Botan::BlockCipher::clone(), cmac, ctr, name(), Botan::Buffered_Computation::output_length(), TAG_SIZE, and Botan::to_string().

38  :
39  BLOCK_SIZE(cipher->block_size()),
40  TAG_SIZE(tag_size ? tag_size / 8 : BLOCK_SIZE),
41  cipher_name(cipher->name()),
42  ctr_buf(DEFAULT_BUFFERSIZE)
43  {
44  cmac = new CMAC(cipher->clone());
45  ctr = new CTR_BE(cipher); // takes ownership
46 
47  if(tag_size % 8 != 0 || TAG_SIZE == 0 || TAG_SIZE > cmac->output_length())
48  throw Invalid_Argument(name() + ": Bad tag size " + to_string(tag_size));
49  }
std::string name() const
Definition: eax.cpp:106
StreamCipher * ctr
Definition: eax.h:74
SecureVector< byte > ctr_buf
Definition: eax.h:94
const size_t TAG_SIZE
Definition: eax.h:64
MessageAuthenticationCode * cmac
Definition: eax.h:79
std::string cipher_name
Definition: eax.h:69
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
const size_t BLOCK_SIZE
Definition: eax.h:59
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
virtual size_t output_length() const =0

Member Function Documentation

virtual bool Botan::Filter::attachable ( )
inlinevirtualinherited

Check whether this filter is an attachable filter.

Returns
true if this filter is attachable, false otherwise

Reimplemented in Botan::SecureQueue, and Botan::DataSink.

Definition at line 50 of file filter.h.

50 { return true; }
virtual void Botan::Filter::end_msg ( )
inlinevirtualinherited
std::string Botan::EAX_Base::name ( ) const
virtual
Returns
name of this mode

Implements Botan::Filter.

Definition at line 106 of file eax.cpp.

References cipher_name.

Referenced by EAX_Base().

107  {
108  return (cipher_name + "/EAX");
109  }
std::string cipher_name
Definition: eax.h:69
void Botan::Filter::send ( const byte  in[],
size_t  length 
)
protectedinherited
Parameters
insome input for the filter
lengththe length of in

Definition at line 28 of file filter.cpp.

References Botan::MemoryRegion< T >::clear(), Botan::MemoryRegion< T >::size(), and Botan::Filter::write().

Referenced by Botan::PK_Encryptor_Filter::end_msg(), Botan::Zlib_Compression::end_msg(), Botan::Bzip_Compression::end_msg(), Botan::Hex_Encoder::end_msg(), Botan::Base64_Encoder::end_msg(), Botan::PK_Decryptor_Filter::end_msg(), Botan::Bzip_Decompression::end_msg(), Botan::Zlib_Decompression::end_msg(), Botan::PK_Signer_Filter::end_msg(), Botan::Hex_Decoder::end_msg(), Botan::Base64_Decoder::end_msg(), Botan::PK_Verifier_Filter::end_msg(), Botan::Hash_Filter::end_msg(), Botan::MAC_Filter::end_msg(), Botan::Bzip_Compression::flush(), Botan::Zlib_Compression::flush(), Botan::Zlib_Compression::write(), Botan::Bzip_Compression::write(), Botan::StreamCipher_Filter::write(), Botan::Bzip_Decompression::write(), Botan::Zlib_Decompression::write(), Botan::Hex_Decoder::write(), and Botan::Base64_Decoder::write().

29  {
30  bool nothing_attached = true;
31  for(size_t j = 0; j != total_ports(); ++j)
32  if(next[j])
33  {
34  if(write_queue.size())
35  next[j]->write(&write_queue[0], write_queue.size());
36  next[j]->write(input, length);
37  nothing_attached = false;
38  }
39 
40  if(nothing_attached)
41  write_queue += std::make_pair(input, length);
42  else
43  write_queue.clear();
44  }
virtual void write(const byte input[], size_t length)=0
size_t size() const
Definition: secmem.h:29
void Botan::Filter::send ( byte  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 63 of file filter.h.

References Botan::Filter::send().

Referenced by Botan::Filter::send().

63 { send(&in, 1); }
void send(const byte in[], size_t length)
Definition: filter.cpp:28
void Botan::Filter::send ( const MemoryRegion< byte > &  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 68 of file filter.h.

References Botan::Filter::send(), and Botan::MemoryRegion< T >::size().

Referenced by Botan::Filter::send().

68 { send(&in[0], in.size()); }
void send(const byte in[], size_t length)
Definition: filter.cpp:28
size_t size() const
Definition: secmem.h:29
void Botan::Filter::send ( const MemoryRegion< byte > &  in,
size_t  length 
)
inlineprotectedinherited
Parameters
insome input for the filter
lengththe number of bytes of in to send

Definition at line 74 of file filter.h.

75  {
76  send(&in[0], length);
77  }
void send(const byte in[], size_t length)
Definition: filter.cpp:28
void Botan::EAX_Base::set_header ( const byte  header[],
size_t  header_len 
)

Set some additional data that is not included in the ciphertext but that will be authenticated.

Parameters
headerthe header contents
header_lenlength of header in bytes

Definition at line 98 of file eax.cpp.

References cmac, and header_mac.

99  {
100  header_mac = eax_prf(1, BLOCK_SIZE, cmac, header, length);
101  }
SecureVector< byte > header_mac
Definition: eax.h:89
MessageAuthenticationCode * cmac
Definition: eax.h:79
const size_t BLOCK_SIZE
Definition: eax.h:59
void Botan::EAX_Base::set_iv ( const InitializationVector iv)
virtual

Set the initialization vector of this filter. Note: you should call set_iv() only after you have called set_key()

Parameters
ivthe initialization vector to use

Reimplemented from Botan::Keyed_Filter.

Definition at line 89 of file eax.cpp.

References Botan::OctetString::begin(), cmac, ctr, Botan::OctetString::length(), nonce_mac, Botan::StreamCipher::set_iv(), and Botan::MemoryRegion< T >::size().

Referenced by Botan::EAX_Decryption::EAX_Decryption().

90  {
91  nonce_mac = eax_prf(0, BLOCK_SIZE, cmac, iv.begin(), iv.length());
93  }
virtual void set_iv(const byte iv[], size_t iv_len)
StreamCipher * ctr
Definition: eax.h:74
MessageAuthenticationCode * cmac
Definition: eax.h:79
size_t size() const
Definition: secmem.h:29
const size_t BLOCK_SIZE
Definition: eax.h:59
SecureVector< byte > nonce_mac
Definition: eax.h:84
void Botan::EAX_Base::set_key ( const SymmetricKey key)
virtual

Set the key of this filter

Parameters
keythe key to use

Implements Botan::Keyed_Filter.

Definition at line 64 of file eax.cpp.

References cmac, ctr, header_mac, and Botan::SymmetricAlgorithm::set_key().

Referenced by Botan::EAX_Decryption::EAX_Decryption().

65  {
66  /*
67  * These could share the key schedule, which is one nice part of EAX,
68  * but it's much easier to ignore that here...
69  */
70  ctr->set_key(key);
71  cmac->set_key(key);
72 
73  header_mac = eax_prf(1, BLOCK_SIZE, cmac, 0, 0);
74  }
StreamCipher * ctr
Definition: eax.h:74
SecureVector< byte > header_mac
Definition: eax.h:89
MessageAuthenticationCode * cmac
Definition: eax.h:79
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:60
const size_t BLOCK_SIZE
Definition: eax.h:59
void Botan::EAX_Base::start_msg ( )
protectedvirtual

Start a new message. Must be closed by end_msg() before another message can be started.

Reimplemented from Botan::Filter.

Definition at line 79 of file eax.cpp.

References cmac, and Botan::Buffered_Computation::update().

80  {
81  for(size_t i = 0; i != BLOCK_SIZE - 1; ++i)
82  cmac->update(0);
83  cmac->update(2);
84  }
MessageAuthenticationCode * cmac
Definition: eax.h:79
void update(const byte in[], size_t length)
Definition: buf_comp.h:33
const size_t BLOCK_SIZE
Definition: eax.h:59
bool Botan::EAX_Base::valid_iv_length ( size_t  ) const
inlinevirtual

EAX supports arbitrary IV lengths

Reimplemented from Botan::Keyed_Filter.

Definition at line 45 of file eax.h.

45 { return true; }
bool Botan::EAX_Base::valid_keylength ( size_t  length) const
virtual

Check whether a key length is valid for this filter

Parameters
lengththe key length to be checked for validity
Returns
true if the key length is valid, false otherwise

Implements Botan::Keyed_Filter.

Definition at line 54 of file eax.cpp.

References ctr, and Botan::SymmetricAlgorithm::valid_keylength().

55  {
56  if(!ctr->valid_keylength(n))
57  return false;
58  return true;
59  }
StreamCipher * ctr
Definition: eax.h:74
BigInt n
Definition: numthry.cpp:26
bool valid_keylength(size_t length) const
Definition: sym_algo.h:51
virtual void Botan::Filter::write ( const byte  input[],
size_t  length 
)
pure virtualinherited

Member Data Documentation

const size_t Botan::EAX_Base::BLOCK_SIZE
protected

The block size of the underlying cipher

Definition at line 59 of file eax.h.

std::string Botan::EAX_Base::cipher_name
protected

The name of the cipher

Definition at line 69 of file eax.h.

Referenced by name().

MessageAuthenticationCode* Botan::EAX_Base::cmac
protected

The MAC (CMAC)

Definition at line 79 of file eax.h.

Referenced by EAX_Base(), set_header(), set_iv(), set_key(), and start_msg().

StreamCipher* Botan::EAX_Base::ctr
protected

The stream cipher (CTR mode)

Definition at line 74 of file eax.h.

Referenced by EAX_Base(), set_iv(), set_key(), and valid_keylength().

SecureVector<byte> Botan::EAX_Base::ctr_buf
protected

A buffer for CTR mode encryption

Definition at line 94 of file eax.h.

SecureVector<byte> Botan::EAX_Base::header_mac
protected

The MAC of the header

Definition at line 89 of file eax.h.

Referenced by set_header(), and set_key().

SecureVector<byte> Botan::EAX_Base::nonce_mac
protected

The MAC of the nonce

Definition at line 84 of file eax.h.

Referenced by set_iv().

const size_t Botan::EAX_Base::TAG_SIZE
protected

The requested tag name

Definition at line 64 of file eax.h.

Referenced by EAX_Base(), and Botan::EAX_Decryption::EAX_Decryption().


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