@@ -71,6 +71,20 @@ pub type EcdhHashFn = unsafe extern "C" fn(
71
71
data : * mut c_void ,
72
72
) -> c_int ;
73
73
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
+
74
88
/// A Secp256k1 context, containing various precomputed values and such
75
89
/// needed to do elliptic curve computations. If you create one of these
76
90
/// with `secp256k1_context_create` you MUST destroy it with
@@ -125,6 +139,55 @@ impl Default for Signature {
125
139
}
126
140
}
127
141
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
+ }
128
191
129
192
#[ cfg( not( feature = "fuzztarget" ) ) ]
130
193
extern "C" {
@@ -301,6 +364,92 @@ extern "C" {
301
364
hashfp : EcdhHashFn ,
302
365
data : * mut c_void ,
303
366
) -> 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 ;
304
453
}
305
454
306
455
@@ -459,6 +608,7 @@ mod fuzz_dummy {
459
608
use self :: std:: boxed:: Box ;
460
609
use types:: * ;
461
610
use { Signature , Context , NonceFn , EcdhHashFn , PublicKey ,
611
+ SchnorrNonceFn , XOnlyPublicKey , KeyPair ,
462
612
SECP256K1_START_NONE , SECP256K1_START_VERIFY , SECP256K1_START_SIGN ,
463
613
SECP256K1_SER_COMPRESSED , SECP256K1_SER_UNCOMPRESSED } ;
464
614
@@ -470,6 +620,8 @@ mod fuzz_dummy {
470
620
pub static secp256k1_ecdh_hash_function_default: EcdhHashFn ;
471
621
#[ cfg_attr( not( feature = "external-symbols" ) , link_name = "rustsecp256k1_v0_3_1_nonce_function_rfc6979" ) ]
472
622
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 ;
473
625
}
474
626
475
627
// Contexts
@@ -841,6 +993,95 @@ mod fuzz_dummy {
841
993
( * out. offset ( 16 ) ) = 0x00 ; // result should always be a valid secret key
842
994
1
843
995
}
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
+ }
844
1085
}
845
1086
#[ cfg( feature = "fuzztarget" ) ]
846
1087
pub use self :: fuzz_dummy:: * ;
0 commit comments