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.

50 lines
1.4 KiB

  1. #ifndef CRYPTOPP_CBCMAC_H
  2. #define CRYPTOPP_CBCMAC_H
  3. #include "seckey.h"
  4. #include "secblock.h"
  5. NAMESPACE_BEGIN(CryptoPP)
  6. //! _
  7. class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticationCode
  8. {
  9. public:
  10. CBC_MAC_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 const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
  15. protected:
  16. virtual BlockCipher & AccessCipher() =0;
  17. private:
  18. void ProcessBuf();
  19. SecByteBlock m_reg;
  20. unsigned int m_counter;
  21. };
  22. //! <a href="http://www.weidai.com/scan-mirror/mac.html#CBC-MAC">CBC-MAC</a>
  23. /*! Compatible with FIPS 113. T should be a class derived from BlockCipherDocumentation.
  24. Secure only for fixed length messages. For variable length messages use CMAC or DMAC.
  25. */
  26. template <class T>
  27. class CBC_MAC : public MessageAuthenticationCodeImpl<CBC_MAC_Base, CBC_MAC<T> >, public SameKeyLengthAs<T>
  28. {
  29. public:
  30. CBC_MAC() {}
  31. CBC_MAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
  32. {this->SetKey(key, length);}
  33. static std::string StaticAlgorithmName() {return std::string("CBC-MAC(") + T::StaticAlgorithmName() + ")";}
  34. private:
  35. BlockCipher & AccessCipher() {return m_cipher;}
  36. typename T::Encryption m_cipher;
  37. };
  38. NAMESPACE_END
  39. #endif