Crypto++  5.6.5
Free C++ class library of cryptographic schemes
Go to the documentation of this file.
1 // eax.h - originally written and placed in the public domain by Wei Dai
3 //! \file eax.h
4 //! \brief EAX block cipher mode of operation
6 #ifndef CRYPTOPP_EAX_H
7 #define CRYPTOPP_EAX_H
9 #include "authenc.h"
10 #include "modes.h"
11 #include "cmac.h"
15 //! \class EAX_Base
16 //! \brief EAX block cipher base implementation
17 //! \details Base implementation of the AuthenticatedSymmetricCipher interface
18 //! \since Crypto++ 5.6.0
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 EAX block cipher final implementation
72 //! \tparam T_BlockCipher block cipher
73 //! \tparam T_IsEncryption direction in which to operate the cipher
74 //! \since Crypto++ 5.6.0
75 template <class T_BlockCipher, bool T_IsEncryption>
76 class EAX_Final : public EAX_Base
77 {
78 public:
79  static std::string StaticAlgorithmName()
80  {return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");}
82  {return T_IsEncryption;}
84 private:
85  CMAC_Base & AccessMAC() {return m_cmac;}
86  CMAC<T_BlockCipher> m_cmac;
87 };
89 #ifdef EAX // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11
90 #undef EAX
91 #endif
93 //! \class EAX
94 //! \brief EAX block cipher mode of operation
95 //! \tparam T_BlockCipher block cipher
96 //! \details \p EAX provides the \p Encryption and \p Decryption typedef. See EAX_Base
97 //! and EAX_Final for the AuthenticatedSymmetricCipher implementation.
98 //! \sa <a href="">EAX</a> at the Crypto Lounge
99 //! \since Crypto++ 5.6.0
100 template <class T_BlockCipher>
102 {
105 };
109 #endif
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: eax.h:81
size_t DefaultKeyLength() const
Returns default key length.
Definition: eax.h:29
bool IsValidKeyLength(size_t n) const
Returns whether keylength is a valid key length.
Definition: eax.h:33
lword MaxHeaderLength() const
Provides the maximum length of AAD that can be input.
Definition: eax.h:47
Class file for modes of operation.
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
Definition: seckey.h:437
EAX block cipher base implementation.
Definition: eax.h:19
size_t MaxKeyLength() const
Returns largest valid key length.
Definition: eax.h:27
unsigned int MinIVLength() const
Provides the minimum size of an IV.
Definition: eax.h:41
Classes for CMAC message authentication code.
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: eax.h:39
EAX block cipher final implementation.
Definition: eax.h:76
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1109
Base implementation for one direction (encryption or decryption) of a stream cipher or block cipher m...
Definition: authenc.h:19
unsigned int MaxIVLength() const
Provides the maximum size of an IV.
Definition: eax.h:43
size_t GetValidKeyLength(size_t n) const
Returns a valid key length for the algorithm.
Definition: eax.h:31
size_t MinKeyLength() const
Returns smallest valid key length.
Definition: eax.h:25
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: eax.h:35
Secure IVs requirements as enumerated values.
Definition: cryptlib.h:604
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: eax.h:23
CMAC base implementation.
Definition: cmac.h:18
Crypto++ library namespace.
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: eax.h:45
lword MaxMessageLength() const
Provides the maximum length of encrypted data.
Definition: eax.h:49
Base classes for working with authenticated encryption modes of encryption.
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: eax.h:37
EAX block cipher mode of operation.
Definition: eax.h:101
Interface for retrieving values given their names.
Definition: cryptlib.h:285