Skip to content

Commit 11e2eb5

Browse files
committed
f schnorrsig
1 parent a64d99c commit 11e2eb5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/schnorrsig.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
1919
use std::{ptr, fmt, error};
2020

21-
use secp256k1::{self, Secp256k1, Signing, Verification, Message, key};
21+
use secp256k1::{self, Secp256k1, Signing, Verification, Message};
22+
use secp256k1::key::{PublicKey, SecretKey};
2223

2324
use ffi;
2425
use super::ScratchSpace;
@@ -112,24 +113,24 @@ impl From<ffi::SchnorrSignature> for Signature {
112113
/// Schnorrsig signing trait
113114
pub trait Sign {
114115
/// Creates a Schnorr signature as defined by BIP-schnorr from a message and a secret key.
115-
fn schnorrsig_sign(&self, msg: &Message, sk: &key::SecretKey)
116+
fn schnorrsig_sign(&self, msg: &Message, sk: &SecretKey)
116117
-> Signature;
117118
}
118119

119120
/// Schnorrsig verification trait
120121
pub trait Verify {
121122
/// Verifies a Schnorr signature as defined by BIP-schnorr
122-
fn schnorrsig_verify(&self, msg: &Message, sig: &Signature, pk: &key::PublicKey) -> Result<(), Error>;
123+
fn schnorrsig_verify(&self, msg: &Message, sig: &Signature, pk: &PublicKey) -> Result<(), Error>;
123124
/// Takes slices of messages, Schnorr signatures and public keys and verifies them all at once.
124125
/// That's faster than if they would have been verified one by one. Returns an Error if a
125126
/// single Signature fails verification.
126-
fn schnorrsig_verify_batch(&self, msgs: &[Message], sigs: &[Signature], pks: &[key::PublicKey]) -> Result<(), Error>;
127+
fn schnorrsig_verify_batch(&self, msgs: &[Message], sigs: &[Signature], pks: &[PublicKey]) -> Result<(), Error>;
127128
}
128129

129130
impl<C: Signing> Sign for Secp256k1<C> {
130131
/// Constructs a signature for `msg` using the secret key `sk` and BIP-schnorr nonce
131132
/// Requires a signing-capable context.
132-
fn schnorrsig_sign(&self, msg: &Message, sk: &key::SecretKey)
133+
fn schnorrsig_sign(&self, msg: &Message, sk: &SecretKey)
133134
-> Signature {
134135
let mut ret = unsafe { ffi::SchnorrSignature::blank() };
135136
unsafe {
@@ -152,7 +153,7 @@ impl<C: Verification> Verify for Secp256k1<C> {
152153
/// Checks that `sig` is a valid Schnorr signature for `msg` using the public key
153154
/// `pubkey`. Returns `Ok(true)` on success.Requires a verify-capable context.
154155
#[inline]
155-
fn schnorrsig_verify(&self, msg: &Message, sig: &Signature, pk: &key::PublicKey) -> Result<(), Error> {
156+
fn schnorrsig_verify(&self, msg: &Message, sig: &Signature, pk: &PublicKey) -> Result<(), Error> {
156157
unsafe {
157158
if ffi::secp256k1_schnorrsig_verify(*self.ctx(), sig.as_ptr(), msg.as_ptr(), pk.as_ptr()) == 0 {
158159
Err(Error::IncorrectSignature)
@@ -162,7 +163,7 @@ impl<C: Verification> Verify for Secp256k1<C> {
162163
}
163164
}
164165

165-
fn schnorrsig_verify_batch(&self, msgs: &[Message], sigs: &[Signature], pks: &[key::PublicKey]) -> Result<(), Error> {
166+
fn schnorrsig_verify_batch(&self, msgs: &[Message], sigs: &[Signature], pks: &[PublicKey]) -> Result<(), Error> {
166167
if msgs.len() != sigs.len() || msgs.len() != pks.len() {
167168
return Err(Error::ArgumentLength);
168169
}
@@ -182,10 +183,11 @@ impl<C: Verification> Verify for Secp256k1<C> {
182183
if sigs.len() >= 1 << 31 {
183184
return Err(Error::TooManySignatures);
184185
}
186+
let scratch_space = ScratchSpace::new(&self, 8192);
185187
unsafe {
186188
/* TODO: use proper scratch space api */
187-
let scratch_space = ScratchSpace::new(&self, 8192);
188-
let result = ffi::secp256k1_schnorrsig_verify_batch(*self.ctx(), scratch_space.scratch_space(),
189+
let result = ffi::secp256k1_schnorrsig_verify_batch(*self.ctx(),
190+
scratch_space.scratch_space(),
189191
sigptrs.as_ptr(),
190192
msgptrs.as_ptr(),
191193
pkptrs.as_ptr(),

0 commit comments

Comments
 (0)