aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2019-09-17 19:29:59 -0400
committerAndrew Chow <achow101-github@achow101.com>2020-11-10 14:33:37 -0500
commit210b693db66e7c5b618014b5a287aee15af00045 (patch)
tree4615e9c69c139d3441d20b65011417a59ecb7cdf /src/util
parent95e61c1cf2a91d041c8025306ba36f0ea2806894 (diff)
downloadbitcoin-210b693db66e7c5b618014b5a287aee15af00045.tar.xz
Add generic SaltedSipHasher
SaltedSipHasher is a generic hasher that can be used with most things we would hash in an unordered container.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/hasher.cpp7
-rw-r--r--src/util/hasher.h12
2 files changed, 19 insertions, 0 deletions
diff --git a/src/util/hasher.cpp b/src/util/hasher.cpp
index 236b8e926f..5900daf050 100644
--- a/src/util/hasher.cpp
+++ b/src/util/hasher.cpp
@@ -10,3 +10,10 @@
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
+
+SaltedSipHasher::SaltedSipHasher() : m_k0(GetRand(std::numeric_limits<uint64_t>::max())), m_k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
+
+size_t SaltedSipHasher::operator()(const Span<const unsigned char>& script) const
+{
+ return CSipHasher(m_k0, m_k1).Write(script.data(), script.size()).Finalize();
+}
diff --git a/src/util/hasher.h b/src/util/hasher.h
index 77301df63d..fa2fea30d8 100644
--- a/src/util/hasher.h
+++ b/src/util/hasher.h
@@ -84,4 +84,16 @@ struct BlockHasher
size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
};
+class SaltedSipHasher
+{
+private:
+ /** Salt */
+ const uint64_t m_k0, m_k1;
+
+public:
+ SaltedSipHasher();
+
+ size_t operator()(const Span<const unsigned char>& script) const;
+};
+
#endif // BITCOIN_UTIL_HASHER_H