androidabe

git clone git://git.codymlewis.com/androidabe.git
Log | Files | Refs | Submodules | README

commit ce75a01f4cd1371358ebf88c4fa87454a779a269
parent e1a336d0a5508f4f2f5141785c79988af4000b82
Author: Cody Lewis <cody@codymlewis.com>
Date:   Fri, 29 May 2020 14:39:29 +1000

Generalized JNI calling functions

Diffstat:
Mabe/src/main/cpp/native-lib.c | 172+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Mabe/src/main/cpp/native-lib.h | 121+++++++------------------------------------------------------------------------
Mapp/src/main/java/com/codymlewis/androidabe/MainActivity.java | 4++--
3 files changed, 127 insertions(+), 170 deletions(-)

diff --git a/abe/src/main/cpp/native-lib.c b/abe/src/main/cpp/native-lib.c @@ -16,6 +16,58 @@ #include "native-lib.h" + +jclass get_Class(JNIEnv* env, const char* class_name) +{ + char cn[20 + strlen(class_name)]; + sprintf(cn, "com/codymlewis/abe/%s", class_name); + return (*env)->FindClass(env, cn); +} + +jstring get_string_from_Object(JNIEnv* env, jclass Class, jobject object, const char* fun_name) +{ + jmethodID get_string = (*env)->GetMethodID(env, Class, fun_name, "()Ljava/lang/String;"); + return (jstring) (*env)->CallObjectMethod(env, object, get_string); +} + +jint get_int_from_Object(JNIEnv* env, jclass Class, jobject object, const char* fun_name) +{ + jmethodID get_int = (*env)->GetMethodID(env, Class, fun_name, "()I"); + return (*env)->CallIntMethod(env, object, get_int); +} + +void set_byteArray_into_Object(JNIEnv* env, jclass Class, jobject object, const char* fun_name, jbyteArray jba) +{ + jmethodID set_jba = (*env)->GetMethodID(env, Class, fun_name, "([B)V"); + (*env)->CallVoidMethod(env, object, set_jba, jba); +} + +jbyteArray get_byteArray_from_Object(JNIEnv* env, jclass Class, jobject object, const char* fun_name) +{ + jmethodID get_jba = (*env)->GetMethodID(env, Class, fun_name, "()[B"); + return (jbyteArray) (*env)->CallObjectMethod(env, object, get_jba); +} + +jmethodID get_bAfL_methID(JNIEnv* env, jclass Class, const char* fun_name) +{ + return (*env)->GetMethodID(env, Class, fun_name, "(I)[B"); +} + +jbyteArray get_byteArray_from_List(JNIEnv* env, jobject object, jmethodID method, const jint i) +{ + return (jbyteArray) (*env)->CallObjectMethod(env, object, method, i); +} + +jmethodID add_bAtL_methID(JNIEnv* env, jclass Class, const char* fun_name) +{ + return (*env)->GetMethodID(env, Class, fun_name, "([B)V"); +} + +void add_byteArray_to_List(JNIEnv* env, jobject object, jmethodID method, jbyteArray jba) +{ + (*env)->CallVoidMethod(env, object, method, jba); +} + jbyteArray buffer_to_jbyteArray(JNIEnv* env, const unsigned char* buf, const int buf_len) { jbyteArray jba = (*env)->NewByteArray(env, buf_len); @@ -125,18 +177,18 @@ Java_com_codymlewis_abe_Functions_setup( jobject thiz, jobject keychain) { - jclass Keychain = get_Keychain(env); - int k = Keychain_getK(env, Keychain, keychain); + jclass Keychain = get_Class(env, "Keychain"); + int k = get_int_from_Object(env, Keychain, keychain, "getK"); pairing_t pairing; element_t g; - init_pairing(env, &pairing, Keychain_getGroupData(env, Keychain, keychain)); + init_pairing(env, &pairing, get_string_from_Object(env, Keychain, keychain, "getGroupData")); element_init_G2(g, pairing); element_random(g); // Is g chosen correctly? element_pp_t g_pp; element_pp_init(g_pp, g); jbyteArray g_jba = element_to_jbyteArray(env, pairing, g, "G2"); - Keychain_setG(env, Keychain, keychain, g_jba); + set_byteArray_into_Object(env, Keychain, keychain, "setG", g_jba); element_t y; element_t Y; @@ -169,19 +221,19 @@ Java_com_codymlewis_abe_Functions_issueToken( jobject keychain, jobject token) { - jclass Keychain = get_Keychain(env); - jclass Token = get_Token(env); + jclass Keychain = get_Class(env, "Keychain"); + jclass Token = get_Class(env, "Token"); pairing_t pairing; - init_pairing(env, &pairing, Keychain_getGroupData(env, Keychain, keychain)); + init_pairing(env, &pairing, get_string_from_Object(env, Keychain, keychain, "getGroupData")); element_t h; element_init_G1(h, pairing); element_random(h); - Token_setSigma(env, Token, token, "setSigma1", element_to_jbyteArray(env, pairing, h, "G1")); + set_byteArray_into_Object(env, Token, token, "setSigma1", element_to_jbyteArray(env, pairing, h, "G1")); element_t hbar; element_init_G1(hbar, pairing); element_random(hbar); - Token_setSigma(env, Token, token, "setSigmabar1", element_to_jbyteArray(env, pairing, hbar, "G1")); + set_byteArray_into_Object(env, Token, token, "setSigmabar1", element_to_jbyteArray(env, pairing, hbar, "G1")); pairing_clear(pairing); element_clear(h); @@ -191,10 +243,11 @@ Java_com_codymlewis_abe_Functions_issueToken( int calc_m_i(JNIEnv* env, jclass token, jmethodID getAttribute, int i, element_t H_1_a_i, element_t Adash_i, element_t m_i) { - unsigned char* a_i = jbyteArray_to_buffer(env, Token_getAttribute(env, token, getAttribute, i)); + unsigned char* a_i = jbyteArray_to_buffer(env, get_byteArray_from_List(env, token, getAttribute, i)); hash_1(a_i, strlen((char*) a_i), H_1_a_i); element_add(m_i, H_1_a_i, Adash_i); pbc_free(a_i); + return 1; } JNIEXPORT jint JNICALL @@ -204,35 +257,35 @@ Java_com_codymlewis_abe_Functions_proveKnowledge( jobject keychain, jobject token) { - jclass Keychain = get_Keychain(env); - jclass Token = get_Token(env); - jmethodID addAdash = get_Token_addAdash_ID(env, Token); + jclass Keychain = get_Class(env, "Keychain"); + jclass Token = get_Class(env, "Token"); + jmethodID addAdash = add_bAtL_methID(env, Token, "addAdash"); pairing_t pairing; - init_pairing(env, &pairing, Keychain_getGroupData(env, Keychain, keychain)); + init_pairing(env, &pairing, get_string_from_Object(env, Keychain, keychain, "getGroupData")); // TODO: Check h is in G_2 element_t h; element_init_G1(h, pairing); - element_from_jbyteArray(env, h, Token_getSigma(env, Token, token, "getSigma1")); + element_from_jbyteArray(env, h, get_byteArray_from_Object(env, Token, token, "getSigma1")); - int k = Keychain_getK(env, Keychain, keychain); + int k = get_int_from_Object(env, Keychain, keychain, "getK"); element_t Adash[k + 1]; for (size_t i = 0; i < k + 1; ++i) { element_init_Zr(Adash[i], pairing); element_random(Adash[i]); - Token_addAdash(env, token, addAdash, element_to_jbyteArray(env, pairing, Adash[i], "Zr")); + add_byteArray_to_List(env, token, addAdash, element_to_jbyteArray(env, pairing, Adash[i], "Zr")); } element_t hbar; element_init_G1(hbar, pairing); - element_from_jbyteArray(env, hbar, Token_getSigma(env, Token, token, "getSigmabar1")); + element_from_jbyteArray(env, hbar, get_byteArray_from_Object(env, Token, token, "getSigmabar1")); element_t H_content; element_init_G1(H_content, pairing); - unsigned char* g_buf = jbyteArray_to_buffer(env, Keychain_getG(env, Keychain, keychain)); + unsigned char* g_buf = jbyteArray_to_buffer(env, get_byteArray_from_Object(env, Keychain, keychain, "getG")); char n_buf[strlen((char*) g_buf) + 1]; - sprintf(n_buf, "%s%x", g_buf, Token_getN(env, Token, token) + 1); + sprintf(n_buf, "%s%x", g_buf, get_int_from_Object(env, Token, token, "getN") + 1); hash_2((unsigned char*) n_buf, strlen(n_buf), H_content); element_pow_zn(H_content, H_content, Adash[0]); size_t n = (size_t) pairing_length_bytes(pairing, "G1"); @@ -240,7 +293,7 @@ Java_com_codymlewis_abe_Functions_proveKnowledge( element_to_bytes(H_buffer, H_content); hash_1(H_buffer, n, H_content); element_pow_zn(H_content, hbar, H_content); - Token_setTbar(env, Token, token, element_to_jbyteArray(env, pairing, H_content, "G1")); + set_byteArray_into_Object(env, Token, token, "setTbar", element_to_jbyteArray(env, pairing, H_content, "G1")); pbc_free(g_buf); unsigned char* pok; @@ -248,7 +301,7 @@ Java_com_codymlewis_abe_Functions_proveKnowledge( pok = pbc_malloc(n); element_t temp; element_init_G1(temp, pairing); - jmethodID getAttribute = get_Token_getAttribute_ID(env, Token); + jmethodID getAttribute = get_bAfL_methID(env, Token, "getAttribute"); element_t H_1_a_i; element_init_Zr(H_1_a_i, pairing); element_t m_i; @@ -259,7 +312,6 @@ Java_com_codymlewis_abe_Functions_proveKnowledge( element_pow_zn(temp, h, Adash[0]); element_to_bytes(pok, temp); } else { - // TODO LOOKS like this might be off by one! // calculate m_i = H_1(a_i) + a'_i calc_m_i(env, token, getAttribute, i - 1, H_1_a_i, Adash[i], m_i); print_el(pairing, H_1_a_i, "Zr", "proveKnowledge", "H_1_a_i"); @@ -273,7 +325,7 @@ Java_com_codymlewis_abe_Functions_proveKnowledge( pbc_free(m_i_buf); } } - Token_setPok(env, Token, token, buffer_to_jbyteArray(env, pok, n)); + set_byteArray_into_Object(env, Token, token, "setPok", buffer_to_jbyteArray(env, pok, n)); pbc_free(pok); element_clear(H_1_a_i); element_clear(m_i); @@ -298,41 +350,42 @@ int calc_sig_2( { element_t h; element_init_G1(h, pairing); - element_from_jbyteArray(env, h, Token_getSigma(env, Token, token, "getSigma1")); + element_from_jbyteArray(env, h, get_byteArray_from_Object(env, Token, token, "getSigma1")); element_t x; element_init_Zr(x, pairing); - element_from_jbyteArray(env, x, Keychain_getSecretX(env, Keychain, keychain)); + element_from_jbyteArray(env, x, get_byteArray_from_Object(env, Keychain, keychain, "getSecretX")); element_t temp_G1; element_init_G1(temp_G1, pairing); element_t temp_Zr; element_init_Zr(temp_Zr, pairing); element_t temp_y; element_init_Zr(temp_y, pairing); - int k = Keychain_getK(env, Keychain, keychain); + int k = get_int_from_Object(env, Keychain, keychain, "getK"); - print_el(pairing, h, "G1", "checkSigmas", "h"); + print_el(pairing, h, "G1", "calc_sig_2", "h"); + jmethodID getSecretY = get_bAfL_methID(env, Keychain, "getSecretY"); element_pow_zn(sig_2, h, x); // h^x - element_from_jbyteArray(env, temp_Zr, Token_getW(env, Token, token)); - element_from_jbyteArray(env, temp_y, Keychain_getSecretY(env, Keychain, keychain, 0)); + element_from_jbyteArray(env, temp_Zr, get_byteArray_from_Object(env, Token, token, "getW")); + element_from_jbyteArray(env, temp_y, get_byteArray_from_List(env, keychain, getSecretY, 0)); element_mul(temp_Zr, temp_Zr, temp_y); // w * y_0 element_pow_zn(temp_G1, h, temp_Zr); // h^(w*y_0) element_mul(sig_2, sig_2, temp_G1); // h^x * h^(w*y_0) hash_1(I, strlen((char*) I), temp_Zr); - element_from_jbyteArray(env, temp_y, Keychain_getSecretY(env, Keychain, keychain, k + 1)); + element_from_jbyteArray(env, temp_y, get_byteArray_from_List(env, keychain, getSecretY, k + 1)); element_mul(temp_Zr, temp_Zr, temp_y); // H_1(I) * y_(k+1) element_pow_zn(temp_G1, h, temp_Zr); // h^(H_1(I) * y_(k+1)) element_mul(sig_2, sig_2, temp_G1); // h^x * h^(w*y_0) * h^(H_1(I) * y_(k+1)) element_t H_1_a_i; element_init_Zr(H_1_a_i, pairing); - jmethodID getAttribute = get_Token_getAttribute_ID(env, Token); - jmethodID getAdash = get_Token_getAdash_ID(env, Token); + jmethodID getAttribute = get_bAfL_methID(env, Token, "getAttribute"); + jmethodID getAdash = get_bAfL_methID(env, Token, "getAdash"); for (size_t i = 0; i < k; ++i) { // store m_i in temp_Zr - element_from_jbyteArray(env, temp_Zr, Token_getAdash(env, token, getAdash, i)); + element_from_jbyteArray(env, temp_Zr, get_byteArray_from_List(env, token, getAdash, i)); calc_m_i(env, token, getAttribute, i, H_1_a_i, temp_Zr, temp_Zr); - element_from_jbyteArray(env, temp_y, Keychain_getSecretY(env, Keychain, keychain, i)); + element_from_jbyteArray(env, temp_y, get_byteArray_from_List(env, keychain, getSecretY, i)); element_mul(temp_Zr, temp_Zr, temp_y); // m_i * y_i element_pow_zn(temp_G1, h, temp_Zr); // h^(m_i * y_i) element_mul(sig_2, sig_2, temp_G1); // h^x * h^(w*y_0) * h^(H_1(I) * y_(k+1)) * Prod(h^(m_i * y_i)) @@ -358,10 +411,13 @@ int calc_sigbar_2( { element_t h; element_init_G1(h, pairing); - element_from_jbyteArray(env, h, Token_getSigma(env, Token, token, "getSigma1")); + element_from_jbyteArray(env, h, get_byteArray_from_Object(env, Token, token, "getSigma1")); + + print_el(pairing, h, "G1", "calc_sigbar_2", "h"); + element_t x; element_init_Zr(x, pairing); - element_from_jbyteArray(env, x, Keychain_getSecretX(env, Keychain, keychain)); + element_from_jbyteArray(env, x, get_byteArray_from_Object(env, Keychain, keychain, "getSecretX")); element_t temp_G1; element_init_G1(temp_G1, pairing); element_t temp_Zr; @@ -369,15 +425,16 @@ int calc_sigbar_2( element_t temp_y; element_init_Zr(temp_y, pairing); + jmethodID getSecretY = get_bAfL_methID(env, Keychain, "getSecretY"); element_pow_zn(sigbar_2, h, x); - element_from_jbyteArray(env, temp_G1, Token_getTbar(env, Token, token)); - element_from_jbyteArray(env, temp_y, Keychain_getSecretY(env, Keychain, keychain, 0)); + element_from_jbyteArray(env, temp_G1, get_byteArray_from_Object(env, Token, token, "getTbar")); + element_from_jbyteArray(env, temp_y, get_byteArray_from_List(env, keychain, getSecretY, 0)); element_pow_zn(temp_G1, temp_G1, temp_y); // Tbar^y_0 element_mul(sigbar_2, sigbar_2, temp_G1); // h^x Tbar^y_0 - element_from_jbyteArray(env, temp_Zr, Token_getMr(env, Token, token)); + element_from_jbyteArray(env, temp_Zr, get_byteArray_from_Object(env, Token, token, "getMr")); element_pow_zn(temp_G1, h, temp_Zr); // h^m_r element_mul(sigbar_2, sigbar_2, temp_G1); // h^x * Tbar^y_0 * h^m_r - element_from_jbyteArray(env, temp_y, Keychain_getSecretY(env, Keychain, keychain, 1)); + element_from_jbyteArray(env, temp_y, get_byteArray_from_List(env, keychain, getSecretY, 1)); element_mul(sigbar_2, sigbar_2, temp_y); // h^x * Tbar^y_0 * h^m_r * y_1 element_clear(temp_G1); @@ -395,30 +452,31 @@ Java_com_codymlewis_abe_Functions_completeTokenIssue( jobject keychain, jobject token) { - jclass Keychain = get_Keychain(env); - jclass Token = get_Token(env); + jclass Keychain = get_Class(env, "Keychain"); + jclass Token = get_Class(env, "Token"); pairing_t pairing; - init_pairing(env, &pairing, Keychain_getGroupData(env, Keychain, keychain)); + init_pairing(env, &pairing, get_string_from_Object(env, Keychain, keychain, "getGroupData")); // TODO check attributes and pok, fix time char I[64]; - sprintf(I, "%lf%d", pbc_get_time(), Token_getN(env, Token, token)); - Token_setI(env, Token, token, buffer_to_jbyteArray(env, (unsigned char*) I, sizeof(I) / sizeof(I[0]))); + sprintf(I, "%lf%d", pbc_get_time(), get_int_from_Object(env, Token, token, "getN")); + set_byteArray_into_Object(env, Token, token, "setI", buffer_to_jbyteArray(env, (unsigned char*) I, sizeof(I) / sizeof(I[0]))); __android_log_print(ANDROID_LOG_DEBUG, "completeTokenIssue", "I = %s", (unsigned char*) I); element_t sig_2; element_init_G1(sig_2, pairing); calc_sig_2(env, Keychain, keychain, Token, token, pairing, (unsigned char*) I, sig_2); - Token_setSigma(env, Token, token, "setSigma2", element_to_jbyteArray(env, pairing, sig_2, "G1")); + + set_byteArray_into_Object(env, Token, token, "setSigma2", element_to_jbyteArray(env, pairing, sig_2, "G1")); element_t m_r; element_init_Zr(m_r, pairing); element_random(m_r); - Token_setSigma(env, Token, token, "setMr", element_to_jbyteArray(env, pairing, m_r, "Zr")); + set_byteArray_into_Object(env, Token, token, "setMr", element_to_jbyteArray(env, pairing, m_r, "Zr")); element_t sigbar_2; element_init_G1(sigbar_2, pairing); calc_sigbar_2(env, Keychain, keychain, Token, token, pairing, sigbar_2); - Token_setSigma(env, Token, token, "setSigmabar2", element_to_jbyteArray(env, pairing, sigbar_2, "G1")); + set_byteArray_into_Object(env, Token, token, "setSigmabar2", element_to_jbyteArray(env, pairing, sigbar_2, "G1")); // print_el(pairing, sig_2, "G1", "completeTokenIssue", "calced"); // element_t token_sig_2; @@ -444,20 +502,20 @@ Java_com_codymlewis_abe_Functions_checkSigmas( { // TODO check that the 1 sigmas calculate correctly int ret_val = 0; - jclass Keychain = get_Keychain(env); - jclass Token = get_Token(env); + jclass Keychain = get_Class(env, "Keychain"); + jclass Token = get_Class(env, "Token"); pairing_t pairing; - init_pairing(env, &pairing, Keychain_getGroupData(env, Keychain, keychain)); - unsigned char* I = jbyteArray_to_buffer(env, Token_getI(env, Token, token)); + init_pairing(env, &pairing, get_string_from_Object(env, Keychain, keychain, "getGroupData")); + unsigned char* I = jbyteArray_to_buffer(env, get_byteArray_from_Object(env, Token, token, "getI")); __android_log_print(ANDROID_LOG_DEBUG, "checkSigmas", "I = %s", I); element_t sig_2; element_init_G1(sig_2, pairing); -// calc_sig_2(env, Keychain, keychain, Token, token, pairing, I, sig_2); - element_from_jbyteArray(env, sig_2, Token_getSigma(env, Token, token, "getSigma2")); + calc_sig_2(env, Keychain, keychain, Token, token, pairing, I, sig_2); +// element_from_jbyteArray(env, sig_2, get_byteArray_from_Object(env, Token, token, "getSigma2")); element_t token_sig_2; element_init_G1(token_sig_2, pairing); - element_from_jbyteArray(env, token_sig_2, Token_getSigma(env, Token, token, "getSigma2")); + element_from_jbyteArray(env, token_sig_2, get_byteArray_from_Object(env, Token, token, "getSigma2")); __android_log_print(ANDROID_LOG_DEBUG, "checkSigmas", "before check 1"); // print_el(pairing, sig_2, "G1", "checkSigmas", "calced"); @@ -469,7 +527,7 @@ Java_com_codymlewis_abe_Functions_checkSigmas( calc_sigbar_2(env, Keychain, keychain, Token, token, pairing, sigbar_2); element_t token_sigbar_2; element_init_G1(token_sigbar_2, pairing); - element_from_jbyteArray(env, token_sigbar_2, Token_getSigma(env, Token, token, "getSigmabar2")); + element_from_jbyteArray(env, token_sigbar_2, get_byteArray_from_Object(env, Token, token, "getSigmabar2")); if (!element_cmp(sigbar_2, token_sigbar_2)) { ret_val = 1; diff --git a/abe/src/main/cpp/native-lib.h b/abe/src/main/cpp/native-lib.h @@ -83,125 +83,24 @@ int hash_1(const unsigned char* buf, const size_t len, element_t e); */ int hash_2(unsigned char* buf, const size_t len, element_t e); -// Keychain Java related functions -jclass get_Keychain(JNIEnv* env) { - return (*env)->FindClass(env, "com/codymlewis/abe/Keychain"); -} - -int Keychain_getK(JNIEnv* env, jclass Keychain, jobject keychain) { - jmethodID getK = (*env)->GetMethodID(env, Keychain, "getK", "()I"); - return (*env)->CallIntMethod(env, keychain, getK); -} - -jstring Keychain_getGroupData(JNIEnv* env, jclass Keychain, jobject keychain) { - jmethodID getGroupData = (*env)->GetMethodID(env, Keychain, "getGroupData", "()Ljava/lang/String;"); - return (jstring) (*env)->CallObjectMethod(env, keychain, getGroupData); -} - -void Keychain_setG(JNIEnv* env, jclass Keychain, jobject keychain, jbyteArray g) { - jmethodID setG = (*env)->GetMethodID(env, Keychain, "setG", "([B)V"); - (*env)->CallVoidMethod(env, keychain, setG, g); -} - -jbyteArray Keychain_getG(JNIEnv* env, jclass Keychain, jobject keychain) { - jmethodID getG = (*env)->GetMethodID(env, Keychain, "getG", "()[B"); - return (jbyteArray) (*env)->CallObjectMethod(env, keychain, getG); -} - -jbyteArray Keychain_getSecretX(JNIEnv* env, jclass Keychain, jobject keychain) { - jmethodID getSecretX = (*env)->GetMethodID(env, Keychain, "getSecretX", "()[B"); - return (jbyteArray) (*env)->CallObjectMethod(env, keychain, getSecretX); -} - -jbyteArray Keychain_getSecretY(JNIEnv* env, jclass Keychain, jobject keychain, const jint i) { - jmethodID getSecretY = (*env)->GetMethodID(env, Keychain, "getSecretY", "(I)[B"); - return (jbyteArray) (*env)->CallObjectMethod(env, keychain, getSecretY, i); -} - -// Token Java related functions -jclass get_Token(JNIEnv* env) { - return (*env)->FindClass(env, "com/codymlewis/abe/Token"); -} - -void Token_setSigma(JNIEnv* env, jclass Token, jobject token, char* fun_name, jbyteArray jba) { - jmethodID setSigma = (*env)->GetMethodID(env, Token, fun_name, "([B)V"); - (*env)->CallVoidMethod(env, token, setSigma, jba); -} - -jbyteArray Token_getSigma(JNIEnv* env, jclass Token, jobject token, char* fun_name) { - jmethodID getSigma = (*env)->GetMethodID(env, Token, fun_name, "()[B"); - return (jbyteArray) (*env)->CallObjectMethod(env, token, getSigma); -} - -void Token_setN(JNIEnv* env, jclass Token, jobject token, int n) { - jmethodID setN = (*env)->GetMethodID(env, Token, "setN", "(I)V"); - (*env)->CallVoidMethod(env, token, setN, n); -} +// Java related functions +jclass get_Class(JNIEnv* env, const char* class_name); -jint Token_getN(JNIEnv* env, jclass Token, jobject token) { - jmethodID getN = (*env)->GetMethodID(env, Token, "getN", "()I"); - return (*env)->CallIntMethod(env, token, getN); -} +jstring get_string_from_Object(JNIEnv* env, jclass Class, jobject object, const char* fun_name); -jmethodID get_Token_addAdash_ID(JNIEnv* env, jclass Token) { - return (*env)->GetMethodID(env, Token, "addAdash", "([B)V"); -} +jint get_int_from_Object(JNIEnv* env, jclass Class, jobject object, const char* fun_name); -void Token_addAdash(JNIEnv* env, jobject token, jmethodID addAdash, jbyteArray jba) { - (*env)->CallVoidMethod(env, token, addAdash, jba); -} +void set_byteArray_into_Object(JNIEnv* env, jclass Class, jobject object, const char* fun_name, jbyteArray jba); -jmethodID get_Token_getAdash_ID(JNIEnv* env, jclass Token) { - return (*env)->GetMethodID(env, Token, "getAdash", "(I)[B"); -} +jbyteArray get_byteArray_from_Object(JNIEnv* env, jclass Class, jobject object, const char* fun_name); -jbyteArray Token_getAdash(JNIEnv* env, jobject token, jmethodID getAdash, const jint i) { - return (jbyteArray) (*env)->CallObjectMethod(env, token, getAdash, i); -} +jmethodID get_bAfL_methID(JNIEnv* env, jclass Class, const char* fun_name); -void Token_setTbar(JNIEnv* env, jclass Token, jobject token, jbyteArray jba) { - jmethodID setTbar = (*env)->GetMethodID(env, Token, "setTbar", "([B)V"); - (*env)->CallVoidMethod(env, token, setTbar, jba); -} +jbyteArray get_byteArray_from_List(JNIEnv* env, jobject object, jmethodID method, const jint i); -jbyteArray Token_getTbar(JNIEnv* env, jclass Token, jobject token) { - jmethodID getTbar = (*env)->GetMethodID(env, Token, "getTbar", "()[B"); - return (jbyteArray) (*env)->CallObjectMethod(env, token, getTbar); -} - -jmethodID get_Token_getAttribute_ID(JNIEnv* env, jclass Token) { - return (*env)->GetMethodID(env, Token, "getAttribute", "(I)[B"); -} - -jbyteArray Token_getAttribute(JNIEnv* env, jobject token, jmethodID getAttribute, jint i) { - return (jbyteArray) (*env)->CallObjectMethod(env, token, getAttribute, i); -} - -void Token_setPok(JNIEnv* env, jclass Token, jobject token, jbyteArray jba) { - jmethodID setPok = (*env)->GetMethodID(env, Token, "setPok", "([B)V"); - (*env)->CallVoidMethod(env, token, setPok, jba); -} - -void Token_setI(JNIEnv* env, jclass Token, jobject token, jbyteArray jba) { - jmethodID setI = (*env)->GetMethodID(env, Token, "setI", "([B)V"); - (*env)->CallVoidMethod(env, token, setI, jba); -} - -jbyteArray Token_getI(JNIEnv* env, jclass Token, jobject token) { - jmethodID getI = (*env)->GetMethodID(env, Token, "getI", "()[B"); - return (jbyteArray) (*env)->CallObjectMethod(env, token, getI); -} - -jbyteArray Token_getW(JNIEnv* env, jclass Token, jobject token) { - jmethodID getW = (*env)->GetMethodID(env, Token, "getW", "()[B"); - return (jbyteArray) (*env)->CallObjectMethod(env, token, getW); -} - -jbyteArray Token_getMr(JNIEnv* env, jclass Token, jobject token) { - jmethodID getMr = (*env)->GetMethodID(env, Token, "getMr", "()[B"); - return (jbyteArray) (*env)->CallObjectMethod(env, token, getMr); -} +jmethodID add_bAtL_methID(JNIEnv* env, jclass Class, const char* fun_name); +void add_byteArray_to_List(JNIEnv* env, jobject object, jmethodID method, jbyteArray jba); void print_el(pairing_t pairing, element_t el, const char* group, const char* fun_name, const char* var_name) { diff --git a/app/src/main/java/com/codymlewis/androidabe/MainActivity.java b/app/src/main/java/com/codymlewis/androidabe/MainActivity.java @@ -50,8 +50,8 @@ public class MainActivity extends AppCompatActivity { text += String.format("PoK = %s\n", Base64.getEncoder().encodeToString(token.getPok())); Functions.completeTokenIssue(kc, token); text += String.format("sigma2 = %s\n", Base64.getEncoder().encodeToString(token.getSigma2())); -// text += String.format("Mr = %s\n", Base64.getEncoder().encodeToString(token.getMr())); -// text += String.format("sigmabar2 = %s\n", Base64.getEncoder().encodeToString(token.getSigmabar2())); + text += String.format("Mr = %s\n", Base64.getEncoder().encodeToString(token.getMr())); + text += String.format("sigmabar2 = %s\n", Base64.getEncoder().encodeToString(token.getSigmabar2())); if (Functions.checkSigmas(kc, token)) { text += "Sigmas successfully calculated\n"; } else {