17#include <shared_mutex>
31 CSHA256 m_salted_hasher_schnorr;
34 std::shared_mutex cs_sigcache;
44 static constexpr unsigned char PADDING_ECDSA[32] = {
'E'};
45 static constexpr unsigned char PADDING_SCHNORR[32] = {
'S'};
46 m_salted_hasher_ecdsa.
Write(
nonce.begin(), 32);
47 m_salted_hasher_ecdsa.
Write(PADDING_ECDSA, 32);
48 m_salted_hasher_schnorr.
Write(
nonce.begin(), 32);
49 m_salted_hasher_schnorr.
Write(PADDING_SCHNORR, 32);
53 ComputeEntryECDSA(
uint256& entry,
const uint256 &hash,
const std::vector<unsigned char>& vchSig,
const CPubKey& pubkey)
const
55 CSHA256 hasher = m_salted_hasher_ecdsa;
62 CSHA256 hasher = m_salted_hasher_schnorr;
67 Get(
const uint256& entry,
const bool erase)
69 std::shared_lock<std::shared_mutex> lock(cs_sigcache);
70 return setValid.contains(entry, erase);
75 std::unique_lock<std::shared_mutex> lock(cs_sigcache);
76 setValid.insert(entry);
78 uint32_t setup_bytes(
size_t n)
80 return setValid.setup_bytes(n);
90static CSignatureCache signatureCache;
100 size_t nElems = signatureCache.setup_bytes(nMaxCacheSize);
101 LogPrintf(
"Using %zu MiB out of %zu/2 requested for signature cache, able to store %zu elements\n",
102 (nElems*
sizeof(
uint256)) >>20, (nMaxCacheSize*2)>>20, nElems);
108 signatureCache.ComputeEntryECDSA(entry,
sighash, vchSig, pubkey);
109 if (signatureCache.Get(entry, !
store))
114 signatureCache.Set(entry);
121 signatureCache.ComputeEntrySchnorr(entry,
sighash, sig, pubkey);
122 if (signatureCache.Get(entry, !
store))
return true;
124 if (
store) signatureCache.Set(entry);
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
An encapsulated public key.
const unsigned char * data() const
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
A hasher class for SHA-256.
void Finalize(unsigned char hash[OUTPUT_SIZE])
CSHA256 & Write(const unsigned char *data, size_t len)
bool VerifySchnorrSignature(Span< const unsigned char > sig, const XOnlyPubKey &pubkey, const uint256 &sighash) const override
bool VerifyECDSASignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const override
cache implements a cache with properties similar to a cuckoo-set.
virtual bool VerifySchnorrSignature(Span< const unsigned char > sig, const XOnlyPubKey &pubkey, const uint256 &sighash) const
virtual bool VerifyECDSASignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
A Span is an object that can refer to a contiguous sequence of objects.
constexpr std::size_t size() const noexcept
constexpr C * data() const noexcept
static constexpr size_t size()
const unsigned char * data() const
static unsigned const char sighash[]
uint256 GetRandHash() noexcept
void InitSignatureCache()
static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE
static const int64_t MAX_MAX_SIG_CACHE_SIZE