~ubuntu-branches/debian/sid/bitcoin/sid

« back to all changes in this revision

Viewing changes to src/hash.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2015-07-29 15:45:52 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20150729154552-p5t8q38o0ekh1f09
Tags: 0.11.0-1
* New upstream release (Closes: #793622)
  - build on all archs, big endian is now supported
* Updated symbols file
* Added bitcoin-cli.1 manpage from contrib/debian/manpages
* Updated debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) 2013-2014 The Bitcoin developers
 
1
// Copyright (c) 2013-2014 The Bitcoin Core developers
2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
 
5
5
#include "hash.h"
 
6
#include "crypto/common.h"
6
7
#include "crypto/hmac_sha512.h"
 
8
#include "pubkey.h"
 
9
 
7
10
 
8
11
inline uint32_t ROTL32(uint32_t x, int8_t r)
9
12
{
23
26
 
24
27
        //----------
25
28
        // body
26
 
        const uint32_t* blocks = (const uint32_t*)(&vDataToHash[0] + nblocks * 4);
 
29
        const uint8_t* blocks = &vDataToHash[0] + nblocks * 4;
27
30
 
28
31
        for (int i = -nblocks; i; i++) {
29
 
            uint32_t k1 = blocks[i];
 
32
            uint32_t k1 = ReadLE32(blocks + i*4);
30
33
 
31
34
            k1 *= c1;
32
35
            k1 = ROTL32(k1, 15);
69
72
    return h1;
70
73
}
71
74
 
72
 
void BIP32Hash(const unsigned char chainCode[32], unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
 
75
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
73
76
{
74
77
    unsigned char num[4];
75
78
    num[0] = (nChild >> 24) & 0xFF;
76
79
    num[1] = (nChild >> 16) & 0xFF;
77
80
    num[2] = (nChild >>  8) & 0xFF;
78
81
    num[3] = (nChild >>  0) & 0xFF;
79
 
    CHMAC_SHA512(chainCode, 32).Write(&header, 1)
80
 
                               .Write(data, 32)
81
 
                               .Write(num, 4)
82
 
                               .Finalize(output);
 
82
    CHMAC_SHA512(chainCode.begin(), chainCode.size()).Write(&header, 1).Write(data, 32).Write(num, 4).Finalize(output);
83
83
}