22 if(!
count || !key || !iv)
29 di.
Write(salt.data(), salt.size());
32 for(
int i = 0; i !=
count - 1; i++)
48 if (derivation_method == 0) {
69 memcpy(
vchKey.data(), new_key.data(), new_key.size());
70 memcpy(
vchIV.data(), new_iv.data(), new_iv.size());
86 size_t nLen = enc.
Encrypt(vchPlaintext.data(), vchPlaintext.size(), vchCiphertext.data());
87 if(nLen < vchPlaintext.size())
89 vchCiphertext.resize(nLen);
100 plaintext.resize(ciphertext.size());
103 int len = dec.
Decrypt(ciphertext.data(), ciphertext.size(), plaintext.data());
107 plaintext.resize(len);
116 if(!cKeyCrypter.
SetKey(vMasterKey, chIV))
118 return cKeyCrypter.
Encrypt(vchPlaintext, vchCiphertext);
126 if (!key_crypter.
SetKey(master_key, iv_prefix)) {
129 return key_crypter.
Decrypt(ciphertext, plaintext);
139 if (secret.size() != 32) {
static const int AES_BLOCKSIZE
int Decrypt(const unsigned char *data, int size, unsigned char *out) const
int Encrypt(const unsigned char *data, int size, unsigned char *out) const
An encapsulated private key.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
An encapsulated public key.
bool IsCompressed() const
Check whether this is a compressed public key.
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)
constexpr const unsigned char * data() const
Encryption/decryption context with key information.
bool Decrypt(std::span< const unsigned char > ciphertext, CKeyingMaterial &plaintext) const
int BytesToKeySHA512AES(std::span< const unsigned char > salt, const SecureString &key_data, int count, unsigned char *key, unsigned char *iv) const
std::vector< unsigned char, secure_allocator< unsigned char > > vchKey
bool SetKeyFromPassphrase(const SecureString &key_data, std::span< const unsigned char > salt, const unsigned int rounds, const unsigned int derivation_method)
bool SetKey(const CKeyingMaterial &new_key, std::span< const unsigned char > new_iv)
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext) const
std::vector< unsigned char, secure_allocator< unsigned char > > vchIV
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 > > CKeyingMaterial
const unsigned int WALLET_CRYPTO_KEY_SIZE
bool DecryptSecret(const CKeyingMaterial &master_key, const std::span< const unsigned char > ciphertext, const uint256 &iv, CKeyingMaterial &plaintext)
const unsigned int WALLET_CRYPTO_IV_SIZE
bool DecryptKey(const CKeyingMaterial &master_key, const std::span< const unsigned char > crypted_secret, const CPubKey &pub_key, CKey &key)
const unsigned int WALLET_CRYPTO_SALT_SIZE
bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< unsigned char > &vchCiphertext)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
unsigned char * UCharCast(char *c)