Changeset View
Changeset View
Standalone View
Standalone View
src/test/script_tests.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 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 "data/script_tests.json.h" | #include "data/script_tests.json.h" | ||||
#include "core_io.h" | #include "core_io.h" | ||||
#include "key.h" | #include "key.h" | ||||
#include "keystore.h" | #include "keystore.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "script/script.h" | #include "script/script.h" | ||||
#include "script/script_error.h" | #include "script/script_error.h" | ||||
#include "script/sign.h" | #include "script/sign.h" | ||||
#include "test/scriptflags.h" | #include "test/scriptflags.h" | ||||
#include "test/sigutil.h" | |||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#if defined(HAVE_CONSENSUS_LIB) | #if defined(HAVE_CONSENSUS_LIB) | ||||
#include "script/bitcoinconsensus.h" | #include "script/bitcoinconsensus.h" | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (libconsensus_flags == flags) { | ||||
(const uint8_t *)&stream[0], stream.size(), | (const uint8_t *)&stream[0], stream.size(), | ||||
0, libconsensus_flags, nullptr) == expect, | 0, libconsensus_flags, nullptr) == expect, | ||||
message); | message); | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
static void NegateSignatureS(std::vector<uint8_t> &vchSig) { | |||||
// Parse the signature. | |||||
std::vector<uint8_t> r, s; | |||||
r = std::vector<uint8_t>(vchSig.begin() + 4, | |||||
vchSig.begin() + 4 + vchSig[3]); | |||||
s = std::vector<uint8_t>(vchSig.begin() + 6 + vchSig[3], | |||||
vchSig.begin() + 6 + vchSig[3] + | |||||
vchSig[5 + vchSig[3]]); | |||||
// Really ugly to implement mod-n negation here, but it would be feature | |||||
// creep to expose such functionality from libsecp256k1. | |||||
static const uint8_t order[33] = { | |||||
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, | |||||
0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41}; | |||||
while (s.size() < 33) { | |||||
s.insert(s.begin(), 0x00); | |||||
} | |||||
int carry = 0; | |||||
for (int p = 32; p >= 1; p--) { | |||||
int n = (int)order[p] - s[p] - carry; | |||||
s[p] = (n + 256) & 0xFF; | |||||
carry = (n < 0); | |||||
} | |||||
assert(carry == 0); | |||||
if (s.size() > 1 && s[0] == 0 && s[1] < 0x80) { | |||||
s.erase(s.begin()); | |||||
} | |||||
// Reconstruct the signature. | |||||
vchSig.clear(); | |||||
vchSig.push_back(0x30); | |||||
vchSig.push_back(4 + r.size() + s.size()); | |||||
vchSig.push_back(0x02); | |||||
vchSig.push_back(r.size()); | |||||
vchSig.insert(vchSig.end(), r.begin(), r.end()); | |||||
vchSig.push_back(0x02); | |||||
vchSig.push_back(s.size()); | |||||
vchSig.insert(vchSig.end(), s.begin(), s.end()); | |||||
} | |||||
namespace { | namespace { | ||||
const uint8_t vchKey0[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | const uint8_t vchKey0[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; | ||||
const uint8_t vchKey1[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | const uint8_t vchKey1[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}; | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}; | ||||
const uint8_t vchKey2[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | const uint8_t vchKey2[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}; | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}; | ||||
▲ Show 20 Lines • Show All 1,554 Lines • Show Last 20 Lines |