Crypto++ 8.4 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();}
38 IV_Requirement IVRequirement() const
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;}
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
68 CTR_Mode_ExternalCipher::Encryption m_ctr;
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();}
83 bool IsForwardTransformation() const
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>
104 struct EAX : public AuthenticatedSymmetricCipherDocumentation
105 {
106 typedef EAX_Final<T_BlockCipher, true> Encryption;
107 typedef EAX_Final<T_BlockCipher, false> Decryption;
108 };
109
110 NAMESPACE_END
111
112 #endif
EAX
EAX block cipher mode of operation.
Definition: eax.h:104
EAX_Final::AlgorithmProvider
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: eax.h:81
EAX_Base::DigestSize
unsigned int DigestSize() const
Provides the digest size of the hash.
Definition: eax.h:46
EAX_Base::OptimalDataAlignment
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: eax.h:36
CMAC_Base::AlgorithmProvider
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: cmac.h:37
EAX_Base::IVRequirement
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: eax.h:38
modes.h
Classes for block cipher modes of operation.
CMAC< T_BlockCipher >
EAX_Base::MinIVLength
unsigned int MinIVLength() const
Provides the minimum size of an IV.
Definition: eax.h:42
SymmetricCipher
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode.
Definition: cryptlib.h:1290
EAX_Base::MaxIVLength
unsigned int MaxIVLength() const
Provides the maximum size of an IV.
Definition: eax.h:44
AuthenticatedSymmetricCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
Definition: seckey.h:425
CipherModeFinalTemplate_ExternalCipher< ConcretePolicyHolder< Empty, AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > > > >
EAX_Base::AlgorithmProvider
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: eax.h:24
EAX_Base::AlgorithmName
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: eax.h:22
SimpleKeyingInterface::IV_Requirement
IV_Requirement
Secure IVs requirements as enumerated values.
Definition: cryptlib.h:719
EAX_Base::IsValidKeyLength
bool IsValidKeyLength(size_t n) const
Returns whether keylength is a valid key length.
Definition: eax.h:34
EAX_Base::GetValidKeyLength
size_t GetValidKeyLength(size_t n) const
Returns a valid key length for the algorithm.
Definition: eax.h:32
EAX_Base::MaxHeaderLength
lword MaxHeaderLength() const
Provides the maximum length of AAD that can be input.
Definition: eax.h:48
EAX_Final::IsForwardTransformation
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: eax.h:83
authenc.h
Classes for authenticated encryption modes of operation.
AuthenticatedSymmetricCipherBase
Base class for authenticated encryption modes of operation.
Definition: authenc.h:40
EAX_Base::MaxKeyLength
size_t MaxKeyLength() const
Returns largest valid key length.
Definition: eax.h:28
EAX_Base::MinKeyLength
size_t MinKeyLength() const
Returns smallest valid key length.
Definition: eax.h:26
CMAC_Base
CMAC base implementation.
Definition: cmac.h:24
lword
word64 lword
Large word type.
Definition: config_int.h:158
EAX_Base::MaxMessageLength
lword MaxMessageLength() const
Provides the maximum length of encrypted data.
Definition: eax.h:50
CryptoPP
Crypto++ library namespace.
EAX_Base::IVSize
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: eax.h:40
EAX_Base
EAX block cipher base implementation.
Definition: eax.h:18
cmac.h
Classes for CMAC message authentication code.
EAX_Base::DefaultKeyLength
size_t DefaultKeyLength() const
Returns default key length.
Definition: eax.h:30
LWORD_MAX
const lword LWORD_MAX
Large word type max value.
Definition: config_int.h:164
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:321
EAX_Final
EAX block cipher final implementation.
Definition: eax.h:76