Bump to 1.4-M3

This commit is contained in:
Ugljesa Jovanovic 2020-07-07 00:00:53 +02:00 committed by Ugljesa Jovanovic
parent 71ec5b7585
commit f5150557d6
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
9 changed files with 44 additions and 17 deletions

View File

@ -28,7 +28,7 @@ repositories {
} }
dependencies { dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M2") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M3")
} }
System.setProperty("PROJECT_PATH", project.projectDir.parentFile.toString()) System.setProperty("PROJECT_PATH", project.projectDir.parentFile.toString())

View File

@ -16,14 +16,14 @@
object Versions { object Versions {
val kotlinCoroutines = "1.3.5-native-mt-arm-1.4-M2-SNAPSHOT" //NOTE: my linux arm32 and arm64 build val kotlinCoroutines = "1.3.5-native-mt-arm-1.4-M2-SNAPSHOT" //NOTE: my linux arm32 and arm64 build
val kotlin = "1.4-M2" val kotlin = "1.4-M3"
val kotlinSerialization = "0.20.0-1.4-M2" val kotlinSerialization = "0.20.0-1.4-M3"
val atomicfu = "0.14.3-M2-2-SNAPSHOT" //NOTE: my linux arm32 and arm64 build val atomicfu = "0.14.3-M2-2-SNAPSHOT" //NOTE: my linux arm32 and arm64 build
val nodePlugin = "1.3.0" val nodePlugin = "1.3.0"
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-3-SNAPSHOT" val kotlinBigNumVersion = "0.1.6-1.4-M3-1-SNAPSHOT"
val lazySodium = "4.2.6" val lazySodium = "4.2.6"
val jna = "5.5.0" val jna = "5.5.0"

View File

@ -117,7 +117,7 @@ object CryptoPrimitives : PrimitivesApi {
// salt, // salt,
// key, // key,
// associatedData, // associatedData,
// parallelism, // parallelism
// tagLength, // tagLength,
// memory, // memory,
// numberOfIterations // numberOfIterations

View File

@ -1,6 +1,7 @@
package com.ionspin.kotlin.crypto.authenticated package com.ionspin.kotlin.crypto.authenticated
import com.ionspin.kotlin.crypto.CryptoInitializerDelegated import com.ionspin.kotlin.crypto.CryptoInitializerDelegated
import com.ionspin.kotlin.crypto.Initializer
import com.ionspin.kotlin.crypto.hash.encodeToUByteArray import com.ionspin.kotlin.crypto.hash.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.hexColumsPrint import com.ionspin.kotlin.crypto.util.hexColumsPrint
import com.ionspin.kotlin.crypto.util.testBlocking import com.ionspin.kotlin.crypto.util.testBlocking
@ -184,10 +185,10 @@ class XChaCha20Poly1305Test {
} }
//Missing jvm and js impl
@Ignore
@Test @Test
fun testStreamingImpl() { fun testStreamingImpl() = testBlocking {
Initializer.initialize()
val key = UByteArray(32) { 0U} val key = UByteArray(32) { 0U}
val state = ubyteArrayOf( val state = ubyteArrayOf(
0x2DU, 0xDBU, 0xC7U, 0xB2U, 0x03U, 0xBCU, 0xC3U, 0x22U, 0xBDU, 0x0CU, 0xBAU, 0x82U, 0xADU, 0x77U, 0x79U, 0x44U, 0x2DU, 0xDBU, 0xC7U, 0xB2U, 0x03U, 0xBCU, 0xC3U, 0x22U, 0xBDU, 0x0CU, 0xBAU, 0x82U, 0xADU, 0x77U, 0x79U, 0x44U,
@ -212,6 +213,7 @@ class XChaCha20Poly1305Test {
val xcha = XChaCha20Poly1305Delegated(key, 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 {
// expected.contentEquals(result) // expected.contentEquals(result)
// } // }

View File

@ -29,7 +29,9 @@ import kotlin.coroutines.startCoroutine
fun testBlocking(block : suspend () -> Unit) { fun testBlocking(block : suspend () -> Unit) {
val continuation = Continuation<Unit>(EmptyCoroutineContext) { val continuation = Continuation<Unit>(EmptyCoroutineContext) {
//Do nothing //Do nothing
println("Done") if (it.isFailure) {
throw it.exceptionOrNull()!!
}
} }
block.startCoroutine(continuation) block.startCoroutine(continuation)
} }

View File

@ -46,7 +46,7 @@ interface JsSodiumInterface {
//XChaCha20Poly1305 //XChaCha20Poly1305
//encrypt //encrypt
fun crypto_secretstream_xchacha20poly1305_init_push(header: Uint8Array) : dynamic fun crypto_secretstream_xchacha20poly1305_init_push(header: Uint8Array) : dynamic
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: Char) : Uint8Array fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: UByte) : Uint8Array
//decrypt //decrypt
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic

View File

@ -54,15 +54,18 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
var state : dynamic = null var state : dynamic = null
actual fun initializeForEncryption(key: UByteArray) : UByteArray { actual fun initializeForEncryption(key: UByteArray) : UByteArray {
println("Initializaing for encryption")
val stateAndHeader = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array()) val stateAndHeader = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
val state = stateAndHeader.state val state = stateAndHeader.state
val header = stateAndHeader.header val header = stateAndHeader.header
console.log(state) console.log(state)
console.log(header) console.log(header)
println("Done initializaing for encryption")
return header return header
} }
actual fun initializeForDecryption(key: UByteArray, header: UByteArray) { actual fun initializeForDecryption(key: UByteArray, header: UByteArray) {
} }
internal actual constructor( internal actual constructor(
@ -70,12 +73,14 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
testState: UByteArray, testState: UByteArray,
testHeader: UByteArray testHeader: UByteArray
) : this() { ) : this() {
state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(testHeader.toUInt8Array(), key.toUInt8Array())
console.log(state)
println("Done initializaing test state")
} }
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray { actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
// val encrypted val encrypted = getSodium().crypto_secretstream_xchacha20poly1305_push(state, data.toUInt8Array(), additionalData.toUInt8Array(), 0U)
TODO() return encrypted.toUByteArray()
} }
actual fun decrypt(data: UByteArray, additionalData: UByteArray): UByteArray { actual fun decrypt(data: UByteArray, additionalData: UByteArray): UByteArray {

View File

@ -1,6 +1,8 @@
package com.ionspin.kotlin.crypto.authenticated package com.ionspin.kotlin.crypto.authenticated
import com.goterl.lazycode.lazysodium.SodiumJava import com.goterl.lazycode.lazysodium.SodiumJava
import com.goterl.lazycode.lazysodium.interfaces.SecretStream
import com.ionspin.kotlin.crypto.util.hexColumsPrint
/** /**
* Created by Ugljesa Jovanovic * Created by Ugljesa Jovanovic
@ -54,12 +56,16 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
} }
} }
val state : SecretStream.State = SecretStream.State()
val sodium = SodiumJava()
internal actual constructor( internal actual constructor(
key: UByteArray, key: UByteArray,
testState: UByteArray, testState: UByteArray,
testHeader: UByteArray testHeader: UByteArray
) : this() { ) : this() {
state.k = testState.sliceArray(0 until 32).toByteArray()
state.nonce = testState.sliceArray(32 until 44).toByteArray()
} }
actual fun initializeForEncryption(key: UByteArray) : UByteArray { actual fun initializeForEncryption(key: UByteArray) : UByteArray {
@ -70,11 +76,21 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
} }
actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray { actual fun encrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
TODO("not implemented yet") val ciphertext = ByteArray(1 + data.size + 16)
sodium.crypto_secretstream_xchacha20poly1305_push(
state, ciphertext, null,
data.toByteArray(), data.size.toLong(),
additionalData.toByteArray(), additionalData.size.toLong(),
0
)
return ciphertext.toUByteArray()
} }
actual fun decrypt(data: UByteArray, additionalData: UByteArray): UByteArray { actual fun decrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
TODO("not implemented yet") val plaintext = ByteArray(data.size - 17)
TODO()
} }

View File

@ -28,7 +28,9 @@ import kotlin.coroutines.startCoroutine
fun testBlocking(block : suspend () -> Unit) { fun testBlocking(block : suspend () -> Unit) {
val continuation = Continuation<Unit>(EmptyCoroutineContext) { val continuation = Continuation<Unit>(EmptyCoroutineContext) {
//Do nothing //Do nothing
println("Done") if (it.isFailure) {
throw it.exceptionOrNull()!!
}
} }
block.startCoroutine(continuation) block.startCoroutine(continuation)
} }