00001
00002
00003
00004
00005
00006
00007 #ifndef CRYPTOPP_CBCMAC_H
00008 #define CRYPTOPP_CBCMAC_H
00009
00010 #include "seckey.h"
00011 #include "secblock.h"
00012
00013 NAMESPACE_BEGIN(CryptoPP)
00014
00015
00016 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode
00017 {
00018 public:
00019 CBC_MAC_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 const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
00025
00026 protected:
00027 virtual BlockCipher & AccessCipher() =0;
00028
00029 private:
00030 void ProcessBuf();
00031 SecByteBlock m_reg;
00032 unsigned int m_counter;
00033 };
00034
00035
00036
00037
00038
00039 template <class T>
00040 class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
00041 {
00042 public:
00043 CBC_MAC() {}
00044 CBC_MAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
00045 {this->SetKey(key, length);}
00046
00047 static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
00048
00049 private:
00050 BlockCipher & AccessCipher() {return m_cipher;}
00051 typename T::Encryption m_cipher;
00052 };
00053
00054 NAMESPACE_END
00055
00056 #endif