Remove coroutines

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-07-05 19:40:22 +02:00
1 parent 8625002ea4
commit 71ec5b7585
24 files changed
+123 -237

No files matched your search

@@ -131,7 +131,6 @@ kotlin {
}
//Not supported in OFFICIAL coroutines at the moment (we're running a custom build)
runningOnLinuxArm64 {
println("Configuring Linux Arm 64 targets")
@@ -249,7 +248,6 @@ kotlin {
dependencies {
implementation(kotlin(Deps.Common.stdLib))
implementation(kotlin(Deps.Common.test))
implementation(Deps.Common.coroutines)
implementation(Deps.Common.kotlinBigNum)
api(project(Deps.Common.apiProject))
}
@@ -262,7 +260,6 @@ kotlin {
}
val nativeDependencies = independentDependencyBlock {
implementation(Deps.Native.coroutines)
}
val nativeMain by creating {
@@ -281,7 +278,6 @@ kotlin {
kotlin.setSrcDirs(emptySet<String>())
}
dependencies {
implementation(Deps.Native.coroutines)
}
}
@@ -420,7 +416,6 @@ kotlin {
implementation(kotlin(Deps.Jvm.stdLib))
implementation(kotlin(Deps.Jvm.test))
implementation(kotlin(Deps.Jvm.testJUnit))
implementation(Deps.Jvm.coroutinesCore)
//lazysodium
implementation(Deps.Jvm.Delegated.lazysodium)
@@ -431,20 +426,17 @@ kotlin {
dependencies {
implementation(kotlin(Deps.Jvm.test))
implementation(kotlin(Deps.Jvm.testJUnit))
implementation(Deps.Jvm.coroutinesTest)
implementation(kotlin(Deps.Jvm.reflection))
}
}
val jsMain by getting {
dependencies {
implementation(kotlin(Deps.Js.stdLib))
implementation(Deps.Js.coroutines)
implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second))
}
}
val jsTest by getting {
dependencies {
implementation(Deps.Js.coroutines)
implementation(kotlin(Deps.Js.test))
implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second))
}
@@ -164,7 +164,8 @@ object Crypto {
}
override fun createMultipartDecryptor(key: SymmetricKey, header: MultipartEncryptionHeader) : MultipartAuthenticatedDecryption {
val decryptor = XChaCha20Poly1305Delegated(key.value, header.nonce)
val decryptor = XChaCha20Poly1305Delegated()
decryptor.initializeForDecryption(key.value, header.nonce)
return MultipartAuthenticatedDecryptor(decryptor)
}
@@ -174,8 +175,11 @@ object Crypto {
class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKey) : MultipartAuthenticatedEncryption {
val header = MultipartEncryptionHeader(SRNG.getRandomBytes(24))
val primitive = XChaCha20Poly1305Delegated(key.value, header.nonce)
val header : MultipartEncryptionHeader
val primitive = XChaCha20Poly1305Delegated()
init {
header = MultipartEncryptionHeader(primitive.initializeForEncryption(key.value))
}
override fun startEncryption(): MultipartEncryptionHeader {
return header
@@ -6,13 +6,14 @@ package com.ionspin.kotlin.crypto.authenticated
* ugljesa.jovanovic@ionspin.com
* on 14-Jun-2020
*/
expect class XChaCha20Poly1305Delegated constructor(key: UByteArray, nonce: UByteArray) {
internal constructor(key: UByteArray, nonce: UByteArray, testState : UByteArray, testHeader: UByteArray)
expect class XChaCha20Poly1305Delegated internal constructor() {
internal constructor(key: UByteArray, testState : UByteArray, testHeader: UByteArray)
companion object {
fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, additionalData: UByteArray) : UByteArray
fun decrypt(key: UByteArray, nonce: UByteArray, ciphertext: UByteArray, additionalData: UByteArray) : UByteArray
}
fun initializeForEncryption(key: UByteArray) : UByteArray
fun initializeForDecryption(key: UByteArray, header: UByteArray)
fun encrypt(data: UByteArray, additionalData: UByteArray = ubyteArrayOf()) : UByteArray
fun decrypt(data: UByteArray, additionalData: UByteArray = ubyteArrayOf()) : UByteArray
@@ -209,7 +209,7 @@ class XChaCha20Poly1305Test {
0xDEU, 0xFBU, 0x5CU, 0x7FU, 0x1CU, 0x26U, 0x32U, 0x2CU, 0x51U, 0xF6U, 0xEFU, 0xC6U, 0x34U, 0xC4U, 0xACU, 0x6CU,
0xE8U, 0xF9U, 0x4BU, 0xABU, 0xA3U,
)
val xcha = XChaCha20Poly1305Delegated(key, ubyteArrayOf(), state, header)
val xcha = XChaCha20Poly1305Delegated(key, state, header)
val data = UByteArray(100) { 0U }
val result = xcha.encrypt(data)
// assertTrue {
@@ -22,7 +22,8 @@ class Sha256Test {
}
@Test
fun statelessSimpleTest() {
fun statelessSimpleTest() = testBlocking {
Initializer.initialize()
val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
val result = CryptoPrimitives.Sha256.stateless("test".encodeToUByteArray()).toHexString()
// println("Result: $result")
@@ -32,7 +33,8 @@ class Sha256Test {
//This is a bad test since it's not larger than one block
//but for now I'm testing that the platform library is being correctly called
@Test
fun updateableSimpleTest() {
fun updateableSimpleTest() = testBlocking {
Initializer.initialize()
val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
val sha256 = CryptoPrimitives.Sha256.updateable()
sha256.update("t".encodeToUByteArray())
@@ -22,7 +22,8 @@ class Sha512Test {
}
@Test
fun statelessSimpleTest() {
fun statelessSimpleTest() = testBlocking {
Initializer.initialize()
val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" +
"b143732c304cc5fa9ad8e6f57f50028a8ff"
val result = CryptoPrimitives.Sha512.stateless("test".encodeToUByteArray()).toHexString()
@@ -33,7 +34,8 @@ class Sha512Test {
//This is a bad test since it's not larger than one block
//but for now I'm testing that the platform library is being correctly called
@Test
fun updateableSimpleTest() {
fun updateableSimpleTest() = testBlocking {
Initializer.initialize()
val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" +
"b143732c304cc5fa9ad8e6f57f50028a8ff"
val sha512 = CryptoPrimitives.Sha512.updateable()
@@ -16,11 +16,20 @@
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.Continuation
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.startCoroutine
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 20-Jul-2019
*/
expect fun testBlocking(block : suspend () -> Unit)
fun testBlocking(block : suspend () -> Unit) {
val continuation = Continuation<Unit>(EmptyCoroutineContext) {
//Do nothing
println("Done")
}
block.startCoroutine(continuation)
}
@@ -44,7 +44,12 @@ interface JsSodiumInterface {
fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, additionalData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
//XChaCha20Poly1305
//encrypt
fun crypto_secretstream_xchacha20poly1305_init_push(header: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: Char) : Uint8Array
//decrypt
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic
}
@@ -16,7 +16,7 @@ import org.khronos.webgl.Uint8Array
* ugljesa.jovanovic@ionspin.com
* on 14-Jun-2020
*/
actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonce: UByteArray) {
actual class XChaCha20Poly1305Delegated internal actual constructor() {
actual companion object {
actual fun encrypt(
key: UByteArray,
@@ -51,16 +51,25 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc
}
}
init {
// val state =
var state : dynamic = null
actual fun initializeForEncryption(key: UByteArray) : UByteArray {
val stateAndHeader = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
val state = stateAndHeader.state
val header = stateAndHeader.header
console.log(state)
console.log(header)
return header
}
actual fun initializeForDecryption(key: UByteArray, header: UByteArray) {
}
internal actual constructor(
key: UByteArray,
nonce: UByteArray,
testState: UByteArray,
testHeader: UByteArray
) : this(key, nonce) {
) : this() {
}
@@ -73,4 +82,6 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc
TODO("not implemented yet")
}
}
@@ -15,14 +15,14 @@
*/
package com.ionspin.kotlin.crypto.util
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 ()-> Unit) : dynamic = GlobalScope.promise { block() }
//
//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 ()-> Unit) : dynamic = GlobalScope.promise { block() }
@@ -7,7 +7,7 @@ import com.goterl.lazycode.lazysodium.SodiumJava
* ugljesa.jovanovic@ionspin.com
* on 14-Jun-2020
*/
actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonce: UByteArray) {
actual class XChaCha20Poly1305Delegated internal actual constructor() {
actual companion object {
actual fun encrypt(
key: UByteArray,
@@ -56,13 +56,19 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc
internal actual constructor(
key: UByteArray,
nonce: UByteArray,
testState: UByteArray,
testHeader: UByteArray
) : this(key, ubyteArrayOf()) {
) : this() {
}
actual fun initializeForEncryption(key: UByteArray) : UByteArray {
TODO()
}
actual fun initializeForDecryption(key: UByteArray, header: UByteArray) {
}
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
TODO("not implemented yet")
}
@@ -72,4 +78,6 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc
}
}
@@ -16,12 +16,19 @@
package com.ionspin.kotlin.crypto.util
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import kotlin.coroutines.Continuation
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.startCoroutine
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 20-Jul-2019
*/
actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() }
//actual fun testBlocking(block: suspend () -> Unit) {
// val continuation = Continuation<Unit>(EmptyCoroutineContext) {
// println("Done")
// }
// block.startCoroutine(continuation)
//
//}
@@ -10,7 +10,7 @@ import platform.posix.malloc
* ugljesa.jovanovic@ionspin.com
* on 14-Jun-2020
*/
actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray, val nonce: UByteArray) {
actual class XChaCha20Poly1305Delegated internal actual constructor() {
actual companion object {
actual fun encrypt(
key: UByteArray,
@@ -61,13 +61,18 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray,
}
}
var state =
malloc(crypto_secretstream_xchacha20poly1305_state.size.convert())!!
.reinterpret<crypto_secretstream_xchacha20poly1305_state>()
.pointed
val header = UByteArray(crypto_secretstream_xchacha20poly1305_HEADERBYTES.toInt()) { 0U }
actual internal constructor(
key: UByteArray,
nonce: UByteArray,
testState: UByteArray,
testHeader: UByteArray
) : this(key, nonce) {
) : this() {
val pointer = state.ptr.reinterpret<UByteVar>()
for (i in 0 until crypto_secretstream_xchacha20poly1305_state.size.toInt()) {
pointer[i] = testState[i]
@@ -81,14 +86,9 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray,
println("header after setting-----------")
}
var state =
malloc(crypto_secretstream_xchacha20poly1305_state.size.convert())!!
.reinterpret<crypto_secretstream_xchacha20poly1305_state>()
.pointed
val header = UByteArray(crypto_secretstream_xchacha20poly1305_HEADERBYTES.toInt()) { 0U }
init {
actual fun initializeForEncryption(key: UByteArray) : UByteArray {
val pinnedHeader = header.pin()
crypto_secretstream_xchacha20poly1305_init_push(state.ptr, pinnedHeader.addressOf(0), key.toCValues())
println("state-----------")
@@ -97,9 +97,15 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray,
println("--------header-----------")
header.hexColumsPrint()
println("--------header-----------")
pinnedHeader.unpin()
return header
}
actual fun initializeForDecryption(key: UByteArray, header: UByteArray) {
}
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
val ciphertextWithTag = UByteArray(data.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt())
val ciphertextWithTagPinned = ciphertextWithTag.pin()
@@ -125,4 +131,6 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray,
}
}
@@ -14,14 +14,14 @@
* 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() }
//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() }