WIP: Fix build/test issues

This commit is contained in:
Johannes Leupold committed 2024-08-14 11:47:29 +02:00
1 parent 338c1f0012
commit 9a4a776bbd
14 files changed
+1378 -1152

No files matched your search

@@ -2,7 +2,7 @@ package com.ionspin.kotlin.crypto.ed25519
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
import kotlin.UByteArray
import com.ionspin.kotlin.crypto.util.toCString
actual abstract class Ed25519LowLevel actual constructor() {
actual fun isValidPoint(encoded: UByteArray): Boolean =
@@ -26,10 +26,32 @@ actual abstract class Ed25519LowLevel actual constructor() {
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 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
}
@@ -2,7 +2,8 @@ package com.ionspin.kotlin.crypto.ristretto255
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
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 fun isValidPoint(encoded: UByteArray): Boolean =
@@ -34,6 +35,36 @@ actual abstract class Ristretto255LowLevel actual constructor() {
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 {
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
}