@@ -706,6 +706,33 @@ void scriptless_atomic_swap(secp256k1_scratch_space *scratch) {
706
706
CHECK (secp256k1_schnorrsig_verify (ctx , & final_sig_a , msg32_a , & combined_pk_a ) == 1 );
707
707
}
708
708
709
+ /* Checks that hash initialized by secp256k1_musig_sha256_init_tagged has the
710
+ * expected state. */
711
+ void sha256_tag_test (void ) {
712
+ char tag [17 ] = "MuSig coefficient" ;
713
+ secp256k1_sha256 sha ;
714
+ secp256k1_sha256 sha_tagged ;
715
+ unsigned char buf [32 ];
716
+ size_t i ;
717
+
718
+ secp256k1_sha256_initialize (& sha );
719
+ secp256k1_sha256_write (& sha , (unsigned char * ) tag , 17 );
720
+ secp256k1_sha256_finalize (& sha , buf );
721
+ /* buf = SHA256("MuSig coefficient") */
722
+
723
+ secp256k1_sha256_initialize (& sha );
724
+ secp256k1_sha256_write (& sha , buf , 32 );
725
+ secp256k1_sha256_write (& sha , buf , 32 );
726
+ /* Is buffer fully consumed? */
727
+ CHECK ((sha .bytes & 0x3F ) == 0 );
728
+
729
+ /* Compare with tagged SHA */
730
+ secp256k1_musig_sha256_init_tagged (& sha_tagged );
731
+ for (i = 0 ; i < 8 ; i ++ ) {
732
+ CHECK (sha_tagged .s [i ] == sha .s [i ]);
733
+ }
734
+ }
735
+
709
736
void run_musig_tests (void ) {
710
737
int i ;
711
738
secp256k1_scratch_space * scratch = secp256k1_scratch_space_create (ctx , 1024 * 1024 );
@@ -716,6 +743,7 @@ void run_musig_tests(void) {
716
743
/* Run multiple times to ensure that the nonce is negated in some tests */
717
744
scriptless_atomic_swap (scratch );
718
745
}
746
+ sha256_tag_test ();
719
747
720
748
secp256k1_scratch_space_destroy (scratch );
721
749
}
0 commit comments