Remove 32bit native set, and use convert instead
This commit is contained in:
parent
907128fcfa
commit
459131f082
@ -293,21 +293,6 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val native32Main by creating {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
nativeDependencies(this)
|
||||
}
|
||||
}
|
||||
|
||||
val native32Test by creating {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Set up shared source sets
|
||||
//linux, linuxArm32Hfp, linuxArm64
|
||||
val linux64Bit = setOf(
|
||||
@ -406,13 +391,7 @@ kotlin {
|
||||
}
|
||||
compilations.getByName("test") {
|
||||
println("Setting native test dep for $this@withType.name")
|
||||
if (linux64Bit.contains(this@withType.name) ||
|
||||
macos64Bit.contains(this@withType.name) ||
|
||||
mingw64Bit.contains(this@withType.name)) {
|
||||
defaultSourceSet.dependsOn(nativeTest)
|
||||
} else {
|
||||
defaultSourceSet.dependsOn(native32Test)
|
||||
}
|
||||
defaultSourceSet.dependsOn(nativeTest)
|
||||
|
||||
|
||||
}
|
||||
@ -465,19 +444,7 @@ kotlin {
|
||||
kotlin.srcDir("src/nativeTest")
|
||||
}
|
||||
}
|
||||
//can still be useful for cinterop and debugging
|
||||
// val linuxArm32HfpMain by getting {
|
||||
// dependsOn(native32Main)
|
||||
// isRunningInIdea {
|
||||
// kotlin.srcDir("src/native32Main/kotlin")
|
||||
// }
|
||||
// }
|
||||
// val linuxArm32HfpTest by getting {
|
||||
// dependsOn(native32Test)
|
||||
// isRunningInIdea {
|
||||
// kotlin.srcDir("src/native32Test/kotlin")
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
runningOnMacos {
|
||||
|
@ -1,19 +0,0 @@
|
||||
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()
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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.toUInt())
|
||||
return UByteArray(amount) {
|
||||
array[it]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
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
|
||||
*/
|
||||
|
||||
|
||||
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.toUInt(),
|
||||
inputString.encodeToByteArray().toUByteArray().toCValues(),
|
||||
inputString.length.toULong(),
|
||||
key?.run { this.encodeToByteArray().toUByteArray().toCValues() },
|
||||
key?.length?.toUInt() ?: 0U
|
||||
)
|
||||
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.toUInt(),
|
||||
inputMessage.toCValues(),
|
||||
inputMessage.size.toULong(),
|
||||
key.toCValues(),
|
||||
key.size.toUInt() ?: 0U
|
||||
)
|
||||
println("HashPointer: ${hashResult.toHexString()}")
|
||||
println(hashResult.toHexString())
|
||||
return hashResult
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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")
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* 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() }
|
@ -18,14 +18,16 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
|
||||
init {
|
||||
println("Initializing libsodium hash")
|
||||
requestedHashLength = hashLength
|
||||
println("Size ${crypto_generichash_state.size}")
|
||||
println("Align ${crypto_generichash_state.align}")
|
||||
state = nativeHeap.alloc()
|
||||
println("allocated state")
|
||||
crypto_generichash_init(state.ptr, key?.run { this.toUByteArray().toCValues() }, key?.size?.toULong() ?: 0UL, hashLength.toULong())
|
||||
crypto_generichash_init(state.ptr, key?.run { this.toUByteArray().toCValues() }, key?.size?.toULong() ?: 0UL, hashLength.convert())
|
||||
println("Initialized libsodium hash")
|
||||
}
|
||||
|
||||
override fun update(data: UByteArray) {
|
||||
crypto_generichash_update(state.ptr, data.toCValues(), data.size.toULong())
|
||||
crypto_generichash_update(state.ptr, data.toCValues(), data.size.convert())
|
||||
}
|
||||
|
||||
override fun update(data: String) {
|
||||
@ -38,6 +40,7 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
|
||||
val hashResultPinned = hashResult.pin()
|
||||
val result = crypto_generichash_final(state.ptr, hashResultPinned.addressOf(0), requestedHashLength.toULong())
|
||||
println("HashPointer: ${hashResult.toHexString()}")
|
||||
|
||||
return hashResult
|
||||
// val inputString = "test"
|
||||
// val hashLength = 64
|
||||
|
@ -1,15 +1,11 @@
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegated
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bStateless
|
||||
import com.ionspin.kotlin.crypto.sample.Sample
|
||||
import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.measureTime
|
||||
|
||||
@ExperimentalTime
|
||||
|
||||
fun main() {
|
||||
println("Test")
|
||||
// Blake
|
||||
val blake = Blake2bDelegated()
|
||||
blake.digest()
|
||||
println("Result: ${Blake2bStateless.digest("test")}")
|
||||
|
||||
Sample.runSample()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user