5#ifndef DIGESTPP_PROVIDERS_STREEBOG_HPP
6#define DIGESTPP_PROVIDERS_STREEBOG_HPP
20namespace streebog_functions
23 static inline uint64_t
lps(
unsigned char* ch)
38 memcpy(ch, block, 64);
50 static inline void xor_blocks(uint64_t* block,
const uint64_t* toxor)
62 static inline void e(uint64_t* K,
const unsigned char* m)
66 xor_blocks(K,
reinterpret_cast<const uint64_t*
>(m));
67 for (
int i = 0; i < 12; i++)
76 static inline void gN(uint64_t* h,
const unsigned char* m, uint64_t N)
84 xor_blocks(h,
reinterpret_cast<const uint64_t*
>(m));
87 static inline void addm(
const unsigned char* m, uint64_t* h)
89 const uint64_t* m64 =
reinterpret_cast<const uint64_t*
>(m);
90 bool carry =
false, overflow =
false;
91 for (
int i = 0; i < 8; i++)
93 uint64_t t = h[i] + m64[i];
94 overflow = t < h[i] || t < m64[i];
102template<
size_t HS = 0>
108 template<size_t hss=HS, typename std::enable_if<hss == 0>::type* =
nullptr>
115 template<size_t hss=HS, typename std::enable_if<hss != 0>::type* =
nullptr>
119 static_assert(hss == 256 || hss == 512);
131 memset(&h[0], hs == 512 ? 0 : 1,
sizeof(uint64_t) * 8);
132 memset(&S[0], 0,
sizeof(uint64_t) * 8);
135 inline void update(
const unsigned char* data,
size_t len)
138 [
this](
const unsigned char* data,
size_t len) { transform(data, len, false); });
141 inline void final(
unsigned char*
hash)
145 memset(&m[pos], 0, 64 - pos);
146 transform(&m[0], 1,
false);
147 total += (pos - 1) * 8;
149 memcpy(&m[0], &total,
sizeof(total));
150 memset(&m[
sizeof(total)], 0, 64 -
sizeof(total));
151 transform(&m[0], 1,
true);
152 transform(
reinterpret_cast<const unsigned char*
>(&S[0]), 1,
true);
167 inline void transform(
const unsigned char* mp,
size_t num_blks,
bool final)
169 for (
size_t blk = 0; blk < num_blks; blk++)
178 std::array<uint64_t, 8> h;
179 std::array<uint64_t, 8> S;
180 std::array<unsigned char, 64> m;
Definition streebog_provider.hpp:104
void update(const unsigned char *data, size_t len)
Definition streebog_provider.hpp:135
size_t hash_size() const
Definition streebog_provider.hpp:164
streebog_provider()
Definition streebog_provider.hpp:116
streebog_provider(size_t hashsize)
Definition streebog_provider.hpp:109
void init()
Definition streebog_provider.hpp:127
~streebog_provider()
Definition streebog_provider.hpp:122
void clear()
Definition streebog_provider.hpp:157
static void addm(const unsigned char *m, uint64_t *h)
Definition streebog_provider.hpp:87
static void e(uint64_t *K, const unsigned char *m)
Definition streebog_provider.hpp:62
static uint64_t lps(unsigned char *ch)
Definition streebog_provider.hpp:23
static void lps_block(uint64_t *block)
Definition streebog_provider.hpp:35
static void xor_blocks(uint64_t *block, const uint64_t *toxor)
Definition streebog_provider.hpp:50
static void gN(uint64_t *h, const unsigned char *m, uint64_t N)
Definition streebog_provider.hpp:76
void validate_hash_size(size_t hs, std::initializer_list< size_t > set)
Definition validate_hash_size.hpp:14
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
Definition streebog_constants.hpp:16