Skip to content

Commit

Permalink
Full checking of all loaded keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Jan 26, 2012
1 parent 4c932cc commit 91f43a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/db.cpp
Expand Up @@ -862,7 +862,7 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
ssValue >> pkey;
key.SetPubKey(vchPubKey);
key.SetPrivKey(pkey);
if (key.GetPubKey() != vchPubKey)
if (key.GetPubKey() != vchPubKey || !key.IsValid())
return DB_CORRUPT;
}
else
Expand All @@ -871,6 +871,8 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
ssValue >> wkey;
key.SetPubKey(vchPubKey);
key.SetPrivKey(wkey.vchPrivKey);
if (key.GetPubKey() != vchPubKey || !key.IsValid())
return DB_CORRUPT;
}
if (!pwallet->LoadKey(key))
return DB_CORRUPT;
Expand Down
12 changes: 12 additions & 0 deletions src/key.h
Expand Up @@ -307,6 +307,18 @@ class CKey
return false;
return true;
}

bool IsValid()
{
if (!fSet)
return false;

bool fCompr;
CSecret secret = GetSecret(fCompr);
CKey key2;
key2.SetSecret(secret, fCompr);
return GetPubKey() == key2.GetPubKey();
}
};

#endif

0 comments on commit 91f43a3

Please sign in to comment.