Parallelism cleanup and preaparations
This commit is contained in:
1 parent
aaaa5c176b
commit
799a9bb74e
10 files changed
+116
-26
No files matched your search
+18
@@ -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 = "",
|
||||
|
||||
+38
@@ -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()
|
||||
}
|
||||
}
|
||||
+41
@@ -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()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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)
|
||||
@@ -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 {
|
||||
|
||||
+2
-2
@@ -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() }
|
||||
+1
-1
@@ -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() }
|
||||
+1
-1
@@ -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() }
|
||||
Reference in new issue
Block a user