Skip to content

Commit

Permalink
0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypfau committed Oct 22, 2022
1 parent 9dcf3ad commit cbdd6f1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 52 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
with:
path: ~/.konan
key: ${{ runner.os }}-konan

- name: Run build with Gradle Wrapper
uses: gradle/gradle-build-action@v2
with:
arguments: publish
arguments: publish closeAndReleaseStagingRepository
26 changes: 0 additions & 26 deletions .github/workflows/release.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

Expand All @@ -19,6 +19,6 @@ dependencies {
<dependency>
<groupId>io.github.andreypfau</groupId>
<artifactId>curve25519-kotlin-jvm</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
</dependency>
```
20 changes: 10 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,16 @@ publishing {
}
}
}
// repositories {
// maven {
// name = "GitHubPackages"
// url = uri("https://maven.pkg.github.com/andreypfau/curve25519-kotlin")
// credentials {
// username = System.getenv("GITHUB_ACTOR")
// password = System.getenv("GITHUB_TOKEN")
// }
// }
// }
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/andreypfau/curve25519-kotlin")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}

tasks.withType<PublishToMavenRepository> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ class Ed25519PrivateKey internal constructor(
internal val data: ByteArray
) {
fun toByteArray(): ByteArray = toByteArray(ByteArray(Ed25519.PRIVATE_KEY_SIZE_BYTES))
fun toByteArray(output: ByteArray, offset: Int = 0): ByteArray =
data.copyInto(output, offset)
fun toByteArray(destination: ByteArray, destinationOffset: Int = 0): ByteArray =
data.copyInto(destination, destinationOffset)

fun seed(): ByteArray = seed(ByteArray(Ed25519.SEED_SIZE_BYTES))
fun seed(output: ByteArray, offset: Int = 0): ByteArray {
data.copyInto(output, offset, 0, Ed25519.SEED_SIZE_BYTES)
return output
fun seed(destination: ByteArray, destinationOffset: Int = 0): ByteArray {
data.copyInto(destination, destinationOffset, 0, Ed25519.SEED_SIZE_BYTES)
return destination
}

fun publicKey(): Ed25519PublicKey =
Ed25519PublicKey(data.copyOfRange(32, 64))

fun sign(message: ByteArray): ByteArray = sign(message, ByteArray(Ed25519.SIGNATURE_SIZE_BYTES))
fun sign(message: ByteArray, output: ByteArray, offset: Int = 0): ByteArray {
fun sign(message: ByteArray, destination: ByteArray, destinationOffset: Int = 0): ByteArray {
val extsk = sha512(data, 0, 32)
extsk[0] = (extsk[0].toInt() and 248).toByte()
extsk[31] = (extsk[31].toInt() and 127).toByte()
Expand All @@ -48,10 +48,10 @@ class Ed25519PrivateKey internal constructor(
s.add(s, r)

// S = (r + H(R,A,m)a) mod L
rCompressed.data.copyInto(output, offset)
s.toByteArray(output, offset + 32)
rCompressed.data.copyInto(destination, destinationOffset)
s.toByteArray(destination, destinationOffset + 32)

return output
return destination
}

fun sharedKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ import io.github.andreypfau.curve25519.internal.varTimeDoubleScalarBaseMul
import io.github.andreypfau.curve25519.scalar.Scalar

class Ed25519PublicKey internal constructor(
internal val data: ByteArray
internal val data: ByteArray,
internal val offset: Int = 0
) {
constructor(data: ByteArray) : this(data.copyOf(SIZE_BYTES), 0)

fun toByteArray(): ByteArray = toByteArray(ByteArray(SIZE_BYTES))
fun toByteArray(destination: ByteArray, destinationOffset: Int = 0) =
data.copyInto(destination, destinationOffset, offset, offset + SIZE_BYTES)

fun verify(
message: ByteArray,
signature: ByteArray
): Boolean {
val aCompressed = CompressedEdwardsY(data)
val aCompressed = CompressedEdwardsY(data.copyOfRange(offset, offset + SIZE_BYTES))
val a = EdwardsPoint.from(aCompressed)

// hram = H(R,A,m)
val hash = sha512(signature.copyOfRange(0, 32) + data + message)
val hash = sha512(signature.copyOfRange(0, 32) + data.copyOfRange(offset, SIZE_BYTES) + message)
val k = Scalar.fromWideByteArray(hash)
val s = Scalar.fromByteArray(signature, 32)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.github.andreypfau.curve25519.internal.constantTimeEquals
import io.github.andreypfau.curve25519.internal.sha512
import io.github.andreypfau.curve25519.montgomery.MontgomeryPoint
import io.github.andreypfau.curve25519.scalar.Scalar
import kotlin.jvm.JvmStatic

object X25519 {
const val SCALAR_SIZE_BYTES = 32
Expand All @@ -18,6 +19,7 @@ object X25519 {
it[0] = 9
}

@JvmStatic
fun x25519(
scalar: ByteArray,
point: ByteArray = BASEPOINT,
Expand All @@ -33,6 +35,7 @@ object X25519 {
return output
}

@JvmStatic
fun toX25519(
publicKey: Ed25519PublicKey,
output: ByteArray = ByteArray(POINT_SIZE_BYTES),
Expand All @@ -45,6 +48,7 @@ object X25519 {
return output
}

@JvmStatic
fun toX25519(
privateKey: Ed25519PrivateKey,
output: ByteArray = ByteArray(SCALAR_SIZE_BYTES),
Expand All @@ -56,6 +60,7 @@ object X25519 {
return output
}

@JvmStatic
private fun scalarBaseMult(
input: ByteArray,
output: ByteArray = ByteArray(SCALAR_SIZE_BYTES),
Expand All @@ -72,6 +77,7 @@ object X25519 {
return output
}

@JvmStatic
private fun scalarMult(
input: ByteArray,
base: ByteArray,
Expand Down

0 comments on commit cbdd6f1

Please sign in to comment.