Skip to content

Commit 49bee28

Browse files
SessionHero01SessionHero01
authored andcommitted
Added ways to convert x25519 -> ed25519 key
1 parent a1e5a23 commit 49bee28

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

library/src/main/cpp/ed25519.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "util.h"
33

44
#include <session/ed25519.hpp>
5+
#include <session/xed25519.hpp>
56

67
extern "C"
78
JNIEXPORT jbyteArray JNICALL
@@ -58,4 +59,17 @@ Java_network_loki_messenger_libsession_1util_ED25519_generateProMasterKey(JNIEnv
5859
);
5960

6061
});
62+
}
63+
64+
extern "C"
65+
JNIEXPORT jbyteArray JNICALL
66+
Java_network_loki_messenger_libsession_1util_ED25519_positiveEd25519PubKeyFromCurve25519(
67+
JNIEnv *env, jobject thiz, jbyteArray curve25519_pub_key) {
68+
return jni_utils::run_catching_cxx_exception_or_throws<jbyteArray>(env, [=] {
69+
return util::bytes_from_span(
70+
env,
71+
session::xed25519::pubkey(
72+
jni_utils::JavaByteArrayRef(env, curve25519_pub_key).get())
73+
);
74+
});
6175
}

library/src/main/java/network/loki/messenger/libsession_util/ED25519.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,13 @@ object ED25519 : LibSessionUtilCApi() {
3838
* @return The libsodium-style Master Session Pro Ed25519 secret key, 64 bytes.
3939
*/
4040
external fun generateProMasterKey(ed25519Seed: ByteArray): ByteArray
41+
42+
private external fun positiveEd25519PubKeyFromCurve25519(curve25519PubKey: ByteArray): ByteArray
43+
44+
fun ed25519PubKeysFromCurve25519(curve25519PubKey: ByteArray): List<ByteArray> {
45+
val positive = positiveEd25519PubKeyFromCurve25519(curve25519PubKey)
46+
val negative = positive.clone()
47+
negative[31] = (negative[31].toInt() xor 0x80).toByte()
48+
return listOf(positive, negative)
49+
}
4150
}

library/src/main/java/network/loki/messenger/libsession_util/pro/ProProof.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,17 @@ data class ProProof(
7474
val signature: ByteArray,
7575
)
7676

77+
/**
78+
* Checks the status of the Pro proof.
79+
*
80+
* @param senderED25519PubKey The sender (proof generator)'s ED25519 public key.
81+
* @param signedMessage An optional signed message to verify against the proof.
82+
* @param now The current time to use for expiry checks. Defaults to
83+
*/
7784
fun status(
78-
verifyPubKey: ByteArray,
79-
signedMessage: ProSignedMessage?,
80-
now: Instant = Instant.now(),
85+
senderED25519PubKey: ByteArray,
86+
now: Instant,
87+
signedMessage: ProSignedMessage? = null,
8188
): Status {
8289
val signedMessageData = signedMessage?.data
8390
val signedMessageSignature = signedMessage?.signature
@@ -88,7 +95,7 @@ data class ProProof(
8895
expiryMs = expiryMs,
8996
signature = signatureHex.hexToByteArray(),
9097
nowUnixTs = now.toEpochMilli(),
91-
verifyPubKey = verifyPubKey,
98+
verifyPubKey = senderED25519PubKey,
9299
signedMessageData = signedMessageData,
93100
signedMessageSignature = signedMessageSignature
94101
)

0 commit comments

Comments
 (0)