@@ -549,9 +549,9 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
549
549
if (jpubkeys == NULL )
550
550
return NULL ;
551
551
552
- count = (* penv )-> GetArrayLength (penv , jpubkeys );
553
- CHECKRESULT (count < 1 , "pubkey array cannot be empty" )
554
- pubkeys = calloc (count , sizeof (secp256k1_pubkey * ));
552
+ count = (* penv )-> GetArrayLength (penv , jpubkeys );
553
+ CHECKRESULT (count < 1 , "pubkey array cannot be empty" )
554
+ pubkeys = calloc (count , sizeof (secp256k1_pubkey * ));
555
555
556
556
for (i = 0 ; i < count ; i ++ )
557
557
{
@@ -907,6 +907,74 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
907
907
return jnonce ;
908
908
}
909
909
910
+ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1musig_1nonce_1gen_1counter (JNIEnv * penv , jclass clazz , jlong jctx , jlong jcounter , jbyteArray jseckey , jbyteArray jmsg32 , jbyteArray jkeyaggcache , jbyteArray jextra_input32 )
911
+ {
912
+ secp256k1_context * ctx = (secp256k1_context * )jctx ;
913
+ int result = 0 ;
914
+ size_t size ;
915
+ secp256k1_musig_pubnonce pubnonce ;
916
+ secp256k1_musig_secnonce secnonce ;
917
+ jbyte * seckey ;
918
+ unsigned char msg32 [32 ];
919
+ secp256k1_keypair keypair ;
920
+ secp256k1_musig_keyagg_cache keyaggcache ;
921
+ unsigned char extra_input32 [32 ];
922
+ jbyteArray jnonce ;
923
+ jbyte * nonce_ptr = NULL ;
924
+ unsigned char nonce [fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SECRET_NONCE_SIZE + fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_PUBLIC_NONCE_SIZE ];
925
+
926
+ if (jctx == 0 )
927
+ return NULL ;
928
+
929
+ if (jseckey == NULL )
930
+ return NULL ;
931
+
932
+ seckey = (* penv )-> GetByteArrayElements (penv , jseckey , 0 );
933
+ result = secp256k1_keypair_create (ctx , & keypair , seckey );
934
+ (* penv )-> ReleaseByteArrayElements (penv , jseckey , seckey , 0 );
935
+ CHECKRESULT (!result , "secp256k1_keypair_create failed" );
936
+
937
+ size = (* penv )-> GetArrayLength (penv , jseckey );
938
+ CHECKRESULT (size != 32 , "invalid private key size" );
939
+ copy_bytes_from_java (penv , jseckey , size , seckey );
940
+
941
+ if (jmsg32 != NULL )
942
+ {
943
+ size = (* penv )-> GetArrayLength (penv , jmsg32 );
944
+ CHECKRESULT (size != 32 , "invalid message size" );
945
+ copy_bytes_from_java (penv , jmsg32 , size , msg32 );
946
+ }
947
+
948
+ if (jkeyaggcache != NULL )
949
+ {
950
+ size = (* penv )-> GetArrayLength (penv , jkeyaggcache );
951
+ CHECKRESULT (size != sizeof (secp256k1_musig_keyagg_cache ), "invalid keyagg cache size" );
952
+ copy_bytes_from_java (penv , jkeyaggcache , size , keyaggcache .data );
953
+ }
954
+
955
+ if (jextra_input32 != NULL )
956
+ {
957
+ size = (* penv )-> GetArrayLength (penv , jextra_input32 );
958
+ CHECKRESULT (size != 32 , "invalid extra input size" );
959
+ copy_bytes_from_java (penv , jextra_input32 , size , extra_input32 );
960
+ }
961
+
962
+ result = secp256k1_musig_nonce_gen_counter (ctx , & secnonce , & pubnonce , jcounter ,
963
+ & keypair ,
964
+ jmsg32 == NULL ? NULL : msg32 , jkeyaggcache == NULL ? NULL : & keyaggcache , jextra_input32 == NULL ? NULL : extra_input32 );
965
+ CHECKRESULT (!result , "secp256k1_musig_nonce_gen failed" );
966
+
967
+ memcpy (nonce , secnonce .data , fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SECRET_NONCE_SIZE );
968
+ result = secp256k1_musig_pubnonce_serialize (ctx , nonce + fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SECRET_NONCE_SIZE , & pubnonce );
969
+ CHECKRESULT (!result , "secp256k1_musig_pubnonce_serialize failed" );
970
+
971
+ jnonce = (* penv )-> NewByteArray (penv , sizeof (nonce ));
972
+ nonce_ptr = (* penv )-> GetByteArrayElements (penv , jnonce , 0 );
973
+ memcpy (nonce_ptr , nonce , sizeof (nonce ));
974
+ (* penv )-> ReleaseByteArrayElements (penv , jnonce , nonce_ptr , 0 );
975
+ return jnonce ;
976
+ }
977
+
910
978
void free_nonces (secp256k1_musig_pubnonce * * nonces , size_t count )
911
979
{
912
980
size_t i ;
0 commit comments