Broke the JNI now

This commit is contained in:
kngako
2024-08-20 22:29:29 +02:00
parent 83141916e8
commit c39590a859
5 changed files with 209 additions and 32 deletions

View File

@@ -1403,18 +1403,11 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
CHECKRESULT((*penv)->GetArrayLength(penv, jpok64) != 64, "pok64 length must be 64 bytes");
// for (i = 0; i < jn_participants; i++)
// {
// 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]);
// }
for (i = 0; i < jn_participants; i++)
{
jbyteArray id33 = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jids33, i);
size = (*penv)->GetArrayLength(penv, id33);
CHECKRESULT(size != 32, "invalid id33 size");
CHECKRESULT(size != 33, "invalid id33 size");
ids33[i] = (*penv)->GetByteArrayElements(penv, id33, 0);
(*penv)->ReleaseByteArrayElements(penv, id33, ids33[i], 0);
}
@@ -1442,7 +1435,6 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
(*penv)->ReleaseByteArrayElements(penv, jpok64, pok64, 0);
CHECKRESULT(!result, "secp256k1_frost_shares_gen failed");
unsigned char out32[32];
for (i = 0; i < jn_participants; i++)
{
result = secp256k1_frost_share_serialize(ctx, shareGenOutput + (32 * i), &shares[i]);
@@ -1934,7 +1926,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
jbyteArray jnonce;
jbyte *nonce_ptr = NULL;
unsigned char nonce[sizeof(secp256k1_frost_secnonce) + sizeof(secp256k1_frost_pubnonce)]; // TODO: Put correct pubnonce
unsigned char nonce[sizeof(secp256k1_frost_secnonce) + 66]; // TODO: Put correct pubnonce
size_t size, count;
@@ -1967,7 +1959,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
if (jpubkey != NULL) {
size = (*penv)->GetArrayLength(penv, jpubkey);
CHECKRESULT((size != 33) && (size != 65), "invalid public key size");
CHECKRESULT(size != 32, "invalid xonly public key size");
pubkey_ptr = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
result = secp256k1_xonly_pubkey_parse(ctx, &pubkey, (unsigned char *)pubkey_ptr);
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pubkey_ptr, 0);
@@ -2059,7 +2051,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
count = (*penv)->GetArrayLength(penv, jpubnonces);
CHECKRESULT(count <= 0, "public nonces count cannot be 0");
CHECKRESULT(n_pubnonces != 0, "n_pubnonces doesn't match public nonces count");
CHECKRESULT(n_pubnonces != count, "n_pubnonces doesn't match public nonces count");
pubnonces = calloc(count, sizeof(secp256k1_frost_pubnonce *));
@@ -2068,7 +2060,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
pubnonces[i] = calloc(1, sizeof(secp256k1_frost_pubnonce));
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));
CHECKRESULT1(size != 66, "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, jpubnonce, in66, 0);
@@ -2091,7 +2083,8 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
for (i = 0; i < n_pubnonces; i++)
{
jbyteArray id33 = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jids33, i);
CHECKRESULT(size != 32, "invalid id33 size");
size = (*penv)->GetArrayLength(penv, id33);
CHECKRESULT(size != 33, "invalid id33 size");
ids33[i] = (*penv)->GetByteArrayElements(penv, id33, 0);
(*penv)->ReleaseByteArrayElements(penv, id33, ids33[i], 0);
}