Progress on native generator

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-01 18:07:12 +02:00
1 parent c975bdb248
commit 97c631ecb7
10 files changed
+371 -49

No files matched your search

@@ -5,13 +5,25 @@ import kotlin.UByteArray
expect class Sha256State
expect class Hashing {
fun crypto_hash_sha256_init(state: Sha256State): Int
}
expect class Sha512State
expect class GenericHashState
expect class Crypto {
fun crypto_hash_sha256_init(state: Sha256State): Int
fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray)
fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray)
fun crypto_hash_sha512_init(state: Sha512State): Int
fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray)
fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray)
expect class GenericHash {
fun crypto_generichash_init(
state: UByteArray,
state: GenericHashState,
key: UByteArray,
outlen: Int
): Int
@@ -1,5 +1,6 @@
package debug.test
import ByteArray
import com.goterl.lazycode.lazysodium.SodiumJava
import com.goterl.lazycode.lazysodium.interfaces.Hash
import kotlin.Int
@@ -9,20 +10,47 @@ val sodium: SodiumJava = SodiumJava()
actual typealias Sha256State = Hash.State256
actual class Hashing {
actual typealias Sha512State = Hash.State512
actual typealias GenericHashState = ByteArray
actual class Crypto {
actual fun crypto_hash_sha256_init(state: Sha256State): Int {
println("Debug")
return sodium.crypto_hash_sha256_init(state)
}
}
actual class GenericHash {
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
println("Debug")
sodium.crypto_hash_sha256_update(state, input.asByteArray(), input.size.toLong())
}
actual fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray) {
println("Debug")
sodium.crypto_hash_sha256_final(state, out.asByteArray())
}
actual fun crypto_hash_sha512_init(state: Sha512State): Int {
println("Debug")
return sodium.crypto_hash_sha512_init(state)
}
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
println("Debug")
sodium.crypto_hash_sha512_update(state, input.asByteArray(), input.size.toLong())
}
actual fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray) {
println("Debug")
sodium.crypto_hash_sha512_final(state, out.asByteArray())
}
actual fun crypto_generichash_init(
state: UByteArray,
state: GenericHashState,
key: UByteArray,
outlen: Int
): Int {
println("Debug")
return sodium.crypto_generichash_init(state.asByteArray(), key.asByteArray(), key.size, outlen)
return sodium.crypto_generichash_init(state, key.asByteArray(), key.size, outlen)
}
}
@@ -0,0 +1,58 @@
package debug.test
import kotlin.Int
import kotlin.UByteArray
import kotlinx.cinterop.convert
import kotlinx.cinterop.ptr
import kotlinx.cinterop.toCValues
import libsodium.crypto_generichash_blake2b_state
import libsodium.crypto_hash_sha256_state
import libsodium.crypto_hash_sha512_state
actual typealias Sha256State = crypto_hash_sha256_state
actual typealias Sha512State = crypto_hash_sha512_state
actual typealias GenericHashState = crypto_generichash_blake2b_state
actual class Crypto {
actual fun crypto_hash_sha256_init(state: Sha256State): Int {
println("Debug")
return libsodium.crypto_hash_sha256_init(state.ptr)
}
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
println("Debug")
libsodium.crypto_hash_sha256_update(state.ptr, input.toCValues(), input.size.convert())
}
actual fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray) {
println("Debug")
libsodium.crypto_hash_sha256_final(state.ptr, out.toCValues())
}
actual fun crypto_hash_sha512_init(state: Sha512State): Int {
println("Debug")
return libsodium.crypto_hash_sha512_init(state.ptr)
}
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
println("Debug")
libsodium.crypto_hash_sha512_update(state.ptr, input.toCValues(), input.size.convert())
}
actual fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray) {
println("Debug")
libsodium.crypto_hash_sha512_final(state.ptr, out.toCValues())
}
actual fun crypto_generichash_init(
state: GenericHashState,
key: UByteArray,
outlen: Int
): Int {
println("Debug")
return libsodium.crypto_generichash_init(state.ptr, key.toCValues(), key.size.convert(),
outlen.convert())
}
}
@@ -1,5 +0,0 @@
package debug.test
import libsodium.crypto_hash_sha256_state
actual typealias Sha256State = crypto_hash_sha256_state