5#ifndef DIGESTPP_PROVIDERS_SHAKE_HPP
6#define DIGESTPP_PROVIDERS_SHAKE_HPP
19namespace shake_functions
21 static inline size_t left_encode(
size_t num,
unsigned char* buf)
29 size_t result = n + 1;
32 buf[n--] =
static_cast<unsigned char>(num >> (8*i++));
39 unsigned char n =
k12 ? num ? 1 : 0 : 1;
44 size_t result = n + 1;
47 buf[n] =
static_cast<unsigned char>(num >> (8*i++));
54template<
size_t B,
int R>
62 static_assert(B == 128 || B == 256,
"SHAKE only supports 128 and 256 bits");
88 if (!N.empty() || !S.empty())
90 unsigned char buf[1024];
99 update(
reinterpret_cast<const unsigned char*
>(N.data()), N.length());
104 update(
reinterpret_cast<const unsigned char*
>(S.data()), S.length());
105 total += S.length() + N.length();
107 len = r - (total % r);
113 inline void update(
const unsigned char* data,
size_t len)
116 [
this](
const unsigned char* data,
size_t len) { sha3_functions::transform<R>(data, len, A.data(), rate); });
127 size_t processed = 0;
130 m[pos++] = suffix ? suffix : N.empty() && S.empty() ? 0x1F : 0x04;
132 memset(&m[pos], 0, r - pos);
139 size_t to_copy = std::min(hs, r - pos);
140 memcpy(
hash,
reinterpret_cast<unsigned char*
>(A.data()) + pos, to_copy);
141 processed += to_copy;
148 while (processed < hs)
152 pos = std::min(hs - processed, r);
153 memcpy(
hash + processed, A.data(), pos);
169 std::array<uint64_t, 25> A;
170 std::array<unsigned char, 168> m;
173 const size_t rate = B == 128 ? 1344 : 1088;
177 unsigned char suffix;
Definition shake_provider.hpp:56
void update(const unsigned char *data, size_t len)
Definition shake_provider.hpp:113
void squeeze(unsigned char *hash, size_t hs)
Definition shake_provider.hpp:124
void clear()
Definition shake_provider.hpp:158
shake_provider()
Definition shake_provider.hpp:60
~shake_provider()
Definition shake_provider.hpp:65
void set_function_name(const std::string &function_name)
Definition shake_provider.hpp:70
void set_suffix(unsigned char s)
Definition shake_provider.hpp:119
void set_customization(const std::string &customization)
Definition shake_provider.hpp:75
void init()
Definition shake_provider.hpp:80
Main class template implementing the public API for hashing.
Definition hasher.hpp:38
static void transform(uint64_t *A)
Definition sha3_provider.hpp:23
static size_t left_encode(size_t num, unsigned char *buf)
Definition shake_provider.hpp:21
static size_t right_encode(size_t num, unsigned char *buf, bool k12)
Definition shake_provider.hpp:36
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