WIP: Remove *_from_string functions as they're not yet part of a libsodium release

This commit is contained in:
Johannes Leupold committed 2024-08-14 12:11:20 +02:00
1 parent 9a4a776bbd
commit 6d5b2ba6e1
12 files changed
-277

No files matched your search

@@ -1309,22 +1309,6 @@ interface JnaLibsodiumInterface : Library {
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_sub(r: ByteArray, p: ByteArray, q: ByteArray): Int
@@ -1359,10 +1343,6 @@ interface JnaLibsodiumInterface : Library {
fun crypto_core_ed25519_random(p: ByteArray)
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_add(r: ByteArray, p: ByteArray, q: ByteArray): Int
@@ -2,7 +2,6 @@ package com.ionspin.kotlin.crypto.ed25519
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
import com.ionspin.kotlin.crypto.util.toCString
actual abstract class Ed25519LowLevel actual constructor() {
actual fun isValidPoint(encoded: UByteArray): Boolean =
@@ -26,36 +25,6 @@ actual abstract class Ed25519LowLevel actual constructor() {
return result
}
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_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
}
actual fun encodedPointFromUniform(uniform: UByteArray): UByteArray {
val result = UByteArray(crypto_core_ed25519_BYTES)
@@ -2,8 +2,6 @@ package com.ionspin.kotlin.crypto.ristretto255
import com.ionspin.kotlin.crypto.GeneralLibsodiumException.Companion.ensureLibsodiumSuccess
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
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 =
@@ -35,36 +33,6 @@ 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())
}
@@ -1,12 +0,0 @@
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
}