Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
util
hasher.h
Go to the documentation of this file.
1
// Copyright (c) 2019-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_UTIL_HASHER_H
6
#define BITCOIN_UTIL_HASHER_H
7
8
#include <
crypto/common.h
>
9
#include <
crypto/siphash.h
>
10
#include <
primitives/transaction.h
>
11
#include <
uint256.h
>
12
13
#include <cstdint>
14
#include <cstring>
15
#include <span>
16
17
class
SaltedUint256Hasher
18
{
19
const
PresaltedSipHasher
m_hasher
;
20
21
public
:
22
SaltedUint256Hasher
();
23
24
size_t
operator()
(
const
uint256
& hash)
const
25
{
26
return
m_hasher
(hash);
27
}
28
};
29
30
class
SaltedTxidHasher
31
{
32
const
PresaltedSipHasher
m_hasher
;
33
34
public
:
35
SaltedTxidHasher
();
36
37
size_t
operator()
(
const
Txid
& txid)
const
38
{
39
return
m_hasher
(txid.
ToUint256
());
40
}
41
};
42
43
class
SaltedWtxidHasher
44
{
45
const
PresaltedSipHasher
m_hasher
;
46
47
public
:
48
SaltedWtxidHasher
();
49
50
size_t
operator()
(
const
Wtxid
& wtxid)
const
51
{
52
return
m_hasher
(wtxid.
ToUint256
());
53
}
54
};
55
56
class
SaltedOutpointHasher
57
{
58
const
PresaltedSipHasher
m_hasher
;
59
60
public
:
61
SaltedOutpointHasher
();
62
72
size_t
operator()
(
const
COutPoint
&
id
)
const
noexcept
73
{
74
return
m_hasher
(
id
.hash.ToUint256(),
id
.n);
75
}
76
};
77
86
class
SignatureCacheHasher
87
{
88
public
:
89
template
<u
int
8_t hash_select>
90
uint32_t
operator()
(
const
uint256
& key)
const
91
{
92
static_assert
(hash_select <8,
"SignatureCacheHasher only has 8 hashes available."
);
93
uint32_t u;
94
std::memcpy(&u, key.
begin
()+4*hash_select, 4);
95
return
u;
96
}
97
};
98
99
struct
BlockHasher
100
{
101
// this used to call `GetCheapHash()` in uint256, which was later moved; the
102
// cheap hash function simply calls ReadLE64() however, so the end result is
103
// identical
104
size_t
operator()
(
const
uint256
& hash)
const
{
return
ReadLE64
(hash.
begin
()); }
105
};
106
107
class
SaltedSipHasher
108
{
109
private
:
111
const
uint64_t
m_k0
,
m_k1
;
112
113
public
:
114
SaltedSipHasher
();
115
116
size_t
operator()
(
const
std::span<const unsigned char>&
script
)
const
;
117
};
118
119
#endif
// BITCOIN_UTIL_HASHER_H
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition
transaction.h:30
PresaltedSipHasher
Optimized SipHash-2-4 implementation for uint256.
Definition
siphash.h:205
SaltedOutpointHasher::m_hasher
const PresaltedSipHasher m_hasher
Definition
hasher.h:58
SaltedOutpointHasher::operator()
size_t operator()(const COutPoint &id) const noexcept
Having the hash noexcept allows libstdc++'s unordered_map to recalculate the hash during rehash,...
Definition
hasher.h:72
SaltedOutpointHasher::SaltedOutpointHasher
SaltedOutpointHasher()
Definition
hasher.cpp:25
SaltedSipHasher::SaltedSipHasher
SaltedSipHasher()
Definition
hasher.cpp:30
SaltedSipHasher::operator()
size_t operator()(const std::span< const unsigned char > &script) const
Definition
hasher.cpp:35
SaltedSipHasher::m_k0
const uint64_t m_k0
Salt.
Definition
hasher.h:111
SaltedSipHasher::m_k1
const uint64_t m_k1
Definition
hasher.h:111
SaltedTxidHasher::m_hasher
const PresaltedSipHasher m_hasher
Definition
hasher.h:32
SaltedTxidHasher::SaltedTxidHasher
SaltedTxidHasher()
Definition
hasher.cpp:15
SaltedTxidHasher::operator()
size_t operator()(const Txid &txid) const
Definition
hasher.h:37
SaltedUint256Hasher::m_hasher
const PresaltedSipHasher m_hasher
Definition
hasher.h:19
SaltedUint256Hasher::operator()
size_t operator()(const uint256 &hash) const
Definition
hasher.h:24
SaltedUint256Hasher::SaltedUint256Hasher
SaltedUint256Hasher()
Definition
hasher.cpp:10
SaltedWtxidHasher::SaltedWtxidHasher
SaltedWtxidHasher()
Definition
hasher.cpp:20
SaltedWtxidHasher::operator()
size_t operator()(const Wtxid &wtxid) const
Definition
hasher.h:50
SaltedWtxidHasher::m_hasher
const PresaltedSipHasher m_hasher
Definition
hasher.h:45
SignatureCacheHasher
We're hashing a nonce into the entries themselves, so we don't need extra blinding in the set hash co...
Definition
hasher.h:87
SignatureCacheHasher::operator()
uint32_t operator()(const uint256 &key) const
Definition
hasher.h:90
base_blob::begin
constexpr unsigned char * begin()
Definition
uint256.h:101
transaction_identifier::ToUint256
const uint256 & ToUint256() const LIFETIMEBOUND
Definition
transaction_identifier.h:37
uint256
256-bit opaque blob.
Definition
uint256.h:196
common.h
ReadLE64
uint64_t ReadLE64(const B *ptr)
Definition
common.h:35
script
Definition
parsing.cpp:11
transaction.h
siphash.h
BlockHasher
Definition
hasher.h:100
BlockHasher::operator()
size_t operator()(const uint256 &hash) const
Definition
hasher.h:104
Wtxid
transaction_identifier< true > Wtxid
Wtxid commits to all transaction fields including the witness.
Definition
transaction_identifier.h:62
Txid
transaction_identifier< false > Txid
Txid commits to all transaction fields except the witness.
Definition
transaction_identifier.h:60
uint256.h
Generated on
for Bitcoin Core by
1.18.0