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.

70 lines
2.7 KiB

  1. // sha.h - written and placed in the public domain by Wei Dai
  2. //! \file
  3. //! \headerfile sha.h
  4. //! \brief Classes for SHA-1 and SHA-2 family of message digests
  5. #ifndef CRYPTOPP_SHA_H
  6. #define CRYPTOPP_SHA_H
  7. #include "config.h"
  8. #include "iterhash.h"
  9. NAMESPACE_BEGIN(CryptoPP)
  10. /// <a href="http://www.weidai.com/scan-mirror/md.html#SHA-1">SHA-1</a>
  11. class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 20, SHA1>
  12. {
  13. public:
  14. static void CRYPTOPP_API InitState(HashWordType *state);
  15. static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
  16. static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";}
  17. };
  18. typedef SHA1 SHA; // for backwards compatibility
  19. //! implements the SHA-256 standard
  20. class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA256, 32, true>
  21. {
  22. public:
  23. #if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
  24. size_t HashMultipleBlocks(const word32 *input, size_t length);
  25. #endif
  26. static void CRYPTOPP_API InitState(HashWordType *state);
  27. static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
  28. static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";}
  29. };
  30. //! implements the SHA-224 standard
  31. class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA224, 28, true>
  32. {
  33. public:
  34. #if defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
  35. size_t HashMultipleBlocks(const word32 *input, size_t length);
  36. #endif
  37. static void CRYPTOPP_API InitState(HashWordType *state);
  38. static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);}
  39. static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";}
  40. };
  41. //! implements the SHA-512 standard
  42. class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA512, 64, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
  43. {
  44. public:
  45. static void CRYPTOPP_API InitState(HashWordType *state);
  46. static void CRYPTOPP_API Transform(word64 *digest, const word64 *data);
  47. static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";}
  48. };
  49. //! implements the SHA-384 standard
  50. class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA384, 48, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
  51. {
  52. public:
  53. static void CRYPTOPP_API InitState(HashWordType *state);
  54. static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);}
  55. static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";}
  56. };
  57. NAMESPACE_END
  58. #endif