5#ifndef DIGESTPP_PROVIDERS_ASCON_HPP
6#define DIGESTPP_PROVIDERS_ASCON_HPP
20template<ascon_type type>
69 uint64_t Z0 = Z.length() * 8;
70 update(
reinterpret_cast<const unsigned char*
>(&Z0),
sizeof(Z0));
73 update(
reinterpret_cast<const unsigned char*
>(Z.data()), Z.length());
74 size_t pad = Z.length() % 8;
75 update(
reinterpret_cast<const unsigned char*
>(&Z0), 8 - pad);
79 template<ascon_type t=type, typename std::enable_if<t == ascon_type::cxof>::type* =
nullptr>
85 inline void update(
const unsigned char* data,
size_t len)
88 [
this](
const unsigned char* data,
size_t len) { transform(data, len); });
99 memset(&m[pos], 0, r - pos);
100 transform(m.data(), 1);
101 memset(m.data(), 0, r);
106 size_t to_copy = std::min(hs, r - pos);
107 memcpy(
hash,
reinterpret_cast<unsigned char*
>(H.data()) + pos, to_copy);
108 processed += to_copy;
113 transform(m.data(), 1);
116 while (processed < hs)
119 transform(m.data(), 1);
120 pos = std::min(hs - processed, r);
121 memcpy(
hash + processed, H.data(), pos);
126 inline void final(
unsigned char*
hash)
141 inline void transform(
const unsigned char* data,
size_t num_blks)
143 for (
size_t blk = 0; blk < num_blks; blk++)
145 H[0] ^=
reinterpret_cast<const uint64_t*
>(data)[blk];
147 for (
int i = 0; i < 12; i++)
155 uint64_t t0 = H[0] ^ (~H[1] & H[2]);
156 uint64_t t1 = H[1] ^ (~H[2] & H[3]);
157 uint64_t t2 = H[2] ^ (~H[3] & H[4]);
158 uint64_t t3 = H[3] ^ (~H[4] & H[0]);
159 uint64_t t4 = H[4] ^ (~H[0] & H[1]);
176 std::array<uint64_t, 5> H;
177 std::array<unsigned char, 64> m;
179 const size_t rate = 64;
Definition ascon_provider.hpp:22
size_t hash_size() const
Definition ascon_provider.hpp:137
ascon_provider()
Definition ascon_provider.hpp:26
~ascon_provider()
Definition ascon_provider.hpp:31
void init()
Definition ascon_provider.hpp:36
void clear()
Definition ascon_provider.hpp:131
void update(const unsigned char *data, size_t len)
Definition ascon_provider.hpp:85
void set_customization(const std::string &customization)
Definition ascon_provider.hpp:80
void squeeze(unsigned char *hash, size_t hs)
Definition ascon_provider.hpp:91
uint32_t rotate_right(uint32_t x, unsigned n)
Definition functions.hpp:61
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 ascon_constants.hpp:16