Working sodium cinterop
This commit is contained in:
parent
3f7df6c651
commit
cc2f392bb7
@ -22,6 +22,7 @@ import org.gradle.api.tasks.testing.logging.TestLogging
|
|||||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||||
|
import org.jetbrains.kotlin.konan.library.konanCommonLibraryPath
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin(PluginsDeps.multiplatform)
|
kotlin(PluginsDeps.multiplatform)
|
||||||
@ -92,11 +93,16 @@ kotlin {
|
|||||||
compilations.getByName("main") {
|
compilations.getByName("main") {
|
||||||
val libsodiumCinterop by cinterops.creating {
|
val libsodiumCinterop by cinterops.creating {
|
||||||
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
|
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
|
||||||
|
// packageName("sodium")
|
||||||
|
// includeDirs.apply {
|
||||||
|
// allHeaders("/usr/include/sodium")
|
||||||
|
// header("/usr/include/sodium.h")
|
||||||
|
// }
|
||||||
|
// linkerOpts("-lsodium")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binaries {
|
binaries {
|
||||||
staticLib {
|
staticLib {
|
||||||
optimized = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +183,7 @@ kotlin {
|
|||||||
implementation(kotlin(Deps.Common.test))
|
implementation(kotlin(Deps.Common.test))
|
||||||
implementation(Deps.Common.coroutines)
|
implementation(Deps.Common.coroutines)
|
||||||
implementation(Deps.Common.kotlinBigNum)
|
implementation(Deps.Common.kotlinBigNum)
|
||||||
implementation(project(Deps.Common.apiProject))
|
api(project(Deps.Common.apiProject))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val commonTest by getting {
|
val commonTest by getting {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.ionspin.kotlin.crypto.hash.blake2b
|
package com.ionspin.kotlin.crypto.hash.blake2b
|
||||||
import interop.*
|
import interop.*
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
import libsodium.*
|
||||||
/**
|
/**
|
||||||
* Created by Ugljesa Jovanovic
|
* Created by Ugljesa Jovanovic
|
||||||
* ugljesa.jovanovic@ionspin.com
|
* ugljesa.jovanovic@ionspin.com
|
||||||
@ -9,8 +10,7 @@ import kotlinx.cinterop.*
|
|||||||
|
|
||||||
@ExperimentalUnsignedTypes
|
@ExperimentalUnsignedTypes
|
||||||
actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: Int) : Blake2b {
|
actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: Int) : Blake2b {
|
||||||
override val MAX_HASH_BYTES: Int
|
override val MAX_HASH_BYTES: Int = 1024
|
||||||
get() = TODO("not implemented yet")
|
|
||||||
|
|
||||||
override fun update(data: UByteArray) {
|
override fun update(data: UByteArray) {
|
||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
@ -21,7 +21,9 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun digest(): UByteArray {
|
override fun digest(): UByteArray {
|
||||||
TODO("not implemented yet")
|
val result = sodium_init()
|
||||||
|
println("Sodium init $result")
|
||||||
|
return ubyteArrayOf(0U)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun digestString(): String {
|
override fun digestString(): String {
|
||||||
|
@ -17,7 +17,7 @@ class Blake2bLinuxTest {
|
|||||||
@Test
|
@Test
|
||||||
fun testCinterop() {
|
fun testCinterop() {
|
||||||
val sodiumInitResult = sodium_init()
|
val sodiumInitResult = sodium_init()
|
||||||
// println("Sodium init $sodiumInitResult")
|
println("Sodium init $sodiumInitResult")
|
||||||
println("1")
|
println("1")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
headers = sodium.h
|
headers = sodium.h
|
||||||
headerFilter = sodium.h sodium/**
|
headerFilter = sodium.h sodium/**
|
||||||
staticLibraries = libsodium.a
|
staticLibraries = libsodium.a
|
||||||
libraryPaths = /usr/lib
|
libraryPaths = /home/ionspin/Projects/Future/sodiumWrapper/lib
|
||||||
compilerOpts = -Iinclude -I/usr/include
|
compilerOpts = -I/home/ionspin/Projects/Future/sodiumWrapper/include
|
||||||
linkerOpts = -L/usr/lib -lsodium
|
linkerOpts =
|
@ -107,7 +107,6 @@ kotlin {
|
|||||||
|
|
||||||
executable {
|
executable {
|
||||||
println("Optimized: $optimized")
|
println("Optimized: $optimized")
|
||||||
optimized = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,7 +187,7 @@ kotlin {
|
|||||||
implementation(kotlin(Deps.Common.test))
|
implementation(kotlin(Deps.Common.test))
|
||||||
implementation(Deps.Common.coroutines)
|
implementation(Deps.Common.coroutines)
|
||||||
implementation(Deps.Common.kotlinBigNum)
|
implementation(Deps.Common.kotlinBigNum)
|
||||||
implementation(project(":multiplatform-crypto"))
|
implementation(project(":multiplatform-crypto-delegated"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val commonTest by getting {
|
val commonTest by getting {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Pure
|
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegated
|
||||||
import com.ionspin.kotlin.crypto.keyderivation.argon2.ArgonType
|
|
||||||
import kotlin.time.ExperimentalTime
|
import kotlin.time.ExperimentalTime
|
||||||
import kotlin.time.measureTime
|
import kotlin.time.measureTime
|
||||||
|
|
||||||
@ -7,22 +6,7 @@ import kotlin.time.measureTime
|
|||||||
@ExperimentalStdlibApi
|
@ExperimentalStdlibApi
|
||||||
fun main() {
|
fun main() {
|
||||||
println("Test")
|
println("Test")
|
||||||
val argon2Instance = Argon2Pure(
|
// Blake
|
||||||
password = "Password",
|
val blake = Blake2bDelegated()
|
||||||
salt = "RandomSalt",
|
blake.digest()
|
||||||
parallelism = 1,
|
|
||||||
tagLength = 64U,
|
|
||||||
requestedMemorySize = 4096U,
|
|
||||||
numberOfIterations = 100,
|
|
||||||
key = "",
|
|
||||||
associatedData = "",
|
|
||||||
argonType = ArgonType.Argon2id
|
|
||||||
)
|
|
||||||
val time = measureTime {
|
|
||||||
val tag = argon2Instance.derive()
|
|
||||||
val tagString = tag.map { it.toString(16).padStart(2, '0') }.joinToString(separator = "")
|
|
||||||
val expectedTagString = "27c61b6538ef9f4a1250f8712cac09fc4329969295f9440249437d38c1617a005c2702d76a8a59e4cda2dfba48e1132261dacdfd31296945906992ea32f1d06e"
|
|
||||||
println("Tag: ${tagString}")
|
|
||||||
}
|
|
||||||
println("Time $time")
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user