23static const uint64_t blake2b_IV[8] = {0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,
24 0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
25 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL};
27static const uint8_t blake2b_sigma[12][16] = {
28 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
29 {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
30 {9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13}, {2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
31 {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11}, {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
32 {6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5}, {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
33 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}};
35static inline uint64_t load64(
const void *src) {
41static inline uint64_t rotr64(
const uint64_t w,
const unsigned c) {
return (w >> c) | (w << (64 - c)); }
45 a =
a + b + m[blake2b_sigma[
r][2 * i + 0]];
46 d = rotr64(d ^
a, 32);
48 b = rotr64(b ^ c, 24);
49 a =
a + b + m[blake2b_sigma[
r][2 * i + 1]];
50 d = rotr64(d ^
a, 16);
52 b = rotr64(b ^ c, 63);
55inline void blake2b_wrapper::ROUND(
uint8_t r)
noexcept
57 G(
r, 0, v[0], v[4], v[8], v[12]);
58 G(
r, 1, v[1], v[5], v[9], v[13]);
59 G(
r, 2, v[2], v[6], v[10], v[14]);
60 G(
r, 3, v[3], v[7], v[11], v[15]);
61 G(
r, 4, v[0], v[5], v[10], v[15]);
62 G(
r, 5, v[1], v[6], v[11], v[12]);
63 G(
r, 6, v[2], v[7], v[8], v[13]);
64 G(
r, 7, v[3], v[4], v[9], v[14]);
68 blake2b_compress_init(
S, block,
r);
70 for (i = 0; i <
r; ++i) {
77 blake2b_compress_end(
S);
80void blake2b_wrapper::blake2b_compress_init(
blake2b_state *
S,
const uint8_t block[BLAKE2B_BLOCKBYTES],
size_t r) {
81 for (i = 0; i < 16; ++i) {
82 m[i] = load64(block + i *
sizeof(m[i]));
85 for (i = 0; i < 8; ++i) {
91 v[10] = blake2b_IV[2];
92 v[11] = blake2b_IV[3];
93 v[12] = blake2b_IV[4] ^
S->t[0];
94 v[13] = blake2b_IV[5] ^
S->t[1];
95 v[14] = blake2b_IV[6] ^
S->
f[0];
96 v[15] = blake2b_IV[7];
99void blake2b_wrapper::blake2b_compress_end(blake2b_state *
S) {
100 for (i = 0; i < 8; ++i) {
101 S->h[i] =
S->h[i] ^ v[i] ^ v[i + 8];
120 state.f[0] = _f ? std::numeric_limits<uint64_t>::max() : 0;
void blake2b_compress(blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES], size_t r, const yield_function_t &yield)
std::vector< char > bytes
std::variant< blake2b_error, bytes > blake2b(uint32_t _rounds, const bytes &_h, const bytes &_m, const bytes &_t0_offset, const bytes &_t1_offset, bool _f, const yield_function_t &yield)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
unsigned __int64 uint64_t
memcpy((char *) pInfo->slotDescription, s, l)