From 6e51b3bddf782f53527cf968445b298ebdec9bbc Mon Sep 17 00:00:00 2001 From: patrick s Date: Wed, 28 Aug 2013 23:53:26 -0700 Subject: improve wallet load time by removing duplicated calls to EC_KEY_check_key and adding a hash for vchPubKey/vchPrivKey entries in wallet.dat backwards compatible with previous wallet.dat format --- src/key.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/key.cpp') diff --git a/src/key.cpp b/src/key.cpp index 85dc9cda2b..0377140f79 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -166,9 +166,12 @@ public: assert(nSize == nSize2); } - bool SetPrivKey(const CPrivKey &privkey) { + bool SetPrivKey(const CPrivKey &privkey, bool fSkipCheck=false) { const unsigned char* pbegin = &privkey[0]; if (d2i_ECPrivateKey(&pkey, &pbegin, privkey.size())) { + if(fSkipCheck) + return true; + // d2i_ECPrivateKey returns true if parsing succeeds. // This doesn't necessarily mean the key is valid. if (EC_KEY_check_key(pkey)) @@ -409,6 +412,18 @@ bool CKey::SignCompact(const uint256 &hash, std::vector& vchSig) return true; } +bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) { + CECKey key; + if (!key.SetPrivKey(privkey, fSkipCheck)) + return false; + + key.GetSecretBytes(vch); + fCompressed = vchPubKey.IsCompressed(); + fValid = true; + + return true; +} + bool CPubKey::Verify(const uint256 &hash, const std::vector& vchSig) const { if (!IsValid()) return false; -- cgit v1.2.3 From a42eef6f10e1da1c76e1c9ba49a2ff2459c62fea Mon Sep 17 00:00:00 2001 From: patrick s Date: Thu, 29 Aug 2013 01:11:47 -0700 Subject: verify vchPubKey matches calculated public key unless fSkipCheck is set --- src/key.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/key.cpp') diff --git a/src/key.cpp b/src/key.cpp index 0377140f79..fe5222378a 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -421,6 +421,12 @@ bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) { fCompressed = vchPubKey.IsCompressed(); fValid = true; + if (fSkipCheck) + return true; + + if (GetPubKey() != vchPubKey) + return false; + return true; } -- cgit v1.2.3