@@ -565,13 +565,14 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
565
565
return false ;
566
566
if (Unlock (_vMasterKey))
567
567
{
568
- int64_t nStartTime = GetTimeMillis ();
568
+ constexpr MillisecondsDouble target{100 };
569
+ auto start{SteadyClock::now ()};
569
570
crypter.SetKeyFromPassphrase (strNewWalletPassphrase, pMasterKey.second .vchSalt , pMasterKey.second .nDeriveIterations , pMasterKey.second .nDerivationMethod );
570
- pMasterKey.second .nDeriveIterations = static_cast <unsigned int >(pMasterKey.second .nDeriveIterations * ( 100 / (( double )( GetTimeMillis () - nStartTime)) ));
571
+ pMasterKey.second .nDeriveIterations = static_cast <unsigned int >(pMasterKey.second .nDeriveIterations * target / (SteadyClock::now () - start ));
571
572
572
- nStartTime = GetTimeMillis ();
573
+ start = SteadyClock::now ();
573
574
crypter.SetKeyFromPassphrase (strNewWalletPassphrase, pMasterKey.second .vchSalt , pMasterKey.second .nDeriveIterations , pMasterKey.second .nDerivationMethod );
574
- pMasterKey.second .nDeriveIterations = (pMasterKey.second .nDeriveIterations + static_cast <unsigned int >(pMasterKey.second .nDeriveIterations * 100 / (( double )( GetTimeMillis () - nStartTime) ))) / 2 ;
575
+ pMasterKey.second .nDeriveIterations = (pMasterKey.second .nDeriveIterations + static_cast <unsigned int >(pMasterKey.second .nDeriveIterations * target / (SteadyClock::now () - start ))) / 2 ;
575
576
576
577
if (pMasterKey.second .nDeriveIterations < 25000 )
577
578
pMasterKey.second .nDeriveIterations = 25000 ;
@@ -768,13 +769,14 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
768
769
GetStrongRandBytes (kMasterKey .vchSalt );
769
770
770
771
CCrypter crypter;
771
- int64_t nStartTime = GetTimeMillis ();
772
+ constexpr MillisecondsDouble target{100 };
773
+ auto start{SteadyClock::now ()};
772
774
crypter.SetKeyFromPassphrase (strWalletPassphrase, kMasterKey .vchSalt , 25000 , kMasterKey .nDerivationMethod );
773
- kMasterKey .nDeriveIterations = static_cast <unsigned int >(2500000 / (( double )( GetTimeMillis () - nStartTime) ));
775
+ kMasterKey .nDeriveIterations = static_cast <unsigned int >(25000 * target / (SteadyClock::now () - start ));
774
776
775
- nStartTime = GetTimeMillis ();
777
+ start = SteadyClock::now ();
776
778
crypter.SetKeyFromPassphrase (strWalletPassphrase, kMasterKey .vchSalt , kMasterKey .nDeriveIterations , kMasterKey .nDerivationMethod );
777
- kMasterKey .nDeriveIterations = (kMasterKey .nDeriveIterations + static_cast <unsigned int >(kMasterKey .nDeriveIterations * 100 / (( double )( GetTimeMillis () - nStartTime) ))) / 2 ;
779
+ kMasterKey .nDeriveIterations = (kMasterKey .nDeriveIterations + static_cast <unsigned int >(kMasterKey .nDeriveIterations * target / (SteadyClock::now () - start ))) / 2 ;
778
780
779
781
if (kMasterKey .nDeriveIterations < 25000 )
780
782
kMasterKey .nDeriveIterations = 25000 ;
0 commit comments