Remove coroutines
This commit is contained in:
parent
8625002ea4
commit
71ec5b7585
@ -23,7 +23,7 @@ object Versions {
|
|||||||
val dokkaPlugin = "0.11.0-dev-44"
|
val dokkaPlugin = "0.11.0-dev-44"
|
||||||
val taskTreePlugin = "1.5"
|
val taskTreePlugin = "1.5"
|
||||||
|
|
||||||
val kotlinBigNumVersion = "0.1.6-1.4-M2-2-SNAPSHOT"
|
val kotlinBigNumVersion = "0.1.6-1.4-M2-3-SNAPSHOT"
|
||||||
|
|
||||||
val lazySodium = "4.2.6"
|
val lazySodium = "4.2.6"
|
||||||
val jna = "5.5.0"
|
val jna = "5.5.0"
|
||||||
|
@ -69,7 +69,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Not supported in OFFICIAL coroutines at the moment
|
|
||||||
linuxArm64() {
|
linuxArm64() {
|
||||||
binaries {
|
binaries {
|
||||||
staticLib {
|
staticLib {
|
||||||
@ -77,7 +76,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Not supported in OFFICAL coroutines at the moment
|
|
||||||
linuxArm32Hfp() {
|
linuxArm32Hfp() {
|
||||||
binaries {
|
binaries {
|
||||||
staticLib {
|
staticLib {
|
||||||
|
@ -131,7 +131,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Not supported in OFFICIAL coroutines at the moment (we're running a custom build)
|
|
||||||
runningOnLinuxArm64 {
|
runningOnLinuxArm64 {
|
||||||
println("Configuring Linux Arm 64 targets")
|
println("Configuring Linux Arm 64 targets")
|
||||||
|
|
||||||
@ -249,7 +248,6 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Common.stdLib))
|
implementation(kotlin(Deps.Common.stdLib))
|
||||||
implementation(kotlin(Deps.Common.test))
|
implementation(kotlin(Deps.Common.test))
|
||||||
implementation(Deps.Common.coroutines)
|
|
||||||
implementation(Deps.Common.kotlinBigNum)
|
implementation(Deps.Common.kotlinBigNum)
|
||||||
api(project(Deps.Common.apiProject))
|
api(project(Deps.Common.apiProject))
|
||||||
}
|
}
|
||||||
@ -262,7 +260,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val nativeDependencies = independentDependencyBlock {
|
val nativeDependencies = independentDependencyBlock {
|
||||||
implementation(Deps.Native.coroutines)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val nativeMain by creating {
|
val nativeMain by creating {
|
||||||
@ -281,7 +278,6 @@ kotlin {
|
|||||||
kotlin.setSrcDirs(emptySet<String>())
|
kotlin.setSrcDirs(emptySet<String>())
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Native.coroutines)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,7 +416,6 @@ kotlin {
|
|||||||
implementation(kotlin(Deps.Jvm.stdLib))
|
implementation(kotlin(Deps.Jvm.stdLib))
|
||||||
implementation(kotlin(Deps.Jvm.test))
|
implementation(kotlin(Deps.Jvm.test))
|
||||||
implementation(kotlin(Deps.Jvm.testJUnit))
|
implementation(kotlin(Deps.Jvm.testJUnit))
|
||||||
implementation(Deps.Jvm.coroutinesCore)
|
|
||||||
|
|
||||||
//lazysodium
|
//lazysodium
|
||||||
implementation(Deps.Jvm.Delegated.lazysodium)
|
implementation(Deps.Jvm.Delegated.lazysodium)
|
||||||
@ -431,20 +426,17 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Jvm.test))
|
implementation(kotlin(Deps.Jvm.test))
|
||||||
implementation(kotlin(Deps.Jvm.testJUnit))
|
implementation(kotlin(Deps.Jvm.testJUnit))
|
||||||
implementation(Deps.Jvm.coroutinesTest)
|
|
||||||
implementation(kotlin(Deps.Jvm.reflection))
|
implementation(kotlin(Deps.Jvm.reflection))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jsMain by getting {
|
val jsMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Js.stdLib))
|
implementation(kotlin(Deps.Js.stdLib))
|
||||||
implementation(Deps.Js.coroutines)
|
|
||||||
implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second))
|
implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jsTest by getting {
|
val jsTest by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Js.coroutines)
|
|
||||||
implementation(kotlin(Deps.Js.test))
|
implementation(kotlin(Deps.Js.test))
|
||||||
implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second))
|
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 {
|
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)
|
return MultipartAuthenticatedDecryptor(decryptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +175,11 @@ object Crypto {
|
|||||||
|
|
||||||
class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKey) : MultipartAuthenticatedEncryption {
|
class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKey) : MultipartAuthenticatedEncryption {
|
||||||
|
|
||||||
val header = MultipartEncryptionHeader(SRNG.getRandomBytes(24))
|
val header : MultipartEncryptionHeader
|
||||||
val primitive = XChaCha20Poly1305Delegated(key.value, header.nonce)
|
val primitive = XChaCha20Poly1305Delegated()
|
||||||
|
init {
|
||||||
|
header = MultipartEncryptionHeader(primitive.initializeForEncryption(key.value))
|
||||||
|
}
|
||||||
|
|
||||||
override fun startEncryption(): MultipartEncryptionHeader {
|
override fun startEncryption(): MultipartEncryptionHeader {
|
||||||
return header
|
return header
|
||||||
|
@ -6,13 +6,14 @@ package com.ionspin.kotlin.crypto.authenticated
|
|||||||
* ugljesa.jovanovic@ionspin.com
|
* ugljesa.jovanovic@ionspin.com
|
||||||
* on 14-Jun-2020
|
* on 14-Jun-2020
|
||||||
*/
|
*/
|
||||||
expect class XChaCha20Poly1305Delegated constructor(key: UByteArray, nonce: UByteArray) {
|
expect class XChaCha20Poly1305Delegated internal constructor() {
|
||||||
internal constructor(key: UByteArray, nonce: UByteArray, testState : UByteArray, testHeader: UByteArray)
|
internal constructor(key: UByteArray, testState : UByteArray, testHeader: UByteArray)
|
||||||
companion object {
|
companion object {
|
||||||
fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, additionalData: UByteArray) : UByteArray
|
fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, additionalData: UByteArray) : UByteArray
|
||||||
fun decrypt(key: UByteArray, nonce: UByteArray, ciphertext: 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 encrypt(data: UByteArray, additionalData: UByteArray = ubyteArrayOf()) : UByteArray
|
||||||
fun decrypt(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,
|
0xDEU, 0xFBU, 0x5CU, 0x7FU, 0x1CU, 0x26U, 0x32U, 0x2CU, 0x51U, 0xF6U, 0xEFU, 0xC6U, 0x34U, 0xC4U, 0xACU, 0x6CU,
|
||||||
0xE8U, 0xF9U, 0x4BU, 0xABU, 0xA3U,
|
0xE8U, 0xF9U, 0x4BU, 0xABU, 0xA3U,
|
||||||
)
|
)
|
||||||
val xcha = XChaCha20Poly1305Delegated(key, ubyteArrayOf(), state, header)
|
val xcha = XChaCha20Poly1305Delegated(key, state, header)
|
||||||
val data = UByteArray(100) { 0U }
|
val data = UByteArray(100) { 0U }
|
||||||
val result = xcha.encrypt(data)
|
val result = xcha.encrypt(data)
|
||||||
// assertTrue {
|
// assertTrue {
|
||||||
|
@ -22,7 +22,8 @@ class Sha256Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun statelessSimpleTest() {
|
fun statelessSimpleTest() = testBlocking {
|
||||||
|
Initializer.initialize()
|
||||||
val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
|
val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
|
||||||
val result = CryptoPrimitives.Sha256.stateless("test".encodeToUByteArray()).toHexString()
|
val result = CryptoPrimitives.Sha256.stateless("test".encodeToUByteArray()).toHexString()
|
||||||
// println("Result: $result")
|
// println("Result: $result")
|
||||||
@ -32,7 +33,8 @@ class Sha256Test {
|
|||||||
//This is a bad test since it's not larger than one block
|
//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
|
//but for now I'm testing that the platform library is being correctly called
|
||||||
@Test
|
@Test
|
||||||
fun updateableSimpleTest() {
|
fun updateableSimpleTest() = testBlocking {
|
||||||
|
Initializer.initialize()
|
||||||
val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
|
val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
|
||||||
val sha256 = CryptoPrimitives.Sha256.updateable()
|
val sha256 = CryptoPrimitives.Sha256.updateable()
|
||||||
sha256.update("t".encodeToUByteArray())
|
sha256.update("t".encodeToUByteArray())
|
||||||
|
@ -22,7 +22,8 @@ class Sha512Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun statelessSimpleTest() {
|
fun statelessSimpleTest() = testBlocking {
|
||||||
|
Initializer.initialize()
|
||||||
val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" +
|
val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" +
|
||||||
"b143732c304cc5fa9ad8e6f57f50028a8ff"
|
"b143732c304cc5fa9ad8e6f57f50028a8ff"
|
||||||
val result = CryptoPrimitives.Sha512.stateless("test".encodeToUByteArray()).toHexString()
|
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
|
//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
|
//but for now I'm testing that the platform library is being correctly called
|
||||||
@Test
|
@Test
|
||||||
fun updateableSimpleTest() {
|
fun updateableSimpleTest() = testBlocking {
|
||||||
|
Initializer.initialize()
|
||||||
val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" +
|
val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" +
|
||||||
"b143732c304cc5fa9ad8e6f57f50028a8ff"
|
"b143732c304cc5fa9ad8e6f57f50028a8ff"
|
||||||
val sha512 = CryptoPrimitives.Sha512.updateable()
|
val sha512 = CryptoPrimitives.Sha512.updateable()
|
||||||
|
@ -16,11 +16,20 @@
|
|||||||
|
|
||||||
package com.ionspin.kotlin.crypto.util
|
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
|
* Created by Ugljesa Jovanovic
|
||||||
* ugljesa.jovanovic@ionspin.com
|
* ugljesa.jovanovic@ionspin.com
|
||||||
* on 20-Jul-2019
|
* 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
|
fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, additionalData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||||
|
|
||||||
//XChaCha20Poly1305
|
//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
|
* ugljesa.jovanovic@ionspin.com
|
||||||
* on 14-Jun-2020
|
* on 14-Jun-2020
|
||||||
*/
|
*/
|
||||||
actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonce: UByteArray) {
|
actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||||
actual companion object {
|
actual companion object {
|
||||||
actual fun encrypt(
|
actual fun encrypt(
|
||||||
key: UByteArray,
|
key: UByteArray,
|
||||||
@ -51,16 +51,25 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
var state : dynamic = null
|
||||||
// val state =
|
|
||||||
|
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(
|
internal actual constructor(
|
||||||
key: UByteArray,
|
key: UByteArray,
|
||||||
nonce: UByteArray,
|
|
||||||
testState: UByteArray,
|
testState: UByteArray,
|
||||||
testHeader: UByteArray
|
testHeader: UByteArray
|
||||||
) : this(key, nonce) {
|
) : this() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,4 +82,6 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc
|
|||||||
TODO("not implemented yet")
|
TODO("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package com.ionspin.kotlin.crypto.util
|
package com.ionspin.kotlin.crypto.util
|
||||||
|
//
|
||||||
import kotlinx.coroutines.GlobalScope
|
//import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.promise
|
//import kotlinx.coroutines.promise
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Created by Ugljesa Jovanovic
|
// * Created by Ugljesa Jovanovic
|
||||||
* ugljesa.jovanovic@ionspin.com
|
// * ugljesa.jovanovic@ionspin.com
|
||||||
* on 20-Jul-2019
|
// * on 20-Jul-2019
|
||||||
*/
|
// */
|
||||||
actual fun testBlocking(block: suspend ()-> Unit) : dynamic = GlobalScope.promise { block() }
|
//actual fun testBlocking(block: suspend ()-> Unit) : dynamic = GlobalScope.promise { block() }
|
||||||
|
@ -7,7 +7,7 @@ import com.goterl.lazycode.lazysodium.SodiumJava
|
|||||||
* ugljesa.jovanovic@ionspin.com
|
* ugljesa.jovanovic@ionspin.com
|
||||||
* on 14-Jun-2020
|
* on 14-Jun-2020
|
||||||
*/
|
*/
|
||||||
actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonce: UByteArray) {
|
actual class XChaCha20Poly1305Delegated internal actual constructor() {
|
||||||
actual companion object {
|
actual companion object {
|
||||||
actual fun encrypt(
|
actual fun encrypt(
|
||||||
key: UByteArray,
|
key: UByteArray,
|
||||||
@ -56,13 +56,19 @@ actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, nonc
|
|||||||
|
|
||||||
internal actual constructor(
|
internal actual constructor(
|
||||||
key: UByteArray,
|
key: UByteArray,
|
||||||
nonce: UByteArray,
|
|
||||||
testState: UByteArray,
|
testState: UByteArray,
|
||||||
testHeader: 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 {
|
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
||||||
TODO("not implemented yet")
|
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
|
package com.ionspin.kotlin.crypto.util
|
||||||
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlin.coroutines.Continuation
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
import kotlin.coroutines.startCoroutine
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ugljesa Jovanovic
|
* Created by Ugljesa Jovanovic
|
||||||
* ugljesa.jovanovic@ionspin.com
|
* ugljesa.jovanovic@ionspin.com
|
||||||
* on 20-Jul-2019
|
* 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
|
* ugljesa.jovanovic@ionspin.com
|
||||||
* on 14-Jun-2020
|
* 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 companion object {
|
||||||
actual fun encrypt(
|
actual fun encrypt(
|
||||||
key: UByteArray,
|
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(
|
actual internal constructor(
|
||||||
key: UByteArray,
|
key: UByteArray,
|
||||||
nonce: UByteArray,
|
|
||||||
testState: UByteArray,
|
testState: UByteArray,
|
||||||
testHeader: UByteArray
|
testHeader: UByteArray
|
||||||
) : this(key, nonce) {
|
) : this() {
|
||||||
val pointer = state.ptr.reinterpret<UByteVar>()
|
val pointer = state.ptr.reinterpret<UByteVar>()
|
||||||
for (i in 0 until crypto_secretstream_xchacha20poly1305_state.size.toInt()) {
|
for (i in 0 until crypto_secretstream_xchacha20poly1305_state.size.toInt()) {
|
||||||
pointer[i] = testState[i]
|
pointer[i] = testState[i]
|
||||||
@ -81,14 +86,9 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray,
|
|||||||
println("header after setting-----------")
|
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()
|
val pinnedHeader = header.pin()
|
||||||
crypto_secretstream_xchacha20poly1305_init_push(state.ptr, pinnedHeader.addressOf(0), key.toCValues())
|
crypto_secretstream_xchacha20poly1305_init_push(state.ptr, pinnedHeader.addressOf(0), key.toCValues())
|
||||||
println("state-----------")
|
println("state-----------")
|
||||||
@ -97,9 +97,15 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray,
|
|||||||
println("--------header-----------")
|
println("--------header-----------")
|
||||||
header.hexColumsPrint()
|
header.hexColumsPrint()
|
||||||
println("--------header-----------")
|
println("--------header-----------")
|
||||||
|
pinnedHeader.unpin()
|
||||||
|
return header
|
||||||
|
}
|
||||||
|
|
||||||
|
actual fun initializeForDecryption(key: UByteArray, header: UByteArray) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
|
||||||
val ciphertextWithTag = UByteArray(data.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt())
|
val ciphertextWithTag = UByteArray(data.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt())
|
||||||
val ciphertextWithTagPinned = ciphertextWithTag.pin()
|
val ciphertextWithTagPinned = ciphertextWithTag.pin()
|
||||||
@ -125,4 +131,6 @@ actual class XChaCha20Poly1305Delegated actual constructor(val key: UByteArray,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.ionspin.kotlin.crypto.util
|
//package com.ionspin.kotlin.crypto.util
|
||||||
|
//
|
||||||
import kotlinx.coroutines.CoroutineScope
|
//import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.runBlocking
|
//import kotlinx.coroutines.runBlocking
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Created by Ugljesa Jovanovic
|
// * Created by Ugljesa Jovanovic
|
||||||
* ugljesa.jovanovic@ionspin.com
|
// * ugljesa.jovanovic@ionspin.com
|
||||||
* on 20-Jul-2019
|
// * on 20-Jul-2019
|
||||||
*/
|
// */
|
||||||
actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() }
|
//actual fun testBlocking(block: suspend () -> Unit) = runBlocking { block() }
|
||||||
|
@ -197,7 +197,6 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Common.stdLib))
|
implementation(kotlin(Deps.Common.stdLib))
|
||||||
implementation(kotlin(Deps.Common.test))
|
implementation(kotlin(Deps.Common.test))
|
||||||
implementation(Deps.Common.coroutines)
|
|
||||||
implementation(Deps.Common.kotlinBigNum)
|
implementation(Deps.Common.kotlinBigNum)
|
||||||
implementation(project(Deps.Common.apiProject))
|
implementation(project(Deps.Common.apiProject))
|
||||||
}
|
}
|
||||||
@ -213,7 +212,6 @@ kotlin {
|
|||||||
val nativeMain by creating {
|
val nativeMain by creating {
|
||||||
dependsOn(commonMain)
|
dependsOn(commonMain)
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Native.coroutines)
|
|
||||||
}
|
}
|
||||||
isRunningInIdea {
|
isRunningInIdea {
|
||||||
kotlin.setSrcDirs(emptySet<String>())
|
kotlin.setSrcDirs(emptySet<String>())
|
||||||
@ -224,7 +222,6 @@ kotlin {
|
|||||||
val nativeTest by creating {
|
val nativeTest by creating {
|
||||||
dependsOn(commonTest)
|
dependsOn(commonTest)
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Native.coroutines)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,26 +254,22 @@ kotlin {
|
|||||||
implementation(kotlin(Deps.Jvm.stdLib))
|
implementation(kotlin(Deps.Jvm.stdLib))
|
||||||
implementation(kotlin(Deps.Jvm.test))
|
implementation(kotlin(Deps.Jvm.test))
|
||||||
implementation(kotlin(Deps.Jvm.testJUnit))
|
implementation(kotlin(Deps.Jvm.testJUnit))
|
||||||
implementation(Deps.Jvm.coroutinesCore)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jvmTest by getting {
|
val jvmTest by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Jvm.test))
|
implementation(kotlin(Deps.Jvm.test))
|
||||||
implementation(kotlin(Deps.Jvm.testJUnit))
|
implementation(kotlin(Deps.Jvm.testJUnit))
|
||||||
implementation(Deps.Jvm.coroutinesTest)
|
|
||||||
implementation(kotlin(Deps.Jvm.reflection))
|
implementation(kotlin(Deps.Jvm.reflection))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jsMain by getting {
|
val jsMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Js.stdLib))
|
implementation(kotlin(Deps.Js.stdLib))
|
||||||
implementation(Deps.Js.coroutines)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jsTest by getting {
|
val jsTest by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Js.coroutines)
|
|
||||||
implementation(kotlin(Deps.Js.test))
|
implementation(kotlin(Deps.Js.test))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -355,7 +348,6 @@ kotlin {
|
|||||||
// val mingwX86Main by getting {
|
// val mingwX86Main by getting {
|
||||||
// dependsOn(commonMain)
|
// dependsOn(commonMain)
|
||||||
// dependencies {
|
// dependencies {
|
||||||
// implementation(Deps.Native.coroutines)
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@ -367,7 +359,6 @@ kotlin {
|
|||||||
val mingwX64Main by getting {
|
val mingwX64Main by getting {
|
||||||
dependsOn(commonMain)
|
dependsOn(commonMain)
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Native.coroutines)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 kotlin.time.ExperimentalTime
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 {
|
|
||||||
Coroutines14.argonParallel()
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,11 +16,19 @@
|
|||||||
|
|
||||||
package com.ionspin.kotlin.crypto.util
|
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
|
* Created by Ugljesa Jovanovic
|
||||||
* ugljesa.jovanovic@ionspin.com
|
* ugljesa.jovanovic@ionspin.com
|
||||||
* on 20-Jul-2019
|
* 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)
|
||||||
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.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() }
|
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.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() }
|
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.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() }
|
|
@ -143,7 +143,6 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Common.stdLib))
|
implementation(kotlin(Deps.Common.stdLib))
|
||||||
implementation(kotlin(Deps.Common.test))
|
implementation(kotlin(Deps.Common.test))
|
||||||
implementation(Deps.Common.coroutines)
|
|
||||||
implementation(Deps.Common.kotlinBigNum)
|
implementation(Deps.Common.kotlinBigNum)
|
||||||
implementation(project(":multiplatform-crypto-delegated"))
|
implementation(project(":multiplatform-crypto-delegated"))
|
||||||
}
|
}
|
||||||
@ -159,14 +158,12 @@ kotlin {
|
|||||||
val nativeMain by creating {
|
val nativeMain by creating {
|
||||||
dependsOn(commonMain)
|
dependsOn(commonMain)
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Native.coroutines)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val nativeTest by creating {
|
val nativeTest by creating {
|
||||||
dependsOn(commonTest)
|
dependsOn(commonTest)
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Native.coroutines)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,26 +173,22 @@ kotlin {
|
|||||||
implementation(kotlin(Deps.Jvm.stdLib))
|
implementation(kotlin(Deps.Jvm.stdLib))
|
||||||
implementation(kotlin(Deps.Jvm.test))
|
implementation(kotlin(Deps.Jvm.test))
|
||||||
implementation(kotlin(Deps.Jvm.testJUnit))
|
implementation(kotlin(Deps.Jvm.testJUnit))
|
||||||
implementation(Deps.Jvm.coroutinesCore)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jvmTest by getting {
|
val jvmTest by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Jvm.test))
|
implementation(kotlin(Deps.Jvm.test))
|
||||||
implementation(kotlin(Deps.Jvm.testJUnit))
|
implementation(kotlin(Deps.Jvm.testJUnit))
|
||||||
implementation(Deps.Jvm.coroutinesTest)
|
|
||||||
implementation(kotlin(Deps.Jvm.reflection))
|
implementation(kotlin(Deps.Jvm.reflection))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jsMain by getting {
|
val jsMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Js.stdLib))
|
implementation(kotlin(Deps.Js.stdLib))
|
||||||
implementation(Deps.Js.coroutines)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jsTest by getting {
|
val jsTest by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(Deps.Js.coroutines)
|
|
||||||
implementation(kotlin(Deps.Js.test))
|
implementation(kotlin(Deps.Js.test))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user