c-kzg-4844/bindings/java/c_kzg_4844_jni.c

70 lines
1.8 KiB
C
Raw Normal View History

2022-11-23 18:37:46 +00:00
#include <stdlib.h>
2022-11-23 17:17:06 +00:00
#include "c_kzg_4844_jni.h"
#include "c_kzg_4844.h"
KZGSettings *settings;
JNIEXPORT void JNICALL Java_CKzg4844JNI_loadTrustedSetup(JNIEnv *env, jclass thisCls, jstring file)
{
settings = malloc(sizeof(KZGSettings));
2022-11-23 18:37:46 +00:00
const char *file_native = (*env)->GetStringUTFChars(env, file, 0);
2022-11-23 17:17:06 +00:00
FILE *f = fopen(file_native, "r");
if (f == NULL)
{
free(settings);
2022-11-23 18:37:46 +00:00
(*env)->ReleaseStringUTFChars(env, file, file_native);
2022-11-23 17:17:06 +00:00
return;
}
if (load_trusted_setup(settings, f) != C_KZG_OK)
{
free(settings);
fclose(f);
2022-11-23 18:37:46 +00:00
(*env)->ReleaseStringUTFChars(env, file, file_native);
2022-11-23 17:17:06 +00:00
return;
}
fclose(f);
2022-11-23 17:26:15 +00:00
2022-11-23 18:37:46 +00:00
printf("Loaded Trusted Setup from %s\n", file_native);
(*env)->ReleaseStringUTFChars(env, file, file_native);
2022-11-23 17:17:06 +00:00
}
JNIEXPORT void JNICALL Java_CKzg4844JNI_freeTrustedSetup(JNIEnv *env, jclass thisCls)
{
free_trusted_setup(settings);
free(settings);
2022-11-23 18:37:46 +00:00
printf("Trusted Setup was unloaded\n");
2022-11-23 17:17:06 +00:00
}
JNIEXPORT jbyteArray JNICALL Java_CKzg4844JNI_computeAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jint count)
{
2022-11-23 18:37:46 +00:00
// NOT YET IMPLEMENTED
// jbyte *blobs_native = (*env)->GetByteArrayElements(env, blobs, NULL);
jbyteArray proof = (*env)->NewByteArray(env, 48);
2022-11-23 17:17:06 +00:00
return proof;
}
JNIEXPORT jboolean JNICALL Java_CKzg4844JNI_verifyAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jbyteArray commitments, jint count, jbyteArray proof)
{
2022-11-23 18:37:46 +00:00
// NOT YET IMPLEMENTED
2022-11-23 17:17:06 +00:00
return false;
}
2022-11-23 18:37:46 +00:00
JNIEXPORT jbyteArray JNICALL Java_CKzg4844JNI_blobToKzgCommitment(JNIEnv *env, jclass thisCls, jbyteArray blob)
2022-11-23 17:17:06 +00:00
{
2022-11-23 18:37:46 +00:00
// NOT YET IMPLEMENTED
jbyteArray ret = (*env)->NewByteArray(env, 48);
2022-11-23 17:17:06 +00:00
return ret;
}
JNIEXPORT jboolean JNICALL Java_CKzg4844JNI_verifyKzgProof(JNIEnv *env, jclass thisCls, jbyteArray commitment, jbyteArray z, jbyteArray y, jbyteArray proof)
{
2022-11-23 18:37:46 +00:00
// NOT YET IMPLEMENTED
2022-11-23 17:17:06 +00:00
return false;
}