Skip to content

Commit 45a4459

Browse files
committed
Update secp256k1-sys to add schnorr/extra-keys
1 parent cfb5651 commit 45a4459

File tree

4 files changed

+245
-2
lines changed

4 files changed

+245
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ external-symbols = ["secp256k1-sys/external-symbols"]
3434
fuzztarget = ["secp256k1-sys/fuzztarget"]
3535

3636
[dependencies]
37-
secp256k1-sys = { version = "0.3.0", default-features = false, path = "./secp256k1-sys" }
37+
secp256k1-sys = { version = "0.3.1", default-features = false, path = "./secp256k1-sys" }
3838
bitcoin_hashes = { version = "0.9", optional = true }
3939
rand = { version = "0.6", default-features = false, optional = true }
4040
serde = { version = "1.0", default-features = false, optional = true }

secp256k1-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secp256k1-sys"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
55
"Andrew Poelstra <apoelstra@wpsoftware.net>",
66
"Steven Roose <steven@stevenroose.org>" ]

secp256k1-sys/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ fn main() {
3939
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
4040
.define("SECP256K1_BUILD", Some("1"))
4141
.define("ENABLE_MODULE_ECDH", Some("1"))
42+
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
43+
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
4244
.define("ECMULT_GEN_PREC_BITS", Some("4"))
4345
// TODO these three should be changed to use libgmp, at least until secp PR 290 is merged
4446
.define("USE_NUM_NONE", Some("1"))

secp256k1-sys/src/lib.rs

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ pub type EcdhHashFn = unsafe extern "C" fn(
7171
data: *mut c_void,
7272
) -> c_int;
7373

74+
/// Same as secp256k1_nonce function with the exception of accepting an
75+
/// additional pubkey argument and not requiring an attempt argument. The pubkey
76+
/// argument can protect signature schemes with key-prefixed challenge hash
77+
/// inputs against reusing the nonce when signing with the wrong precomputed
78+
/// pubkey.
79+
pub type SchnorrNonceFn = unsafe extern "C" fn(
80+
nonce32: *mut c_uchar,
81+
msg32: *const c_uchar,
82+
key32: *const c_uchar,
83+
xonly_pk32: *const c_uchar,
84+
algo16: *const c_uchar,
85+
data: *mut c_void,
86+
) -> c_int;
87+
7488
/// A Secp256k1 context, containing various precomputed values and such
7589
/// needed to do elliptic curve computations. If you create one of these
7690
/// with `secp256k1_context_create` you MUST destroy it with
@@ -125,6 +139,55 @@ impl Default for Signature {
125139
}
126140
}
127141

142+
#[repr(C)]
143+
pub struct XOnlyPublicKey([c_uchar; 64]);
144+
impl_array_newtype!(XOnlyPublicKey, c_uchar, 64);
145+
impl_raw_debug!(XOnlyPublicKey);
146+
147+
impl XOnlyPublicKey {
148+
/// Create a new (zeroed) x-only public key usable for the FFI interface
149+
pub fn new() -> XOnlyPublicKey { XOnlyPublicKey([0; 64]) }
150+
pub fn from_array(data: [c_uchar; 64]) -> XOnlyPublicKey {
151+
XOnlyPublicKey(data)
152+
}
153+
}
154+
155+
impl hash::Hash for XOnlyPublicKey {
156+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
157+
state.write(&self.0)
158+
}
159+
}
160+
161+
impl Default for XOnlyPublicKey {
162+
fn default() -> Self {
163+
XOnlyPublicKey::new()
164+
}
165+
}
166+
167+
#[repr(C)]
168+
pub struct KeyPair([c_uchar; 96]);
169+
impl_array_newtype!(KeyPair, c_uchar, 96);
170+
impl_raw_debug!(KeyPair);
171+
172+
impl KeyPair {
173+
/// Create a new (zeroed) key pair usable for the FFI interface
174+
pub fn new() -> KeyPair { KeyPair([0; 96]) }
175+
pub fn from_array(data: [c_uchar; 96]) -> KeyPair {
176+
KeyPair(data)
177+
}
178+
}
179+
180+
impl hash::Hash for KeyPair {
181+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
182+
state.write(&self.0)
183+
}
184+
}
185+
186+
impl Default for KeyPair {
187+
fn default() -> Self {
188+
KeyPair::new()
189+
}
190+
}
128191

129192
#[cfg(not(feature = "fuzztarget"))]
130193
extern "C" {
@@ -301,6 +364,92 @@ extern "C" {
301364
hashfp: EcdhHashFn,
302365
data: *mut c_void,
303366
) -> c_int;
367+
368+
369+
// Schnorr Signatures
370+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_nonce_function_bip340")]
371+
pub static secp256k1_nonce_function_bip340: SchnorrNonceFn;
372+
373+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_schnorrsig_sign")]
374+
pub fn secp256k1_schnorrsig_sign(
375+
cx: *const Context,
376+
sig: *mut c_uchar,
377+
msg32: *const c_uchar,
378+
keypair: *const KeyPair,
379+
noncefp: SchnorrNonceFn,
380+
noncedata: *const c_void
381+
) -> c_int;
382+
383+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_schnorrsig_verify")]
384+
pub fn secp256k1_schnorrsig_verify(
385+
cx: *const Context,
386+
sig64: *const c_uchar,
387+
msg32: *const c_uchar,
388+
pubkey: *const XOnlyPublicKey,
389+
) -> c_int;
390+
391+
// Extra keys
392+
393+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_keypair_create")]
394+
pub fn secp256k1_keypair_create(
395+
cx: *const Context,
396+
keypair: *mut KeyPair,
397+
seckey: *const c_uchar,
398+
) -> c_int;
399+
400+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_xonly_pubkey_parse")]
401+
pub fn secp256k1_xonly_pubkey_parse(
402+
cx: *const Context,
403+
pubkey: *mut XOnlyPublicKey,
404+
input32: *const c_uchar,
405+
) -> c_int;
406+
407+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_xonly_pubkey_serialize")]
408+
pub fn secp256k1_xonly_pubkey_serialize(
409+
cx: *const Context,
410+
output32: *mut c_uchar,
411+
pubkey: *const XOnlyPublicKey,
412+
) -> c_int;
413+
414+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_xonly_pubkey_from_pubkey")]
415+
pub fn secp256k1_xonly_pubkey_from_pubkey(
416+
cx: *const Context,
417+
xonly_pubkey: *mut XOnlyPublicKey,
418+
pk_parity: *mut c_int,
419+
pubkey: *const PublicKey,
420+
) -> c_int;
421+
422+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_xonly_pubkey_tweak_add")]
423+
pub fn secp256k1_xonly_pubkey_tweak_add(
424+
cx: *const Context,
425+
output_pubkey: *mut PublicKey,
426+
internal_pubkey: *const XOnlyPublicKey,
427+
tweak32: *const c_uchar,
428+
) -> c_int;
429+
430+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_keypair_xonly_pub")]
431+
pub fn secp256k1_keypair_xonly_pub(
432+
cx: *const Context,
433+
pubkey: *mut XOnlyPublicKey,
434+
pk_parity: *mut c_int,
435+
keypair: *const KeyPair
436+
) -> c_int;
437+
438+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_keypair_xonly_tweak_add")]
439+
pub fn secp256k1_keypair_xonly_tweak_add(
440+
cx: *const Context,
441+
keypair: *mut KeyPair,
442+
tweak32: *const c_uchar,
443+
) -> c_int;
444+
445+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_xonly_pubkey_tweak_add_check")]
446+
pub fn secp256k1_xonly_pubkey_tweak_add_check(
447+
cx: *const Context,
448+
tweaked_pubkey32: *const c_uchar,
449+
tweaked_pubkey_parity: c_int,
450+
internal_pubkey: *const XOnlyPublicKey,
451+
tweak32: *const c_uchar,
452+
) -> c_int;
304453
}
305454

306455

@@ -459,6 +608,7 @@ mod fuzz_dummy {
459608
use self::std::boxed::Box;
460609
use types::*;
461610
use {Signature, Context, NonceFn, EcdhHashFn, PublicKey,
611+
SchnorrNonceFn, XOnlyPublicKey, KeyPair,
462612
SECP256K1_START_NONE, SECP256K1_START_VERIFY, SECP256K1_START_SIGN,
463613
SECP256K1_SER_COMPRESSED, SECP256K1_SER_UNCOMPRESSED};
464614

@@ -470,6 +620,8 @@ mod fuzz_dummy {
470620
pub static secp256k1_ecdh_hash_function_default: EcdhHashFn;
471621
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_nonce_function_rfc6979")]
472622
pub static secp256k1_nonce_function_rfc6979: NonceFn;
623+
#[cfg_attr(not(feature = "external-symbols"), link_name = "rustsecp256k1_v0_3_1_nonce_function_bip340")]
624+
pub static secp256k1_nonce_function_bip340: SchnorrNonceFn;
473625
}
474626

475627
// Contexts
@@ -841,6 +993,95 @@ mod fuzz_dummy {
841993
(*out.offset(16)) = 0x00; // result should always be a valid secret key
842994
1
843995
}
996+
997+
pub unsafe fn secp256k1_schnorrsig_sign(
998+
_cx: *const Context,
999+
_sig: *mut c_uchar,
1000+
_msg32: *const c_uchar,
1001+
_keypair: *const KeyPair,
1002+
_noncefp: SchnorrNonceFn,
1003+
_noncedata: *const c_void
1004+
) -> c_int {
1005+
unimplemented!();
1006+
}
1007+
1008+
pub unsafe fn secp256k1_schnorrsig_verify(
1009+
_cx: *const Context,
1010+
_sig64: *const c_uchar,
1011+
_msg32: *const c_uchar,
1012+
_pubkey: *const XOnlyPublicKey,
1013+
) -> c_int {
1014+
unimplemented!();
1015+
}
1016+
1017+
pub fn secp256k1_xonly_pubkey_parse(
1018+
_cx: *const Context,
1019+
_pubkey: *mut XOnlyPublicKey,
1020+
_input32: *const c_uchar,
1021+
) -> c_int {
1022+
unimplemented!();
1023+
}
1024+
1025+
pub fn secp256k1_xonly_pubkey_serialize(
1026+
_cx: *const Context,
1027+
_output32: *mut c_uchar,
1028+
_pubkey: *const XOnlyPublicKey,
1029+
) -> c_int {
1030+
unimplemented!();
1031+
}
1032+
1033+
pub unsafe fn secp256k1_xonly_pubkey_from_pubkey(
1034+
_cx: *const Context,
1035+
_xonly_pubkey: *mut XOnlyPublicKey,
1036+
_pk_parity: *mut c_int,
1037+
_pubkey: *const PublicKey,
1038+
) -> c_int {
1039+
unimplemented!();
1040+
}
1041+
1042+
pub unsafe fn secp256k1_keypair_create(
1043+
_cx: *const Context,
1044+
_keypair: *mut KeyPair,
1045+
_seckey: *const c_uchar,
1046+
) -> c_int {
1047+
unimplemented!();
1048+
}
1049+
1050+
pub unsafe fn secp256k1_xonly_pubkey_tweak_add(
1051+
_cx: *const Context,
1052+
_output_pubkey: *mut PublicKey,
1053+
_internal_pubkey: *const XOnlyPublicKey,
1054+
_tweak32: *const c_uchar,
1055+
) -> c_int {
1056+
unimplemented!();
1057+
}
1058+
1059+
pub unsafe fn secp256k1_keypair_xonly_pub(
1060+
_cx: *const Context,
1061+
_pubkey: *mut XOnlyPublicKey,
1062+
_pk_parity: *mut c_int,
1063+
_keypair: *const KeyPair
1064+
) -> c_int {
1065+
unimplemented!();
1066+
}
1067+
1068+
pub unsafe fn secp256k1_keypair_xonly_tweak_add(
1069+
_cx: *const Context,
1070+
_keypair: *mut KeyPair,
1071+
_tweak32: *const c_uchar,
1072+
) -> c_int {
1073+
unimplemented!();
1074+
}
1075+
1076+
pub unsafe fn secp256k1_xonly_pubkey_tweak_add_check(
1077+
_cx: *const Context,
1078+
_tweaked_pubkey32: *const c_uchar,
1079+
_tweaked_pubkey_parity: c_int,
1080+
_internal_pubkey: *const XOnlyPublicKey,
1081+
_tweak32: *const c_uchar,
1082+
) -> c_int {
1083+
unimplemented!();
1084+
}
8441085
}
8451086
#[cfg(feature = "fuzztarget")]
8461087
pub use self::fuzz_dummy::*;

0 commit comments

Comments
 (0)