| 263 | } |
| 264 | |
| 265 | bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig) const { |
| 266 | if (!fValid) |
| 267 | return false; |
| 268 | vchSig.resize(CPubKey::COMPACT_SIGNATURE_SIZE); |
| 269 | int rec = -1; |
| 270 | secp256k1_ecdsa_recoverable_signature rsig; |
| 271 | int ret = secp256k1_ecdsa_sign_recoverable(secp256k1_context_sign, &rsig, hash.begin(), begin(), secp256k1_nonce_function_rfc6979, nullptr); |
| 272 | assert(ret); |
| 273 | ret = secp256k1_ecdsa_recoverable_signature_serialize_compact(secp256k1_context_sign, &vchSig[1], &rec, &rsig); |
| 274 | assert(ret); |
| 275 | assert(rec != -1); |
| 276 | vchSig[0] = 27 + rec + (fCompressed ? 4 : 0); |
| 277 | // Additional verification step to prevent using a potentially corrupted signature |
| 278 | secp256k1_pubkey epk, rpk; |
| 279 | ret = secp256k1_ec_pubkey_create(secp256k1_context_sign, &epk, begin()); |
| 280 | assert(ret); |
| 281 | ret = secp256k1_ecdsa_recover(GetVerifyContext(), &rpk, &rsig, hash.begin()); |
| 282 | assert(ret); |
| 283 | ret = secp256k1_ec_pubkey_cmp(GetVerifyContext(), &epk, &rpk); |
| 284 | assert(ret == 0); |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | bool CKey::SignSchnorr(const uint256& hash, Span<unsigned char> sig, const uint256* merkle_root, const uint256& aux) const |
| 289 | { |