@@ -7,12 +7,13 @@ use core::{fmt, ptr, str};
7
7
8
8
#[ cfg( feature = "rand" ) ]
9
9
use rand:: { CryptoRng , Rng } ;
10
+ use secp256k1_sys:: SchnorrSigExtraParams ;
10
11
11
12
use crate :: ffi:: { self , CPtr } ;
12
13
use crate :: key:: { Keypair , XOnlyPublicKey } ;
13
14
#[ cfg( feature = "global-context" ) ]
14
15
use crate :: SECP256K1 ;
15
- use crate :: { constants, from_hex, Error , Message , Secp256k1 , Signing , Verification } ;
16
+ use crate :: { constants, from_hex, Error , Secp256k1 , Signing , Verification } ;
16
17
17
18
/// Represents a schnorr signature.
18
19
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -93,28 +94,30 @@ impl Signature {
93
94
/// Verifies a schnorr signature for `msg` using `pk` and the global [`SECP256K1`] context.
94
95
#[ inline]
95
96
#[ cfg( feature = "global-context" ) ]
96
- pub fn verify ( & self , msg : & Message , pk : & XOnlyPublicKey ) -> Result < ( ) , Error > {
97
+ pub fn verify ( & self , msg : & [ u8 ] , pk : & XOnlyPublicKey ) -> Result < ( ) , Error > {
97
98
SECP256K1 . verify_schnorr ( self , msg, pk)
98
99
}
99
100
}
100
101
101
102
impl < C : Signing > Secp256k1 < C > {
102
103
fn sign_schnorr_helper (
103
104
& self ,
104
- msg : & Message ,
105
+ msg : & [ u8 ] ,
105
106
keypair : & Keypair ,
106
107
nonce_data : * const ffi:: types:: c_uchar ,
107
108
) -> Signature {
108
109
unsafe {
109
110
let mut sig = [ 0u8 ; constants:: SCHNORR_SIGNATURE_SIZE ] ;
111
+ let extra = SchnorrSigExtraParams :: new ( None , nonce_data. cast ( ) ) ;
110
112
assert_eq ! (
111
113
1 ,
112
- ffi:: secp256k1_schnorrsig_sign (
114
+ ffi:: secp256k1_schnorrsig_sign_custom (
113
115
self . ctx. as_ptr( ) ,
114
116
sig. as_mut_c_ptr( ) ,
115
117
msg. as_c_ptr( ) ,
118
+ msg. len( ) ,
116
119
keypair. as_c_ptr( ) ,
117
- nonce_data ,
120
+ & extra ,
118
121
)
119
122
) ;
120
123
@@ -125,19 +128,19 @@ impl<C: Signing> Secp256k1<C> {
125
128
/// Creates a schnorr signature internally using the [`rand::rngs::ThreadRng`] random number
126
129
/// generator to generate the auxiliary random data.
127
130
#[ cfg( feature = "rand-std" ) ]
128
- pub fn sign_schnorr ( & self , msg : & Message , keypair : & Keypair ) -> Signature {
131
+ pub fn sign_schnorr ( & self , msg : & [ u8 ] , keypair : & Keypair ) -> Signature {
129
132
self . sign_schnorr_with_rng ( msg, keypair, & mut rand:: thread_rng ( ) )
130
133
}
131
134
132
135
/// Creates a schnorr signature without using any auxiliary random data.
133
- pub fn sign_schnorr_no_aux_rand ( & self , msg : & Message , keypair : & Keypair ) -> Signature {
136
+ pub fn sign_schnorr_no_aux_rand ( & self , msg : & [ u8 ] , keypair : & Keypair ) -> Signature {
134
137
self . sign_schnorr_helper ( msg, keypair, ptr:: null ( ) )
135
138
}
136
139
137
140
/// Creates a schnorr signature using the given auxiliary random data.
138
141
pub fn sign_schnorr_with_aux_rand (
139
142
& self ,
140
- msg : & Message ,
143
+ msg : & [ u8 ] ,
141
144
keypair : & Keypair ,
142
145
aux_rand : & [ u8 ; 32 ] ,
143
146
) -> Signature {
@@ -149,7 +152,7 @@ impl<C: Signing> Secp256k1<C> {
149
152
#[ cfg( feature = "rand" ) ]
150
153
pub fn sign_schnorr_with_rng < R : Rng + CryptoRng > (
151
154
& self ,
152
- msg : & Message ,
155
+ msg : & [ u8 ] ,
153
156
keypair : & Keypair ,
154
157
rng : & mut R ,
155
158
) -> Signature {
@@ -164,15 +167,15 @@ impl<C: Verification> Secp256k1<C> {
164
167
pub fn verify_schnorr (
165
168
& self ,
166
169
sig : & Signature ,
167
- msg : & Message ,
170
+ msg : & [ u8 ] ,
168
171
pubkey : & XOnlyPublicKey ,
169
172
) -> Result < ( ) , Error > {
170
173
unsafe {
171
174
let ret = ffi:: secp256k1_schnorrsig_verify (
172
175
self . ctx . as_ptr ( ) ,
173
176
sig. as_c_ptr ( ) ,
174
177
msg. as_c_ptr ( ) ,
175
- 32 ,
178
+ msg . len ( ) ,
176
179
pubkey. as_c_ptr ( ) ,
177
180
) ;
178
181
@@ -235,9 +238,7 @@ mod tests {
235
238
}
236
239
237
240
#[ cfg( feature = "rand-std" ) ]
238
- fn sign_helper (
239
- sign : fn ( & Secp256k1 < crate :: All > , & Message , & Keypair , & mut ThreadRng ) -> Signature ,
240
- ) {
241
+ fn sign_helper ( sign : fn ( & Secp256k1 < crate :: All > , & [ u8 ] , & Keypair , & mut ThreadRng ) -> Signature ) {
241
242
let secp = Secp256k1 :: new ( ) ;
242
243
243
244
let mut rng = rand:: thread_rng ( ) ;
@@ -246,7 +247,6 @@ mod tests {
246
247
247
248
for _ in 0 ..100 {
248
249
let msg = crate :: random_32_bytes ( & mut rand:: thread_rng ( ) ) ;
249
- let msg = Message :: from_digest_slice ( & msg) . unwrap ( ) ;
250
250
251
251
let sig = sign ( & secp, & msg, & kp, & mut rng) ;
252
252
@@ -260,8 +260,7 @@ mod tests {
260
260
fn schnorr_sign ( ) {
261
261
let secp = Secp256k1 :: new ( ) ;
262
262
263
- let hex_msg = hex_32 ! ( "E48441762FB75010B2AA31A512B62B4148AA3FB08EB0765D76B252559064A614" ) ;
264
- let msg = Message :: from_digest_slice ( & hex_msg) . unwrap ( ) ;
263
+ let msg = hex_32 ! ( "E48441762FB75010B2AA31A512B62B4148AA3FB08EB0765D76B252559064A614" ) ;
265
264
let sk = Keypair :: from_seckey_str (
266
265
& secp,
267
266
"688C77BC2D5AAFF5491CF309D4753B732135470D05B7B2CD21ADD0744FE97BEF" ,
@@ -282,8 +281,7 @@ mod tests {
282
281
fn schnorr_verify ( ) {
283
282
let secp = Secp256k1 :: new ( ) ;
284
283
285
- let hex_msg = hex_32 ! ( "E48441762FB75010B2AA31A512B62B4148AA3FB08EB0765D76B252559064A614" ) ;
286
- let msg = Message :: from_digest_slice ( & hex_msg) . unwrap ( ) ;
284
+ let msg = hex_32 ! ( "E48441762FB75010B2AA31A512B62B4148AA3FB08EB0765D76B252559064A614" ) ;
287
285
let sig = Signature :: from_str ( "6470FD1303DDA4FDA717B9837153C24A6EAB377183FC438F939E0ED2B620E9EE5077C4A8B8DCA28963D772A94F5F0DDF598E1C47C137F91933274C7C3EDADCE8" ) . unwrap ( ) ;
288
286
let pubkey = XOnlyPublicKey :: from_str (
289
287
"B33CC9EDC096D0A83416964BD3C6247B8FECD256E4EFA7870D2C854BDEB33390" ,
@@ -462,7 +460,7 @@ mod tests {
462
460
463
461
let s = Secp256k1 :: new ( ) ;
464
462
465
- let msg = Message :: from_digest_slice ( & [ 1 ; 32 ] ) . unwrap ( ) ;
463
+ let msg = [ 1 ; 32 ] ;
466
464
let keypair = Keypair :: from_seckey_slice ( & s, & [ 2 ; 32 ] ) . unwrap ( ) ;
467
465
let aux = [ 3u8 ; 32 ] ;
468
466
let sig = s. sign_schnorr_with_aux_rand ( & msg, & keypair, & aux) ;
@@ -506,4 +504,208 @@ mod tests {
506
504
assert_tokens ( & pk. readable ( ) , & [ Token :: Str ( PK_STR ) ] ) ;
507
505
assert_tokens ( & pk. readable ( ) , & [ Token :: String ( PK_STR ) ] ) ;
508
506
}
507
+
508
+ #[ test]
509
+ #[ cfg( feature = "alloc" ) ]
510
+ #[ cfg( not( secp256k1_fuzz) ) ] // fixed sig vectors can't work with fuzz-sigs
511
+ fn bip340_test_vectors ( ) {
512
+ struct TestVector {
513
+ secret_key : Option < [ u8 ; 32 ] > ,
514
+ public_key : [ u8 ; 32 ] ,
515
+ aux_rand : Option < [ u8 ; 32 ] > ,
516
+ message : Vec < u8 > ,
517
+ signature : [ u8 ; 64 ] ,
518
+ should_fail_verify : bool ,
519
+ }
520
+ fn hex_arr < T : From < [ u8 ; N ] > , const N : usize > ( s : & str ) -> T {
521
+ let mut out = [ 0 ; N ] ;
522
+ from_hex ( s, & mut out) . unwrap ( ) ;
523
+ out. into ( )
524
+ }
525
+ let hex_vec = |s : & str | {
526
+ let mut v = vec ! [ 0u8 ; s. len( ) / 2 ] ;
527
+ from_hex ( s, v. as_mut_slice ( ) ) . unwrap ( ) ;
528
+ v
529
+ } ;
530
+
531
+ let vectors = [
532
+ TestVector {
533
+ secret_key : hex_arr ( "0000000000000000000000000000000000000000000000000000000000000003" ) ,
534
+ public_key : hex_arr ( "F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9" ) ,
535
+ aux_rand : hex_arr ( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
536
+ message : hex_vec ( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
537
+ signature : hex_arr ( "E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA821525F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0" ) ,
538
+ should_fail_verify : false ,
539
+ } ,
540
+ TestVector {
541
+ secret_key : hex_arr ( "B7E151628AED2A6ABF7158809CF4F3C762E7160F38B4DA56A784D9045190CFEF" ) ,
542
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
543
+ aux_rand : hex_arr ( "0000000000000000000000000000000000000000000000000000000000000001" ) ,
544
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
545
+ signature : hex_arr ( "6896BD60EEAE296DB48A229FF71DFE071BDE413E6D43F917DC8DCF8C78DE33418906D11AC976ABCCB20B091292BFF4EA897EFCB639EA871CFA95F6DE339E4B0A" ) ,
546
+ should_fail_verify : false ,
547
+ } ,
548
+ TestVector {
549
+ secret_key : hex_arr ( "C90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B14E5C9" ) ,
550
+ public_key : hex_arr ( "DD308AFEC5777E13121FA72B9CC1B7CC0139715309B086C960E18FD969774EB8" ) ,
551
+ aux_rand : hex_arr ( "C87AA53824B4D7AE2EB035A2B5BBBCCC080E76CDC6D1692C4B0B62D798E6D906" ) ,
552
+ message : hex_vec ( "7E2D58D8B3BCDF1ABADEC7829054F90DDA9805AAB56C77333024B9D0A508B75C" ) ,
553
+ signature : hex_arr ( "5831AAEED7B44BB74E5EAB94BA9D4294C49BCF2A60728D8B4C200F50DD313C1BAB745879A5AD954A72C45A91C3A51D3C7ADEA98D82F8481E0E1E03674A6F3FB7" ) ,
554
+ should_fail_verify : false ,
555
+ } ,
556
+ TestVector {
557
+ secret_key : hex_arr ( "0B432B2677937381AEF05BB02A66ECD012773062CF3FA2549E44F58ED2401710" ) ,
558
+ public_key : hex_arr ( "25D1DFF95105F5253C4022F628A996AD3A0D95FBF21D468A1B33F8C160D8F517" ) ,
559
+ aux_rand : hex_arr ( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ) ,
560
+ message : hex_vec ( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ) ,
561
+ signature : hex_arr ( "7EB0509757E246F19449885651611CB965ECC1A187DD51B64FDA1EDC9637D5EC97582B9CB13DB3933705B32BA982AF5AF25FD78881EBB32771FC5922EFC66EA3" ) ,
562
+ should_fail_verify : false ,
563
+ } ,
564
+ TestVector {
565
+ secret_key : None ,
566
+ public_key : hex_arr ( "D69C3509BB99E412E68B0FE8544E72837DFA30746D8BE2AA65975F29D22DC7B9" ) ,
567
+ aux_rand : None ,
568
+ message : hex_vec ( "4DF3C3F68FCC83B27E9D42C90431A72499F17875C81A599B566C9889B9696703" ) ,
569
+ signature : hex_arr ( "00000000000000000000003B78CE563F89A0ED9414F5AA28AD0D96D6795F9C6376AFB1548AF603B3EB45C9F8207DEE1060CB71C04E80F593060B07D28308D7F4" ) ,
570
+ should_fail_verify : false ,
571
+ } ,
572
+ TestVector {
573
+ secret_key : None ,
574
+ public_key : hex_arr ( "EEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34" ) ,
575
+ aux_rand : None ,
576
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
577
+ signature : hex_arr ( "6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E17776969E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B" ) ,
578
+ should_fail_verify : true ,
579
+ } ,
580
+ TestVector {
581
+ secret_key : None ,
582
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
583
+ aux_rand : None ,
584
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
585
+ signature : hex_arr ( "FFF97BD5755EEEA420453A14355235D382F6472F8568A18B2F057A14602975563CC27944640AC607CD107AE10923D9EF7A73C643E166BE5EBEAFA34B1AC553E2" ) ,
586
+ should_fail_verify : true ,
587
+ } ,
588
+ TestVector {
589
+ secret_key : None ,
590
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
591
+ aux_rand : None ,
592
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
593
+ signature : hex_arr ( "1FA62E331EDBC21C394792D2AB1100A7B432B013DF3F6FF4F99FCB33E0E1515F28890B3EDB6E7189B630448B515CE4F8622A954CFE545735AAEA5134FCCDB2BD" ) ,
594
+ should_fail_verify : true ,
595
+ } ,
596
+ TestVector {
597
+ secret_key : None ,
598
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
599
+ aux_rand : None ,
600
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
601
+ signature : hex_arr ( "6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E177769961764B3AA9B2FFCB6EF947B6887A226E8D7C93E00C5ED0C1834FF0D0C2E6DA6" ) ,
602
+ should_fail_verify : true ,
603
+ } ,
604
+ TestVector {
605
+ secret_key : None ,
606
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
607
+ aux_rand : None ,
608
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
609
+ signature : hex_arr ( "0000000000000000000000000000000000000000000000000000000000000000123DDA8328AF9C23A94C1FEECFD123BA4FB73476F0D594DCB65C6425BD186051" ) ,
610
+ should_fail_verify : true ,
611
+ } ,
612
+ TestVector {
613
+ secret_key : None ,
614
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
615
+ aux_rand : None ,
616
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
617
+ signature : hex_arr ( "00000000000000000000000000000000000000000000000000000000000000017615FBAF5AE28864013C099742DEADB4DBA87F11AC6754F93780D5A1837CF197" ) ,
618
+ should_fail_verify : true ,
619
+ } ,
620
+ TestVector {
621
+ secret_key : None ,
622
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
623
+ aux_rand : None ,
624
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
625
+ signature : hex_arr ( "4A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D69E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B" ) ,
626
+ should_fail_verify : true ,
627
+ } ,
628
+ TestVector {
629
+ secret_key : None ,
630
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
631
+ aux_rand : None ,
632
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
633
+ signature : hex_arr ( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F69E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B" ) ,
634
+ should_fail_verify : true ,
635
+ } ,
636
+ TestVector {
637
+ secret_key : None ,
638
+ public_key : hex_arr ( "DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659" ) ,
639
+ aux_rand : None ,
640
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
641
+ signature : hex_arr ( "6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E177769FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141" ) ,
642
+ should_fail_verify : true ,
643
+ } ,
644
+ TestVector {
645
+ secret_key : None ,
646
+ public_key : hex_arr ( "778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117" ) ,
647
+ aux_rand : None ,
648
+ message : hex_vec ( "243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89" ) ,
649
+ signature : hex_arr ( "6CFF5C3BA86C69EA4B7376F31A9BCB4F74C1976089B2D9963DA2E5543E17776969E89B4C5564D00349106B8497785DD7D1D713A8AE82B32FA79D5F7FC407D39B" ) ,
650
+ should_fail_verify : true ,
651
+ } ,
652
+ TestVector {
653
+ secret_key : hex_arr ( "0340034003400340034003400340034003400340034003400340034003400340" ) ,
654
+ public_key : hex_arr ( "778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117" ) ,
655
+ aux_rand : hex_arr ( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
656
+ message : hex_vec ( "" ) ,
657
+ signature : hex_arr ( "71535DB165ECD9FBBC046E5FFAEA61186BB6AD436732FCCC25291A55895464CF6069CE26BF03466228F19A3A62DB8A649F2D560FAC652827D1AF0574E427AB63" ) ,
658
+ should_fail_verify : false ,
659
+ } ,
660
+ TestVector {
661
+ secret_key : hex_arr ( "0340034003400340034003400340034003400340034003400340034003400340" ) ,
662
+ public_key : hex_arr ( "778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117" ) ,
663
+ aux_rand : hex_arr ( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
664
+ message : hex_vec ( "11" ) ,
665
+ signature : hex_arr ( "08A20A0AFEF64124649232E0693C583AB1B9934AE63B4C3511F3AE1134C6A303EA3173BFEA6683BD101FA5AA5DBC1996FE7CACFC5A577D33EC14564CEC2BACBF" ) ,
666
+ should_fail_verify : false ,
667
+ } ,
668
+ TestVector {
669
+ secret_key : hex_arr ( "0340034003400340034003400340034003400340034003400340034003400340" ) ,
670
+ public_key : hex_arr ( "778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117" ) ,
671
+ aux_rand : hex_arr ( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
672
+ message : hex_vec ( "0102030405060708090A0B0C0D0E0F1011" ) ,
673
+ signature : hex_arr ( "5130F39A4059B43BC7CAC09A19ECE52B5D8699D1A71E3C52DA9AFDB6B50AC370C4A482B77BF960F8681540E25B6771ECE1E5A37FD80E5A51897C5566A97EA5A5" ) ,
674
+ should_fail_verify : false ,
675
+ } ,
676
+ TestVector {
677
+ secret_key : hex_arr ( "0340034003400340034003400340034003400340034003400340034003400340" ) ,
678
+ public_key : hex_arr ( "778CAA53B4393AC467774D09497A87224BF9FAB6F6E68B23086497324D6FD117" ) ,
679
+ aux_rand : hex_arr ( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
680
+ message : hex_vec ( "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" ) ,
681
+ signature : hex_arr ( "403B12B0D8555A344175EA7EC746566303321E5DBFA8BE6F091635163ECA79A8585ED3E3170807E7C03B720FC54C7B23897FCBA0E9D0B4A06894CFD249F22367" ) ,
682
+ should_fail_verify : false ,
683
+ } ,
684
+ ] ;
685
+ let secp = Secp256k1 :: new ( ) ;
686
+
687
+ for TestVector {
688
+ secret_key,
689
+ public_key,
690
+ aux_rand,
691
+ message,
692
+ signature,
693
+ should_fail_verify,
694
+ } in vectors
695
+ {
696
+ if let ( Some ( secret_key) , Some ( aux_rand) ) = ( secret_key, aux_rand) {
697
+ let keypair = Keypair :: from_seckey_slice ( & secp, & secret_key) . unwrap ( ) ;
698
+ assert_eq ! ( keypair. x_only_public_key( ) . 0 . serialize( ) , public_key) ;
699
+ let sig = secp. sign_schnorr_with_aux_rand ( & message, & keypair, & aux_rand) ;
700
+ assert_eq ! ( sig. serialize( ) , signature) ;
701
+ }
702
+ let sig = Signature :: from_slice ( & signature) . unwrap ( ) ;
703
+ let is_verified = if let Ok ( pubkey) = XOnlyPublicKey :: from_slice ( & public_key) {
704
+ secp. verify_schnorr ( & sig, & message, & pubkey) . is_ok ( )
705
+ } else {
706
+ false
707
+ } ;
708
+ assert_eq ! ( is_verified, !should_fail_verify) ;
709
+ }
710
+ }
509
711
}
0 commit comments