THis bug was originally reported by Alex AXe: https://bitcointalk.org/index.php?topic=704756.msg14401298#msg14401298
const unsigned char *vchZero = NULL;
-void CKey::SetCompressedPubKey()
+void CKey::SetCompressedPubKey(bool fCompressed)
{
- EC_KEY_set_conv_form(pkey, POINT_CONVERSION_COMPRESSED);
- fCompressedPubKey = true;
+ EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
+ fCompressedPubKey = fCompressed;
}
void CKey::Reset()
{
if (!EC_KEY_generate_key(pkey))
throw key_error("CKey::MakeNewKey() : EC_KEY_generate_key failed");
- if (fCompressed)
- SetCompressedPubKey();
+ SetCompressedPubKey(fCompressed);
fSet = true;
}
}
BN_clear_free(bn);
fSet = true;
- if (fCompressed)
- SetCompressedPubKey();
+ SetCompressedPubKey(fCompressed);
return true;
}
{
CKey keyRec;
keyRec.fSet = true;
- if (fCompressedPubKey)
- keyRec.SetCompressedPubKey();
+ keyRec.SetCompressedPubKey(fCompressedPubKey);
if (ECDSA_SIG_recover_key_GFp(keyRec.pkey, sig, (unsigned char*)&hash, sizeof(hash), i, 1) == 1)
if (keyRec.GetPubKey() == this->GetPubKey())
{
bool IsNull() const;
bool IsCompressed() const;
- void SetCompressedPubKey();
+ void SetCompressedPubKey(bool fCompressed=true);
void MakeNewKey(bool fCompressed=true);
bool SetPrivKey(const CPrivKey& vchPrivKey);
- bool SetSecret(const CSecret& vchSecret, bool fCompressed = true);
+ bool SetSecret(const CSecret& vchSecret, bool fCompressed = false);
CSecret GetSecret(bool &fCompressed) const;
CSecret GetSecret() const;
CPrivKey GetPrivKey() const;
return false;
CKey key;
key.SetSecret(vchSecret);
- if (vchPubKey.size() == 33)
- key.SetCompressedPubKey();
+ key.SetCompressedPubKey(vchPubKey.IsCompressed());
if (key.GetPubKey() == vchPubKey)
break;
return false;
if (vchSecret.size() != 32)
return false;
keyOut.SetSecret(vchSecret);
- if (vchPubKey.size() == 33)
- keyOut.SetCompressedPubKey();
+ keyOut.SetCompressedPubKey(vchPubKey.IsCompressed());
return true;
}
}
return false;
CKey key;
key.SetSecret(vchSecret);
- if (vchPubKey.size() == 33)
- key.SetCompressedPubKey();
+ key.SetCompressedPubKey(vchPubKey.IsCompressed());
if (!CBasicKeyStore::AddKey(key))
return false;
}
strErr = "Error reading wallet database: CPrivKey pubkey inconsistency";
return false;
}
- if (vchPubKey.size() == 33) {
- key.SetCompressedPubKey();
- }
+ key.SetCompressedPubKey(vchPubKey.IsCompressed());
if (!key.IsValid())
{
strErr = "Error reading wallet database: invalid CPrivKey";
strErr = "Error reading wallet database: CWalletKey pubkey inconsistency";
return false;
}
- if (vchPubKey.size() == 33) {
- key.SetCompressedPubKey();
- }
+ key.SetCompressedPubKey(vchPubKey.IsCompressed());
if (!key.IsValid())
{
strErr = "Error reading wallet database: invalid CWalletKey";