Skip to content

Commit

Permalink
Do not use obsolete CPrivKey for passing keys around
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa authored and Matt Corallo committed Jul 13, 2011
1 parent b6b039d commit 0efda1a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
16 changes: 0 additions & 16 deletions src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,6 @@ class CKey
return false;
return true;
}

static bool Sign(const CPrivKey& vchPrivKey, uint256 hash, std::vector<unsigned char>& vchSig)
{
CKey key;
if (!key.SetPrivKey(vchPrivKey))
return false;
return key.Sign(hash, vchSig);
}

static bool Verify(const std::vector<unsigned char>& vchPubKey, uint256 hash, const std::vector<unsigned char>& vchSig)
{
CKey key;
if (!key.SetPubKey(vchPubKey))
return false;
return key.Verify(hash, vchSig);
}
};

#endif
6 changes: 2 additions & 4 deletions src/keystore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ bool CCryptoKeyStore::AddCryptedKey(const std::vector<unsigned char> &vchPubKey,
return true;
}

bool CCryptoKeyStore::GetPrivKey(const std::vector<unsigned char> &vchPubKey, CPrivKey& keyOut) const
bool CCryptoKeyStore::GetPrivKey(const std::vector<unsigned char> &vchPubKey, CKey& keyOut) const
{
CRITICAL_BLOCK(cs_vMasterKey)
{
Expand All @@ -114,9 +114,7 @@ bool CCryptoKeyStore::GetPrivKey(const std::vector<unsigned char> &vchPubKey, CP
CSecret vchSecret;
if (!DecryptSecret(vMasterKey, (*mi).second, Hash((*mi).first.begin(), (*mi).first.end()), vchSecret))
return false;
CKey key;
key.SetSecret(vchSecret);
keyOut = key.GetPrivKey();
keyOut.SetSecret(vchSecret);
return true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/keystore.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CKeyStore

virtual bool AddKey(const CKey& key) =0;
virtual bool HaveKey(const std::vector<unsigned char> &vchPubKey) const =0;
virtual bool GetPrivKey(const std::vector<unsigned char> &vchPubKey, CPrivKey& keyOut) const =0;
virtual bool GetPrivKey(const std::vector<unsigned char> &vchPubKey, CKey& keyOut) const =0;
virtual std::vector<unsigned char> GenerateNewKey();
};

Expand All @@ -30,12 +30,12 @@ class CBasicKeyStore : public CKeyStore
{
return (mapKeys.count(vchPubKey) > 0);
}
bool GetPrivKey(const std::vector<unsigned char> &vchPubKey, CPrivKey& keyOut) const
bool GetPrivKey(const std::vector<unsigned char> &vchPubKey, CKey& keyOut) const
{
std::map<std::vector<unsigned char>, CPrivKey>::const_iterator mi = mapKeys.find(vchPubKey);
if (mi != mapKeys.end())
{
keyOut = (*mi).second;
keyOut.SetPrivKey((*mi).second);
return true;
}
return false;
Expand Down Expand Up @@ -109,7 +109,7 @@ class CCryptoKeyStore : public CBasicKeyStore
return CBasicKeyStore::HaveKey(vchPubKey);
return mapCryptedKeys.count(vchPubKey) > 0;
}
bool GetPrivKey(const std::vector<unsigned char> &vchPubKey, CPrivKey& keyOut) const;
bool GetPrivKey(const std::vector<unsigned char> &vchPubKey, CKey& keyOut) const;
};

#endif
12 changes: 6 additions & 6 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,13 +1038,13 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
{
// Sign
const valtype& vchPubKey = item.second;
CPrivKey privkey;
if (!keystore.GetPrivKey(vchPubKey, privkey))
CKey key;
if (!keystore.GetPrivKey(vchPubKey, key))
return false;
if (hash != 0)
{
vector<unsigned char> vchSig;
if (!CKey::Sign(privkey, hash, vchSig))
if (!key.Sign(hash, vchSig))
return false;
vchSig.push_back((unsigned char)nHashType);
scriptSigRet << vchSig;
Expand All @@ -1057,13 +1057,13 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
if (mi == mapPubKeys.end())
return false;
const vector<unsigned char>& vchPubKey = (*mi).second;
CPrivKey privkey;
if (!keystore.GetPrivKey(vchPubKey, privkey))
CKey key;
if (!keystore.GetPrivKey(vchPubKey, key))
return false;
if (hash != 0)
{
vector<unsigned char> vchSig;
if (!CKey::Sign(privkey, hash, vchSig))
if (!key.Sign(hash, vchSig))
return false;
vchSig.push_back((unsigned char)nHashType);
scriptSigRet << vchSig << vchPubKey;
Expand Down

0 comments on commit 0efda1a

Please sign in to comment.