MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / NegateSignatureS

Function NegateSignatureS

src/test/script_tests.cpp:148–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}; // struct ScriptTest
147
148void static NegateSignatureS(std::vector<unsigned char>& vchSig) {
149 // Parse the signature.
150 std::vector<unsigned char> r, s;
151 r = std::vector<unsigned char>(vchSig.begin() + 4, vchSig.begin() + 4 + vchSig[3]);
152 s = std::vector<unsigned char>(vchSig.begin() + 6 + vchSig[3], vchSig.begin() + 6 + vchSig[3] + vchSig[5 + vchSig[3]]);
153
154 while (s.size() < 33) {
155 s.insert(s.begin(), 0x00);
156 }
157 assert(s[0] == 0);
158 // Perform mod-n negation of s by (ab)using libsecp256k1
159 // (note that this function is meant to be used for negating secret keys,
160 // but it works for any non-zero scalar modulo the group order, i.e. also for s)
161 int ret = secp256k1_ec_seckey_negate(secp256k1_context_static, s.data() + 1);
162 assert(ret);
163
164 if (s[1] < 0x80) {
165 s.erase(s.begin());
166 }
167
168 // Reconstruct the signature.
169 vchSig.clear();
170 vchSig.push_back(0x30);
171 vchSig.push_back(4 + r.size() + s.size());
172 vchSig.push_back(0x02);
173 vchSig.push_back(r.size());
174 vchSig.insert(vchSig.end(), r.begin(), r.end());
175 vchSig.push_back(0x02);
176 vchSig.push_back(s.size());
177 vchSig.insert(vchSig.end(), s.begin(), s.end());
178}
179
180namespace
181{

Callers 1

TestBuilderClass · 0.85

Calls 9

beginMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
dataMethod · 0.45
eraseMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected