diff --git a/gradle.properties b/gradle.properties index 17a1efc..f90245d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ org.gradle.parallel=true kotlin.code.style=official -kotlin.js.compiler=both +kotlin.js.compiler=ir kotlin.mpp.enableGranularSourceSetsMetadata=true org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=4096m diff --git a/multiplatform-crypto/build.gradle.kts b/multiplatform-crypto/build.gradle.kts index 9ac7dad..0017c04 100644 --- a/multiplatform-crypto/build.gradle.kts +++ b/multiplatform-crypto/build.gradle.kts @@ -250,13 +250,13 @@ kotlin { val jsMain by getting { dependencies { implementation(kotlin(Deps.Js.stdLib)) - implementation(kotlin(Deps.Js.test)) implementation(Deps.Js.coroutines) } } val jsTest by getting { dependencies { - implementation(kotlin("test-js")) + implementation(Deps.Js.coroutines) + implementation(kotlin(Deps.Js.test)) } } val linuxMain by getting { @@ -400,21 +400,20 @@ tasks { } } - val jsIrNodeTest by getting(KotlinJsTest::class) { - + val jsNodeTest by getting(KotlinJsTest::class) { testLogging { events("PASSED", "FAILED", "SKIPPED") showStandardStreams = true } } - val legacyjsNodeTest by getting(KotlinJsTest::class) { - - testLogging { - events("PASSED", "FAILED", "SKIPPED") - showStandardStreams = true - } - } +// val legacyjsNodeTest by getting(KotlinJsTest::class) { +// +// testLogging { +// events("PASSED", "FAILED", "SKIPPED") +// showStandardStreams = true +// } +// } // val jsIrBrowserTest by getting(KotlinJsTest::class) { // testLogging { diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt index b294f51..6ec4e24 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt @@ -44,6 +44,13 @@ data class SegmentPosition( val slice: Int ) +data class ArgonResult( + val hashBytes: Array +) { + val hashString by lazy { hashBytes.map { it.toString(16).padStart(2, '0') }.joinToString(separator = "") } + +} + @ExperimentalStdlibApi class Argon2( private val password: Array, @@ -57,6 +64,17 @@ class Argon2( private val argonType: ArgonType = ArgonType.Argon2id ) : KeyDerivationFunction { + companion object { + fun derive( + password: String, + parallelism: Int = 16, + memory : Int = 4096, + numberOfIterations : Int = 10 + ) : ArgonResult { + return ArgonResult(emptyArray()) + } + } + constructor( password: String, salt: String = "", diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt new file mode 100644 index 0000000..d3d7ee9 --- /dev/null +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt @@ -0,0 +1,38 @@ +/* + * 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.parallelization + +import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2 +import kotlinx.coroutines.* +import kotlin.coroutines.CoroutineContext +import kotlin.time.ExperimentalTime +import kotlin.time.measureTime + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 17-May-2020 + */ +@ExperimentalTime +object Coroutines14 { + fun argonParallel() : Array { + val argon = Argon2() + argon + println("Placeholder") + return emptyArray() + } +} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/parallelization/CoroutinesDebugTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/parallelization/CoroutinesDebugTest.kt new file mode 100644 index 0000000..96ae49a --- /dev/null +++ b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/parallelization/CoroutinesDebugTest.kt @@ -0,0 +1,41 @@ +/* + * 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.parallelization + +import com.ionspin.kotlin.crypto.util.testBlocking +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlin.test.Test +import kotlin.time.ExperimentalTime + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 17-May-2020 + */ +@ExperimentalTime +class CoroutinesDebugTest { + + @Test + fun debugTest() = testBlocking { + GlobalScope.launch { + Coroutines14.argonParallel() + + } + + } +} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt index 8d7b658..ab0598d 100644 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt +++ b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt @@ -23,4 +23,4 @@ import kotlinx.coroutines.CoroutineScope * ugljesa.jovanovic@ionspin.com * on 20-Jul-2019 */ -expect fun testBlocking(block : suspend (scope : CoroutineScope) -> Unit) \ No newline at end of file +expect fun testBlocking(block : suspend () -> Unit) \ No newline at end of file diff --git a/multiplatform-crypto/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt index ff8b494..5d6330e 100644 --- a/multiplatform-crypto/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ b/multiplatform-crypto/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt @@ -16,6 +16,8 @@ package com.ionspin.kotlin.crypto +import kotlin.browser.window + /** * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com @@ -25,15 +27,7 @@ actual object SRNG { var counter = 0 @ExperimentalUnsignedTypes actual fun getRandomBytes(amount: Int): Array { - val runningOnNode = js( - "var isNode = false;\n" + - "if (typeof window === 'undefined') {\n" + - " isNode = true;\n" + - " } else {\n" + - " isNode = false;\n" + - " }\n" + - "return isNode;" - ) + val runningOnNode = jsTypeOf(window) == "undefined" val randomBytes = if (runningOnNode) { js("require('crypto')").randomBytes(amount).toJSON().data } else { diff --git a/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt index 8dcc985..2df4151 100644 --- a/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ b/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt @@ -16,13 +16,13 @@ package com.ionspin.kotlin.crypto.util -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.promise + /** * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com * on 20-Jul-2019 */ -actual fun testBlocking(block: suspend (scope: CoroutineScope) -> Unit) : dynamic = GlobalScope.promise { block(this) } \ No newline at end of file +actual fun testBlocking(block: suspend ()-> Unit) : dynamic = GlobalScope.promise { block() } \ No newline at end of file diff --git a/multiplatform-crypto/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt index 328fcc4..8fb509a 100644 --- a/multiplatform-crypto/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ b/multiplatform-crypto/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt @@ -24,4 +24,4 @@ import kotlinx.coroutines.runBlocking * ugljesa.jovanovic@ionspin.com * on 20-Jul-2019 */ -actual fun testBlocking(block: suspend (scope: CoroutineScope) -> Unit) = runBlocking { block(this) } \ No newline at end of file +actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() } \ No newline at end of file diff --git a/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt b/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt index 328fcc4..8fb509a 100644 --- a/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt +++ b/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/crypto/util/testBlocking.kt @@ -24,4 +24,4 @@ import kotlinx.coroutines.runBlocking * ugljesa.jovanovic@ionspin.com * on 20-Jul-2019 */ -actual fun testBlocking(block: suspend (scope: CoroutineScope) -> Unit) = runBlocking { block(this) } \ No newline at end of file +actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() } \ No newline at end of file