14 #include <boost/thread/shared_mutex.hpp> 27 CSHA256 m_salted_hasher_schnorr;
30 boost::shared_mutex cs_sigcache;
40 static constexpr
unsigned char PADDING_ECDSA[32] = {
'E'};
41 static constexpr
unsigned char PADDING_SCHNORR[32] = {
'S'};
42 m_salted_hasher_ecdsa.
Write(nonce.
begin(), 32);
43 m_salted_hasher_ecdsa.
Write(PADDING_ECDSA, 32);
44 m_salted_hasher_schnorr.
Write(nonce.
begin(), 32);
45 m_salted_hasher_schnorr.
Write(PADDING_SCHNORR, 32);
49 ComputeEntryECDSA(
uint256& entry,
const uint256 &hash,
const std::vector<unsigned char>& vchSig,
const CPubKey& pubkey)
const 51 CSHA256 hasher = m_salted_hasher_ecdsa;
52 hasher.
Write(hash.
begin(), 32).Write(&pubkey[0], pubkey.
size()).Write(&vchSig[0], vchSig.size()).Finalize(entry.
begin());
58 CSHA256 hasher = m_salted_hasher_schnorr;
65 boost::shared_lock<boost::shared_mutex> lock(cs_sigcache);
66 return setValid.contains(entry, erase);
71 boost::unique_lock<boost::shared_mutex> lock(cs_sigcache);
72 setValid.insert(entry);
74 uint32_t setup_bytes(
size_t n)
76 return setValid.setup_bytes(n);
86 static CSignatureCache signatureCache;
96 size_t nElems = signatureCache.setup_bytes(nMaxCacheSize);
97 LogPrintf(
"Using %zu MiB out of %zu/2 requested for signature cache, able to store %zu elements\n",
98 (nElems*
sizeof(
uint256)) >>20, (nMaxCacheSize*2)>>20, nElems);
104 signatureCache.ComputeEntryECDSA(entry, sighash, vchSig, pubkey);
105 if (signatureCache.Get(entry, !store))
110 signatureCache.Set(entry);
117 signatureCache.ComputeEntrySchnorr(entry, sighash, sig, pubkey);
118 if (signatureCache.Get(entry, !store))
return true;
120 if (store) signatureCache.Set(entry);
peer m_getdata_requests erase(peer.m_getdata_requests.begin(), it)
CSHA256 & Write(const unsigned char *data, size_t len)
bool VerifySchnorrSignature(Span< const unsigned char > sig, const XOnlyPubKey &pubkey, const uint256 &sighash) const override
virtual bool VerifySchnorrSignature(Span< const unsigned char > sig, const XOnlyPubKey &pubkey, const uint256 &sighash) const
static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE
uint256 GetRandHash() noexcept
constexpr std::size_t size() const noexcept
cache implements a cache with properties similar to a cuckoo-set.
static void LogPrintf(const char *fmt, const Args &... args)
virtual bool VerifyECDSASignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
An encapsulated public key.
void InitSignatureCache()
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
static const int64_t MAX_MAX_SIG_CACHE_SIZE
constexpr C * data() const noexcept
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool VerifyECDSASignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const override
A Span is an object that can refer to a contiguous sequence of objects.
A hasher class for SHA-256.