Changeset View
Changeset View
Standalone View
Standalone View
src/test/key_tests.cpp
// Copyright (c) 2012-2019 The Bitcoin Core developers | // Copyright (c) 2012-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <key.h> | #include <key.h> | ||||
#include <chainparams.h> // For Params() | #include <chainparams.h> // For Params() | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/string.h> | |||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(key_signature_tests) { | ||||
// 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" + ToString(i); | ||||
msg_hash = Hash(msg.begin(), msg.end()); | msg_hash = Hash(msg.begin(), msg.end()); | ||||
BOOST_CHECK(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); | ||||
Show All 37 Lines |