summaryrefslogtreecommitdiff
path: root/sm3.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-11-23 23:19:09 -0500
committerJeffrey Walton <noloader@gmail.com>2017-11-23 23:19:09 -0500
commit5267723a4923464f677d22f73f97a9e975a187a9 (patch)
tree87322ddc7214bc854d85f73985de18181511c6e6 /sm3.h
parent13652cf9bf8d0d15f4aacd7a3e0426c4b2e553f7 (diff)
downloadcryptopp-git-5267723a4923464f677d22f73f97a9e975a187a9.tar.gz
Add SM3 hash function (GH #541)
Diffstat (limited to 'sm3.h')
-rw-r--r--sm3.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/sm3.h b/sm3.h
new file mode 100644
index 00000000..9a21f88a
--- /dev/null
+++ b/sm3.h
@@ -0,0 +1,61 @@
+// sm3.h - written and placed in the public domain by Jeffrey Walton and Han Lulu
+// Based on the specification provided by Sean Shen and Xiaodong Lee.
+// Based on code by Krzysztof Kwiatkowski and Jack Lloyd.
+// Also see https://tools.ietf.org/html/draft-shen-sm3-hash.
+
+//! \file sm3.h
+//! \brief Classes for the SM3 hash function
+//! \details SM3 is a Chinese national hash function designed by Xiaoyun Wang, et al.
+//! \sa <A HREF="https://tools.ietf.org/html/draft-shen-sm3-hash">SM3 Hash Function</A>
+//! \since Crypto++ 6.0
+
+#ifndef CRYPTOPP_SM3_H
+#define CRYPTOPP_SM3_H
+
+#include "config.h"
+#include "iterhash.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+//! \class SM3
+//! \brief SM3 hash function
+//! \details SM3 is a Chinese national hash function designed by Xiaoyun Wang, et al.
+//! \sa <A HREF="https://tools.ietf.org/html/draft-shen-sm3-hash">SM3 Hash Function</A>
+//! \since Crypto++ 6.0
+class SM3 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SM3, 32, true>
+{
+public:
+ //! \brief Initialize state array
+ //! \param state the state of the hash
+ //! \details InitState sets a state array to SHA256 initial values
+ //! \details Hashes which derive from IteratedHashWithStaticTransform provide static
+ //! member functions InitState and Transform. External classes, like SEAL and MDC,
+ //! can initialize state with a user provided key and operate the hash on the data
+ //! with the user supplied state.
+ //! \note On Intel platforms the state array must be 16-byte aligned for SSE2.
+ static void InitState(HashWordType *state);
+
+ //! \brief Operate the hash
+ //! \param digest the state of the hash
+ //! \param data the data to be digested
+ //! \details Transform operates the hash on <tt>data</tt>. When the call is invoked
+ //! <tt>digest</tt> holds initial state. Upon return <tt>digest</tt> holds the hash
+ //! or updated state.
+ //! \details Hashes which derive from IteratedHashWithStaticTransform provide static
+ //! member functions InitState and Transform. External classes, like SEAL and MDC,
+ //! can initialize state with a user provided key and operate the hash on the data
+ //! with the user supplied state.
+ //! \note On Intel platforms the state array and data must be 16-byte aligned for SSE2.
+ static void Transform(HashWordType *digest, const HashWordType *data);
+
+ //! \brief The algorithm name
+ //! \returns C-style string "SM3"
+ CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "SM3"; }
+
+protected:
+ size_t HashMultipleBlocks(const HashWordType *input, size_t length);
+};
+
+NAMESPACE_END
+
+#endif // CRYPTOPP_SM3_H