|
|
@ -86,6 +86,20 @@ bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig) const { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CKey::VerifyPubKey(const CPubKey& pubkey) const { |
|
|
|
|
|
|
|
if (pubkey.IsCompressed() != fCompressed) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
unsigned char rnd[8]; |
|
|
|
|
|
|
|
std::string str = "Bitcoin key verification\n"; |
|
|
|
|
|
|
|
GetRandBytes(rnd, sizeof(rnd)); |
|
|
|
|
|
|
|
uint256 hash; |
|
|
|
|
|
|
|
CHash256().Write((unsigned char*)str.data(), str.size()).Write(rnd, sizeof(rnd)).Finalize((unsigned char*)&hash); |
|
|
|
|
|
|
|
std::vector<unsigned char> vchSig; |
|
|
|
|
|
|
|
Sign(hash, vchSig); |
|
|
|
|
|
|
|
return pubkey.Verify(hash, vchSig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig) const { |
|
|
|
bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig) const { |
|
|
|
if (!fValid) |
|
|
|
if (!fValid) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -111,10 +125,7 @@ bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) { |
|
|
|
if (fSkipCheck) |
|
|
|
if (fSkipCheck) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
if (GetPubKey() != vchPubKey) |
|
|
|
return VerifyPubKey(vchPubKey); |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CKey::Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const { |
|
|
|
bool CKey::Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const { |
|
|
@ -190,5 +201,13 @@ void CExtKey::Decode(const unsigned char code[74]) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ECC_InitSanityCheck() { |
|
|
|
bool ECC_InitSanityCheck() { |
|
|
|
return CECKey::SanityCheck(); |
|
|
|
#if !defined(USE_SECP256K1) |
|
|
|
|
|
|
|
if (!CECKey::SanityCheck()) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
CKey key; |
|
|
|
|
|
|
|
key.MakeNewKey(true); |
|
|
|
|
|
|
|
CPubKey pubkey = key.GetPubKey(); |
|
|
|
|
|
|
|
return key.VerifyPubKey(pubkey); |
|
|
|
} |
|
|
|
} |
|
|
|