Arduino Cryptography Library
Public Member Functions | List of all members
EAX< T > Class Template Reference

Implementation of the EAX authenticated cipher. More...

#include <EAX.h>

Inheritance diagram for EAX< T >:
EAXCommon AuthenticatedCipher Cipher

Public Member Functions

 EAX ()
 Constructs a new EAX object for the block cipher T.
 
- Public Member Functions inherited from EAXCommon
size_t keySize () const
 Default size of the key for this cipher, in bytes. More...
 
size_t ivSize () const
 Size of the initialization vector for this cipher, in bytes. More...
 
size_t tagSize () const
 Returns the size of the authentication tag. More...
 
bool setKey (const uint8_t *key, size_t len)
 Sets the key to use for future encryption and decryption operations. More...
 
bool setIV (const uint8_t *iv, size_t len)
 Sets the initialization vector to use for future encryption and decryption operations. More...
 
void encrypt (uint8_t *output, const uint8_t *input, size_t len)
 Encrypts an input buffer and writes the ciphertext to an output buffer. More...
 
void decrypt (uint8_t *output, const uint8_t *input, size_t len)
 Decrypts an input buffer and writes the plaintext to an output buffer. More...
 
void addAuthData (const void *data, size_t len)
 Adds extra data that will be authenticated but not encrypted. More...
 
void computeTag (void *tag, size_t len)
 Finalizes the encryption process and computes the authentication tag. More...
 
bool checkTag (const void *tag, size_t len)
 Finalizes the decryption process and checks the authentication tag. More...
 
void clear ()
 Clears all security-sensitive state from this cipher. More...
 
- Public Member Functions inherited from AuthenticatedCipher
 AuthenticatedCipher ()
 Constructs a new authenticated cipher.
 
virtual ~AuthenticatedCipher ()
 Destroys this authenticated cipher.
 
- Public Member Functions inherited from Cipher
 Cipher ()
 Constructs a new cipher object.
 
virtual ~Cipher ()
 Destroys this cipher object. More...
 

Additional Inherited Members

- Protected Member Functions inherited from EAXCommon
 EAXCommon ()
 Constructs a new cipher in EAX mode. More...
 
void setBlockCipher (BlockCipher *cipher)
 Sets the block cipher to use for this EAX object. More...
 

Detailed Description

template<typename T>
class EAX< T >

Implementation of the EAX authenticated cipher.

EAX mode converts a block cipher into an authenticated cipher that uses the block cipher T to encrypt and authenticate.

The size of the key is determined by the underlying block cipher T. The IV is recommended to be 128 bits (16 bytes) in length, but other lengths are supported as well. The default tagSize() is 128 bits (16 bytes) but the EAX specification does allow smaller tag sizes.

The template parameter T must be a concrete subclass of BlockCipher indicating the specific block cipher to use. The block cipher must have a block size of 128 bits. For example, the following creates a EAX object using AES256 as the underlying cipher and then uses it to encrypt and authenticate a plaintext block:

eax.setKey(key, sizeof(key));
eax.setIV(iv, sizeof(iv));
eax.addAuthData(adata, sizeof(adata));
eax.encrypt(ciphertext, plaintext, sizeof(plaintext));
eax.computeTag(tag, sizeof(tag));
bool setIV(const uint8_t *iv, size_t len)
Sets the initialization vector to use for future encryption and decryption operations.
Definition: EAX.cpp:76
void encrypt(uint8_t *output, const uint8_t *input, size_t len)
Encrypts an input buffer and writes the ciphertext to an output buffer.
Definition: EAX.cpp:100
void computeTag(void *tag, size_t len)
Finalizes the encryption process and computes the authentication tag.
Definition: EAX.cpp:122
void addAuthData(const void *data, size_t len)
Adds extra data that will be authenticated but not encrypted.
Definition: EAX.cpp:116
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: EAX.cpp:71
Implementation of the EAX authenticated cipher.
Definition: EAX.h:77

The decryption process is almost identical to convert a ciphertext and tag back into plaintext and then check the tag:

eax.setKey(key, sizeof(key));
eax.setIV(iv, sizeof(iv));
eax.addAuthData(adata, sizeof(adata));
eax.decrypt(ciphertext, plaintext, sizeof(plaintext));
if (!eax.checkTag(tag, sizeof(tag))) {
// The data was invalid - do not use it.
...
}
void decrypt(uint8_t *output, const uint8_t *input, size_t len)
Decrypts an input buffer and writes the plaintext to an output buffer.
Definition: EAX.cpp:108
bool checkTag(const void *tag, size_t len)
Finalizes the decryption process and checks the authentication tag.
Definition: EAX.cpp:130

The EAX class can also be used to implement message authentication by omitting the plaintext:

eax.setKey(key, sizeof(key));
eax.setIV(iv, sizeof(iv));
eax.addAuthData(adata1, sizeof(adata1));
eax.addAuthData(adata2, sizeof(adata1));
...
eax.addAuthData(adataN, sizeof(adataN));
eax.computeTag(tag, sizeof(tag));

References: https://en.wikipedia.org/wiki/EAX_mode, http://web.cs.ucdavis.edu/~rogaway/papers/eax.html

See also
EAXCommon, GCM

Definition at line 76 of file EAX.h.


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