A pure Kotlin/Multiplatform implementation of group operations on Curve25519.
dependencies {
implementation("io.github.andreypfau:curve25519-kotlin:0.0.7")
}
<dependency>
<groupId>io.github.andreypfau</groupId>
<artifactId>curve25519-kotlin-jvm</artifactId>
<version>0.0.7</version>
</dependency>
val privateKey: Ed25519PrivateKey = Ed25519.generateKey(Random)
val publicKey: Ed25519PublicKey = privateKey.publicKey()
val seedBytes: ByteArray = ByteArray(32)
val privateKey: Ed25519PrivateKey = Ed25519.keyFromSeed(seedBytes)
val publicKey: Ed25519PublicKey = privateKey.publicKey()
val message: ByteArray = "test message".encodeToByteArray()
val signature: ByteArray = privateKey.sign(message)
check(publicKey.verify(message, signature)) // Valid message returns true
val invalidMessage = "invalid message".encodeToByteArray()
check(!publicKey.verify(invalidMessage, signature)) // Invalid message returns false
val alicePrivate = Ed25519.generateKey(Random)
val alicePublic = alicePrivate.publicKey()
val bobPrivate = Ed25519.generateKey(Random)
val bobPublic = bobPrivate.publicKey()
val aliceShared = alicePrivate.sharedKey(bobPublic)
val bobShared = bobPrivate.sharedKey(alicePublic)
check(aliceShared.contentEquals(bobShared))