From 2887ae253514b59a04ef34eb161c7c6caf636f99 Mon Sep 17 00:00:00 2001 From: Johannes Leupold Date: Wed, 14 Aug 2024 23:04:55 +0200 Subject: [PATCH] Remove unintentional formatting changes and add .editorconfig --- .editorconfig | 9 + .../ed25519/Ed25519.kt | 246 +- .../ristretto255/Ristretto255.kt | 223 +- .../kotlin/crypto/ed25519/Ed25519Test.kt | 426 ++-- .../crypto/ristretto255/Ristretto255Test.kt | 382 +-- .../kotlin/crypto/ed25519/Ed25519LowLevel.kt | 132 +- .../ristretto255/Ristretto255LowLevel.kt | 116 +- .../kotlin/crypto/JnaLibsodiumInterface.kt | 2178 ++++++++--------- .../kotlin/crypto/ed25519/Ed25519LowLevel.kt | 170 +- .../ristretto255/Ristretto255LowLevel.kt | 145 +- .../kotlin/crypto/ed25519/Ed25519LowLevel.kt | 332 +-- .../ristretto255/Ristretto255LowLevel.kt | 291 +-- 12 files changed, 2329 insertions(+), 2321 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a469d63 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +# EditorConfig is awesome: https://editorconfig.org + +# top-most EditorConfig file +root = true + +[*.{kt,kts}] +indent_size = 4 +indent_style = space +max_line_length = 120 \ No newline at end of file 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 79fb7c0..92d2bfe 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 @@ -18,174 +18,174 @@ const val crypto_scalarmult_ed25519_BYTES = 32U const val crypto_scalarmult_ed25519_SCALARBYTES = 32U expect abstract class 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 invertScalar(scalar: UByteArray): UByteArray - fun negateScalar(scalar: UByteArray): UByteArray - fun complementScalar(scalar: UByteArray): UByteArray - fun addScalars(x: UByteArray, y: UByteArray): UByteArray - fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray - fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray - fun reduceScalar(scalar: UByteArray): UByteArray - fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray - fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray - fun scalarMultiplicationBase(n: UByteArray): UByteArray - fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray + 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 invertScalar(scalar: UByteArray): UByteArray + fun negateScalar(scalar: UByteArray): UByteArray + fun complementScalar(scalar: UByteArray): UByteArray + fun addScalars(x: UByteArray, y: UByteArray): UByteArray + fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray + fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray + fun reduceScalar(scalar: UByteArray): UByteArray + fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray + fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray + fun scalarMultiplicationBase(n: UByteArray): UByteArray + fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray } object Ed25519 : Ed25519LowLevel() { - fun add(p: Point, q: Point): Point = - Point(addPoints(p.encoded, q.encoded)) + 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 subtract(p: Point, q: Point): Point = + Point(subtractPoints(p.encoded, q.encoded)) - fun pointFromUniform(uniform: UByteArray): Point = Point(encodedPointFromUniform(uniform)) + fun pointFromUniform(uniform: UByteArray): Point = Point(encodedPointFromUniform(uniform)) - fun randomPoint(): Point = Point(randomEncodedPoint()) + fun randomPoint(): Point = Point(randomEncodedPoint()) - fun randomScalar(): Scalar = Scalar(randomEncodedScalar()) + fun randomScalar(): Scalar = Scalar(randomEncodedScalar()) - fun invert(scalar: Scalar): Scalar = - Scalar(invertScalar(scalar.encoded)) + fun invert(scalar: Scalar): Scalar = + Scalar(invertScalar(scalar.encoded)) - fun negate(scalar: Scalar): Scalar = - Scalar(negateScalar(scalar.encoded)) + fun negate(scalar: Scalar): Scalar = + Scalar(negateScalar(scalar.encoded)) - fun complement(scalar: Scalar): Scalar = - Scalar(complementScalar(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 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 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 multiply(x: Scalar, y: Scalar): Scalar = + Scalar(multiplyScalars(x.encoded, y.encoded)) - fun reduce(scalar: Scalar): Scalar = - Scalar(reduceScalar(scalar.encoded)) + fun reduce(scalar: Scalar): Scalar = + Scalar(reduceScalar(scalar.encoded)) - fun scalarMultiplication(p: Point, n: Scalar): Point = - Point(scalarMultiplication(n.encoded, p.encoded)) + fun scalarMultiplication(p: Point, n: Scalar): Point = + Point(scalarMultiplication(n.encoded, p.encoded)) - fun scalarMultiplicationNoClamp(p: Point, n: Scalar): Point = - Point(scalarMultiplicationNoClamp(n.encoded, p.encoded)) + fun scalarMultiplicationNoClamp(p: Point, n: Scalar): Point = + Point(scalarMultiplicationNoClamp(n.encoded, p.encoded)) - fun scalarMultiplicationBase(n: Scalar): Point = - Point(scalarMultiplicationBase(n.encoded)) + fun scalarMultiplicationBase(n: Scalar): Point = + Point(scalarMultiplicationBase(n.encoded)) - fun scalarMultiplicationBaseNoClamp(n: Scalar): Point = - Point(scalarMultiplicationBaseNoClamp(n.encoded)) + fun scalarMultiplicationBaseNoClamp(n: Scalar): Point = + Point(scalarMultiplicationBaseNoClamp(n.encoded)) - data class Point(val encoded: UByteArray) { - operator fun plus(q: Point): Point = add(this, q) - operator fun minus(q: Point): Point = subtract(this, q) + data class Point(val encoded: UByteArray) { + operator fun plus(q: Point): Point = add(this, q) + operator fun minus(q: Point): Point = subtract(this, q) - operator fun times(n: Scalar): Point = scalarMultiplication(this, n) - fun times(n: Scalar, clamp: Boolean): Point = - if (clamp) scalarMultiplication(this, n) else scalarMultiplicationNoClamp(this, n) + operator fun times(n: Scalar): Point = scalarMultiplication(this, n) + fun times(n: Scalar, clamp: Boolean): Point = + if (clamp) scalarMultiplication(this, n) else scalarMultiplicationNoClamp(this, n) - fun toHex(): String = LibsodiumUtil.toHex(encoded) + fun toHex(): String = LibsodiumUtil.toHex(encoded) - override fun equals(other: Any?): Boolean = (other as? Point)?.encoded?.contentEquals(encoded) == true - override fun hashCode(): Int = encoded.contentHashCode() + override fun equals(other: Any?): Boolean = (other as? Point)?.encoded?.contentEquals(encoded) == true + override fun hashCode(): Int = encoded.contentHashCode() - companion object { - val IDENTITY: Point = Point(UByteArray(crypto_core_ed25519_BYTES)) - val BASE: Point = scalarMultiplicationBaseNoClamp(Scalar.ONE) + companion object { + val IDENTITY: Point = Point(UByteArray(crypto_core_ed25519_BYTES)) + val BASE: Point = scalarMultiplicationBaseNoClamp(Scalar.ONE) - fun fromUniform(uniform: UByteArray): Point = pointFromUniform(uniform) + fun fromUniform(uniform: UByteArray): Point = pointFromUniform(uniform) - fun random(): Point = randomPoint() + fun random(): Point = randomPoint() - fun multiplyBase(n: Scalar): Point = scalarMultiplicationBase(n) + fun multiplyBase(n: Scalar): Point = scalarMultiplicationBase(n) - fun multiplyBaseNoClamp(n: Scalar): Point = scalarMultiplicationBaseNoClamp(n) + fun multiplyBaseNoClamp(n: Scalar): Point = scalarMultiplicationBaseNoClamp(n) - fun fromHex(hex: String): Point = Point(LibsodiumUtil.fromHex(hex)) + fun fromHex(hex: String): Point = Point(LibsodiumUtil.fromHex(hex)) + } } - } - data class Scalar(val encoded: UByteArray) { - operator fun plus(y: Scalar): Scalar = add(this, y) - operator fun plus(y: UInt): Scalar = this + fromUInt(y) - operator fun plus(y: ULong): Scalar = this + fromULong(y) + data class Scalar(val encoded: UByteArray) { + operator fun plus(y: Scalar): Scalar = add(this, y) + operator fun plus(y: UInt): Scalar = this + fromUInt(y) + operator fun plus(y: ULong): Scalar = this + fromULong(y) - operator fun minus(y: Scalar): Scalar = subtract(this, y) - operator fun minus(y: UInt): Scalar = this - fromUInt(y) - operator fun minus(y: ULong): Scalar = this - fromULong(y) + operator fun minus(y: Scalar): Scalar = subtract(this, y) + operator fun minus(y: UInt): Scalar = this - fromUInt(y) + operator fun minus(y: ULong): Scalar = this - fromULong(y) - operator fun times(y: Scalar): Scalar = multiply(this, y) - operator fun times(y: UInt): Scalar = this * fromUInt(y) - operator fun times(y: ULong): Scalar = this * fromULong(y) + operator fun times(y: Scalar): Scalar = multiply(this, y) + operator fun times(y: UInt): Scalar = this * fromUInt(y) + operator fun times(y: ULong): Scalar = this * fromULong(y) - operator fun div(y: Scalar): Scalar = multiply(this, invert(y)) - operator fun div(y: UInt): Scalar = this / fromUInt(y) - operator fun div(y: ULong): Scalar = this / fromULong(y) + operator fun div(y: Scalar): Scalar = multiply(this, invert(y)) + 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 = negate(this) - operator fun times(p: Point): Point = scalarMultiplication(p, this) - fun times(p: Point, clamp: Boolean): Point = - if (clamp) scalarMultiplication(p, this) else scalarMultiplicationNoClamp(p, this) + operator fun times(p: Point): Point = scalarMultiplication(p, this) + fun times(p: Point, clamp: Boolean): Point = + if (clamp) scalarMultiplication(p, this) else scalarMultiplicationNoClamp(p, this) - fun reduce(): Scalar = reduce(this) - fun invert(): Scalar = invert(this) - fun complement(): Scalar = complement(this) + fun reduce(): Scalar = reduce(this) + fun invert(): Scalar = invert(this) + fun complement(): Scalar = complement(this) - fun multiplyWithBase(): Point = scalarMultiplicationBase(this) + fun multiplyWithBase(): Point = scalarMultiplicationBase(this) - fun multiplyWithBaseNoClamp(): Point = scalarMultiplicationBaseNoClamp(this) + fun multiplyWithBaseNoClamp(): Point = scalarMultiplicationBaseNoClamp(this) - fun toHex(): String = LibsodiumUtil.toHex(encoded) + 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() + 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) + companion object { + val ZERO = fromUInt(0U) + val ONE = fromUInt(1U) + val TWO = fromUInt(2U) - fun random(): Scalar = randomScalar() + fun random(): Scalar = randomScalar() - fun fromUInt(i: UInt): Scalar = fromULong(i.toULong()) + fun fromUInt(i: UInt): Scalar = fromULong(i.toULong()) - fun fromULong(l: ULong): Scalar { - val encoded = UByteArray(crypto_core_ed25519_SCALARBYTES) - var rem = l + fun fromULong(l: ULong): Scalar { + val encoded = UByteArray(crypto_core_ed25519_SCALARBYTES) + var rem = l - for (i in 0..7) { - encoded[i] = (rem and 0xffU).toUByte() - rem = rem shr 8 + for (i in 0..7) { + encoded[i] = (rem and 0xffU).toUByte() + rem = rem shr 8 + } + + return Scalar(encoded) + } + + fun fromHex(hex: String): Scalar { + require(hex.length <= 2 * crypto_core_ed25519_NONREDUCEDSCALARBYTES) { + "Scalars must be at most $crypto_core_ed25519_NONREDUCEDSCALARBYTES bytes long" + } + + if (hex.length > 2 * crypto_core_ed25519_SCALARBYTES) { + val encoded = LibsodiumUtil.fromHex(hex.padEnd(2 * crypto_core_ed25519_NONREDUCEDSCALARBYTES, '0')) + // Scalars are encoded in little-endian order, so the end can be padded with zeroes up to the size of a + // non-reduced scalar. After decoding, it is reduced, to obtain a scalar in the canonical range + return Scalar(reduceScalar(encoded)) + } else { + val encoded = LibsodiumUtil.fromHex(hex.padEnd(2 * crypto_core_ed25519_SCALARBYTES, '0')) + // Scalars are encoded in little-endian order, so the end can be padded with zeroes up to the size of a + // scalar. + return Scalar(encoded) + } + } } - - return Scalar(encoded) - } - - fun fromHex(hex: String): Scalar { - require(hex.length <= 2 * crypto_core_ed25519_NONREDUCEDSCALARBYTES) { - "Scalars must be at most $crypto_core_ed25519_NONREDUCEDSCALARBYTES bytes long" - } - - if (hex.length > 2 * crypto_core_ed25519_SCALARBYTES) { - val encoded = LibsodiumUtil.fromHex(hex.padEnd(2 * crypto_core_ed25519_NONREDUCEDSCALARBYTES, '0')) - // Scalars are encoded in little-endian order, so the end can be padded with zeroes up to the size of a - // non-reduced scalar. After decoding, it is reduced, to obtain a scalar in the canonical range - return Scalar(reduceScalar(encoded)) - } else { - val encoded = LibsodiumUtil.fromHex(hex.padEnd(2 * crypto_core_ed25519_SCALARBYTES, '0')) - // Scalars are encoded in little-endian order, so the end can be padded with zeroes up to the size of a - // scalar. - return Scalar(encoded) - } - } } - } } \ 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 8a43cea..790632a 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 @@ -17,158 +17,159 @@ const val crypto_scalarmult_ristretto255_BYTES = 32U const val crypto_scalarmult_ristretto255_SCALARBYTES = 32U expect abstract class 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 invertScalar(scalar: UByteArray): UByteArray - fun negateScalar(scalar: UByteArray): UByteArray - fun complementScalar(scalar: UByteArray): UByteArray - fun addScalars(x: UByteArray, y: UByteArray): UByteArray - fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray - fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray - fun reduceScalar(scalar: UByteArray): UByteArray - fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray - fun scalarMultiplicationBase(n: UByteArray): UByteArray + 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 invertScalar(scalar: UByteArray): UByteArray + fun negateScalar(scalar: UByteArray): UByteArray + fun complementScalar(scalar: UByteArray): UByteArray + fun addScalars(x: UByteArray, y: UByteArray): UByteArray + fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray + fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray + fun reduceScalar(scalar: UByteArray): UByteArray + fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray + fun scalarMultiplicationBase(n: UByteArray): UByteArray } object Ristretto255 : Ristretto255LowLevel() { - fun add(p: Point, q: Point): Point = - Point(addPoints(p.encoded, q.encoded)) + 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 subtract(p: Point, q: Point): Point = + Point(subtractPoints(p.encoded, q.encoded)) - fun pointFromHash(hash: UByteArray): Point = Point(encodedPointFromHash(hash)) + fun pointFromHash(hash: UByteArray): Point = Point(encodedPointFromHash(hash)) - fun randomPoint(): Point = Point(randomEncodedPoint()) + fun randomPoint(): Point = Point(randomEncodedPoint()) - fun randomScalar(): Scalar = Scalar(randomEncodedScalar()) + fun randomScalar(): Scalar = Scalar(randomEncodedScalar()) - fun invert(scalar: Scalar): Scalar = - Scalar(invertScalar(scalar.encoded)) + fun invert(scalar: Scalar): Scalar = + Scalar(invertScalar(scalar.encoded)) - fun negate(scalar: Scalar): Scalar = - Scalar(negateScalar(scalar.encoded)) + fun negate(scalar: Scalar): Scalar = + Scalar(negateScalar(scalar.encoded)) - fun complement(scalar: Scalar): Scalar = - Scalar(complementScalar(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 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 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 multiply(x: Scalar, y: Scalar): Scalar = + Scalar(multiplyScalars(x.encoded, y.encoded)) - fun reduce(scalar: Scalar): Scalar = - Scalar(reduceScalar(scalar.encoded)) + fun reduce(scalar: Scalar): Scalar = + Scalar(reduceScalar(scalar.encoded)) - fun scalarMultiplication(p: Point, n: Scalar): Point = - Point(scalarMultiplication(n.encoded, p.encoded)) + fun scalarMultiplication(p: Point, n: Scalar): Point = + Point(scalarMultiplication(n.encoded, p.encoded)) - fun scalarMultiplicationBase(n: Scalar): Point = - Point(scalarMultiplicationBase(n.encoded)) + fun scalarMultiplicationBase(n: Scalar): Point = + Point(scalarMultiplicationBase(n.encoded)) - data class Point(val encoded: UByteArray) { - operator fun plus(q: Point): Point = add(this, q) - operator fun minus(q: Point): Point = subtract(this, q) + data class Point(val encoded: UByteArray) { + operator fun plus(q: Point): Point = add(this, q) + operator fun minus(q: Point): Point = subtract(this, q) - operator fun times(n: Scalar): Point = scalarMultiplication(this, n) + operator fun times(n: Scalar): Point = scalarMultiplication(this, n) - fun toHex(): String = LibsodiumUtil.toHex(encoded) + fun toHex(): String = LibsodiumUtil.toHex(encoded) - override fun equals(other: Any?): Boolean = (other as? Point)?.encoded?.contentEquals(encoded) == true - override fun hashCode(): Int = encoded.contentHashCode() + override fun equals(other: Any?): Boolean = (other as? Point)?.encoded?.contentEquals(encoded) == true + override fun hashCode(): Int = encoded.contentHashCode() - companion object { - val IDENTITY: Point = Point(UByteArray(crypto_core_ristretto255_BYTES)) - val BASE: Point = scalarMultiplicationBase(Scalar.ONE) + companion object { + val IDENTITY: Point = Point(UByteArray(crypto_core_ristretto255_BYTES)) + val BASE: Point = scalarMultiplicationBase(Scalar.ONE) - fun fromHash(hash: UByteArray): Point = pointFromHash(hash) + fun fromHash(hash: UByteArray): Point = pointFromHash(hash) - fun random(): Point = randomPoint() + fun random(): Point = randomPoint() - fun multiplyBase(n: Scalar): Point = scalarMultiplicationBase(n) + fun multiplyBase(n: Scalar): Point = scalarMultiplicationBase(n) - fun fromHex(hex: String): Point = Point(LibsodiumUtil.fromHex(hex)) + fun fromHex(hex: String): Point = Point(LibsodiumUtil.fromHex(hex)) + } } - } - data class Scalar(val encoded: UByteArray) { - operator fun plus(y: Scalar): Scalar = add(this, y) - operator fun plus(y: UInt): Scalar = this + fromUInt(y) - operator fun plus(y: ULong): Scalar = this + fromULong(y) + data class Scalar(val encoded: UByteArray) { + operator fun plus(y: Scalar): Scalar = add(this, y) + operator fun plus(y: UInt): Scalar = this + fromUInt(y) + operator fun plus(y: ULong): Scalar = this + fromULong(y) - operator fun minus(y: Scalar): Scalar = subtract(this, y) - operator fun minus(y: UInt): Scalar = this - fromUInt(y) - operator fun minus(y: ULong): Scalar = this - fromULong(y) + operator fun minus(y: Scalar): Scalar = subtract(this, y) + operator fun minus(y: UInt): Scalar = this - fromUInt(y) + operator fun minus(y: ULong): Scalar = this - fromULong(y) - operator fun times(y: Scalar): Scalar = multiply(this, y) - operator fun times(y: UInt): Scalar = this * fromUInt(y) - operator fun times(y: ULong): Scalar = this * fromULong(y) + operator fun times(y: Scalar): Scalar = multiply(this, y) + operator fun times(y: UInt): Scalar = this * fromUInt(y) + operator fun times(y: ULong): Scalar = this * fromULong(y) - operator fun div(y: Scalar): Scalar = multiply(this, invert(y)) - operator fun div(y: UInt): Scalar = this / fromUInt(y) - operator fun div(y: ULong): Scalar = this / fromULong(y) + operator fun div(y: Scalar): Scalar = multiply(this, invert(y)) + 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 = negate(this) - operator fun times(p: Point): Point = scalarMultiplication(p, this) + operator fun times(p: Point): Point = scalarMultiplication(p, this) - fun reduce(): Scalar = reduce(this) - fun invert(): Scalar = invert(this) - fun complement(): Scalar = complement(this) + fun reduce(): Scalar = reduce(this) + fun invert(): Scalar = invert(this) + fun complement(): Scalar = complement(this) - fun multiplyWithBase(): Point = scalarMultiplicationBase(this) + fun multiplyWithBase(): Point = scalarMultiplicationBase(this) - fun toHex(): String = LibsodiumUtil.toHex(encoded) + 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() + 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) + companion object { + val ZERO = fromUInt(0U) + val ONE = fromUInt(1U) + val TWO = fromUInt(2U) - fun random(): Scalar = randomScalar() + fun random(): Scalar = randomScalar() - fun fromUInt(i: UInt): Scalar = fromULong(i.toULong()) + fun fromUInt(i: UInt): Scalar = fromULong(i.toULong()) - fun fromULong(l: ULong): Scalar { - val encoded = UByteArray(crypto_core_ristretto255_SCALARBYTES) - var rem = l + fun fromULong(l: ULong): Scalar { + val encoded = UByteArray(crypto_core_ristretto255_SCALARBYTES) + var rem = l - for (i in 0..7) { - encoded[i] = (rem and 0xffU).toUByte() - rem = rem shr 8 + for (i in 0..7) { + encoded[i] = (rem and 0xffU).toUByte() + rem = rem shr 8 + } + + return Scalar(encoded) + } + + fun fromHex(hex: String): Scalar { + require(hex.length <= 2 * crypto_core_ristretto255_NONREDUCEDSCALARBYTES) { + "Scalars must be at most $crypto_core_ristretto255_NONREDUCEDSCALARBYTES bytes long" + } + + if (hex.length > 2 * crypto_core_ristretto255_SCALARBYTES) { + val encoded = + LibsodiumUtil.fromHex(hex.padEnd(2 * crypto_core_ristretto255_NONREDUCEDSCALARBYTES, '0')) + // Scalars are encoded in little-endian order, so the end can be padded with zeroes up to the size of a + // non-reduced scalar. After decoding, it is reduced, to obtain a scalar in the canonical range + return Scalar(reduceScalar(encoded)) + } else { + val encoded = LibsodiumUtil.fromHex(hex.padEnd(2 * crypto_core_ristretto255_SCALARBYTES, '0')) + // Scalars are encoded in little-endian order, so the end can be padded with zeroes up to the size of a + // scalar. + return Scalar(encoded) + } + } } - - return Scalar(encoded) - } - - fun fromHex(hex: String): Scalar { - require(hex.length <= 2 * crypto_core_ristretto255_NONREDUCEDSCALARBYTES) { - "Scalars must be at most $crypto_core_ristretto255_NONREDUCEDSCALARBYTES bytes long" - } - - if (hex.length > 2 * crypto_core_ristretto255_SCALARBYTES) { - val encoded = LibsodiumUtil.fromHex(hex.padEnd(2 * crypto_core_ristretto255_NONREDUCEDSCALARBYTES, '0')) - // Scalars are encoded in little-endian order, so the end can be padded with zeroes up to the size of a - // non-reduced scalar. After decoding, it is reduced, to obtain a scalar in the canonical range - return Scalar(reduceScalar(encoded)) - } else { - val encoded = LibsodiumUtil.fromHex(hex.padEnd(2 * crypto_core_ristretto255_SCALARBYTES, '0')) - // Scalars are encoded in little-endian order, so the end can be padded with zeroes up to the size of a - // scalar. - return Scalar(encoded) - } - } } - } } \ 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 1a07af8..e7d3e6c 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 @@ -10,244 +10,244 @@ import kotlin.test.assertNotEquals import kotlin.test.assertTrue class Ed25519Test { - // Test vectors from https://github.com/jedisct1/libsodium/blob/master/test/default/core_ed25519.c - val badEncodings = arrayOf( - "0000000000000000000000000000000000000000000000000000000000000000", - "0100000000000000000000000000000000000000000000000000000000000000", - "0200000000000000000000000000000000000000000000000000000000000000", - // Non canonical encodings - "f6ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f", - "f5ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f", - ) + // Test vectors from https://github.com/jedisct1/libsodium/blob/master/test/default/core_ed25519.c + val badEncodings = arrayOf( + "0000000000000000000000000000000000000000000000000000000000000000", + "0100000000000000000000000000000000000000000000000000000000000000", + "0200000000000000000000000000000000000000000000000000000000000000", + // Non canonical encodings + "f6ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f", + "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 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", - "9d2e8fc82097672be7b3eb9b9ac74d0cd22087ce04a202a51e88702dceab88a1" to "6b1f76c95d2a201a25b77e73de875637e250acb8e22c44230b2c21bb5a45bb15", - "7863e96b9a73ffb45df22e2692f395d24b5d7acf745c5fa536818fd00e3ba6f6" to "43be765b38f32d815203e1657c261545366f15b24af2a97694b9320b4a36c407", - "1dfd309d25f6a2c6e0358cddf8dcf8c0fd018ccc7eb799d71fa829640cb5adb3" to "4c6b7015631f4063d85f3b195c7dfcb699a242b3449dc9b4abce8948df88a28e", - "40bc69ec71804975dfcbd90b18ca5d9d0117b2e15cacf61e21960b33742a9d55" to "722b608070036ad2e82927338c5edca18f2d0e6f8ed393321ed3704269af1f29", - "06c705d68c6224de01437208d7af2b3d933c1822abbe8f551b584cba073dc645" to "bb713b72bf705cc5a3daf299b787d28d47fdb39dc98a13082657b4137081624f", - "e4307d89b2e904063a6a16c9cf09b4225e0b5f4dd2367f08b11bf7787fa626d3" to "f10dea3347ab6792fac62ee6825dad3e4915f15287506db8067ecdbf00f0f30a", - "6f61fe548ff2cd7bc64d1d3cf4a707a8efba8247e906042d76e98b730f5d1d4d" to "5c43c14cb548b09ac8180c627bcf76bd7720aca21ef72cc13c5584e34ec23ff6", - ) + // Test vectors generated with sodium.js + private val fromUniformTestVectors = arrayOf( + "d5d31a04bf9cd6b4f3f014ab57f95d439a0bd741e71f1ecb580143235545255e" to "cb9fff40134270e80e0dcfcdc66aa4ebf02cd27c9d9d26adfdf78d0012ad1b62", + "9d2e8fc82097672be7b3eb9b9ac74d0cd22087ce04a202a51e88702dceab88a1" to "6b1f76c95d2a201a25b77e73de875637e250acb8e22c44230b2c21bb5a45bb15", + "7863e96b9a73ffb45df22e2692f395d24b5d7acf745c5fa536818fd00e3ba6f6" to "43be765b38f32d815203e1657c261545366f15b24af2a97694b9320b4a36c407", + "1dfd309d25f6a2c6e0358cddf8dcf8c0fd018ccc7eb799d71fa829640cb5adb3" to "4c6b7015631f4063d85f3b195c7dfcb699a242b3449dc9b4abce8948df88a28e", + "40bc69ec71804975dfcbd90b18ca5d9d0117b2e15cacf61e21960b33742a9d55" to "722b608070036ad2e82927338c5edca18f2d0e6f8ed393321ed3704269af1f29", + "06c705d68c6224de01437208d7af2b3d933c1822abbe8f551b584cba073dc645" to "bb713b72bf705cc5a3daf299b787d28d47fdb39dc98a13082657b4137081624f", + "e4307d89b2e904063a6a16c9cf09b4225e0b5f4dd2367f08b11bf7787fa626d3" to "f10dea3347ab6792fac62ee6825dad3e4915f15287506db8067ecdbf00f0f30a", + "6f61fe548ff2cd7bc64d1d3cf4a707a8efba8247e906042d76e98b730f5d1d4d" to "5c43c14cb548b09ac8180c627bcf76bd7720aca21ef72cc13c5584e34ec23ff6", + ) - // Test vectors generated with sodium.js - private val basePointSmallMultiplesNoClamp = arrayOf( - // This is the basepoint - "5866666666666666666666666666666666666666666666666666666666666666", - // These are small multiples of the basepoint - "c9a3f86aae465f0e56513864510f3997561fa2c9e85ea21dc2292309f3cd6022", - "d4b4f5784868c3020403246717ec169ff79e26608ea126a1ab69ee77d1b16712", - "2f1132ca61ab38dff00f2fea3228f24c6c71d58085b80e47e19515cb27e8d047", - "edc876d6831fd2105d0b4389ca2e283166469289146e2ce06faefe98b22548df", - "f47e49f9d07ad2c1606b4d94067c41f9777d4ffda709b71da1d88628fce34d85", - "b862409fb5c4c4123df2abf7462b88f041ad36dd6864ce872fd5472be363c5b1", - "b4b937fca95b2f1e93e41e62fc3c78818ff38a66096fad6e7973e5c90006d321", - "c0f1225584444ec730446e231390781ffdd2f256e9fcbeb2f40dddc2c2233d7f", - "2c7be86ab07488ba43e8e03d85a67625cfbf98c8544de4c877241b7aaafc7fe3", - "1337036ac32d8f30d4589c3c1c595812ce0fff40e37c6f5a97ab213f318290ad", - "f9e42d2edc81d23367967352b47e4856b82578634e6c1de72280ce8b60ce70c0", - "801f40eaaee1ef8723279a28b2cf4037b889dad222604678748b53ed0db0db92", - "39289c8998fd69835c26b619e89848a7bf02b7cb7ad1ba1581cbc4506f2550ce", - "df5c2eadc44c6d94a19a9aa118afe5ac3193d26401f76251f522ff042dfbcb92", - "eb2767c137ab7ad8279c078eff116ab0786ead3a2e0f989f72c37f82f2969670", - ) + // Test vectors generated with sodium.js + private val basePointSmallMultiplesNoClamp = arrayOf( + // This is the basepoint + "5866666666666666666666666666666666666666666666666666666666666666", + // These are small multiples of the basepoint + "c9a3f86aae465f0e56513864510f3997561fa2c9e85ea21dc2292309f3cd6022", + "d4b4f5784868c3020403246717ec169ff79e26608ea126a1ab69ee77d1b16712", + "2f1132ca61ab38dff00f2fea3228f24c6c71d58085b80e47e19515cb27e8d047", + "edc876d6831fd2105d0b4389ca2e283166469289146e2ce06faefe98b22548df", + "f47e49f9d07ad2c1606b4d94067c41f9777d4ffda709b71da1d88628fce34d85", + "b862409fb5c4c4123df2abf7462b88f041ad36dd6864ce872fd5472be363c5b1", + "b4b937fca95b2f1e93e41e62fc3c78818ff38a66096fad6e7973e5c90006d321", + "c0f1225584444ec730446e231390781ffdd2f256e9fcbeb2f40dddc2c2233d7f", + "2c7be86ab07488ba43e8e03d85a67625cfbf98c8544de4c877241b7aaafc7fe3", + "1337036ac32d8f30d4589c3c1c595812ce0fff40e37c6f5a97ab213f318290ad", + "f9e42d2edc81d23367967352b47e4856b82578634e6c1de72280ce8b60ce70c0", + "801f40eaaee1ef8723279a28b2cf4037b889dad222604678748b53ed0db0db92", + "39289c8998fd69835c26b619e89848a7bf02b7cb7ad1ba1581cbc4506f2550ce", + "df5c2eadc44c6d94a19a9aa118afe5ac3193d26401f76251f522ff042dfbcb92", + "eb2767c137ab7ad8279c078eff116ab0786ead3a2e0f989f72c37f82f2969670", + ) - // Test vectors generated with sodium.js - // Because of clamping, the lowest three bits of the scalar are cleared to make it a multiple of the cofactor (8) - // This makes two scalars yield the same result if they only differ in the lowest three bits. Because of this, for - // these test vectors, the scalars used to obtain them are set to s = i * 4 + 1 where i is the index - val basePointSmallMultiplesClamped = arrayOf( - "693e47972caf527c7883ad1b39822f026f47db2ab0e1919955b8993aa04411d1", - "693e47972caf527c7883ad1b39822f026f47db2ab0e1919955b8993aa04411d1", - "c9877dfd1ccda6393a15aed8aba06798456798355f2a9da4e182fecd40290157", - "c9877dfd1ccda6393a15aed8aba06798456798355f2a9da4e182fecd40290157", - "33598cc739b5da481888220cc8d584ba6c385a4c489cb6305446fd78d591bd96", - "33598cc739b5da481888220cc8d584ba6c385a4c489cb6305446fd78d591bd96", - "b46a44945eaff85c6de56812f8b035f01f6680a6f37f74bc6aa992bd0ef2d32a", - "b46a44945eaff85c6de56812f8b035f01f6680a6f37f74bc6aa992bd0ef2d32a", - "31b532ff5943a5c73690714ceb6414b99d50b0daee2b2d994ea78adf7ac28f4f", - "31b532ff5943a5c73690714ceb6414b99d50b0daee2b2d994ea78adf7ac28f4f", - "140fcdae065d38753b1b563c61ab588da04e7b822a5575483d123fb96f30868d", - "140fcdae065d38753b1b563c61ab588da04e7b822a5575483d123fb96f30868d", - "cb920ec5b5ebcce941d7e84c9ade21d4628c2b020b3c32f7e1b07fbb825c145d", - "cb920ec5b5ebcce941d7e84c9ade21d4628c2b020b3c32f7e1b07fbb825c145d", - "d479546534fa8a146475623ca938efe42c6d561732088f8c3fd687ffff15210b", - "d479546534fa8a146475623ca938efe42c6d561732088f8c3fd687ffff15210b", - ) + // Test vectors generated with sodium.js + // Because of clamping, the lowest three bits of the scalar are cleared to make it a multiple of the cofactor (8) + // This makes two scalars yield the same result if they only differ in the lowest three bits. Because of this, for + // these test vectors, the scalars used to obtain them are set to s = i * 4 + 1 where i is the index + val basePointSmallMultiplesClamped = arrayOf( + "693e47972caf527c7883ad1b39822f026f47db2ab0e1919955b8993aa04411d1", + "693e47972caf527c7883ad1b39822f026f47db2ab0e1919955b8993aa04411d1", + "c9877dfd1ccda6393a15aed8aba06798456798355f2a9da4e182fecd40290157", + "c9877dfd1ccda6393a15aed8aba06798456798355f2a9da4e182fecd40290157", + "33598cc739b5da481888220cc8d584ba6c385a4c489cb6305446fd78d591bd96", + "33598cc739b5da481888220cc8d584ba6c385a4c489cb6305446fd78d591bd96", + "b46a44945eaff85c6de56812f8b035f01f6680a6f37f74bc6aa992bd0ef2d32a", + "b46a44945eaff85c6de56812f8b035f01f6680a6f37f74bc6aa992bd0ef2d32a", + "31b532ff5943a5c73690714ceb6414b99d50b0daee2b2d994ea78adf7ac28f4f", + "31b532ff5943a5c73690714ceb6414b99d50b0daee2b2d994ea78adf7ac28f4f", + "140fcdae065d38753b1b563c61ab588da04e7b822a5575483d123fb96f30868d", + "140fcdae065d38753b1b563c61ab588da04e7b822a5575483d123fb96f30868d", + "cb920ec5b5ebcce941d7e84c9ade21d4628c2b020b3c32f7e1b07fbb825c145d", + "cb920ec5b5ebcce941d7e84c9ade21d4628c2b020b3c32f7e1b07fbb825c145d", + "d479546534fa8a146475623ca938efe42c6d561732088f8c3fd687ffff15210b", + "d479546534fa8a146475623ca938efe42c6d561732088f8c3fd687ffff15210b", + ) - @Test - fun testRandomPoint() = runTest { - LibsodiumInitializer.initializeWithCallback { - val p = Ed25519.Point.random() - val q = Ed25519.Point.random() - val r = Ed25519.Point.random() + @Test + fun testRandomPoint() = runTest { + LibsodiumInitializer.initializeWithCallback { + val p = Ed25519.Point.random() + val q = Ed25519.Point.random() + val r = Ed25519.Point.random() - assertNotEquals(p, q) - assertNotEquals(q, r) - assertNotEquals(r, p) + assertNotEquals(p, q) + assertNotEquals(q, r) + assertNotEquals(r, p) - assertTrue { Ed25519.isValidPoint(p.encoded) } - assertTrue { Ed25519.isValidPoint(q.encoded) } - assertTrue { Ed25519.isValidPoint(r.encoded) } - } - } - - @Test - fun testPointHexConversion() = runTest { - LibsodiumInitializer.initializeWithCallback { - repeat(10) { - val p = Ed25519.Point.random() - - assertEquals(p, Ed25519.Point.fromHex(p.toHex())) - } - } - } - - @Test - fun testIsValidPoint() = runTest { - LibsodiumInitializer.initializeWithCallback { - for (hexEncoded in badEncodings) { - assertFalse { Ed25519.isValidPoint(LibsodiumUtil.fromHex(hexEncoded)) } - } - - for (hexEncoded in basePointSmallMultiplesNoClamp) { - assertTrue { Ed25519.isValidPoint(LibsodiumUtil.fromHex(hexEncoded)) } - } - - for (hexEncoded in basePointSmallMultiplesClamped) { - assertTrue { Ed25519.isValidPoint(LibsodiumUtil.fromHex(hexEncoded)) } - } - } - } - - @Test - fun testPointArithmeticNoClamp() = runTest { - LibsodiumInitializer.initializeWithCallback { - for (i in basePointSmallMultiplesNoClamp.indices) { - val p = Ed25519.Point.fromHex(basePointSmallMultiplesNoClamp[i]) - val b = Ed25519.Point.BASE - val n = Ed25519.Scalar.fromUInt(i.toUInt() + 1U) - - assertEquals(p, Ed25519.scalarMultiplicationBaseNoClamp(n)) - assertEquals(p, Ed25519.scalarMultiplicationNoClamp(b, n)) - assertEquals(p, n.multiplyWithBaseNoClamp()) - - for (j in 0.. = listOf("state", "count", "buf") + override fun getFieldOrder(): List = listOf("state", "count", "buf") - @JvmField - val state = IntArray(8) + @JvmField + val state = IntArray(8) - @JvmField - var count: Long = 0 + @JvmField + var count: Long = 0 - @JvmField - val buf = ByteArray(64) + @JvmField + val buf = ByteArray(64) } class Hash512State : Structure() { - override fun getFieldOrder(): List = listOf("state", "count", "buf") + override fun getFieldOrder(): List = listOf("state", "count", "buf") - @JvmField - val state = LongArray(8) + @JvmField + val state = LongArray(8) - @JvmField - var count: LongArray = LongArray(2) + @JvmField + var count: LongArray = LongArray(2) - @JvmField - val buf = ByteArray(128) + @JvmField + val buf = ByteArray(128) } class Blake2bState : Structure() { - override fun getFieldOrder(): List = listOf("opaque") + override fun getFieldOrder(): List = listOf("opaque") - @JvmField - val opaque = ByteArray(384) + @JvmField + val opaque = ByteArray(384) } //typedef struct crypto_sign_ed25519ph_state { // crypto_hash_sha512_state hs; //} crypto_sign_ed25519ph_state; class Ed25519SignatureState : Structure() { - override fun getFieldOrder() = listOf("hs") + override fun getFieldOrder() = listOf("hs") - @JvmField - var hs: Hash512State = Hash512State() + @JvmField + var hs: Hash512State = Hash512State() } @@ -59,995 +59,995 @@ class Ed25519SignatureState : Structure() { // unsigned char _pad[8]; // } crypto_secretstream_xchacha20poly1305_state; class SecretStreamXChaCha20Poly1305State : Structure() { - override fun getFieldOrder(): List = listOf("k", "nonce", "_pad") + override fun getFieldOrder(): List = listOf("k", "nonce", "_pad") - @JvmField - val k = ByteArray(32) + @JvmField + val k = ByteArray(32) - @JvmField - val nonce = ByteArray(12) + @JvmField + val nonce = ByteArray(12) - @JvmField - val _pad = ByteArray(8) + @JvmField + val _pad = ByteArray(8) } interface JnaLibsodiumInterface : Library { - // ---- Initialization --- + // ---- Initialization --- - fun sodium_init(): Int + fun sodium_init() : Int - // ---- Initialization end --- + // ---- Initialization end --- - // ---- Utils ---- - fun sodium_version_string(): String + // ---- Utils ---- + fun sodium_version_string(): String - // void - // randombytes_buf(void * const buf, const size_t size) - fun randombytes_buf(buffer: ByteArray, bufferSize: Int) + // void + // randombytes_buf(void * const buf, const size_t size) + fun randombytes_buf(buffer: ByteArray, bufferSize: Int) - // void randombytes_buf_deterministic(void * const buf, const size_t size, - // const unsigned char seed[randombytes_SEEDBYTES]) - fun randombytes_buf_deterministic( - buffer: ByteArray, - size: Int, - seed: ByteArray, - ) + // void randombytes_buf_deterministic(void * const buf, const size_t size, + // const unsigned char seed[randombytes_SEEDBYTES]) + fun randombytes_buf_deterministic( + buffer: ByteArray, + size: Int, + seed: ByteArray + ) - // uint32_t randombytes_random(void) - fun randombytes_random(): Long + // uint32_t randombytes_random(void) + fun randombytes_random() : Long - // uint32_t randombytes_uniform(const uint32_t upper_bound); - fun randombytes_uniform( - upperBound: Long, - ): Long + // uint32_t randombytes_uniform(const uint32_t upper_bound); + fun randombytes_uniform( + upperBound: Long + ) : Long - // void sodium_memzero(void * const pnt, const size_t len); - fun sodium_memzero(array: ByteArray, len: Int) + // void sodium_memzero(void * const pnt, const size_t len); + fun sodium_memzero(array: ByteArray, len: Int) - // int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len) - fun sodium_memcmp(b1: ByteArray, b2: ByteArray, len: Int): Int + // int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len) + fun sodium_memcmp(b1: ByteArray, b2: ByteArray, len: Int): Int - // char *sodium_bin2hex(char * const hex, const size_t hex_maxlen, - // const unsigned char * const bin, const size_t bin_len) - fun sodium_bin2hex( - hex: ByteArray, - hexMaxlen: Int, - bin: ByteArray, - binLen: Int, - ): String + // char *sodium_bin2hex(char * const hex, const size_t hex_maxlen, + // const unsigned char * const bin, const size_t bin_len) + fun sodium_bin2hex( + hex: ByteArray, + hexMaxlen: Int, + bin: ByteArray, + binLen: Int + ): String - // int sodium_hex2bin( - // unsigned char * const bin, const size_t bin_maxlen, - // const char * const hex, const size_t hex_len, - // const char * const ignore, size_t * const bin_len, - // const char ** const hex_end) - fun sodium_hex2bin( - bin: ByteArray, - binMaxLength: Int, - hex: ByteArray, - hexLen: Int, - ignore: ByteArray?, - binLen: Pointer, - hexEnd: Pointer?, - ): Int + // int sodium_hex2bin( + // unsigned char * const bin, const size_t bin_maxlen, + // const char * const hex, const size_t hex_len, + // const char * const ignore, size_t * const bin_len, + // const char ** const hex_end) + fun sodium_hex2bin( + bin: ByteArray, + binMaxLength: Int, + hex: ByteArray, + hexLen: Int, + ignore: ByteArray?, + binLen: Pointer, + hexEnd: Pointer? + ): Int - // int sodium_pad(size_t *padded_buflen_p, unsigned char *buf, - // size_t unpadded_buflen, size_t blocksize, size_t max_buflen) - fun sodium_pad( - paddedBufferLength: Pointer, - buffer: ByteArray, - unpaddedBufferLength: Int, - blockSize: Int, - maxBufferLength: Int, - ): Int + // int sodium_pad(size_t *padded_buflen_p, unsigned char *buf, + // size_t unpadded_buflen, size_t blocksize, size_t max_buflen) + fun sodium_pad( + paddedBufferLength: Pointer, + buffer: ByteArray, + unpaddedBufferLength: Int, + blockSize: Int, + maxBufferLength: Int + ): Int - // int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf, - // size_t padded_buflen, size_t blocksize) - fun sodium_unpad( - unpaddedBufferLength: Pointer, - buffer: ByteArray, - paddedBufferLength: Int, - blockSize: Int, - ): Int + // int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf, + // size_t padded_buflen, size_t blocksize) + fun sodium_unpad( + unpaddedBufferLength: Pointer, + buffer: ByteArray, + paddedBufferLength: Int, + blockSize: Int + ) : Int - // char *sodium_bin2base64(char * const b64, const size_t b64_maxlen, - // const unsigned char * const bin, const size_t bin_len, - // const int variant) - fun sodium_bin2base64( - base64: ByteArray, - base64MaxLength: Int, - bin: ByteArray, - binLength: Int, - variant: Int, - ) + // char *sodium_bin2base64(char * const b64, const size_t b64_maxlen, + // const unsigned char * const bin, const size_t bin_len, + // const int variant) + fun sodium_bin2base64( + base64: ByteArray, + base64MaxLength: Int, + bin: ByteArray, + binLength: Int, + variant: Int + ) - // int sodium_base642bin( - // unsigned char * const bin, const size_t bin_maxlen, - // const char * const b64, const size_t b64_len, - // const char * const ignore, size_t * const bin_len, - // const char ** const b64_end, const int variant) - fun sodium_base642bin( - bin: ByteArray, - binMaxLength: Int, - base64: ByteArray, - base64Length: Int, - ignore: ByteArray?, - binLength: Pointer, - base64End: Pointer?, - variant: Int, - ): Int + // int sodium_base642bin( + // unsigned char * const bin, const size_t bin_maxlen, + // const char * const b64, const size_t b64_len, + // const char * const ignore, size_t * const bin_len, + // const char ** const b64_end, const int variant) + fun sodium_base642bin( + bin: ByteArray, + binMaxLength: Int, + base64: ByteArray, + base64Length: Int, + ignore: ByteArray?, + binLength: Pointer, + base64End: Pointer?, + variant: Int + ): Int - // size_t sodium_base64_encoded_len(const size_t bin_len, const int variant) - fun sodium_base64_encoded_len(binLength: Int, variant: Int): Int + // size_t sodium_base64_encoded_len(const size_t bin_len, const int variant) + fun sodium_base64_encoded_len(binLength: Int, variant: Int): Int - // --- Utils end ---- + // --- Utils end ---- - // int crypto_generichash(unsigned char *out, size_t outlen, - // const unsigned char *in, unsigned long long inlen, - // const unsigned char *key, size_t keylen) - fun crypto_generichash( - out: ByteArray, - outlen: Int, - input: ByteArray, - inputLength: Long, - key: ByteArray, - keylen: Int, - ): Int + // int crypto_generichash(unsigned char *out, size_t outlen, + // const unsigned char *in, unsigned long long inlen, + // const unsigned char *key, size_t keylen) + fun crypto_generichash( + out: ByteArray, + outlen: Int, + input: ByteArray, + inputLength: Long, + key: ByteArray, + keylen: Int + ): Int - // int crypto_hash_sha256(unsigned char *out, const unsigned char *in, - // unsigned long long inlen) - fun crypto_hash_sha256(out: ByteArray, input: ByteArray, inputLength: Long): Int + // int crypto_hash_sha256(unsigned char *out, const unsigned char *in, + // unsigned long long inlen) + fun crypto_hash_sha256(out: ByteArray, input: ByteArray, inputLength: Long): Int - // int crypto_hash_sha512(unsigned char *out, const unsigned char *in, - // unsigned long long inlen) - fun crypto_hash_sha512(out: ByteArray, input: ByteArray, inputLength: Long): Int + // int crypto_hash_sha512(unsigned char *out, const unsigned char *in, + // unsigned long long inlen) + fun crypto_hash_sha512(out: ByteArray, input: ByteArray, inputLength: Long): Int // // // ---- Generic hash ---- // Updateable // - // int crypto_generichash_init(crypto_generichash_state *state, - // const unsigned char *key, - // const size_t keylen, const size_t outlen) - // Output cant be larger than 64 so no need to use Long to represent size_t here - fun crypto_generichash_init(state: Blake2bState, key: ByteArray, keylen: Int, outlen: Int): Int + // int crypto_generichash_init(crypto_generichash_state *state, + // const unsigned char *key, + // const size_t keylen, const size_t outlen) + // Output cant be larger than 64 so no need to use Long to represent size_t here + fun crypto_generichash_init(state: Blake2bState, key: ByteArray, keylen: Int, outlen: Int): Int - // int crypto_generichash_update(crypto_generichash_state *state, - // const unsigned char *in, - // unsigned long long inlen) - fun crypto_generichash_update(state: Blake2bState, inputMessage: ByteArray, inputLength: Long): Int + // int crypto_generichash_update(crypto_generichash_state *state, + // const unsigned char *in, + // unsigned long long inlen) + fun crypto_generichash_update(state: Blake2bState, inputMessage: ByteArray, inputLength: Long): Int - // int crypto_generichash_final(crypto_generichash_state *state, - // unsigned char *out, const size_t outlen) - // Output cant be larger than 64 so no need to use Long to represent size_t here - fun crypto_generichash_final(state: Blake2bState, out: ByteArray, hashLength: Int): Int + // int crypto_generichash_final(crypto_generichash_state *state, + // unsigned char *out, const size_t outlen) + // Output cant be larger than 64 so no need to use Long to represent size_t here + fun crypto_generichash_final(state: Blake2bState, out: ByteArray, hashLength: Int): Int - // void crypto_generichash_keygen(unsigned char k[crypto_generichash_KEYBYTES]) - fun crypto_generichash_keygen(key: ByteArray) + // void crypto_generichash_keygen(unsigned char k[crypto_generichash_KEYBYTES]) + fun crypto_generichash_keygen(key: ByteArray) - fun crypto_generichash_statebytes(): Int + fun crypto_generichash_statebytes(): Int - // + // // // ---- Generic hash end ---- // Updateable // // // ---- Blake2b ---- - // int crypto_generichash_blake2b(unsigned char *out, size_t outlen, - // const unsigned char *in, - // unsigned long long inlen, - // const unsigned char *key, size_t keylen) - // Output cant be larger than 64 so no need to use Long to represent size_t here - fun crypto_generichash_blake2b( - out: ByteArray, - outlen: Int, - input: ByteArray, - inputLength: Long, - key: ByteArray, - keylen: Int, - ): Int + // int crypto_generichash_blake2b(unsigned char *out, size_t outlen, + // const unsigned char *in, + // unsigned long long inlen, + // const unsigned char *key, size_t keylen) + // Output cant be larger than 64 so no need to use Long to represent size_t here + fun crypto_generichash_blake2b( + out: ByteArray, + outlen: Int, + input: ByteArray, + inputLength: Long, + key: ByteArray, + keylen: Int + ): Int - // int crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state, - // const unsigned char *key, - // const size_t keylen, const size_t outlen) - fun crypto_generichash_blake2b_init(kstate: ByteArray, key: ByteArray, keylen: Int, outlen: Int): Int + // int crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state, + // const unsigned char *key, + // const size_t keylen, const size_t outlen) + fun crypto_generichash_blake2b_init(kstate: ByteArray, key: ByteArray, keylen: Int, outlen: Int): Int - // int crypto_generichash_blake2b_update(crypto_generichash_blake2b_state *state, - // const unsigned char *in, - // unsigned long long inlen) - fun crypto_generichash_blake2b_update(state: ByteArray, inputMessage: ByteArray, inputLength: Long): Int + // int crypto_generichash_blake2b_update(crypto_generichash_blake2b_state *state, + // const unsigned char *in, + // unsigned long long inlen) + fun crypto_generichash_blake2b_update(state: ByteArray, inputMessage: ByteArray, inputLength: Long): Int - // int crypto_generichash_blake2b_final(crypto_generichash_blake2b_state *state, - // unsigned char *out, - // const size_t outlen) - fun crypto_generichash_blake2b_final(state: ByteArray, out: ByteArray, hashLength: Int): Int + // int crypto_generichash_blake2b_final(crypto_generichash_blake2b_state *state, + // unsigned char *out, + // const size_t outlen) + fun crypto_generichash_blake2b_final(state: ByteArray, out: ByteArray, hashLength: Int): Int - // void crypto_generichash_blake2b_keygen(unsigned char k[crypto_generichash_blake2b_KEYBYTES]) - fun crypto_generichash_blake2b_keygen(key: ByteArray) + // void crypto_generichash_blake2b_keygen(unsigned char k[crypto_generichash_blake2b_KEYBYTES]) + fun crypto_generichash_blake2b_keygen(key: ByteArray) // // // ---- Blake2b end ---- // // // ---- Short hash ---- // - // int crypto_shorthash(unsigned char *out, const unsigned char *in, - // unsigned long long inlen, const unsigned char *k) - fun crypto_shorthash(out: ByteArray, input: ByteArray, inlen: Long, key: ByteArray): Int + // int crypto_shorthash(unsigned char *out, const unsigned char *in, + // unsigned long long inlen, const unsigned char *k) + fun crypto_shorthash(out: ByteArray, input: ByteArray, inlen: Long, key: ByteArray): Int - // void crypto_shorthash_keygen(unsigned char k[crypto_shorthash_KEYBYTES]) - fun crypto_shorthash_keygen(key: ByteArray) + // void crypto_shorthash_keygen(unsigned char k[crypto_shorthash_KEYBYTES]) + fun crypto_shorthash_keygen(key: ByteArray) // // ---- Short hash end ---- // - // int crypto_hash_sha256_init(crypto_hash_sha256_state *state) - fun crypto_hash_sha256_init(state: Hash256State): Int + // int crypto_hash_sha256_init(crypto_hash_sha256_state *state) + fun crypto_hash_sha256_init(state: Hash256State): Int - // int crypto_hash_sha256_update(crypto_hash_sha256_state *state, - // const unsigned char *in, - // unsigned long long inlen) - fun crypto_hash_sha256_update(state: Hash256State, input: ByteArray, inlen: Long): Int + // int crypto_hash_sha256_update(crypto_hash_sha256_state *state, + // const unsigned char *in, + // unsigned long long inlen) + fun crypto_hash_sha256_update(state: Hash256State, input: ByteArray, inlen: Long): Int - // int crypto_hash_sha256_final(crypto_hash_sha256_state *state, - // unsigned char *out) - fun crypto_hash_sha256_final(state: Hash256State, out: ByteArray): Int + // int crypto_hash_sha256_final(crypto_hash_sha256_state *state, + // unsigned char *out) + fun crypto_hash_sha256_final(state: Hash256State, out: ByteArray): Int - // int crypto_hash_sha512_init(crypto_hash_sha512_state *state) - fun crypto_hash_sha512_init(state: Hash512State): Int + // int crypto_hash_sha512_init(crypto_hash_sha512_state *state) + fun crypto_hash_sha512_init(state: Hash512State): Int - // int crypto_hash_sha512_update(crypto_hash_sha512_state *state, - // const unsigned char *in, - // unsigned long long inlen) - fun crypto_hash_sha512_update(state: Hash512State, input: ByteArray, inlen: Long): Int + // int crypto_hash_sha512_update(crypto_hash_sha512_state *state, + // const unsigned char *in, + // unsigned long long inlen) + fun crypto_hash_sha512_update(state: Hash512State, input: ByteArray, inlen: Long): Int - // int crypto_hash_sha512_final(crypto_hash_sha512_state *state, - // unsigned char *out) - fun crypto_hash_sha512_final(state: Hash512State, out: ByteArray): Int + // int crypto_hash_sha512_final(crypto_hash_sha512_state *state, + // unsigned char *out) + fun crypto_hash_sha512_final(state: Hash512State, out: ByteArray): Int - // - // --------------------- AEAD - // + // + // --------------------- AEAD + // - // - // XChaCha20Poly1305Ietf - // + // + // XChaCha20Poly1305Ietf + // - // int crypto_aead_xchacha20poly1305_ietf_encrypt( - // unsigned char *c, - // unsigned long long *clen_p, - // const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *nsec, - // const unsigned char *npub, - // const unsigned char *k - // ) - fun crypto_aead_xchacha20poly1305_ietf_encrypt( - ciphertext: ByteArray, - ciphertextLength: LongArray?, - message: ByteArray, - messageLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - nsec: ByteArray?, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_xchacha20poly1305_ietf_encrypt( + // unsigned char *c, + // unsigned long long *clen_p, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *nsec, + // const unsigned char *npub, + // const unsigned char *k + // ) + fun crypto_aead_xchacha20poly1305_ietf_encrypt( + ciphertext: ByteArray, + ciphertextLength: LongArray?, + message: ByteArray, + messageLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + nsec: ByteArray?, + npub: ByteArray, + key: ByteArray + ): Int - // int crypto_aead_xchacha20poly1305_ietf_decrypt( - // unsigned char *m, - // unsigned long long *mlen_p, - // unsigned char *nsec, - // const unsigned char *c, - // unsigned long long clen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_xchacha20poly1305_ietf_decrypt( - message: ByteArray, - messageLength: LongArray?, - nsec: ByteArray?, - ciphertext: ByteArray, - ciphertextLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_xchacha20poly1305_ietf_decrypt( + // unsigned char *m, + // unsigned long long *mlen_p, + // unsigned char *nsec, + // const unsigned char *c, + // unsigned long long clen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_xchacha20poly1305_ietf_decrypt( + message: ByteArray, + messageLength: LongArray?, + nsec: ByteArray?, + ciphertext: ByteArray, + ciphertextLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + npub: ByteArray, + key: ByteArray + ): Int - // int crypto_aead_xchacha20poly1305_ietf_encrypt_detached( - // unsigned char *c, - // unsigned char *mac, - // unsigned long long *maclen_p, - // const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *nsec, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached( - ciphertext: ByteArray, - mac: ByteArray, - maclen: LongArray?, - message: ByteArray, - messageLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - nsec: ByteArray?, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_xchacha20poly1305_ietf_encrypt_detached( + // unsigned char *c, + // unsigned char *mac, + // unsigned long long *maclen_p, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *nsec, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_xchacha20poly1305_ietf_encrypt_detached( + ciphertext: ByteArray, + mac: ByteArray, + maclen: LongArray?, + message: ByteArray, + messageLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + nsec: ByteArray?, + npub: ByteArray, + key: ByteArray + ): Int - // int crypto_aead_xchacha20poly1305_ietf_decrypt_detached( - // unsigned char *m, - // unsigned char *nsec, - // const unsigned char *c, - // unsigned long long clen, - // const unsigned char *mac, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_xchacha20poly1305_ietf_decrypt_detached( - message: ByteArray, - nsec: ByteArray?, - ciphertext: ByteArray, - ciphertextLength: Long, - mac: ByteArray, - additionalData: ByteArray, - additionalDataLength: Long, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_xchacha20poly1305_ietf_decrypt_detached( + // unsigned char *m, + // unsigned char *nsec, + // const unsigned char *c, + // unsigned long long clen, + // const unsigned char *mac, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_xchacha20poly1305_ietf_decrypt_detached( + message: ByteArray, + nsec: ByteArray?, + ciphertext: ByteArray, + ciphertextLength: Long, + mac: ByteArray, + additionalData: ByteArray, + additionalDataLength: Long, + npub: ByteArray, + key: ByteArray + ): Int - // void crypto_aead_xchacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES]) - fun crypto_aead_xchacha20poly1305_ietf_keygen(key: ByteArray) + // void crypto_aead_xchacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES]) + fun crypto_aead_xchacha20poly1305_ietf_keygen(key: ByteArray) - // - // ChaCha20Poly1305Ietf - // + // + // ChaCha20Poly1305Ietf + // - // int crypto_aead_chacha20poly1305_ietf_encrypt( - // unsigned char *c, - // unsigned long long *clen_p, - // const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *nsec, - // const unsigned char *npub, - // const unsigned char *k - // ) - fun crypto_aead_chacha20poly1305_ietf_encrypt( - ciphertext: ByteArray, - ciphertextLength: LongArray?, - message: ByteArray, - messageLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - nsec: ByteArray?, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_chacha20poly1305_ietf_encrypt( + // unsigned char *c, + // unsigned long long *clen_p, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *nsec, + // const unsigned char *npub, + // const unsigned char *k + // ) + fun crypto_aead_chacha20poly1305_ietf_encrypt( + ciphertext: ByteArray, + ciphertextLength: LongArray?, + message: ByteArray, + messageLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + nsec: ByteArray?, + npub: ByteArray, + key: ByteArray + ) : Int - // int crypto_aead_chacha20poly1305_ietf_decrypt( - // unsigned char *m, - // unsigned long long *mlen_p, - // unsigned char *nsec, - // const unsigned char *c, - // unsigned long long clen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_chacha20poly1305_ietf_decrypt( - message: ByteArray, - messageLength: LongArray?, - nsec: ByteArray?, - ciphertext: ByteArray, - ciphertextLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_chacha20poly1305_ietf_decrypt( + // unsigned char *m, + // unsigned long long *mlen_p, + // unsigned char *nsec, + // const unsigned char *c, + // unsigned long long clen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_chacha20poly1305_ietf_decrypt( + message: ByteArray, + messageLength: LongArray?, + nsec: ByteArray?, + ciphertext: ByteArray, + ciphertextLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + npub: ByteArray, + key: ByteArray + ): Int - // int crypto_aead_chacha20poly1305_ietf_encrypt_detached( - // unsigned char *c, - // unsigned char *mac, - // unsigned long long *maclen_p, - // const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *nsec, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_chacha20poly1305_ietf_encrypt_detached( - ciphertext: ByteArray, - mac: ByteArray, - maclen: LongArray?, - message: ByteArray, - messageLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - nsec: ByteArray?, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_chacha20poly1305_ietf_encrypt_detached( + // unsigned char *c, + // unsigned char *mac, + // unsigned long long *maclen_p, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *nsec, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_chacha20poly1305_ietf_encrypt_detached( + ciphertext: ByteArray, + mac: ByteArray, + maclen: LongArray?, + message: ByteArray, + messageLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + nsec: ByteArray?, + npub: ByteArray, + key: ByteArray + ): Int - // int crypto_aead_chacha20poly1305_ietf_decrypt_detached( - // unsigned char *m, - // unsigned char *nsec, - // const unsigned char *c, - // unsigned long long clen, - // const unsigned char *mac, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_chacha20poly1305_ietf_decrypt_detached( - message: ByteArray, - nsec: ByteArray?, - ciphertext: ByteArray, - ciphertextLength: Long, - mac: ByteArray, - additionalData: ByteArray, - additionalDataLength: Long, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_chacha20poly1305_ietf_decrypt_detached( + // unsigned char *m, + // unsigned char *nsec, + // const unsigned char *c, + // unsigned long long clen, + // const unsigned char *mac, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_chacha20poly1305_ietf_decrypt_detached( + message: ByteArray, + nsec: ByteArray?, + ciphertext: ByteArray, + ciphertextLength: Long, + mac: ByteArray, + additionalData: ByteArray, + additionalDataLength: Long, + npub: ByteArray, + key: ByteArray + ): Int - // void crypto_aead_chacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES]) - fun crypto_aead_chacha20poly1305_ietf_keygen(key: ByteArray) + // void crypto_aead_chacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES]) + fun crypto_aead_chacha20poly1305_ietf_keygen(key: ByteArray) - // - // ChaCha20Poly1305 - // + // + // ChaCha20Poly1305 + // - // - // //decrypt - // int crypto_aead_xchacha20poly1305_encrypt( - // unsigned char *c, - // unsigned long long *clen_p, - // const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *nsec, - // const unsigned char *npub, - // const unsigned char *k - // ) - fun crypto_aead_chacha20poly1305_encrypt( - ciphertext: ByteArray, - ciphertextLength: LongArray?, - message: ByteArray, - messageLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - nsec: ByteArray?, - npub: ByteArray, - key: ByteArray, - ): Int + // + // //decrypt + // int crypto_aead_xchacha20poly1305_encrypt( + // unsigned char *c, + // unsigned long long *clen_p, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *nsec, + // const unsigned char *npub, + // const unsigned char *k + // ) + fun crypto_aead_chacha20poly1305_encrypt( + ciphertext: ByteArray, + ciphertextLength: LongArray?, + message: ByteArray, + messageLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + nsec: ByteArray?, + npub: ByteArray, + key: ByteArray + ): Int - // int crypto_aead_xchacha20poly1305_decrypt(unsigned char *m, - // unsigned long long *mlen_p, - // unsigned char *nsec, - // const unsigned char *c, - // unsigned long long clen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_chacha20poly1305_decrypt( - message: ByteArray, - messageLength: LongArray?, - nsec: ByteArray?, - ciphertext: ByteArray, - ciphertextLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_xchacha20poly1305_decrypt(unsigned char *m, + // unsigned long long *mlen_p, + // unsigned char *nsec, + // const unsigned char *c, + // unsigned long long clen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_chacha20poly1305_decrypt( + message: ByteArray, + messageLength: LongArray?, + nsec: ByteArray?, + ciphertext: ByteArray, + ciphertextLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + npub: ByteArray, + key: ByteArray + ): Int - // int crypto_aead_chacha20poly1305_encrypt_detached( - // unsigned char *c, - // unsigned char *mac, - // unsigned long long *maclen_p, - // const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *nsec, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_chacha20poly1305_encrypt_detached( - ciphertext: ByteArray, - mac: ByteArray, - maclen: LongArray?, - message: ByteArray, - messageLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - nsec: ByteArray?, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_chacha20poly1305_encrypt_detached( + // unsigned char *c, + // unsigned char *mac, + // unsigned long long *maclen_p, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *nsec, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_chacha20poly1305_encrypt_detached( + ciphertext: ByteArray, + mac: ByteArray, + maclen: LongArray?, + message: ByteArray, + messageLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + nsec: ByteArray?, + npub: ByteArray, + key: ByteArray + ): Int - // int crypto_aead_chacha20poly1305_decrypt_detached( - // unsigned char *m, - // unsigned char *nsec, - // const unsigned char *c, - // unsigned long long clen, - // const unsigned char *mac, - // const unsigned char *ad, - // unsigned long long adlen, - // const unsigned char *npub, - // const unsigned char *k) - fun crypto_aead_chacha20poly1305_decrypt_detached( - message: ByteArray, - nsec: ByteArray?, - ciphertext: ByteArray, - ciphertextLength: Long, - mac: ByteArray, - additionalData: ByteArray, - additionalDataLength: Long, - npub: ByteArray, - key: ByteArray, - ): Int + // int crypto_aead_chacha20poly1305_decrypt_detached( + // unsigned char *m, + // unsigned char *nsec, + // const unsigned char *c, + // unsigned long long clen, + // const unsigned char *mac, + // const unsigned char *ad, + // unsigned long long adlen, + // const unsigned char *npub, + // const unsigned char *k) + fun crypto_aead_chacha20poly1305_decrypt_detached( + message: ByteArray, + nsec: ByteArray?, + ciphertext: ByteArray, + ciphertextLength: Long, + mac: ByteArray, + additionalData: ByteArray, + additionalDataLength: Long, + npub: ByteArray, + key: ByteArray + ): Int - // void crypto_aead_chacha20poly1305_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES]) - fun crypto_aead_chacha20poly1305_keygen(key: ByteArray) + // void crypto_aead_chacha20poly1305_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES]) + fun crypto_aead_chacha20poly1305_keygen(key: ByteArray) - // ---- AEAD end ---- + // ---- AEAD end ---- - // ---- Secret stream ----- + // ---- Secret stream ----- - // crypto_secretstream_xchacha20poly1305_headerbytes - fun crypto_secretstream_xchacha20poly1305_headerbytes(): Int + // crypto_secretstream_xchacha20poly1305_headerbytes + fun crypto_secretstream_xchacha20poly1305_headerbytes(): Int - //encrypt + //encrypt - // int crypto_secretstream_xchacha20poly1305_init_push - // (crypto_secretstream_xchacha20poly1305_state *state, - // unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES], - // const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]) - fun crypto_secretstream_xchacha20poly1305_init_push( - state: SecretStreamXChaCha20Poly1305State, - header: ByteArray, - key: ByteArray, - ): Int + // int crypto_secretstream_xchacha20poly1305_init_push + // (crypto_secretstream_xchacha20poly1305_state *state, + // unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES], + // const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]) + fun crypto_secretstream_xchacha20poly1305_init_push( + state: SecretStreamXChaCha20Poly1305State, + header: ByteArray, + key: ByteArray + ): Int - // int crypto_secretstream_xchacha20poly1305_push - // (crypto_secretstream_xchacha20poly1305_state *state, - // unsigned char *c, unsigned long long *clen_p, - // const unsigned char *m, unsigned long long mlen, - // const unsigned char *ad, unsigned long long adlen, unsigned char tag) - fun crypto_secretstream_xchacha20poly1305_push( - state: SecretStreamXChaCha20Poly1305State, - ciphertext: ByteArray, - ciphertextLength: LongArray?, - message: ByteArray, - messageLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - tag: Byte, - ): Int + // int crypto_secretstream_xchacha20poly1305_push + // (crypto_secretstream_xchacha20poly1305_state *state, + // unsigned char *c, unsigned long long *clen_p, + // const unsigned char *m, unsigned long long mlen, + // const unsigned char *ad, unsigned long long adlen, unsigned char tag) + fun crypto_secretstream_xchacha20poly1305_push( + state: SecretStreamXChaCha20Poly1305State, + ciphertext: ByteArray, + ciphertextLength: LongArray?, + message: ByteArray, + messageLength: Long, + additionalData: ByteArray, + additionalDataLength: Long, + tag: Byte + ): Int - // decrypt + // decrypt - // int crypto_secretstream_xchacha20poly1305_init_pull - // (crypto_secretstream_xchacha20poly1305_state *state, - // const unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES], - // const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]) - fun crypto_secretstream_xchacha20poly1305_init_pull( - state: SecretStreamXChaCha20Poly1305State, - header: ByteArray, - key: ByteArray, - ): Int + // int crypto_secretstream_xchacha20poly1305_init_pull + // (crypto_secretstream_xchacha20poly1305_state *state, + // const unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES], + // const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]) + fun crypto_secretstream_xchacha20poly1305_init_pull( + state: SecretStreamXChaCha20Poly1305State, + header: ByteArray, + key: ByteArray + ): Int - // int crypto_secretstream_xchacha20poly1305_pull - // (crypto_secretstream_xchacha20poly1305_state *state, - // unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p, - // const unsigned char *c, unsigned long long clen, - // const unsigned char *ad, unsigned long long adlen) - fun crypto_secretstream_xchacha20poly1305_pull( - state: SecretStreamXChaCha20Poly1305State, - message: ByteArray, - messageLength: LongArray?, - tagAddress: ByteArray, - ciphertext: ByteArray, - ciphertextLength: Long, - additionalData: ByteArray, - additionalDataLength: Long, - ): Int + // int crypto_secretstream_xchacha20poly1305_pull + // (crypto_secretstream_xchacha20poly1305_state *state, + // unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p, + // const unsigned char *c, unsigned long long clen, + // const unsigned char *ad, unsigned long long adlen) + fun crypto_secretstream_xchacha20poly1305_pull( + state: SecretStreamXChaCha20Poly1305State, + message: ByteArray, + messageLength: LongArray?, + tagAddress: ByteArray, + ciphertext: ByteArray, + ciphertextLength: Long, + additionalData: ByteArray, + additionalDataLength: Long + ): Int - //keygen and rekey + //keygen and rekey - // void crypto_secretstream_xchacha20poly1305_keygen - // (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]) - fun crypto_secretstream_xchacha20poly1305_keygen(key: ByteArray) + // void crypto_secretstream_xchacha20poly1305_keygen + // (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]) + fun crypto_secretstream_xchacha20poly1305_keygen(key: ByteArray) - // void crypto_secretstream_xchacha20poly1305_rekey - // (crypto_secretstream_xchacha20poly1305_state *state) - fun crypto_secretstream_xchacha20poly1305_rekey(state: SecretStreamXChaCha20Poly1305State) + // void crypto_secretstream_xchacha20poly1305_rekey + // (crypto_secretstream_xchacha20poly1305_state *state) + fun crypto_secretstream_xchacha20poly1305_rekey(state: SecretStreamXChaCha20Poly1305State) - // ---- Secret stream end ----- + // ---- Secret stream end ----- // // // ---- SecretBox ---- - // int crypto_secretbox_detached( - // unsigned char *c, unsigned char *mac, - // const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *n, - // const unsigned char *k) - fun crypto_secretbox_detached( - ciphertext: ByteArray, - mac: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int + // int crypto_secretbox_detached( + // unsigned char *c, unsigned char *mac, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *n, + // const unsigned char *k) + fun crypto_secretbox_detached( + ciphertext: ByteArray, + mac: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + key: ByteArray + ): Int - // int crypto_secretbox_easy( - // unsigned char *c, const unsigned char *m, - // unsigned long long mlen, const unsigned char *n, - // const unsigned char *k) - fun crypto_secretbox_easy( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int + // int crypto_secretbox_easy( + // unsigned char *c, const unsigned char *m, + // unsigned long long mlen, const unsigned char *n, + // const unsigned char *k) + fun crypto_secretbox_easy( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + key: ByteArray + ): Int - // void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES]) - fun crypto_secretbox_keygen(key: ByteArray) + // void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES]) + fun crypto_secretbox_keygen(key: ByteArray) - // int crypto_secretbox_open_detached( - // unsigned char *m, - // const unsigned char *c, - // const unsigned char *mac, - // unsigned long long clen, - // const unsigned char *n, - // const unsigned char *k) - fun crypto_secretbox_open_detached( - message: ByteArray, - ciphertext: ByteArray, - mac: ByteArray, - ciphertextLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int + // int crypto_secretbox_open_detached( + // unsigned char *m, + // const unsigned char *c, + // const unsigned char *mac, + // unsigned long long clen, + // const unsigned char *n, + // const unsigned char *k) + fun crypto_secretbox_open_detached( + message: ByteArray, + ciphertext: ByteArray, + mac: ByteArray, + ciphertextLength: Long, + nonce: ByteArray, + key: ByteArray + ): Int - // int crypto_secretbox_open_easy( - // unsigned char *m, const unsigned char *c, - // unsigned long long clen, const unsigned char *n, - // const unsigned char *k) - fun crypto_secretbox_open_easy( - message: ByteArray, - ciphertext: ByteArray, - ciphertextLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int + // int crypto_secretbox_open_easy( + // unsigned char *m, const unsigned char *c, + // unsigned long long clen, const unsigned char *n, + // const unsigned char *k) + fun crypto_secretbox_open_easy( + message: ByteArray, + ciphertext: ByteArray, + ciphertextLength: Long, + nonce: ByteArray, + key: ByteArray + ): Int - // ---- SecretBox End ---- + // ---- SecretBox End ---- - // ---- Auth ---- + // ---- Auth ---- - // int crypto_auth(unsigned char *out, const unsigned char *in, - // unsigned long long inlen, const unsigned char *k) - fun crypto_auth( - out: ByteArray, - input: ByteArray, - inputLength: Long, - key: ByteArray, - ): Int + // int crypto_auth(unsigned char *out, const unsigned char *in, + // unsigned long long inlen, const unsigned char *k) + fun crypto_auth( + out: ByteArray, + input: ByteArray, + inputLength: Long, + key: ByteArray + ): Int - // void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES]) - fun crypto_auth_keygen(key: ByteArray) + // void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES]) + fun crypto_auth_keygen(key: ByteArray) - // int crypto_auth_verify(const unsigned char *h, const unsigned char *in, - // unsigned long long inlen, const unsigned char *k) - fun crypto_auth_verify( - hash: ByteArray, - input: ByteArray, - inputLength: Long, - key: ByteArray, - ): Int + // int crypto_auth_verify(const unsigned char *h, const unsigned char *in, + // unsigned long long inlen, const unsigned char *k) + fun crypto_auth_verify( + hash: ByteArray, + input: ByteArray, + inputLength: Long, + key: ByteArray + ): Int - //Same params as general variant - fun crypto_auth_hmacsha256( - out: ByteArray, - input: ByteArray, - inputLength: Long, - key: ByteArray, - ): Int + //Same params as general variant + fun crypto_auth_hmacsha256( + out: ByteArray, + input: ByteArray, + inputLength: Long, + key: ByteArray + ): Int - //Same params as general variant - fun crypto_auth_hmacsha256_keygen(key: ByteArray) + //Same params as general variant + fun crypto_auth_hmacsha256_keygen(key: ByteArray) - //Same params as general variant - fun crypto_auth_hmacsha256_verify( - hash: ByteArray, - input: ByteArray, - inputLength: Long, - key: ByteArray, - ): Int + //Same params as general variant + fun crypto_auth_hmacsha256_verify( + hash: ByteArray, + input: ByteArray, + inputLength: Long, + key: ByteArray + ): Int - //Same params as general variant - fun crypto_auth_hmacsha512( - out: ByteArray, - input: ByteArray, - inputLength: Long, - key: ByteArray, - ): Int + //Same params as general variant + fun crypto_auth_hmacsha512( + out: ByteArray, + input: ByteArray, + inputLength: Long, + key: ByteArray + ): Int - //Same params as general variant - fun crypto_auth_hmacsha512_keygen(key: ByteArray) + //Same params as general variant + fun crypto_auth_hmacsha512_keygen(key: ByteArray) - //Same params as general variant - fun crypto_auth_hmacsha512_verify( - hash: ByteArray, - input: ByteArray, - inputLength: Long, - key: ByteArray, - ): Int + //Same params as general variant + fun crypto_auth_hmacsha512_verify( + hash: ByteArray, + input: ByteArray, + inputLength: Long, + key: ByteArray + ): Int - // + // // // ---- Auth end ---- // // // ---- Box ---- // - // int crypto_box_keypair(unsigned char *pk, unsigned char *sk) - fun crypto_box_keypair(publicKey: ByteArray, secretKey: ByteArray): Int + // int crypto_box_keypair(unsigned char *pk, unsigned char *sk) + fun crypto_box_keypair(publicKey: ByteArray, secretKey: ByteArray): Int - // int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk, - // const unsigned char *seed) - fun crypto_box_seed_keypair( - publicKey: ByteArray, - secretKey: ByteArray, - seed: ByteArray, - ): Int + // int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk, + // const unsigned char *seed) + fun crypto_box_seed_keypair( + publicKey: ByteArray, + secretKey: ByteArray, + seed: ByteArray + ): Int - // int crypto_box_easy(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, const unsigned char *n, - // const unsigned char *pk, const unsigned char *sk) - fun crypto_box_easy( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - recipientPublicKey: ByteArray, - senderSecretKey: ByteArray, - ): Int + // int crypto_box_easy(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, const unsigned char *n, + // const unsigned char *pk, const unsigned char *sk) + fun crypto_box_easy( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + recipientPublicKey: ByteArray, + senderSecretKey: ByteArray + ): Int - // int crypto_box_open_easy(unsigned char *m, const unsigned char *c, - // unsigned long long clen, const unsigned char *n, - // const unsigned char *pk, const unsigned char *sk) - fun crypto_box_open_easy( - message: ByteArray, - ciphertext: ByteArray, - ciphertextLength: Long, - nonce: ByteArray, - senderPublickKey: ByteArray, - recipientSecretKey: ByteArray, - ): Int + // int crypto_box_open_easy(unsigned char *m, const unsigned char *c, + // unsigned long long clen, const unsigned char *n, + // const unsigned char *pk, const unsigned char *sk) + fun crypto_box_open_easy( + message: ByteArray, + ciphertext: ByteArray, + ciphertextLength: Long, + nonce: ByteArray, + senderPublickKey: ByteArray, + recipientSecretKey: ByteArray + ): Int - // int crypto_box_detached(unsigned char *c, unsigned char *mac, - // const unsigned char *m, unsigned long long mlen, - // const unsigned char *n, const unsigned char *pk, - // const unsigned char *sk) - fun crypto_box_detached( - ciphertext: ByteArray, - mac: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - recipientPublicKey: ByteArray, - senderSecretKey: ByteArray, - ): Int + // int crypto_box_detached(unsigned char *c, unsigned char *mac, + // const unsigned char *m, unsigned long long mlen, + // const unsigned char *n, const unsigned char *pk, + // const unsigned char *sk) + fun crypto_box_detached( + ciphertext: ByteArray, + mac: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + recipientPublicKey: ByteArray, + senderSecretKey: ByteArray + ): Int - // int crypto_box_open_detached( - // unsigned char *m, const unsigned char *c, - // const unsigned char *mac, - // unsigned long long clen, - // const unsigned char *n, - // const unsigned char *pk, - // const unsigned char *sk) - fun crypto_box_open_detached( - message: ByteArray, - ciphertext: ByteArray, - mac: ByteArray, - ciphertextLength: Long, - nonce: ByteArray, - senderPublickKey: ByteArray, - recipientSecretKey: ByteArray, - ): Int + // int crypto_box_open_detached( + // unsigned char *m, const unsigned char *c, + // const unsigned char *mac, + // unsigned long long clen, + // const unsigned char *n, + // const unsigned char *pk, + // const unsigned char *sk) + fun crypto_box_open_detached( + message: ByteArray, + ciphertext: ByteArray, + mac: ByteArray, + ciphertextLength: Long, + nonce: ByteArray, + senderPublickKey: ByteArray, + recipientSecretKey: ByteArray + ): Int - // int crypto_box_beforenm(unsigned char *k, const unsigned char *pk, - // const unsigned char *sk) - fun crypto_box_beforenm( - sessionKey: ByteArray, - publicKey: ByteArray, - secretKey: ByteArray, - ): Int + // int crypto_box_beforenm(unsigned char *k, const unsigned char *pk, + // const unsigned char *sk) + fun crypto_box_beforenm( + sessionKey: ByteArray, + publicKey: ByteArray, + secretKey: ByteArray + ): Int - // int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, const unsigned char *n, - // const unsigned char *k) - fun crypto_box_easy_afternm( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - sessionKey: ByteArray, - ): Int + // int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, const unsigned char *n, + // const unsigned char *k) + fun crypto_box_easy_afternm( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + sessionKey: ByteArray + ): Int - // int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c, - // unsigned long long clen, const unsigned char *n, - // const unsigned char *k) - fun crypto_box_open_easy_afternm( - message: ByteArray, - ciphertext: ByteArray, - ciphertextLength: Long, - nonce: ByteArray, - sessionKey: ByteArray, - ): Int + // int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c, + // unsigned long long clen, const unsigned char *n, + // const unsigned char *k) + fun crypto_box_open_easy_afternm( + message: ByteArray, + ciphertext: ByteArray, + ciphertextLength: Long, + nonce: ByteArray, + sessionKey: ByteArray + ): Int - // int crypto_box_seal(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, const unsigned char *pk) - fun crypto_box_seal( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - recipientPublicKey: ByteArray, - ): Int + // int crypto_box_seal(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, const unsigned char *pk) + fun crypto_box_seal( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + recipientPublicKey: ByteArray + ): Int - // int crypto_box_seal_open(unsigned char *m, const unsigned char *c, - // unsigned long long clen, - // const unsigned char *pk, const unsigned char *sk) - fun crypto_box_seal_open( - message: ByteArray, - ciphertext: ByteArray, - ciphertextLength: Long, - senderPublickKey: ByteArray, - recipientSecretKey: ByteArray, - ): Int + // int crypto_box_seal_open(unsigned char *m, const unsigned char *c, + // unsigned long long clen, + // const unsigned char *pk, const unsigned char *sk) + fun crypto_box_seal_open( + message: ByteArray, + ciphertext: ByteArray, + ciphertextLength: Long, + senderPublickKey: ByteArray, + recipientSecretKey: ByteArray + ): Int // // // ---- Box end ---- // // // ---- Sign start ---- - // int crypto_sign( - // unsigned char *sm, unsigned long long *smlen_p, - // const unsigned char *m, unsigned long long mlen, - // const unsigned char *sk) - fun crypto_sign( - signedMessage: ByteArray, - signedMessageLength: LongArray?, - message: ByteArray, - messageLength: Long, - secretKey: ByteArray, - ): Int + // int crypto_sign( + // unsigned char *sm, unsigned long long *smlen_p, + // const unsigned char *m, unsigned long long mlen, + // const unsigned char *sk) + fun crypto_sign( + signedMessage: ByteArray, + signedMessageLength: LongArray?, + message: ByteArray, + messageLength: Long, + secretKey: ByteArray + ): Int - // int crypto_sign_open( - // unsigned char *m, unsigned long long *mlen_p, - // const unsigned char *sm, unsigned long long smlen, - // const unsigned char *pk) - fun crypto_sign_open( - message: ByteArray, - messageLength: LongArray?, - signedMessage: ByteArray, - signedMessageLength: Long, - publicKey: ByteArray, - ): Int + // int crypto_sign_open( + // unsigned char *m, unsigned long long *mlen_p, + // const unsigned char *sm, unsigned long long smlen, + // const unsigned char *pk) + fun crypto_sign_open( + message: ByteArray, + messageLength: LongArray?, + signedMessage: ByteArray, + signedMessageLength: Long, + publicKey: ByteArray + ): Int - // int crypto_sign_detached( - // unsigned char *sig, unsigned long long *siglen_p, - // const unsigned char *m, unsigned long long mlen, - // const unsigned char *sk) - fun crypto_sign_detached( - signature: ByteArray, - signatureLength: LongArray?, - message: ByteArray, - messageLength: Long, - secretKey: ByteArray, - ): Int + // int crypto_sign_detached( + // unsigned char *sig, unsigned long long *siglen_p, + // const unsigned char *m, unsigned long long mlen, + // const unsigned char *sk) + fun crypto_sign_detached( + signature: ByteArray, + signatureLength: LongArray?, + message: ByteArray, + messageLength: Long, + secretKey: ByteArray + ): Int - // int crypto_sign_verify_detached( - // const unsigned char *sig, - // const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *pk) - fun crypto_sign_verify_detached( - signature: ByteArray, - message: ByteArray, - messageLength: Long, - publicKey: ByteArray, - ): Int + // int crypto_sign_verify_detached( + // const unsigned char *sig, + // const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *pk) + fun crypto_sign_verify_detached( + signature: ByteArray, + message: ByteArray, + messageLength: Long, + publicKey: ByteArray + ): Int - // int crypto_sign_ed25519_pk_to_curve25519( - // unsigned char *curve25519_pk, - // const unsigned char *ed25519_pk) - fun crypto_sign_ed25519_pk_to_curve25519( - curve25519PublicKey: ByteArray, - ed25519PublicKey: ByteArray, - ): Int + // int crypto_sign_ed25519_pk_to_curve25519( + // unsigned char *curve25519_pk, + // const unsigned char *ed25519_pk) + fun crypto_sign_ed25519_pk_to_curve25519( + curve25519PublicKey: ByteArray, + ed25519PublicKey: ByteArray + ): Int - // int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk, - // const unsigned char *ed25519_sk) - fun crypto_sign_ed25519_sk_to_curve25519( - curve25519SecretKey: ByteArray, - ed25519SecretKey: ByteArray, - ): Int + // int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk, + // const unsigned char *ed25519_sk) + fun crypto_sign_ed25519_sk_to_curve25519( + curve25519SecretKey: ByteArray, + ed25519SecretKey: ByteArray + ): Int - // int crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk) - fun crypto_sign_ed25519_sk_to_pk( - ed25519PublicKey: ByteArray, - ed25519SecretKey: ByteArray, - ): Int + // int crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk) + fun crypto_sign_ed25519_sk_to_pk( + ed25519PublicKey: ByteArray, + ed25519SecretKey: ByteArray + ): Int - // int crypto_sign_ed25519_sk_to_seed(unsigned char *seed, - // const unsigned char *sk) - fun crypto_sign_ed25519_sk_to_seed( - seed: ByteArray, - ed25519SecretKey: ByteArray, - ): Int + // int crypto_sign_ed25519_sk_to_seed(unsigned char *seed, + // const unsigned char *sk) + fun crypto_sign_ed25519_sk_to_seed( + seed: ByteArray, + ed25519SecretKey: ByteArray + ): Int - // int crypto_sign_init(crypto_sign_state *state); - fun crypto_sign_init(state: Ed25519SignatureState) + // int crypto_sign_init(crypto_sign_state *state); + fun crypto_sign_init(state: Ed25519SignatureState) - // int crypto_sign_update(crypto_sign_state *state, - // const unsigned char *m, unsigned long long mlen) - fun crypto_sign_update( - state: Ed25519SignatureState, - message: ByteArray, - messageLength: Long, - ): Int + // int crypto_sign_update(crypto_sign_state *state, + // const unsigned char *m, unsigned long long mlen) + fun crypto_sign_update( + state: Ed25519SignatureState, + message: ByteArray, + messageLength: Long + ): Int - // int crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig, - // unsigned long long *siglen_p, - // const unsigned char *sk) - fun crypto_sign_final_create( - state: Ed25519SignatureState, - signature: ByteArray, - signatureLength: LongArray?, - secretKey: ByteArray, - ): Int + // int crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig, + // unsigned long long *siglen_p, + // const unsigned char *sk) + fun crypto_sign_final_create( + state: Ed25519SignatureState, + signature: ByteArray, + signatureLength: LongArray?, + secretKey: ByteArray + ): Int - // int crypto_sign_final_verify(crypto_sign_state *state, const unsigned char *sig, - // const unsigned char *pk) - fun crypto_sign_final_verify( - state: Ed25519SignatureState, - signature: ByteArray, - publicKey: ByteArray, - ): Int + // int crypto_sign_final_verify(crypto_sign_state *state, const unsigned char *sig, + // const unsigned char *pk) + fun crypto_sign_final_verify( + state: Ed25519SignatureState, + signature: ByteArray, + publicKey: ByteArray + ): Int - // int crypto_sign_keypair(unsigned char *pk, unsigned char *sk) - fun crypto_sign_keypair( - publicKey: ByteArray, secretKey: ByteArray, - ): Int + // int crypto_sign_keypair(unsigned char *pk, unsigned char *sk) + fun crypto_sign_keypair( + publicKey: ByteArray, secretKey: ByteArray + ): Int - // int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk, - // const unsigned char *seed) - fun crypto_sign_seed_keypair( - publicKey: ByteArray, - secretKey: ByteArray, - seed: ByteArray, - ): Int + // int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk, + // const unsigned char *seed) + fun crypto_sign_seed_keypair( + publicKey: ByteArray, + secretKey: ByteArray, + seed: ByteArray + ): Int // // ---- Sign end ---- @@ -1058,280 +1058,274 @@ interface JnaLibsodiumInterface : Library { // // ---- KDF ---- // - // int crypto_kdf_derive_from_key(unsigned char *subkey, size_t subkey_len, - // uint64_t subkey_id, - // const char ctx[crypto_kdf_CONTEXTBYTES], - // const unsigned char key[crypto_kdf_KEYBYTES]) - fun crypto_kdf_derive_from_key( - subkey: ByteArray, - subkeyLength: Int, - subkeyId: Long, - context: ByteArray, - key: ByteArray, - ): Int + // int crypto_kdf_derive_from_key(unsigned char *subkey, size_t subkey_len, + // uint64_t subkey_id, + // const char ctx[crypto_kdf_CONTEXTBYTES], + // const unsigned char key[crypto_kdf_KEYBYTES]) + fun crypto_kdf_derive_from_key( + subkey: ByteArray, + subkeyLength: Int, + subkeyId: Long, + context: ByteArray, + key: ByteArray + ): Int - // void crypto_kdf_keygen(unsigned char k[crypto_kdf_KEYBYTES]) - fun crypto_kdf_keygen( - key: ByteArray, - ) + // void crypto_kdf_keygen(unsigned char k[crypto_kdf_KEYBYTES]) + fun crypto_kdf_keygen( + key: ByteArray + ) // // // ---- KDF end ----- // - // // ---- Password hashing ---- + // // ---- Password hashing ---- // - // int crypto_pwhash(unsigned char * const out, unsigned long long outlen, - // const char * const passwd, unsigned long long passwdlen, - // const unsigned char * const salt, - // unsigned long long opslimit, size_t memlimit, int alg) - fun crypto_pwhash( - output: ByteArray, - outputLength: Long, - password: String, - passwordLength: Long, - salt: ByteArray, - opslimit: Long, - memlimit: Long, - algorithm: Int, - ): Int + // int crypto_pwhash(unsigned char * const out, unsigned long long outlen, + // const char * const passwd, unsigned long long passwdlen, + // const unsigned char * const salt, + // unsigned long long opslimit, size_t memlimit, int alg) + fun crypto_pwhash( + output: ByteArray, + outputLength: Long, + password: String, + passwordLength: Long, + salt: ByteArray, + opslimit: Long, + memlimit: Long, + algorithm : Int + ) : Int - // int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES], - // const char * const passwd, unsigned long long passwdlen, - // unsigned long long opslimit, size_t memlimit) - fun crypto_pwhash_str( - output: ByteArray, - password: String, - passwordLength: Long, - opslimit: Long, - memlimit: Long, - ): Int + // int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES], + // const char * const passwd, unsigned long long passwdlen, + // unsigned long long opslimit, size_t memlimit) + fun crypto_pwhash_str( + output: ByteArray, + password: String, + passwordLength: Long, + opslimit: Long, + memlimit: Long + ) : Int - // int crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES], - // unsigned long long opslimit, size_t memlimit) - fun crypto_pwhash_str_needs_rehash( - output: String, - opslimit: Long, - memlimit: Long, - ): Int - - // int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES], - // const char * const passwd, - // unsigned long long passwdlen) - fun crypto_pwhash_str_verify( - hash: String, - password: String, - passwordLength: Long, - ): Int + // int crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES], + // unsigned long long opslimit, size_t memlimit) + fun crypto_pwhash_str_needs_rehash( + output: String, + opslimit: Long, + memlimit: Long + ) : Int + // int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES], + // const char * const passwd, + // unsigned long long passwdlen) + fun crypto_pwhash_str_verify( + hash: String, + password: String, + passwordLength: Long + ) : Int // // // ---- Password hashing end ---- // + // // ---- Key exchange ---- - // int crypto_kx_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES], - // unsigned char sk[crypto_kx_SECRETKEYBYTES]) - fun crypto_kx_keypair( - publicKey: ByteArray, - secretKey: ByteArray, - ): Int + // int crypto_kx_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES], + // unsigned char sk[crypto_kx_SECRETKEYBYTES]) + fun crypto_kx_keypair( + publicKey: ByteArray, + secretKey: ByteArray + ): Int - // int crypto_kx_seed_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES], - // unsigned char sk[crypto_kx_SECRETKEYBYTES], - // const unsigned char seed[crypto_kx_SEEDBYTES]) - fun crypto_kx_seed_keypair( - publicKey: ByteArray, - secretKey: ByteArray, - seed: ByteArray, - ): Int - - // int crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES], - // unsigned char tx[crypto_kx_SESSIONKEYBYTES], - // const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES], - // const unsigned char client_sk[crypto_kx_SECRETKEYBYTES], - // const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES]) - fun crypto_kx_client_session_keys( - receiveKey: ByteArray, - sendKey: ByteArray, - clientPublicKey: ByteArray, - clientSecretKey: ByteArray, - serverPublicKey: ByteArray, - ): Int - - // int crypto_kx_server_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES], - // unsigned char tx[crypto_kx_SESSIONKEYBYTES], - // const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES], - // const unsigned char server_sk[crypto_kx_SECRETKEYBYTES], - // const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES]) - fun crypto_kx_server_session_keys( - receiveKey: ByteArray, - sendKey: ByteArray, - serverPublicKey: ByteArray, - serverSecretKey: ByteArray, - clientPublicKey: ByteArray, - ): Int + // int crypto_kx_seed_keypair(unsigned char pk[crypto_kx_PUBLICKEYBYTES], + // unsigned char sk[crypto_kx_SECRETKEYBYTES], + // const unsigned char seed[crypto_kx_SEEDBYTES]) + fun crypto_kx_seed_keypair( + publicKey: ByteArray, + secretKey: ByteArray, + seed: ByteArray + ): Int + // int crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES], + // unsigned char tx[crypto_kx_SESSIONKEYBYTES], + // const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES], + // const unsigned char client_sk[crypto_kx_SECRETKEYBYTES], + // const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES]) + fun crypto_kx_client_session_keys( + receiveKey : ByteArray, + sendKey: ByteArray, + clientPublicKey: ByteArray, + clientSecretKey: ByteArray, + serverPublicKey: ByteArray + ): Int + // int crypto_kx_server_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES], + // unsigned char tx[crypto_kx_SESSIONKEYBYTES], + // const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES], + // const unsigned char server_sk[crypto_kx_SECRETKEYBYTES], + // const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES]) + fun crypto_kx_server_session_keys( + receiveKey: ByteArray, + sendKey: ByteArray, + serverPublicKey: ByteArray, + serverSecretKey: ByteArray, + clientPublicKey: ByteArray + ): Int // // // ---- Key exchange end ---- // // // -- Stream ---- - // int crypto_stream_chacha20(unsigned char *c, unsigned long long clen, - // const unsigned char *n, const unsigned char *k) - fun crypto_stream_chacha20( - stream: ByteArray, - streamLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int + // int crypto_stream_chacha20(unsigned char *c, unsigned long long clen, + // const unsigned char *n, const unsigned char *k) + fun crypto_stream_chacha20( + stream: ByteArray, + streamLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int + // int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, const unsigned char *n, + // const unsigned char *k) + fun crypto_stream_chacha20_xor( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int + // int crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *n, uint64_t ic, + // const unsigned char *k) + fun crypto_stream_chacha20_xor_ic( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + initialCounter : Long, + key: ByteArray + ) : Int - // int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, const unsigned char *n, - // const unsigned char *k) - fun crypto_stream_chacha20_xor( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int + // int crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen, + // const unsigned char *n, const unsigned char *k) + fun crypto_stream_chacha20_ietf( + stream: ByteArray, + streamLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int - // int crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *n, uint64_t ic, - // const unsigned char *k) - fun crypto_stream_chacha20_xor_ic( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - initialCounter: Long, - key: ByteArray, - ): Int + // int crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, const unsigned char *n, + // const unsigned char *k) + fun crypto_stream_chacha20_ietf_xor( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int - // int crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen, - // const unsigned char *n, const unsigned char *k) - fun crypto_stream_chacha20_ietf( - stream: ByteArray, - streamLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int + // int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *n, uint32_t ic, + // const unsigned char *k) + fun crypto_stream_chacha20_ietf_xor_ic( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + initialCounter : Int, + key: ByteArray + ) : Int - // int crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, const unsigned char *n, - // const unsigned char *k) - fun crypto_stream_chacha20_ietf_xor( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int + // void crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES]) + fun crypto_stream_chacha20_keygen(key: ByteArray) - // int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *n, uint32_t ic, - // const unsigned char *k) - fun crypto_stream_chacha20_ietf_xor_ic( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - initialCounter: Int, - key: ByteArray, - ): Int + // int crypto_stream_xchacha20(unsigned char *c, unsigned long long clen, + // const unsigned char *n, const unsigned char *k) + fun crypto_stream_xchacha20( + stream: ByteArray, + streamLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int - // void crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES]) - fun crypto_stream_chacha20_keygen(key: ByteArray) + // int crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, const unsigned char *n, + // const unsigned char *k) + fun crypto_stream_xchacha20_xor( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + key: ByteArray + ) : Int - // int crypto_stream_xchacha20(unsigned char *c, unsigned long long clen, - // const unsigned char *n, const unsigned char *k) - fun crypto_stream_xchacha20( - stream: ByteArray, - streamLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int - - // int crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, const unsigned char *n, - // const unsigned char *k) - fun crypto_stream_xchacha20_xor( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - key: ByteArray, - ): Int - - // int crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m, - // unsigned long long mlen, - // const unsigned char *n, uint64_t ic, - // const unsigned char *k) - fun crypto_stream_xchacha20_xor_ic( - ciphertext: ByteArray, - message: ByteArray, - messageLength: Long, - nonce: ByteArray, - initialCounter: Long, - key: ByteArray, - ): Int - - // void crypto_stream_xchacha20_keygen(unsigned char k[crypto_stream_xchacha20_KEYBYTES]) - fun crypto_stream_xchacha20_keygen(key: ByteArray) + // int crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m, + // unsigned long long mlen, + // const unsigned char *n, uint64_t ic, + // const unsigned char *k) + fun crypto_stream_xchacha20_xor_ic( + ciphertext: ByteArray, + message: ByteArray, + messageLength: Long, + nonce: ByteArray, + initialCounter : Long, + key: ByteArray + ) : Int + // void crypto_stream_xchacha20_keygen(unsigned char k[crypto_stream_xchacha20_KEYBYTES]) + fun crypto_stream_xchacha20_keygen(key: ByteArray) - // +// // // ---- Stream end ---- // // // ---- Scalar multiplication ---- // - // int crypto_scalarmult(unsigned char *q, const unsigned char *n, - // const unsigned char *p) - fun crypto_scalarmult(q: ByteArray, n: ByteArray, p: ByteArray): Int - - // int crypto_scalarmult_base(unsigned char *q, const unsigned char *n) - fun crypto_scalarmult_base(q: ByteArray, b: ByteArray): Int + // int crypto_scalarmult(unsigned char *q, const unsigned char *n, + // const unsigned char *p) + fun crypto_scalarmult(q: ByteArray, n: ByteArray, p: ByteArray): Int + // int crypto_scalarmult_base(unsigned char *q, const unsigned char *n) + fun crypto_scalarmult_base(q: ByteArray, b: ByteArray): Int // // // ---- Scalar multiplication end ---- // // // ---- Ristretto255 ---- - fun crypto_core_ristretto255_is_valid_point(p: ByteArray): Int + fun crypto_core_ristretto255_is_valid_point(p: ByteArray): Int - fun crypto_core_ristretto255_random(p: ByteArray) + fun crypto_core_ristretto255_random(p: ByteArray) - fun crypto_core_ristretto255_from_hash(p: ByteArray, r: ByteArray): Int + fun crypto_core_ristretto255_from_hash(p: ByteArray, r: ByteArray): Int - fun crypto_core_ristretto255_add(r: ByteArray, p: ByteArray, q: ByteArray): Int + fun crypto_core_ristretto255_add(r: ByteArray, p: ByteArray, q: ByteArray): Int - fun crypto_core_ristretto255_sub(r: ByteArray, p: ByteArray, q: ByteArray): Int + fun crypto_core_ristretto255_sub(r: ByteArray, p: ByteArray, q: ByteArray): Int - fun crypto_core_ristretto255_scalar_random(r: ByteArray) + fun crypto_core_ristretto255_scalar_random(r: ByteArray) - fun crypto_core_ristretto255_scalar_reduce(r: ByteArray, s: ByteArray) + fun crypto_core_ristretto255_scalar_reduce(r: ByteArray, s: ByteArray) - fun crypto_core_ristretto255_scalar_invert(recip: ByteArray, s: ByteArray): Int + fun crypto_core_ristretto255_scalar_invert(recip: ByteArray, s: ByteArray): Int - fun crypto_core_ristretto255_scalar_negate(neg: ByteArray, s: ByteArray) + fun crypto_core_ristretto255_scalar_negate(neg: ByteArray, s: ByteArray) - fun crypto_core_ristretto255_scalar_complement(comp: ByteArray, s: ByteArray) + fun crypto_core_ristretto255_scalar_complement(comp: ByteArray, s: ByteArray) - fun crypto_core_ristretto255_scalar_add(z: ByteArray, x: ByteArray, y: ByteArray) + fun crypto_core_ristretto255_scalar_add(z: ByteArray, x: ByteArray, y: ByteArray) - fun crypto_core_ristretto255_scalar_sub(z: ByteArray, x: ByteArray, y: ByteArray) + fun crypto_core_ristretto255_scalar_sub(z: ByteArray, x: ByteArray, y: ByteArray) - fun crypto_core_ristretto255_scalar_mul(z: ByteArray, x: ByteArray, y: ByteArray) + fun crypto_core_ristretto255_scalar_mul(z: ByteArray, x: ByteArray, y: ByteArray) - fun crypto_scalarmult_ristretto255(q: ByteArray, n: ByteArray, p: ByteArray): Int + fun crypto_scalarmult_ristretto255(q: ByteArray, n: ByteArray, p: ByteArray): Int - fun crypto_scalarmult_ristretto255_base(q: ByteArray, n: ByteArray): Int + fun crypto_scalarmult_ristretto255_base(q: ByteArray, n: ByteArray): Int // // // ---- Ristretto255 end ---- @@ -1339,39 +1333,39 @@ interface JnaLibsodiumInterface : Library { // // // ---- Ed25519 ---- - fun crypto_core_ed25519_is_valid_point(p: ByteArray): Int + fun crypto_core_ed25519_is_valid_point(p: ByteArray): Int - fun crypto_core_ed25519_random(p: ByteArray) + fun crypto_core_ed25519_random(p: ByteArray) - fun crypto_core_ed25519_from_uniform(p: ByteArray, r: ByteArray): Int + fun crypto_core_ed25519_from_uniform(p: ByteArray, r: ByteArray): Int - fun crypto_core_ed25519_add(r: ByteArray, p: ByteArray, q: ByteArray): Int + fun crypto_core_ed25519_add(r: ByteArray, p: ByteArray, q: ByteArray): Int - fun crypto_core_ed25519_sub(r: ByteArray, p: ByteArray, q: ByteArray): Int + fun crypto_core_ed25519_sub(r: ByteArray, p: ByteArray, q: ByteArray): Int - fun crypto_core_ed25519_scalar_random(r: ByteArray) + fun crypto_core_ed25519_scalar_random(r: ByteArray) - fun crypto_core_ed25519_scalar_reduce(r: ByteArray, s: ByteArray) + fun crypto_core_ed25519_scalar_reduce(r: ByteArray, s: ByteArray) - fun crypto_core_ed25519_scalar_invert(recip: ByteArray, s: ByteArray): Int + fun crypto_core_ed25519_scalar_invert(recip: ByteArray, s: ByteArray): Int - fun crypto_core_ed25519_scalar_negate(neg: ByteArray, s: ByteArray) + fun crypto_core_ed25519_scalar_negate(neg: ByteArray, s: ByteArray) - fun crypto_core_ed25519_scalar_complement(comp: ByteArray, s: ByteArray) + fun crypto_core_ed25519_scalar_complement(comp: ByteArray, s: ByteArray) - fun crypto_core_ed25519_scalar_add(z: ByteArray, x: ByteArray, y: ByteArray) + fun crypto_core_ed25519_scalar_add(z: ByteArray, x: ByteArray, y: ByteArray) - fun crypto_core_ed25519_scalar_sub(z: ByteArray, x: ByteArray, y: ByteArray) + fun crypto_core_ed25519_scalar_sub(z: ByteArray, x: ByteArray, y: ByteArray) - fun crypto_core_ed25519_scalar_mul(z: ByteArray, x: ByteArray, y: ByteArray) + fun crypto_core_ed25519_scalar_mul(z: ByteArray, x: ByteArray, y: ByteArray) - fun crypto_scalarmult_ed25519(q: ByteArray, n: ByteArray, p: ByteArray): Int + fun crypto_scalarmult_ed25519(q: ByteArray, n: ByteArray, p: ByteArray): Int - fun crypto_scalarmult_ed25519_noclamp(q: ByteArray, n: ByteArray, p: ByteArray): Int + fun crypto_scalarmult_ed25519_noclamp(q: ByteArray, n: ByteArray, p: ByteArray): Int - fun crypto_scalarmult_ed25519_base(q: ByteArray, n: ByteArray): Int + fun crypto_scalarmult_ed25519_base(q: ByteArray, n: ByteArray): Int - fun crypto_scalarmult_ed25519_base_noclamp(q: ByteArray, n: ByteArray): Int + fun crypto_scalarmult_ed25519_base_noclamp(q: ByteArray, n: ByteArray): Int // // // ---- Ed25519 end ---- 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 5268c3d..688992a 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 @@ -4,133 +4,133 @@ import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibso import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna actual abstract class Ed25519LowLevel actual constructor() { - actual fun isValidPoint(encoded: UByteArray): Boolean = - sodiumJna.crypto_core_ed25519_is_valid_point(encoded.asByteArray()) == 1 + actual fun isValidPoint(encoded: UByteArray): Boolean = + sodiumJna.crypto_core_ed25519_is_valid_point(encoded.asByteArray()) == 1 - actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - sodiumJna.crypto_core_ed25519_add(result.asByteArray(), p.asByteArray(), q.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_core_ed25519_add(result.asByteArray(), p.asByteArray(), q.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - sodiumJna.crypto_core_ed25519_sub(result.asByteArray(), p.asByteArray(), q.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_core_ed25519_sub(result.asByteArray(), p.asByteArray(), q.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - sodiumJna.crypto_core_ed25519_from_uniform(result.asByteArray(), uniform.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_core_ed25519_from_uniform(result.asByteArray(), uniform.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ed25519_BYTES).also { - sodiumJna.crypto_core_ed25519_random(it.asByteArray()) - } + actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ed25519_BYTES).also { + sodiumJna.crypto_core_ed25519_random(it.asByteArray()) + } - actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ed25519_SCALARBYTES).also { - sodiumJna.crypto_core_ed25519_scalar_random(it.asByteArray()) - } + actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ed25519_SCALARBYTES).also { + sodiumJna.crypto_core_ed25519_scalar_random(it.asByteArray()) + } - actual fun invertScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + actual fun invertScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - sodiumJna.crypto_core_ed25519_scalar_invert(result.asByteArray(), scalar.asByteArray()).ensureLibsodiumSuccess() + sodiumJna.crypto_core_ed25519_scalar_invert(result.asByteArray(), scalar.asByteArray()).ensureLibsodiumSuccess() - return result - } + return result + } - actual fun negateScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + actual fun negateScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - sodiumJna.crypto_core_ed25519_scalar_negate(result.asByteArray(), scalar.asByteArray()) + sodiumJna.crypto_core_ed25519_scalar_negate(result.asByteArray(), scalar.asByteArray()) - return result - } + return result + } - actual fun complementScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + actual fun complementScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - sodiumJna.crypto_core_ed25519_scalar_complement(result.asByteArray(), scalar.asByteArray()) + sodiumJna.crypto_core_ed25519_scalar_complement(result.asByteArray(), scalar.asByteArray()) - return result - } + return result + } - actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - sodiumJna.crypto_core_ed25519_scalar_add(result.asByteArray(), x.asByteArray(), y.asByteArray()) + sodiumJna.crypto_core_ed25519_scalar_add(result.asByteArray(), x.asByteArray(), y.asByteArray()) - return result - } + return result + } - actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - sodiumJna.crypto_core_ed25519_scalar_sub(result.asByteArray(), x.asByteArray(), y.asByteArray()) + sodiumJna.crypto_core_ed25519_scalar_sub(result.asByteArray(), x.asByteArray(), y.asByteArray()) - return result - } + return result + } - actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - sodiumJna.crypto_core_ed25519_scalar_mul(result.asByteArray(), x.asByteArray(), y.asByteArray()) + sodiumJna.crypto_core_ed25519_scalar_mul(result.asByteArray(), x.asByteArray(), y.asByteArray()) - return result - } + return result + } - actual fun reduceScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + actual fun reduceScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - sodiumJna.crypto_core_ed25519_scalar_reduce(result.asByteArray(), scalar.asByteArray()) + sodiumJna.crypto_core_ed25519_scalar_reduce(result.asByteArray(), scalar.asByteArray()) - return result - } + return result + } - actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - sodiumJna.crypto_scalarmult_ed25519(result.asByteArray(), n.asByteArray(), p.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_scalarmult_ed25519(result.asByteArray(), n.asByteArray(), p.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - sodiumJna.crypto_scalarmult_ed25519_noclamp(result.asByteArray(), n.asByteArray(), p.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_scalarmult_ed25519_noclamp(result.asByteArray(), n.asByteArray(), p.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - sodiumJna.crypto_scalarmult_ed25519_base(result.asByteArray(), n.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_scalarmult_ed25519_base(result.asByteArray(), n.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - sodiumJna.crypto_scalarmult_ed25519_base_noclamp(result.asByteArray(), n.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_scalarmult_ed25519_base_noclamp(result.asByteArray(), n.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } } \ No newline at end of file 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 6fa3081..cf48b2d 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 @@ -4,114 +4,115 @@ import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibso import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna actual abstract class Ristretto255LowLevel actual constructor() { - actual fun isValidPoint(encoded: UByteArray): Boolean = - sodiumJna.crypto_core_ristretto255_is_valid_point(encoded.asByteArray()) == 1 + actual fun isValidPoint(encoded: UByteArray): Boolean = + sodiumJna.crypto_core_ristretto255_is_valid_point(encoded.asByteArray()) == 1 - actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) + actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) - sodiumJna.crypto_core_ristretto255_add(result.asByteArray(), p.asByteArray(), q.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_core_ristretto255_add(result.asByteArray(), p.asByteArray(), q.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) + actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) - sodiumJna.crypto_core_ristretto255_sub(result.asByteArray(), p.asByteArray(), q.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_core_ristretto255_sub(result.asByteArray(), p.asByteArray(), q.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun encodedPointFromHash(hash: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) + actual fun encodedPointFromHash(hash: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) - sodiumJna.crypto_core_ristretto255_from_hash(result.asByteArray(), hash.asByteArray()) + sodiumJna.crypto_core_ristretto255_from_hash(result.asByteArray(), hash.asByteArray()) - return result - } + return result + } - actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).also { - sodiumJna.crypto_core_ristretto255_random(it.asByteArray()) - } + actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).also { + sodiumJna.crypto_core_ristretto255_random(it.asByteArray()) + } - actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ristretto255_SCALARBYTES).also { - sodiumJna.crypto_core_ristretto255_scalar_random(it.asByteArray()) - } + actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ristretto255_SCALARBYTES).also { + sodiumJna.crypto_core_ristretto255_scalar_random(it.asByteArray()) + } - actual fun invertScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + actual fun invertScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - sodiumJna.crypto_core_ristretto255_scalar_invert(result.asByteArray(), scalar.asByteArray()).ensureLibsodiumSuccess() + sodiumJna.crypto_core_ristretto255_scalar_invert(result.asByteArray(), scalar.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun negateScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + actual fun negateScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - sodiumJna.crypto_core_ristretto255_scalar_negate(result.asByteArray(), scalar.asByteArray()) + sodiumJna.crypto_core_ristretto255_scalar_negate(result.asByteArray(), scalar.asByteArray()) - return result - } + return result + } - actual fun complementScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + actual fun complementScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - sodiumJna.crypto_core_ristretto255_scalar_complement(result.asByteArray(), scalar.asByteArray()) + sodiumJna.crypto_core_ristretto255_scalar_complement(result.asByteArray(), scalar.asByteArray()) - return result - } + return result + } - actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - sodiumJna.crypto_core_ristretto255_scalar_add(result.asByteArray(), x.asByteArray(), y.asByteArray()) + sodiumJna.crypto_core_ristretto255_scalar_add(result.asByteArray(), x.asByteArray(), y.asByteArray()) - return result - } + return result + } - actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - sodiumJna.crypto_core_ristretto255_scalar_sub(result.asByteArray(), x.asByteArray(), y.asByteArray()) + sodiumJna.crypto_core_ristretto255_scalar_sub(result.asByteArray(), x.asByteArray(), y.asByteArray()) - return result - } + return result + } - actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - sodiumJna.crypto_core_ristretto255_scalar_mul(result.asByteArray(), x.asByteArray(), y.asByteArray()) + sodiumJna.crypto_core_ristretto255_scalar_mul(result.asByteArray(), x.asByteArray(), y.asByteArray()) - return result - } + return result + } - actual fun reduceScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + actual fun reduceScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - sodiumJna.crypto_core_ristretto255_scalar_reduce(result.asByteArray(), scalar.asByteArray()) + sodiumJna.crypto_core_ristretto255_scalar_reduce(result.asByteArray(), scalar.asByteArray()) - return result - } + return result + } - actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) + actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) - sodiumJna.crypto_scalarmult_ristretto255(result.asByteArray(), n.asByteArray(), p.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_scalarmult_ristretto255(result.asByteArray(), n.asByteArray(), p.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } - actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) + actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) - sodiumJna.crypto_scalarmult_ristretto255_base(result.asByteArray(), n.asByteArray()) - .ensureLibsodiumSuccess() + sodiumJna.crypto_scalarmult_ristretto255_base(result.asByteArray(), n.asByteArray()) + .ensureLibsodiumSuccess() - return result - } + return result + } } \ No newline at end of file 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 49829ad..af645e5 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 @@ -23,208 +23,208 @@ import libsodium.crypto_scalarmult_ed25519_noclamp actual abstract class Ed25519LowLevel actual constructor() { - actual fun isValidPoint(encoded: UByteArray): Boolean { - return encoded.usePinned { crypto_core_ed25519_is_valid_point(it.toPtr()) == 1 } - } + actual fun isValidPoint(encoded: UByteArray): Boolean { + return encoded.usePinned { crypto_core_ed25519_is_valid_point(it.toPtr()) == 1 } + } - actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - result.usePinned { resultPinned -> - p.usePinned { pPinned -> - q.usePinned { qPinned -> - crypto_core_ed25519_add(resultPinned.toPtr(), pPinned.toPtr(), qPinned.toPtr()) - .ensureLibsodiumSuccess() + result.usePinned { resultPinned -> + p.usePinned { pPinned -> + q.usePinned { qPinned -> + crypto_core_ed25519_add(resultPinned.toPtr(), pPinned.toPtr(), qPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } } - } + + return result } - return result - } + actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) - - result.usePinned { resultPinned -> - p.usePinned { pPinned -> - q.usePinned { qPinned -> - crypto_core_ed25519_sub(resultPinned.toPtr(), pPinned.toPtr(), qPinned.toPtr()) - .ensureLibsodiumSuccess() + result.usePinned { resultPinned -> + p.usePinned { pPinned -> + q.usePinned { qPinned -> + crypto_core_ed25519_sub(resultPinned.toPtr(), pPinned.toPtr(), qPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } } - } + + return result } - return result - } + actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) - actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) - - result.usePinned { resultPinned -> - uniform.usePinned { uniformPinned -> - crypto_core_ed25519_from_uniform(resultPinned.toPtr(), uniformPinned.toPtr()) - .ensureLibsodiumSuccess() - } - } - - return result - } - - actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ed25519_BYTES).apply { - usePinned { crypto_core_ed25519_random(it.toPtr()) } - } - - actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ed25519_SCALARBYTES).apply { - usePinned { crypto_core_ed25519_scalar_random(it.toPtr()) } - } - - actual fun invertScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - - result.usePinned { resultPinned -> - scalar.usePinned { scalarPinned -> - crypto_core_ed25519_scalar_invert(resultPinned.toPtr(), scalarPinned.toPtr()).ensureLibsodiumSuccess() - } - } - - - return result - } - - actual fun negateScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - - result.usePinned { resultPinned -> - scalar.usePinned { scalarPinned -> - crypto_core_ed25519_scalar_negate(resultPinned.toPtr(), scalarPinned.toPtr()) - } - } - - - return result - } - - actual fun complementScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - - result.usePinned { resultPinned -> - scalar.usePinned { scalarPinned -> - crypto_core_ed25519_scalar_complement(resultPinned.toPtr(), scalarPinned.toPtr()) - } - } - - return result - } - - actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - - result.usePinned { resultPinned -> - x.usePinned { xPinned -> - y.usePinned { yPinned -> - crypto_core_ed25519_scalar_add(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + result.usePinned { resultPinned -> + uniform.usePinned { uniformPinned -> + crypto_core_ed25519_from_uniform(resultPinned.toPtr(), uniformPinned.toPtr()) + .ensureLibsodiumSuccess() + } } - } + + return result } - return result - } + actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ed25519_BYTES).apply { + usePinned { crypto_core_ed25519_random(it.toPtr()) } + } - actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ed25519_SCALARBYTES).apply { + usePinned { crypto_core_ed25519_scalar_random(it.toPtr()) } + } - result.usePinned { resultPinned -> - x.usePinned { xPinned -> - y.usePinned { yPinned -> - crypto_core_ed25519_scalar_sub(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + actual fun invertScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + + result.usePinned { resultPinned -> + scalar.usePinned { scalarPinned -> + crypto_core_ed25519_scalar_invert(resultPinned.toPtr(), scalarPinned.toPtr()).ensureLibsodiumSuccess() + } } - } + + + return result } - return result - } + actual fun negateScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - - result.usePinned { resultPinned -> - x.usePinned { xPinned -> - y.usePinned { yPinned -> - crypto_core_ed25519_scalar_mul(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + result.usePinned { resultPinned -> + scalar.usePinned { scalarPinned -> + crypto_core_ed25519_scalar_negate(resultPinned.toPtr(), scalarPinned.toPtr()) + } } - } + + + return result } - return result - } + actual fun complementScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - actual fun reduceScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - - result.usePinned { resultPinned -> - scalar.usePinned { scalarPinned -> - crypto_core_ed25519_scalar_reduce(resultPinned.toPtr(), scalarPinned.toPtr()) - } - } - - return result - } - - actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) - - result.usePinned { resultPinned -> - n.usePinned { nPinned -> - p.usePinned { pPinned -> - crypto_scalarmult_ed25519(resultPinned.toPtr(), nPinned.toPtr(), pPinned.toPtr()) - .ensureLibsodiumSuccess() + result.usePinned { resultPinned -> + scalar.usePinned { scalarPinned -> + crypto_core_ed25519_scalar_complement(resultPinned.toPtr(), scalarPinned.toPtr()) + } } - } + + return result } + actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - return result - } - - actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) - - result.usePinned { resultPinned -> - n.usePinned { nPinned -> - p.usePinned { pPinned -> - crypto_scalarmult_ed25519_noclamp(resultPinned.toPtr(), nPinned.toPtr(), pPinned.toPtr()) - .ensureLibsodiumSuccess() + result.usePinned { resultPinned -> + x.usePinned { xPinned -> + y.usePinned { yPinned -> + crypto_core_ed25519_scalar_add(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + } + } } - } + + return result } + actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - return result - } + result.usePinned { resultPinned -> + x.usePinned { xPinned -> + y.usePinned { yPinned -> + crypto_core_ed25519_scalar_sub(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + } + } + } - actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) - - result.usePinned { resultPinned -> - n.usePinned { nPinned -> - crypto_scalarmult_ed25519_base(resultPinned.toPtr(), nPinned.toPtr()) - .ensureLibsodiumSuccess() - } + return result } - return result - } + actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) - actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ed25519_BYTES) + result.usePinned { resultPinned -> + x.usePinned { xPinned -> + y.usePinned { yPinned -> + crypto_core_ed25519_scalar_mul(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + } + } + } - result.usePinned { resultPinned -> - n.usePinned { nPinned -> - crypto_scalarmult_ed25519_base_noclamp(resultPinned.toPtr(), nPinned.toPtr()) - .ensureLibsodiumSuccess() - } + return result } - return result - } + actual fun reduceScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_SCALARBYTES) + + result.usePinned { resultPinned -> + scalar.usePinned { scalarPinned -> + crypto_core_ed25519_scalar_reduce(resultPinned.toPtr(), scalarPinned.toPtr()) + } + } + + return result + } + + actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) + + result.usePinned { resultPinned -> + n.usePinned { nPinned -> + p.usePinned { pPinned -> + crypto_scalarmult_ed25519(resultPinned.toPtr(), nPinned.toPtr(), pPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } + } + + + return result + } + + actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) + + result.usePinned { resultPinned -> + n.usePinned { nPinned -> + p.usePinned { pPinned -> + crypto_scalarmult_ed25519_noclamp(resultPinned.toPtr(), nPinned.toPtr(), pPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } + } + + + return result + } + + actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) + + result.usePinned { resultPinned -> + n.usePinned { nPinned -> + crypto_scalarmult_ed25519_base(resultPinned.toPtr(), nPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } + + return result + } + + actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ed25519_BYTES) + + result.usePinned { resultPinned -> + n.usePinned { nPinned -> + crypto_scalarmult_ed25519_base_noclamp(resultPinned.toPtr(), nPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } + + return result + } } \ No newline at end of file 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 5bb6bd1..2e191c6 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 @@ -21,178 +21,181 @@ import libsodium.crypto_scalarmult_ristretto255_base actual abstract class Ristretto255LowLevel actual constructor() { - actual fun isValidPoint(encoded: UByteArray): Boolean { - return encoded.usePinned { crypto_core_ristretto255_is_valid_point(it.toPtr()) == 1 } - } + actual fun isValidPoint(encoded: UByteArray): Boolean { + return encoded.usePinned { crypto_core_ristretto255_is_valid_point(it.toPtr()) == 1 } + } - actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) + actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) - result.usePinned { resultPinned -> - p.usePinned { pPinned -> - q.usePinned { qPinned -> - crypto_core_ristretto255_add(resultPinned.toPtr(), pPinned.toPtr(), qPinned.toPtr()) - .ensureLibsodiumSuccess() + result.usePinned { resultPinned -> + p.usePinned { pPinned -> + q.usePinned { qPinned -> + crypto_core_ristretto255_add(resultPinned.toPtr(), pPinned.toPtr(), qPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } } - } + + return result } - return result - } + actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) - actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) - - result.usePinned { resultPinned -> - p.usePinned { pPinned -> - q.usePinned { qPinned -> - crypto_core_ristretto255_sub(resultPinned.toPtr(), pPinned.toPtr(), qPinned.toPtr()) - .ensureLibsodiumSuccess() + result.usePinned { resultPinned -> + p.usePinned { pPinned -> + q.usePinned { qPinned -> + crypto_core_ristretto255_sub(resultPinned.toPtr(), pPinned.toPtr(), qPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } } - } + + return result } - return result - } + actual fun encodedPointFromHash(hash: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) - actual fun encodedPointFromHash(hash: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) - - result.usePinned { resultPinned -> - hash.usePinned { hashPinned -> - crypto_core_ristretto255_from_hash(resultPinned.toPtr(), hashPinned.toPtr()) - } - } - - return result - } - - actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).apply { - usePinned { crypto_core_ristretto255_random(it.toPtr()) } - } - - actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ristretto255_SCALARBYTES).apply { - usePinned { crypto_core_ristretto255_scalar_random(it.toPtr()) } - } - - actual fun invertScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - - result.usePinned { resultPinned -> - scalar.usePinned { scalarPinned -> - crypto_core_ristretto255_scalar_invert(resultPinned.toPtr(), scalarPinned.toPtr()).ensureLibsodiumSuccess() - } - } - - - return result - } - - actual fun negateScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - - result.usePinned { resultPinned -> - scalar.usePinned { scalarPinned -> - crypto_core_ristretto255_scalar_negate(resultPinned.toPtr(), scalarPinned.toPtr()) - } - } - - - return result - } - - actual fun complementScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - - result.usePinned { resultPinned -> - scalar.usePinned { scalarPinned -> - crypto_core_ristretto255_scalar_complement(resultPinned.toPtr(), scalarPinned.toPtr()) - } - } - - return result - } - - actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - - result.usePinned { resultPinned -> - x.usePinned { xPinned -> - y.usePinned { yPinned -> - crypto_core_ristretto255_scalar_add(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + result.usePinned { resultPinned -> + hash.usePinned { hashPinned -> + crypto_core_ristretto255_from_hash(resultPinned.toPtr(), hashPinned.toPtr()) + } } - } + + return result } - return result - } + actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).apply { + usePinned { crypto_core_ristretto255_random(it.toPtr()) } + } - actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + actual fun randomEncodedScalar(): UByteArray = UByteArray(crypto_core_ristretto255_SCALARBYTES).apply { + usePinned { crypto_core_ristretto255_scalar_random(it.toPtr()) } + } - result.usePinned { resultPinned -> - x.usePinned { xPinned -> - y.usePinned { yPinned -> - crypto_core_ristretto255_scalar_sub(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + actual fun invertScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + + result.usePinned { resultPinned -> + scalar.usePinned { scalarPinned -> + crypto_core_ristretto255_scalar_invert( + resultPinned.toPtr(), + scalarPinned.toPtr() + ).ensureLibsodiumSuccess() + } } - } + + + return result } - return result - } + actual fun negateScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - - result.usePinned { resultPinned -> - x.usePinned { xPinned -> - y.usePinned { yPinned -> - crypto_core_ristretto255_scalar_mul(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + result.usePinned { resultPinned -> + scalar.usePinned { scalarPinned -> + crypto_core_ristretto255_scalar_negate(resultPinned.toPtr(), scalarPinned.toPtr()) + } } - } + + + return result } - return result - } + actual fun complementScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - actual fun reduceScalar(scalar: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - - result.usePinned { resultPinned -> - scalar.usePinned { scalarPinned -> - crypto_core_ristretto255_scalar_reduce(resultPinned.toPtr(), scalarPinned.toPtr()) - } - } - - return result - } - - actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) - - result.usePinned { resultPinned -> - n.usePinned { nPinned -> - p.usePinned { pPinned -> - crypto_scalarmult_ristretto255(resultPinned.toPtr(), nPinned.toPtr(), pPinned.toPtr()) - .ensureLibsodiumSuccess() + result.usePinned { resultPinned -> + scalar.usePinned { scalarPinned -> + crypto_core_ristretto255_scalar_complement(resultPinned.toPtr(), scalarPinned.toPtr()) + } } - } + + return result } + actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) - return result - } + result.usePinned { resultPinned -> + x.usePinned { xPinned -> + y.usePinned { yPinned -> + crypto_core_ristretto255_scalar_add(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + } + } + } - actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { - val result = UByteArray(crypto_core_ristretto255_BYTES) - - result.usePinned { resultPinned -> - n.usePinned { nPinned -> - crypto_scalarmult_ristretto255_base(resultPinned.toPtr(), nPinned.toPtr()) - .ensureLibsodiumSuccess() - } + return result } - return result - } + actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + + result.usePinned { resultPinned -> + x.usePinned { xPinned -> + y.usePinned { yPinned -> + crypto_core_ristretto255_scalar_sub(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + } + } + } + + return result + } + + actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + + result.usePinned { resultPinned -> + x.usePinned { xPinned -> + y.usePinned { yPinned -> + crypto_core_ristretto255_scalar_mul(resultPinned.toPtr(), xPinned.toPtr(), yPinned.toPtr()) + } + } + } + + return result + } + + actual fun reduceScalar(scalar: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_SCALARBYTES) + + result.usePinned { resultPinned -> + scalar.usePinned { scalarPinned -> + crypto_core_ristretto255_scalar_reduce(resultPinned.toPtr(), scalarPinned.toPtr()) + } + } + + return result + } + + actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) + + result.usePinned { resultPinned -> + n.usePinned { nPinned -> + p.usePinned { pPinned -> + crypto_scalarmult_ristretto255(resultPinned.toPtr(), nPinned.toPtr(), pPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } + } + + + return result + } + + actual fun scalarMultiplicationBase(n: UByteArray): UByteArray { + val result = UByteArray(crypto_core_ristretto255_BYTES) + + result.usePinned { resultPinned -> + n.usePinned { nPinned -> + crypto_scalarmult_ristretto255_base(resultPinned.toPtr(), nPinned.toPtr()) + .ensureLibsodiumSuccess() + } + } + + return result + } } \ No newline at end of file