21 if (!count || !key || !iv)
27 di.
Write((
const unsigned char*)strKeyData.c_str(), strKeyData.size());
28 di.
Write(chSalt.data(), chSalt.size());
31 for (
int i = 0; i != count - 1; i++)
46 if (nDerivationMethod == 0)
65 memcpy(
vchIV.data(), chNewIV.data(), chNewIV.size());
78 vchCiphertext.resize(vchPlaintext.size() + AES_BLOCKSIZE);
81 size_t nLen = enc.
Encrypt(&vchPlaintext[0], vchPlaintext.size(), vchCiphertext.data());
82 if (nLen < vchPlaintext.size())
84 vchCiphertext.resize(nLen);
94 int nLen = vchCiphertext.size();
95 vchPlaintext.resize(nLen);
97 nLen = dec.
Decrypt(vchCiphertext.data(), vchCiphertext.size(), &vchPlaintext[0]);
100 vchPlaintext.resize(nLen);
109 if (!cKeyCrypter.
SetKey(vMasterKey, chIV))
119 if (!cKeyCrypter.
SetKey(vMasterKey, chIV))
130 if (vchSecret.size() != 32)
167 std::vector<unsigned char> vchCryptedSecret;
208 const CPubKey& vchPubKey = (*mi).second.first;
209 const std::vector<unsigned char>& vchCryptedSecret = (*mi).second.second;
224 vchPubKeyOut = (*mi).second.first;
237 std::set<CKeyID> set_address;
239 set_address.insert(mi.first);
251 for (KeyMap::value_type& mKey :
mapKeys) {
252 const CKey& key = mKey.second;
255 std::vector<unsigned char> vchCryptedSecret;
int Decrypt(const unsigned char *data, int size, unsigned char *out) const
int Encrypt(const unsigned char *data, int size, unsigned char *out) const
SaplingSpendingKeyMap mapSaplingSpendingKeys
bool GetKey(const CKeyID &address, CKey &keyOut) const
std::set< CKeyID > GetKeys() const
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Add a key to the store.
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
bool HaveKey(const CKeyID &address) const
Check whether a key corresponding to a given address is present in the store.
Encryption/decryption context with key information.
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext) const
bool SetKey(const CKeyingMaterial &chNewKey, const std::vector< unsigned char > &chNewIV)
bool SetKeyFromPassphrase(const SecureString &strKeyData, const std::vector< unsigned char > &chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
bool Decrypt(const std::vector< unsigned char > &vchCiphertext, CKeyingMaterial &vchPlaintext) const
int BytesToKeySHA512AES(const std::vector< unsigned char > &chSalt, const SecureString &strKeyData, int count, unsigned char *key, unsigned char *iv) const
std::vector< unsigned char, secure_allocator< unsigned char > > vchIV
std::vector< unsigned char, secure_allocator< unsigned char > > vchKey
bool GetKey(const CKeyID &address, CKey &keyOut) const override
std::atomic< bool > fUseCrypto
if fUseCrypto is true, mapKeys and mapSaplingSpendingKeys must be empty if fUseCrypto is false,...
static bool DecryptKey(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCryptedSecret, const CPubKey &vchPubKey, CKey &key)
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
bool HaveKey(const CKeyID &address) const override
Check whether a key corresponding to a given address is present in the store.
bool EncryptKeys(CKeyingMaterial &vMasterKeyIn)
will encrypt previously unencrypted keys
virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector< unsigned char > &vchCryptedSecret)
CKeyingMaterial vMasterKey
CryptedKeyMap mapCryptedKeys
std::set< CKeyID > GetKeys() const override
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
An encapsulated private key.
const unsigned char * end() const
CPubKey GetPubKey() const
Compute the public key from a private key.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
const unsigned char * begin() const
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
A reference to a CKey: the Hash160 of its serialized public key.
RecursiveMutex cs_KeyStore
An encapsulated public key.
bool IsCompressed() const
Check whether this is a compressed public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
uint256 GetHash() const
Get the 256-bit hash of this public key.
A hasher class for SHA-512.
static constexpr size_t OUTPUT_SIZE
void Finalize(unsigned char hash[OUTPUT_SIZE])
CSHA512 & Write(const unsigned char *data, size_t len)
void memory_cleanse(void *ptr, size_t len)
bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< unsigned char > &vchCiphertext)
bool DecryptSecret(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCiphertext, const uint256 &nIV, CKeyingMaterial &vchPlaintext)
const unsigned int WALLET_CRYPTO_IV_SIZE
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
const unsigned int WALLET_CRYPTO_SALT_SIZE
const unsigned int WALLET_CRYPTO_KEY_SIZE
void * memcpy(void *a, const void *b, size_t c)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
#define WITH_LOCK(cs, code)
Run code while locking a mutex.