|
33 | 33 | #include <util/error.h> |
34 | 34 | #include <util/moneystr.h> |
35 | 35 | #include <util/string.h> |
| 36 | +#include <util/time.h> |
36 | 37 | #include <util/translation.h> |
37 | 38 | #ifdef USE_BDB |
38 | 39 | #include <wallet/bdb.h> |
@@ -570,13 +571,14 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, |
570 | 571 | return false; |
571 | 572 | if (Unlock(_vMasterKey)) |
572 | 573 | { |
573 | | - int64_t nStartTime = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()); |
| 574 | + constexpr MillisecondsDouble target{100}; |
| 575 | + auto start{SteadyClock::now()}; |
574 | 576 | crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); |
575 | | - pMasterKey.second.nDeriveIterations = static_cast<unsigned int>(pMasterKey.second.nDeriveIterations * (100 / ((double)(TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - nStartTime)))); |
| 577 | + pMasterKey.second.nDeriveIterations = static_cast<unsigned int>(pMasterKey.second.nDeriveIterations * target / (SteadyClock::now() - start)); |
576 | 578 |
|
577 | | - nStartTime = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()); |
| 579 | + start = SteadyClock::now(); |
578 | 580 | crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); |
579 | | - pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + static_cast<unsigned int>(pMasterKey.second.nDeriveIterations * 100 / ((double)(TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - nStartTime)))) / 2; |
| 581 | + pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + static_cast<unsigned int>(pMasterKey.second.nDeriveIterations * target / (SteadyClock::now() - start))) / 2; |
580 | 582 |
|
581 | 583 | if (pMasterKey.second.nDeriveIterations < 25000) |
582 | 584 | pMasterKey.second.nDeriveIterations = 25000; |
@@ -775,13 +777,14 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) |
775 | 777 | GetStrongRandBytes(kMasterKey.vchSalt); |
776 | 778 |
|
777 | 779 | CCrypter crypter; |
778 | | - int64_t nStartTime = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()); |
| 780 | + constexpr MillisecondsDouble target{100}; |
| 781 | + auto start{SteadyClock::now()}; |
779 | 782 | crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod); |
780 | | - kMasterKey.nDeriveIterations = static_cast<unsigned int>(2500000 / ((double)(TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - nStartTime))); |
| 783 | + kMasterKey.nDeriveIterations = static_cast<unsigned int>(25000 * target / (SteadyClock::now() - start)); |
781 | 784 |
|
782 | | - nStartTime = TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()); |
| 785 | + start = SteadyClock::now(); |
783 | 786 | crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod); |
784 | | - kMasterKey.nDeriveIterations = (kMasterKey.nDeriveIterations + static_cast<unsigned int>(kMasterKey.nDeriveIterations * 100 / ((double)(TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) - nStartTime)))) / 2; |
| 787 | + kMasterKey.nDeriveIterations = (kMasterKey.nDeriveIterations + static_cast<unsigned int>(kMasterKey.nDeriveIterations * target / (SteadyClock::now() - start))) / 2; |
785 | 788 |
|
786 | 789 | if (kMasterKey.nDeriveIterations < 25000) |
787 | 790 | kMasterKey.nDeriveIterations = 25000; |
|
0 commit comments