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