Crypto++
|
00001 #ifndef CRYPTOPP_CMAC_H 00002 #define CRYPTOPP_CMAC_H 00003 00004 #include "seckey.h" 00005 #include "secblock.h" 00006 00007 NAMESPACE_BEGIN(CryptoPP) 00008 00009 //! _ 00010 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode 00011 { 00012 public: 00013 CMAC_Base() {} 00014 00015 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); 00016 void Update(const byte *input, size_t length); 00017 void TruncatedFinal(byte *mac, size_t size); 00018 unsigned int DigestSize() const {return GetCipher().BlockSize();} 00019 unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();} 00020 unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();} 00021 00022 protected: 00023 friend class EAX_Base; 00024 00025 const BlockCipher & GetCipher() const {return const_cast<CMAC_Base*>(this)->AccessCipher();} 00026 virtual BlockCipher & AccessCipher() =0; 00027 00028 void ProcessBuf(); 00029 SecByteBlock m_reg; 00030 unsigned int m_counter; 00031 }; 00032 00033 /// <a href="http://www.cryptolounge.org/wiki/CMAC">CMAC</a> 00034 /*! Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32 */ 00035 template <class T> 00036 class CMAC : public MessageAuthenticationCodeImpl<CMAC_Base, CMAC<T> >, public SameKeyLengthAs<T> 00037 { 00038 public: 00039 CMAC() {} 00040 CMAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH) 00041 {this->SetKey(key, length);} 00042 00043 static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";} 00044 00045 private: 00046 BlockCipher & AccessCipher() {return m_cipher;} 00047 typename T::Encryption m_cipher; 00048 }; 00049 00050 NAMESPACE_END 00051 00052 #endif