mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Do not use obsolete CPrivKey for passing keys around
This commit is contained in:
parent
b6b039d84e
commit
0efda1a79e
16
src/key.h
16
src/key.h
@ -220,22 +220,6 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
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
|
#endif
|
||||||
|
@ -100,7 +100,7 @@ bool CCryptoKeyStore::AddCryptedKey(const std::vector<unsigned char> &vchPubKey,
|
|||||||
return true;
|
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)
|
CRITICAL_BLOCK(cs_vMasterKey)
|
||||||
{
|
{
|
||||||
@ -114,9 +114,7 @@ bool CCryptoKeyStore::GetPrivKey(const std::vector<unsigned char> &vchPubKey, CP
|
|||||||
CSecret vchSecret;
|
CSecret vchSecret;
|
||||||
if (!DecryptSecret(vMasterKey, (*mi).second, Hash((*mi).first.begin(), (*mi).first.end()), vchSecret))
|
if (!DecryptSecret(vMasterKey, (*mi).second, Hash((*mi).first.begin(), (*mi).first.end()), vchSecret))
|
||||||
return false;
|
return false;
|
||||||
CKey key;
|
keyOut.SetSecret(vchSecret);
|
||||||
key.SetSecret(vchSecret);
|
|
||||||
keyOut = key.GetPrivKey();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public:
|
|||||||
|
|
||||||
virtual bool AddKey(const CKey& key) =0;
|
virtual bool AddKey(const CKey& key) =0;
|
||||||
virtual bool HaveKey(const std::vector<unsigned char> &vchPubKey) const =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();
|
virtual std::vector<unsigned char> GenerateNewKey();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,12 +30,12 @@ public:
|
|||||||
{
|
{
|
||||||
return (mapKeys.count(vchPubKey) > 0);
|
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);
|
std::map<std::vector<unsigned char>, CPrivKey>::const_iterator mi = mapKeys.find(vchPubKey);
|
||||||
if (mi != mapKeys.end())
|
if (mi != mapKeys.end())
|
||||||
{
|
{
|
||||||
keyOut = (*mi).second;
|
keyOut.SetPrivKey((*mi).second);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -109,7 +109,7 @@ public:
|
|||||||
return CBasicKeyStore::HaveKey(vchPubKey);
|
return CBasicKeyStore::HaveKey(vchPubKey);
|
||||||
return mapCryptedKeys.count(vchPubKey) > 0;
|
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
|
#endif
|
||||||
|
@ -1038,13 +1038,13 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
|
|||||||
{
|
{
|
||||||
// Sign
|
// Sign
|
||||||
const valtype& vchPubKey = item.second;
|
const valtype& vchPubKey = item.second;
|
||||||
CPrivKey privkey;
|
CKey key;
|
||||||
if (!keystore.GetPrivKey(vchPubKey, privkey))
|
if (!keystore.GetPrivKey(vchPubKey, key))
|
||||||
return false;
|
return false;
|
||||||
if (hash != 0)
|
if (hash != 0)
|
||||||
{
|
{
|
||||||
vector<unsigned char> vchSig;
|
vector<unsigned char> vchSig;
|
||||||
if (!CKey::Sign(privkey, hash, vchSig))
|
if (!key.Sign(hash, vchSig))
|
||||||
return false;
|
return false;
|
||||||
vchSig.push_back((unsigned char)nHashType);
|
vchSig.push_back((unsigned char)nHashType);
|
||||||
scriptSigRet << vchSig;
|
scriptSigRet << vchSig;
|
||||||
@ -1057,13 +1057,13 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
|
|||||||
if (mi == mapPubKeys.end())
|
if (mi == mapPubKeys.end())
|
||||||
return false;
|
return false;
|
||||||
const vector<unsigned char>& vchPubKey = (*mi).second;
|
const vector<unsigned char>& vchPubKey = (*mi).second;
|
||||||
CPrivKey privkey;
|
CKey key;
|
||||||
if (!keystore.GetPrivKey(vchPubKey, privkey))
|
if (!keystore.GetPrivKey(vchPubKey, key))
|
||||||
return false;
|
return false;
|
||||||
if (hash != 0)
|
if (hash != 0)
|
||||||
{
|
{
|
||||||
vector<unsigned char> vchSig;
|
vector<unsigned char> vchSig;
|
||||||
if (!CKey::Sign(privkey, hash, vchSig))
|
if (!key.Sign(hash, vchSig))
|
||||||
return false;
|
return false;
|
||||||
vchSig.push_back((unsigned char)nHashType);
|
vchSig.push_back((unsigned char)nHashType);
|
||||||
scriptSigRet << vchSig << vchPubKey;
|
scriptSigRet << vchSig << vchPubKey;
|
||||||
|
Loading…
Reference in New Issue
Block a user