Update for latest libsecp: normalize signatures and use "lax DER" parsing

This commit is contained in:
Andrew Poelstra 2015-10-26 14:38:47 -05:00
parent 67c0b8fba7
commit 8daf06cc1d
2 changed files with 7 additions and 4 deletions

View File

@ -1,7 +1,7 @@
[package] [package]
name = "bitcoin" name = "bitcoin"
version = "0.3.9" version = "0.3.10"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"] authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
license = "CC0-1.0" license = "CC0-1.0"
homepage = "https://github.com/apoelstra/rust-bitcoin/" homepage = "https://github.com/apoelstra/rust-bitcoin/"
@ -24,7 +24,7 @@ num_cpus = "0.2"
rand = "0.3" rand = "0.3"
rust-crypto = "0.2" rust-crypto = "0.2"
rustc-serialize = "0.3" rustc-serialize = "0.3"
secp256k1 = "0.3" secp256k1 = "0.4"
serde = "0.6" serde = "0.6"
serde_json = "0.6" serde_json = "0.6"
time = "0.1" time = "0.1"

View File

@ -1667,7 +1667,10 @@ fn check_signature(secp: &Secp256k1, sig_slice: &[u8], pk_slice: &[u8], script:
// We can unwrap -- only failure mode is on length, which is fixed to 32 // We can unwrap -- only failure mode is on length, which is fixed to 32
let msg = secp256k1::Message::from_slice(&signature_hash[..]).unwrap(); let msg = secp256k1::Message::from_slice(&signature_hash[..]).unwrap();
let sig = try!(secp256k1::Signature::from_der(secp, sig_slice).map_err(Error::Ecdsa)); // TODO: both from_der_lax and normalize() should not be used once BIP66 is accepted
let mut sig = try!(secp256k1::Signature::from_der_lax(secp, sig_slice).map_err(Error::Ecdsa));
// Normalize it
sig.normalize_s(secp);
Secp256k1::verify(secp, &msg, &sig, &pubkey).map_err(Error::Ecdsa) Secp256k1::verify(secp, &msg, &sig, &pubkey).map_err(Error::Ecdsa)
} }
@ -2068,7 +2071,7 @@ impl Script {
match check_signature(secp, sig_slice, pk_slice, script, tx, input_index) { match check_signature(secp, sig_slice, pk_slice, script, tx, input_index) {
Ok(()) => stack.push(MaybeOwned::Borrowed(SCRIPT_TRUE)), Ok(()) => stack.push(MaybeOwned::Borrowed(SCRIPT_TRUE)),
_ => stack.push(MaybeOwned::Borrowed(SCRIPT_FALSE)), _ => stack.push(MaybeOwned::Borrowed(SCRIPT_FALSE))
} }
if op == opcodes::Ordinary::OP_CHECKSIGVERIFY { op_verify!(stack, Error::VerifyFailed); } if op == opcodes::Ordinary::OP_CHECKSIGVERIFY { op_verify!(stack, Error::VerifyFailed); }
} }