| 13 | } |
| 14 | |
| 15 | unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char>& vDataToHash) |
| 16 | { |
| 17 | // The following is MurmurHash3 (x86_32), see http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp |
| 18 | uint32_t h1 = nHashSeed; |
| 19 | const uint32_t c1 = 0xcc9e2d51; |
| 20 | const uint32_t c2 = 0x1b873593; |
| 21 | |
| 22 | const int nblocks = vDataToHash.size() / 4; |
| 23 | |
| 24 | //---------- |
| 25 | // body |
| 26 | const uint8_t* blocks = vDataToHash.data(); |
| 27 | |
| 28 | for (int i = 0; i < nblocks; ++i) { |
| 29 | uint32_t k1 = ReadLE32(blocks + i*4); |
| 30 | |
| 31 | k1 *= c1; |
| 32 | k1 = ROTL32(k1, 15); |
| 33 | k1 *= c2; |
| 34 | |
| 35 | h1 ^= k1; |
| 36 | h1 = ROTL32(h1, 13); |
| 37 | h1 = h1 * 5 + 0xe6546b64; |
| 38 | } |
| 39 | |
| 40 | //---------- |
| 41 | // tail |
| 42 | const uint8_t* tail = vDataToHash.data() + nblocks * 4; |
| 43 | |
| 44 | uint32_t k1 = 0; |
| 45 | |
| 46 | switch (vDataToHash.size() & 3) { |
| 47 | case 3: |
| 48 | k1 ^= tail[2] << 16; |
| 49 | case 2: |
| 50 | k1 ^= tail[1] << 8; |
| 51 | case 1: |
| 52 | k1 ^= tail[0]; |
| 53 | k1 *= c1; |
| 54 | k1 = ROTL32(k1, 15); |
| 55 | k1 *= c2; |
| 56 | h1 ^= k1; |
| 57 | } |
| 58 | |
| 59 | //---------- |
| 60 | // finalization |
| 61 | h1 ^= vDataToHash.size(); |
| 62 | h1 ^= h1 >> 16; |
| 63 | h1 *= 0x85ebca6b; |
| 64 | h1 ^= h1 >> 13; |
| 65 | h1 *= 0xc2b2ae35; |
| 66 | h1 ^= h1 >> 16; |
| 67 | |
| 68 | return h1; |
| 69 | } |
| 70 | |
| 71 | void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]) |
| 72 | { |