Expose Schnorr sign/verify
This commit is contained in:
parent
9a91b69fad
commit
8aa2569818
1
build.rs
1
build.rs
|
@ -39,6 +39,7 @@ fn main() {
|
||||||
.define("USE_ENDOMORPHISM", Some("1"))
|
.define("USE_ENDOMORPHISM", Some("1"))
|
||||||
// These all are OK.
|
// These all are OK.
|
||||||
.define("ENABLE_MODULE_ECDH", Some("1"))
|
.define("ENABLE_MODULE_ECDH", Some("1"))
|
||||||
|
.define("ENABLE_MODULE_SCHNORR", Some("1"))
|
||||||
.define("ENABLE_MODULE_RECOVERY", Some("1"));
|
.define("ENABLE_MODULE_RECOVERY", Some("1"));
|
||||||
|
|
||||||
// secp256k1
|
// secp256k1
|
||||||
|
|
|
@ -35,6 +35,9 @@ pub const COMPRESSED_PUBLIC_KEY_SIZE: usize = 33;
|
||||||
/// The maximum size of a signature
|
/// The maximum size of a signature
|
||||||
pub const MAX_SIGNATURE_SIZE: usize = 72;
|
pub const MAX_SIGNATURE_SIZE: usize = 72;
|
||||||
|
|
||||||
|
/// The size of a Schnorr signature
|
||||||
|
pub const SCHNORR_SIGNATURE_SIZE: usize = 64;
|
||||||
|
|
||||||
/// The maximum size of a compact signature
|
/// The maximum size of a compact signature
|
||||||
pub const COMPACT_SIGNATURE_SIZE: usize = 64;
|
pub const COMPACT_SIGNATURE_SIZE: usize = 64;
|
||||||
|
|
||||||
|
|
21
src/ffi.rs
21
src/ffi.rs
|
@ -198,6 +198,27 @@ extern "C" {
|
||||||
msg32: *const c_uchar)
|
msg32: *const c_uchar)
|
||||||
-> c_int;
|
-> c_int;
|
||||||
|
|
||||||
|
// Schnorr
|
||||||
|
pub fn secp256k1_schnorr_sign(cx: *const Context,
|
||||||
|
sig64: *mut c_uchar,
|
||||||
|
msg32: *const c_uchar,
|
||||||
|
sk: *const c_uchar,
|
||||||
|
noncefn: NonceFn,
|
||||||
|
noncedata: *const c_void)
|
||||||
|
-> c_int;
|
||||||
|
|
||||||
|
pub fn secp256k1_schnorr_verify(cx: *const Context,
|
||||||
|
sig64: *const c_uchar,
|
||||||
|
msg32: *const c_uchar,
|
||||||
|
pk: *const PublicKey)
|
||||||
|
-> c_int;
|
||||||
|
|
||||||
|
pub fn secp256k1_schnorr_recover(cx: *const Context,
|
||||||
|
pk: *mut PublicKey,
|
||||||
|
sig64: *const c_uchar,
|
||||||
|
msg32: *const c_uchar)
|
||||||
|
-> c_int;
|
||||||
|
|
||||||
// EC
|
// EC
|
||||||
pub fn secp256k1_ec_seckey_verify(cx: *const Context,
|
pub fn secp256k1_ec_seckey_verify(cx: *const Context,
|
||||||
sk: *const c_uchar) -> c_int;
|
sk: *const c_uchar) -> c_int;
|
||||||
|
|
|
@ -53,6 +53,7 @@ pub mod constants;
|
||||||
pub mod ecdh;
|
pub mod ecdh;
|
||||||
pub mod ffi;
|
pub mod ffi;
|
||||||
pub mod key;
|
pub mod key;
|
||||||
|
pub mod schnorr;
|
||||||
|
|
||||||
/// A tag used for recovering the public key from a compact signature
|
/// A tag used for recovering the public key from a compact signature
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
|
@ -489,8 +490,7 @@ impl Secp256k1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines the public key for which `sig` is a valid signature for
|
/// Determines the public key for which `sig` is a valid signature for
|
||||||
/// `msg`. Returns through the out-pointer `pubkey`. Requires a verify-capable
|
/// `msg`. Requires a verify-capable context.
|
||||||
/// context.
|
|
||||||
pub fn recover(&self, msg: &Message, sig: &RecoverableSignature)
|
pub fn recover(&self, msg: &Message, sig: &RecoverableSignature)
|
||||||
-> Result<key::PublicKey, Error> {
|
-> Result<key::PublicKey, Error> {
|
||||||
if self.caps == ContextFlag::SignOnly || self.caps == ContextFlag::None {
|
if self.caps == ContextFlag::SignOnly || self.caps == ContextFlag::None {
|
||||||
|
@ -585,12 +585,8 @@ mod tests {
|
||||||
|
|
||||||
// Try pk recovery
|
// Try pk recovery
|
||||||
assert_eq!(none.recover(&msg, &sigr), Err(IncapableContext));
|
assert_eq!(none.recover(&msg, &sigr), Err(IncapableContext));
|
||||||
assert_eq!(none.recover(&msg, &sigr), Err(IncapableContext));
|
|
||||||
assert_eq!(sign.recover(&msg, &sigr), Err(IncapableContext));
|
|
||||||
assert_eq!(sign.recover(&msg, &sigr), Err(IncapableContext));
|
assert_eq!(sign.recover(&msg, &sigr), Err(IncapableContext));
|
||||||
assert!(vrfy.recover(&msg, &sigr).is_ok());
|
assert!(vrfy.recover(&msg, &sigr).is_ok());
|
||||||
assert!(vrfy.recover(&msg, &sigr).is_ok());
|
|
||||||
assert!(full.recover(&msg, &sigr).is_ok());
|
|
||||||
assert!(full.recover(&msg, &sigr).is_ok());
|
assert!(full.recover(&msg, &sigr).is_ok());
|
||||||
|
|
||||||
assert_eq!(vrfy.recover(&msg, &sigr),
|
assert_eq!(vrfy.recover(&msg, &sigr),
|
||||||
|
|
Loading…
Reference in New Issue