Skip to content

Latest commit

 

History

History
69 lines (49 loc) · 1.91 KB

README.md

File metadata and controls

69 lines (49 loc) · 1.91 KB

curve25519-kotlin

Maven Central License Kotlin

A pure Kotlin/Multiplatform implementation of group operations on Curve25519.

Gradle Kotlin DSL:

dependencies {
    implementation("io.github.andreypfau:curve25519-kotlin:0.0.7")
}

Apache Maven:

<dependency>
    <groupId>io.github.andreypfau</groupId>
    <artifactId>curve25519-kotlin-jvm</artifactId>
    <version>0.0.7</version>
</dependency>

Examples:

Generate key-pair from random

val privateKey: Ed25519PrivateKey = Ed25519.generateKey(Random)
val publicKey: Ed25519PublicKey = privateKey.publicKey()

Generate key-pair from seed bytes

val seedBytes: ByteArray = ByteArray(32)
val privateKey: Ed25519PrivateKey = Ed25519.keyFromSeed(seedBytes)
val publicKey: Ed25519PublicKey = privateKey.publicKey() 

Signing messages & verify signatures

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

Shared key calculation

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))