Merge rust-bitcoin/rust-secp256k1#440: Add secp256k1_schnorrsig_sign_custom to sys crate
0b27bde60b
Bump secp256k1-sys minor version (Tibo-lg)4beebd168e
Add secp256k1_schnorrsig_sign_custom to sys crate (Tibo-lg) Pull request description: Trying to update to the latest version I noticed that I lost the ability to pass a nonce to the schnorr signing function. This PR restore this ability by adding `secp256k1_schnorrsig_sign_custom` to the sys crate. I hid the struct members of `SchnorrSigExtraParams` and added a `new` method to make sure that the `magic` field is properly initialized, I think that make the most sense but happy to hear other opinions. ACKs for top commit: apoelstra: ACK0b27bde60b
Tree-SHA512: 7181eddb5815ca1a5ae1044f2a6fd8a214f8df9c45352e5f2ab6607f7e0d819cb8856fc2d6596b9d740b859df91d559595e7912332e292079c9ac1d27ec5c00b
This commit is contained in:
commit
33f76e4c5c
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "secp256k1-sys"
|
name = "secp256k1-sys"
|
||||||
version = "0.5.1"
|
version = "0.5.2"
|
||||||
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
|
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
|
||||||
"Andrew Poelstra <apoelstra@wpsoftware.net>",
|
"Andrew Poelstra <apoelstra@wpsoftware.net>",
|
||||||
"Steven Roose <steven@stevenroose.org>" ]
|
"Steven Roose <steven@stevenroose.org>" ]
|
||||||
|
|
|
@ -87,12 +87,42 @@ pub type EcdhHashFn = Option<unsafe extern "C" fn(
|
||||||
pub type SchnorrNonceFn = Option<unsafe extern "C" fn(
|
pub type SchnorrNonceFn = Option<unsafe extern "C" fn(
|
||||||
nonce32: *mut c_uchar,
|
nonce32: *mut c_uchar,
|
||||||
msg32: *const c_uchar,
|
msg32: *const c_uchar,
|
||||||
|
msg_len: size_t,
|
||||||
key32: *const c_uchar,
|
key32: *const c_uchar,
|
||||||
xonly_pk32: *const c_uchar,
|
xonly_pk32: *const c_uchar,
|
||||||
algo16: *const c_uchar,
|
algo16: *const c_uchar,
|
||||||
|
algo_len: size_t,
|
||||||
data: *mut c_void,
|
data: *mut c_void,
|
||||||
) -> c_int>;
|
) -> 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
|
/// A Secp256k1 context, containing various precomputed values and such
|
||||||
/// needed to do elliptic curve computations. If you create one of these
|
/// needed to do elliptic curve computations. If you create one of these
|
||||||
/// with `secp256k1_context_create` you MUST destroy it with
|
/// with `secp256k1_context_create` you MUST destroy it with
|
||||||
|
@ -461,6 +491,17 @@ extern "C" {
|
||||||
aux_rand32: *const c_uchar
|
aux_rand32: *const c_uchar
|
||||||
) -> c_int;
|
) -> 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")]
|
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_schnorrsig_verify")]
|
||||||
pub fn secp256k1_schnorrsig_verify(
|
pub fn secp256k1_schnorrsig_verify(
|
||||||
cx: *const Context,
|
cx: *const Context,
|
||||||
|
|
Loading…
Reference in New Issue