50 #define decshake(bits) \ 51 int shake##bits(uint8_t*, size_t, const uint8_t*, size_t); 53 #define decsha3(bits) \ 54 int sha3_##bits(uint8_t*, size_t, const uint8_t*, size_t); 66 static const uint8_t
rho[24] = \
67 { 1, 3, 6, 10, 15, 21,
68 28, 36, 45, 55, 2, 14,
69 27, 41, 56, 8, 25, 43,
70 62, 18, 39, 61, 20, 44};
71 static const uint8_t pi[24] = \
72 {10, 7, 11, 17, 18, 3,
74 15, 23, 19, 13, 12, 2,
76 static const uint64_t RC[24] = \
77 {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL,
78 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL,
79 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL,
80 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL,
81 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL,
82 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL};
85 #define rol(x, s) (((x) << s) | ((x) >> (64 - s))) 86 #define REPEAT6(e) e e e e e e 87 #define REPEAT24(e) REPEAT6(e e e e) 88 #define REPEAT5(e) e e e e e 89 #define FOR5(v, s, e) \ 94 static inline void keccakf(
void* state) {
95 uint64_t*
a = (uint64_t*)state;
100 for (
int i = 0; i < 24; i++) {
108 a[y + x] ^= b[(x + 4) % 5] ^
rol(b[(x + 1) % 5], 1); ))
122 a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); ))
132 #define _(S) do { S } while (0) 133 #define FOR(i, ST, L, S) \ 134 _(for (size_t i = 0; i < L; i += ST) { S; }) 135 #define mkapply_ds(NAME, S) \ 136 static inline void NAME(uint8_t* dst, \ 137 const uint8_t* src, \ 141 #define mkapply_sd(NAME, S) \ 142 static inline void NAME(const uint8_t* src, \ 155 #define foldP(I, L, F) \ 156 while (L >= rate) { \ 164 static inline int hash(uint8_t* out,
size_t outlen,
165 const uint8_t* in,
size_t inlen,
166 size_t rate, uint8_t delim) {
167 if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >=
Plen)) {
170 uint8_t
a[
Plen] = {0};
172 foldP(in, inlen, xorin);
181 foldP(out, outlen, setout);
182 setout(a, out, outlen);
188 #define defshake(bits) \ 189 int shake##bits(uint8_t* out, size_t outlen, \ 190 const uint8_t* in, size_t inlen) { \ 191 return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x1f); \ 193 #define defsha3(bits) \ 194 int sha3_##bits(uint8_t* out, size_t outlen, \ 195 const uint8_t* in, size_t inlen) { \ 196 if (outlen > (bits/8)) { \ 199 return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \ 217 if (o_output.
size() != 32)
219 keccak::sha3_256(o_output.
data(), 32, _input.
data(), _input.
size());
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
A modifiable reference to an existing object or vector in memory.
void keccak(uint8_t const *_data, uint64_t _size, uint8_t *o_hash)
std::hash for asio::adress
#define mkapply_sd(NAME, S)
#define decshake(bits)
libkeccak-tiny
vector_ref< byte const > bytesConstRef
bytes rlpList()
Export a list of items in RLP format, returning a byte array.
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
#define mkapply_ds(NAME, S)