revert to using c
This commit is contained in:
parent
c6fc155060
commit
a05211c23c
|
@ -1,3 +1,4 @@
|
||||||
lib/
|
lib/
|
||||||
*.class
|
*.class
|
||||||
*.o
|
*.o
|
||||||
|
*.a
|
|
@ -23,7 +23,7 @@ public class CKzg4844JNI {
|
||||||
public static native boolean verifyAggregateKzgProof(byte[] blobs, byte[] commitments, int count,
|
public static native boolean verifyAggregateKzgProof(byte[] blobs, byte[] commitments, int count,
|
||||||
byte[] proof);
|
byte[] proof);
|
||||||
|
|
||||||
public static native byte[] blobToKzgCommitment(byte[] commitment);
|
public static native byte[] blobToKzgCommitment(byte[] blob);
|
||||||
|
|
||||||
public static native boolean verifyKzgProof(byte[] commitment, byte[] z, byte[] y, byte[] proof);
|
public static native boolean verifyKzgProof(byte[] commitment, byte[] z, byte[] y, byte[] proof);
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
# Build Shared Library
|
# Build Shared Library
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
* libblst.a is available in ../../blst/ directory. Follow the instructions in the home README.md.
|
||||||
|
* JAVA_HOME environment variable is set.
|
||||||
|
|
||||||
## Windows
|
## Windows
|
||||||
|
|
||||||
```bat
|
```bat
|
||||||
g++ -c -I..\..\blst\bindings -I..\..\src\ -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" c_kzg_4844_jni.cpp -o c_kzg_4844_jni.o
|
TBC
|
||||||
g++ -shared -o lib/ckzg4844jni.dll c_kzg_4844.o c_kzg_4844_jni.o -Wl,--add-stdcall-alias
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Linux
|
## Linux
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
g++ -c -fPIC -I../../blst/bindings -I../../src/ -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux c_kzg_4844_jni.cpp -o c_kzg_4844_jni.o
|
clang -O -Wall -shared -fPIC -I../../blst/bindings -I../../src/ -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -o lib/libckzg4844jni.so c_kzg_4844_jni.c ../../src/c_kzg_4844.c ../../blst/libblst.a
|
||||||
g++ -shared -fPIC -o lib/libckzg4844jni.so c_kzg_4844.o c_kzg_4844_jni.o -lc
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Mac-OS
|
## Mac-OS
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
g++ -c -fPIC -I../../blst/bindings -I../../src/ -I${JAVA_HOME}/include -I${JAVA_HOME}/include/darwin c_kzg_4844_jni.cpp -o c_kzg_4844_jni.o
|
TBC
|
||||||
g++ -dynamiclib -o lib/libckzg4844jni.dylib c_kzg_4844.o c_kzg_4844_jni.o -lc
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stdlib.h>
|
||||||
#include "c_kzg_4844_jni.h"
|
#include "c_kzg_4844_jni.h"
|
||||||
#include "c_kzg_4844.h"
|
#include "c_kzg_4844.h"
|
||||||
|
|
||||||
|
@ -7,15 +8,14 @@ JNIEXPORT void JNICALL Java_CKzg4844JNI_loadTrustedSetup(JNIEnv *env, jclass thi
|
||||||
{
|
{
|
||||||
settings = malloc(sizeof(KZGSettings));
|
settings = malloc(sizeof(KZGSettings));
|
||||||
|
|
||||||
const char *file_native = env->GetStringUTFChars(file, 0);
|
const char *file_native = (*env)->GetStringUTFChars(env, file, 0);
|
||||||
|
|
||||||
FILE *f = fopen(file_native, "r");
|
FILE *f = fopen(file_native, "r");
|
||||||
|
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
{
|
{
|
||||||
free(settings);
|
free(settings);
|
||||||
env->ReleaseStringUTFChars(file, file_native);
|
(*env)->ReleaseStringUTFChars(env, file, file_native);
|
||||||
// need to throw an exception
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,44 +23,47 @@ JNIEXPORT void JNICALL Java_CKzg4844JNI_loadTrustedSetup(JNIEnv *env, jclass thi
|
||||||
{
|
{
|
||||||
free(settings);
|
free(settings);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
env->ReleaseStringUTFChars(file, file_native);
|
(*env)->ReleaseStringUTFChars(env, file, file_native);
|
||||||
// need to throw an exception
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
env->ReleaseStringUTFChars(file, file_native);
|
|
||||||
|
|
||||||
printf("Loaded Trusted Setup");
|
printf("Loaded Trusted Setup from %s\n", file_native);
|
||||||
|
|
||||||
|
(*env)->ReleaseStringUTFChars(env, file, file_native);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_CKzg4844JNI_freeTrustedSetup(JNIEnv *env, jclass thisCls)
|
JNIEXPORT void JNICALL Java_CKzg4844JNI_freeTrustedSetup(JNIEnv *env, jclass thisCls)
|
||||||
{
|
{
|
||||||
free_trusted_setup(settings);
|
free_trusted_setup(settings);
|
||||||
free(settings);
|
free(settings);
|
||||||
|
printf("Trusted Setup was unloaded\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jbyteArray JNICALL Java_CKzg4844JNI_computeAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jint count)
|
JNIEXPORT jbyteArray JNICALL Java_CKzg4844JNI_computeAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jint count)
|
||||||
{
|
{
|
||||||
jbyte *blobs_native = env->GetByteArrayElements(blobs, NULL);
|
// NOT YET IMPLEMENTED
|
||||||
jbyteArray proof = env->NewByteArray(48);
|
// jbyte *blobs_native = (*env)->GetByteArrayElements(env, blobs, NULL);
|
||||||
g1_t *out;
|
jbyteArray proof = (*env)->NewByteArray(env, 48);
|
||||||
bytes_to_g1(out, (uint8_t *)blobs_native);
|
|
||||||
return proof;
|
return proof;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_CKzg4844JNI_verifyAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jbyteArray commitments, jint count, jbyteArray proof)
|
JNIEXPORT jboolean JNICALL Java_CKzg4844JNI_verifyAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jbyteArray commitments, jint count, jbyteArray proof)
|
||||||
{
|
{
|
||||||
|
// NOT YET IMPLEMENTED
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jbyteArray JNICALL Java_CKzg4844JNI_blobToKzgCommitment(JNIEnv *env, jclass thisCls, jbyteArray commitment)
|
JNIEXPORT jbyteArray JNICALL Java_CKzg4844JNI_blobToKzgCommitment(JNIEnv *env, jclass thisCls, jbyteArray blob)
|
||||||
{
|
{
|
||||||
jbyteArray ret = env->NewByteArray(48);
|
// NOT YET IMPLEMENTED
|
||||||
|
jbyteArray ret = (*env)->NewByteArray(env, 48);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_CKzg4844JNI_verifyKzgProof(JNIEnv *env, jclass thisCls, jbyteArray commitment, jbyteArray z, jbyteArray y, jbyteArray proof)
|
JNIEXPORT jboolean JNICALL Java_CKzg4844JNI_verifyKzgProof(JNIEnv *env, jclass thisCls, jbyteArray commitment, jbyteArray z, jbyteArray y, jbyteArray proof)
|
||||||
{
|
{
|
||||||
|
// NOT YET IMPLEMENTED
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
Loading…
Reference in New Issue