Skip to content

Commit

Permalink
Update secp256k1 submodule to fdc09608036822afc1cebbe0c5b56cebf8ba508d
Browse files Browse the repository at this point in the history
  • Loading branch information
sstone committed Sep 17, 2024
1 parent 4203b06 commit c5b66d3
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 29 deletions.
4 changes: 2 additions & 2 deletions jni/c/headers/java/fr_acinq_secp256k1_Secp256k1CFunctions.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions jni/c/src/fr_acinq_secp256k1_Secp256k1CFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,17 +907,16 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
return jnonce;
}

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)
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)
{
secp256k1_context *ctx = (secp256k1_context *)jctx;
int result = 0;
size_t size;
secp256k1_musig_pubnonce pubnonce;
secp256k1_musig_secnonce secnonce;
jbyte *pubkey_ptr;
secp256k1_pubkey pubkey;
unsigned char seckey[32];
jbyte *seckey;
unsigned char msg32[32];
secp256k1_keypair keypair;
secp256k1_musig_keyagg_cache keyaggcache;
unsigned char extra_input32[32];
jbyteArray jnonce;
Expand All @@ -930,20 +929,15 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jseckey == NULL)
return NULL;

seckey = (*penv)->GetByteArrayElements(penv, jseckey, 0);
result = secp256k1_keypair_create(ctx, &keypair, seckey);
(*penv)->ReleaseByteArrayElements(penv, jseckey, seckey, 0);
CHECKRESULT(!result, "secp256k1_keypair_create failed");

size = (*penv)->GetArrayLength(penv, jseckey);
CHECKRESULT(size != 32, "invalid private key size");
copy_bytes_from_java(penv, jseckey, size, seckey);

if (jpubkey == NULL)
return NULL;

size = (*penv)->GetArrayLength(penv, jpubkey);
CHECKRESULT((size != 33) && (size != 65), "invalid public key size");
pubkey_ptr = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
result = secp256k1_ec_pubkey_parse(ctx, &pubkey, (unsigned char *)pubkey_ptr, size);
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pubkey_ptr, 0);
CHECKRESULT(!result, "secp256k1_ec_pubkey_parse failed");

if (jmsg32 != NULL)
{
size = (*penv)->GetArrayLength(penv, jmsg32);
Expand All @@ -966,7 +960,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
}

result = secp256k1_musig_nonce_gen_counter(ctx, &secnonce, &pubnonce, jcounter,
seckey, &pubkey,
&keypair,
jmsg32 == NULL ? NULL : msg32, jkeyaggcache == NULL ? NULL : &keyaggcache, jextra_input32 == NULL ? NULL : extra_input32);
CHECKRESULT(!result, "secp256k1_musig_nonce_gen failed");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Secp256k1CFunctions {

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);

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);
public static native byte[] secp256k1_musig_nonce_gen_counter(long ctx, long nonrepeating_cnt, byte[] seckey, byte[] msg32, byte[] keyagg_cache, byte[] extra_input32);

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

Expand Down
4 changes: 2 additions & 2 deletions jni/src/main/kotlin/fr/acinq/secp256k1/NativeSecp256k1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public object NativeSecp256k1 : Secp256k1 {
return Secp256k1CFunctions.secp256k1_musig_nonce_gen(Secp256k1Context.getContext(), sessionRandom32, privkey, pubkey, msg32, keyaggCache, extraInput32)
}

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

override fun musigNonceAgg(pubnonces: Array<ByteArray>): ByteArray {
Expand Down
2 changes: 1 addition & 1 deletion native/secp256k1
Submodule secp256k1 updated 71 files
+5 −2 .cirrus.yml
+1 −1 .github/actions/install-homebrew-valgrind/action.yml
+5 −0 .github/actions/run-in-docker-action/action.yml
+104 −31 .github/workflows/ci.yml
+1 −0 .gitignore
+31 −2 CHANGELOG.md
+71 −58 CMakeLists.txt
+1 −0 CONTRIBUTING.md
+11 −0 Makefile.am
+5 −3 README.md
+16 −0 build-aux/m4/bitcoin_secp.m4
+6 −4 ci/ci.sh
+1 −1 ci/linux-debian.Dockerfile
+0 −12 cmake/AllTargetsCompileOptions.cmake
+2 −2 cmake/CheckArm32Assembly.cmake
+18 −0 cmake/CheckMemorySanitizer.cmake
+52 −42 configure.ac
+11 −9 doc/musig.md
+3 −2 doc/release-process.md
+4 −0 examples/CMakeLists.txt
+1 −1 examples/ecdh.c
+1 −1 examples/ecdsa.c
+123 −0 examples/ellswift.c
+67 −23 examples/musig.c
+3 −3 examples/schnorr.c
+1 −1 include/secp256k1.h
+1 −1 include/secp256k1_ellswift.h
+78 −72 include/secp256k1_musig.h
+7 −0 src/checkmem.h
+1 −1 src/ctime_tests.c
+2 −2 src/ecmult_const_impl.h
+108 −13 src/ecmult_gen.h
+2 −2 src/ecmult_gen_compute_table.h
+79 −55 src/ecmult_gen_compute_table_impl.h
+261 −51 src/ecmult_gen_impl.h
+6 −6 src/ecmult_impl.h
+2 −2 src/field.h
+2 −2 src/group.h
+2 −2 src/group_impl.h
+12 −1 src/hsort.h
+39 −30 src/hsort_impl.h
+3 −3 src/modules/ecdh/tests_impl.h
+26 −26 src/modules/ellswift/tests_impl.h
+1 −1 src/modules/extrakeys/Makefile.am.include
+18 −18 src/modules/extrakeys/tests_impl.h
+3 −5 src/modules/musig/keyagg.h
+23 −24 src/modules/musig/keyagg_impl.h
+0 −1 src/modules/musig/main_impl.h
+0 −1 src/modules/musig/session.h
+123 −108 src/modules/musig/session_impl.h
+71 −59 src/modules/musig/tests_impl.h
+5 −5 src/modules/musig/vectors.h
+4 −4 src/modules/recovery/tests_impl.h
+1 −1 src/modules/schnorrsig/main_impl.h
+3 −3 src/modules/schnorrsig/tests_exhaustive_impl.h
+30 −30 src/modules/schnorrsig/tests_impl.h
+49 −28 src/precompute_ecmult_gen.c
+1,767 −9,734 src/precomputed_ecmult_gen.c
+2 −2 src/precomputed_ecmult_gen.h
+4 −4 src/scalar.h
+47 −25 src/scalar_4x64_impl.h
+7 −6 src/scalar_8x32_impl.h
+19 −12 src/scalar_low_impl.h
+8 −14 src/secp256k1.c
+11 −11 src/testrand.h
+22 −22 src/testrand_impl.h
+337 −383 src/tests.c
+6 −6 src/tests_exhaustive.c
+123 −4 src/testutil.h
+16 −1 src/util.h
+1 −1 tools/check-abi.sh
3 changes: 1 addition & 2 deletions src/commonMain/kotlin/fr/acinq/secp256k1/Secp256k1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,12 @@ public interface Secp256k1 {
*
* @param nonRepeatingCounter non-repeating counter that must never be reused with the same private key
* @param privkey signer's private key.
* @param pubkey signer's public key
* @param msg32 (optional) 32-byte message that will be signed, if already known.
* @param keyaggCache (optional) key aggregation cache data from the signing session.
* @param extraInput32 (optional) additional 32-byte random data.
* @return serialized version of the secret nonce and the corresponding public nonce.
*/
public fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, pubkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray
public fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray

/**
* Aggregate public nonces from all participants of a signing session.
Expand Down
8 changes: 4 additions & 4 deletions src/nativeMain/kotlin/fr/acinq/secp256k1/Secp256k1Native.kt
Original file line number Diff line number Diff line change
Expand Up @@ -325,22 +325,22 @@ public object Secp256k1Native : Secp256k1 {
return nonce
}

override fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, pubkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray {
override fun musigNonceGenCounter(nonRepeatingCounter: ULong, privkey: ByteArray, msg32: ByteArray?, keyaggCache: ByteArray?, extraInput32: ByteArray?): ByteArray {
require(privkey.size ==32)
require(pubkey.size == 33 || pubkey.size == 65)
msg32?.let { require(it.size == 32) }
keyaggCache?.let { require(it.size == Secp256k1.MUSIG2_PUBLIC_KEYAGG_CACHE_SIZE) }
extraInput32?.let { require(it.size == 32) }
val nonce = memScoped {
val secnonce = alloc<secp256k1_musig_secnonce>()
val pubnonce = alloc<secp256k1_musig_pubnonce>()
val nPubkey = allocPublicKey(pubkey)
val nKeypair = alloc<secp256k1_keypair>()
secp256k1_keypair_create(ctx, nKeypair.ptr, toNat(privkey))
val nKeyAggCache = keyaggCache?.let {
val n = alloc<secp256k1_musig_keyagg_cache>()
memcpy(n.ptr, toNat(it), Secp256k1.MUSIG2_PUBLIC_KEYAGG_CACHE_SIZE.toULong())
n
}
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")
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")
val nPubnonce = allocArray<UByteVar>(Secp256k1.MUSIG2_PUBLIC_NONCE_SIZE)
secp256k1_musig_pubnonce_serialize(ctx, nPubnonce, pubnonce.ptr).requireSuccess("secp256k1_musig_pubnonce_serialize failed")
secnonce.ptr.readBytes(Secp256k1.MUSIG2_SECRET_NONCE_SIZE) + nPubnonce.readBytes(Secp256k1.MUSIG2_PUBLIC_NONCE_SIZE)
Expand Down
3 changes: 1 addition & 2 deletions tests/src/commonTest/kotlin/fr/acinq/secp256k1/Musig2Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ class Musig2Test {
@Test
fun `generate secret nonce from counter`() {
val sk = Hex.decode("EEC1CB7D1B7254C5CAB0D9C61AB02E643D464A59FE6C96A7EFE871F07C5AEF54")
val pk = Secp256k1.pubkeyCreate(sk)
val nonce = Secp256k1.musigNonceGenCounter(0UL, sk, pk, null, null, null)
val nonce = Secp256k1.musigNonceGenCounter(0UL, sk, null, null, null)
val secnonce = nonce.copyOfRange(0, Secp256k1.MUSIG2_SECRET_NONCE_SIZE)
val pubnonce = nonce.copyOfRange(Secp256k1.MUSIG2_SECRET_NONCE_SIZE, Secp256k1.MUSIG2_SECRET_NONCE_SIZE + Secp256k1.MUSIG2_PUBLIC_NONCE_SIZE)
assertContentEquals(secnonce.copyOfRange(4, 4 + 64), Hex.decode("842F1380CD17A198FC3DAD3B7DA7492941F46976F2702FF7C66F24F472036AF1DA3F952DDE4A2DA6B6325707CE87A4E3616D06FC5F81A9C99386D20A99CECF99"))
Expand Down

0 comments on commit c5b66d3

Please sign in to comment.