1010#include < limits>
1111#include < android/log.h>
1212
13+ #if defined(__x86_64__) || defined(_M_X64)
14+ #define USE_AESNI
15+ #elif defined(__aarch64__) || defined(_M_ARM64)
1316#define USE_ARM_AES
17+ #endif
1418
1519#include " Krypt/src/Krypt.hpp"
1620#include " jpp.hpp"
@@ -35,120 +39,6 @@ constexpr static jint FILE_SIGNATURE_SIZE = 7;
3539// / the size of one AES block in bytes.
3640constexpr static size_t AES_BLOCK_SIZE = 16 ;
3741
38- extern " C" JNIEXPORT jstring JNICALL Java_com_application_bethela_BethelaActivity_doubleString (
39- JNIEnv *env,
40- jobject,
41- jstring arg
42- ) {
43- jboolean isCopy = 1 ;
44- const char *c_str_arg = env->GetStringUTFChars (arg, &isCopy);
45- std::string test (c_str_arg);
46- test += " | 2" + test + " : " ;
47- jstring doubleString = env->NewStringUTF (test.c_str ());
48- delete[] c_str_arg;
49- return doubleString;
50- }
51-
52- extern " C" JNIEXPORT jbyteArray JNICALL Java_com_application_bethela_BethelaActivity_doubleByte (
53- JNIEnv *env,
54- jobject,
55- jbyteArray arg,
56- jint size
57- ) {
58- jbyte *read_only = env->GetByteArrayElements (arg, nullptr );
59-
60- jbyteArray doubleArray = env->NewByteArray (size * 2 );
61- env->SetByteArrayRegion (doubleArray, 0 , size, read_only);
62- env->SetByteArrayRegion (doubleArray, size, size, read_only);
63-
64- env->ReleaseByteArrayElements (arg, read_only, 0 );
65-
66- return doubleArray;
67- }
68-
69- extern " C" JNIEXPORT jobjectArray JNICALL Java_com_application_bethela_BethelaActivity_transpose (
70- JNIEnv *env,
71- jobject,
72- jobjectArray arr,
73- jint row,
74- jint column
75- ) {
76- // Create a vector that will hold the original jintArray rows
77- std::vector<jintArray> original_rows;
78-
79- // Allocate an array of pointers that will contain the copy/reference of the rows
80- jint **row_elements = new jint *[row];
81-
82- for (jsize i = 0 ; i < row; ++i) {
83- // get the `jintArray` row at index `i` of the `jobjectArray arr`, push it to a vector
84- original_rows.push_back ((jintArray) env->GetObjectArrayElement (arr, i));
85-
86- // create a copy/reference buffer of the aquired `jintArray`
87- row_elements[i] = env->GetIntArrayElements (original_rows.back (), nullptr );
88- }
89-
90- // Allocate a new C 2D array for the transpose and apply the transpose
91- jint **transposed_row_elements = new jint *[column];
92- for (jsize i = 0 ; i < column; ++i) {
93- transposed_row_elements[i] = new jint[row];
94- for (jsize j = 0 ; j < row; ++j) {
95- transposed_row_elements[i][j] = row_elements[j][i];
96- }
97- }
98-
99- // create a new jobjectArray that will contain the transpose 2D array values
100- jclass jintArrayClass = env->FindClass (" [I" );
101- jobjectArray transposed = env->NewObjectArray (column, jintArrayClass, nullptr );
102-
103- for (jsize i = 0 ; i < column; ++i) {
104- // create a new jintArray
105- jintArray curr_row = env->NewIntArray (row);
106-
107- // set the values of the new jintArray using the values of the transposed matrix
108- env->SetIntArrayRegion (curr_row, 0 , row, transposed_row_elements[i]);
109-
110- // add the row jintArray to the main jobjectArray transpose matrix
111- env->SetObjectArrayElement (transposed, i, curr_row);
112- }
113-
114- // release the copy/reference buffers of the original rows that we got from the first loop
115- for (jsize i = 0 ; i < row; ++i) {
116- env->ReleaseIntArrayElements (original_rows[i], row_elements[i], 0 );
117- }
118-
119- // deallocate all of the C++ array that we allocated using C++ convention
120- for (jsize i = 0 ; i < column; ++i) {
121- delete[] transposed_row_elements[i];
122- }
123-
124- delete[] transposed_row_elements;
125- delete[] row_elements;
126-
127- return transposed;
128- }
129-
130- extern " C" JNIEXPORT jintArray JNICALL Java_com_application_bethela_BethelaActivity_reverse (
131- JNIEnv *env,
132- jobject,
133- jintArray arr,
134- jint size
135- ) {
136- // A C array that could be a copy or a direct pointer to `arr`
137- jint *reverse_array = env->GetIntArrayElements (arr, nullptr );
138-
139- // reverse the array
140- for (jsize i = 0 ; i < size / 2 ; ++i) {
141- jint temp = reverse_array[i];
142- reverse_array[i] = reverse_array[size - 1 - i];
143- reverse_array[size - 1 - i] = temp;
144- }
145-
146- // free the C array and apply the changes back to the `arr`
147- env->ReleaseIntArrayElements (arr, reverse_array, 0 );
148-
149- return arr;
150- }
151-
15242namespace RESULT_CODE {
15343 jint INVALID_INTERNAL_BUFFER_SIZE = -1 ;
15444 jint THREAD_ATTACHMENT_FAILED = -2 ;
0 commit comments