Improve JNI handling of frost share gen

This commit is contained in:
kngako 2024-08-20 01:39:22 +02:00
parent 08f0304d4c
commit f5ab7fdeb7
2 changed files with 22 additions and 12 deletions

View File

@ -1379,7 +1379,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
jbyte *pubkeyBytes; jbyte *pubkeyBytes;
unsigned char seed32[32]; unsigned char seed32[32];
unsigned char *ids33[jn_participants]; const jbyte *ids33[jn_participants];
if (jctx == 0) if (jctx == 0)
return NULL; return NULL;
@ -1399,17 +1399,23 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
copy_bytes_from_java(penv, jseed32, size, seed32); copy_bytes_from_java(penv, jseed32, size, seed32);
size = (*penv)->GetArrayLength(penv, jids33); size = (*penv)->GetArrayLength(penv, jids33);
CHECKRESULT(size != jn_participants, "invalid ids33 size"); CHECKRESULT(size != jn_participants, "ids33 needs to be of size jn_participants");
CHECKRESULT((*penv)->GetArrayLength(penv, jpok64) != 64, "pok64 length must be 64 bytes"); 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++) for (i = 0; i < jn_participants; i++)
{ {
jbyteArray jid33 = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jids33, i); jbyteArray id33 = (jbyteArray)(*penv)->GetObjectArrayElement(penv, jids33, i);
size = (*penv)->GetArrayLength(penv, jid33); // TODO: Check id33 size is 33...
CHECKRESULT(size != 33, "invalid id33 size"); ids33[i] = (*penv)->GetByteArrayElements(penv, id33, 0);
copy_bytes_from_java(penv, jid33, 33, ids33[i]); }
}
int sharesLength = jn_participants * 32; int sharesLength = jn_participants * 32;
int vssCommitmentLength = jthreshold * 65; int vssCommitmentLength = jthreshold * 65;

View File

@ -145,18 +145,22 @@ public object NativeSecp256k1 : Secp256k1 {
totalSigners, totalSigners,
ids33 ids33
) )
println(Hex.encode(result))
val shares = Array(totalSigners) { index -> val shares = Array(totalSigners) { index ->
val startIndex = 0 + (index*32); val startIndex = 0 + (index*32);
val endIndex = 32 + (index*32); val endIndex = 31 + (index*32);
result.sliceArray( result.sliceArray(
startIndex..endIndex startIndex..endIndex
) )
} }
val vssCommitment = Array(totalSigners) { index -> val sharesOffset = totalSigners*32;
val startIndex = 0 + (index*65);
val endIndex = 65 + (index*65); val vssCommitment = Array(threshold) { index ->
val startIndex = sharesOffset + (index*65);
val endIndex = sharesOffset + 64 + (index*65);
result.sliceArray( result.sliceArray(
startIndex..endIndex startIndex..endIndex