The most optimized implementation of Ed25519 (http://ed25519.cr.yp.to/) contains both C and assembly code. As my program is implemented in JAVA, I would like to generate a shared library (.so) for Ed25519 but failed. This is most probably because Ed25519 assembly code does not support -fPIC (If i was wrong pls point out). It seems that JDK 8 can support the static linking (Linking static library with JNI), but there is no example I can found online. I tried to generate a static library (.a) and simply load it as a shared library by JNI, but obviously JAVA can not accept it. So in practice how can I link and load a static library to my JAVA program?
Asked
Active
Viewed 490 times
1 Answers
1
OK, now I have statically integrated ED25519 with my Java program. I believe the solution can be easily applied to other cases in which shared library can not be generated.
Basically, I implement a wrapper in C, which :
- invokes JNI interface 'JNI_CreateJavaVM' to launch a JVM, say, my_jvm;
- in my_jvm, registers each native method defined in java code with the corresponding method implemented in static library, by JNI interface 'RegisterNatives' (may needs a glue program in this step);
- launches java code in my_jvm, e.g., by JNI interface 'CallStaticVoidMethod'.
The wrapper is linked with the static library (ED25519.a in my case) by GCC. My java program is launched through the wrapper.
Then, the native methods in Java can locate and invoke the methods in C library.

milaneee
- 21
- 5
-
Could you post your solution online. In github or something. i think it might be useful for others – Hilikus Jul 07 '17 at 12:22