Crypto++
|
00001 #ifndef CRYPTOPP_EAX_H 00002 #define CRYPTOPP_EAX_H 00003 00004 #include "authenc.h" 00005 #include "modes.h" 00006 #include "cmac.h" 00007 00008 NAMESPACE_BEGIN(CryptoPP) 00009 00010 //! . 00011 class CRYPTOPP_NO_VTABLE EAX_Base : public AuthenticatedSymmetricCipherBase 00012 { 00013 public: 00014 // AuthenticatedSymmetricCipher 00015 std::string AlgorithmName() const 00016 {return GetMAC().GetCipher().AlgorithmName() + std::string("/EAX");} 00017 size_t MinKeyLength() const 00018 {return GetMAC().MinKeyLength();} 00019 size_t MaxKeyLength() const 00020 {return GetMAC().MaxKeyLength();} 00021 size_t DefaultKeyLength() const 00022 {return GetMAC().DefaultKeyLength();} 00023 size_t GetValidKeyLength(size_t n) const 00024 {return GetMAC().GetValidKeyLength(n);} 00025 bool IsValidKeyLength(size_t n) const 00026 {return GetMAC().IsValidKeyLength(n);} 00027 unsigned int OptimalDataAlignment() const 00028 {return GetMAC().OptimalDataAlignment();} 00029 IV_Requirement IVRequirement() const 00030 {return UNIQUE_IV;} 00031 unsigned int IVSize() const 00032 {return GetMAC().TagSize();} 00033 unsigned int MinIVLength() const 00034 {return 0;} 00035 unsigned int MaxIVLength() const 00036 {return UINT_MAX;} 00037 unsigned int DigestSize() const 00038 {return GetMAC().TagSize();} 00039 lword MaxHeaderLength() const 00040 {return LWORD_MAX;} 00041 lword MaxMessageLength() const 00042 {return LWORD_MAX;} 00043 00044 protected: 00045 // AuthenticatedSymmetricCipherBase 00046 bool AuthenticationIsOnPlaintext() const 00047 {return false;} 00048 unsigned int AuthenticationBlockSize() const 00049 {return 1;} 00050 void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms); 00051 void Resync(const byte *iv, size_t len); 00052 size_t AuthenticateBlocks(const byte *data, size_t len); 00053 void AuthenticateLastHeaderBlock(); 00054 void AuthenticateLastFooterBlock(byte *mac, size_t macSize); 00055 SymmetricCipher & AccessSymmetricCipher() {return m_ctr;} 00056 const CMAC_Base & GetMAC() const {return const_cast<EAX_Base *>(this)->AccessMAC();} 00057 virtual CMAC_Base & AccessMAC() =0; 00058 00059 CTR_Mode_ExternalCipher::Encryption m_ctr; 00060 }; 00061 00062 //! . 00063 template <class T_BlockCipher, bool T_IsEncryption> 00064 class EAX_Final : public EAX_Base 00065 { 00066 public: 00067 static std::string StaticAlgorithmName() 00068 {return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");} 00069 bool IsForwardTransformation() const 00070 {return T_IsEncryption;} 00071 00072 private: 00073 CMAC_Base & AccessMAC() {return m_cmac;} 00074 CMAC<T_BlockCipher> m_cmac; 00075 }; 00076 00077 #ifdef EAX // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11 00078 #undef EAX 00079 #endif 00080 00081 /// <a href="http://www.cryptolounge.org/wiki/EAX">EAX</a> 00082 template <class T_BlockCipher> 00083 struct EAX : public AuthenticatedSymmetricCipherDocumentation 00084 { 00085 typedef EAX_Final<T_BlockCipher, true> Encryption; 00086 typedef EAX_Final<T_BlockCipher, false> Decryption; 00087 }; 00088 00089 NAMESPACE_END 00090 00091 #endif