Skip to content

Commit ff77611

Browse files
committed
Add Rust FFI for Musig2 module
1 parent a21d6ca commit ff77611

File tree

1 file changed

+186
-0
lines changed

1 file changed

+186
-0
lines changed

secp256k1-sys/src/lib.rs

+186
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,147 @@ extern "C" {
672672
hashfp: EllswiftEcdhHashFn,
673673
data: *mut c_void)
674674
-> c_int;
675+
676+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_pubnonce_parse")]
677+
pub fn secp256k1_musig_pubnonce_parse(
678+
cx: *const Context,
679+
nonce: *mut MusigPubNonce,
680+
in66: *const c_uchar,
681+
) -> c_int;
682+
683+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_pubnonce_serialize")]
684+
pub fn secp256k1_musig_pubnonce_serialize(
685+
cx: *const Context,
686+
out66: *mut c_uchar,
687+
nonce: *const MusigPubNonce,
688+
) -> c_int;
689+
690+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_aggnonce_parse")]
691+
pub fn secp256k1_musig_aggnonce_parse(
692+
cx: *const Context,
693+
nonce: *mut MusigAggNonce,
694+
in66: *const c_uchar,
695+
) -> c_int;
696+
697+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_aggnonce_serialize")]
698+
pub fn secp256k1_musig_aggnonce_serialize(
699+
cx: *const Context,
700+
out66: *mut c_uchar,
701+
nonce: *const MusigAggNonce,
702+
) -> c_int;
703+
704+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_partial_sig_parse")]
705+
pub fn secp256k1_musig_partial_sig_parse(
706+
cx: *const Context,
707+
sig: *mut MusigPartialSignature,
708+
in32: *const c_uchar,
709+
) -> c_int;
710+
711+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_partial_sig_serialize")]
712+
pub fn secp256k1_musig_partial_sig_serialize(
713+
cx: *const Context,
714+
out32: *mut c_uchar,
715+
sig: *const MusigPartialSignature,
716+
) -> c_int;
717+
718+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_pubkey_agg")]
719+
pub fn secp256k1_musig_pubkey_agg(
720+
cx: *const Context,
721+
agg_pk: *mut XOnlyPublicKey,
722+
keyagg_cache: *mut MusigKeyAggCache,
723+
pubkeys: *const *const PublicKey,
724+
n_pubkeys: size_t,
725+
) -> c_int;
726+
727+
#[cfg_attr(not(rust_secp_no_symbol_renaming),link_name = "rustsecp256k1_v0_11_musig_pubkey_get")]
728+
pub fn secp256k1_musig_pubkey_get(
729+
cx: *const Context,
730+
agg_pk: *mut PublicKey,
731+
keyagg_cache: *const MusigKeyAggCache,
732+
) -> c_int;
733+
734+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_pubkey_ec_tweak_add")]
735+
pub fn secp256k1_musig_pubkey_ec_tweak_add(
736+
cx: *const Context,
737+
output_pubkey: *mut PublicKey,
738+
keyagg_cache: *mut MusigKeyAggCache,
739+
tweak32: *const c_uchar,
740+
) -> c_int;
741+
742+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_pubkey_xonly_tweak_add")]
743+
pub fn secp256k1_musig_pubkey_xonly_tweak_add(
744+
cx: *const Context,
745+
output_pubkey: *mut PublicKey,
746+
keyagg_cache: *mut MusigKeyAggCache,
747+
tweak32: *const c_uchar,
748+
) -> c_int;
749+
750+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_nonce_gen")]
751+
pub fn secp256k1_musig_nonce_gen(
752+
cx: *const Context,
753+
secnonce: *mut MusigSecNonce,
754+
pubnonce: *mut MusigPubNonce,
755+
session_secrand32: *const c_uchar,
756+
seckey: *const c_uchar,
757+
pubkey: *const PublicKey,
758+
msg32: *const c_uchar,
759+
keyagg_cache: *const MusigKeyAggCache,
760+
extra_input32: *const c_uchar,
761+
) -> c_int;
762+
763+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_nonce_agg")]
764+
pub fn secp256k1_musig_nonce_agg(
765+
cx: *const Context,
766+
aggnonce: *mut MusigAggNonce,
767+
pubnonces: *const *const MusigPubNonce,
768+
n_pubnonces: size_t,
769+
) -> c_int;
770+
771+
772+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_nonce_process")]
773+
pub fn secp256k1_musig_nonce_process(
774+
cx: *const Context,
775+
session: *mut MusigSession,
776+
aggnonce: *const MusigAggNonce,
777+
msg32: *const c_uchar,
778+
keyagg_cache: *const MusigKeyAggCache,
779+
) -> c_int;
780+
781+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_partial_sign")]
782+
pub fn secp256k1_musig_partial_sign(
783+
cx: *const Context,
784+
partial_sig: *mut MusigPartialSignature,
785+
secnonce: *mut MusigSecNonce,
786+
keypair: *const Keypair,
787+
keyagg_cache: *const MusigKeyAggCache,
788+
session: *const MusigSession,
789+
) -> c_int;
790+
791+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_partial_sig_verify")]
792+
pub fn secp256k1_musig_partial_sig_verify(
793+
cx: *const Context,
794+
partial_sig: *const MusigPartialSignature,
795+
pubnonce: *const MusigPubNonce,
796+
pubkey: *const PublicKey,
797+
keyagg_cache: *const MusigKeyAggCache,
798+
session: *const MusigSession,
799+
) -> c_int;
800+
801+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_musig_partial_sig_agg")]
802+
pub fn secp256k1_musig_partial_sig_agg(
803+
cx: *const Context,
804+
sig64: *mut c_uchar,
805+
session: *const MusigSession,
806+
partial_sigs: *const *const MusigPartialSignature,
807+
n_sigs: size_t,
808+
) -> c_int;
809+
810+
#[cfg_attr(not(rust_secp_no_symbol_renaming), link_name = "rustsecp256k1_v0_11_ec_pubkey_sort")]
811+
pub fn secp256k1_ec_pubkey_sort(
812+
ctx: *const Context,
813+
pubkeys: *mut *const PublicKey,
814+
n_pubkeys: size_t
815+
) -> c_int;
675816
}
676817

677818
#[cfg(not(secp256k1_fuzz))]
@@ -1098,6 +1239,51 @@ impl <T: CPtr> CPtr for Option<T> {
10981239
}
10991240
}
11001241

1242+
pub const MUSIG_KEYAGG_LEN: usize = 197;
1243+
pub const MUSIG_SECNONCE_LEN: usize = 132;
1244+
pub const MUSIG_PUBNONCE_LEN: usize = 132;
1245+
pub const MUSIG_AGGNONCE_LEN: usize = 132;
1246+
pub const MUSIG_AGGNONCE_SERIALIZED_LEN: usize = 66;
1247+
pub const MUSIG_PUBNONCE_SERIALIZED_LEN: usize = 66;
1248+
pub const MUSIG_SESSION_LEN: usize = 133;
1249+
pub const MUSIG_PART_SIG_LEN: usize = 36;
1250+
1251+
#[repr(C)]
1252+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1253+
pub struct MusigKeyAggCache([c_uchar; MUSIG_KEYAGG_LEN]);
1254+
impl_array_newtype!(MusigKeyAggCache, c_uchar, MUSIG_KEYAGG_LEN);
1255+
impl_raw_debug!(MusigKeyAggCache);
1256+
1257+
#[repr(C)]
1258+
#[derive(Copy, Clone, PartialEq, Eq)]
1259+
pub struct MusigSecNonce([c_uchar; MUSIG_SECNONCE_LEN]);
1260+
impl_array_newtype!(MusigSecNonce, c_uchar, MUSIG_SECNONCE_LEN);
1261+
impl_raw_debug!(MusigSecNonce);
1262+
1263+
#[repr(C)]
1264+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1265+
pub struct MusigPubNonce([c_uchar; MUSIG_PUBNONCE_LEN]);
1266+
impl_array_newtype!(MusigPubNonce, c_uchar, MUSIG_PUBNONCE_LEN);
1267+
impl_raw_debug!(MusigPubNonce);
1268+
1269+
#[repr(C)]
1270+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1271+
pub struct MusigAggNonce([c_uchar; MUSIG_AGGNONCE_LEN]);
1272+
impl_array_newtype!(MusigAggNonce, c_uchar, MUSIG_AGGNONCE_LEN);
1273+
impl_raw_debug!(MusigAggNonce);
1274+
1275+
#[repr(C)]
1276+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1277+
pub struct MusigSession([c_uchar; MUSIG_SESSION_LEN]);
1278+
impl_array_newtype!(MusigSession, c_uchar, MUSIG_SESSION_LEN);
1279+
impl_raw_debug!(MusigSession);
1280+
1281+
#[repr(C)]
1282+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1283+
pub struct MusigPartialSignature([c_uchar; MUSIG_PART_SIG_LEN]);
1284+
impl_array_newtype!(MusigPartialSignature, c_uchar, MUSIG_PART_SIG_LEN);
1285+
impl_raw_debug!(MusigPartialSignature);
1286+
11011287
#[cfg(secp256k1_fuzz)]
11021288
mod fuzz_dummy {
11031289
use super::*;

0 commit comments

Comments
 (0)