Add native parameter pining
This commit is contained in:
1 parent
97c631ecb7
commit
a972b022d3
2 files changed
+87
-20
No files matched your search
+17
-9
@@ -2,7 +2,9 @@ package debug.test
|
||||
|
||||
import kotlin.Int
|
||||
import kotlin.UByteArray
|
||||
import kotlinx.cinterop.addressOf
|
||||
import kotlinx.cinterop.convert
|
||||
import kotlinx.cinterop.pin
|
||||
import kotlinx.cinterop.ptr
|
||||
import kotlinx.cinterop.toCValues
|
||||
import libsodium.crypto_generichash_blake2b_state
|
||||
@@ -22,13 +24,15 @@ actual class Crypto {
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
|
||||
println("Debug")
|
||||
libsodium.crypto_hash_sha256_update(state.ptr, input.toCValues(), input.size.convert())
|
||||
val pinnedInput = input.pin()
|
||||
libsodium.crypto_hash_sha256_update(state.ptr, pinnedInput.addressOf(0), input.size.convert())
|
||||
pinnedInput.unpin()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha256_final(state: Sha256State, out: UByteArray) {
|
||||
println("Debug")
|
||||
libsodium.crypto_hash_sha256_final(state.ptr, out.toCValues())
|
||||
val pinnedOut = out.pin()
|
||||
libsodium.crypto_hash_sha256_final(state.ptr, pinnedOut.addressOf(0))
|
||||
pinnedOut.unpin()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_init(state: Sha512State): Int {
|
||||
@@ -37,13 +41,15 @@ actual class Crypto {
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
|
||||
println("Debug")
|
||||
libsodium.crypto_hash_sha512_update(state.ptr, input.toCValues(), input.size.convert())
|
||||
val pinnedInput = input.pin()
|
||||
libsodium.crypto_hash_sha512_update(state.ptr, pinnedInput.addressOf(0), input.size.convert())
|
||||
pinnedInput.unpin()
|
||||
}
|
||||
|
||||
actual fun crypto_hash_sha512_final(state: Sha512State, out: UByteArray) {
|
||||
println("Debug")
|
||||
libsodium.crypto_hash_sha512_final(state.ptr, out.toCValues())
|
||||
val pinnedOut = out.pin()
|
||||
libsodium.crypto_hash_sha512_final(state.ptr, pinnedOut.addressOf(0))
|
||||
pinnedOut.unpin()
|
||||
}
|
||||
|
||||
actual fun crypto_generichash_init(
|
||||
@@ -51,8 +57,10 @@ actual class Crypto {
|
||||
key: UByteArray,
|
||||
outlen: Int
|
||||
): Int {
|
||||
val pinnedKey = key.pin()
|
||||
println("Debug")
|
||||
return libsodium.crypto_generichash_init(state.ptr, key.toCValues(), key.size.convert(),
|
||||
return libsodium.crypto_generichash_init(state.ptr, pinnedKey.addressOf(0), key.size.convert(),
|
||||
outlen.convert())
|
||||
pinnedKey.unpin()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user