@@ -26,6 +26,8 @@ void test_schnorrsig_api(secp256k1_scratch_space *scratch) {
26
26
unsigned char sk3 [32 ];
27
27
unsigned char msg [32 ];
28
28
unsigned char data32 [32 ];
29
+ unsigned char rand32 [32 ];
30
+ unsigned char rand_commitment32 [32 ];
29
31
unsigned char sig64 [64 ];
30
32
secp256k1_pubkey pk [3 ];
31
33
secp256k1_schnorrsig sig ;
@@ -116,6 +118,39 @@ void test_schnorrsig_api(secp256k1_scratch_space *scratch) {
116
118
CHECK (secp256k1_schnorrsig_verify_s2c_commit (vrfy , & sig , data32 , NULL , nonce_is_negated ) == 0 );
117
119
CHECK (ecount == 4 );
118
120
121
+ secp256k1_rand256 (rand32 );
122
+ ecount = 0 ;
123
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_host_commit (none , rand_commitment32 , rand32 ) == 1 );
124
+ CHECK (ecount == 0 );
125
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_host_commit (none , NULL , rand32 ) == 0 );
126
+ CHECK (ecount == 1 );
127
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_host_commit (none , rand_commitment32 , NULL ) == 0 );
128
+ CHECK (ecount == 2 );
129
+
130
+ ecount = 0 ;
131
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_commit (sign , & s2c_ctx , msg , sk1 , rand_commitment32 ) == 1 );
132
+ CHECK (ecount == 0 );
133
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_commit (none , & s2c_ctx , msg , sk1 , rand_commitment32 ) == 0 );
134
+ CHECK (ecount == 1 );
135
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_commit (sign , NULL , msg , sk1 , rand_commitment32 ) == 0 );
136
+ CHECK (ecount == 2 );
137
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_commit (sign , & s2c_ctx , NULL , sk1 , rand_commitment32 ) == 0 );
138
+ CHECK (ecount == 3 );
139
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_commit (sign , & s2c_ctx , msg , NULL , rand_commitment32 ) == 0 );
140
+ CHECK (ecount == 4 );
141
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_commit (sign , & s2c_ctx , msg , sk1 , NULL ) == 0 );
142
+ CHECK (ecount == 5 );
143
+
144
+ ecount = 0 ;
145
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_setrand (none , & s2c_ctx , rand32 ) == 1 );
146
+ CHECK (ecount == 0 );
147
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_setrand (none , NULL , rand32 ) == 0 );
148
+ CHECK (ecount == 1 );
149
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_setrand (none , & s2c_ctx , NULL ) == 0 );
150
+ CHECK (ecount == 2 );
151
+ CHECK (secp256k1_schnorrsig_sign (sign , & sig , & nonce_is_negated , msg , sk1 , NULL , & s2c_ctx ) == 1 );
152
+ CHECK (secp256k1_schnorrsig_verify_s2c_commit (vrfy , & sig , rand32 , & s2c_ctx .original_pubnonce , nonce_is_negated ) == 1 );
153
+
119
154
ecount = 0 ;
120
155
CHECK (secp256k1_schnorrsig_verify (none , & sig , msg , & pk [0 ]) == 0 );
121
156
CHECK (ecount == 1 );
@@ -780,6 +815,38 @@ void test_schnorrsig_s2c_commit_verify(void) {
780
815
}
781
816
}
782
817
818
+ void test_schnorrsig_anti_nonce_sidechannel (void ) {
819
+ unsigned char msg32 [32 ];
820
+ unsigned char key32 [32 ];
821
+ unsigned char algo16 [16 ];
822
+ unsigned char rand32 [32 ];
823
+ unsigned char rand_commitment32 [32 ];
824
+ secp256k1_s2c_commit_context s2c_ctx ;
825
+ secp256k1_pubkey s2c_original_nonce ;
826
+ secp256k1_schnorrsig sig ;
827
+ int nonce_is_negated ;
828
+
829
+ secp256k1_rand256 (msg32 );
830
+ secp256k1_rand256 (key32 );
831
+ secp256k1_rand256 (rand32 );
832
+ memset (algo16 , 23 , sizeof (algo16 ));
833
+
834
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_host_commit (ctx , rand_commitment32 , rand32 ) == 1 );
835
+
836
+ /* Host sends rand_commitment32 to client. */
837
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_commit (ctx , & s2c_ctx , msg32 , key32 , rand_commitment32 ) == 1 );
838
+
839
+ /* Client sends s2c original nonce. Host replies with rand32. */
840
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_setrand (ctx , & s2c_ctx , rand32 ) == 1 );
841
+ /* Providing wrong data results in an error. */
842
+ CHECK (secp256k1_schnorrsig_anti_nonce_sidechan_client_setrand (ctx , & s2c_ctx , rand_commitment32 ) == 0 );
843
+ CHECK (secp256k1_s2c_commit_get_original_nonce (ctx , & s2c_original_nonce , & s2c_ctx ) == 1 );
844
+ CHECK (secp256k1_schnorrsig_sign (ctx , & sig , & nonce_is_negated , msg32 , key32 , NULL , & s2c_ctx ) == 1 );
845
+
846
+ /* Client sends signature to host. */
847
+ CHECK (secp256k1_schnorrsig_verify_s2c_commit (ctx , & sig , rand32 , & s2c_original_nonce , nonce_is_negated ) == 1 );
848
+ }
849
+
783
850
void run_schnorrsig_tests (void ) {
784
851
int i ;
785
852
secp256k1_scratch_space * scratch = secp256k1_scratch_space_create (ctx , 1024 * 1024 );
@@ -794,6 +861,8 @@ void run_schnorrsig_tests(void) {
794
861
* a test. */
795
862
test_schnorrsig_s2c_commit_verify ();
796
863
}
864
+ test_schnorrsig_anti_nonce_sidechannel ();
865
+
797
866
secp256k1_scratch_space_destroy (scratch );
798
867
}
799
868
0 commit comments