Skip to content

Commit 210b693

Browse files
committed
Add generic SaltedSipHasher
SaltedSipHasher is a generic hasher that can be used with most things we would hash in an unordered container.
1 parent 95e61c1 commit 210b693

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/util/hasher.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@
1010
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
1111

1212
SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
13+
14+
SaltedSipHasher::SaltedSipHasher() : m_k0(GetRand(std::numeric_limits<uint64_t>::max())), m_k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
15+
16+
size_t SaltedSipHasher::operator()(const Span<const unsigned char>& script) const
17+
{
18+
return CSipHasher(m_k0, m_k1).Write(script.data(), script.size()).Finalize();
19+
}

src/util/hasher.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,16 @@ struct BlockHasher
8484
size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
8585
};
8686

87+
class SaltedSipHasher
88+
{
89+
private:
90+
/** Salt */
91+
const uint64_t m_k0, m_k1;
92+
93+
public:
94+
SaltedSipHasher();
95+
96+
size_t operator()(const Span<const unsigned char>& script) const;
97+
};
98+
8799
#endif // BITCOIN_UTIL_HASHER_H

0 commit comments

Comments
 (0)