From 63f90aa9155a6b7b11651517f7eaa64339c866f0 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Sat, 6 Jun 2020 15:55:42 +0200 Subject: [PATCH] Workround for invalid aligment when using nativeHeap alloc --- .../com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt index b52aea0..31a8440 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt @@ -1,7 +1,6 @@ package com.ionspin.kotlin.crypto.hash.blake2b import com.ionspin.kotlin.crypto.util.toHexString import kotlinx.cinterop.* -import kotlinx.cinterop.nativeHeap.alloc import libsodium.* /** * Created by Ugljesa Jovanovic @@ -20,7 +19,7 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I requestedHashLength = hashLength println("Size ${crypto_generichash_state.size}") println("Align ${crypto_generichash_state.align}") - state = nativeHeap.alloc() + state = nativeHeap.alloc(crypto_generichash_state.size, 1).reinterpret() println("allocated state") crypto_generichash_init(state.ptr, key?.run { this.toUByteArray().toCValues() }, key?.size?.convert() ?: 0UL, hashLength.convert()) println("Initialized libsodium hash")