Skip to content

Commit 31ac769

Browse files
committed
Update secp256k1 submodule to fdc09608036822afc1cebbe0c5b56cebf8ba508d
1 parent e695b55 commit 31ac769

File tree

8 files changed

+21
-29
lines changed

8 files changed

+21
-29
lines changed

jni/c/headers/java/fr_acinq_secp256k1_Secp256k1CFunctions.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jni/c/src/fr_acinq_secp256k1_Secp256k1CFunctions.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -907,17 +907,16 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
907907
return jnonce;
908908
}
909909

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 jpubkey, jbyteArray jmsg32, jbyteArray jkeyaggcache, jbyteArray jextra_input32)
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)
911911
{
912912
secp256k1_context *ctx = (secp256k1_context *)jctx;
913913
int result = 0;
914914
size_t size;
915915
secp256k1_musig_pubnonce pubnonce;
916916
secp256k1_musig_secnonce secnonce;
917-
jbyte *pubkey_ptr;
918-
secp256k1_pubkey pubkey;
919-
unsigned char seckey[32];
917+
jbyte *seckey;
920918
unsigned char msg32[32];
919+
secp256k1_keypair keypair;
921920
secp256k1_musig_keyagg_cache keyaggcache;
922921
unsigned char extra_input32[32];
923922
jbyteArray jnonce;
@@ -930,20 +929,15 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
930929
if (jseckey == NULL)
931930
return NULL;
932931

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+
933937
size = (*penv)->GetArrayLength(penv, jseckey);
934938
CHECKRESULT(size != 32, "invalid private key size");
935939
copy_bytes_from_java(penv, jseckey, size, seckey);
936940

937-
if (jpubkey == NULL)
938-
return NULL;
939-
940-
size = (*penv)->GetArrayLength(penv, jpubkey);
941-
CHECKRESULT((size != 33) && (size != 65), "invalid public key size");
942-
pubkey_ptr = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
943-
result = secp256k1_ec_pubkey_parse(ctx, &pubkey, (unsigned char *)pubkey_ptr, size);
944-
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pubkey_ptr, 0);
945-
CHECKRESULT(!result, "secp256k1_ec_pubkey_parse failed");
946-
947941
if (jmsg32 != NULL)
948942
{
949943
size = (*penv)->GetArrayLength(penv, jmsg32);
@@ -966,7 +960,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
966960
}
967961

968962
result = secp256k1_musig_nonce_gen_counter(ctx, &secnonce, &pubnonce, jcounter,
969-
seckey, &pubkey,
963+
&keypair,
970964
jmsg32 == NULL ? NULL : msg32, jkeyaggcache == NULL ? NULL : &keyaggcache, jextra_input32 == NULL ? NULL : extra_input32);
971965
CHECKRESULT(!result, "secp256k1_musig_nonce_gen failed");
972966

jni/src/main/java/fr/acinq/secp256k1/Secp256k1CFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class Secp256k1CFunctions {
9191

9292
public static native byte[] secp256k1_musig_nonce_gen(long ctx, byte[] session_rand32, byte[] seckey, byte[] pubkey, byte[] msg32, byte[] keyagg_cache, byte[] extra_input32);
9393

94-
public static native byte[] secp256k1_musig_nonce_gen_counter(long ctx, long nonrepeating_cnt, byte[] seckey, byte[] pubkey, byte[] msg32, byte[] keyagg_cache, byte[] extra_input32);
94+
public static native byte[] secp256k1_musig_nonce_gen_counter(long ctx, long nonrepeating_cnt, byte[] seckey, byte[] msg32, byte[] keyagg_cache, byte[] extra_input32);
9595

9696
public static native byte[] secp256k1_musig_nonce_agg(long ctx, byte[][] nonces);
9797

jni/src/main/kotlin/fr/acinq/secp256k1/NativeSecp256k1.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public object NativeSecp256k1 : Secp256k1 {
9696
return Secp256k1CFunctions.secp256k1_musig_nonce_gen(Secp256k1Context.getContext(), sessionRandom32, privkey, pubkey, msg32, keyaggCache, extraInput32)
9797
}
9898

99-
override fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, pubkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray {
100-
return Secp256k1CFunctions.secp256k1_musig_nonce_gen_counter(Secp256k1Context.getContext(), nonRepeatingCounter.toLong(), privkey, pubkey, msg32, keyaggCache, extraInput32)
99+
override fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray {
100+
return Secp256k1CFunctions.secp256k1_musig_nonce_gen_counter(Secp256k1Context.getContext(), nonRepeatingCounter.toLong(), privkey, msg32, keyaggCache, extraInput32)
101101
}
102102

103103
override fun musigNonceAgg(pubnonces: Array<ByteArray>): ByteArray {

native/secp256k1

Submodule secp256k1 updated 71 files

src/commonMain/kotlin/fr/acinq/secp256k1/Secp256k1.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,12 @@ public interface Secp256k1 {
176176
*
177177
* @param nonRepeatingCounter non-repeating counter that must never be reused with the same private key
178178
* @param privkey signer's private key.
179-
* @param pubkey signer's public key
180179
* @param msg32 (optional) 32-byte message that will be signed, if already known.
181180
* @param keyaggCache (optional) key aggregation cache data from the signing session.
182181
* @param extraInput32 (optional) additional 32-byte random data.
183182
* @return serialized version of the secret nonce and the corresponding public nonce.
184183
*/
185-
public fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, pubkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray
184+
public fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray
186185

187186
/**
188187
* Aggregate public nonces from all participants of a signing session.

src/nativeMain/kotlin/fr/acinq/secp256k1/Secp256k1Native.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,22 +325,22 @@ public object Secp256k1Native : Secp256k1 {
325325
return nonce
326326
}
327327

328-
override fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, pubkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray {
328+
override fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray {
329329
require(privkey.size ==32)
330-
require(pubkey.size == 33 || pubkey.size == 65)
331330
msg32?.let { require(it.size == 32) }
332331
keyaggCache?.let { require(it.size == Secp256k1.MUSIG2_PUBLIC_KEYAGG_CACHE_SIZE) }
333332
extraInput32?.let { require(it.size == 32) }
334333
val nonce = memScoped {
335334
val secnonce = alloc<secp256k1_musig_secnonce>()
336335
val pubnonce = alloc<secp256k1_musig_pubnonce>()
337-
val nPubkey = allocPublicKey(pubkey)
336+
val nKeypair = alloc<secp256k1_keypair>()
337+
secp256k1_keypair_create(ctx, nKeypair.ptr, toNat(privkey))
338338
val nKeyAggCache = keyaggCache?.let {
339339
val n = alloc<secp256k1_musig_keyagg_cache>()
340340
memcpy(n.ptr, toNat(it), Secp256k1.MUSIG2_PUBLIC_KEYAGG_CACHE_SIZE.toULong())
341341
n
342342
}
343-
secp256k1_musig_nonce_gen_counter(ctx, secnonce.ptr, pubnonce.ptr, nonRepeatingCounter, toNat(privkey), nPubkey.ptr, msg32?.let { toNat(it) },nKeyAggCache?.ptr, extraInput32?.let { toNat(it) }).requireSuccess("secp256k1_musig_nonce_gen_counter() failed")
343+
secp256k1_musig_nonce_gen_counter(ctx, secnonce.ptr, pubnonce.ptr, nonRepeatingCounter, nKeypair.ptr, msg32?.let { toNat(it) },nKeyAggCache?.ptr, extraInput32?.let { toNat(it) }).requireSuccess("secp256k1_musig_nonce_gen_counter() failed")
344344
val nPubnonce = allocArray<UByteVar>(Secp256k1.MUSIG2_PUBLIC_NONCE_SIZE)
345345
secp256k1_musig_pubnonce_serialize(ctx, nPubnonce, pubnonce.ptr).requireSuccess("secp256k1_musig_pubnonce_serialize failed")
346346
secnonce.ptr.readBytes(Secp256k1.MUSIG2_SECRET_NONCE_SIZE) + nPubnonce.readBytes(Secp256k1.MUSIG2_PUBLIC_NONCE_SIZE)

tests/src/commonTest/kotlin/fr/acinq/secp256k1/Musig2Test.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ class Musig2Test {
9393
@Test
9494
fun `generate secret nonce from counter`() {
9595
val sk = Hex.decode("EEC1CB7D1B7254C5CAB0D9C61AB02E643D464A59FE6C96A7EFE871F07C5AEF54")
96-
val pk = Secp256k1.pubkeyCreate(sk)
97-
val nonce = Secp256k1.musigNonceGenCounter(0UL, sk, pk, null, null, null)
96+
val nonce = Secp256k1.musigNonceGenCounter(0UL, sk, null, null, null)
9897
val secnonce = nonce.copyOfRange(0, Secp256k1.MUSIG2_SECRET_NONCE_SIZE)
9998
val pubnonce = nonce.copyOfRange(Secp256k1.MUSIG2_SECRET_NONCE_SIZE, Secp256k1.MUSIG2_SECRET_NONCE_SIZE + Secp256k1.MUSIG2_PUBLIC_NONCE_SIZE)
10099
assertContentEquals(secnonce.copyOfRange(4, 4 + 64), Hex.decode("842F1380CD17A198FC3DAD3B7DA7492941F46976F2702FF7C66F24F472036AF1DA3F952DDE4A2DA6B6325707CE87A4E3616D06FC5F81A9C99386D20A99CECF99"))

0 commit comments

Comments
 (0)