| 200 | } |
| 201 | |
| 202 | bool check_tx_sig(const struct bitcoin_tx *tx, size_t input_num, |
| 203 | const u8 *redeemscript, |
| 204 | const u8 *witness_script, |
| 205 | const struct pubkey *key, |
| 206 | const struct bitcoin_signature *sig) |
| 207 | { |
| 208 | struct sha256_double hash; |
| 209 | bool use_segwit = witness_script != NULL; |
| 210 | const u8 *script = use_segwit ? witness_script : redeemscript; |
| 211 | bool ret; |
| 212 | |
| 213 | /* We only support a limited subset of sighash types. */ |
| 214 | if (sig->sighash_type != SIGHASH_ALL) { |
| 215 | if (!witness_script) |
| 216 | return false; |
| 217 | if (sig->sighash_type != (SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)) |
| 218 | return false; |
| 219 | } |
| 220 | assert(input_num < tx->wtx->num_inputs); |
| 221 | |
| 222 | bitcoin_tx_hash_for_sig(tx, input_num, script, sig->sighash_type, &hash); |
| 223 | dump_tx("check_tx_sig", tx, input_num, script, key, &hash); |
| 224 | |
| 225 | ret = check_signed_hash(&hash, &sig->s, key); |
| 226 | if (!ret) |
| 227 | dump_tx("Sig failed", tx, input_num, redeemscript, key, &hash); |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | /* Stolen direct from bitcoin/src/script/sign.cpp: |
| 232 | // Copyright (c) 2009-2010 Satoshi Nakamoto |
no test coverage detected