Changeset View
Changeset View
Standalone View
Standalone View
src/test/key_tests.cpp
Show First 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(key_signature_tests) { | ||||
CKey key = DecodeSecret(strSecret1); | CKey key = DecodeSecret(strSecret1); | ||||
std::string msg = "A message to be signed"; | std::string msg = "A message to be signed"; | ||||
uint256 msg_hash = Hash(msg.begin(), msg.end()); | uint256 msg_hash = Hash(msg.begin(), msg.end()); | ||||
std::vector<uint8_t> sig; | std::vector<uint8_t> sig; | ||||
bool found = false; | bool found = false; | ||||
for (int i = 1; i <= 20; ++i) { | for (int i = 1; i <= 20; ++i) { | ||||
sig.clear(); | sig.clear(); | ||||
key.SignECDSA(msg_hash, sig, false, i); | BOOST_CHECK(key.SignECDSA(msg_hash, sig, false, i)); | ||||
found = sig[3] == 0x21 && sig[4] == 0x00; | found = sig[3] == 0x21 && sig[4] == 0x00; | ||||
if (found) { | if (found) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
BOOST_CHECK(found); | BOOST_CHECK(found); | ||||
// When entropy is not specified, we should always see low R signatures that | // When entropy is not specified, we should always see low R signatures that | ||||
// are less than 70 bytes in 256 tries We should see at least one signature | // are less than 70 bytes in 256 tries We should see at least one signature | ||||
// that is less than 70 bytes. | // that is less than 70 bytes. | ||||
found = true; | found = true; | ||||
bool found_small = false; | bool found_small = false; | ||||
for (int i = 0; i < 256; ++i) { | for (int i = 0; i < 256; ++i) { | ||||
sig.clear(); | sig.clear(); | ||||
msg = "A message to be signed" + std::to_string(i); | msg = "A message to be signed" + std::to_string(i); | ||||
msg_hash = Hash(msg.begin(), msg.end()); | msg_hash = Hash(msg.begin(), msg.end()); | ||||
key.SignECDSA(msg_hash, sig); | BOOST_CHECK(key.SignECDSA(msg_hash, sig)); | ||||
found = sig[3] == 0x20; | found = sig[3] == 0x20; | ||||
BOOST_CHECK(sig.size() <= 70); | BOOST_CHECK(sig.size() <= 70); | ||||
found_small |= sig.size() < 70; | found_small |= sig.size() < 70; | ||||
} | } | ||||
BOOST_CHECK(found); | BOOST_CHECK(found); | ||||
BOOST_CHECK(found_small); | BOOST_CHECK(found_small); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |