Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(SOURCES
logging.cpp
encryption.cpp
jni_utils.cpp
ed25519.cpp
)

add_library( # Sets the name of the library.
Expand Down
33 changes: 33 additions & 0 deletions library/src/main/cpp/ed25519.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "jni_utils.h"
#include "util.h"

#include <session/ed25519.hpp>

extern "C"
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_ED25519_sign(JNIEnv *env, jobject thiz,
jbyteArray ed25519_private_key,
jbyteArray message) {
return jni_utils::run_catching_cxx_exception_or_throws<jbyteArray>(env, [=] {
auto sigs = session::ed25519::sign(
jni_utils::JavaByteArrayRef(env, ed25519_private_key).get(),
jni_utils::JavaByteArrayRef(env, message).get());

return util::bytes_from_vector(env, sigs);
});
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ED25519_verify(JNIEnv *env, jobject thiz,
jbyteArray ed25519_public_key,
jbyteArray message,
jbyteArray signature) {
return jni_utils::run_catching_cxx_exception_or_throws<jboolean>(env, [=] {
return session::ed25519::verify(
jni_utils::JavaByteArrayRef(env, signature).get(),
jni_utils::JavaByteArrayRef(env, ed25519_public_key).get(),
jni_utils::JavaByteArrayRef(env, message).get()
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package network.loki.messenger.libsession_util

object ED25519 {
/**
* Sign a message using the ed25519 private key
*
* @param ed25519PrivateKey 64 bytes ed25519 private key
* @param message Message to sign
* @return 64 bytes signature
*/
external fun sign(
ed25519PrivateKey: ByteArray,
message: ByteArray,
): ByteArray

/**
* Verify a message using the ed25519 public key
*
* @param ed25519PublicKey 32 bytes ed25519 public key
* @param message Message to verify
* @param signature 64 bytes signature
*/
external fun verify(
ed25519PublicKey: ByteArray,
message: ByteArray,
signature: ByteArray,
): Boolean
}