18#define __builtin_memcpy memcpy
23#define __LITTLE_ENDIAN 1234
24#define __BIG_ENDIAN 4321
25#define __BYTE_ORDER __LITTLE_ENDIAN
27#include <machine/endian.h>
32#if __BYTE_ORDER == __LITTLE_ENDIAN
35#define to_le64(X) __builtin_bswap64(X)
38#if __BYTE_ORDER == __LITTLE_ENDIAN
39#define to_be64(X) __builtin_bswap64(X)
45static inline uint64_t load_le(
const uint8_t*
data)
53 __builtin_memcpy(&word,
data,
sizeof(word));
57static inline void keccak(uint64_t* out,
size_t bits,
const uint8_t*
data,
size_t size)
59 static const size_t word_size =
sizeof(uint64_t);
60 const size_t hash_size = bits / 8;
61 const size_t block_size = (1600 - bits * 2) / 8;
65 uint64_t last_word = 0;
66 uint8_t* last_word_iter = (uint8_t*)&last_word;
70 while (size >= block_size) {
71 for (i = 0; i < (block_size / word_size); ++i) {
72 state[i] ^= load_le(
data);
83 while (size >= word_size) {
84 *state_iter ^= load_le(
data);
91 *last_word_iter = *
data;
96 *last_word_iter = 0x01;
97 *state_iter ^=
to_le64(last_word);
99 state[(block_size / word_size) - 1] ^= 0x8000000000000000;
103 for (i = 0; i < (hash_size / word_size); ++i)
const std::vector< MemoryValue > data
struct keccak256 ethash_keccak256(const uint8_t *data, size_t size) NOEXCEPT
void ethash_keccakf1600(uint64_t state[KECCAKF1600_LANES]) NOEXCEPT
uint64_t word64s[KECCAK256_OUTPUT_WORDS]