00001
00002
00003
00004
00005
00006
00007 #ifndef CRYPTOPP_CMAC_H
00008 #define CRYPTOPP_CMAC_H
00009
00010 #include "seckey.h"
00011 #include "secblock.h"
00012
00013 NAMESPACE_BEGIN(CryptoPP)
00014
00015
00016 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode
00017 {
00018 public:
00019 CMAC_Base() : m_counter(0) {}
00020
00021 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
00022 void Update(const byte *input, size_t length);
00023 void TruncatedFinal(byte *mac, size_t size);
00024 unsigned int DigestSize() const {return GetCipher().BlockSize();}
00025 unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
00026 unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
00027
00028 protected:
00029 friend class EAX_Base;
00030
00031 const BlockCipher & GetCipher() const {return const_cast<CMAC_Base*>(this)->AccessCipher();}
00032 virtual BlockCipher & AccessCipher() =0;
00033
00034 void ProcessBuf();
00035 SecByteBlock m_reg;
00036 unsigned int m_counter;
00037 };
00038
00039
00040
00041 template <class T>
00042 class CMAC : public MessageAuthenticationCodeImpl<CMAC_Base, CMAC<T> >, public SameKeyLengthAs<T>
00043 {
00044 public:
00045 CMAC() {}
00046 CMAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
00047 {this->SetKey(key, length);}
00048
00049 static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";}
00050
00051 private:
00052 BlockCipher & AccessCipher() {return m_cipher;}
00053 typename T::Encryption m_cipher;
00054 };
00055
00056 NAMESPACE_END
00057
00058 #endif