Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

  1. #ifndef CRYPTOPP_CMAC_H
  2. #define CRYPTOPP_CMAC_H
  3. #include "seckey.h"
  4. #include "secblock.h"
  5. NAMESPACE_BEGIN(CryptoPP)
  6. //! _
  7. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode
  8. {
  9. public:
  10. CMAC_Base() {}
  11. void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
  12. void Update(const byte *input, size_t length);
  13. void TruncatedFinal(byte *mac, size_t size);
  14. unsigned int DigestSize() const {return GetCipher().BlockSize();}
  15. unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
  16. unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
  17. protected:
  18. friend class EAX_Base;
  19. const BlockCipher & GetCipher() const {return const_cast<CMAC_Base*>(this)->AccessCipher();}
  20. virtual BlockCipher & AccessCipher() =0;
  21. void ProcessBuf();
  22. SecByteBlock m_reg;
  23. unsigned int m_counter;
  24. };
  25. /// <a href="http://www.cryptolounge.org/wiki/CMAC">CMAC</a>
  26. /*! Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32 */
  27. template <class T>
  28. class CMAC : public MessageAuthenticationCodeImpl<CMAC_Base, CMAC<T> >, public SameKeyLengthAs<T>
  29. {
  30. public:
  31. CMAC() {}
  32. CMAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
  33. {this->SetKey(key, length);}
  34. static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";}
  35. private:
  36. BlockCipher & AccessCipher() {return m_cipher;}
  37. typename T::Encryption m_cipher;
  38. };
  39. NAMESPACE_END
  40. #endif