From 91f43a33f8fb9d87bd2b6a7a279e4a6f5c1e3c96 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 26 Jan 2012 19:26:34 +0100 Subject: [PATCH] Full checking of all loaded keys --- src/db.cpp | 4 +++- src/key.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/db.cpp b/src/db.cpp index 9ad05ba7..07f58ef3 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -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 @@ -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; diff --git a/src/key.h b/src/key.h index c28222a9..f7bdc87c 100644 --- a/src/key.h +++ b/src/key.h @@ -307,6 +307,18 @@ public: 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