Skip to content

Commit 4beebd1

Browse files
committed
Add secp256k1_schnorrsig_sign_custom to sys crate
1 parent a0064c2 commit 4beebd1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

secp256k1-sys/src/lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,42 @@ pub type EcdhHashFn = Option<unsafe extern "C" fn(
8787
pub type SchnorrNonceFn = Option<unsafe extern "C" fn(
8888
nonce32: *mut c_uchar,
8989
msg32: *const c_uchar,
90+
msg_len: size_t,
9091
key32: *const c_uchar,
9192
xonly_pk32: *const c_uchar,
9293
algo16: *const c_uchar,
94+
algo_len: size_t,
9395
data: *mut c_void,
9496
) -> c_int>;
9597

98+
/// Data structure that contains additional arguments for schnorrsig_sign_custom.
99+
#[repr(C)]
100+
pub struct SchnorrSigExtraParams {
101+
magic: [c_uchar; 4],
102+
nonce_fp: SchnorrNonceFn,
103+
ndata: *const c_void,
104+
}
105+
106+
impl SchnorrSigExtraParams {
107+
/// Create a new SchnorrSigExtraParams properly initialized.
108+
///
109+
/// `nonce_fp`: pointer to a nonce generation function. If NULL
110+
/// rustsecp256k1_v0_5_0_nonce_function_bip340 is used
111+
///
112+
/// `ndata`: pointer to arbitrary data used by the nonce generation function
113+
/// (can be NULL). If it is non-NULL and
114+
/// rustsecp256k1_v0_5_0_nonce_function_bip340 is used,
115+
/// then ndata must be a pointer to 32-byte auxiliary randomness as per
116+
/// BIP-340.
117+
pub fn new(nonce_fp: SchnorrNonceFn, ndata: *const c_void) -> Self {
118+
SchnorrSigExtraParams {
119+
magic: [0xda, 0x6f, 0xb3, 0x8c],
120+
nonce_fp,
121+
ndata,
122+
}
123+
}
124+
}
125+
96126
/// A Secp256k1 context, containing various precomputed values and such
97127
/// needed to do elliptic curve computations. If you create one of these
98128
/// with `secp256k1_context_create` you MUST destroy it with
@@ -461,6 +491,17 @@ extern "C" {
461491
aux_rand32: *const c_uchar
462492
) -> c_int;
463493

494+
// Schnorr Signatures with extra parameters (see [`SchnorrSigExtraParams`])
495+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_schnorrsig_sign_custom")]
496+
pub fn secp256k1_schnorrsig_sign_custom(
497+
cx: *const Context,
498+
sig: *mut c_uchar,
499+
msg: *const c_uchar,
500+
msg_len: size_t,
501+
keypair: *const KeyPair,
502+
extra_params: *const SchnorrSigExtraParams,
503+
) -> c_int;
504+
464505
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_5_0_schnorrsig_verify")]
465506
pub fn secp256k1_schnorrsig_verify(
466507
cx: *const Context,

0 commit comments

Comments
 (0)