5#ifndef DIGESTPP_PROVIDERS_ESCH_HPP
6#define DIGESTPP_PROVIDERS_ESCH_HPP
20namespace esch_functions
24static inline void sparkle(std::array<uint32_t, N>& H,
int rounds,
int ns)
26 for(
int s = 0; s < ns; s++)
30 for (
int j = 0, px = 0, py = 1; j < rounds; j++, px += 2, py += 2)
45 uint32_t x = H[0] ^ H[2] ^ H[4];
46 uint32_t y = H[1] ^ H[3] ^ H[5];
55 for (
int i = 0, j = rounds; i < rounds; i+=2, j+=2)
58 H[j + 1] ^= H[i + 1] ^ x;
62 for (
int i = 0; i < rounds - 2; i++)
65 H[i] = H[i + rounds + 2];
67 H[rounds * 2 - 2] = H[rounds - 2];
68 H[rounds * 2 - 1] = H[rounds - 1];
76template<
size_t N,
bool XOF,
size_t HS = 0>
82 template<bool xof=XOF, size_t hss = HS, typename std::enable_if<!xof && hss == 0>::type* =
nullptr>
84 : hs(hashsize), squeezing(false)
86 static_assert(N == 384 || N == 512,
"Esch only supports 384 and 512 bits state size");
90 template<bool xof=XOF, size_t hss = HS, typename std::enable_if<!xof && hss != 0>::type* =
nullptr>
92 : hs(hss), squeezing(false)
94 static_assert(N == 384 || N == 512,
"Esch only supports 384 and 512 bits state size");
95 static_assert(hss == 256 || hss == 384,
"Esch only supports output size of 256 and 384 bits");
98 template<bool xof=XOF, typename std::enable_if<xof>::type* =
nullptr>
101 static_assert(N == 384 || N == 512,
"Esch only supports 384 and 512 bits state size");
118 inline void update(
const unsigned char* data,
size_t len)
121 [
this](
const unsigned char* data,
size_t len) { transform(data, len, false); });
126 size_t processed = 0;
133 memset(&m[pos], 0, 16 - pos);
135 H[(hs+128)/64 - 1] ^= (XOF ? 0x5000000 : 0x1000000);
138 H[(hs+128)/64 - 1] ^= (XOF ? 0x6000000 : 0x2000000);
140 transform(m.data(), 1,
true);
144 size_t to_copy = std::min(hss, 16 - pos);
145 memcpy(
hash,
reinterpret_cast<unsigned char*
>(H.data()) + pos, to_copy);
146 processed += to_copy;
151 while (processed < hss)
155 pos = std::min(hss - processed,
static_cast<size_t>(16));
156 memcpy(
hash + processed, H.data(), pos);
162 inline void final(
unsigned char*
hash)
177 inline void transform(
const unsigned char* data,
size_t num_blks,
bool lastBlock)
179 for (
size_t blk = 0; blk < num_blks; blk++)
182 for (
int i = 0; i < 4; i++)
183 M[i] =
reinterpret_cast<const uint32_t*
>(data)[blk * 4 + i];
184 uint32_t x = M[0] ^ M[2];
185 uint32_t y = M[1] ^ M[3];
188 H[0] = H[0] ^ M[0] ^ y;
189 H[1] = H[1] ^ M[1] ^ x;
190 H[2] = H[2] ^ M[2] ^ y;
191 H[3] = H[3] ^ M[3] ^ x;
199 int steps = lastBlock ? 11 : 7;
207 std::array<uint32_t, N / 32> H;
208 std::array<unsigned char, 128> m;
Definition esch_provider.hpp:78
void init()
Definition esch_provider.hpp:109
void squeeze(unsigned char *hash, size_t hss)
Definition esch_provider.hpp:124
void update(const unsigned char *data, size_t len)
Definition esch_provider.hpp:118
void clear()
Definition esch_provider.hpp:167
esch_provider()
Definition esch_provider.hpp:99
size_t hash_size() const
Definition esch_provider.hpp:173
esch_provider(size_t hashsize)
Definition esch_provider.hpp:83
esch_provider()
Definition esch_provider.hpp:91
~esch_provider()
Definition esch_provider.hpp:104
static void sparkle(std::array< uint32_t, N > &H, int rounds, int ns)
Definition esch_provider.hpp:24
uint32_t rotate_right(uint32_t x, unsigned n)
Definition functions.hpp:61
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 esch_constants.hpp:16