sm3.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // sm3.h - written and placed in the public domain by Jeffrey Walton and Han Lulu
  2. // Based on the specification provided by Sean Shen and Xiaodong Lee.
  3. // Based on code by Krzysztof Kwiatkowski and Jack Lloyd.
  4. // Also see https://tools.ietf.org/html/draft-shen-sm3-hash.
  5. /// \file sm3.h
  6. /// \brief Classes for the SM3 hash function
  7. /// \details SM3 is a hash function designed by Xiaoyun Wang, et al. The hash is part of the
  8. /// Chinese State Cryptography Administration portfolio.
  9. /// \sa <A HREF="https://tools.ietf.org/html/draft-shen-sm3-hash">SM3 Hash Function</A> and
  10. /// <A HREF="http://github.com/guanzhi/GmSSL">Reference implementation using OpenSSL</A>.
  11. /// \since Crypto++ 6.0
  12. #ifndef CRYPTOPP_SM3_H
  13. #define CRYPTOPP_SM3_H
  14. #include "config.h"
  15. #include "iterhash.h"
  16. NAMESPACE_BEGIN(CryptoPP)
  17. /// \brief SM3 hash function
  18. /// \details SM3 is a hash function designed by Xiaoyun Wang, et al. The hash is part of the
  19. /// Chinese State Cryptography Administration portfolio.
  20. /// \sa <A HREF="https://tools.ietf.org/html/draft-shen-sm3-hash">SM3 Hash Function</A>
  21. /// \since Crypto++ 6.0
  22. class SM3 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SM3, 32, true>
  23. {
  24. public:
  25. /// \brief Initialize state array
  26. /// \param state the state of the hash
  27. /// \details InitState sets a state array to SM3 initial values
  28. /// \details Hashes which derive from IteratedHashWithStaticTransform provide static
  29. /// member functions InitState() and Transform(). External classes, like SEAL and MDC,
  30. /// can initialize state with a user provided key and operate the hash on the data
  31. /// with the user supplied state.
  32. static void InitState(HashWordType *state);
  33. /// \brief Operate the hash
  34. /// \param digest the state of the hash
  35. /// \param data the data to be digested
  36. /// \details Transform() operates the hash on <tt>data</tt>. When the call is invoked
  37. /// <tt>digest</tt> holds initial or current state. Upon return <tt>digest</tt> holds
  38. /// the hash or updated state.
  39. /// \details Hashes which derive from IteratedHashWithStaticTransform provide static
  40. /// member functions InitState() and Transform(). External classes, like SEAL and MDC,
  41. /// can initialize state with a user provided key and operate the hash on the data
  42. /// with the user supplied state.
  43. static void Transform(HashWordType *digest, const HashWordType *data);
  44. /// \brief The algorithm name
  45. /// \return C-style string "SM3"
  46. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "SM3"; }
  47. protected:
  48. size_t HashMultipleBlocks(const HashWordType *input, size_t length);
  49. };
  50. NAMESPACE_END
  51. #endif // CRYPTOPP_SM3_H