Team Fortress 2 Source Code as on 22/4/2020
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.

69 lines
1.6 KiB

  1. // sha3.h - written and placed in the public domain by Wei Dai
  2. //! \file
  3. //! \headerfile sha3.h
  4. //! \brief Classes for SHA-3 message digests
  5. #ifndef CRYPTOPP_SHA3_H
  6. #define CRYPTOPP_SHA3_H
  7. #include "cryptlib.h"
  8. #include "secblock.h"
  9. NAMESPACE_BEGIN(CryptoPP)
  10. /// <a href="http://en.wikipedia.org/wiki/SHA-3">SHA-3</a>
  11. class SHA3 : public HashTransformation
  12. {
  13. public:
  14. SHA3(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
  15. unsigned int DigestSize() const {return m_digestSize;}
  16. std::string AlgorithmName() const {return "SHA-3-" + IntToString(m_digestSize*8);}
  17. unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
  18. void Update(const byte *input, size_t length);
  19. void Restart();
  20. void TruncatedFinal(byte *hash, size_t size);
  21. protected:
  22. inline unsigned int r() const {return 200 - 2 * m_digestSize;}
  23. FixedSizeSecBlock<word64, 25> m_state;
  24. unsigned int m_digestSize, m_counter;
  25. };
  26. class SHA3_224 : public SHA3
  27. {
  28. public:
  29. CRYPTOPP_CONSTANT(DIGESTSIZE = 28)
  30. SHA3_224() : SHA3(DIGESTSIZE) {}
  31. static const char * StaticAlgorithmName() {return "SHA-3-224";}
  32. };
  33. class SHA3_256 : public SHA3
  34. {
  35. public:
  36. CRYPTOPP_CONSTANT(DIGESTSIZE = 32)
  37. SHA3_256() : SHA3(DIGESTSIZE) {}
  38. static const char * StaticAlgorithmName() {return "SHA-3-256";}
  39. };
  40. class SHA3_384 : public SHA3
  41. {
  42. public:
  43. CRYPTOPP_CONSTANT(DIGESTSIZE = 48)
  44. SHA3_384() : SHA3(DIGESTSIZE) {}
  45. static const char * StaticAlgorithmName() {return "SHA-3-384";}
  46. };
  47. class SHA3_512 : public SHA3
  48. {
  49. public:
  50. CRYPTOPP_CONSTANT(DIGESTSIZE = 64)
  51. SHA3_512() : SHA3(DIGESTSIZE) {}
  52. static const char * StaticAlgorithmName() {return "SHA-3-512";}
  53. };
  54. NAMESPACE_END
  55. #endif