Crypto++  5.6.3
Free C++ class library of cryptographic schemes
Go to the documentation of this file.
1 // eax.h - written and placed in the public domain by Wei Dai
3 //! \file
4 //! \headerfile eax.h
5 //! \brief EAX block cipher mode of operation
7 #ifndef CRYPTOPP_EAX_H
8 #define CRYPTOPP_EAX_H
10 #include "authenc.h"
11 #include "modes.h"
12 #include "cmac.h"
16 //! \class EAX_Base
17 //! \brief EAX block cipher mode of operation
18 //! \details Implementations and overrides in \p EAX_Base apply to both \p ENCRYPTION and \p DECRYPTION directions
19 class CRYPTOPP_NO_VTABLE EAX_Base : public AuthenticatedSymmetricCipherBase
20 {
21 public:
22  // AuthenticatedSymmetricCipher
23  std::string AlgorithmName() const
24  {return GetMAC().GetCipher().AlgorithmName() + std::string("/EAX");}
25  size_t MinKeyLength() const
26  {return GetMAC().MinKeyLength();}
27  size_t MaxKeyLength() const
28  {return GetMAC().MaxKeyLength();}
29  size_t DefaultKeyLength() const
30  {return GetMAC().DefaultKeyLength();}
31  size_t GetValidKeyLength(size_t n) const
32  {return GetMAC().GetValidKeyLength(n);}
33  bool IsValidKeyLength(size_t n) const
34  {return GetMAC().IsValidKeyLength(n);}
35  unsigned int OptimalDataAlignment() const
36  {return GetMAC().OptimalDataAlignment();}
38  {return UNIQUE_IV;}
39  unsigned int IVSize() const
40  {return GetMAC().TagSize();}
41  unsigned int MinIVLength() const
42  {return 0;}
43  unsigned int MaxIVLength() const
44  {return UINT_MAX;}
45  unsigned int DigestSize() const
46  {return GetMAC().TagSize();}
47  lword MaxHeaderLength() const
48  {return LWORD_MAX;}
49  lword MaxMessageLength() const
50  {return LWORD_MAX;}
52 protected:
53  // AuthenticatedSymmetricCipherBase
54  bool AuthenticationIsOnPlaintext() const
55  {return false;}
56  unsigned int AuthenticationBlockSize() const
57  {return 1;}
58  void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params);
59  void Resync(const byte *iv, size_t len);
60  size_t AuthenticateBlocks(const byte *data, size_t len);
61  void AuthenticateLastHeaderBlock();
62  void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
63  SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
64  const CMAC_Base & GetMAC() const {return const_cast<EAX_Base *>(this)->AccessMAC();}
65  virtual CMAC_Base & AccessMAC() =0;
68 };
70 //! \class EAX_Final
71 //! \brief Class specific methods used to operate the cipher.
72 //! \tparam T_BlockCipher block cipher
73 //! \tparam T_IsEncryption direction in which to operate the cipher
74 //! \details Implementations and overrides in \p GCM_Final apply to either
75 //! \p ENCRYPTION or \p DECRYPTION, depending on the template parameter \p T_IsEncryption.
76 //! \details \p EAX_Final does not use inner classes \p Enc and \p Dec.
77 template <class T_BlockCipher, bool T_IsEncryption>
78 class EAX_Final : public EAX_Base
79 {
80 public:
81  static std::string StaticAlgorithmName()
82  {return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");}
84  {return T_IsEncryption;}
86 private:
87  CMAC_Base & AccessMAC() {return m_cmac;}
88  CMAC<T_BlockCipher> m_cmac;
89 };
91 #ifdef EAX // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11
92 #undef EAX
93 #endif
95 //! \class EAX
96 //! \brief The EAX block cipher mode of operation
97 //! \details EAX is an Authenticated Encryption with Associated Data (AEAD) block
98 //! cipher mode of operation designed to simultaneously provide both authentication
99 //! and privacy of the message.
100 //! \tparam T_BlockCipher block cipher
101 //! \details \p EAX provides the \p Encryption and \p Decryption typedef.
102 //! \sa <a href="">EAX</a> at the Crypto Lounge
103 template <class T_BlockCipher>
105 {
108 };
112 #endif
size_t MinKeyLength() const
Returns smallest valid key length in bytes.
Definition: eax.h:25
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: eax.h:45
Class file for modes of operation.
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
Definition: seckey.h:414
EAX block cipher mode of operation.
Definition: eax.h:19
size_t MaxKeyLength() const
Returns largest valid key length in bytes.
Definition: eax.h:27
Classes for CMAC message authentication code.
size_t GetValidKeyLength(size_t n) const
Definition: eax.h:31
Class specific methods used to operate the cipher.
Definition: eax.h:78
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1008
lword MaxMessageLength() const
the maximum length of encrypted data
Definition: eax.h:49
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: eax.h:35
IV_Requirement IVRequirement() const
returns the minimal requirement for secure IVs
Definition: eax.h:37
Provides IV requirements as an enumerated value.
Definition: cryptlib.h:549
lword MaxHeaderLength() const
the maximum length of AAD that can be input before the encrypted data
Definition: eax.h:47
size_t DefaultKeyLength() const
Returns default (recommended) key length in bytes.
Definition: eax.h:29
Definition: cmac.h:16
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: eax.h:39
Crypto++ library namespace.
unsigned int MinIVLength() const
returns minimal length of IVs accepted by this object
Definition: eax.h:41
unsigned int MaxIVLength() const
returns maximal length of IVs accepted by this object
Definition: eax.h:43
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: eax.h:23
Base classes for working with authenticated encryption modes of encryption.
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: eax.h:83
The EAX block cipher mode of operation.
Definition: eax.h:104
bool IsValidKeyLength(size_t n) const
Returns whether keylength is a valid key length.
Definition: eax.h:33
Interface for retrieving values given their names.
Definition: cryptlib.h:257