Idea cinterop stopped working, again... fixed blake2b stateless segmentation

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-06-07 00:55:46 +02:00
1 parent d380863a29
commit 1be0470745
4 files changed
+32 -36

No files matched your search

+27 -23
View File
@@ -81,16 +81,6 @@ kotlin {
staticLib {
}
}
compilations.getByName("main") {
val libsodiumCinterop by cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-linux-x86-64/include/")
}
kotlinOptions.freeCompilerArgs = listOf(
"-include-binary", "${project.rootDir}/sodiumWrapper/static-linux-x86-64/lib/libsodium.a"
)
}
}
@@ -99,15 +89,6 @@ kotlin {
staticLib {
}
}
compilations.getByName("main") {
val libsodiumCinterop by cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-arm64/include/")
}
kotlinOptions.freeCompilerArgs = listOf(
"-include-binary", "${project.rootDir}/sodiumWrapper/static-arm64/lib/libsodium.a"
)
}
}
// Linux 32 is using target-sysroot-2-raspberrypi which is missing getrandom and explicit_bzero in stdlib
// so konanc can't build klib because getrandom missing will cause sodium_misuse()
@@ -296,8 +277,11 @@ kotlin {
//Set up shared source sets
//linux, linuxArm32Hfp, linuxArm64
val linux64Bit = setOf(
"linuxX64", "linuxArm64"
"linuxX64"
)
val linuxArm64Bit = setOf {
"linuxArm64"
}
val linux32Bit = setOf(
"" // "linuxArm32Hfp"
)
@@ -330,9 +314,29 @@ kotlin {
compilations.getByName("main") {
if (linux64Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(nativeMain)
compilations.getByName("main") {
val libsodiumCinterop by cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-linux-x86-64/include/")
}
kotlinOptions.freeCompilerArgs = listOf(
"-include-binary", "${project.rootDir}/sodiumWrapper/static-linux-x86-64/lib/libsodium.a"
)
}
}
if (linuxArm64Bit.contains(this@withType.name)) {
compilations.getByName("main") {
val libsodiumCinterop by cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-arm64/include/")
}
kotlinOptions.freeCompilerArgs = listOf(
"-include-binary", "${project.rootDir}/sodiumWrapper/static-arm64/lib/libsodium.a"
)
}
}
if (linux32Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(createWorkaround32bitNativeMainSourceSet(this@withType.name, nativeDependencies))
defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
}
if (macos64Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
@@ -351,7 +355,7 @@ kotlin {
}
if (ios32Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(createWorkaround32bitNativeMainSourceSet(this@withType.name, nativeDependencies))
defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
println("Setting ios cinterop for $this")
val libsodiumCinterop by cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
@@ -375,7 +379,7 @@ kotlin {
}
if (watchos32Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(createWorkaround32bitNativeMainSourceSet(this@withType.name, nativeDependencies))
defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
println("Setting ios cinterop for $this")
val libsodiumCinterop by cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
@@ -70,15 +70,16 @@ actual object Blake2bDelegatedStateless : Blake2bStateless {
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
val hashResult = UByteArray(MAX_HASH_BYTES)
val hashResultPinned = hashResult.pin()
crypto_generichash(
StableRef.create(hashResult).asCPointer().reinterpret(),
hashResultPinned.addressOf(0),
hashLength.convert(),
inputMessage.toCValues(),
inputMessage.size.convert(),
key.toCValues(),
key.size.convert() ?: 0UL
)
hashResultPinned.unpin()
return hashResult
}