5 #include <llvm/Support/Debug.h> 7 #include "BuildInfo.gen.h" 14 #if !defined(NDEBUG) // Debug 18 static std::ostream nullStream{
nullptr};
20 return (llvm::DebugFlag && llvm::isCurrentDebugType(_channel)) ? std::cerr : nullStream;
22 return (
void)_channel, nullStream;
43 static const uint8_t
rho[24] = \
44 { 1, 3, 6, 10, 15, 21,
45 28, 36, 45, 55, 2, 14,
46 27, 41, 56, 8, 25, 43,
47 62, 18, 39, 61, 20, 44};
48 static const uint8_t pi[24] = \
49 {10, 7, 11, 17, 18, 3,
51 15, 23, 19, 13, 12, 2,
53 static const uint64_t RC[24] = \
54 {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL,
55 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL,
56 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL,
57 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL,
58 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL,
59 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL};
62 #define rol(x, s) (((x) << s) | ((x) >> (64 - s))) 63 #define REPEAT6(e) e e e e e e 64 #define REPEAT24(e) REPEAT6(e e e e) 65 #define REPEAT5(e) e e e e e 66 #define FOR5(v, s, e) \ 68 REPEAT5(e; v = decltype(v)(v + s);) 71 static inline void keccakf(
void* state) {
72 uint64_t*
a = (uint64_t*)state;
77 for (
int i = 0; i < 24; i++) {
85 a[y + x] ^= b[(x + 4) % 5] ^
rol(b[(x + 1) % 5], 1); ))
90 a[pi[
x]] =
rol(t, rho[x]);
99 a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); ))
109 #define _(S) do { S } while (0) 110 #define FOR(i, ST, L, S) \ 111 _(for (size_t i = 0; i < L; i += ST) { S; }) 112 #define mkapply_ds(NAME, S) \ 113 static inline void NAME(uint8_t* dst, \ 114 const uint8_t* src, \ 118 #define mkapply_sd(NAME, S) \ 119 static inline void NAME(const uint8_t* src, \ 132 #define foldP(I, L, F) \ 133 while (L >= rate) { \ 141 static inline int hash(uint8_t* out,
size_t outlen,
142 const uint8_t* in,
size_t inlen,
143 size_t rate, uint8_t delim) {
144 if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >=
Plen)) {
147 uint8_t
a[
Plen] = {0};
149 foldP(in, inlen, xorin);
158 foldP(out, outlen, setout);
159 setout(a, out, outlen);
165 #define defkeccak(bits) \ 166 static int keccak_##bits(uint8_t* out, size_t outlen, \ 167 const uint8_t* in, size_t inlen) { \ 168 if (outlen > (bits/8)) { \ 171 return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \ 178 void keccak(uint8_t
const* _data, uint64_t _size, uint8_t* o_hash)
180 keccak_256(o_hash, 32, _data, _size);
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
void keccak(uint8_t const *_data, uint64_t _size, uint8_t *o_hash)
#define mkapply_sd(NAME, S)
#define mkapply_ds(NAME, S)
std::ostream & getLogStream(char const *_channel)