15 inline uint32_t
ROTL32(uint32_t x, int8_t r)
17 return (x << r) | (x >> (32 - r));
20 unsigned int MurmurHash3(
unsigned int nHashSeed,
const std::vector<unsigned char>& vDataToHash)
23 uint32_t h1 = nHashSeed;
24 const uint32_t c1 = 0xcc9e2d51;
25 const uint32_t c2 = 0x1b873593;
27 const int nblocks = vDataToHash.size() / 4;
31 const uint8_t* blocks = vDataToHash.data();
33 for (
int i = 0; i < nblocks; ++i) {
34 uint32_t k1 = ReadLE32(blocks + i*4);
42 h1 = h1 * 5 + 0xe6546b64;
47 const uint8_t* tail = vDataToHash.data() + nblocks * 4;
51 switch (vDataToHash.size() & 3) {
66 h1 ^= vDataToHash.size();
76 void BIP32Hash(
const ChainCode &chainCode,
unsigned int nChild,
unsigned char header,
const unsigned char data[32],
unsigned char output[64])
79 num[0] = (nChild >> 24) & 0xFF;
80 num[1] = (nChild >> 16) & 0xFF;
81 num[2] = (nChild >> 8) & 0xFF;
82 num[3] = (nChild >> 0) & 0xFF;
86 #define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b)))) 88 #define SIPROUND do { \ 89 v0 += v1; v1 = ROTL(v1, 13); v1 ^= v0; \ 91 v2 += v3; v3 = ROTL(v3, 16); v3 ^= v2; \ 92 v0 += v3; v3 = ROTL(v3, 21); v3 ^= v0; \ 93 v2 += v1; v1 = ROTL(v1, 17); v1 ^= v2; \ 99 v[0] = 0x736f6d6570736575ULL ^ k0;
100 v[1] = 0x646f72616e646f6dULL ^ k1;
101 v[2] = 0x6c7967656e657261ULL ^ k0;
102 v[3] = 0x7465646279746573ULL ^ k1;
109 uint64_t v0 =
v[0], v1 =
v[1], v2 =
v[2], v3 =
v[3];
111 assert(
count % 8 == 0);
129 uint64_t v0 =
v[0], v1 =
v[1], v2 =
v[2], v3 =
v[3];
134 t |= ((uint64_t)(*(data++))) << (8 * (c % 8));
157 uint64_t v0 =
v[0], v1 =
v[1], v2 =
v[2], v3 =
v[3];
159 uint64_t t =
tmp | (((uint64_t)
count) << 56);
170 return v0 ^ v1 ^ v2 ^ v3;
178 uint64_t v0 = 0x736f6d6570736575ULL ^ k0;
179 uint64_t v1 = 0x646f72616e646f6dULL ^ k1;
180 uint64_t v2 = 0x6c7967656e657261ULL ^ k0;
181 uint64_t v3 = 0x7465646279746573ULL ^ k1 ^ d;
201 v3 ^= ((uint64_t)4) << 59;
204 v0 ^= ((uint64_t)4) << 59;
210 return v0 ^ v1 ^ v2 ^ v3;
218 uint64_t v0 = 0x736f6d6570736575ULL ^ k0;
219 uint64_t v1 = 0x646f72616e646f6dULL ^ k1;
220 uint64_t v2 = 0x6c7967656e657261ULL ^ k0;
221 uint64_t v3 = 0x7465646279746573ULL ^ k1 ^ d;
241 d = (((uint64_t)36) << 56) | extra;
251 return v0 ^ v1 ^ v2 ^ v3;
void Finalize(unsigned char hash[OUTPUT_SIZE])
CHMAC_SHA512 & Write(const unsigned char *data, size_t len)
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data It is treated as if this was the little-endian interpretation of ...
CSipHasher(uint64_t k0, uint64_t k1)
Construct a SipHash calculator initialized with 128-bit key (k0, k1)
unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector< unsigned char > &vDataToHash)
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
unsigned int size() const
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
uint64_t GetUint64(int pos) const
uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256 &val, uint32_t extra)
uint32_t ROTL32(uint32_t x, int8_t r)
A hasher class for HMAC-SHA-512.