From 62504165e4ef41370fb56a1fb4f2e4fca9f4d227 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 4 Sep 2014 20:32:49 -0500 Subject: [PATCH] Reimplement non-typesafe `verify` fn, call it `verify_raw`. The typesafe version could not accept illegally padded signatures because `Signature` is a fixed-width type. Unfortunately such signatures are on the blockchain, and we need a way to verify them. --- src/secp256k1.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/secp256k1.rs b/src/secp256k1.rs index 83ac115..dd62976 100644 --- a/src/secp256k1.rs +++ b/src/secp256k1.rs @@ -233,11 +233,20 @@ impl Secp256k1 { Ok(pk) } + /// Checks that `sig` is a valid ECDSA signature for `msg` using the public + /// key `pubkey`. Returns `Ok(true)` on success. Note that this function cannot + /// be used for Bitcoin consensus checking since there are transactions out + /// there with zero-padded signatures that don't fit in the `Signature` type. + /// Use `verify_raw` instead. + #[inline] + pub fn verify(msg: &[u8], sig: &Signature, pk: &key::PublicKey) -> Result<()> { + Secp256k1::verify_raw(msg, sig.as_slice(), pk) + } /// Checks that `sig` is a valid ECDSA signature for `msg` using the public /// key `pubkey`. Returns `Ok(true)` on success. #[inline] - pub fn verify(msg: &[u8], sig: &Signature, pk: &key::PublicKey) -> Result<()> { + pub fn verify_raw(msg: &[u8], sig: &[u8], pk: &key::PublicKey) -> Result<()> { init(); // This is a static function, so we have to init let res = unsafe { ffi::secp256k1_ecdsa_verify(msg.as_ptr(), msg.len() as c_int,