File indexing completed on 2025-01-18 09:54:54
0001
0002
0003
0004
0005
0006
0007 #ifndef CRYPTOPP_CBCMAC_H
0008 #define CRYPTOPP_CBCMAC_H
0009
0010 #include "seckey.h"
0011 #include "secblock.h"
0012
0013 NAMESPACE_BEGIN(CryptoPP)
0014
0015
0016
0017 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode
0018 {
0019 public:
0020 CBC_MAC_Base() : m_counter(0) {}
0021
0022 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
0023 void Update(const byte *input, size_t length);
0024 void TruncatedFinal(byte *mac, size_t size);
0025 unsigned int DigestSize() const {return const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
0026
0027 protected:
0028 virtual BlockCipher & AccessCipher() =0;
0029
0030 private:
0031 void ProcessBuf();
0032 SecByteBlock m_reg;
0033 unsigned int m_counter;
0034 };
0035
0036
0037
0038
0039
0040
0041
0042 template <class T>
0043 class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
0044 {
0045 public:
0046
0047 CBC_MAC() {}
0048
0049
0050
0051 CBC_MAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
0052 {this->SetKey(key, length);}
0053
0054 static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
0055
0056 private:
0057 BlockCipher & AccessCipher() {return m_cipher;}
0058 typename T::Encryption m_cipher;
0059 };
0060
0061 NAMESPACE_END
0062
0063 #endif