1 // Copyright (c) 2013-2014 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "crypto/common.h"
7 #include "crypto/hmac_sha512.h"
11 inline uint32_t ROTL32(uint32_t x, int8_t r)
13 return (x << r) | (x >> (32 - r));
16 unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char>& vDataToHash)
18 // The following is MurmurHash3 (x86_32), see http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp
19 uint32_t h1 = nHashSeed;
20 if (vDataToHash.size() > 0)
22 const uint32_t c1 = 0xcc9e2d51;
23 const uint32_t c2 = 0x1b873593;
25 const int nblocks = vDataToHash.size() / 4;
29 const uint8_t* blocks = &vDataToHash[0] + nblocks * 4;
31 for (int i = -nblocks; i; i++) {
32 uint32_t k1 = ReadLE32(blocks + i*4);
40 h1 = h1 * 5 + 0xe6546b64;
45 const uint8_t* tail = (const uint8_t*)(&vDataToHash[0] + nblocks * 4);
49 switch (vDataToHash.size() & 3) {
65 h1 ^= vDataToHash.size();
75 void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
78 num[0] = (nChild >> 24) & 0xFF;
79 num[1] = (nChild >> 16) & 0xFF;
80 num[2] = (nChild >> 8) & 0xFF;
81 num[3] = (nChild >> 0) & 0xFF;
82 CHMAC_SHA512(chainCode.begin(), chainCode.size()).Write(&header, 1).Write(data, 32).Write(num, 4).Finalize(output);