24 #ifndef INC_SM3_HPP_8F10C8B6_226C_4673_BDD5_B1BA3F7C180C
25 #define INC_SM3_HPP_8F10C8B6_226C_4673_BDD5_B1BA3F7C180C
60 static constexpr
size_t SM3_DIGEST_SIZE = 32;
61 static constexpr
size_t SM3_BLOCK_SIZE = 64;
65 uint32_t digest[SM3_DIGEST_SIZE /
sizeof(uint32_t)];
66 uint32_t workspace[SM3_BLOCK_SIZE /
sizeof(uint32_t)];
67 uint32_t workspace_used;
68 uint32_t processed_high;
69 uint32_t processed_low;
72 static constexpr uint32_t SM3_PAD_SIZE = 56;
73 static constexpr uint32_t T0 = 0x79cc4519u;
74 static constexpr uint32_t T1 = 0x7a879d8au;
76 static inline uint32_t FF0(
const uint32_t x,
const uint32_t y,
const uint32_t z) {
return (( x ) ^ ( y ) ^ ( z )); }
77 static inline uint32_t FF1(
const uint32_t x,
const uint32_t y,
const uint32_t z) {
return ((( x ) & ( y )) | (( x ) & ( z )) | (( y ) & ( z ))); }
78 static inline uint32_t GG0(
const uint32_t x,
const uint32_t y,
const uint32_t z) {
return (( x ) ^ ( y ) ^ ( z )); }
79 static inline uint32_t GG1(
const uint32_t x,
const uint32_t y,
const uint32_t z) {
return ((( x ) & ( y )) | (( ~x ) & ( z ))); }
81 static inline uint32_t rotleft(
const uint32_t x,
const uint32_t y)
83 return (x << y) | (x >> (32 - (y & 0x3F)));
86 static inline uint32_t p0(
const uint32_t x)
88 return x ^ rotleft(x, 9) ^ rotleft(x, 17);
91 static inline uint32_t p1(
const uint32_t x)
93 return (x ^ rotleft(x, 15) ^ rotleft(x, 23));
96 static inline uint32_t min(
const uint32_t x,
const uint32_t y)
98 return (x > y) ? y : x;
101 static inline uint32_t swap(
const uint32_t x)
103 return ((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >> 8) | ((x & 0x0000ff00) << 8) | (x << 24);
106 static inline void addwc(uint32_t* hi, uint32_t* lo,
const uint32_t val)
112 static void transformBlock(uint32_t* digest, uint8_t* input);
113 void finalize(uint8_t* output);
146 size_t getSize()
const override {
return SM3_DIGEST_SIZE; }
154 void update(
const uint8_t* buf,
size_t len)
override;
202 return ChecksumAlgoId::SM3;
Add some utilities to Checksum class.
Computes a hash from a byte stream.
Computes a checksum from a byte stream.
Computes the SM3 hash from a byte stream.
void reset() override
Resets the SM3 hash to initial state of computation.
size_t getSize() const override
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
std::string getName() const override
Returns the name of the checksum or the hash algorithm.
static std::string getHashName()
Returns the name of the hash algorithm.
static Checksum * getNewInstance()
Gets a new instance of this class.
void update(const uint8_t *buf, size_t len) override
Updates the SM3 hash with specified array of bytes.
SM3()
Default constructor.
ChecksumAlgoId getID() const override
Returns an unique identifier for the checksum or the hash algorithm.
uint8_t * getValue(uint8_t *buffer) const override
Returns the SM3 hash value in the first 32 bytes of the given address.
ChecksumAlgoId
Ids of algorithms of checksums.