Bitcoin Core  21.99.0
P2P Digital Currency
hasher.h
Go to the documentation of this file.
1 // Copyright (c) 2019 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/siphash.h>
10 #include <uint256.h>
11 
13 {
14 private:
16  const uint64_t k0, k1;
17 
18 public:
20 
21  size_t operator()(const uint256& txid) const {
22  return SipHashUint256(k0, k1, txid);
23  }
24 };
25 
27 {
28 private:
30  const uint64_t k0, k1;
31 
32 public:
34 
48  size_t operator()(const COutPoint& id) const noexcept {
49  return SipHashUint256Extra(k0, k1, id.hash, id.n);
50  }
51 };
52 
54 {
55  size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
56 };
57 
67 {
68 public:
69  template <uint8_t hash_select>
70  uint32_t operator()(const uint256& key) const
71  {
72  static_assert(hash_select <8, "SignatureCacheHasher only has 8 hashes available.");
73  uint32_t u;
74  std::memcpy(&u, key.begin()+4*hash_select, 4);
75  return u;
76  }
77 };
78 
80 {
81  // this used to call `GetCheapHash()` in uint256, which was later moved; the
82  // cheap hash function simply calls ReadLE64() however, so the end result is
83  // identical
84  size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
85 };
86 
88 {
89 private:
91  const uint64_t m_k0, m_k1;
92 
93 public:
95 
96  size_t operator()(const Span<const unsigned char>& script) const;
97 };
98 
99 #endif // BITCOIN_UTIL_HASHER_H
SaltedSipHasher::operator()
size_t operator()(const Span< const unsigned char > &script) const
Definition: hasher.cpp:16
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:66
FilterHeaderHasher::operator()
size_t operator()(const uint256 &hash) const
Definition: hasher.h:55
SaltedOutpointHasher::k0
const uint64_t k0
Salt.
Definition: hasher.h:30
transaction.h
uint256.h
SaltedTxidHasher::k1
const uint64_t k1
Definition: hasher.h:16
SaltedOutpointHasher::SaltedOutpointHasher
SaltedOutpointHasher()
Definition: hasher.cpp:12
BlockHasher
Definition: hasher.h:79
Span
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:92
SaltedOutpointHasher::operator()
size_t operator()(const COutPoint &id) const noexcept
This must return size_t.
Definition: hasher.h:48
siphash.h
SipHashUint256Extra
uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256 &val, uint32_t extra)
Definition: siphash.cpp:134
SipHashUint256
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
Definition: siphash.cpp:94
SaltedTxidHasher
Definition: hasher.h:12
SaltedOutpointHasher::k1
const uint64_t k1
Definition: hasher.h:30
BlockHasher::operator()
size_t operator()(const uint256 &hash) const
Definition: hasher.h:84
uint256
256-bit opaque blob.
Definition: uint256.h:124
SaltedSipHasher::SaltedSipHasher
SaltedSipHasher()
Definition: hasher.cpp:14
SaltedSipHasher
Definition: hasher.h:87
ReadLE64
static uint64_t ReadLE64(const unsigned char *ptr)
Definition: common.h:31
SaltedOutpointHasher
Definition: hasher.h:26
SignatureCacheHasher::operator()
uint32_t operator()(const uint256 &key) const
Definition: hasher.h:70
SaltedTxidHasher::k0
const uint64_t k0
Salt.
Definition: hasher.h:16
SaltedTxidHasher::SaltedTxidHasher
SaltedTxidHasher()
Definition: hasher.cpp:10
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
SaltedSipHasher::m_k0
const uint64_t m_k0
Salt.
Definition: hasher.h:91
SaltedTxidHasher::operator()
size_t operator()(const uint256 &txid) const
Definition: hasher.h:21
base_blob::begin
unsigned char * begin()
Definition: uint256.h:58
FilterHeaderHasher
Definition: hasher.h:53
SaltedSipHasher::m_k1
const uint64_t m_k1
Definition: hasher.h:91