A few JNI fixes
This commit is contained in:
parent
5117507f25
commit
e6cba2b505
@ -35,6 +35,13 @@ extern "C" {
|
|||||||
#define fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_KEYAGG_CACHE_SIZE 197L
|
#define fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_KEYAGG_CACHE_SIZE 197L
|
||||||
#undef fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SESSION_SIZE
|
#undef fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SESSION_SIZE
|
||||||
#define fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SESSION_SIZE 133L
|
#define fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SESSION_SIZE 133L
|
||||||
|
|
||||||
|
#undef fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_SECRET_NONCE_SIZE
|
||||||
|
#define fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_SECRET_NONCE_SIZE 68L
|
||||||
|
#undef fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_AGGREGATE_SHARE_SIZE
|
||||||
|
#define fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_AGGREGATE_SHARE_SIZE 32L
|
||||||
|
#undef fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_SESSION_SIZE
|
||||||
|
#define fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_SESSION_SIZE 133L
|
||||||
/*
|
/*
|
||||||
* Class: fr_acinq_secp256k1_Secp256k1CFunctions
|
* Class: fr_acinq_secp256k1_Secp256k1CFunctions
|
||||||
* Method: secp256k1_context_create
|
* Method: secp256k1_context_create
|
||||||
|
@ -1761,6 +1761,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
|
|||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
CHECKRESULT((*penv)->GetArrayLength(penv, jpublicKey) != 32, "public key must be 32 bytes");
|
||||||
pub = (*penv)->GetByteArrayElements(penv, jpublicKey, 0);
|
pub = (*penv)->GetByteArrayElements(penv, jpublicKey, 0);
|
||||||
result = secp256k1_xonly_pubkey_parse(ctx, &public_key, (unsigned char *)pub);
|
result = secp256k1_xonly_pubkey_parse(ctx, &public_key, (unsigned char *)pub);
|
||||||
(*penv)->ReleaseByteArrayElements(penv, jpublicKey, pub, 0);
|
(*penv)->ReleaseByteArrayElements(penv, jpublicKey, pub, 0);
|
||||||
@ -1958,8 +1959,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (jpubkey != NULL) {
|
if (jpubkey != NULL) {
|
||||||
size = (*penv)->GetArrayLength(penv, jpubkey);
|
CHECKRESULT((*penv)->GetArrayLength(penv, jpubkey) != 32, "public key must be 32 bytes");
|
||||||
CHECKRESULT(size != 32, "invalid xonly public key size");
|
|
||||||
pubkey_ptr = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
|
pubkey_ptr = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
|
||||||
result = secp256k1_xonly_pubkey_parse(ctx, &pubkey, (unsigned char *)pubkey_ptr);
|
result = secp256k1_xonly_pubkey_parse(ctx, &pubkey, (unsigned char *)pubkey_ptr);
|
||||||
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pubkey_ptr, 0);
|
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pubkey_ptr, 0);
|
||||||
@ -2071,6 +2071,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
|
|||||||
CHECKRESULT(size != 32, "invalid message size");
|
CHECKRESULT(size != 32, "invalid message size");
|
||||||
copy_bytes_from_java(penv, jmsg32, size, msg32);
|
copy_bytes_from_java(penv, jmsg32, size, msg32);
|
||||||
|
|
||||||
|
CHECKRESULT((*penv)->GetArrayLength(penv, jpubkey) != 32, "public key must be 32 bytes");
|
||||||
pub = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
|
pub = (*penv)->GetByteArrayElements(penv, jpubkey, 0);
|
||||||
result = secp256k1_xonly_pubkey_parse(ctx, &public_key, (unsigned char *)pub);
|
result = secp256k1_xonly_pubkey_parse(ctx, &public_key, (unsigned char *)pub);
|
||||||
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pub, 0);
|
(*penv)->ReleaseByteArrayElements(penv, jpubkey, pub, 0);
|
||||||
@ -2169,17 +2170,17 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
|
|||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
copy_bytes_from_java(penv, jsecnonce, fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SECRET_NONCE_SIZE, secnonce.data);
|
CHECKRESULT((*penv)->GetArrayLength(penv, jsecnonce) != fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_SECRET_NONCE_SIZE, "invalid secnonce size");
|
||||||
|
copy_bytes_from_java(penv, jsecnonce, fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_SECRET_NONCE_SIZE, secnonce.data);
|
||||||
|
|
||||||
size = (*penv)->GetArrayLength(penv, jagg_share);
|
CHECKRESULT((*penv)->GetArrayLength(penv, jagg_share) != fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_AGGREGATE_SHARE_SIZE, "invalid agg_share size");
|
||||||
CHECKRESULT(size != sizeof(secp256k1_frost_share), "invalid agg_share size");
|
|
||||||
in32 = (*penv)->GetByteArrayElements(penv, jagg_share, 0);
|
in32 = (*penv)->GetByteArrayElements(penv, jagg_share, 0);
|
||||||
result = secp256k1_frost_share_parse(ctx, &agg_share, (unsigned char *)in32);
|
result = secp256k1_frost_share_parse(ctx, &agg_share, (unsigned char *)in32);
|
||||||
(*penv)->ReleaseByteArrayElements(penv, jagg_share, in32, 0);
|
(*penv)->ReleaseByteArrayElements(penv, jagg_share, in32, 0);
|
||||||
CHECKRESULT(!result, "secp256k1_frost_share_parse failed");
|
CHECKRESULT(!result, "secp256k1_frost_share_parse failed");
|
||||||
|
|
||||||
CHECKRESULT((*penv)->GetArrayLength(penv, jsession) != fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SESSION_SIZE, "invalid session size");
|
CHECKRESULT((*penv)->GetArrayLength(penv, jsession) != fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_SESSION_SIZE, "invalid session size");
|
||||||
copy_bytes_from_java(penv, jsession, fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_MUSIG_SESSION_SIZE, session.data);
|
copy_bytes_from_java(penv, jsession, fr_acinq_secp256k1_Secp256k1CFunctions_SECP256K1_FROST_SESSION_SIZE, session.data);
|
||||||
|
|
||||||
if (jtweak_cache != NULL)
|
if (jtweak_cache != NULL)
|
||||||
{
|
{
|
||||||
@ -2199,11 +2200,14 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
|
|||||||
);
|
);
|
||||||
CHECKRESULT(!result, "secp256k1_frost_partial_sign failed");
|
CHECKRESULT(!result, "secp256k1_frost_partial_sign failed");
|
||||||
|
|
||||||
jpsig = (*penv)->NewByteArray(penv, 32);
|
unsigned char partial_sig_bytes[32];
|
||||||
ptr = (*penv)->GetByteArrayElements(penv, jpsig, 0);
|
|
||||||
result = secp256k1_frost_partial_sig_serialize(ctx, (unsigned char *)ptr, &partial_sig);
|
result = secp256k1_frost_partial_sig_serialize(ctx, partial_sig_bytes, &partial_sig);
|
||||||
CHECKRESULT(!result, "secp256k1_frost_partial_sig_serialize failed");
|
CHECKRESULT(!result, "secp256k1_frost_partial_sig_serialize failed");
|
||||||
|
|
||||||
|
jpsig = (*penv)->NewByteArray(penv, 32);
|
||||||
|
copy_bytes_to_java(penv, jpsig, 32, partial_sig_bytes);
|
||||||
|
|
||||||
return jpsig;
|
return jpsig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2364,7 +2368,7 @@ JNIEXPORT jbyteArray JNICALL Java_fr_acinq_secp256k1_Secp256k1CFunctions_secp256
|
|||||||
free_frost_partial_sigs(psigs, count);
|
free_frost_partial_sigs(psigs, count);
|
||||||
CHECKRESULT(!result, "secp256k1_frost_partial_sig_agg failed");
|
CHECKRESULT(!result, "secp256k1_frost_partial_sig_agg failed");
|
||||||
|
|
||||||
jpsig = (*penv)->NewByteArray(penv, 64);
|
jbyteArray jsig = (*penv)->NewByteArray(penv, 64);
|
||||||
copy_bytes_to_java(penv, jpsig, 64, sig64);
|
copy_bytes_to_java(penv, jsig, 64, sig64);
|
||||||
return jpsig;
|
return jsig;
|
||||||
}
|
}
|
@ -481,7 +481,6 @@ class FrostTest: BaseTest() {
|
|||||||
signer.jsonObject["session"]!!.jsonPrimitive.content
|
signer.jsonObject["session"]!!.jsonPrimitive.content
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
val partialSignature = Secp256k1.frostPartialSign(
|
val partialSignature = Secp256k1.frostPartialSign(
|
||||||
secNonce,
|
secNonce,
|
||||||
aggregateShare,
|
aggregateShare,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user