aboutsummaryrefslogtreecommitdiff
path: root/src/script/sigcache.h
diff options
context:
space:
mode:
authorJeremy Rubin <jeremy.l.rubin@gmail.com>2017-01-05 12:03:01 -0500
committerJeremy Rubin <jeremy.l.rubin@gmail.com>2017-04-12 14:42:41 -0700
commitf9c88079df8b78b8fab75e0903ca395654f2d360 (patch)
tree77d19ed9c6149a5091880c5be6b128695661ec72 /src/script/sigcache.h
parent471ed00fcd3b6feb2e37ad071c7ead78b4e2dad7 (diff)
Deduplicate SignatureCacheHasher
This moves the SignatureCacheHasher to the sigcache header, out of the anonymous namespace, so that the tests can import it.
Diffstat (limited to 'src/script/sigcache.h')
-rw-r--r--src/script/sigcache.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/script/sigcache.h b/src/script/sigcache.h
index 60690583de..55cec4cc8d 100644
--- a/src/script/sigcache.h
+++ b/src/script/sigcache.h
@@ -19,6 +19,27 @@ static const int64_t MAX_MAX_SIG_CACHE_SIZE = 16384;
class CPubKey;
+/**
+ * We're hashing a nonce into the entries themselves, so we don't need extra
+ * blinding in the set hash computation.
+ *
+ * This may exhibit platform endian dependent behavior but because these are
+ * nonced hashes (random) and this state is only ever used locally it is safe.
+ * All that matters is local consistency.
+ */
+class SignatureCacheHasher
+{
+public:
+ template <uint8_t hash_select>
+ uint32_t operator()(const uint256& key) const
+ {
+ static_assert(hash_select <8, "SignatureCacheHasher only has 8 hashes available.");
+ uint32_t u;
+ std::memcpy(&u, key.begin()+4*hash_select, 4);
+ return u;
+ }
+};
+
class CachingTransactionSignatureChecker : public TransactionSignatureChecker
{
private: