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