Workround for invalid aligment when using nativeHeap alloc

This commit is contained in:
Ugljesa Jovanovic 2020-06-06 15:55:42 +02:00 committed by Ugljesa Jovanovic
parent f6458a893d
commit 63f90aa915
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F

View File

@ -1,7 +1,6 @@
package com.ionspin.kotlin.crypto.hash.blake2b package com.ionspin.kotlin.crypto.hash.blake2b
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import kotlinx.cinterop.* import kotlinx.cinterop.*
import kotlinx.cinterop.nativeHeap.alloc
import libsodium.* import libsodium.*
/** /**
* Created by Ugljesa Jovanovic * Created by Ugljesa Jovanovic
@ -20,7 +19,7 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
requestedHashLength = hashLength requestedHashLength = hashLength
println("Size ${crypto_generichash_state.size}") println("Size ${crypto_generichash_state.size}")
println("Align ${crypto_generichash_state.align}") println("Align ${crypto_generichash_state.align}")
state = nativeHeap.alloc() state = nativeHeap.alloc(crypto_generichash_state.size, 1).reinterpret()
println("allocated state") println("allocated state")
crypto_generichash_init(state.ptr, key?.run { this.toUByteArray().toCValues() }, key?.size?.convert() ?: 0UL, hashLength.convert()) crypto_generichash_init(state.ptr, key?.run { this.toUByteArray().toCValues() }, key?.size?.convert() ?: 0UL, hashLength.convert())
println("Initialized libsodium hash") println("Initialized libsodium hash")