20 if(!count || !key || !iv)
26 di.
Write((
const unsigned char*)strKeyData.data(), strKeyData.size());
27 di.
Write(chSalt.data(), chSalt.size());
30 for(
int i = 0; i != count - 1; i++)
45 if (nDerivationMethod == 0)
65 memcpy(
vchIV.data(), chNewIV.data(), chNewIV.size());
81 size_t nLen = enc.
Encrypt(&vchPlaintext[0], vchPlaintext.size(), vchCiphertext.data());
82 if(nLen < vchPlaintext.size())
84 vchCiphertext.resize(nLen);
95 int nLen = vchCiphertext.size();
97 vchPlaintext.resize(nLen);
100 nLen = dec.
Decrypt(vchCiphertext.data(), vchCiphertext.size(), &vchPlaintext[0]);
103 vchPlaintext.resize(nLen);
112 if(!cKeyCrypter.
SetKey(vMasterKey, chIV))
122 if(!cKeyCrypter.
SetKey(vMasterKey, chIV))
130 if(!
DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret))
133 if (vchSecret.size() != 32)
136 key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed());
137 return key.VerifyPubKey(vchPubKey);
bool SetKeyFromPassphrase(const SecureString &strKeyData, const std::vector< unsigned char > &chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
const unsigned int WALLET_CRYPTO_KEY_SIZE
bool DecryptKey(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCryptedSecret, const CPubKey &vchPubKey, CKey &key)
bool SetKey(const CKeyingMaterial &chNewKey, const std::vector< unsigned char > &chNewIV)
Encryption/decryption context with key information.
int Encrypt(const unsigned char *data, int size, unsigned char *out) const
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool Decrypt(const std::vector< unsigned char > &vchCiphertext, CKeyingMaterial &vchPlaintext) const
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
const unsigned int WALLET_CRYPTO_IV_SIZE
void Finalize(unsigned char hash[OUTPUT_SIZE])
void memory_cleanse(void *ptr, size_t len)
Secure overwrite a buffer (possibly containing secret data) with zero-bytes.
std::vector< unsigned char, secure_allocator< unsigned char > > vchKey
std::vector< unsigned char, secure_allocator< unsigned char > > vchIV
An encapsulated public key.
int Decrypt(const unsigned char *data, int size, unsigned char *out) const
static constexpr size_t OUTPUT_SIZE
int BytesToKeySHA512AES(const std::vector< unsigned char > &chSalt, const SecureString &strKeyData, int count, unsigned char *key, unsigned char *iv) const
const unsigned int WALLET_CRYPTO_SALT_SIZE
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext) const
void * memcpy(void *a, const void *b, size_t c)
bool DecryptSecret(const CKeyingMaterial &vMasterKey, const std::vector< unsigned char > &vchCiphertext, const uint256 &nIV, CKeyingMaterial &vchPlaintext)
CSHA512 & Write(const unsigned char *data, size_t len)
bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< unsigned char > &vchCiphertext)
An encapsulated private key.
A hasher class for SHA-512.
static const int AES_BLOCKSIZE