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 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 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  size_t MinKeyLength() const
25  {return GetMAC().MinKeyLength();}
26  size_t MaxKeyLength() const
27  {return GetMAC().MaxKeyLength();}
28  size_t DefaultKeyLength() const
29  {return GetMAC().DefaultKeyLength();}
30  size_t GetValidKeyLength(size_t n) const
31  {return GetMAC().GetValidKeyLength(n);}
32  bool IsValidKeyLength(size_t n) const
33  {return GetMAC().IsValidKeyLength(n);}
34  unsigned int OptimalDataAlignment() const
35  {return GetMAC().OptimalDataAlignment();}
37  {return UNIQUE_IV;}
38  unsigned int IVSize() const
39  {return GetMAC().TagSize();}
40  unsigned int MinIVLength() const
41  {return 0;}
42  unsigned int MaxIVLength() const
43  {return UINT_MAX;}
44  unsigned int DigestSize() const
45  {return GetMAC().TagSize();}
46  lword MaxHeaderLength() const
47  {return LWORD_MAX;}
48  lword MaxMessageLength() const
49  {return LWORD_MAX;}
51 protected:
52  // AuthenticatedSymmetricCipherBase
53  bool AuthenticationIsOnPlaintext() const
54  {return false;}
55  unsigned int AuthenticationBlockSize() const
56  {return 1;}
57  void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params);
58  void Resync(const byte *iv, size_t len);
59  size_t AuthenticateBlocks(const byte *data, size_t len);
60  void AuthenticateLastHeaderBlock();
61  void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
62  SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
63  const CMAC_Base & GetMAC() const {return const_cast<EAX_Base *>(this)->AccessMAC();}
64  virtual CMAC_Base & AccessMAC() =0;
67 };
69 //! \class EAX_Final
70 //! \brief EAX block cipher final implementation
71 //! \tparam T_BlockCipher block cipher
72 //! \tparam T_IsEncryption direction in which to operate the cipher
73 template <class T_BlockCipher, bool T_IsEncryption>
74 class EAX_Final : public EAX_Base
75 {
76 public:
77  static std::string StaticAlgorithmName()
78  {return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");}
80  {return T_IsEncryption;}
82 private:
83  CMAC_Base & AccessMAC() {return m_cmac;}
84  CMAC<T_BlockCipher> m_cmac;
85 };
87 #ifdef EAX // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11
88 #undef EAX
89 #endif
91 //! \class EAX
92 //! \brief EAX block cipher mode of operation
93 //! \tparam T_BlockCipher block cipher
94 //! \details \p EAX provides the \p Encryption and \p Decryption typedef. See EAX_Base
95 //! and EAX_Final for the AuthenticatedSymmetricCipher implementation.
96 //! \sa <a href="">EAX</a> at the Crypto Lounge
97 template <class T_BlockCipher>
99 {
102 };
106 #endif
size_t MinKeyLength() const
Returns smallest valid key length in bytes.
Definition: eax.h:24
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: eax.h:44
Class file for modes of operation.
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 in bytes.
Definition: eax.h:26
Classes for CMAC message authentication code.
size_t GetValidKeyLength(size_t n) const
Definition: eax.h:30
EAX block cipher final implementation.
Definition: eax.h:74
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1099
lword MaxMessageLength() const
Provides the maximum length of encrypted data.
Definition: eax.h:48
Base implementation for one direction (encryption or decryption) of a stream cipher or block cipher m...
Definition: authenc.h:17
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: eax.h:34
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: eax.h:36
Secure IVs requirements as enumerated values.
Definition: cryptlib.h:590
lword MaxHeaderLength() const
Provides the maximum length of AAD that can be input.
Definition: eax.h:46
size_t DefaultKeyLength() const
Returns default (recommended) key length in bytes.
Definition: eax.h:28
CMAC base implementation.
Definition: cmac.h:16
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: eax.h:38
Crypto++ library namespace.
unsigned int MinIVLength() const
Provides the minimum size of an IV.
Definition: eax.h:40
unsigned int MaxIVLength() const
Provides the maximum size of an IV.
Definition: eax.h:42
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: eax.h:22
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:79
EAX block cipher mode of operation.
Definition: eax.h:98
bool IsValidKeyLength(size_t n) const
Returns whether keylength is a valid key length.
Definition: eax.h:32
Interface for retrieving values given their names.
Definition: cryptlib.h:277