Arm 64 build local configure for now, adding 32bit native sourceset, not connected yet
This commit is contained in:
1 parent
f4ddfe9cac
commit
fa080f28d8
12 files changed
+243
-30
No files matched your search
@@ -27,7 +27,7 @@ plugins {
|
||||
id(PluginsDeps.signing)
|
||||
id(PluginsDeps.node) version Versions.nodePlugin
|
||||
id(PluginsDeps.dokka) version Versions.dokkaPlugin
|
||||
id("com.dorongold.task-tree") version "1.5"
|
||||
id(PluginsDeps.taskTree) version Versions.taskTreePlugin
|
||||
}
|
||||
|
||||
val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
@@ -84,12 +84,6 @@ kotlin {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Not supported in OFFICIAL coroutines at the moment (we're running a custom build)
|
||||
runningOnLinuxArm64 {
|
||||
println("Configuring Linux Arm 64 targets")
|
||||
linuxArm64() {
|
||||
binaries {
|
||||
staticLib {
|
||||
@@ -97,6 +91,14 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Not supported in OFFICIAL coroutines at the moment (we're running a custom build)
|
||||
runningOnLinuxArm64 {
|
||||
println("Configuring Linux Arm 64 targets")
|
||||
|
||||
}
|
||||
|
||||
runningOnLinuxArm32 {
|
||||
@@ -235,13 +237,23 @@ kotlin {
|
||||
if ((this@withType.name.contains("ios") || this@withType.name.contains("tvos") || this@withType.name.contains("watchos")).not()) {
|
||||
defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
|
||||
println("Setting cinterop for $this")
|
||||
val libsodiumCinterop by cinterops.creating {
|
||||
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
|
||||
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/include/")
|
||||
if (this@withType.name.contains("arm64")) {
|
||||
val libsodiumCinterop by cinterops.creating {
|
||||
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
|
||||
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/libsodium-arm64/include/")
|
||||
}
|
||||
kotlinOptions.freeCompilerArgs = listOf(
|
||||
"-include-binary", "${project.rootDir}/sodiumWrapper/libsodium-arm64/lib/libsodium.a"
|
||||
)
|
||||
} else {
|
||||
val libsodiumCinterop by cinterops.creating {
|
||||
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
|
||||
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/include/")
|
||||
}
|
||||
kotlinOptions.freeCompilerArgs = listOf(
|
||||
"-include-binary", "${project.rootDir}/sodiumWrapper/lib/libsodium.a"
|
||||
)
|
||||
}
|
||||
kotlinOptions.freeCompilerArgs = listOf(
|
||||
"-include-binary", "${project.rootDir}/sodiumWrapper/lib/libsodium.a"
|
||||
)
|
||||
}
|
||||
if (this@withType.name.contains("ios") || this@withType.name.contains("tvos") || this@withType.name.contains("watchos")) {
|
||||
defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.ionspin.kotlin.crypto
|
||||
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import libsodium.sodium_init
|
||||
|
||||
actual object Initializer {
|
||||
actual suspend fun initialize() {
|
||||
GlobalScope.launch {
|
||||
sodium_init()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
actual fun initializeWithCallback(done: () -> Unit) {
|
||||
sodium_init()
|
||||
done()
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2019 Ugljesa Jovanovic
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.ionspin.kotlin.crypto
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import libsodium.randombytes_buf
|
||||
import platform.posix.*
|
||||
//import libsod
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 21-Sep-2019
|
||||
*/
|
||||
actual object SRNG {
|
||||
@Suppress("EXPERIMENTAL_UNSIGNED_LITERALS")
|
||||
actual fun getRandomBytes(amount: Int): UByteArray {
|
||||
memScoped {
|
||||
val array = allocArray<UByteVar>(amount)
|
||||
randombytes_buf(array, amount.toULong())
|
||||
return UByteArray(amount) {
|
||||
array[it]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.ionspin.kotlin.crypto.hash.blake2b
|
||||
import com.ionspin.kotlin.crypto.util.toHexString
|
||||
import kotlinx.cinterop.*
|
||||
import libsodium.*
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: Int) : Blake2b {
|
||||
override val MAX_HASH_BYTES: Int = 64
|
||||
|
||||
override fun update(data: UByteArray) {
|
||||
TODO("not implemented yet")
|
||||
}
|
||||
|
||||
override fun update(data: String) {
|
||||
TODO("not implemented yet")
|
||||
}
|
||||
|
||||
override fun digest(): UByteArray {
|
||||
val result = sodium_init()
|
||||
println("Sodium init $result")
|
||||
return ubyteArrayOf(0U)
|
||||
}
|
||||
|
||||
override fun digestString(): String {
|
||||
TODO("not implemented yet")
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS")
|
||||
actual object Blake2bStateless : Blake2bStatelessInterface {
|
||||
override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray {
|
||||
val hashResult = UByteArray(MAX_HASH_BYTES)
|
||||
val hashResultPinned = hashResult.pin()
|
||||
crypto_generichash(
|
||||
hashResultPinned.addressOf(0),
|
||||
hashLength.toULong(),
|
||||
inputString.encodeToByteArray().toUByteArray().toCValues(),
|
||||
inputString.length.toULong(),
|
||||
key?.run { this.encodeToByteArray().toUByteArray().toCValues() },
|
||||
key?.length?.toULong() ?: 0UL
|
||||
)
|
||||
println("HashPointer: ${hashResult.toHexString()}")
|
||||
println(hashResult.toHexString())
|
||||
return hashResult
|
||||
}
|
||||
|
||||
override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
|
||||
val hashResult = UByteArray(MAX_HASH_BYTES)
|
||||
|
||||
crypto_generichash(
|
||||
StableRef.create(hashResult).asCPointer().reinterpret(),
|
||||
hashLength.toULong(),
|
||||
inputMessage.toCValues(),
|
||||
inputMessage.size.toULong(),
|
||||
key.toCValues(),
|
||||
key.size.toULong() ?: 0UL
|
||||
)
|
||||
println("HashPointer: ${hashResult.toHexString()}")
|
||||
println(hashResult.toHexString())
|
||||
return hashResult
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.ionspin.kotlin.crypto.hash.blake2b
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 24-May-2020
|
||||
*/
|
||||
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bStateless
|
||||
import com.ionspin.kotlin.crypto.util.testBlocking
|
||||
import interop.*
|
||||
import kotlinx.cinterop.*
|
||||
import libsodium.*
|
||||
|
||||
import kotlin.test.Test
|
||||
|
||||
class Blake2bLinuxTest {
|
||||
|
||||
@Test
|
||||
fun testCinterop() {
|
||||
val sodiumInitResult = sodium_init()
|
||||
println("Sodium init $sodiumInitResult")
|
||||
println("1")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBlake2BSodiumInterop() = testBlocking {
|
||||
Blake2bStateless.digest("test")
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2019 Ugljesa Jovanovic
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.ionspin.kotlin.crypto.util
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 20-Jul-2019
|
||||
*/
|
||||
actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() }
|
||||
Reference in new issue
Block a user