mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Read and write a checksum for encrypted keys
This commit is contained in:
parent
3b69310beb
commit
a8334f7ac3
1 changed files with 16 additions and 1 deletions
|
@ -109,7 +109,11 @@ bool WalletBatch::WriteCryptedKey(const CPubKey& vchPubKey,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!WriteIC(std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey), vchCryptedSecret, false)) {
|
||||
// Compute a checksum of the encrypted key
|
||||
uint256 checksum = Hash(vchCryptedSecret.begin(), vchCryptedSecret.end());
|
||||
|
||||
const auto key = std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey);
|
||||
if (!WriteIC(key, std::make_pair(vchCryptedSecret, checksum), false)) {
|
||||
return false;
|
||||
}
|
||||
EraseIC(std::make_pair(DBKeys::KEY, vchPubKey));
|
||||
|
@ -332,6 +336,17 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
|||
}
|
||||
std::vector<unsigned char> vchPrivKey;
|
||||
ssValue >> vchPrivKey;
|
||||
|
||||
// Get the checksum and check it
|
||||
if (!ssValue.eof()) {
|
||||
uint256 checksum;
|
||||
ssValue >> checksum;
|
||||
if (Hash(vchPrivKey.begin(), vchPrivKey.end()) != checksum) {
|
||||
strErr = "Error reading wallet database: Crypted key corrupt";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
wss.nCKeys++;
|
||||
|
||||
if (!pwallet->GetOrCreateLegacyScriptPubKeyMan()->LoadCryptedKey(vchPubKey, vchPrivKey))
|
||||
|
|
Loading…
Add table
Reference in a new issue