1#ifndef CRYPTOPP_EAX_H 2#define CRYPTOPP_EAX_H 3 4#include "authenc.h" 5#include "modes.h" 6#include "cmac.h" 7 8NAMESPACE_BEGIN(CryptoPP) 9 10//! . 11class CRYPTOPP_NO_VTABLE EAX_Base : public AuthenticatedSymmetricCipherBase 12{ 13public: 14 // AuthenticatedSymmetricCipher 15 std::string AlgorithmName() const 16 {return GetMAC().GetCipher().AlgorithmName() + std::string("/EAX");} 17 size_t MinKeyLength() const 18 {return GetMAC().MinKeyLength();} 19 size_t MaxKeyLength() const 20 {return GetMAC().MaxKeyLength();} 21 size_t DefaultKeyLength() const 22 {return GetMAC().DefaultKeyLength();} 23 size_t GetValidKeyLength(size_t n) const 24 {return GetMAC().GetValidKeyLength(n);} 25 bool IsValidKeyLength(size_t n) const 26 {return GetMAC().IsValidKeyLength(n);} 27 unsigned int OptimalDataAlignment() const 28 {return GetMAC().OptimalDataAlignment();} 29 IV_Requirement IVRequirement() const 30 {return UNIQUE_IV;} 31 unsigned int IVSize() const 32 {return GetMAC().TagSize();} 33 unsigned int MinIVLength() const 34 {return 0;} 35 unsigned int MaxIVLength() const 36 {return UINT_MAX;} 37 unsigned int DigestSize() const 38 {return GetMAC().TagSize();} 39 lword MaxHeaderLength() const 40 {return LWORD_MAX;} 41 lword MaxMessageLength() const 42 {return LWORD_MAX;} 43 44protected: 45 // AuthenticatedSymmetricCipherBase 46 bool AuthenticationIsOnPlaintext() const 47 {return false;} 48 unsigned int AuthenticationBlockSize() const 49 {return 1;} 50 void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms); 51 void Resync(const byte *iv, size_t len); 52 size_t AuthenticateBlocks(const byte *data, size_t len); 53 void AuthenticateLastHeaderBlock(); 54 void AuthenticateLastFooterBlock(byte *mac, size_t macSize); 55 SymmetricCipher & AccessSymmetricCipher() {return m_ctr;} 56 const CMAC_Base & GetMAC() const {return const_cast<EAX_Base *>(this)->AccessMAC();} 57 virtual CMAC_Base & AccessMAC() =0; 58 59 CTR_Mode_ExternalCipher::Encryption m_ctr; 60}; 61 62//! . 63template <class T_BlockCipher, bool T_IsEncryption> 64class EAX_Final : public EAX_Base 65{ 66public: 67 static std::string StaticAlgorithmName() 68 {return T_BlockCipher::StaticAlgorithmName() + std::string("/EAX");} 69 bool IsForwardTransformation() const 70 {return T_IsEncryption;} 71 72private: 73 CMAC_Base & AccessMAC() {return m_cmac;} 74 CMAC<T_BlockCipher> m_cmac; 75}; 76 77#ifdef EAX // EAX is defined to 11 on GCC 3.4.3, OpenSolaris 8.11 78#undef EAX 79#endif 80 81/// <a href="http://www.cryptolounge.org/wiki/EAX">EAX</a> 82template <class T_BlockCipher> 83struct EAX : public AuthenticatedSymmetricCipherDocumentation 84{ 85 typedef EAX_Final<T_BlockCipher, true> Encryption; 86 typedef EAX_Final<T_BlockCipher, false> Decryption; 87}; 88 89NAMESPACE_END 90 91#endif 92