mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
wallet: EncryptWallet forced derivations
Forcing a derivation count is useful for benchmarks, since otherwise `EncryptWallet` trying to normalize itself interferes with measurement.
This commit is contained in:
parent
8fa10edcd1
commit
b7e6995380
2 changed files with 19 additions and 11 deletions
|
@ -807,7 +807,7 @@ void CWallet::AddToSpends(const CWalletTx& wtx, WalletBatch* batch)
|
||||||
AddToSpends(txin.prevout, wtx.GetHash(), batch);
|
AddToSpends(txin.prevout, wtx.GetHash(), batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase, std::optional<unsigned int> forceIterations)
|
||||||
{
|
{
|
||||||
if (IsCrypted())
|
if (IsCrypted())
|
||||||
return false;
|
return false;
|
||||||
|
@ -823,6 +823,13 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||||
GetStrongRandBytes(kMasterKey.vchSalt);
|
GetStrongRandBytes(kMasterKey.vchSalt);
|
||||||
|
|
||||||
CCrypter crypter;
|
CCrypter crypter;
|
||||||
|
|
||||||
|
// False by default, used by test or benchmarking code
|
||||||
|
if(forceIterations.has_value()) {
|
||||||
|
kMasterKey.nDeriveIterations = forceIterations.value();
|
||||||
|
}
|
||||||
|
// Try to find an nDeriveIterations that takes about 100ms
|
||||||
|
else {
|
||||||
constexpr MillisecondsDouble target{100};
|
constexpr MillisecondsDouble target{100};
|
||||||
auto start{SteadyClock::now()};
|
auto start{SteadyClock::now()};
|
||||||
crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod);
|
crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod);
|
||||||
|
@ -834,6 +841,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||||
|
|
||||||
if (kMasterKey.nDeriveIterations < 25000)
|
if (kMasterKey.nDeriveIterations < 25000)
|
||||||
kMasterKey.nDeriveIterations = 25000;
|
kMasterKey.nDeriveIterations = 25000;
|
||||||
|
}
|
||||||
|
|
||||||
WalletLogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations);
|
WalletLogPrintf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations);
|
||||||
|
|
||||||
|
|
|
@ -581,7 +581,7 @@ public:
|
||||||
|
|
||||||
bool Unlock(const SecureString& strWalletPassphrase);
|
bool Unlock(const SecureString& strWalletPassphrase);
|
||||||
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
|
bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase);
|
||||||
bool EncryptWallet(const SecureString& strWalletPassphrase);
|
bool EncryptWallet(const SecureString& strWalletPassphrase, std::optional<unsigned int> forceIterations = std::nullopt);
|
||||||
|
|
||||||
void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
unsigned int ComputeTimeSmart(const CWalletTx& wtx, bool rescanning_old_block) const;
|
unsigned int ComputeTimeSmart(const CWalletTx& wtx, bool rescanning_old_block) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue