Crypto++  8.8
Free C++ class library of cryptographic schemes
eax.h
Go to the documentation of this file.
1 // eax.h - originally written and placed in the public domain by Wei Dai
2 
3 /// \file eax.h
4 /// \brief EAX block cipher mode of operation
5 
6 #ifndef CRYPTOPP_EAX_H
7 #define CRYPTOPP_EAX_H
8 
9 #include "authenc.h"
10 #include "modes.h"
11 #include "cmac.h"
12 
13 NAMESPACE_BEGIN(CryptoPP)
14 
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();}
49  {return LWORD_MAX;}
51  {return LWORD_MAX;}
52 
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;
67 
69 };
70 
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;}
85 
86 private:
87  CMAC_Base & AccessMAC() {return m_cmac;}
88  CMAC<T_BlockCipher> m_cmac;
89 };
90 
91 #ifdef EAX // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11
92 #undef EAX
93 #endif
94 
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="http://www.cryptopp.com/wiki/EAX_Mode">EAX Mode</a> and
100 /// <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
101 /// on the Crypto++ wiki.
102 /// \since Crypto++ 5.6.0
103 template <class T_BlockCipher>
105 {
108 };
109 
110 NAMESPACE_END
111 
112 #endif
Classes for authenticated encryption modes of operation.
Base class for authenticated encryption modes of operation.
Definition: authenc.h:41
CMAC base implementation.
Definition: cmac.h:25
EAX block cipher base implementation.
Definition: eax.h:19
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: eax.h:46
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
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: eax.h:38
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: eax.h:24
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: eax.h:36
size_t GetValidKeyLength(size_t n) const
Returns a valid key length for the algorithm.
Definition: eax.h:32
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: eax.h:22
unsigned int MaxIVLength() const
Provides the maximum size of an IV.
Definition: eax.h:44
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
lword MaxMessageLength() const
Provides the maximum length of encrypted data.
Definition: eax.h:50
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: eax.h:40
size_t MinKeyLength() const
Returns smallest valid key length.
Definition: eax.h:26
size_t DefaultKeyLength() const
Returns default key length.
Definition: eax.h:30
EAX block cipher final implementation.
Definition: eax.h:77
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: eax.h:83
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: eax.h:81
Interface for retrieving values given their names.
Definition: cryptlib.h:327
IV_Requirement
Secure IVs requirements as enumerated values.
Definition: cryptlib.h:724
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode.
Definition: cryptlib.h:1296
Classes for CMAC message authentication code.
const lword LWORD_MAX
Large word type max value.
Definition: config_int.h:174
word64 lword
Large word type.
Definition: config_int.h:168
Classes for block cipher modes of operation.
Crypto++ library namespace.
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
Definition: seckey.h:426
EAX block cipher mode of operation.
Definition: eax.h:105