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.

48 lines
1.4 KiB

  1. #ifndef CRYPTOPP_TRUNHASH_H
  2. #define CRYPTOPP_TRUNHASH_H
  3. #include "cryptlib.h"
  4. NAMESPACE_BEGIN(CryptoPP)
  5. class NullHash : public HashTransformation
  6. {
  7. public:
  8. void Update(const byte *input, size_t length) {}
  9. unsigned int DigestSize() const {return 0;}
  10. void TruncatedFinal(byte *digest, size_t digestSize) {}
  11. bool TruncatedVerify(const byte *digest, size_t digestLength) {return true;}
  12. };
  13. //! construct new HashModule with smaller DigestSize() from existing one
  14. template <class T>
  15. class TruncatedHashTemplate : public HashTransformation
  16. {
  17. public:
  18. TruncatedHashTemplate(T hm, unsigned int digestSize)
  19. : m_hm(hm), m_digestSize(digestSize) {}
  20. TruncatedHashTemplate(const byte *key, size_t keyLength, unsigned int digestSize)
  21. : m_hm(key, keyLength), m_digestSize(digestSize) {}
  22. TruncatedHashTemplate(size_t digestSize)
  23. : m_digestSize(digestSize) {}
  24. void Restart()
  25. {m_hm.Restart();}
  26. void Update(const byte *input, size_t length)
  27. {m_hm.Update(input, length);}
  28. unsigned int DigestSize() const {return m_digestSize;}
  29. void TruncatedFinal(byte *digest, size_t digestSize)
  30. {m_hm.TruncatedFinal(digest, digestSize);}
  31. bool TruncatedVerify(const byte *digest, size_t digestLength)
  32. {return m_hm.TruncatedVerify(digest, digestLength);}
  33. private:
  34. T m_hm;
  35. unsigned int m_digestSize;
  36. };
  37. typedef TruncatedHashTemplate<HashTransformation &> TruncatedHashModule;
  38. NAMESPACE_END
  39. #endif