Crypto++  8.2
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 /// \brief EAX block cipher base implementation
16 /// \details Base implementation of the AuthenticatedSymmetricCipher interface
17 /// \since Crypto++ 5.6.0
18 class CRYPTOPP_NO_VTABLE EAX_Base : public AuthenticatedSymmetricCipherBase
19 {
20 public:
21  // AuthenticatedSymmetricCipher
22  std::string AlgorithmName() const
23  {return GetMAC().GetCipher().AlgorithmName() + std::string("/EAX");}
24  std::string AlgorithmProvider() const
25  {return GetMAC().GetCipher().AlgorithmProvider();}
26  size_t MinKeyLength() const
27  {return GetMAC().MinKeyLength();}
28  size_t MaxKeyLength() const
29  {return GetMAC().MaxKeyLength();}
30  size_t DefaultKeyLength() const
31  {return GetMAC().DefaultKeyLength();}
32  size_t GetValidKeyLength(size_t n) const
33  {return GetMAC().GetValidKeyLength(n);}
34  bool IsValidKeyLength(size_t n) const
35  {return GetMAC().IsValidKeyLength(n);}
36  unsigned int OptimalDataAlignment() const
37  {return GetMAC().OptimalDataAlignment();}
39  {return UNIQUE_IV;}
40  unsigned int IVSize() const
41  {return GetMAC().TagSize();}
42  unsigned int MinIVLength() const
43  {return 0;}
44  unsigned int MaxIVLength() const
45  {return UINT_MAX;}
46  unsigned int DigestSize() const
47  {return GetMAC().TagSize();}
48  lword MaxHeaderLength() const
49  {return LWORD_MAX;}
50  lword MaxMessageLength() const
51  {return LWORD_MAX;}
53 protected:
54  // AuthenticatedSymmetricCipherBase
55  bool AuthenticationIsOnPlaintext() const
56  {return false;}
57  unsigned int AuthenticationBlockSize() const
58  {return 1;}
59  void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params);
60  void Resync(const byte *iv, size_t len);
61  size_t AuthenticateBlocks(const byte *data, size_t len);
62  void AuthenticateLastHeaderBlock();
63  void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
64  SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
65  const CMAC_Base & GetMAC() const {return const_cast<EAX_Base *>(this)->AccessMAC();}
66  virtual CMAC_Base & AccessMAC() =0;
69 };
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");}
81  std::string AlgorithmProvider() const
82  {return m_cmac.AlgorithmProvider();}
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 /// \brief EAX block cipher mode of operation
96 /// \tparam T_BlockCipher block cipher
97 /// \details \p EAX provides the \p Encryption and \p Decryption typedef. See EAX_Base
98 /// and EAX_Final for the AuthenticatedSymmetricCipher implementation.
99 /// \sa <a href="">EAX Mode</a> and
100 /// <A HREF="">Modes of Operation</A>
101 /// on the Crypto++ wiki.
102 /// \since Crypto++ 5.6.0
103 template <class T_BlockCipher>
105 {
108 };
112 #endif
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: eax.h:83
size_t DefaultKeyLength() const
Returns default key length.
Definition: eax.h:30
bool IsValidKeyLength(size_t n) const
Returns whether keylength is a valid key length.
Definition: eax.h:34
lword MaxHeaderLength() const
Provides the maximum length of AAD that can be input.
Definition: eax.h:48
Classes for block cipher modes of operation.
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: eax.h:24
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
Definition: seckey.h:425
EAX block cipher base implementation.
Definition: eax.h:18
size_t MaxKeyLength() const
Returns largest valid key length.
Definition: eax.h:28
unsigned int MinIVLength() const
Provides the minimum size of an IV.
Definition: eax.h:42
Classes for CMAC message authentication code.
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: eax.h:40
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:1286
Base class for authenticated encryption modes of operation.
Definition: authenc.h:40
unsigned int MaxIVLength() const
Provides the maximum size of an IV.
Definition: eax.h:44
size_t GetValidKeyLength(size_t n) const
Returns a valid key length for the algorithm.
Definition: eax.h:32
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: cmac.h:37
size_t MinKeyLength() const
Returns smallest valid key length.
Definition: eax.h:26
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: eax.h:36
Secure IVs requirements as enumerated values.
Definition: cryptlib.h:719
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: eax.h:22
CMAC base implementation.
Definition: cmac.h:24
Crypto++ library namespace.
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: eax.h:81
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: eax.h:46
lword MaxMessageLength() const
Provides the maximum length of encrypted data.
Definition: eax.h:50
Classes for authenticated encryption modes of operation.
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: eax.h:38
EAX block cipher mode of operation.
Definition: eax.h:104
Interface for retrieving values given their names.
Definition: cryptlib.h:321