File indexing completed on 2025-01-18 09:55:01
0001
0002
0003
0004
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
0016
0017
0018 class CRYPTOPP_NO_VTABLE EAX_Base : public AuthenticatedSymmetricCipherBase
0019 {
0020 public:
0021
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
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 ¶ms);
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
0072
0073
0074
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
0092 #undef EAX
0093 #endif
0094
0095
0096
0097
0098
0099
0100
0101
0102
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