5#ifndef DIGESTPP_PROVIDERS_SM3_HPP
6#define DIGESTPP_PROVIDERS_SM3_HPP
18namespace sm3_functions
20 static inline uint32_t
xorf(uint32_t x, uint32_t y, uint32_t z)
25 static inline uint32_t
ff1(uint32_t x, uint32_t y, uint32_t z)
27 return (x & y) ^ (x & z) ^ (y & z);
30 static inline uint32_t
gg1(uint32_t x, uint32_t y, uint32_t z)
32 return (x & y) ^ (~x & z);
35 static inline uint32_t
p0(uint32_t x)
40 static inline uint32_t
p1(uint32_t x)
74 inline void update(
const unsigned char* data,
size_t len)
77 [
this](
const unsigned char* data,
size_t len) { transform(data, len); });
80 inline void final(
unsigned char*
hash)
87 memset(&m[pos], 0, 64 - pos);
88 transform(m.data(), 1);
91 memset(&m[pos], 0, 56 - pos);
93 memcpy(&m[64 - 8], &mlen, 64 / 8);
94 transform(m.data(), 1);
95 for (
int i = 0; i < 8; i++)
97 memcpy(
hash, H.data(), 32);
109 inline void transform(
const unsigned char* data,
size_t num_blks)
111 for (uint64_t blk = 0; blk < num_blks; blk++)
114 for (uint32_t i = 0; i < 64 / 4; i++)
115 M[i] =
byteswap(
reinterpret_cast<const uint32_t*
>(data)[blk * 16 + i]);
119 for (
int t = 0; t <= 15; t++)
121 for (
int t = 16; t <= 67; t++)
123 for (
int t = 0; t <= 63; t++)
124 W2[t] = W[t] ^ W[t + 4];
135 for (
int t = 0; t <= 15; t++)
151 for (
int t = 16; t <= 63; t++)
178 std::array<uint32_t, 8> H;
179 std::array<unsigned char, 64> m;
Definition sm3_provider.hpp:47
void init()
Definition sm3_provider.hpp:60
size_t hash_size() const
Definition sm3_provider.hpp:106
void update(const unsigned char *data, size_t len)
Definition sm3_provider.hpp:74
void clear()
Definition sm3_provider.hpp:100
~sm3_provider()
Definition sm3_provider.hpp:55
sm3_provider()
Definition sm3_provider.hpp:51
static uint32_t p1(uint32_t x)
Definition sm3_provider.hpp:40
static uint32_t xorf(uint32_t x, uint32_t y, uint32_t z)
Definition sm3_provider.hpp:20
static uint32_t gg1(uint32_t x, uint32_t y, uint32_t z)
Definition sm3_provider.hpp:30
static uint32_t ff1(uint32_t x, uint32_t y, uint32_t z)
Definition sm3_provider.hpp:25
static uint32_t p0(uint32_t x)
Definition sm3_provider.hpp:35
uint16_t byteswap(uint16_t val)
Definition functions.hpp:16
uint32_t rotate_left(uint32_t x, unsigned n)
Definition functions.hpp:67
void zero_memory(void *v, size_t n)
Definition functions.hpp:85
void absorb_bytes(const unsigned char *data, size_t len, size_t bs, size_t bschk, unsigned char *m, size_t &pos, T &total, TF transform)
Definition absorb_data.hpp:16
digestpp namespace
Definition ascon.hpp:14