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;
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);
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
An encapsulated public key.
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 void LogPrintf(const char *fmt, const Args &... args)
peer m_getdata_requests erase(peer.m_getdata_requests.begin(), it)
uint256 GetRandHash() noexcept
void InitSignatureCache()
static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE
static const int64_t MAX_MAX_SIG_CACHE_SIZE