Most test cases on JNI

This commit is contained in:
kngako
2024-08-20 01:05:29 +02:00
parent af3f44f426
commit 08f0304d4c
3 changed files with 164 additions and 45 deletions

View File

@@ -1390,7 +1390,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jids33 == NULL)
return NULL;
CHECKRESULT(jthreshold <= 0, "threshold can't be 0");
CHECKRESULT(jthreshold <= 1, "threshold can't be less then 1");
CHECKRESULT(jn_participants <= 0, "n_participants can't be 0");
CHECKRESULT(jthreshold > jn_participants, "threshold can't be greater then n_participants");
@@ -1512,8 +1512,8 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jid33 == NULL)
return NULL;
CHECKRESULT(jthreshold <= 0, "threshold can't be 0");
CHECKRESULT(jtotalShareCount <= 0, "totalShareCount can't be 0");
CHECKRESULT(jthreshold <= 1, "threshold can't be less then 1");
CHECKRESULT(jtotalShareCount <= 1, "totalShareCount can't be 0");
CHECKRESULT(jthreshold > jtotalShareCount, "threshold can't be greater then totalShareCount");
count = (*penv)->GetArrayLength(penv, jshares);
@@ -1547,7 +1547,6 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
for (int j = 0; j < jthreshold; j++)
{
// vss_commitment[i] = calloc(1, sizeof(secp256k1_pubkey));
jvss_commitment_bytes = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jvss_commitment, j);
size = (*penv)->GetArrayLength(penv, jvss_commitment_bytes);
CHECKRESULT1(size != 65, "invalid vss commitment size", free_pubkeys(vss_commitments, count));
@@ -1600,6 +1599,8 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
jbyte *id33;
secp256k1_pubkey *vss_commitment;
jbyteArray jvss_commitment_bytes;
jbyteArray jpubkey;
jbyte *pub;
@@ -1619,7 +1620,7 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
int result = 0;
CHECKRESULT(jthreshold <= 0, "threshold can't be 0");
CHECKRESULT(jthreshold <= 1, "threshold can't be less then 1");
size = (*penv)->GetArrayLength(penv, jshare);
@@ -1632,18 +1633,18 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
id33 = (*penv)->GetByteArrayElements(penv, jid33, 0);
count = (*penv)->GetArrayLength(penv, jvss_commitment);
vss_commitment = calloc(count, sizeof(secp256k1_pubkey *));
CHECKRESULT(count != jthreshold, "vss_commitment needs to be the same as the threshold");
vss_commitment = calloc(jthreshold, sizeof(secp256k1_pubkey));
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));
jvss_commitment_bytes = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jvss_commitment, i);
size = (*penv)->GetArrayLength(penv, jvss_commitment_bytes);
CHECKRESULT1(size != 65, "invalid vss commitment size", free(vss_commitment));
pub = (*penv)->GetByteArrayElements(penv, jvss_commitment_bytes, 0);
result = secp256k1_ec_pubkey_parse(ctx, &vss_commitment[i], (unsigned char *)pub, size);
(*penv)->ReleaseByteArrayElements(penv, jvss_commitment_bytes, pub, 0);
CHECKRESULT1(!result, "secp256k1_ec_pubkey_parse failed", free(vss_commitment));
}
result = secp256k1_frost_share_verify(
@@ -1651,7 +1652,7 @@ JNIEXPORT jint JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256k1_1fr
jthreshold,
(unsigned char *)id33,
&share,
(const secp256k1_pubkey *const *)vss_commitment
&vss_commitment
);
return result;
@@ -1690,9 +1691,9 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
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");
CHECKRESULT(jthreshold <= 1, "threshold can't be less then 1");
CHECKRESULT(jtotalSignersCount <= 1, "totalSignersCount can't be less then 1");
CHECKRESULT(jthreshold > jtotalSignersCount, "threshold can't be greater then n_participants");
id33 = (*penv)->GetByteArrayElements(penv, jid33, 0);