From 4beebd168e4e68918be2b5b05ad2ed874edfbd1e Mon Sep 17 00:00:00 2001 From: Tibo-lg Date: Fri, 6 May 2022 12:16:53 +0900 Subject: [PATCH 1/2] Add secp256k1_schnorrsig_sign_custom to sys crate --- secp256k1-sys/src/lib.rs | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/secp256k1-sys/src/lib.rs b/secp256k1-sys/src/lib.rs index a681f98..ebbe483 100644 --- a/secp256k1-sys/src/lib.rs +++ b/secp256k1-sys/src/lib.rs @@ -87,12 +87,42 @@ pub type EcdhHashFn = Option c_int>; +/// Data structure that contains additional arguments for schnorrsig_sign_custom. +#[repr(C)] +pub struct SchnorrSigExtraParams { + magic: [c_uchar; 4], + nonce_fp: SchnorrNonceFn, + ndata: *const c_void, +} + +impl SchnorrSigExtraParams { + /// Create a new SchnorrSigExtraParams properly initialized. + /// + /// `nonce_fp`: pointer to a nonce generation function. If NULL + /// rustsecp256k1_v0_5_0_nonce_function_bip340 is used + /// + /// `ndata`: pointer to arbitrary data used by the nonce generation function + /// (can be NULL). If it is non-NULL and + /// rustsecp256k1_v0_5_0_nonce_function_bip340 is used, + /// then ndata must be a pointer to 32-byte auxiliary randomness as per + /// BIP-340. + pub fn new(nonce_fp: SchnorrNonceFn, ndata: *const c_void) -> Self { + SchnorrSigExtraParams { + magic: [0xda, 0x6f, 0xb3, 0x8c], + nonce_fp, + ndata, + } + } +} + /// A Secp256k1 context, containing various precomputed values and such /// needed to do elliptic curve computations. If you create one of these /// with `secp256k1_context_create` you MUST destroy it with @@ -461,6 +491,17 @@ extern "C" { aux_rand32: *const c_uchar ) -> c_int; + // Schnorr Signatures with extra parameters (see [`SchnorrSigExtraParams`]) + #[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_schnorrsig_sign_custom")] + pub fn secp256k1_schnorrsig_sign_custom( + cx: *const Context, + sig: *mut c_uchar, + msg: *const c_uchar, + msg_len: size_t, + keypair: *const KeyPair, + extra_params: *const SchnorrSigExtraParams, + ) -> c_int; + #[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_schnorrsig_verify")] pub fn secp256k1_schnorrsig_verify( cx: *const Context, From 0b27bde60b2d9866be9937d7bce812355e9ccb46 Mon Sep 17 00:00:00 2001 From: Tibo-lg Date: Sat, 7 May 2022 20:32:08 +0900 Subject: [PATCH 2/2] Bump secp256k1-sys minor version --- secp256k1-sys/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/secp256k1-sys/Cargo.toml b/secp256k1-sys/Cargo.toml index 203011f..43da598 100644 --- a/secp256k1-sys/Cargo.toml +++ b/secp256k1-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "secp256k1-sys" -version = "0.5.1" +version = "0.5.2" authors = [ "Dawid Ciężarkiewicz ", "Andrew Poelstra ", "Steven Roose " ]