mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-09 05:14:22 +01:00
QA: add test for CKey::Negate()
This commit is contained in:
parent
463921bb64
commit
3b64f852e4
1 changed files with 32 additions and 0 deletions
|
@ -188,4 +188,36 @@ BOOST_AUTO_TEST_CASE(key_signature_tests)
|
||||||
BOOST_CHECK(found_small);
|
BOOST_CHECK(found_small);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(key_key_negation)
|
||||||
|
{
|
||||||
|
// create a dummy hash for signature comparison
|
||||||
|
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(hash.begin());
|
||||||
|
|
||||||
|
// import the static test key
|
||||||
|
CKey key = DecodeSecret(strSecret1C);
|
||||||
|
|
||||||
|
// create a signature
|
||||||
|
std::vector<unsigned char> vch_sig;
|
||||||
|
std::vector<unsigned char> vch_sig_cmp;
|
||||||
|
key.Sign(hash, vch_sig);
|
||||||
|
|
||||||
|
// negate the key twice
|
||||||
|
BOOST_CHECK(key.GetPubKey().data()[0] == 0x03);
|
||||||
|
key.Negate();
|
||||||
|
// after the first negation, the signature must be different
|
||||||
|
key.Sign(hash, vch_sig_cmp);
|
||||||
|
BOOST_CHECK(vch_sig_cmp != vch_sig);
|
||||||
|
BOOST_CHECK(key.GetPubKey().data()[0] == 0x02);
|
||||||
|
key.Negate();
|
||||||
|
// after the second negation, we should have the original key and thus the
|
||||||
|
// same signature
|
||||||
|
key.Sign(hash, vch_sig_cmp);
|
||||||
|
BOOST_CHECK(vch_sig_cmp == vch_sig);
|
||||||
|
BOOST_CHECK(key.GetPubKey().data()[0] == 0x03);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
Loading…
Add table
Reference in a new issue