add witnessgen to android (attempt)

This commit is contained in:
turnoffthiscomputer
2024-09-24 18:04:30 +02:00
parent dbc4deef32
commit 294d9f71e2
10 changed files with 315 additions and 142 deletions

View File

@@ -25,6 +25,12 @@ set_target_properties(prove_rsa_65537_sha1 PROPERTIES IMPORTED_LOCATION ${CMAKE_
add_library(prove_rsapss_65537_sha256 SHARED IMPORTED)
set_target_properties(prove_rsapss_65537_sha256 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_prove_rsapss_65537_sha256.so)
add_library(prove_ecdsa_secp256r1_sha256 SHARED IMPORTED)
set_target_properties(prove_ecdsa_secp256r1_sha256 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_prove_ecdsa_secp256r1_sha256.so)
add_library(prove_ecdsa_secp256r1_sha1 SHARED IMPORTED)
set_target_properties(prove_ecdsa_secp256r1_sha1 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_prove_ecdsa_secp256r1_sha1.so)
add_library(${CMAKE_PROJECT_NAME} SHARED
proofofpassportapp.cpp)

View File

@@ -0,0 +1,39 @@
#ifndef WITNESSCALC_prove_ecdsa_secp256r1_sha1_H
#define WITNESSCALC_prove_ecdsa_secp256r1_sha1_H
#ifdef __cplusplus
extern "C" {
#endif
#define WITNESSCALC_OK 0x0
#define WITNESSCALC_ERROR 0x1
#define WITNESSCALC_ERROR_SHORT_BUFFER 0x2
/**
*
* @return error code:
* WITNESSCALC_OK - in case of success.
* WITNESSCALC_ERROR - in case of an error.
*
* On success wtns_buffer is filled with witness data and
* wtns_size contains the number bytes copied to wtns_buffer.
*
* If wtns_buffer is too small then the function returns WITNESSCALC_ERROR_SHORT_BUFFER
* and the minimum size for wtns_buffer in wtns_size.
*
*/
int
witnesscalc_prove_ecdsa_secp256r1_sha1(
const char *circuit_buffer, unsigned long circuit_size,
const char *json_buffer, unsigned long json_size,
char *wtns_buffer, unsigned long *wtns_size,
char *error_msg, unsigned long error_msg_maxsize);
#ifdef __cplusplus
}
#endif
#endif // WITNESSCALC_prove_ecdsa_secp256r1_sha1_H

View File

@@ -0,0 +1,39 @@
#ifndef WITNESSCALC_prove_ecdsa_secp256r1_sha256_H
#define WITNESSCALC_prove_ecdsa_secp256r1_sha256_H
#ifdef __cplusplus
extern "C" {
#endif
#define WITNESSCALC_OK 0x0
#define WITNESSCALC_ERROR 0x1
#define WITNESSCALC_ERROR_SHORT_BUFFER 0x2
/**
*
* @return error code:
* WITNESSCALC_OK - in case of success.
* WITNESSCALC_ERROR - in case of an error.
*
* On success wtns_buffer is filled with witness data and
* wtns_size contains the number bytes copied to wtns_buffer.
*
* If wtns_buffer is too small then the function returns WITNESSCALC_ERROR_SHORT_BUFFER
* and the minimum size for wtns_buffer in wtns_size.
*
*/
int
witnesscalc_prove_ecdsa_secp256r1_sha256(
const char *circuit_buffer, unsigned long circuit_size,
const char *json_buffer, unsigned long json_size,
char *wtns_buffer, unsigned long *wtns_size,
char *error_msg, unsigned long error_msg_maxsize);
#ifdef __cplusplus
}
#endif
#endif // WITNESSCALC_prove_ecdsa_secp256r1_sha256_H

View File

@@ -4,50 +4,52 @@
#include "include/witnesscalc_prove_rsa_65537_sha256.h"
#include "include/witnesscalc_prove_rsa_65537_sha1.h"
#include "include/witnesscalc_prove_rsapss_65537_sha256.h"
#include "include/witnesscalc_prove_ecdsa_secp256r1_sha256.h"
#include "include/witnesscalc_prove_ecdsa_secp256r1_sha1.h"
#include <jni.h>
#include <iostream>
using namespace std;
extern "C"
JNIEXPORT jint JNICALL
extern "C" JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_groth16_1prover(JNIEnv *env, jobject thiz,
jbyteArray zkey_buffer, jlong zkey_size,
jbyteArray wtns_buffer, jlong wtns_size,
jbyteArray proof_buffer, jlongArray proof_size,
jbyteArray public_buffer,
jlongArray public_size, jbyteArray error_msg,
jlong error_msg_max_size) {
const void *zkeyBuffer = env->GetByteArrayElements(zkey_buffer, nullptr);
const void *wtnsBuffer = env->GetByteArrayElements(wtns_buffer, nullptr);
char *proofBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(proof_buffer,
nullptr));
char *publicBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(public_buffer,
nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));
jbyteArray zkey_buffer, jlong zkey_size,
jbyteArray wtns_buffer, jlong wtns_size,
jbyteArray proof_buffer, jlongArray proof_size,
jbyteArray public_buffer,
jlongArray public_size, jbyteArray error_msg,
jlong error_msg_max_size)
{
const void *zkeyBuffer = env->GetByteArrayElements(zkey_buffer, nullptr);
const void *wtnsBuffer = env->GetByteArrayElements(wtns_buffer, nullptr);
char *proofBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(proof_buffer,
nullptr));
char *publicBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(public_buffer,
nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));
unsigned long proofSize = env->GetLongArrayElements(proof_size, nullptr)[0];
unsigned long publicSize = env->GetLongArrayElements(public_size, nullptr)[0];
unsigned long proofSize = env->GetLongArrayElements(proof_size, nullptr)[0];
unsigned long publicSize = env->GetLongArrayElements(public_size, nullptr)[0];
int result = groth16_prover(zkeyBuffer, static_cast<unsigned long>(zkey_size),
wtnsBuffer, static_cast<unsigned long>(wtns_size),
proofBuffer, &proofSize,
publicBuffer, &publicSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));
int result = groth16_prover(zkeyBuffer, static_cast<unsigned long>(zkey_size),
wtnsBuffer, static_cast<unsigned long>(wtns_size),
proofBuffer, &proofSize,
publicBuffer, &publicSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));
env->SetLongArrayRegion(proof_size, 0, 1, reinterpret_cast<const jlong *>(&proofSize));
env->SetLongArrayRegion(public_size, 0, 1, reinterpret_cast<const jlong *>(&publicSize));
env->SetLongArrayRegion(proof_size, 0, 1, reinterpret_cast<const jlong *>(&proofSize));
env->SetLongArrayRegion(public_size, 0, 1, reinterpret_cast<const jlong *>(&publicSize));
env->ReleaseByteArrayElements(zkey_buffer,
reinterpret_cast<jbyte *>(const_cast<void *>(zkeyBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer,
reinterpret_cast<jbyte *>(const_cast<void *>(wtnsBuffer)), 0);
env->ReleaseByteArrayElements(proof_buffer, reinterpret_cast<jbyte *>(proofBuffer), 0);
env->ReleaseByteArrayElements(public_buffer, reinterpret_cast<jbyte *>(publicBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
env->ReleaseByteArrayElements(zkey_buffer,
reinterpret_cast<jbyte *>(const_cast<void *>(zkeyBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer,
reinterpret_cast<jbyte *>(const_cast<void *>(wtnsBuffer)), 0);
env->ReleaseByteArrayElements(proof_buffer, reinterpret_cast<jbyte *>(proofBuffer), 0);
env->ReleaseByteArrayElements(public_buffer, reinterpret_cast<jbyte *>(publicBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
return result;
return result;
}
// extern "C"
@@ -67,7 +69,6 @@ Java_com_proofofpassportapp_prover_ZKPTools_groth16_1prover(JNIEnv *env, jobject
// unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
// int result = witnesscalc_register_sha256WithRSAEncryption_65537(
// circuitBuffer, static_cast<unsigned long>(circuit_size),
// jsonBuffer, static_cast<unsigned long>(json_size),
@@ -104,7 +105,6 @@ Java_com_proofofpassportapp_prover_ZKPTools_groth16_1prover(JNIEnv *env, jobject
// unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
// int result = witnesscalc_disclose(
// circuitBuffer, static_cast<unsigned long>(circuit_size),
// jsonBuffer, static_cast<unsigned long>(json_size),
@@ -124,165 +124,236 @@ Java_com_proofofpassportapp_prover_ZKPTools_groth16_1prover(JNIEnv *env, jobject
// return result;
// }
extern "C"
JNIEXPORT jint JNICALL
extern "C" JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1prove_1rsa_165537_1sha256(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size) {
const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size)
{
const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
circuit_buffer, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
int result = witnesscalc_prove_rsa_65537_sha256(
int result = witnesscalc_prove_rsa_65537_sha256(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));
// Set the result and release the resources
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));
// Set the result and release the resources
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));
env->ReleaseByteArrayElements(circuit_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
env->ReleaseByteArrayElements(circuit_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
return result;
return result;
}
extern "C"
JNIEXPORT jint JNICALL
extern "C" JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1prove_1rsa_165537_1sha1(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size) {
const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size)
{
const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
circuit_buffer, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
int result = witnesscalc_prove_rsa_65537_sha1(
int result = witnesscalc_prove_rsa_65537_sha1(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));
// Set the result and release the resources
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));
// Set the result and release the resources
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));
env->ReleaseByteArrayElements(circuit_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
env->ReleaseByteArrayElements(circuit_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
return result;
return result;
}
extern "C"
JNIEXPORT jint JNICALL
extern "C" JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1prove_1rsapss_165537_1sha256(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size) {
const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size)
{
const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
circuit_buffer, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
int result = witnesscalc_prove_rsapss_65537_sha256(
int result = witnesscalc_prove_rsapss_65537_sha256(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));
// Set the result and release the resources
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));
// Set the result and release the resources
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));
env->ReleaseByteArrayElements(circuit_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
env->ReleaseByteArrayElements(circuit_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
return result;
return result;
}
extern "C"
JNIEXPORT jint JNICALL Java_com_proofofpassportapp_prover_ZKPTools_groth16_1prover_1zkey_1file(
JNIEnv *env, jobject obj,
jstring zkeyPath,
jbyteArray wtnsBuffer, jlong wtnsSize,
jbyteArray proofBuffer, jlongArray proofSize,
jbyteArray publicBuffer, jlongArray publicSize,
jbyteArray errorMsg, jlong errorMsgMaxSize
) {
// Convert jbyteArray to native types
const char *nativeZkeyPath = env->GetStringUTFChars(zkeyPath, nullptr);
extern "C" JNIEXPORT jint JNICALL Java_com_proofofpassportapp_prover_ZKPTools_groth16_1prover_1zkey_1file(
JNIEnv *env, jobject obj,
jstring zkeyPath,
jbyteArray wtnsBuffer, jlong wtnsSize,
jbyteArray proofBuffer, jlongArray proofSize,
jbyteArray publicBuffer, jlongArray publicSize,
jbyteArray errorMsg, jlong errorMsgMaxSize)
{
// Convert jbyteArray to native types
const char *nativeZkeyPath = env->GetStringUTFChars(zkeyPath, nullptr);
void *nativeWtnsBuffer = env->GetByteArrayElements(wtnsBuffer, nullptr);
void *nativeWtnsBuffer = env->GetByteArrayElements(wtnsBuffer, nullptr);
char *nativeProofBuffer = (char *) env->GetByteArrayElements(proofBuffer, nullptr);
char *nativePublicBuffer = (char *) env->GetByteArrayElements(publicBuffer, nullptr);
char *nativeErrorMsg = (char *) env->GetByteArrayElements(errorMsg, nullptr);
char *nativeProofBuffer = (char *)env->GetByteArrayElements(proofBuffer, nullptr);
char *nativePublicBuffer = (char *)env->GetByteArrayElements(publicBuffer, nullptr);
char *nativeErrorMsg = (char *)env->GetByteArrayElements(errorMsg, nullptr);
jlong *nativeProofSizeArr = env->GetLongArrayElements(proofSize, 0);
jlong *nativePublicSizeArr = env->GetLongArrayElements(publicSize, 0);
jlong *nativeProofSizeArr = env->GetLongArrayElements(proofSize, 0);
jlong *nativePublicSizeArr = env->GetLongArrayElements(publicSize, 0);
unsigned long nativeProofSize = nativeProofSizeArr[0];
unsigned long nativePublicSize = nativePublicSizeArr[0];
unsigned long nativeProofSize = nativeProofSizeArr[0];
unsigned long nativePublicSize = nativePublicSizeArr[0];
// Call the groth16_prover function`
int status_code = groth16_prover_zkey_file(
// Call the groth16_prover function`
int status_code = groth16_prover_zkey_file(
nativeZkeyPath,
nativeWtnsBuffer, wtnsSize,
nativeProofBuffer, &nativeProofSize,
nativePublicBuffer, &nativePublicSize,
nativeErrorMsg, errorMsgMaxSize
);
nativeErrorMsg, errorMsgMaxSize);
// Convert the results back to JNI types
nativeProofSizeArr[0] = nativeProofSize;
nativePublicSizeArr[0] = nativePublicSize;
// Convert the results back to JNI types
nativeProofSizeArr[0] = nativeProofSize;
nativePublicSizeArr[0] = nativePublicSize;
env->SetLongArrayRegion(proofSize, 0, 1, (jlong *) nativeProofSizeArr);
env->SetLongArrayRegion(publicSize, 0, 1, (jlong *) nativePublicSizeArr);
env->SetLongArrayRegion(proofSize, 0, 1, (jlong *)nativeProofSizeArr);
env->SetLongArrayRegion(publicSize, 0, 1, (jlong *)nativePublicSizeArr);
// Release the native buffers
env->ReleaseByteArrayElements(wtnsBuffer, (jbyte *) nativeWtnsBuffer, 0);
env->ReleaseByteArrayElements(proofBuffer, (jbyte *) nativeProofBuffer, 0);
env->ReleaseByteArrayElements(publicBuffer, (jbyte *) nativePublicBuffer, 0);
env->ReleaseByteArrayElements(errorMsg, (jbyte *) nativeErrorMsg, 0);
// Release the native buffers
env->ReleaseByteArrayElements(wtnsBuffer, (jbyte *)nativeWtnsBuffer, 0);
env->ReleaseByteArrayElements(proofBuffer, (jbyte *)nativeProofBuffer, 0);
env->ReleaseByteArrayElements(publicBuffer, (jbyte *)nativePublicBuffer, 0);
env->ReleaseByteArrayElements(errorMsg, (jbyte *)nativeErrorMsg, 0);
env->ReleaseLongArrayElements(proofSize, (jlong *) nativeProofSizeArr, 0);
env->ReleaseLongArrayElements(publicSize, (jlong *) nativePublicSizeArr, 0);
env->ReleaseLongArrayElements(proofSize, (jlong *)nativeProofSizeArr, 0);
env->ReleaseLongArrayElements(publicSize, (jlong *)nativePublicSizeArr, 0);
return status_code;
return status_code;
}
// Function for ECDSA secp256r1 with SHA-256
extern "C" JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1prove_1ecdsa_1secp256r1_1sha256(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size)
{
const char *circuitBuffer = reinterpret_cast<const char *>(
env->GetByteArrayElements(circuit_buffer, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(
env->GetByteArrayElements(json_buffer, nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(
env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(
env->GetByteArrayElements(error_msg, nullptr));
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
int result = witnesscalc_prove_ecdsa_secp256r1_sha256(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));
// Update the witness size
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));
// Release resources
env->ReleaseByteArrayElements(circuit_buffer, reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer, reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
return result;
}
// Function for ECDSA secp256r1 with SHA-1
extern "C" JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1prove_1ecdsa_1secp256r1_1sha1(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size)
{
const char *circuitBuffer = reinterpret_cast<const char *>(
env->GetByteArrayElements(circuit_buffer, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(
env->GetByteArrayElements(json_buffer, nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(
env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(
env->GetByteArrayElements(error_msg, nullptr));
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];
int result = witnesscalc_prove_ecdsa_secp256r1_sha1(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));
// Update the witness size
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));
// Release resources
env->ReleaseByteArrayElements(circuit_buffer, reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer, reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);
return result;
}

View File

@@ -72,6 +72,8 @@ class ProverModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
"prove_rsa_65537_sha256" -> zkpTools::witnesscalc_prove_rsa_65537_sha256
"prove_rsa_65537_sha1" -> zkpTools::witnesscalc_prove_rsa_65537_sha1
"prove_rsapss_65537_sha256" -> zkpTools::witnesscalc_prove_rsapss_65537_sha256
"prove_ecdsa_secp256r1_sha1" -> zkpTools::witnesscalc_prove_ecdsa_secp256r1_sha1
"prove_ecdsa_secp256r1_sha256" -> zkpTools::witnesscalc_prove_ecdsa_secp256r1_sha256
else -> throw IllegalArgumentException("Invalid witness calculator name")
}
@@ -162,6 +164,22 @@ class ZKPTools(val context: Context) {
wtnsSize: LongArray,
errorMsg: ByteArray,
errorMsgMaxSize: Long): Int
external fun witnesscalc_prove_ecdsa_secp256r1_sha1(circuitBuffer: ByteArray,
circuitSize: Long,
jsonBuffer: ByteArray,
jsonSize: Long,
wtnsBuffer: ByteArray,
wtnsSize: LongArray,
errorMsg: ByteArray,
errorMsgMaxSize: Long): Int
external fun witnesscalc_prove_ecdsa_secp256r1_sha256(circuitBuffer: ByteArray,
circuitSize: Long,
jsonBuffer: ByteArray,
jsonSize: Long,
wtnsBuffer: ByteArray,
wtnsSize: LongArray,
errorMsg: ByteArray,
errorMsgMaxSize: Long): Int
external fun groth16_prover(
zkeyBuffer: ByteArray, zkeySize: Long,