Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:01

0001 // eax.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file eax.h

0004 /// \brief EAX block cipher mode of operation

0005 
0006 #ifndef CRYPTOPP_EAX_H
0007 #define CRYPTOPP_EAX_H
0008 
0009 #include "authenc.h"
0010 #include "modes.h"
0011 #include "cmac.h"
0012 
0013 NAMESPACE_BEGIN(CryptoPP)
0014 
0015 /// \brief EAX block cipher base implementation

0016 /// \details Base implementation of the AuthenticatedSymmetricCipher interface

0017 /// \since Crypto++ 5.6.0

0018 class CRYPTOPP_NO_VTABLE EAX_Base : public AuthenticatedSymmetricCipherBase
0019 {
0020 public:
0021     // AuthenticatedSymmetricCipher

0022     std::string AlgorithmName() const
0023         {return GetMAC().GetCipher().AlgorithmName() + std::string("/EAX");}
0024     std::string AlgorithmProvider() const
0025         {return GetMAC().GetCipher().AlgorithmProvider();}
0026     size_t MinKeyLength() const
0027         {return GetMAC().MinKeyLength();}
0028     size_t MaxKeyLength() const
0029         {return GetMAC().MaxKeyLength();}
0030     size_t DefaultKeyLength() const
0031         {return GetMAC().DefaultKeyLength();}
0032     size_t GetValidKeyLength(size_t n) const
0033         {return GetMAC().GetValidKeyLength(n);}
0034     bool IsValidKeyLength(size_t n) const
0035         {return GetMAC().IsValidKeyLength(n);}
0036     unsigned int OptimalDataAlignment() const
0037         {return GetMAC().OptimalDataAlignment();}
0038     IV_Requirement IVRequirement() const
0039         {return UNIQUE_IV;}
0040     unsigned int IVSize() const
0041         {return GetMAC().TagSize();}
0042     unsigned int MinIVLength() const
0043         {return 0;}
0044     unsigned int MaxIVLength() const
0045         {return UINT_MAX;}
0046     unsigned int DigestSize() const
0047         {return GetMAC().TagSize();}
0048     lword MaxHeaderLength() const
0049         {return LWORD_MAX;}
0050     lword MaxMessageLength() const
0051         {return LWORD_MAX;}
0052 
0053 protected:
0054     // AuthenticatedSymmetricCipherBase

0055     bool AuthenticationIsOnPlaintext() const
0056         {return false;}
0057     unsigned int AuthenticationBlockSize() const
0058         {return 1;}
0059     void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params);
0060     void Resync(const byte *iv, size_t len);
0061     size_t AuthenticateBlocks(const byte *data, size_t len);
0062     void AuthenticateLastHeaderBlock();
0063     void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
0064     SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
0065     const CMAC_Base & GetMAC() const {return const_cast<EAX_Base *>(this)->AccessMAC();}
0066     virtual CMAC_Base & AccessMAC() =0;
0067 
0068     CTR_Mode_ExternalCipher::Encryption m_ctr;
0069 };
0070 
0071 /// \brief EAX block cipher final implementation

0072 /// \tparam T_BlockCipher block cipher

0073 /// \tparam T_IsEncryption direction in which to operate the cipher

0074 /// \since Crypto++ 5.6.0

0075 template <class T_BlockCipher, bool T_IsEncryption>
0076 class EAX_Final : public EAX_Base
0077 {
0078 public:
0079     static std::string StaticAlgorithmName()
0080         {return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");}
0081     std::string AlgorithmProvider() const
0082         {return m_cmac.AlgorithmProvider();}
0083     bool IsForwardTransformation() const
0084         {return T_IsEncryption;}
0085 
0086 private:
0087     CMAC_Base & AccessMAC() {return m_cmac;}
0088     CMAC<T_BlockCipher> m_cmac;
0089 };
0090 
0091 #ifdef EAX  // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11

0092 #undef EAX
0093 #endif
0094 
0095 /// \brief EAX block cipher mode of operation

0096 /// \tparam T_BlockCipher block cipher

0097 /// \details \p EAX provides the \p Encryption and \p Decryption typedef. See EAX_Base

0098 ///   and EAX_Final for the AuthenticatedSymmetricCipher implementation.

0099 /// \sa <a href="http://www.cryptopp.com/wiki/EAX_Mode">EAX Mode</a> and

0100 ///   <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>

0101 ///   on the Crypto++ wiki.

0102 /// \since Crypto++ 5.6.0

0103 template <class T_BlockCipher>
0104 struct EAX : public AuthenticatedSymmetricCipherDocumentation
0105 {
0106     typedef EAX_Final<T_BlockCipher, true> Encryption;
0107     typedef EAX_Final<T_BlockCipher, false> Decryption;
0108 };
0109 
0110 NAMESPACE_END
0111 
0112 #endif