| 146 | }; // struct ScriptTest |
| 147 | |
| 148 | void 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 | |
| 180 | namespace |
| 181 | { |
no test coverage detected