diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/ed25519/Ed25519.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/ed25519/Ed25519.kt index 332b506..27bfca2 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/ed25519/Ed25519.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/ed25519/Ed25519.kt @@ -21,9 +21,9 @@ expect object Ed25519LowLevel { fun isValidPoint(encoded: UByteArray): Boolean fun addPoints(p: UByteArray, q: UByteArray): UByteArray fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray - fun encodedPointFromUniform(uniform: UByteArray): UByteArray - fun randomEncodedPoint(): UByteArray - fun randomEncodedScalar(): UByteArray + fun pointFromUniform(uniform: UByteArray): UByteArray + fun randomPoint(): UByteArray + fun randomScalar(): UByteArray fun invertScalar(scalar: UByteArray): UByteArray fun negateScalar(scalar: UByteArray): UByteArray fun complementScalar(scalar: UByteArray): UByteArray @@ -38,16 +38,14 @@ expect object Ed25519LowLevel { } object Ed25519 { - - data class Point(private val encoded: UByteArray) { - + data class Point(val encoded: UByteArray) { companion object { val IDENTITY: Point = Point(UByteArray(crypto_core_ed25519_BYTES)) val BASE: Point = multiplyBaseNoClamp(Scalar.ONE) - fun fromUniform(uniform: UByteArray): Point = Point(Ed25519LowLevel.encodedPointFromUniform(uniform)) + fun fromUniform(uniform: UByteArray): Point = Point(Ed25519LowLevel.pointFromUniform(uniform)) - fun random(): Point = Point(Ed25519LowLevel.randomEncodedPoint()) + fun random(): Point = Point(Ed25519LowLevel.randomPoint()) fun multiplyBase(n: Scalar): Point = Point(Ed25519LowLevel.scalarMultiplicationBase(n.encoded)) @@ -55,10 +53,11 @@ object Ed25519 { Point(Ed25519LowLevel.scalarMultiplicationBaseNoClamp(n.encoded)) fun fromHex(hex: String): Point = Point(LibsodiumUtil.fromHex(hex)) - - fun isValid(point: Point) : Boolean = Ed25519LowLevel.isValidPoint(point.encoded) } + val isValid: Boolean + get() = Ed25519LowLevel.isValidPoint(encoded) + operator fun plus(q: Point): Point = Point(Ed25519LowLevel.addPoints(this.encoded, q.encoded)) operator fun minus(q: Point): Point = Point(Ed25519LowLevel.subtractPoints(this.encoded, q.encoded)) @@ -73,22 +72,12 @@ object Ed25519 { } data class Scalar(val encoded: UByteArray) { - companion object { val ZERO = fromUInt(0U) val ONE = fromUInt(1U) val TWO = fromUInt(2U) - - fun random(): Scalar = Scalar(Ed25519LowLevel.randomEncodedScalar()) - - fun invert(scalar: Scalar): Scalar = Scalar(Ed25519LowLevel.invertScalar(scalar.encoded)) - - fun negate(scalar: Scalar): Scalar = Scalar(Ed25519LowLevel.negateScalar(scalar.encoded)) - - fun reduce(scalar: Scalar): Scalar = Scalar(Ed25519LowLevel.reduceScalar(scalar.encoded)) - - fun complement(scalar: Scalar) : Scalar = Scalar(Ed25519LowLevel.complementScalar(scalar.encoded)) + fun random(): Scalar = Scalar(Ed25519LowLevel.randomScalar()) fun fromUInt(i: UInt): Scalar = fromULong(i.toULong()) @@ -135,19 +124,19 @@ object Ed25519 { operator fun times(y: UInt): Scalar = this * fromUInt(y) operator fun times(y: ULong): Scalar = this * fromULong(y) - operator fun div(y: Scalar): Scalar = times(invert(y)) + operator fun div(y: Scalar): Scalar = times(y.invert()) operator fun div(y: UInt): Scalar = this / fromUInt(y) operator fun div(y: ULong): Scalar = this / fromULong(y) - operator fun unaryMinus(): Scalar = negate(this) + operator fun unaryMinus(): Scalar = Scalar(Ed25519LowLevel.negateScalar(this.encoded)) operator fun times(p: Point): Point = p.times(this) fun times(p: Point, clamp: Boolean): Point = if (clamp) p.times(this) else p.times(this, clamp) - fun reduce(): Scalar = reduce(this) - fun invert(): Scalar = invert(this) - fun complement(): Scalar = complement(this) + fun reduce(): Scalar = Scalar(Ed25519LowLevel.reduceScalar(this.encoded)) + fun invert(): Scalar = Scalar(Ed25519LowLevel.invertScalar(this.encoded)) + fun complement(): Scalar = Scalar(Ed25519LowLevel.complementScalar(this.encoded)) fun multiplyWithBase(): Point = Point.multiplyBase(this) @@ -157,7 +146,5 @@ object Ed25519 { override fun equals(other: Any?): Boolean = (other as? Scalar)?.encoded?.contentEquals(encoded) == true override fun hashCode(): Int = encoded.contentHashCode() - - } } \ No newline at end of file diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/ristretto255/Ristretto255.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/ristretto255/Ristretto255.kt index cd03d4e..faa1c9f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/ristretto255/Ristretto255.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/ristretto255/Ristretto255.kt @@ -20,9 +20,9 @@ expect object Ristretto255LowLevel { fun isValidPoint(encoded: UByteArray): Boolean fun addPoints(p: UByteArray, q: UByteArray): UByteArray fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray - fun encodedPointFromHash(hash: UByteArray): UByteArray - fun randomEncodedPoint(): UByteArray - fun randomEncodedScalar(): UByteArray + fun pointFromHash(hash: UByteArray): UByteArray + fun randomPoint(): UByteArray + fun randomScalar(): UByteArray fun invertScalar(scalar: UByteArray): UByteArray fun negateScalar(scalar: UByteArray): UByteArray fun complementScalar(scalar: UByteArray): UByteArray @@ -35,62 +35,23 @@ expect object Ristretto255LowLevel { } object Ristretto255 { -// fun add(p: Point, q: Point): Point = -// Point(addPoints(p.encoded, q.encoded)) -// -// fun subtract(p: Point, q: Point): Point = -// Point(subtractPoints(p.encoded, q.encoded)) -// -// fun pointFromHash(hash: UByteArray): Point = Point(encodedPointFromHash(hash)) -// -// fun randomPoint(): Point = Point(randomEncodedPoint()) -// -// fun randomScalar(): Scalar = Scalar(randomEncodedScalar()) -// -// fun invert(scalar: Scalar): Scalar = -// Scalar(invertScalar(scalar.encoded)) -// -// fun negate(scalar: Scalar): Scalar = -// Scalar(negateScalar(scalar.encoded)) -// -// fun complement(scalar: Scalar): Scalar = -// Scalar(complementScalar(scalar.encoded)) -// -// fun add(x: Scalar, y: Scalar): Scalar = -// Scalar(addScalars(x.encoded, y.encoded)) -// -// fun subtract(x: Scalar, y: Scalar): Scalar = -// Scalar(subtractScalars(x.encoded, y.encoded)) -// -// fun multiply(x: Scalar, y: Scalar): Scalar = -// Scalar(multiplyScalars(x.encoded, y.encoded)) -// -// fun reduce(scalar: Scalar): Scalar = -// Scalar(reduceScalar(scalar.encoded)) -// -// fun scalarMultiplication(p: Point, n: Scalar): Point = -// Point(scalarMultiplication(n.encoded, p.encoded)) -// -// fun scalarMultiplicationBase(n: Scalar): Point = -// Point(scalarMultiplicationBase(n.encoded)) - data class Point(val encoded: UByteArray) { - companion object { val IDENTITY: Point = Point(UByteArray(crypto_core_ristretto255_BYTES)) val BASE: Point = multiplyBase(Scalar.ONE) - fun fromHash(hash: UByteArray): Point = Point(Ristretto255LowLevel.encodedPointFromHash(hash)) + fun fromHash(hash: UByteArray): Point = Point(Ristretto255LowLevel.pointFromHash(hash)) - fun random(): Point = Point(Ristretto255LowLevel.randomEncodedPoint()) + fun random(): Point = Point(Ristretto255LowLevel.randomPoint()) fun multiplyBase(n: Scalar): Point = Point(Ristretto255LowLevel.scalarMultiplicationBase(n.encoded)) fun fromHex(hex: String): Point = Point(LibsodiumUtil.fromHex(hex)) - - fun isValid(point: Point) : Boolean = Ristretto255LowLevel.isValidPoint(point.encoded) } + val isValid: Boolean + get() = Ristretto255LowLevel.isValidPoint(this.encoded) + operator fun plus(q: Point): Point = Point(Ristretto255LowLevel.addPoints(this.encoded, q.encoded)) operator fun minus(q: Point): Point = Point(Ristretto255LowLevel.subtractPoints(this.encoded, q.encoded)) @@ -100,61 +61,16 @@ object Ristretto255 { override fun equals(other: Any?): Boolean = (other as? Point)?.encoded?.contentEquals(encoded) == true override fun hashCode(): Int = encoded.contentHashCode() - - } data class Scalar(val encoded: UByteArray) { - operator fun plus(y: Scalar): Scalar = Scalar(Ristretto255LowLevel.addScalars(this.encoded, y.encoded)) - operator fun plus(y: UInt): Scalar = this + fromUInt(y) - operator fun plus(y: ULong): Scalar = this + fromULong(y) - - operator fun minus(y: Scalar): Scalar = Scalar(Ristretto255LowLevel.subtractScalars(this.encoded, y.encoded)) - operator fun minus(y: UInt): Scalar = this - fromUInt(y) - operator fun minus(y: ULong): Scalar = this - fromULong(y) - - operator fun times(y: Scalar): Scalar = Scalar(Ristretto255LowLevel.multiplyScalars(this.encoded, y.encoded)) - operator fun times(y: UInt): Scalar = this * fromUInt(y) - operator fun times(y: ULong): Scalar = this * fromULong(y) - - operator fun div(y: Scalar): Scalar = Scalar(Ristretto255LowLevel.multiplyScalars(this.encoded, y.invert().encoded)) - operator fun div(y: UInt): Scalar = this / fromUInt(y) - operator fun div(y: ULong): Scalar = this / fromULong(y) - - operator fun unaryMinus(): Scalar = negate(this) - - operator fun times(p: Point): Point = p.times(this) - - fun reduce(): Scalar = reduce(this) - fun invert(): Scalar = invert(this) - fun complement(): Scalar = complement(this) - - fun multiplyWithBase(): Point = Point.multiplyBase(this) - - fun toHex(): String = LibsodiumUtil.toHex(encoded) - - override fun equals(other: Any?): Boolean = (other as? Scalar)?.encoded?.contentEquals(encoded) == true - override fun hashCode(): Int = encoded.contentHashCode() - companion object { val ZERO = fromUInt(0U) val ONE = fromUInt(1U) val TWO = fromUInt(2U) - fun random(): Scalar = Scalar(Ristretto255LowLevel.randomEncodedScalar()) + fun random(): Scalar = Scalar(Ristretto255LowLevel.randomScalar()) - fun invert(scalar: Scalar): Scalar = - Scalar(Ristretto255LowLevel.invertScalar(scalar.encoded)) - - fun negate(scalar: Scalar): Scalar = - Scalar(Ristretto255LowLevel.negateScalar(scalar.encoded)) - - fun reduce(scalar: Scalar): Scalar = - Scalar(Ristretto255LowLevel.reduceScalar(scalar.encoded)) - - fun complement(scalar: Scalar): Scalar = - Scalar(Ristretto255LowLevel.complementScalar(scalar.encoded)) - fun fromUInt(i: UInt): Scalar = fromULong(i.toULong()) fun fromULong(l: ULong): Scalar { @@ -188,5 +104,38 @@ object Ristretto255 { } } } + + operator fun plus(y: Scalar): Scalar = Scalar(Ristretto255LowLevel.addScalars(this.encoded, y.encoded)) + operator fun plus(y: UInt): Scalar = this + fromUInt(y) + operator fun plus(y: ULong): Scalar = this + fromULong(y) + + operator fun minus(y: Scalar): Scalar = Scalar(Ristretto255LowLevel.subtractScalars(this.encoded, y.encoded)) + operator fun minus(y: UInt): Scalar = this - fromUInt(y) + operator fun minus(y: ULong): Scalar = this - fromULong(y) + + operator fun times(y: Scalar): Scalar = Scalar(Ristretto255LowLevel.multiplyScalars(this.encoded, y.encoded)) + operator fun times(y: UInt): Scalar = this * fromUInt(y) + operator fun times(y: ULong): Scalar = this * fromULong(y) + + operator fun div(y: Scalar): Scalar = + Scalar(Ristretto255LowLevel.multiplyScalars(this.encoded, y.invert().encoded)) + + operator fun div(y: UInt): Scalar = this / fromUInt(y) + operator fun div(y: ULong): Scalar = this / fromULong(y) + + operator fun unaryMinus(): Scalar = Scalar(Ristretto255LowLevel.negateScalar(this.encoded)) + + operator fun times(p: Point): Point = p.times(this) + + fun reduce(): Scalar = Scalar(Ristretto255LowLevel.reduceScalar(this.encoded)) + fun invert(): Scalar = Scalar(Ristretto255LowLevel.invertScalar(this.encoded)) + fun complement(): Scalar = Scalar(Ristretto255LowLevel.complementScalar(this.encoded)) + + fun multiplyWithBase(): Point = Point.multiplyBase(this) + + fun toHex(): String = LibsodiumUtil.toHex(encoded) + + override fun equals(other: Any?): Boolean = (other as? Scalar)?.encoded?.contentEquals(encoded) == true + override fun hashCode(): Int = encoded.contentHashCode() } } \ No newline at end of file diff --git a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519Test.kt b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519Test.kt index 28e2cee..1eadcd3 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519Test.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519Test.kt @@ -20,16 +20,6 @@ class Ed25519Test { "f5ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f", ) - // Test vectors generated with sodium.js - private val fromHashTestVectors = arrayOf( - "The sodium crypto library compiled to WebAssembly and pure JavaScript" to "50127230808e661643a11badce3c7220ab8de25f890528694f5155ab9c5d5339", - "using Emscripten, with automatically generated wrappers to" to "546d28c823c00b7d1c355c2f3ed6faaed2b7f406b45568c83f14b00ad88c212d", - "make it easy to use in web applications." to "69f1db12b628f6a0573c3ca440dbfe23c161d0a832cf4ca263ed33d15f337780", - "The complete library weighs 188 KB" to "9ad2302066752dccc14e26d7da4bb7a839c211a7e46f558ff106c632106d8f71", - "(minified, gzipped, includes pure JS + WebAssembly versions)" to "07787c86d65d8157b0e7bbf634c46e638f7dc88c560f60dfd1f5e85de64d681c", - "and can run in a web browser as well as server-side." to "c33fedca4b8e6fdd7ecc4109ec624f81900d8c207e1497297f4ca87c154c0640", - ) - // Test vectors generated with sodium.js private val fromUniformTestVectors = arrayOf( "d5d31a04bf9cd6b4f3f014ab57f95d439a0bd741e71f1ecb580143235545255e" to "cb9fff40134270e80e0dcfcdc66aa4ebf02cd27c9d9d26adfdf78d0012ad1b62", @@ -98,9 +88,9 @@ class Ed25519Test { assertNotEquals(q, r) assertNotEquals(r, p) - assertTrue { Ed25519.Point.isValid(p) } - assertTrue { Ed25519.Point.isValid(q) } - assertTrue { Ed25519.Point.isValid(r) } + assertTrue { p.isValid } + assertTrue { q.isValid } + assertTrue { r.isValid } } } @@ -119,15 +109,15 @@ class Ed25519Test { fun testIsValidPoint() = runTest { LibsodiumInitializer.initializeWithCallback { for (hexEncoded in badEncodings) { - assertFalse { Ed25519.Point.isValid(Ed25519.Point.fromHex(hexEncoded)) } + assertFalse { Ed25519.Point.fromHex(hexEncoded).isValid } } for (hexEncoded in basePointSmallMultiplesNoClamp) { - assertTrue { Ed25519.Point.isValid(Ed25519.Point.fromHex(hexEncoded)) } + assertTrue { Ed25519.Point.fromHex(hexEncoded).isValid } } for (hexEncoded in basePointSmallMultiplesClamped) { - assertTrue { Ed25519.Point.isValid(Ed25519.Point.fromHex(hexEncoded)) } + assertTrue { Ed25519.Point.fromHex(hexEncoded).isValid } } } } diff --git a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255Test.kt b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255Test.kt index d1725a2..d99ff51 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255Test.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255Test.kt @@ -1,9 +1,7 @@ package com.ionspin.kotlin.crypto.ristretto255 import com.ionspin.kotlin.crypto.LibsodiumInitializer -import com.ionspin.kotlin.crypto.ed25519.Ed25519 import com.ionspin.kotlin.crypto.hash.Hash -import com.ionspin.kotlin.crypto.util.LibsodiumUtil import com.ionspin.kotlin.crypto.util.encodeToUByteArray import com.ionspin.kotlin.crypto.util.runTest import kotlin.test.Test @@ -95,10 +93,9 @@ class Ristretto255Test { assertNotEquals(r, p) - - assertTrue { Ristretto255.Point.isValid(p) } - assertTrue { Ristretto255.Point.isValid(q) } - assertTrue { Ristretto255.Point.isValid(r) } + assertTrue { p.isValid } + assertTrue { q.isValid } + assertTrue { r.isValid } } } @@ -117,11 +114,11 @@ class Ristretto255Test { fun testIsValidPoint() = runTest { LibsodiumInitializer.initializeWithCallback { for (hexEncoded in badEncodings) { - assertFalse { Ristretto255.Point.isValid(Ristretto255.Point.fromHex(hexEncoded)) } + assertFalse { Ristretto255.Point.fromHex(hexEncoded).isValid } } for (hexEncoded in basePointSmallMultiples) { - assertTrue { Ristretto255.Point.isValid(Ristretto255.Point.fromHex(hexEncoded)) } + assertTrue { Ristretto255.Point.fromHex(hexEncoded).isValid } } } } diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt index 0723463..4e33907 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt @@ -20,19 +20,19 @@ actual object Ed25519LowLevel { return result.toUByteArray() } - actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray { + actual fun pointFromUniform(uniform: UByteArray): UByteArray { val result = getSodium().crypto_core_ed25519_from_uniform(uniform.toUInt8Array()) return result.toUByteArray() } - actual fun randomEncodedPoint(): UByteArray { + actual fun randomPoint(): UByteArray { val result = getSodium().crypto_core_ed25519_random() return result.toUByteArray() } - actual fun randomEncodedScalar(): UByteArray { + actual fun randomScalar(): UByteArray { val result = getSodium().crypto_core_ed25519_scalar_random() return result.toUByteArray() diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt index 14d4c29..6e40b1c 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt @@ -20,19 +20,19 @@ actual object Ristretto255LowLevel { return result.toUByteArray() } - actual fun encodedPointFromHash(hash: UByteArray): UByteArray { + actual fun pointFromHash(hash: UByteArray): UByteArray { val result = getSodium().crypto_core_ristretto255_from_hash(hash.toUInt8Array()) return result.toUByteArray() } - actual fun randomEncodedPoint(): UByteArray { + actual fun randomPoint(): UByteArray { val result = getSodium().crypto_core_ristretto255_random() return result.toUByteArray() } - actual fun randomEncodedScalar(): UByteArray { + actual fun randomScalar(): UByteArray { val result = getSodium().crypto_core_ristretto255_scalar_random() return result.toUByteArray() diff --git a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt index 1c633e6..e9503c9 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt @@ -25,7 +25,7 @@ actual object Ed25519LowLevel { return result } - actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray { + actual fun pointFromUniform(uniform: UByteArray): UByteArray { val result = UByteArray(crypto_core_ed25519_BYTES) sodiumJna.crypto_core_ed25519_from_uniform(result.asByteArray(), uniform.asByteArray()) @@ -34,11 +34,11 @@ actual object Ed25519LowLevel { return result } - actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ed25519_BYTES).also { + actual fun randomPoint(): UByteArray = UByteArray(crypto_core_ed25519_BYTES).also { sodiumJna.crypto_core_ed25519_random(it.asByteArray()) } - actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ed25519_SCALARBYTES).also { + actual fun randomScalar(): UByteArray = UByteArray(crypto_core_ed25519_SCALARBYTES).also { sodiumJna.crypto_core_ed25519_scalar_random(it.asByteArray()) } diff --git a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt index 8aa8fe8..cbf3752 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt @@ -25,7 +25,7 @@ actual object Ristretto255LowLevel { return result } - actual fun encodedPointFromHash(hash: UByteArray): UByteArray { + actual fun pointFromHash(hash: UByteArray): UByteArray { val result = UByteArray(crypto_core_ristretto255_BYTES) sodiumJna.crypto_core_ristretto255_from_hash(result.asByteArray(), hash.asByteArray()) @@ -33,11 +33,11 @@ actual object Ristretto255LowLevel { return result } - actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).also { + actual fun randomPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).also { sodiumJna.crypto_core_ristretto255_random(it.asByteArray()) } - actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ristretto255_SCALARBYTES).also { + actual fun randomScalar(): UByteArray = UByteArray(crypto_core_ristretto255_SCALARBYTES).also { sodiumJna.crypto_core_ristretto255_scalar_random(it.asByteArray()) } diff --git a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt index e6791e0..0526a03 100644 --- a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt +++ b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/ed25519/Ed25519LowLevel.kt @@ -57,7 +57,7 @@ actual object Ed25519LowLevel { return result } - actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray { + actual fun pointFromUniform(uniform: UByteArray): UByteArray { val result = UByteArray(crypto_core_ed25519_BYTES) result.usePinned { resultPinned -> @@ -70,11 +70,11 @@ actual object Ed25519LowLevel { return result } - actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ed25519_BYTES).apply { + actual fun randomPoint(): UByteArray = UByteArray(crypto_core_ed25519_BYTES).apply { usePinned { crypto_core_ed25519_random(it.toPtr()) } } - actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ed25519_SCALARBYTES).apply { + actual fun randomScalar(): UByteArray = UByteArray(crypto_core_ed25519_SCALARBYTES).apply { usePinned { crypto_core_ed25519_scalar_random(it.toPtr()) } } diff --git a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt index 357f50c..61b9595 100644 --- a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt +++ b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/ristretto255/Ristretto255LowLevel.kt @@ -55,7 +55,7 @@ actual object Ristretto255LowLevel { return result } - actual fun encodedPointFromHash(hash: UByteArray): UByteArray { + actual fun pointFromHash(hash: UByteArray): UByteArray { val result = UByteArray(crypto_core_ristretto255_BYTES) result.usePinned { resultPinned -> @@ -67,11 +67,11 @@ actual object Ristretto255LowLevel { return result } - actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).apply { + actual fun randomPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).apply { usePinned { crypto_core_ristretto255_random(it.toPtr()) } } - actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ristretto255_SCALARBYTES).apply { + actual fun randomScalar(): UByteArray = UByteArray(crypto_core_ristretto255_SCALARBYTES).apply { usePinned { crypto_core_ristretto255_scalar_random(it.toPtr()) } }