Parallelism cleanup and preaparations

This commit is contained in:
Ugljesa Jovanovic 2020-05-18 23:45:24 +02:00 committed by Ugljesa Jovanovic
parent aaaa5c176b
commit 799a9bb74e
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
10 changed files with 116 additions and 26 deletions

View File

@ -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

View File

@ -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 {

View File

@ -44,6 +44,13 @@ data class SegmentPosition(
val slice: Int
)
data class ArgonResult(
val hashBytes: Array<UByte>
) {
val hashString by lazy { hashBytes.map { it.toString(16).padStart(2, '0') }.joinToString(separator = "") }
}
@ExperimentalStdlibApi
class Argon2(
private val password: Array<UByte>,
@ -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 = "",

View File

@ -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<UByte> {
val argon = Argon2()
argon
println("Placeholder")
return emptyArray()
}
}

View File

@ -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()
}
}
}

View File

@ -23,4 +23,4 @@ import kotlinx.coroutines.CoroutineScope
* ugljesa.jovanovic@ionspin.com
* on 20-Jul-2019
*/
expect fun testBlocking(block : suspend (scope : CoroutineScope) -> Unit)
expect fun testBlocking(block : suspend () -> Unit)

View File

@ -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<UByte> {
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 {

View File

@ -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) }
actual fun testBlocking(block: suspend ()-> Unit) : dynamic = GlobalScope.promise { block() }

View File

@ -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) }
actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() }

View File

@ -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) }
actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() }