Coverage Report

Created: 2026-08-25 19:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/crypto/siphash.cpp
Line
Count
Source
1
// Copyright (c) 2016-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 <crypto/siphash.h>
6
7
#include <uint256.h>
8
9
#include <cassert>
10
#include <span>
11
12
180M
CSipHasher::CSipHasher(uint64_t k0, uint64_t k1) : m_state{k0, k1} {}
13
14
CSipHasher& CSipHasher::Write(uint64_t data)
15
461M
{
16
461M
    assert(m_count % 8 == 0);
  Branch (16:5): [True: 461M, False: 0]
17
461M
    m_state.Compress2(data);
18
461M
    m_count += 8;
19
461M
    return *this;
20
461M
}
21
22
CSipHasher& CSipHasher::Write(std::span<const unsigned char> data)
23
199M
{
24
199M
    SipHashState state{m_state.Copy()};
25
199M
    uint64_t t{m_tmp};
26
199M
    uint8_t c{m_count};
27
28
4.79G
    while (data.size() > 0) {
  Branch (28:12): [True: 4.59G, False: 199M]
29
4.59G
        t |= uint64_t{data.front()} << (8 * (c % 8));
30
4.59G
        c++;
31
4.59G
        if ((c & 7) == 0) {
  Branch (31:13): [True: 557M, False: 4.03G]
32
557M
            state.Compress2(t);
33
557M
            t = 0;
34
557M
        }
35
4.59G
        data = data.subspan(1);
36
4.59G
    }
37
38
199M
    m_state = state;
39
199M
    m_count = c;
40
199M
    m_tmp = t;
41
42
199M
    return *this;
43
199M
}
44
45
uint64_t CSipHasher::Finalize() const
46
180M
{
47
180M
    return m_state.Copy()
48
180M
                  .Compress2(m_tmp | (uint64_t{m_count} << 56))
49
180M
                  .Finalize4();
50
180M
}
51
52
SipHasher13UJ& SipHasher13UJ::Write(uint64_t data) noexcept
53
2.71k
{
54
2.71k
    m_state.Compress1(data);
55
2.71k
    return *this;
56
2.71k
}
57
58
SipHasher13UJ& SipHasher13UJ::WriteJumbo(const uint256& hash) noexcept
59
1.92k
{
60
1.92k
    m_state.Compress1Jumbo(hash);
61
1.92k
    return *this;
62
1.92k
}
63
64
uint64_t SipHasher13UJ::Finalize() const noexcept
65
2.32k
{
66
2.32k
    return m_state.Copy().Finalize3U();
67
2.32k
}
68
69
uint64_t PresaltedSipHasher::operator()(const uint256& val) const noexcept
70
177M
{
71
177M
    return m_state.Copy()
72
177M
                  .Compress2(val.GetUint64(0))
73
177M
                  .Compress2(val.GetUint64(1))
74
177M
                  .Compress2(val.GetUint64(2))
75
177M
                  .Compress2(val.GetUint64(3))
76
177M
                  .Compress2(uint64_t{32} << 56)
77
177M
                  .Finalize4();
78
177M
}
79
80
uint64_t PresaltedSipHasher::operator()(const uint256& val, uint32_t extra) const noexcept
81
419M
{
82
419M
    return m_state.Copy()
83
419M
                  .Compress2(val.GetUint64(0))
84
419M
                  .Compress2(val.GetUint64(1))
85
419M
                  .Compress2(val.GetUint64(2))
86
419M
                  .Compress2(val.GetUint64(3))
87
419M
                  .Compress2((uint64_t{36} << 56) | extra)
88
419M
                  .Finalize4();
89
419M
}