Arm 64 build local configure for now, adding 32bit native sourceset, not connected yet
This commit is contained in:
parent
f4ddfe9cac
commit
fa080f28d8
3
.gitignore
vendored
3
.gitignore
vendored
@ -17,3 +17,6 @@ build/
|
||||
/sodiumWrapper/lib/
|
||||
/sodiumWrapper/ios-include/
|
||||
/sodiumWrapper/ios-lib/
|
||||
/sodiumWrapper/static-arm64/
|
||||
/sodiumWrapper/static-arm32/
|
||||
/sodiumWrapper/static-ios/
|
||||
|
@ -21,6 +21,7 @@ object Versions {
|
||||
val atomicfu = "0.14.3-SNAPSHOT" //NOTE: my linux arm32 and arm64 build
|
||||
val nodePlugin = "1.3.0"
|
||||
val dokkaPlugin = "0.9.18"
|
||||
val taskTreePlugin = "1.5"
|
||||
|
||||
val kotlinBigNumVersion = "0.1.6-SNAPSHOT"
|
||||
|
||||
@ -99,5 +100,6 @@ object PluginsDeps {
|
||||
val mavenPublish = "maven-publish"
|
||||
val signing = "signing"
|
||||
val dokka = "org.jetbrains.dokka"
|
||||
val taskTree = "com.dorongold.task-tree"
|
||||
}
|
||||
|
||||
|
@ -82,10 +82,6 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
runningOnLinuxArm64 {
|
||||
//Not supported in OFFICIAL coroutines at the moment
|
||||
linuxArm64() {
|
||||
binaries {
|
||||
@ -93,6 +89,12 @@ kotlin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
runningOnLinuxArm64 {
|
||||
|
||||
}
|
||||
|
||||
runningOnLinuxArm32 {
|
||||
|
@ -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))
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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")
|
||||
}
|
||||
}
|
@ -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() }
|
@ -104,19 +104,19 @@ kotlin {
|
||||
}
|
||||
}
|
||||
//Not supported in coroutines at the moment
|
||||
// linuxArm32Hfp() {
|
||||
// binaries {
|
||||
// staticLib {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
linuxArm32Hfp() {
|
||||
binaries {
|
||||
staticLib {
|
||||
}
|
||||
}
|
||||
}
|
||||
//Not supported in coroutines at the moment
|
||||
// linuxArm64() {
|
||||
// binaries {
|
||||
// staticLib {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
linuxArm64() {
|
||||
binaries {
|
||||
staticLib {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,5 +37,5 @@ rootProject.name = "KotlinMultiplatformCrypto"
|
||||
include("multiplatform-crypto-api")
|
||||
include("multiplatform-crypto")
|
||||
include("multiplatform-crypto-delegated")
|
||||
//include("sample")
|
||||
include("sample")
|
||||
|
||||
|
8
sodiumWrapper/configureLinuxArm64.sh
Executable file
8
sodiumWrapper/configureLinuxArm64.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#! /bin/sh
|
||||
export PREFIX="$(pwd)/libsodium-ios"
|
||||
export CC=/usr/bin/aarch64-linux-gnu-gcc
|
||||
export TARGET_ARCH=armv8-a
|
||||
export CFLAGS="-Os -march=${TARGET_ARCH}"
|
||||
cd libsodium
|
||||
./configure --prefix=$PREFIX --host=aarch64-linux-gnu-gcc --with-sysroot=/home/ionspin/.konan/dependencies/target-sysroot-1-linux-glibc-arm64/ "$@"
|
||||
|
Loading…
x
Reference in New Issue
Block a user