Botan: Botan::EAX_Base Class Reference

Botan 1.10.16

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:

## 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
MessageAuthenticationCode * | cmac
StreamCipher * | ctr
SecureVector< byte > | ctr_buf
SecureVector< byte > | header_mac
SecureVector< byte > | nonce_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; }
Botan::EAX_Base::ctr
StreamCipher * ctr
Definition: eax.h:74
Botan::EAX_Base::cmac
MessageAuthenticationCode * cmac
Definition: eax.h:79

## ◆ EAX_Base()

Botan::EAX_Base::EAX_Base | ( | BlockCipher * | cipher,
|  | size_t | tag_size
| ) |  |
| protected

Parameters

  cipher | the cipher to use
  tag_size | is 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 }
Botan::EAX_Base::ctr
StreamCipher * ctr
Definition: eax.h:74
Botan::EAX_Base::ctr_buf
SecureVector< byte > ctr_buf
Definition: eax.h:94
Botan::EAX_Base::TAG_SIZE
const size_t TAG_SIZE
Definition: eax.h:64
Botan::EAX_Base::cmac
MessageAuthenticationCode * cmac
Definition: eax.h:79
Botan::EAX_Base::cipher_name
std::string cipher_name
Definition: eax.h:69
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::EAX_Base::name
std::string name() const
Definition: eax.cpp:106
Botan::EAX_Base::BLOCK_SIZE
const size_t BLOCK_SIZE
Definition: eax.h:59
Botan::to_string
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
Botan::Buffered_Computation::output_length
virtual size_t output_length() const =0

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

Definition at line 50 of file filter.h.

50 { return true; }

## ◆ end_msg()

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

Notify that the current message is finished; flush buffers and do end-of-message processing (if any).

Reimplemented in Botan::MAC_Filter, Botan::Hash_Filter, Botan::PK_Verifier_Filter, Botan::Base64_Decoder, Botan::Hex_Decoder, Botan::PK_Signer_Filter, Botan::Zlib_Decompression, Botan::Bzip_Decompression, Botan::PK_Decryptor_Filter, Botan::PBE_PKCS5v20, Botan::Base64_Encoder, Botan::Hex_Encoder, Botan::PBE_PKCS5v15, Botan::Bzip_Compression, Botan::Zlib_Compression, and Botan::PK_Encryptor_Filter.

Definition at line 44 of file filter.h.

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

44 {}

## ◆ 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.

References Botan::StreamCipher::cipher(), cipher_name, cmac, ctr, ctr_buf, Botan::Buffered_Computation::final(), header_mac, nonce_mac, Botan::Filter::send(), Botan::MemoryRegion< T >::size(), TAG_SIZE, Botan::Buffered_Computation::update(), and Botan::xor_buf().

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

107 {
108 return (cipher_name + "/EAX");
109 }
Botan::EAX_Base::cipher_name
std::string cipher_name
Definition: eax.h:69

## ◆ send() [1/4]

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

Parameters

  in | some input for the filter
  length | the length of in

Definition at line 28 of file filter.cpp.

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

Referenced by Botan::Base64_Encoder::Base64_Encoder(), Botan::EAX_Decryption::EAX_Decryption(), Botan::PK_Encryptor_Filter::end_msg(), Botan::Bzip_Compression::end_msg(), Botan::Zlib_Compression::end_msg(), Botan::PBE_PKCS5v15::end_msg(), Botan::Hex_Encoder::end_msg(), Botan::Base64_Encoder::end_msg(), Botan::PBE_PKCS5v20::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::Hex_Encoder::Hex_Encoder(), Botan::ECB_Encryption::name(), name(), Botan::ECB_Decryption::name(), Botan::CTS_Encryption::set_iv(), Botan::CFB_Encryption::set_iv(), Botan::CBC_Encryption::set_iv(), Botan::CFB_Decryption::set_iv(), Botan::CTS_Decryption::set_iv(), Botan::CBC_Decryption::set_iv(), Botan::XTS_Encryption::set_key(), Botan::XTS_Decryption::set_key(), Botan::Bzip_Compression::write(), Botan::Zlib_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 }
Botan::Filter::write
virtual void write(const byte input[], size_t length)=0
Botan::MemoryRegion::clear
void clear()
Definition: secmem.h:152
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ send() [2/4]

void Botan::Filter::send | ( | byte | in | ) |
| inlineprotectedinherited

Parameters

  in | some 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); }
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28

## ◆ send() [3/4]

void Botan::Filter::send | ( | const MemoryRegion< byte > & | in | ) |
| inlineprotectedinherited

Parameters

  in | some 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()); }
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ send() [4/4]

void Botan::Filter::send | ( | const MemoryRegion< byte > & | in,
|  | size_t | length
| ) |  |
| inlineprotectedinherited

Parameters

  in | some input for the filter
  length | the number of bytes of in to send

Definition at line 74 of file filter.h.

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

## ◆ 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

  header | the header contents
  header_len | length 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 }
Botan::EAX_Base::header_mac
SecureVector< byte > header_mac
Definition: eax.h:89
Botan::EAX_Base::cmac
MessageAuthenticationCode * cmac
Definition: eax.h:79
Botan::EAX_Base::BLOCK_SIZE
const size_t BLOCK_SIZE
Definition: eax.h:59

## ◆ 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

  iv | the 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());
92 ctr->set_iv(&nonce_mac[0], nonce_mac.size());
93 }
Botan::StreamCipher::set_iv
virtual void set_iv(const byte iv[], size_t iv_len)
Definition: stream_cipher.cpp:12
Botan::EAX_Base::ctr
StreamCipher * ctr
Definition: eax.h:74
Botan::EAX_Base::cmac
MessageAuthenticationCode * cmac
Definition: eax.h:79
Botan::EAX_Base::BLOCK_SIZE
const size_t BLOCK_SIZE
Definition: eax.h:59
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::EAX_Base::nonce_mac
SecureVector< byte > nonce_mac
Definition: eax.h:84

## ◆ set_key()

void Botan::EAX_Base::set_key | ( | const SymmetricKey & | key | ) |
| virtual

Set the key of this filter

Parameters

  key | the 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 }
Botan::EAX_Base::ctr
StreamCipher * ctr
Definition: eax.h:74
Botan::EAX_Base::header_mac
SecureVector< byte > header_mac
Definition: eax.h:89
Botan::EAX_Base::cmac
MessageAuthenticationCode * cmac
Definition: eax.h:79
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:60
Botan::EAX_Base::BLOCK_SIZE
const size_t BLOCK_SIZE
Definition: eax.h:59

## ◆ 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.

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 }
Botan::EAX_Base::cmac
MessageAuthenticationCode * cmac
Definition: eax.h:79
Botan::Buffered_Computation::update
void update(const byte in[], size_t length)
Definition: buf_comp.h:33
Botan::EAX_Base::BLOCK_SIZE
const size_t BLOCK_SIZE
Definition: eax.h:59

## ◆ 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

  length | the 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 }
Botan::EAX_Base::ctr
StreamCipher * ctr
Definition: eax.h:74
Botan::SymmetricAlgorithm::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:51

## ◆ write()

virtual void Botan::Filter::write | ( | const byte | input[],
|  | size_t | length
| ) |  |
| pure virtualinherited

Write a portion of a message to this filter.

Parameters

  input | the input as a byte array
  length | the length of the byte array input

Implemented in Botan::MAC_Filter, Botan::Hash_Filter, Botan::PK_Verifier_Filter, Botan::Base64_Decoder, Botan::Hex_Decoder, Botan::PK_Signer_Filter, Botan::Fork, Botan::Zlib_Decompression, Botan::Bzip_Decompression, Botan::StreamCipher_Filter, Botan::PK_Decryptor_Filter, Botan::DataSink_Stream, Botan::Chain, Botan::PBE_PKCS5v20, Botan::Hex_Encoder, Botan::Base64_Encoder, Botan::PBE_PKCS5v15, Botan::Bzip_Compression, Botan::PK_Encryptor_Filter, Botan::SecureQueue, Botan::Zlib_Compression, and Botan::BitBucket.

Referenced by Botan::Filter::send(), and Botan::Pipe::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.

## ◆ 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 name().

## ◆ cmac

MessageAuthenticationCode* Botan::EAX_Base::cmac
| protected

The MAC (CMAC)

Definition at line 79 of file eax.h.

Referenced by Botan::EAX_Decryption::EAX_Decryption(), name(), set_header(), set_iv(), set_key(), and start_msg().

## ◆ ctr

StreamCipher* Botan::EAX_Base::ctr
| protected

The stream cipher (CTR mode)

Definition at line 74 of file eax.h.

Referenced by Botan::EAX_Decryption::EAX_Decryption(), name(), set_iv(), and set_key().

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

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

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

- src/filters/modes/eax/eax.h
- src/filters/modes/eax/eax.cpp