MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ChangeWalletPassphrase

Method ChangeWalletPassphrase

src/wallet/wallet.cpp:55–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55bool CWallet::ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase,
56 const SecureString &strNewWalletPassphrase) {
57 bool fWasLocked = IsLocked();
58
59 {
60 LOCK(cs_wallet);
61 Lock();
62
63 CCrypter crypter;
64 CKeyingMaterial vMasterKey;
65 for (auto &pMasterKey : mapMasterKeys) {
66 if (!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt,
67 pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
68 return false;
69 if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
70 return false;
71 if (CCryptoKeyStore::Unlock(vMasterKey)) {
72 int64_t nStartTime = GetTimeMillis();
73 crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt,
74 pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
75 pMasterKey.second.nDeriveIterations =
76 pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime)));
77
78 nStartTime = GetTimeMillis();
79 crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt,
80 pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
81 pMasterKey.second.nDeriveIterations =
82 (pMasterKey.second.nDeriveIterations +
83 pMasterKey.second.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime))) /
84 2;
85
86 if (pMasterKey.second.nDeriveIterations < 25000) pMasterKey.second.nDeriveIterations = 25000;
87
88 LogPrint(BCLog::INFO, "Wallet passphrase changed to an nDeriveIterations of %i\n",
89 pMasterKey.second.nDeriveIterations);
90
91 if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt,
92 pMasterKey.second.nDeriveIterations,
93 pMasterKey.second.nDerivationMethod))
94 return false;
95 if (!crypter.Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey))
96 return false;
97 CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second);
98 if (fWasLocked)
99 Lock();
100 return true;
101 }
102 }
103 }
104
105 return false;
106}
107
108void CWallet::SetBestChain(const CBlockLocator &loc) {
109 AssertLockHeld(cs_wallet);

Callers 1

walletpassphrasechangeFunction · 0.80

Calls 6

CWalletDBClass · 0.85
SetKeyFromPassphraseMethod · 0.80
WriteMasterKeyMethod · 0.80
GetTimeMillisFunction · 0.50
DecryptMethod · 0.45
EncryptMethod · 0.45

Tested by

no test coverage detected