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