WIP: Fix build/test issues
This commit is contained in:
parent
338c1f0012
commit
9a4a776bbd
@ -17,11 +17,17 @@ const val crypto_core_ed25519_NONREDUCEDSCALARBYTES = 64
|
|||||||
const val crypto_scalarmult_ed25519_BYTES = 32U
|
const val crypto_scalarmult_ed25519_BYTES = 32U
|
||||||
const val crypto_scalarmult_ed25519_SCALARBYTES = 32U
|
const val crypto_scalarmult_ed25519_SCALARBYTES = 32U
|
||||||
|
|
||||||
|
enum class HashToCurveAlgorithm(val id: Int) {
|
||||||
|
SHA256(1),
|
||||||
|
SHA512(2),
|
||||||
|
}
|
||||||
|
|
||||||
expect abstract class Ed25519LowLevel() {
|
expect abstract class Ed25519LowLevel() {
|
||||||
fun isValidPoint(encoded: UByteArray): Boolean
|
fun isValidPoint(encoded: UByteArray): Boolean
|
||||||
fun addPoints(p: UByteArray, q: UByteArray): UByteArray
|
fun addPoints(p: UByteArray, q: UByteArray): UByteArray
|
||||||
fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray
|
fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray
|
||||||
fun encodedPointFromHash(hash: UByteArray): UByteArray
|
fun encodedPointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray
|
||||||
|
fun encodedPointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray
|
||||||
fun encodedPointFromUniform(uniform: UByteArray): UByteArray
|
fun encodedPointFromUniform(uniform: UByteArray): UByteArray
|
||||||
fun randomEncodedPoint(): UByteArray
|
fun randomEncodedPoint(): UByteArray
|
||||||
fun randomEncodedScalar(): UByteArray
|
fun randomEncodedScalar(): UByteArray
|
||||||
@ -45,7 +51,11 @@ object Ed25519 : Ed25519LowLevel() {
|
|||||||
fun subtract(p: Point, q: Point): Point =
|
fun subtract(p: Point, q: Point): Point =
|
||||||
Point(subtractPoints(p.encoded, q.encoded))
|
Point(subtractPoints(p.encoded, q.encoded))
|
||||||
|
|
||||||
fun pointFromHash(hash: UByteArray): Point = Point(encodedPointFromHash(hash))
|
fun pointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): Point =
|
||||||
|
Point(encodedPointFromString(ctx, msg, hashAlg))
|
||||||
|
|
||||||
|
fun pointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): Point =
|
||||||
|
Point(encodedPointFromStringRo(ctx, msg, hashAlg))
|
||||||
|
|
||||||
fun pointFromUniform(uniform: UByteArray): Point = Point(encodedPointFromUniform(uniform))
|
fun pointFromUniform(uniform: UByteArray): Point = Point(encodedPointFromUniform(uniform))
|
||||||
|
|
||||||
@ -103,8 +113,6 @@ object Ed25519 : Ed25519LowLevel() {
|
|||||||
val IDENTITY: Point = Point(UByteArray(crypto_core_ed25519_BYTES))
|
val IDENTITY: Point = Point(UByteArray(crypto_core_ed25519_BYTES))
|
||||||
val BASE: Point = scalarMultiplicationBaseNoClamp(Scalar.ONE)
|
val BASE: Point = scalarMultiplicationBaseNoClamp(Scalar.ONE)
|
||||||
|
|
||||||
fun fromHash(hash: UByteArray): Point = pointFromHash(hash)
|
|
||||||
|
|
||||||
fun fromUniform(uniform: UByteArray): Point = pointFromUniform(uniform)
|
fun fromUniform(uniform: UByteArray): Point = pointFromUniform(uniform)
|
||||||
|
|
||||||
fun random(): Point = randomPoint()
|
fun random(): Point = randomPoint()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.ionspin.kotlin.crypto.ristretto255
|
package com.ionspin.kotlin.crypto.ristretto255
|
||||||
|
|
||||||
|
import com.ionspin.kotlin.crypto.ed25519.HashToCurveAlgorithm
|
||||||
import com.ionspin.kotlin.crypto.util.LibsodiumUtil
|
import com.ionspin.kotlin.crypto.util.LibsodiumUtil
|
||||||
import kotlin.UByteArray
|
import kotlin.UByteArray
|
||||||
|
|
||||||
@ -22,6 +23,8 @@ expect abstract class Ristretto255LowLevel() {
|
|||||||
fun addPoints(p: UByteArray, q: UByteArray): UByteArray
|
fun addPoints(p: UByteArray, q: UByteArray): UByteArray
|
||||||
fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray
|
fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray
|
||||||
fun encodedPointFromHash(hash: UByteArray): UByteArray
|
fun encodedPointFromHash(hash: UByteArray): UByteArray
|
||||||
|
fun encodedPointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray
|
||||||
|
fun encodedPointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray
|
||||||
fun randomEncodedPoint(): UByteArray
|
fun randomEncodedPoint(): UByteArray
|
||||||
fun randomEncodedScalar(): UByteArray
|
fun randomEncodedScalar(): UByteArray
|
||||||
fun invertScalar(scalar: UByteArray): UByteArray
|
fun invertScalar(scalar: UByteArray): UByteArray
|
||||||
@ -44,6 +47,12 @@ object Ristretto255 : Ristretto255LowLevel() {
|
|||||||
|
|
||||||
fun pointFromHash(hash: UByteArray): Point = Point(encodedPointFromHash(hash))
|
fun pointFromHash(hash: UByteArray): Point = Point(encodedPointFromHash(hash))
|
||||||
|
|
||||||
|
fun pointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): Point =
|
||||||
|
Point(encodedPointFromString(ctx, msg, hashAlg))
|
||||||
|
|
||||||
|
fun pointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): Point =
|
||||||
|
Point(encodedPointFromStringRo(ctx, msg, hashAlg))
|
||||||
|
|
||||||
fun randomPoint(): Point = Point(randomEncodedPoint())
|
fun randomPoint(): Point = Point(randomEncodedPoint())
|
||||||
|
|
||||||
fun randomScalar(): Scalar = Scalar(randomEncodedScalar())
|
fun randomScalar(): Scalar = Scalar(randomEncodedScalar())
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package com.ionspin.kotlin.crypto.ed25519
|
package com.ionspin.kotlin.crypto.ed25519
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
||||||
import com.ionspin.kotlin.crypto.hash.Hash
|
|
||||||
import com.ionspin.kotlin.crypto.util.LibsodiumUtil
|
import com.ionspin.kotlin.crypto.util.LibsodiumUtil
|
||||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
|
||||||
import com.ionspin.kotlin.crypto.util.runTest
|
import com.ionspin.kotlin.crypto.util.runTest
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
@ -183,18 +181,6 @@ class Ed25519Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testPointFromHash() = runTest {
|
|
||||||
LibsodiumInitializer.initializeWithCallback {
|
|
||||||
for ((input, output) in fromHashTestVectors) {
|
|
||||||
val outPoint = Ed25519.Point.fromHex(output)
|
|
||||||
val hash = Hash.sha512(input.encodeToUByteArray())
|
|
||||||
|
|
||||||
assertEquals(outPoint, Ed25519.Point.fromHash(hash))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPointFromUniform() = runTest {
|
fun testPointFromUniform() = runTest {
|
||||||
LibsodiumInitializer.initializeWithCallback {
|
LibsodiumInitializer.initializeWithCallback {
|
||||||
|
@ -63,8 +63,6 @@ class Ristretto255Test {
|
|||||||
|
|
||||||
// Test vectors from https://ristretto.group/test_vectors/ristretto255.html
|
// Test vectors from https://ristretto.group/test_vectors/ristretto255.html
|
||||||
val basePointSmallMultiples = arrayOf(
|
val basePointSmallMultiples = arrayOf(
|
||||||
// This is the identity point
|
|
||||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
||||||
// This is the basepoint
|
// This is the basepoint
|
||||||
"e2f2ae0a6abc4e71a884a961c500515f58e30b6aa582dd8db6a65945e08d2d76",
|
"e2f2ae0a6abc4e71a884a961c500515f58e30b6aa582dd8db6a65945e08d2d76",
|
||||||
// These are small multiples of the basepoint
|
// These are small multiples of the basepoint
|
||||||
@ -131,7 +129,7 @@ class Ristretto255Test {
|
|||||||
for (i in basePointSmallMultiples.indices) {
|
for (i in basePointSmallMultiples.indices) {
|
||||||
val p = Ristretto255.Point.fromHex(basePointSmallMultiples[i])
|
val p = Ristretto255.Point.fromHex(basePointSmallMultiples[i])
|
||||||
val b = Ristretto255.Point.BASE
|
val b = Ristretto255.Point.BASE
|
||||||
val n = Ristretto255.Scalar.fromUInt(i.toUInt())
|
val n = Ristretto255.Scalar.fromUInt(i.toUInt() + 1U)
|
||||||
|
|
||||||
assertEquals(p, Ristretto255.scalarMultiplicationBase(n))
|
assertEquals(p, Ristretto255.scalarMultiplicationBase(n))
|
||||||
assertEquals(p, Ristretto255.scalarMultiplication(b, n))
|
assertEquals(p, Ristretto255.scalarMultiplication(b, n))
|
||||||
@ -146,7 +144,7 @@ class Ristretto255Test {
|
|||||||
assertEquals(q, p - b * m)
|
assertEquals(q, p - b * m)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j in i..<basePointSmallMultiples.size) {
|
for (j in i + 1..<basePointSmallMultiples.size) {
|
||||||
val q = Ristretto255.Point.fromHex(basePointSmallMultiples[j])
|
val q = Ristretto255.Point.fromHex(basePointSmallMultiples[j])
|
||||||
val m = Ristretto255.Scalar.fromUInt(j.toUInt() - i.toUInt())
|
val m = Ristretto255.Scalar.fromUInt(j.toUInt() - i.toUInt())
|
||||||
|
|
||||||
|
@ -375,6 +375,12 @@ external object JsSodiumInterface {
|
|||||||
@JsName("crypto_core_ristretto255_from_hash")
|
@JsName("crypto_core_ristretto255_from_hash")
|
||||||
fun crypto_core_ristretto255_from_hash(r: Uint8Array): Uint8Array
|
fun crypto_core_ristretto255_from_hash(r: Uint8Array): Uint8Array
|
||||||
|
|
||||||
|
@JsName("crypto_core_ristretto255_from_string")
|
||||||
|
fun crypto_core_ed25519_from_string(ctx: String?, message: Uint8Array, hashAlg: Int): Uint8Array
|
||||||
|
|
||||||
|
@JsName("crypto_core_ristretto255_from_string_ro")
|
||||||
|
fun crypto_core_ed25519_from_string_ro(ctx: String?, message: Uint8Array, hashAlg: Int): Uint8Array
|
||||||
|
|
||||||
@JsName("crypto_core_ristretto255_add")
|
@JsName("crypto_core_ristretto255_add")
|
||||||
fun crypto_core_ristretto255_add(p: Uint8Array, q: Uint8Array): Uint8Array
|
fun crypto_core_ristretto255_add(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||||
|
|
||||||
@ -424,8 +430,11 @@ external object JsSodiumInterface {
|
|||||||
@JsName("crypto_core_ed25519_random")
|
@JsName("crypto_core_ed25519_random")
|
||||||
fun crypto_core_ed25519_random(): Uint8Array
|
fun crypto_core_ed25519_random(): Uint8Array
|
||||||
|
|
||||||
@JsName("crypto_core_ed25519_from_hash")
|
@JsName("crypto_core_ed25519_from_string")
|
||||||
fun crypto_core_ed25519_from_hash(r: Uint8Array): Uint8Array
|
fun crypto_core_ed25519_from_string(ctx: String, message: Uint8Array, hashAlg: Int): Uint8Array
|
||||||
|
|
||||||
|
@JsName("crypto_core_ed25519_from_string_ro")
|
||||||
|
fun crypto_core_ed25519_from_string_ro(ctx: String, message: Uint8Array, hashAlg: Int): Uint8Array
|
||||||
|
|
||||||
@JsName("crypto_core_ed25519_from_uniform")
|
@JsName("crypto_core_ed25519_from_uniform")
|
||||||
fun crypto_core_ed25519_from_uniform(r: Uint8Array): Uint8Array
|
fun crypto_core_ed25519_from_uniform(r: Uint8Array): Uint8Array
|
||||||
|
@ -6,28 +6,34 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
|||||||
|
|
||||||
actual abstract class Ed25519LowLevel actual constructor() {
|
actual abstract class Ed25519LowLevel actual constructor() {
|
||||||
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
||||||
getSodium().crypto_core_ed25519_is_valid_point(encoded.toUint8Array())
|
getSodium().crypto_core_ed25519_is_valid_point(encoded.toUInt8Array())
|
||||||
|
|
||||||
actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray {
|
actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_add(p.toUint8Array(), q.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_add(p.toUInt8Array(), q.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray {
|
actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_sub(p.toUint8Array(), q.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_sub(p.toUInt8Array(), q.toUInt8Array())
|
||||||
|
|
||||||
return result
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun encodedPointFromHash(hash: UByteArray): UByteArray {
|
actual fun encodedPointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_from_hash(hash.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_from_string(ctx, msg.toUInt8Array(), hashAlg.id)
|
||||||
|
|
||||||
|
return result.toUByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = getSodium().crypto_core_ed25519_from_string_ro(ctx, msg.toUInt8Array(), hashAlg.id)
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray {
|
actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_from_uniform(hash.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_from_uniform(uniform.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
@ -45,67 +51,67 @@ actual abstract class Ed25519LowLevel actual constructor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actual fun invertScalar(scalar: UByteArray): UByteArray {
|
actual fun invertScalar(scalar: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_scalar_invert(scalar.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_scalar_invert(scalar.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun negateScalar(scalar: UByteArray): UByteArray {
|
actual fun negateScalar(scalar: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_scalar_negate(scalar.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_scalar_negate(scalar.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun complementScalar(scalar: UByteArray): UByteArray {
|
actual fun complementScalar(scalar: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_scalar_complement(scalar.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_scalar_complement(scalar.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray {
|
actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_scalar_add(x.toUint8Array(), y.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_scalar_add(x.toUInt8Array(), y.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray {
|
actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_scalar_sub(x.toUint8Array(), y.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_scalar_sub(x.toUInt8Array(), y.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray {
|
actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_scalar_mul(x.toUint8Array(), y.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_scalar_mul(x.toUInt8Array(), y.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun reduceScalar(scalar: UByteArray): UByteArray {
|
actual fun reduceScalar(scalar: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ed25519_scalar_reduce(scalar.toUint8Array())
|
val result = getSodium().crypto_core_ed25519_scalar_reduce(scalar.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray {
|
actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_scalarmult_ed25519(n.toUint8Array(), p.toUint8Array())
|
val result = getSodium().crypto_scalarmult_ed25519(n.toUInt8Array(), p.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray {
|
actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_scalarmult_ed25519_noclamp(n.toUint8Array(), p.toUint8Array())
|
val result = getSodium().crypto_scalarmult_ed25519_noclamp(n.toUInt8Array(), p.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun scalarMultiplicationBase(n: UByteArray): UByteArray {
|
actual fun scalarMultiplicationBase(n: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_scalarmult_ed25519_base(n.toUint8Array())
|
val result = getSodium().crypto_scalarmult_ed25519_base(n.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray {
|
actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_scalarmult_ed25519_base_noclamp(n.toUint8Array())
|
val result = getSodium().crypto_scalarmult_ed25519_base_noclamp(n.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,34 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
|||||||
|
|
||||||
actual abstract class Ristretto255LowLevel actual constructor() {
|
actual abstract class Ristretto255LowLevel actual constructor() {
|
||||||
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
||||||
getSodium().crypto_core_ristretto255_is_valid_point(encoded.toUint8Array())
|
getSodium().crypto_core_ristretto255_is_valid_point(encoded.toUInt8Array())
|
||||||
|
|
||||||
actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray {
|
actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_add(p.toUint8Array(), q.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_add(p.toUInt8Array(), q.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray {
|
actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_sub(p.toUint8Array(), q.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_sub(p.toUInt8Array(), q.toUInt8Array())
|
||||||
|
|
||||||
return result
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun encodedPointFromHash(hash: UByteArray): UByteArray {
|
actual fun encodedPointFromHash(hash: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_from_hash(hash.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_from_hash(hash.toUInt8Array())
|
||||||
|
|
||||||
|
return result.toUByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = getSodium().crypto_core_ristretto255_from_string(ctx, msg.toUInt8Array(), hashAlg.id)
|
||||||
|
|
||||||
|
return result.toUByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = getSodium().crypto_core_ristretto255_from_string_ro(ctx, msg.toUInt8Array(), hashAlg.id)
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
@ -39,55 +51,55 @@ actual abstract class Ristretto255LowLevel actual constructor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actual fun invertScalar(scalar: UByteArray): UByteArray {
|
actual fun invertScalar(scalar: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_scalar_invert(scalar.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_scalar_invert(scalar.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun negateScalar(scalar: UByteArray): UByteArray {
|
actual fun negateScalar(scalar: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_scalar_negate(scalar.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_scalar_negate(scalar.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun complementScalar(scalar: UByteArray): UByteArray {
|
actual fun complementScalar(scalar: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_scalar_complement(scalar.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_scalar_complement(scalar.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray {
|
actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_scalar_add(x.toUint8Array(), y.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_scalar_add(x.toUInt8Array(), y.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray {
|
actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_scalar_sub(x.toUint8Array(), y.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_scalar_sub(x.toUInt8Array(), y.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray {
|
actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_scalar_mul(x.toUint8Array(), y.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_scalar_mul(x.toUInt8Array(), y.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun reduceScalar(scalar: UByteArray): UByteArray {
|
actual fun reduceScalar(scalar: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_core_ristretto255_scalar_reduce(scalar.toUint8Array())
|
val result = getSodium().crypto_core_ristretto255_scalar_reduce(scalar.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray {
|
actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_scalarmult_ristretto255(n.toUint8Array(), p.toUint8Array())
|
val result = getSodium().crypto_scalarmult_ristretto255(n.toUInt8Array(), p.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun scalarMultiplicationBase(n: UByteArray): UByteArray {
|
actual fun scalarMultiplicationBase(n: UByteArray): UByteArray {
|
||||||
val result = getSodium().crypto_scalarmult_ristretto255_base(n.toUint8Array())
|
val result = getSodium().crypto_scalarmult_ristretto255_base(n.toUInt8Array())
|
||||||
|
|
||||||
return result.toUByteArray()
|
return result.toUByteArray()
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun randombytes_buf_deterministic(
|
fun randombytes_buf_deterministic(
|
||||||
buffer: ByteArray,
|
buffer: ByteArray,
|
||||||
size: Int,
|
size: Int,
|
||||||
seed: ByteArray
|
seed: ByteArray,
|
||||||
)
|
)
|
||||||
|
|
||||||
// uint32_t randombytes_random(void)
|
// uint32_t randombytes_random(void)
|
||||||
@ -99,7 +99,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
|
|
||||||
// uint32_t randombytes_uniform(const uint32_t upper_bound);
|
// uint32_t randombytes_uniform(const uint32_t upper_bound);
|
||||||
fun randombytes_uniform(
|
fun randombytes_uniform(
|
||||||
upperBound: Long
|
upperBound: Long,
|
||||||
): Long
|
): Long
|
||||||
|
|
||||||
// void sodium_memzero(void * const pnt, const size_t len);
|
// void sodium_memzero(void * const pnt, const size_t len);
|
||||||
@ -114,7 +114,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
hex: ByteArray,
|
hex: ByteArray,
|
||||||
hexMaxlen: Int,
|
hexMaxlen: Int,
|
||||||
bin: ByteArray,
|
bin: ByteArray,
|
||||||
binLen: Int
|
binLen: Int,
|
||||||
): String
|
): String
|
||||||
|
|
||||||
// int sodium_hex2bin(
|
// int sodium_hex2bin(
|
||||||
@ -129,7 +129,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
hexLen: Int,
|
hexLen: Int,
|
||||||
ignore: ByteArray?,
|
ignore: ByteArray?,
|
||||||
binLen: Pointer,
|
binLen: Pointer,
|
||||||
hexEnd: Pointer?
|
hexEnd: Pointer?,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
|
// int sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
|
||||||
@ -139,7 +139,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
buffer: ByteArray,
|
buffer: ByteArray,
|
||||||
unpaddedBufferLength: Int,
|
unpaddedBufferLength: Int,
|
||||||
blockSize: Int,
|
blockSize: Int,
|
||||||
maxBufferLength: Int
|
maxBufferLength: Int,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
|
// int sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
|
||||||
@ -148,7 +148,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
unpaddedBufferLength: Pointer,
|
unpaddedBufferLength: Pointer,
|
||||||
buffer: ByteArray,
|
buffer: ByteArray,
|
||||||
paddedBufferLength: Int,
|
paddedBufferLength: Int,
|
||||||
blockSize: Int
|
blockSize: Int,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
base64MaxLength: Int,
|
base64MaxLength: Int,
|
||||||
bin: ByteArray,
|
bin: ByteArray,
|
||||||
binLength: Int,
|
binLength: Int,
|
||||||
variant: Int
|
variant: Int,
|
||||||
)
|
)
|
||||||
|
|
||||||
// int sodium_base642bin(
|
// int sodium_base642bin(
|
||||||
@ -176,7 +176,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ignore: ByteArray?,
|
ignore: ByteArray?,
|
||||||
binLength: Pointer,
|
binLength: Pointer,
|
||||||
base64End: Pointer?,
|
base64End: Pointer?,
|
||||||
variant: Int
|
variant: Int,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// size_t sodium_base64_encoded_len(const size_t bin_len, const int variant)
|
// size_t sodium_base64_encoded_len(const size_t bin_len, const int variant)
|
||||||
@ -193,7 +193,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
input: ByteArray,
|
input: ByteArray,
|
||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray,
|
key: ByteArray,
|
||||||
keylen: Int
|
keylen: Int,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_hash_sha256(unsigned char *out, const unsigned char *in,
|
// int crypto_hash_sha256(unsigned char *out, const unsigned char *in,
|
||||||
@ -243,7 +243,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
input: ByteArray,
|
input: ByteArray,
|
||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray,
|
key: ByteArray,
|
||||||
keylen: Int
|
keylen: Int,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state,
|
// int crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state,
|
||||||
@ -334,7 +334,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
nsec: ByteArray?,
|
nsec: ByteArray?,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_xchacha20poly1305_ietf_decrypt(
|
// int crypto_aead_xchacha20poly1305_ietf_decrypt(
|
||||||
@ -356,7 +356,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_xchacha20poly1305_ietf_encrypt_detached(
|
// int crypto_aead_xchacha20poly1305_ietf_encrypt_detached(
|
||||||
@ -380,7 +380,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
nsec: ByteArray?,
|
nsec: ByteArray?,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_xchacha20poly1305_ietf_decrypt_detached(
|
// int crypto_aead_xchacha20poly1305_ietf_decrypt_detached(
|
||||||
@ -402,7 +402,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// void crypto_aead_xchacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES])
|
// void crypto_aead_xchacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES])
|
||||||
@ -432,7 +432,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
nsec: ByteArray?,
|
nsec: ByteArray?,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_chacha20poly1305_ietf_decrypt(
|
// int crypto_aead_chacha20poly1305_ietf_decrypt(
|
||||||
@ -454,7 +454,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_chacha20poly1305_ietf_encrypt_detached(
|
// int crypto_aead_chacha20poly1305_ietf_encrypt_detached(
|
||||||
@ -478,7 +478,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
nsec: ByteArray?,
|
nsec: ByteArray?,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_chacha20poly1305_ietf_decrypt_detached(
|
// int crypto_aead_chacha20poly1305_ietf_decrypt_detached(
|
||||||
@ -500,7 +500,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// void crypto_aead_chacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES])
|
// void crypto_aead_chacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES])
|
||||||
@ -532,7 +532,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
nsec: ByteArray?,
|
nsec: ByteArray?,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_xchacha20poly1305_decrypt(unsigned char *m,
|
// int crypto_aead_xchacha20poly1305_decrypt(unsigned char *m,
|
||||||
@ -553,7 +553,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_chacha20poly1305_encrypt_detached(
|
// int crypto_aead_chacha20poly1305_encrypt_detached(
|
||||||
@ -577,7 +577,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
nsec: ByteArray?,
|
nsec: ByteArray?,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_aead_chacha20poly1305_decrypt_detached(
|
// int crypto_aead_chacha20poly1305_decrypt_detached(
|
||||||
@ -599,7 +599,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
npub: ByteArray,
|
npub: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// void crypto_aead_chacha20poly1305_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES])
|
// void crypto_aead_chacha20poly1305_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES])
|
||||||
@ -622,7 +622,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_secretstream_xchacha20poly1305_init_push(
|
fun crypto_secretstream_xchacha20poly1305_init_push(
|
||||||
state: SecretStreamXChaCha20Poly1305State,
|
state: SecretStreamXChaCha20Poly1305State,
|
||||||
header: ByteArray,
|
header: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_secretstream_xchacha20poly1305_push
|
// int crypto_secretstream_xchacha20poly1305_push
|
||||||
@ -638,7 +638,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long,
|
additionalDataLength: Long,
|
||||||
tag: Byte
|
tag: Byte,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// decrypt
|
// decrypt
|
||||||
@ -650,7 +650,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_secretstream_xchacha20poly1305_init_pull(
|
fun crypto_secretstream_xchacha20poly1305_init_pull(
|
||||||
state: SecretStreamXChaCha20Poly1305State,
|
state: SecretStreamXChaCha20Poly1305State,
|
||||||
header: ByteArray,
|
header: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_secretstream_xchacha20poly1305_pull
|
// int crypto_secretstream_xchacha20poly1305_pull
|
||||||
@ -666,7 +666,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertext: ByteArray,
|
ciphertext: ByteArray,
|
||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
additionalData: ByteArray,
|
additionalData: ByteArray,
|
||||||
additionalDataLength: Long
|
additionalDataLength: Long,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//keygen and rekey
|
//keygen and rekey
|
||||||
@ -696,7 +696,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_secretbox_easy(
|
// int crypto_secretbox_easy(
|
||||||
@ -708,7 +708,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES])
|
// void crypto_secretbox_keygen(unsigned char k[crypto_secretbox_KEYBYTES])
|
||||||
@ -727,7 +727,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
mac: ByteArray,
|
mac: ByteArray,
|
||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_secretbox_open_easy(
|
// int crypto_secretbox_open_easy(
|
||||||
@ -739,7 +739,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertext: ByteArray,
|
ciphertext: ByteArray,
|
||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// ---- SecretBox End ----
|
// ---- SecretBox End ----
|
||||||
@ -752,7 +752,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
out: ByteArray,
|
out: ByteArray,
|
||||||
input: ByteArray,
|
input: ByteArray,
|
||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES])
|
// void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES])
|
||||||
@ -764,7 +764,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
hash: ByteArray,
|
hash: ByteArray,
|
||||||
input: ByteArray,
|
input: ByteArray,
|
||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//Same params as general variant
|
//Same params as general variant
|
||||||
@ -772,7 +772,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
out: ByteArray,
|
out: ByteArray,
|
||||||
input: ByteArray,
|
input: ByteArray,
|
||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//Same params as general variant
|
//Same params as general variant
|
||||||
@ -783,7 +783,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
hash: ByteArray,
|
hash: ByteArray,
|
||||||
input: ByteArray,
|
input: ByteArray,
|
||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//Same params as general variant
|
//Same params as general variant
|
||||||
@ -791,7 +791,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
out: ByteArray,
|
out: ByteArray,
|
||||||
input: ByteArray,
|
input: ByteArray,
|
||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//Same params as general variant
|
//Same params as general variant
|
||||||
@ -802,7 +802,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
hash: ByteArray,
|
hash: ByteArray,
|
||||||
input: ByteArray,
|
input: ByteArray,
|
||||||
inputLength: Long,
|
inputLength: Long,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -818,7 +818,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_box_seed_keypair(
|
fun crypto_box_seed_keypair(
|
||||||
publicKey: ByteArray,
|
publicKey: ByteArray,
|
||||||
secretKey: ByteArray,
|
secretKey: ByteArray,
|
||||||
seed: ByteArray
|
seed: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_box_easy(unsigned char *c, const unsigned char *m,
|
// int crypto_box_easy(unsigned char *c, const unsigned char *m,
|
||||||
@ -830,7 +830,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
recipientPublicKey: ByteArray,
|
recipientPublicKey: ByteArray,
|
||||||
senderSecretKey: ByteArray
|
senderSecretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_box_open_easy(unsigned char *m, const unsigned char *c,
|
// int crypto_box_open_easy(unsigned char *m, const unsigned char *c,
|
||||||
@ -842,7 +842,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
senderPublickKey: ByteArray,
|
senderPublickKey: ByteArray,
|
||||||
recipientSecretKey: ByteArray
|
recipientSecretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_box_detached(unsigned char *c, unsigned char *mac,
|
// int crypto_box_detached(unsigned char *c, unsigned char *mac,
|
||||||
@ -856,7 +856,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
recipientPublicKey: ByteArray,
|
recipientPublicKey: ByteArray,
|
||||||
senderSecretKey: ByteArray
|
senderSecretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_box_open_detached(
|
// int crypto_box_open_detached(
|
||||||
@ -873,7 +873,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
senderPublickKey: ByteArray,
|
senderPublickKey: ByteArray,
|
||||||
recipientSecretKey: ByteArray
|
recipientSecretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
|
// int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
|
||||||
@ -881,7 +881,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_box_beforenm(
|
fun crypto_box_beforenm(
|
||||||
sessionKey: ByteArray,
|
sessionKey: ByteArray,
|
||||||
publicKey: ByteArray,
|
publicKey: ByteArray,
|
||||||
secretKey: ByteArray
|
secretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
|
// int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
|
||||||
@ -892,7 +892,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
sessionKey: ByteArray
|
sessionKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
|
// int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
|
||||||
@ -903,7 +903,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertext: ByteArray,
|
ciphertext: ByteArray,
|
||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
sessionKey: ByteArray
|
sessionKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_box_seal(unsigned char *c, const unsigned char *m,
|
// int crypto_box_seal(unsigned char *c, const unsigned char *m,
|
||||||
@ -912,7 +912,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertext: ByteArray,
|
ciphertext: ByteArray,
|
||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
recipientPublicKey: ByteArray
|
recipientPublicKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
|
|
||||||
@ -924,7 +924,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
ciphertext: ByteArray,
|
ciphertext: ByteArray,
|
||||||
ciphertextLength: Long,
|
ciphertextLength: Long,
|
||||||
senderPublickKey: ByteArray,
|
senderPublickKey: ByteArray,
|
||||||
recipientSecretKey: ByteArray
|
recipientSecretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
//
|
//
|
||||||
// // ---- Box end ----
|
// // ---- Box end ----
|
||||||
@ -940,7 +940,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
signedMessageLength: LongArray?,
|
signedMessageLength: LongArray?,
|
||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
secretKey: ByteArray
|
secretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_open(
|
// int crypto_sign_open(
|
||||||
@ -952,7 +952,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: LongArray?,
|
messageLength: LongArray?,
|
||||||
signedMessage: ByteArray,
|
signedMessage: ByteArray,
|
||||||
signedMessageLength: Long,
|
signedMessageLength: Long,
|
||||||
publicKey: ByteArray
|
publicKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_detached(
|
// int crypto_sign_detached(
|
||||||
@ -964,7 +964,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
signatureLength: LongArray?,
|
signatureLength: LongArray?,
|
||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
secretKey: ByteArray
|
secretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_verify_detached(
|
// int crypto_sign_verify_detached(
|
||||||
@ -976,7 +976,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
signature: ByteArray,
|
signature: ByteArray,
|
||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
publicKey: ByteArray
|
publicKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_ed25519_pk_to_curve25519(
|
// int crypto_sign_ed25519_pk_to_curve25519(
|
||||||
@ -984,27 +984,27 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
// const unsigned char *ed25519_pk)
|
// const unsigned char *ed25519_pk)
|
||||||
fun crypto_sign_ed25519_pk_to_curve25519(
|
fun crypto_sign_ed25519_pk_to_curve25519(
|
||||||
curve25519PublicKey: ByteArray,
|
curve25519PublicKey: ByteArray,
|
||||||
ed25519PublicKey: ByteArray
|
ed25519PublicKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
|
// int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
|
||||||
// const unsigned char *ed25519_sk)
|
// const unsigned char *ed25519_sk)
|
||||||
fun crypto_sign_ed25519_sk_to_curve25519(
|
fun crypto_sign_ed25519_sk_to_curve25519(
|
||||||
curve25519SecretKey: ByteArray,
|
curve25519SecretKey: ByteArray,
|
||||||
ed25519SecretKey: ByteArray
|
ed25519SecretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk)
|
// int crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk)
|
||||||
fun crypto_sign_ed25519_sk_to_pk(
|
fun crypto_sign_ed25519_sk_to_pk(
|
||||||
ed25519PublicKey: ByteArray,
|
ed25519PublicKey: ByteArray,
|
||||||
ed25519SecretKey: ByteArray
|
ed25519SecretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_ed25519_sk_to_seed(unsigned char *seed,
|
// int crypto_sign_ed25519_sk_to_seed(unsigned char *seed,
|
||||||
// const unsigned char *sk)
|
// const unsigned char *sk)
|
||||||
fun crypto_sign_ed25519_sk_to_seed(
|
fun crypto_sign_ed25519_sk_to_seed(
|
||||||
seed: ByteArray,
|
seed: ByteArray,
|
||||||
ed25519SecretKey: ByteArray
|
ed25519SecretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_init(crypto_sign_state *state);
|
// int crypto_sign_init(crypto_sign_state *state);
|
||||||
@ -1015,7 +1015,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_sign_update(
|
fun crypto_sign_update(
|
||||||
state: Ed25519SignatureState,
|
state: Ed25519SignatureState,
|
||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long
|
messageLength: Long,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig,
|
// int crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig,
|
||||||
@ -1025,7 +1025,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
state: Ed25519SignatureState,
|
state: Ed25519SignatureState,
|
||||||
signature: ByteArray,
|
signature: ByteArray,
|
||||||
signatureLength: LongArray?,
|
signatureLength: LongArray?,
|
||||||
secretKey: ByteArray
|
secretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_final_verify(crypto_sign_state *state, const unsigned char *sig,
|
// int crypto_sign_final_verify(crypto_sign_state *state, const unsigned char *sig,
|
||||||
@ -1033,12 +1033,12 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_sign_final_verify(
|
fun crypto_sign_final_verify(
|
||||||
state: Ed25519SignatureState,
|
state: Ed25519SignatureState,
|
||||||
signature: ByteArray,
|
signature: ByteArray,
|
||||||
publicKey: ByteArray
|
publicKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_keypair(unsigned char *pk, unsigned char *sk)
|
// int crypto_sign_keypair(unsigned char *pk, unsigned char *sk)
|
||||||
fun crypto_sign_keypair(
|
fun crypto_sign_keypair(
|
||||||
publicKey: ByteArray, secretKey: ByteArray
|
publicKey: ByteArray, secretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk,
|
// int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk,
|
||||||
@ -1046,7 +1046,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_sign_seed_keypair(
|
fun crypto_sign_seed_keypair(
|
||||||
publicKey: ByteArray,
|
publicKey: ByteArray,
|
||||||
secretKey: ByteArray,
|
secretKey: ByteArray,
|
||||||
seed: ByteArray
|
seed: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
|
|
||||||
@ -1067,12 +1067,12 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
subkeyLength: Int,
|
subkeyLength: Int,
|
||||||
subkeyId: Long,
|
subkeyId: Long,
|
||||||
context: ByteArray,
|
context: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// void crypto_kdf_keygen(unsigned char k[crypto_kdf_KEYBYTES])
|
// void crypto_kdf_keygen(unsigned char k[crypto_kdf_KEYBYTES])
|
||||||
fun crypto_kdf_keygen(
|
fun crypto_kdf_keygen(
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
)
|
)
|
||||||
//
|
//
|
||||||
// // ---- KDF end -----
|
// // ---- KDF end -----
|
||||||
@ -1093,7 +1093,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
salt: ByteArray,
|
salt: ByteArray,
|
||||||
opslimit: Long,
|
opslimit: Long,
|
||||||
memlimit: Long,
|
memlimit: Long,
|
||||||
algorithm : Int
|
algorithm: Int,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES],
|
// int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES],
|
||||||
@ -1104,7 +1104,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
password: String,
|
password: String,
|
||||||
passwordLength: Long,
|
passwordLength: Long,
|
||||||
opslimit: Long,
|
opslimit: Long,
|
||||||
memlimit: Long
|
memlimit: Long,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES],
|
// int crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES],
|
||||||
@ -1112,15 +1112,16 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_pwhash_str_needs_rehash(
|
fun crypto_pwhash_str_needs_rehash(
|
||||||
output: String,
|
output: String,
|
||||||
opslimit: Long,
|
opslimit: Long,
|
||||||
memlimit: Long
|
memlimit: Long,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES],
|
// int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES],
|
||||||
// const char * const passwd,
|
// const char * const passwd,
|
||||||
// unsigned long long passwdlen)
|
// unsigned long long passwdlen)
|
||||||
fun crypto_pwhash_str_verify(
|
fun crypto_pwhash_str_verify(
|
||||||
hash: String,
|
hash: String,
|
||||||
password: String,
|
password: String,
|
||||||
passwordLength: Long
|
passwordLength: Long,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -1128,7 +1129,6 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // ---- Key exchange ----
|
// // ---- Key exchange ----
|
||||||
|
|
||||||
|
|
||||||
@ -1136,7 +1136,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
// unsigned char sk[crypto_kx_SECRETKEYBYTES])
|
// unsigned char sk[crypto_kx_SECRETKEYBYTES])
|
||||||
fun crypto_kx_keypair(
|
fun crypto_kx_keypair(
|
||||||
publicKey: ByteArray,
|
publicKey: ByteArray,
|
||||||
secretKey: ByteArray
|
secretKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
|
|
||||||
@ -1146,8 +1146,9 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
fun crypto_kx_seed_keypair(
|
fun crypto_kx_seed_keypair(
|
||||||
publicKey: ByteArray,
|
publicKey: ByteArray,
|
||||||
secretKey: ByteArray,
|
secretKey: ByteArray,
|
||||||
seed: ByteArray
|
seed: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],
|
// int crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],
|
||||||
// unsigned char tx[crypto_kx_SESSIONKEYBYTES],
|
// unsigned char tx[crypto_kx_SESSIONKEYBYTES],
|
||||||
// const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES],
|
// const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES],
|
||||||
@ -1158,8 +1159,9 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
sendKey: ByteArray,
|
sendKey: ByteArray,
|
||||||
clientPublicKey: ByteArray,
|
clientPublicKey: ByteArray,
|
||||||
clientSecretKey: ByteArray,
|
clientSecretKey: ByteArray,
|
||||||
serverPublicKey: ByteArray
|
serverPublicKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_kx_server_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],
|
// int crypto_kx_server_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],
|
||||||
// unsigned char tx[crypto_kx_SESSIONKEYBYTES],
|
// unsigned char tx[crypto_kx_SESSIONKEYBYTES],
|
||||||
// const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES],
|
// const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES],
|
||||||
@ -1170,7 +1172,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
sendKey: ByteArray,
|
sendKey: ByteArray,
|
||||||
serverPublicKey: ByteArray,
|
serverPublicKey: ByteArray,
|
||||||
serverSecretKey: ByteArray,
|
serverSecretKey: ByteArray,
|
||||||
clientPublicKey: ByteArray
|
clientPublicKey: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -1184,8 +1186,9 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
stream: ByteArray,
|
stream: ByteArray,
|
||||||
streamLength: Long,
|
streamLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m,
|
// int crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m,
|
||||||
// unsigned long long mlen, const unsigned char *n,
|
// unsigned long long mlen, const unsigned char *n,
|
||||||
// const unsigned char *k)
|
// const unsigned char *k)
|
||||||
@ -1194,8 +1197,9 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m,
|
// int crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m,
|
||||||
// unsigned long long mlen,
|
// unsigned long long mlen,
|
||||||
// const unsigned char *n, uint64_t ic,
|
// const unsigned char *n, uint64_t ic,
|
||||||
@ -1206,7 +1210,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
initialCounter: Long,
|
initialCounter: Long,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen,
|
// int crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen,
|
||||||
@ -1215,7 +1219,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
stream: ByteArray,
|
stream: ByteArray,
|
||||||
streamLength: Long,
|
streamLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m,
|
// int crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m,
|
||||||
@ -1226,7 +1230,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m,
|
// int crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m,
|
||||||
@ -1239,7 +1243,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
initialCounter: Int,
|
initialCounter: Int,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// void crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES])
|
// void crypto_stream_chacha20_keygen(unsigned char k[crypto_stream_chacha20_KEYBYTES])
|
||||||
@ -1251,7 +1255,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
stream: ByteArray,
|
stream: ByteArray,
|
||||||
streamLength: Long,
|
streamLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m,
|
// int crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m,
|
||||||
@ -1262,7 +1266,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
message: ByteArray,
|
message: ByteArray,
|
||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// int crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m,
|
// int crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m,
|
||||||
@ -1275,8 +1279,9 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
messageLength: Long,
|
messageLength: Long,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
initialCounter: Long,
|
initialCounter: Long,
|
||||||
key: ByteArray
|
key: ByteArray,
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
// void crypto_stream_xchacha20_keygen(unsigned char k[crypto_stream_xchacha20_KEYBYTES])
|
// void crypto_stream_xchacha20_keygen(unsigned char k[crypto_stream_xchacha20_KEYBYTES])
|
||||||
fun crypto_stream_xchacha20_keygen(key: ByteArray)
|
fun crypto_stream_xchacha20_keygen(key: ByteArray)
|
||||||
|
|
||||||
@ -1289,6 +1294,7 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
// int crypto_scalarmult(unsigned char *q, const unsigned char *n,
|
// int crypto_scalarmult(unsigned char *q, const unsigned char *n,
|
||||||
// const unsigned char *p)
|
// const unsigned char *p)
|
||||||
fun crypto_scalarmult(q: ByteArray, n: ByteArray, p: ByteArray): Int
|
fun crypto_scalarmult(q: ByteArray, n: ByteArray, p: ByteArray): Int
|
||||||
|
|
||||||
// int crypto_scalarmult_base(unsigned char *q, const unsigned char *n)
|
// int crypto_scalarmult_base(unsigned char *q, const unsigned char *n)
|
||||||
fun crypto_scalarmult_base(q: ByteArray, b: ByteArray): Int
|
fun crypto_scalarmult_base(q: ByteArray, b: ByteArray): Int
|
||||||
//
|
//
|
||||||
@ -1303,6 +1309,22 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
|
|
||||||
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_from_string(
|
||||||
|
p: ByteArray,
|
||||||
|
ctx: ByteArray?,
|
||||||
|
msg: ByteArray,
|
||||||
|
msgLen: Int,
|
||||||
|
hashAlg: Int,
|
||||||
|
): Int
|
||||||
|
|
||||||
|
fun crypto_core_ristretto255_from_string_ro(
|
||||||
|
p: ByteArray,
|
||||||
|
ctx: ByteArray?,
|
||||||
|
msg: ByteArray,
|
||||||
|
msgLen: Int,
|
||||||
|
hashAlg: Int,
|
||||||
|
): 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
|
||||||
@ -1337,7 +1359,9 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
|
|
||||||
fun crypto_core_ed25519_random(p: ByteArray)
|
fun crypto_core_ed25519_random(p: ByteArray)
|
||||||
|
|
||||||
fun crypto_core_ed25519_from_hash(p: ByteArray, r: ByteArray): Int
|
fun crypto_core_ed25519_from_string(p: ByteArray, ctx: ByteArray?, msg: ByteArray, msgLen: Int, hashAlg: Int): Int
|
||||||
|
|
||||||
|
fun crypto_core_ed25519_from_string_ro(p: ByteArray, ctx: ByteArray?, msg: ByteArray, msgLen: Int, hashAlg: Int): Int
|
||||||
|
|
||||||
fun crypto_core_ed25519_from_uniform(p: ByteArray, r: ByteArray): Int
|
fun crypto_core_ed25519_from_uniform(p: ByteArray, r: ByteArray): Int
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package com.ionspin.kotlin.crypto.ed25519
|
|||||||
|
|
||||||
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
|
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
||||||
import kotlin.UByteArray
|
import com.ionspin.kotlin.crypto.util.toCString
|
||||||
|
|
||||||
actual abstract class Ed25519LowLevel actual constructor() {
|
actual abstract class Ed25519LowLevel actual constructor() {
|
||||||
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
||||||
@ -26,10 +26,32 @@ actual abstract class Ed25519LowLevel actual constructor() {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun encodedPointFromHash(hash: UByteArray): UByteArray {
|
actual fun encodedPointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
val result = UByteArray(crypto_core_ed25519_BYTES)
|
val result = UByteArray(crypto_core_ed25519_BYTES)
|
||||||
|
val ctxEncoded = ctx?.toCString()
|
||||||
|
|
||||||
sodiumJna.crypto_core_ed25519_from_hash(result.asByteArray(), hash.asByteArray())
|
sodiumJna.crypto_core_ed25519_from_string(
|
||||||
|
result.asByteArray(),
|
||||||
|
ctxEncoded?.asByteArray(),
|
||||||
|
msg.asByteArray(),
|
||||||
|
msg.size,
|
||||||
|
hashAlg.id
|
||||||
|
).ensureLibsodiumSuccess()
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = UByteArray(crypto_core_ed25519_BYTES)
|
||||||
|
val ctxEncoded = ctx?.toCString()
|
||||||
|
|
||||||
|
sodiumJna.crypto_core_ed25519_from_string_ro(
|
||||||
|
result.asByteArray(),
|
||||||
|
ctxEncoded?.asByteArray(),
|
||||||
|
msg.asByteArray(),
|
||||||
|
msg.size,
|
||||||
|
hashAlg.id
|
||||||
|
).ensureLibsodiumSuccess()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ package com.ionspin.kotlin.crypto.ristretto255
|
|||||||
|
|
||||||
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
|
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
||||||
import kotlin.UByteArray
|
import com.ionspin.kotlin.crypto.ed25519.HashToCurveAlgorithm
|
||||||
|
import com.ionspin.kotlin.crypto.util.toCString
|
||||||
|
|
||||||
actual abstract class Ristretto255LowLevel actual constructor() {
|
actual abstract class Ristretto255LowLevel actual constructor() {
|
||||||
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
||||||
@ -34,6 +35,36 @@ actual abstract class Ristretto255LowLevel actual constructor() {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = UByteArray(crypto_core_ristretto255_BYTES)
|
||||||
|
val ctxEncoded = ctx?.toCString()
|
||||||
|
|
||||||
|
sodiumJna.crypto_core_ristretto255_from_string(
|
||||||
|
result.asByteArray(),
|
||||||
|
ctxEncoded?.asByteArray(),
|
||||||
|
msg.asByteArray(),
|
||||||
|
msg.size,
|
||||||
|
hashAlg.id
|
||||||
|
).ensureLibsodiumSuccess()
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = UByteArray(crypto_core_ristretto255_BYTES)
|
||||||
|
val ctxEncoded = ctx?.toCString()
|
||||||
|
|
||||||
|
sodiumJna.crypto_core_ristretto255_from_string_ro(
|
||||||
|
result.asByteArray(),
|
||||||
|
ctxEncoded?.asByteArray(),
|
||||||
|
msg.asByteArray(),
|
||||||
|
msg.size,
|
||||||
|
hashAlg.id
|
||||||
|
).ensureLibsodiumSuccess()
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).also {
|
actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).also {
|
||||||
sodiumJna.crypto_core_ristretto255_random(it.asByteArray())
|
sodiumJna.crypto_core_ristretto255_random(it.asByteArray())
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.ionspin.kotlin.crypto.util
|
||||||
|
|
||||||
|
fun String.toCString(): UByteArray {
|
||||||
|
val encoded = encodeToUByteArray()
|
||||||
|
val cStr = UByteArray(encoded.size + 1)
|
||||||
|
|
||||||
|
encoded.copyInto(cStr)
|
||||||
|
|
||||||
|
LibsodiumUtil.memzero(encoded)
|
||||||
|
|
||||||
|
return cStr
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package com.ionspin.kotlin.crypto.ed25519
|
package com.ionspin.kotlin.crypto.ed25519
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
|
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
|
||||||
|
import com.ionspin.kotlin.crypto.util.toCString
|
||||||
import com.ionspin.kotlin.crypto.util.toPtr
|
import com.ionspin.kotlin.crypto.util.toPtr
|
||||||
import kotlinx.cinterop.usePinned
|
import kotlinx.cinterop.usePinned
|
||||||
import libsodium.crypto_core_ed25519_add
|
import libsodium.crypto_core_ed25519_add
|
||||||
import libsodium.crypto_core_ed25519_from_hash
|
import libsodium.crypto_core_ed25519_from_string
|
||||||
import libsodium.crypto_core_ed25519_from_uniform
|
import libsodium.crypto_core_ed25519_from_uniform
|
||||||
import libsodium.crypto_core_ed25519_is_valid_point
|
import libsodium.crypto_core_ed25519_is_valid_point
|
||||||
import libsodium.crypto_core_ed25519_random
|
import libsodium.crypto_core_ed25519_random
|
||||||
@ -58,12 +59,53 @@ actual abstract class Ed25519LowLevel actual constructor() {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun encodedPointFromHash(hash: UByteArray): UByteArray {
|
actual fun encodedPointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
val result = UByteArray(crypto_core_ed25519_BYTES)
|
val result = UByteArray(crypto_core_ed25519_BYTES)
|
||||||
|
val ctxEncoded = ctx?.toCString()
|
||||||
|
|
||||||
result.usePinned { resultPinned ->
|
result.usePinned { resultPinned ->
|
||||||
hash.usePinned { hashPinned ->
|
msg.usePinned { msgPinned ->
|
||||||
crypto_core_ed25519_from_hash(resultPinned.toPtr(), hashPinned.toPtr())
|
if (ctxEncoded == null) {
|
||||||
|
crypto_core_ed25519_from_string(resultPinned.toPtr(), null, msgPinned.toPtr(), msg.size, hashAlg.id)
|
||||||
|
.ensureLibsodiumSuccess()
|
||||||
|
} else {
|
||||||
|
ctxEncoded.usePinned { ctxPinned ->
|
||||||
|
crypto_core_ed25519_from_string(
|
||||||
|
resultPinned.toPtr(),
|
||||||
|
ctxPinned.toPtr(),
|
||||||
|
msgPinned.toPtr(),
|
||||||
|
msg.size,
|
||||||
|
hashAlg.id
|
||||||
|
)
|
||||||
|
.ensureLibsodiumSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = UByteArray(crypto_core_ed25519_BYTES)
|
||||||
|
val ctxEncoded = ctx?.toCString()
|
||||||
|
|
||||||
|
result.usePinned { resultPinned ->
|
||||||
|
msg.usePinned { msgPinned ->
|
||||||
|
if (ctxEncoded == null) {
|
||||||
|
crypto_core_ed25519_from_string_ro(resultPinned.toPtr(), null, msgPinned.toPtr(), msg.size, hashAlg.id)
|
||||||
|
.ensureLibsodiumSuccess()
|
||||||
|
} else {
|
||||||
|
ctxEncoded.usePinned { ctxPinned ->
|
||||||
|
crypto_core_ed25519_from_string_ro(
|
||||||
|
resultPinned.toPtr(),
|
||||||
|
ctxPinned.toPtr(),
|
||||||
|
msgPinned.toPtr(),
|
||||||
|
msg.size,
|
||||||
|
hashAlg.id
|
||||||
|
).ensureLibsodiumSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package com.ionspin.kotlin.crypto.ristretto255
|
package com.ionspin.kotlin.crypto.ristretto255
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
|
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
|
||||||
|
import com.ionspin.kotlin.crypto.ed25519.HashToCurveAlgorithm
|
||||||
|
import com.ionspin.kotlin.crypto.util.toCString
|
||||||
import com.ionspin.kotlin.crypto.util.toPtr
|
import com.ionspin.kotlin.crypto.util.toPtr
|
||||||
import kotlinx.cinterop.usePinned
|
import kotlinx.cinterop.usePinned
|
||||||
import libsodium.crypto_core_ristretto255_add
|
import libsodium.crypto_core_ristretto255_add
|
||||||
import libsodium.crypto_core_ristretto255_from_hash
|
import libsodium.crypto_core_ristretto255_from_hash
|
||||||
|
import libsodium.crypto_core_ristretto255_from_string
|
||||||
|
import libsodium.crypto_core_ristretto255_from_string_ro
|
||||||
import libsodium.crypto_core_ristretto255_is_valid_point
|
import libsodium.crypto_core_ristretto255_is_valid_point
|
||||||
import libsodium.crypto_core_ristretto255_random
|
import libsodium.crypto_core_ristretto255_random
|
||||||
import libsodium.crypto_core_ristretto255_scalar_add
|
import libsodium.crypto_core_ristretto255_scalar_add
|
||||||
@ -67,6 +71,59 @@ actual abstract class Ristretto255LowLevel actual constructor() {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromString(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = UByteArray(crypto_core_ristretto255_BYTES)
|
||||||
|
val ctxEncoded = ctx?.toCString()
|
||||||
|
|
||||||
|
result.usePinned { resultPinned ->
|
||||||
|
msg.usePinned { msgPinned ->
|
||||||
|
if (ctxEncoded == null) {
|
||||||
|
crypto_core_ristretto255_from_string(resultPinned.toPtr(), null, msgPinned.toPtr(), msg.size, hashAlg.id)
|
||||||
|
.ensureLibsodiumSuccess()
|
||||||
|
} else {
|
||||||
|
ctxEncoded.usePinned { ctxPinned ->
|
||||||
|
crypto_core_ristretto255_from_string(
|
||||||
|
resultPinned.toPtr(),
|
||||||
|
ctxPinned.toPtr(),
|
||||||
|
msgPinned.toPtr(),
|
||||||
|
msg.size,
|
||||||
|
hashAlg.id
|
||||||
|
)
|
||||||
|
.ensureLibsodiumSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun encodedPointFromStringRo(ctx: String?, msg: UByteArray, hashAlg: HashToCurveAlgorithm): UByteArray {
|
||||||
|
val result = UByteArray(crypto_core_ristretto255_BYTES)
|
||||||
|
val ctxEncoded = ctx?.toCString()
|
||||||
|
|
||||||
|
result.usePinned { resultPinned ->
|
||||||
|
msg.usePinned { msgPinned ->
|
||||||
|
if (ctxEncoded == null) {
|
||||||
|
crypto_core_ristretto255_from_string_ro(resultPinned.toPtr(), null, msgPinned.toPtr(), msg.size, hashAlg.id)
|
||||||
|
.ensureLibsodiumSuccess()
|
||||||
|
} else {
|
||||||
|
ctxEncoded.usePinned { ctxPinned ->
|
||||||
|
crypto_core_ristretto255_from_string_ro(
|
||||||
|
resultPinned.toPtr(),
|
||||||
|
ctxPinned.toPtr(),
|
||||||
|
msgPinned.toPtr(),
|
||||||
|
msg.size,
|
||||||
|
hashAlg.id
|
||||||
|
).ensureLibsodiumSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).apply {
|
actual fun randomEncodedPoint(): UByteArray = UByteArray(crypto_core_ristretto255_BYTES).apply {
|
||||||
usePinned { crypto_core_ristretto255_random(it.toPtr()) }
|
usePinned { crypto_core_ristretto255_random(it.toPtr()) }
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import kotlinx.cinterop.CPointer
|
|||||||
import kotlinx.cinterop.Pinned
|
import kotlinx.cinterop.Pinned
|
||||||
import kotlinx.cinterop.UByteVar
|
import kotlinx.cinterop.UByteVar
|
||||||
import kotlinx.cinterop.addressOf
|
import kotlinx.cinterop.addressOf
|
||||||
import kotlinx.cinterop.toCPointer
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ugljesa Jovanovic
|
* Created by Ugljesa Jovanovic
|
||||||
@ -18,3 +17,14 @@ fun Pinned<UByteArray>.toPtr() : CPointer<UByteVar>? {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun String.toCString(): UByteArray {
|
||||||
|
val encoded = encodeToUByteArray()
|
||||||
|
val cStr = UByteArray(encoded.size + 1)
|
||||||
|
|
||||||
|
encoded.copyInto(cStr)
|
||||||
|
|
||||||
|
LibsodiumUtil.memzero(encoded)
|
||||||
|
|
||||||
|
return cStr
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user