Increase test and fix some compiler errors on the JNI side.

This commit is contained in:
kngako
2024-08-19 21:40:56 +02:00
parent e7f074d36e
commit b1e96f329b
7 changed files with 439 additions and 161 deletions

View File

@@ -529,6 +529,17 @@ void free_pubkeys(secp256k1_pubkey **pubkeys, size_t count)
free(pubkeys);
}
void free_xonly_pubkeys(secp256k1_xonly_pubkey **pubkeys, size_t count)
{
size_t i;
for (i = 0; i < count; i++)
{
if (pubkeys[i] != NULL)
free(pubkeys[i]);
}
free(pubkeys);
}
/*
* Class: fr_acinq_bitcoin_Secp256k1Bindings
* Method: secp256k1_ec_pubkey_combine
@@ -795,7 +806,7 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1sc
pub = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
result = secp256k1_xonly_pubkey_parse(ctx, &pubkey, (unsigned char *)pub);
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pub, 0);
CHECKRESULT(!result, "secp256k1_ec_pubkey_parse failed");
CHECKRESULT(!result, "secp256k1_xonly_pubkey_parse failed");
sig = (*penv)->GetByteArrayElements(penv, jsig, 0);
msg = (*penv)->GetByteArrayElements(penv, jmsg, 0);
@@ -919,7 +930,7 @@ void free_nonces(secp256k1_musig_pubnonce **nonces, size_t count)
free(nonces);
}
void free_nonces(secp256k1_frost_pubnonce **nonces, size_t count)
void free_frost_nonces(secp256k1_frost_pubnonce **nonces, size_t count)
{
size_t i;
for (i = 0; i < count; i++)
@@ -1359,16 +1370,16 @@ JNIEXPORT jobjectArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp2
{
secp256k1_context *ctx = (secp256k1_context *)jctx;
secp256k1_frost_share **shares;
secp256k1_pubkey **vss_commitment;
secp256k1_frost_share shares[jn_participants];
secp256k1_pubkey vss_commitment[jn_participants];
jbyte* pok64;
size_t size;
size_t size, i;
jbyte *pubkeyBytes;
unsigned char seed32[32];
const jbyte *ids33[jn_participants];
unsigned char *ids33[jn_participants];
if (jctx == 0)
return NULL;
@@ -1392,14 +1403,15 @@ JNIEXPORT jobjectArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp2
CHECKRESULT((*penv)->GetArrayLength(penv, jpok64) != 64, "pok64 length must be 64 bytes");
shares = calloc(jn_participants, sizeof(secp256k1_frost_share*));
vss_commitment = calloc(jthreshold, sizeof(secp256k1_pubkey*));
// shares = calloc(jn_participants, sizeof(secp256k1_frost_share*));
// vss_commitment = calloc(jthreshold, sizeof(secp256k1_pubkey*));
for (i = 0; i < jn_participants; i++)
{
jbyteArray id33 = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jids33, i);
// TODO: Check id33 size is 33...
ids33[i] = (*penv)->GetByteArrayElements(penv, id33, 0); // TODO: use setElement
jbyteArray jid33 = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jids33, i);
size = (*penv)->GetArrayLength(penv, jid33);
CHECKRESULT(size != 33, "invalid id33 size");
copy_bytes_from_java(penv, jid33, 33, ids33[i]);
}
int result = 0;
@@ -1413,7 +1425,7 @@ JNIEXPORT jobjectArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp2
seed32,
jthreshold,
jn_participants,
ids33
(const unsigned char * const*) ids33
);
(*penv)->ReleaseByteArrayElements(penv, jpok64, pok64, 0);
CHECKRESULT(!result, "secp256k1_frost_shares_gen failed");
@@ -1425,7 +1437,7 @@ JNIEXPORT jobjectArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp2
unsigned char out32[32];
for (i = 0; i < jn_participants; i++)
{
result = secp256k1_frost_share_serialize(ctx, out32, shares[i]);
result = secp256k1_frost_share_serialize(ctx, out32, &shares[i]);
CHECKRESULT(!result, "secp256k1_frost_share_serialize failed");
jbyteArray jshare = (*penv)->NewByteArray(penv, 32);
@@ -1481,17 +1493,18 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
secp256k1_xonly_pubkey aggregate_public_key;
jbyteArray jaggregate_public_key;
const secp256k1_frost_share **shares;
secp256k1_frost_share **shares;
jbyteArray jshare;
jbyte *in32;
secp256k1_xonly_pubkey **vss_commitments;
secp256k1_pubkey **vss_commitments;
jbyteArray jvss_commitment;
jbyte *pub;
jbyte *id33;
size_t size, count;
size_t size, count, i;
int result = 0;
jbyteArray jresult;
jbyte *result_ptr = NULL;
@@ -1513,7 +1526,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
CHECKRESULT(jtotalShareCount <= 0, "totalShareCount can't be 0");
CHECKRESULT(jthreshold > jtotalShareCount, "threshold can't be greater then totalShareCount");
count = (*penv)->GetArrayLength(penv, jnonces);
count = (*penv)->GetArrayLength(penv, jshares);
CHECKRESULT(count != jtotalShareCount, "jshares count should be total share count.");
shares = calloc(count, sizeof(secp256k1_frost_share*));
@@ -1537,7 +1550,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
vss_commitments[i] = calloc(1, sizeof(secp256k1_pubkey));
jvss_commitment = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jvss_commitments, i);
size = (*penv)->GetArrayLength(penv, jvss_commitment);
CHECKRESULT1((size != 33) && (size != 65), "invalid public key size", free_pubkeys(pubkeys, count));
CHECKRESULT1((size != 33) && (size != 65), "invalid public key size", free_pubkeys(vss_commitments, count));
pub = (*penv)->GetByteArrayElements(penv, jvss_commitment, 0);
result = secp256k1_ec_pubkey_parse(ctx, vss_commitments[i], (unsigned char *)pub, size);
(*penv)->ReleaseByteArrayElements(penv, jvss_commitment, pub, 0);
@@ -1546,19 +1559,16 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
id33 = (*penv)->GetByteArrayElements(penv, jid33, 0);
int result = 0;
result = secp256k1_frost_share_agg(
ctx,
&aggregate_share,
&aggregate_public_key,
shares,
vss_commitments,
(const secp256k1_frost_share *const *)shares,
(const secp256k1_pubkey *const *)vss_commitments,
jtotalShareCount,
jthreshold,
(unsigned char *)id33
);
result = secp256k1_frost_share_serialize(ctx, result_array, &aggregate_share);
CHECKRESULT(!result, "secp256k1_frost_share_serialize failed");
@@ -1588,25 +1598,29 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
jbyte *id33;
secp256k1_xonly_pubkey *vss_commitment;
jbyte *jpub;
secp256k1_pubkey *vss_commitment;
jbyteArray jpubkey;
jbyte *pub;
size_t size, count;
size_t size, count, i;
if (jctx == 0)
return NULL;
return 0;
if (jid33 == NULL)
return NULL;
return 0;
if (jshare == NULL)
return NULL;
return 0;
if (jvss_commitment == NULL)
return NULL;
return 0;
int result = 0;
CHECKRESULT(jthreshold <= 0, "threshold can't be 0");
size = (*penv)->GetArrayLength(penv, jshare);
CHECKRESULT1(size != sizeof(secp256k1_frost_share), "invalid share size", free(&share));
in32 = (*penv)->GetByteArrayElements(penv, jshare, 0);
@@ -1616,20 +1630,27 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
id33 = (*penv)->GetByteArrayElements(penv, jid33, 0);
jpub = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jvss_commitment, i);
size = (*penv)->GetArrayLength(penv, jpub);
CHECKRESULT1((size != 33) && (size != 65), "invalid public key size", free_pubkeys(pubkeys, count));
jpub = (*penv)->GetByteArrayElements(penv, jpub, 0);
result = secp256k1_ec_pubkey_parse(ctx, &vss_commitment, (unsigned char *)jpub, size);
(*penv)->ReleaseByteArrayElements(penv, jpub, jpub, 0);
CHECKRESULT1(!result, "secp256k1_ec_pubkey_parse failed", free(vss_commitment));
count = (*penv)->GetArrayLength(penv, jvss_commitment);
vss_commitment = calloc(count, sizeof(secp256k1_pubkey *));
int result = secp256k1_frost_share_verify(
for (i = 0; i < count; i++)
{
// vss_commitment[i] = calloc(1, sizeof(secp256k1_pubkey));
jpubkey = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jvss_commitment, i);
size = (*penv)->GetArrayLength(penv, jpubkey);
CHECKRESULT1((size != 33) && (size != 65), "invalid public key size", free(vss_commitment));
pub = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
result = secp256k1_ec_pubkey_parse(ctx, &vss_commitment[i], (unsigned char *)pub, size);
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pub, 0);
CHECKRESULT1(!result, "secp256k1_ec_pubkey_parse failed", free(vss_commitment));
}
result = secp256k1_frost_share_verify(
ctx,
jthreshold,
(unsigned char *)id33,
share,
vss_commitment
&share,
(const secp256k1_pubkey *const *)vss_commitment
);
return result;
@@ -1647,13 +1668,13 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
secp256k1_pubkey pubshare;
jbyte *id33;
jbyte *id33, *jpubkey;
secp256k1_xonly_pubkey **vss_commitments;
secp256k1_pubkey **vss_commitments;
jbyteArray jvss_commitment;
jbyte *jpubkey;
jbyteArray jpubshare;
size_t size, count;
size_t size, count, i;
if (jctx == 0)
return NULL;
@@ -1664,6 +1685,8 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jvss_commitments == NULL)
return NULL;
int result = 0;
CHECKRESULT(jthreshold <= 0, "threshold can't be 0");
CHECKRESULT(jtotalSignersCount <= 0, "totalSignersCount can't be 0");
CHECKRESULT(jthreshold > jtotalSignersCount, "totalSignersCount can't be greater then n_participants");
@@ -1678,29 +1701,29 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
vss_commitments[i] = calloc(1, sizeof(secp256k1_pubkey));
jvss_commitment = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jvss_commitments, i);
size = (*penv)->GetArrayLength(penv, jvss_commitment);
CHECKRESULT1((size != 33) && (size != 65), "invalid public key size", free_pubkeys(pubkeys, count));
CHECKRESULT1((size != 33) && (size != 65), "invalid public key size", free_pubkeys(vss_commitments, count));
jpubkey = (*penv)->GetByteArrayElements(penv, jvss_commitment, 0);
result = secp256k1_ec_pubkey_parse(ctx, vss_commitments[i], (unsigned char *)jpub, size);
(*penv)->ReleaseByteArrayElements(penv, jvss_commitment, jpub, 0);
result = secp256k1_ec_pubkey_parse(ctx, vss_commitments[i], (unsigned char *)jpubkey, size);
(*penv)->ReleaseByteArrayElements(penv, jvss_commitment, jpubkey, 0);
CHECKRESULT1(!result, "secp256k1_ec_pubkey_parse failed", free_pubkeys(vss_commitments, count));
}
int result = secp256k1_frost_compute_pubshare(
result = secp256k1_frost_compute_pubshare(
ctx,
&pubshare,
jthreshold,
(unsigned char *)id33
vss_commitments,
(unsigned char *)id33,
(const secp256k1_pubkey * const*)vss_commitments,
jtotalSignersCount
);
jpubkey = (*penv)->NewByteArray(penv, 65);
jbyte *jpubkeyBytes = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
result = secp256k1_ec_pubkey_serialize(ctx, (unsigned char *)jpubkeyBytes, &size, &pubkey, SECP256K1_EC_UNCOMPRESSED);
(*penv)->ReleaseByteArrayElements(penv, jpubkey, jpubkeyBytes, 0);
jpubshare = (*penv)->NewByteArray(penv, 65);
jbyte *jpubshareBytes = (*penv)->GetByteArrayElements(penv, jpubshare, 0);
result = secp256k1_ec_pubkey_serialize(ctx, (unsigned char *)jpubshareBytes, &size, &pubshare, SECP256K1_EC_UNCOMPRESSED);
(*penv)->ReleaseByteArrayElements(penv, jpubshare, jpubshareBytes, 0);
CHECKRESULT(!result, "secp256k1_ec_pubkey_serialize failed");
return jpubkey;
return jpubshare;
}
/*
@@ -1725,12 +1748,14 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jpublicKey == NULL)
return NULL;
int result = 0;
pub = (*penv)->GetByteArrayElements(penv, jpublicKey, 0);
result = secp256k1_xonly_pubkey_parse(ctx, &public_key, (unsigned char *)pub);
(*penv)->ReleaseByteArrayElements(penv, jpublicKey, pub, 0);
CHECKRESULT(!result, "secp256k1_ec_pubkey_parse failed");
CHECKRESULT(!result, "secp256k1_xonly_pubkey_parse failed");
int result = secp256k1_frost_pubkey_tweak(
result = secp256k1_frost_pubkey_tweak(
ctx,
&tweak_cache,
&public_key
@@ -1759,7 +1784,6 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
jbyteArray jpubkey;
secp256k1_frost_tweak_cache tweak_cache;
jbyte *tweak32 = (*penv)->GetByteArrayElements(penv, jtweak32, 0);;
size_t size, count;
@@ -1776,12 +1800,13 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
CHECKRESULT((*penv)->GetArrayLength(penv, jtweak32) != 32, "tweak must be 32 bytes");
tweak32 = (*penv)->GetByteArrayElements(penv, jtweak32, 0);
// TODO: Release Array Elements...
int result = secp256k1_frost_pubkey_ec_tweak_add(
ctx,
pubkey,
&pubkey,
&tweak_cache,
&public_key
(unsigned char *) tweak32
);
(*penv)->ReleaseByteArrayElements(penv, jtweak32, tweak32, 0);
CHECKRESULT(!result, "secp256k1_frost_pubkey_ec_tweak_add failed");
@@ -1815,7 +1840,6 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
jbyteArray jpubkey;
secp256k1_frost_tweak_cache tweak_cache;
jbyte *tweak32 = (*penv)->GetByteArrayElements(penv, jtweak32, 0);;
size_t size, count;
@@ -1833,12 +1857,13 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
return NULL;
CHECKRESULT((*penv)->GetArrayLength(penv, jtweak32) != 32, "tweak must be 32 bytes");
tweak32 = (*penv)->GetByteArrayElements(penv, jtweak32, 0);
// TODO: Release Array elements...
int result = secp256k1_frost_pubkey_xonly_tweak_add(
ctx,
&pubkey,
&tweak_cache,
&public_key
(unsigned char *) tweak32
);
(*penv)->ReleaseByteArrayElements(penv, jtweak32, tweak32, 0);
@@ -1883,7 +1908,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
jbyte *in32;
jbyte *pubkey_ptr;
secp256k1_pubkey pubkey;
secp256k1_xonly_pubkey pubkey;
unsigned char msg32[32];
secp256k1_musig_keyagg_cache keyaggcache;
unsigned char extra_input32[32];
@@ -1906,7 +1931,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jshare != NULL) {
size = (*penv)->GetArrayLength(penv, jshare);
// TODO: CHECKRESULT1(size != fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_PUBLIC_NONCE_SIZE, "invalid public nonce size", free_nonces(pubnonces, count));
// TODO: CHECKRESULT1(size != fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_PUBLIC_NONCE_SIZE, "invalid public nonce size", free_frost_nonces(pubnonces, count));
in32 = (*penv)->GetByteArrayElements(penv, jshare, 0);
result = secp256k1_frost_share_parse(ctx, &share, (unsigned char *)in32);
(*penv)->ReleaseByteArrayElements(penv, jshare, in32, 0);
@@ -1925,9 +1950,9 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
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);
result = secp256k1_xonly_pubkey_parse(ctx, &pubkey, (unsigned char *)pubkey_ptr);
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pubkey_ptr, 0);
CHECKRESULT(!result, "secp256k1_ec_pubkey_parse failed");
CHECKRESULT(!result, "secp256k1_xonly_pubkey_parse failed");
}
@@ -1945,7 +1970,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
session_id32,
jshare == NULL ? NULL : &share,
jmsg32 == NULL ? NULL : msg32,
jpubkey == NULL ? NULL :pubkey_ptr,
jpubkey == NULL ? NULL : &pubkey,
jextra_input32 == NULL ? NULL : extra_input32
);
@@ -1976,18 +2001,20 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
secp256k1_frost_session session;
secp256k1_frost_pubnonce **pubnonces;
jbyte *in66, *pub, *id33;;
jbyte *in66, *pub, *id33;
jbyteArray jpubnonce;
unsigned char msg32[32];
secp256k1_xonly_pubkey public_key;
const jbyte *ids33[jn_participants];
const jbyte *ids33[n_pubnonces];
secp256k1_frost_tweak_cache tweak_cache;
secp256k1_pubkey adaptor;
size_t size, count;
size_t size, count, i;
if (jctx == 0)
return NULL;
@@ -2007,6 +2034,8 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jids33 == NULL)
return NULL;
int result = 0;
CHECKRESULT(n_pubnonces <= 0, "n_pubnonces can't be 0");
count = (*penv)->GetArrayLength(penv, jpubnonces);
@@ -2018,13 +2047,13 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
for (i = 0; i < count; i++)
{
pubnonces[i] = calloc(1, sizeof(secp256k1_frost_pubnonce));
jnonce = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jpubnonces, i);
size = (*penv)->GetArrayLength(penv, jnonce);
CHECKRESULT1(size != fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_PUBLIC_NONCE_SIZE, "invalid public nonce size", free_nonces(pubnonces, count));
in66 = (*penv)->GetByteArrayElements(penv, jnonce, 0);
jpubnonce = (*penv)->GetObjectArrayElement(penv, jpubnonces, i);
size = (*penv)->GetArrayLength(penv, jpubnonce);
CHECKRESULT1(size != sizeof(secp256k1_frost_pubnonce), "invalid public nonce size", free_frost_nonces(pubnonces, count));
in66 = (*penv)->GetByteArrayElements(penv, jpubnonce, 0);
result = secp256k1_frost_pubnonce_parse(ctx, pubnonces[i], (unsigned char *)in66);
(*penv)->ReleaseByteArrayElements(penv, jnonce, in66, 0);
CHECKRESULT1(!result, "secp256k1_frost_pubnonce_parse failed", free_nonces(pubnonces, count));
(*penv)->ReleaseByteArrayElements(penv, jpubnonce, in66, 0);
CHECKRESULT1(!result, "secp256k1_frost_pubnonce_parse failed", free_frost_nonces(pubnonces, count));
}
size = (*penv)->GetArrayLength(penv, jmsg32);
@@ -2058,13 +2087,16 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jadaptor != NULL)
{
size = (*penv)->GetArrayLength(penv, jadaptor);
CHECKRESULT((size != 33) && (size != 65), "invalid public key size");
pub = (*penv)->GetByteArrayElements(penv, jadaptor, 0);
result = secp256k1_ec_pubkey_parse(ctx, &adaptor, (unsigned char *)pub, pubSize);
result = secp256k1_ec_pubkey_parse(ctx, &adaptor, (unsigned char *)pub, size);
(*penv)->ReleaseByteArrayElements(penv, jadaptor, pub, 0);
CHECKRESULT(!result, "secp256k1_ec_pubkey_parse failed");
}
int result = secp256k1_frost_nonce_process(
result = secp256k1_frost_nonce_process(
ctx,
&session,
(const secp256k1_frost_pubnonce *const *)pubnonces,
@@ -2072,7 +2104,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
msg32,
&public_key,
id33,
ids33,
(const unsigned char * const*) ids33,
jtweak_cache == NULL ? NULL : &tweak_cache,
jadaptor == NULL ? NULL : &adaptor
);
@@ -2122,6 +2154,8 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jsession == NULL)
return NULL;
int result = 0;
copy_bytes_from_java(penv, jsecnonce, fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SECRET_NONCE_SIZE, secnonce.data);
size = (*penv)->GetArrayLength(penv, jagg_share);
@@ -2142,7 +2176,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
}
int result = secp256k1_frost_partial_sign(
result = secp256k1_frost_partial_sign(
ctx,
&partial_sig,
&secnonce,
@@ -2184,19 +2218,21 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
size_t size, count;
if (jctx == 0)
return NULL;
return 0;
if (jpartial_sig == NULL)
return NULL;
return 0;
if (jpubnonce == NULL)
return NULL;
return 0;
if (jpubshare == NULL)
return NULL;
return 0;
if (jsession == NULL)
return NULL;
return 0;
int result = 0;
ptr = (*penv)->GetByteArrayElements(penv, jpartial_sig, 0);
result = secp256k1_frost_partial_sig_parse(ctx, &partial_sig, ptr);
@@ -2208,8 +2244,8 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
(*penv)->ReleaseByteArrayElements(penv, jpubnonce, ptr, 0);
CHECKRESULT(!result, "secp256k1_frost_pubnonce_parse failed");
size = (*penv)->GetArrayLength(penv, jpubkey);
CHECKRESULT((size != 33) && (size != 65), "invalid public key size");
size = (*penv)->GetArrayLength(penv, jpubshare);
CHECKRESULT((size != 33) && (size != 65), "invalid public share size");
pubkeyBytes = (*penv)->GetByteArrayElements(penv, jpubshare, 0);
result = secp256k1_ec_pubkey_parse(ctx, &pubshare, (unsigned char *)pubkeyBytes, size);
@@ -2229,7 +2265,7 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
}
int result = secp256k1_frost_partial_sig_verify(
result = secp256k1_frost_partial_sig_verify(
ctx,
&partial_sig,
&pubnonce,
@@ -2241,7 +2277,7 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
return result;
}
void free_partial_sigs(secp256k1_frost_partial_sig **psigs, size_t count)
void free_frost_partial_sigs(secp256k1_frost_partial_sig **psigs, size_t count)
{
size_t i;
for (i = 0; i < count; i++)
@@ -2288,10 +2324,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
CHECKRESULT(size != sizeof(secp256k1_frost_session), "invalid session size");
copy_bytes_from_java(penv, jsession, size, session.data);
if (jpsigs == NULL)
return NULL;
count = (*penv)->GetArrayLength(penv, jpsigs);
count = (*penv)->GetArrayLength(penv, jpartial_sigs);
CHECKRESULT(count <= 0, "partial sigs count cannot be 0");
psigs = calloc(count, sizeof(secp256k1_frost_partial_sig *));
@@ -2299,13 +2332,13 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
for (i = 0; i < count; i++)
{
psigs[i] = calloc(1, sizeof(secp256k1_frost_partial_sig));
jpsig = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jpsigs, i);
jpsig = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jpartial_sigs, i);
size = (*penv)->GetArrayLength(penv, jpsig);
CHECKRESULT1(size != 32, "invalid partial signature size", free_partial_sigs(psigs, count));
CHECKRESULT1(size != 32, "invalid partial signature size", free_frost_partial_sigs(psigs, count));
ptr = (*penv)->GetByteArrayElements(penv, jpsig, 0);
result = secp256k1_frost_partial_sig_parse(ctx, psigs[i], (unsigned char *)ptr);
(*penv)->ReleaseByteArrayElements(penv, jpsig, ptr, 0);
CHECKRESULT1(!result, "secp256k1_frost_partial_sig_parse failed", free_partial_sigs(psigs, count));
CHECKRESULT1(!result, "secp256k1_frost_partial_sig_parse failed", free_frost_partial_sigs(psigs, count));
}
result = secp256k1_frost_partial_sig_agg(
@@ -2315,7 +2348,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
(const secp256k1_frost_partial_sig *const *)psigs,
jn_sigs
);
free_partial_sigs(psigs, count);
free_frost_partial_sigs(psigs, count);
CHECKRESULT(!result, "secp256k1_frost_partial_sig_agg failed");
jpsig = (*penv)->NewByteArray(penv, 64);