@@ -596,13 +596,13 @@ void frost_sha256_tag_test_internal(secp256k1_sha256 *sha_tagged, unsigned char
596596
597597/* Attempts to create a signature for the group public key using given secret
598598 * keys and keygen_cache. */
599- void frost_tweak_test_helper (const secp256k1_xonly_pubkey * agg_pk , const secp256k1_frost_secshare * sr0 , const secp256k1_frost_secshare * sr1 , const secp256k1_frost_secshare * sr2 , secp256k1_frost_keygen_cache * keygen_cache , const unsigned char * const * ids33 , const secp256k1_pubkey * sr_pk0 , const secp256k1_pubkey * sr_pk1 , const secp256k1_pubkey * sr_pk2 ) {
599+ void frost_tweak_test_helper (const secp256k1_xonly_pubkey * agg_pk , const secp256k1_frost_secshare * sr0 , const secp256k1_frost_secshare * sr1 , const secp256k1_frost_secshare * sr2 , secp256k1_frost_keygen_cache * keygen_cache , const secp256k1_pubkey * sr_pk0 , const secp256k1_pubkey * sr_pk1 , const secp256k1_pubkey * sr_pk2 ) {
600600 unsigned char session_id [3 ][32 ];
601601 unsigned char msg [32 ];
602602 secp256k1_frost_secnonce secnonce [3 ];
603603 secp256k1_frost_pubnonce pubnonce [3 ];
604604 const secp256k1_frost_pubnonce * pubnonce_ptr [3 ];
605- secp256k1_frost_session session [5 ];
605+ secp256k1_frost_session session [3 ];
606606 secp256k1_frost_partial_sig partial_sig [3 ];
607607 const secp256k1_frost_partial_sig * partial_sig_ptr [3 ];
608608 unsigned char final_sig [64 ];
@@ -680,33 +680,30 @@ void frost_tweak_test(void) {
680680 secp256k1_pubkey vss_commitment [3 ];
681681 secp256k1_frost_secshare shares [5 ];
682682 int i ;
683- unsigned char id [5 ][33 ];
684- const unsigned char * id_ptr [5 ];
685683 const secp256k1_pubkey * pubshare_ptr [5 ];
684+ size_t ids [5 ];
686685
687686 /* Key Setup */
688687 for (i = 0 ; i < 5 ; i ++ ) {
689688 secp256k1_testrand256 (sk [i ]);
690- id_ptr [i ] = id [i ];
691689 pubshare_ptr [i ] = & pubshare [i ];
690+ ids [i ] = (size_t )i ;
692691 }
693692 secp256k1_testrand256 (seed );
694- size_t ids [5 ];
695693 CHECK (secp256k1_frost_shares_gen (CTX , shares , vss_commitment , seed , 3 , 5 ) == 1 );
696694 /* CHECK(secp256k1_frost_shares_gen(CTX, shares, vss_commitment, seed, 3, 5, id_ptr) == 1); */
697695 for (i = 0 ; i < 5 ; i ++ ) {
698- CHECK (secp256k1_frost_compute_pubshare (CTX , & pubshare [i ], 3 , i , vss_commitment ) == 1 );
696+ CHECK (secp256k1_frost_compute_pubshare (CTX , & pubshare [i ], 3 , ( size_t ) i , vss_commitment ) == 1 );
699697 pubshare_ptr [i ] = & pubshare [i ];
700- ids [i ] = i ;
701698 /* CHECK(secp256k1_frost_share_verify(CTX, 3, id_ptr[i], &shares[i], vss_commitment) == 1); */
702699 /* CHECK(secp256k1_frost_compute_pubshare(CTX, &pubshare[i], 3, id_ptr[i], vss_commitment) == 1); */
703700 }
704701 CHECK (secp256k1_frost_pubkey_gen (CTX , & keygen_cache , pubshare_ptr , 5 , ids ) == 1 );
702+ CHECK (secp256k1_frost_pubkey_get (CTX , & P [0 ], & keygen_cache ) == 1 );
705703 /* Compute P0 and test signing for it */
706704 /* CHECK(secp256k1_frost_pubkey_gen(CTX, &keygen_cache, pubshare_ptr, 5, id_ptr) == 1); */
707- CHECK (secp256k1_frost_pubkey_get (CTX , & P [0 ], & keygen_cache ) == 1 );
708705 CHECK (secp256k1_xonly_pubkey_from_pubkey (CTX , & P_xonly [0 ], NULL , & P [0 ]));
709- frost_tweak_test_helper (& P_xonly [0 ], & shares [0 ], & shares [1 ], & shares [2 ], & keygen_cache , id_ptr , & pubshare [0 ], & pubshare [1 ], & pubshare [2 ]);
706+ frost_tweak_test_helper (& P_xonly [0 ], & shares [0 ], & shares [1 ], & shares [2 ], & keygen_cache , & pubshare [0 ], & pubshare [1 ], & pubshare [2 ]);
710707
711708 /* Compute Pi = f(Pj) + tweaki*G where where j = i-1 and try signing for */
712709 /* that key. If xonly is set to true, the function f is normalizes the input */
@@ -736,68 +733,65 @@ void frost_tweak_test(void) {
736733 CHECK (secp256k1_memcmp_var (& tmp_key , & P [i ], sizeof (tmp_key )) == 0 );
737734 }
738735 /* Test signing for P[i] */
739- frost_tweak_test_helper (& P_xonly [i ], & shares [0 ], & shares [1 ], & shares [2 ], & keygen_cache , id_ptr , & pubshare [0 ], & pubshare [1 ], & pubshare [2 ]);
736+ frost_tweak_test_helper (& P_xonly [i ], & shares [0 ], & shares [1 ], & shares [2 ], & keygen_cache , & pubshare [0 ], & pubshare [1 ], & pubshare [2 ]);
740737 }
741738}
742739
743740/* Performs a FROST DKG */
744- void frost_dkg_test_helper (secp256k1_frost_keygen_cache * keygen_cache , secp256k1_frost_secshare * shares , const unsigned char * const * ids33 ) {
741+ void frost_dkg_test_helper (secp256k1_frost_keygen_cache * keygen_cache , secp256k1_frost_secshare * shares ) {
745742 secp256k1_pubkey vss_commitment [3 ];
746743 unsigned char seed [32 ];
747744 int i ;
748745 secp256k1_pubkey pubshare [5 ];
749746 const secp256k1_pubkey * pubshare_ptr [5 ];
750-
747+ size_t ids [ 5 ];
751748 secp256k1_testrand256 (seed );
752749 for (i = 0 ; i < 5 ; i ++ ) {
753750 pubshare_ptr [i ] = & pubshare [i ];
751+ ids [i ] = (size_t )i ;
754752 }
755753 CHECK (secp256k1_frost_shares_gen (CTX , shares , vss_commitment , seed , 3 , 5 ) == 1 );
756754 for (i = 0 ; i < 5 ; i ++ ) {
757755 CHECK (secp256k1_frost_compute_pubshare (CTX , & pubshare [i ], 3 , (size_t )i , vss_commitment ) == 1 );
758756 }
759- {
760- size_t ids [5 ] = {0 ,1 ,2 ,3 ,4 };
761- CHECK (secp256k1_frost_pubkey_gen (CTX , keygen_cache , pubshare_ptr , 5 , ids ) == 1 );
762- }
757+ CHECK (secp256k1_frost_pubkey_gen (CTX , keygen_cache , pubshare_ptr , 5 , ids ) == 1 );
763758}
764759
765760/* Signs a message with a FROST keypair */
766- int frost_sign_test_helper (unsigned char * final_sig , const secp256k1_frost_secshare * shares , const unsigned char * const * ids33 , const unsigned char * msg , const secp256k1_pubkey * adaptor , secp256k1_frost_keygen_cache * keygen_cache ) {
761+ int frost_sign_test_helper (unsigned char * pre_sig , const secp256k1_frost_secshare * shares , const unsigned char * msg , const secp256k1_pubkey * adaptor , secp256k1_frost_keygen_cache * keygen_cache ) {
767762 unsigned char session_id [3 ][32 ];
768763 secp256k1_frost_secnonce secnonce [3 ];
769764 secp256k1_frost_pubnonce pubnonce [3 ];
770765 const secp256k1_frost_pubnonce * pubnonce_ptr [3 ];
771766 secp256k1_frost_partial_sig partial_sig [5 ];
772767 const secp256k1_frost_partial_sig * partial_sig_ptr [5 ];
773768 secp256k1_frost_session session [3 ];
769+ size_t ids [3 ];
774770 int i ;
775771 int nonce_parity ;
776772 secp256k1_frost_session_internal session_i ;
777773
778774 for (i = 0 ; i < 3 ; i ++ ) {
779775 pubnonce_ptr [i ] = & pubnonce [i ];
780776 partial_sig_ptr [i ] = & partial_sig [i ];
777+ ids [i ] = (size_t )i ;
781778 }
782779
783780 for (i = 0 ; i < 3 ; i ++ ) {
784781 secp256k1_testrand256 (session_id [i ]);
785782 CHECK (secp256k1_frost_nonce_gen (CTX , & secnonce [i ], & pubnonce [i ], session_id [i ], & shares [i ], NULL , NULL , NULL ) == 1 );
786783 }
787- {
788- size_t ids [3 ] = {0 , 1 , 2 };
789- for (i = 0 ; i < 3 ; i ++ ) {
784+ for (i = 0 ; i < 3 ; i ++ ) {
790785 CHECK (secp256k1_frost_nonce_process (CTX , & session [i ], pubnonce_ptr , 3 , msg , ids [i ], ids , keygen_cache , adaptor ) == 1 );
791- }
792786 }
793787 for (i = 0 ; i < 3 ; i ++ ) {
794788 CHECK (secp256k1_frost_partial_sign (CTX , & partial_sig [i ], & secnonce [i ], & shares [i ], & session [i ], keygen_cache ) == 1 );
795789 }
796- CHECK (secp256k1_frost_partial_sig_agg (CTX , final_sig , & session [0 ], partial_sig_ptr , 3 ) == 1 );
790+ CHECK (secp256k1_frost_partial_sig_agg (CTX , pre_sig , & session [0 ], partial_sig_ptr , 3 ) == 1 );
797791
798- CHECK (secp256k1_frost_nonce_parity (CTX , & nonce_parity , & session ) );
792+ CHECK (secp256k1_frost_nonce_parity (CTX , & nonce_parity , & session [ 0 ]) == 1 );
799793
800- secp256k1_frost_session_load (CTX , & session_i , & session );
794+ CHECK ( secp256k1_frost_session_load (CTX , & session_i , & session [ 0 ]) == 1 );
801795
802796 return nonce_parity ;
803797}
@@ -814,8 +808,6 @@ void frost_multi_hop_lock_tests(void) {
814808 secp256k1_xonly_pubkey pk_a ;
815809 secp256k1_xonly_pubkey pk_b ;
816810 secp256k1_pubkey tmp ;
817- unsigned char sk_a [5 ][32 ];
818- unsigned char sk_b [5 ][32 ];
819811 unsigned char asig_ab [64 ];
820812 unsigned char asig_bc [64 ];
821813 unsigned char pop [32 ];
@@ -831,29 +823,16 @@ void frost_multi_hop_lock_tests(void) {
831823 unsigned char sig_bc [64 ];
832824 int nonce_parity_ab ;
833825 int nonce_parity_bc ;
834- int i ;
835- unsigned char id_a [5 ][33 ];
836- const unsigned char * id_ptr_a [5 ];
837- unsigned char id_b [5 ][33 ];
838- const unsigned char * id_ptr_b [5 ];
839826 secp256k1_frost_keygen_cache cache_a ;
840827 secp256k1_frost_keygen_cache cache_b ;
841828
842829 /* Alice DKG */
843- for (i = 0 ; i < 5 ; i ++ ) {
844- secp256k1_testrand256 (sk_a [i ]);
845- id_ptr_a [i ] = id_a [i ];
846- }
847- frost_dkg_test_helper (& cache_a , shares_a , id_ptr_a );
830+ frost_dkg_test_helper (& cache_a , shares_a );
848831 CHECK (secp256k1_frost_pubkey_get (CTX , & tmp , & cache_a ) == 1 );
849832 CHECK (secp256k1_xonly_pubkey_from_pubkey (CTX , & pk_a , NULL , & tmp ) == 1 );
850833
851834 /* Bob DKG */
852- for (i = 0 ; i < 5 ; i ++ ) {
853- secp256k1_testrand256 (sk_b [i ]);
854- id_ptr_b [i ] = id_b [i ];
855- }
856- frost_dkg_test_helper (& cache_b , shares_b , id_ptr_b );
835+ frost_dkg_test_helper (& cache_b , shares_b );
857836 CHECK (secp256k1_frost_pubkey_get (CTX , & tmp , & cache_b ) == 1 );
858837 CHECK (secp256k1_xonly_pubkey_from_pubkey (CTX , & pk_b , NULL , & tmp ) == 1 );
859838
@@ -876,13 +855,13 @@ void frost_multi_hop_lock_tests(void) {
876855 CHECK (secp256k1_eckey_pubkey_tweak_add (& r_ge , & tp ));
877856 secp256k1_pubkey_save (& r , & r_ge );
878857 /* Encrypt Alice's signature with the left lock as the encryption key */
879- nonce_parity_ab = frost_sign_test_helper (asig_ab , shares_a , id_ptr_a , tx_ab , & l , & cache_a );
858+ nonce_parity_ab = frost_sign_test_helper (asig_ab , shares_a , tx_ab , & l , & cache_a );
880859
881860 /* Bob setup */
882861 CHECK (secp256k1_frost_verify_adaptor (CTX , asig_ab , tx_ab , & pk_a , & l , nonce_parity_ab ) == 1 );
883862 secp256k1_testrand256 (tx_bc );
884863 /* Encrypt Bob's signature with the right lock as the encryption key */
885- nonce_parity_bc = frost_sign_test_helper (asig_bc , shares_b , id_ptr_b , tx_bc , & r , & cache_b );
864+ nonce_parity_bc = frost_sign_test_helper (asig_bc , shares_b , tx_bc , & r , & cache_b );
886865
887866 /* Carol decrypt */
888867 CHECK (secp256k1_frost_verify_adaptor (CTX , asig_bc , tx_bc , & pk_b , & r , nonce_parity_bc ) == 1 );
0 commit comments