fuzz coverage

Coverage Report

Created: 2026-04-24 13:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/hash.cpp
Line
Count
Source
1
// Copyright (c) 2013-present 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.
4
5
#include <hash.h>
6
#include <span.h>
7
#include <crypto/common.h>
8
#include <crypto/hmac_sha512.h>
9
10
#include <bit>
11
#include <string>
12
13
unsigned int MurmurHash3(unsigned int nHashSeed, std::span<const unsigned char> vDataToHash)
14
801M
{
15
    // The following is MurmurHash3 (x86_32), see https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
16
801M
    uint32_t h1 = nHashSeed;
17
801M
    const uint32_t c1 = 0xcc9e2d51;
18
801M
    const uint32_t c2 = 0x1b873593;
19
20
801M
    const int nblocks = vDataToHash.size() / 4;
21
22
    //----------
23
    // body
24
801M
    const uint8_t* blocks = vDataToHash.data();
25
26
7.21G
    for (int i = 0; i < nblocks; 
++i6.41G
) {
27
6.41G
        uint32_t k1 = ReadLE32(blocks + i*4);
28
29
6.41G
        k1 *= c1;
30
6.41G
        k1 = std::rotl(k1, 15);
31
6.41G
        k1 *= c2;
32
33
6.41G
        h1 ^= k1;
34
6.41G
        h1 = std::rotl(h1, 13);
35
6.41G
        h1 = h1 * 5 + 0xe6546b64;
36
6.41G
    }
37
38
    //----------
39
    // tail
40
801M
    const uint8_t* tail = vDataToHash.data() + nblocks * 4;
41
42
801M
    uint32_t k1 = 0;
43
44
801M
    switch (vDataToHash.size() & 3) {
45
0
        case 3:
46
0
            k1 ^= tail[2] << 16;
47
0
            [[fallthrough]];
48
0
        case 2:
49
0
            k1 ^= tail[1] << 8;
50
0
            [[fallthrough]];
51
0
        case 1:
52
0
            k1 ^= tail[0];
53
0
            k1 *= c1;
54
0
            k1 = std::rotl(k1, 15);
55
0
            k1 *= c2;
56
0
            h1 ^= k1;
57
801M
    }
58
59
    //----------
60
    // finalization
61
801M
    h1 ^= vDataToHash.size();
62
801M
    h1 ^= h1 >> 16;
63
801M
    h1 *= 0x85ebca6b;
64
801M
    h1 ^= h1 >> 13;
65
801M
    h1 *= 0xc2b2ae35;
66
801M
    h1 ^= h1 >> 16;
67
68
801M
    return h1;
69
801M
}
70
71
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64])
72
0
{
73
0
    unsigned char num[4];
74
0
    WriteBE32(num, nChild);
75
0
    CHMAC_SHA512(chainCode.begin(), chainCode.size()).Write(&header, 1).Write(data, 32).Write(num, 4).Finalize(output);
76
0
}
77
78
uint256 SHA256Uint256(const uint256& input)
79
3.30M
{
80
3.30M
    uint256 result;
81
3.30M
    CSHA256().Write(input.begin(), 32).Finalize(result.begin());
82
3.30M
    return result;
83
3.30M
}
84
85
HashWriter TaggedHash(const std::string& tag)
86
0
{
87
0
    HashWriter writer{};
88
0
    uint256 taghash;
89
0
    CSHA256().Write((const unsigned char*)tag.data(), tag.size()).Finalize(taghash.begin());
90
0
    writer << taghash << taghash;
91
0
    return writer;
92
0
}