Botan 1.10.17
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 (byte in)
void send (const byte in[], size_t length)
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

◆ ~EAX_Base()

Botan::EAX_Base::~EAX_Base ( )
inline

Definition at line 47 of file eax.h.

47{ delete ctr; delete cmac; }
MessageAuthenticationCode * cmac
Definition eax.h:79
StreamCipher * ctr
Definition eax.h:74

References cmac, and ctr.

◆ EAX_Base()

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.

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 }
virtual size_t output_length() const =0
CMAC(BlockCipher *cipher)
Definition cmac.cpp:132
CTR_BE(BlockCipher *cipher)
Definition ctr.cpp:17
const size_t TAG_SIZE
Definition eax.h:64
SecureVector< byte > ctr_buf
Definition eax.h:94
const size_t BLOCK_SIZE
Definition eax.h:59
std::string cipher_name
Definition eax.h:69
std::string name() const
Definition eax.cpp:106
std::string to_string(u64bit n, size_t min_len)
Definition parsing.cpp:42
std::invalid_argument Invalid_Argument
Definition exceptn.h:20

References BLOCK_SIZE, cipher_name, Botan::BlockCipher::clone(), Botan::CMAC::CMAC(), cmac, ctr, Botan::CTR_BE::CTR_BE(), ctr_buf, name(), Botan::Buffered_Computation::output_length(), TAG_SIZE, and Botan::to_string().

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

Member Function Documentation

◆ attachable()

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::DataSink, and Botan::SecureQueue.

Definition at line 50 of file filter.h.

50{ return true; }

◆ end_msg()

virtual void Botan::Filter::end_msg ( )
inlinevirtualinherited

◆ name()

std::string Botan::EAX_Base::name ( ) const
virtual
Returns
name of this mode

Implements Botan::Filter.

Definition at line 106 of file eax.cpp.

107 {
108 return (cipher_name + "/EAX");
109 }

References cipher_name.

Referenced by EAX_Base().

◆ send() [1/4]

void Botan::Filter::send ( byte in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 63 of file filter.h.

63{ send(&in, 1); }
void send(const byte in[], size_t length)
Definition filter.cpp:28

References send().

Referenced by send().

◆ send() [2/4]

void Botan::Filter::send ( const byte in[],
size_t length )
protectedinherited

◆ send() [3/4]

void Botan::Filter::send ( const MemoryRegion< byte > & in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 68 of file filter.h.

68{ send(&in[0], in.size()); }

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

Referenced by send().

◆ send() [4/4]

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 }

References send().

◆ set_header()

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.

99 {
100 header_mac = eax_prf(1, BLOCK_SIZE, cmac, header, length);
101 }
SecureVector< byte > header_mac
Definition eax.h:89

References BLOCK_SIZE, cmac, and header_mac.

◆ set_iv()

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.

90 {
91 nonce_mac = eax_prf(0, BLOCK_SIZE, cmac, iv.begin(), iv.length());
93 }
SecureVector< byte > nonce_mac
Definition eax.h:84
size_t size() const
Definition secmem.h:29
virtual void set_iv(const byte iv[], size_t iv_len)

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

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

◆ set_key()

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.

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 }
void set_key(const SymmetricKey &key)
Definition sym_algo.h:60

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

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

◆ start_msg()

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.

80 {
81 for(size_t i = 0; i != BLOCK_SIZE - 1; ++i)
82 cmac->update(0);
83 cmac->update(2);
84 }
void update(const byte in[], size_t length)
Definition buf_comp.h:33

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

◆ valid_iv_length()

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; }

◆ valid_keylength()

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.

55 {
56 if(!ctr->valid_keylength(n))
57 return false;
58 return true;
59 }
bool valid_keylength(size_t length) const
Definition sym_algo.h:51

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

◆ write()

Member Data Documentation

◆ BLOCK_SIZE

const size_t Botan::EAX_Base::BLOCK_SIZE
protected

The block size of the underlying cipher

Definition at line 59 of file eax.h.

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

◆ cipher_name

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

The name of the cipher

Definition at line 69 of file eax.h.

Referenced by EAX_Base(), and name().

◆ cmac

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(), start_msg(), and ~EAX_Base().

◆ ctr

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(), valid_keylength(), and ~EAX_Base().

◆ ctr_buf

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

A buffer for CTR mode encryption

Definition at line 94 of file eax.h.

Referenced by EAX_Base().

◆ header_mac

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().

◆ nonce_mac

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().

◆ TAG_SIZE

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(), Botan::EAX_Decryption::EAX_Decryption(), and Botan::EAX_Decryption::EAX_Decryption().


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