Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andreypfau/curve25519-kotlin

A pure Kotlin/Multiplatform implementation of group operations on Curve25519.
https://github.com/andreypfau/curve25519-kotlin

cryptography curve25519 ed25519 edwards-curve kotlin kotlin-js kotlin-jvm kotlin-multiplatform kotlin-native montgomery-curve x25519

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# curve25519-kotlin

[![Maven Central](https://img.shields.io/maven-central/v/io.github.andreypfau/curve25519-kotlin.svg)](https://search.maven.org/artifact/io.github.andreypfau/curve25519-kotlin/0.0.6/pom)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Kotlin](https://img.shields.io/badge/kotlin-1.7.20-blue.svg?logo=kotlin)](http://kotlinlang.org)

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

### Gradle Kotlin DSL:

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

### Apache Maven:

```xml

io.github.andreypfau
curve25519-kotlin-jvm
0.0.7

```

## Examples:

### Generate key-pair from random

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

### Generate key-pair from seed bytes

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

### Signing messages & verify signatures

```kotlin
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

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