fuzz coverage

Coverage Report

Created: 2025-08-28 15:26

/Users/eugenesiegel/btc/bitcoin/src/crypto/common.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2014-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
#ifndef BITCOIN_CRYPTO_COMMON_H
6
#define BITCOIN_CRYPTO_COMMON_H
7
8
#include <compat/endian.h>
9
10
#include <concepts>
11
#include <cstddef>
12
#include <cstdint>
13
#include <cstring>
14
15
template <typename B>
16
concept ByteType = std::same_as<B, unsigned char> || std::same_as<B, std::byte>;
17
18
template <ByteType B>
19
inline uint16_t ReadLE16(const B* ptr)
20
0
{
21
0
    uint16_t x;
22
0
    memcpy(&x, ptr, 2);
23
0
    return le16toh_internal(x);
24
0
}
25
26
template <ByteType B>
27
inline uint32_t ReadLE32(const B* ptr)
28
25.3M
{
29
25.3M
    uint32_t x;
30
25.3M
    memcpy(&x, ptr, 4);
31
25.3M
    return le32toh_internal(x);
32
25.3M
}
_Z8ReadLE32ITk8ByteTypehEjPKT_
Line
Count
Source
28
17.7M
{
29
17.7M
    uint32_t x;
30
17.7M
    memcpy(&x, ptr, 4);
31
17.7M
    return le32toh_internal(x);
32
17.7M
}
_Z8ReadLE32ITk8ByteTypeSt4byteEjPKT_
Line
Count
Source
28
7.63M
{
29
7.63M
    uint32_t x;
30
7.63M
    memcpy(&x, ptr, 4);
31
7.63M
    return le32toh_internal(x);
32
7.63M
}
33
34
template <ByteType B>
35
inline uint64_t ReadLE64(const B* ptr)
36
11.7M
{
37
11.7M
    uint64_t x;
38
11.7M
    memcpy(&x, ptr, 8);
39
11.7M
    return le64toh_internal(x);
40
11.7M
}
_Z8ReadLE64ITk8ByteTypehEyPKT_
Line
Count
Source
36
11.3M
{
37
11.3M
    uint64_t x;
38
11.3M
    memcpy(&x, ptr, 8);
39
11.3M
    return le64toh_internal(x);
40
11.3M
}
_Z8ReadLE64ITk8ByteTypeSt4byteEyPKT_
Line
Count
Source
36
403k
{
37
403k
    uint64_t x;
38
403k
    memcpy(&x, ptr, 8);
39
403k
    return le64toh_internal(x);
40
403k
}
41
42
template <ByteType B>
43
inline void WriteLE16(B* ptr, uint16_t x)
44
0
{
45
0
    uint16_t v = htole16_internal(x);
46
0
    memcpy(ptr, &v, 2);
47
0
}
48
49
template <ByteType B>
50
inline void WriteLE32(B* ptr, uint32_t x)
51
9.59M
{
52
9.59M
    uint32_t v = htole32_internal(x);
53
9.59M
    memcpy(ptr, &v, 4);
54
9.59M
}
_Z9WriteLE32ITk8ByteTypehEvPT_j
Line
Count
Source
51
58.2k
{
52
58.2k
    uint32_t v = htole32_internal(x);
53
58.2k
    memcpy(ptr, &v, 4);
54
58.2k
}
_Z9WriteLE32ITk8ByteTypeSt4byteEvPT_j
Line
Count
Source
51
9.53M
{
52
9.53M
    uint32_t v = htole32_internal(x);
53
9.53M
    memcpy(ptr, &v, 4);
54
9.53M
}
55
56
template <ByteType B>
57
inline void WriteLE64(B* ptr, uint64_t x)
58
232
{
59
232
    uint64_t v = htole64_internal(x);
60
232
    memcpy(ptr, &v, 8);
61
232
}
Unexecuted instantiation: _Z9WriteLE64ITk8ByteTypeSt4byteEvPT_y
_Z9WriteLE64ITk8ByteTypehEvPT_y
Line
Count
Source
58
232
{
59
232
    uint64_t v = htole64_internal(x);
60
232
    memcpy(ptr, &v, 8);
61
232
}
62
63
template <ByteType B>
64
inline uint16_t ReadBE16(const B* ptr)
65
2.13k
{
66
2.13k
    uint16_t x;
67
2.13k
    memcpy(&x, ptr, 2);
68
2.13k
    return be16toh_internal(x);
69
2.13k
}
70
71
template <ByteType B>
72
inline uint32_t ReadBE32(const B* ptr)
73
43.2k
{
74
43.2k
    uint32_t x;
75
43.2k
    memcpy(&x, ptr, 4);
76
43.2k
    return be32toh_internal(x);
77
43.2k
}
_Z8ReadBE32ITk8ByteTypehEjPKT_
Line
Count
Source
73
43.2k
{
74
43.2k
    uint32_t x;
75
43.2k
    memcpy(&x, ptr, 4);
76
43.2k
    return be32toh_internal(x);
77
43.2k
}
Unexecuted instantiation: _Z8ReadBE32ITk8ByteTypeSt4byteEjPKT_
78
79
template <ByteType B>
80
inline uint64_t ReadBE64(const B* ptr)
81
6.49M
{
82
6.49M
    uint64_t x;
83
6.49M
    memcpy(&x, ptr, 8);
84
6.49M
    return be64toh_internal(x);
85
6.49M
}
86
87
template <ByteType B>
88
inline void WriteBE16(B* ptr, uint16_t x)
89
0
{
90
0
    uint16_t v = htobe16_internal(x);
91
0
    memcpy(ptr, &v, 2);
92
0
}
93
94
template <ByteType B>
95
inline void WriteBE32(B* ptr, uint32_t x)
96
91.5M
{
97
91.5M
    uint32_t v = htobe32_internal(x);
98
91.5M
    memcpy(ptr, &v, 4);
99
91.5M
}
100
101
template <ByteType B>
102
inline void WriteBE64(B* ptr, uint64_t x)
103
14.9M
{
104
14.9M
    uint64_t v = htobe64_internal(x);
105
14.9M
    memcpy(ptr, &v, 8);
106
14.9M
}
107
108
#endif // BITCOIN_CRYPTO_COMMON_H