Crypto++ 8.7
Free C++ class library of cryptographic schemes
sm3.h
Go to the documentation of this file.
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
6/// \file sm3.h
7/// \brief Classes for the SM3 hash function
8/// \details SM3 is a hash function designed by Xiaoyun Wang, et al. The hash is part of the
9/// Chinese State Cryptography Administration portfolio.
10/// \sa <A HREF="https://tools.ietf.org/html/draft-shen-sm3-hash">SM3 Hash Function</A> and
11/// <A HREF="http://github.com/guanzhi/GmSSL">Reference implementation using OpenSSL</A>.
12/// \since Crypto++ 6.0
13
14#ifndef CRYPTOPP_SM3_H
15#define CRYPTOPP_SM3_H
16
17#include "config.h"
18#include "iterhash.h"
19
20NAMESPACE_BEGIN(CryptoPP)
21
22/// \brief SM3 hash function
23/// \details SM3 is a hash function designed by Xiaoyun Wang, et al. The hash is part of the
24/// Chinese State Cryptography Administration portfolio.
25/// \sa <A HREF="https://tools.ietf.org/html/draft-shen-sm3-hash">SM3 Hash Function</A>
26/// \since Crypto++ 6.0
27class SM3 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SM3, 32, true>
28{
29public:
30 /// \brief Initialize state array
31 /// \param state the state of the hash
32 /// \details InitState sets a state array to SM3 initial values
33 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static
34 /// member functions InitState() and Transform(). External classes, like SEAL and MDC,
35 /// can initialize state with a user provided key and operate the hash on the data
36 /// with the user supplied state.
37 static void InitState(HashWordType *state);
38
39 /// \brief Operate the hash
40 /// \param digest the state of the hash
41 /// \param data the data to be digested
42 /// \details Transform() operates the hash on <tt>data</tt>. When the call is invoked
43 /// <tt>digest</tt> holds initial or current state. Upon return <tt>digest</tt> holds
44 /// the hash or updated state.
45 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static
46 /// member functions InitState() and Transform(). External classes, like SEAL and MDC,
47 /// can initialize state with a user provided key and operate the hash on the data
48 /// with the user supplied state.
49 static void Transform(HashWordType *digest, const HashWordType *data);
50
51 /// \brief The algorithm name
52 /// \return C-style string "SM3"
53 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "SM3"; }
54
55protected:
56 size_t HashMultipleBlocks(const HashWordType *input, size_t length);
57};
58
59NAMESPACE_END
60
61#endif // CRYPTOPP_SM3_H
Iterated hash with a static transformation function.
Definition: iterhash.h:182
SM3 hash function.
Definition: sm3.h:28
Library configuration file.
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
Base classes for iterated hashes.
Crypto++ library namespace.
Converts an enumeration to a type suitable for use as a template parameter.
Definition: cryptlib.h:136