From 0baef1257e5fa1fac554569c7f8d595c8a29942c Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Wed, 5 Oct 2022 13:43:41 +0200 Subject: [PATCH 1/4] Update badge master -> main --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 43e313a..2d5dd28 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![pipeline status](https://gitlab.com/ionspin-github-ci/kotlin-multiplatform-libsodium/badges/master/pipeline.svg)](https://gitlab.com/ionspin-github-ci/kotlin-multiplatform-libsodium/-/commits/master) +[![pipeline status](https://gitlab.com/ionspin-github-ci/kotlin-multiplatform-libsodium/badges/main/pipeline.svg)](https://gitlab.com/ionspin-github-ci/kotlin-multiplatform-libsodium/-/commits/main) ![Danger: Experimental](https://camo.githubusercontent.com/275bc882f21b154b5537b9c123a171a30de9e6aa/68747470733a2f2f7261772e6769746875622e636f6d2f63727970746f7370686572652f63727970746f7370686572652f6d61737465722f696d616765732f6578706572696d656e74616c2e706e67) From 13a880cc73d62a8f10ab2d0ecc7c2f641a1b2db9 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Thu, 6 Oct 2022 10:44:54 +0200 Subject: [PATCH 2/4] Bump sample to use latest snapshot and add some encryption/decryption to binary --- buildSrc/src/main/kotlin/Deps.kt | 2 +- .../com/ionspin/kotlin/crypto/sample/Sample.kt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 4ef3b35..608170d 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -25,7 +25,7 @@ object Versions { val kotlinBigNumVersion = "0.3.7" val jna = "5.10.0" val kotlinPoet = "1.6.0" - val sampleLibsodiumBindings = "0.8.5-SNAPSHOT" + val sampleLibsodiumBindings = "0.8.8-SNAPSHOT" val ktor = "1.3.2" val timber = "4.7.1" val kodeinVersion = "7.1.0" diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/Sample.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/Sample.kt index 2e4fb1f..43b38a0 100644 --- a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/Sample.kt +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/Sample.kt @@ -1,5 +1,7 @@ package com.ionspin.kotlin.crypto.sample +import com.ionspin.kotlin.crypto.aead.AuthenticatedEncryptionWithAssociatedData +import com.ionspin.kotlin.crypto.aead.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES import com.ionspin.kotlin.crypto.hash.Hash import com.ionspin.kotlin.crypto.util.LibsodiumRandom import com.ionspin.kotlin.crypto.util.encodeToUByteArray @@ -10,10 +12,24 @@ object Sample { fun runSample() { val random = LibsodiumRandom.buf(32) println("Random: ${random.toHexString()}") + println("Hashed 123 ${hashSomething()}") + encryptThenDecrypt() } fun hashSomething() : String { val hash = Hash.sha512("123".encodeToUByteArray()) return "Hash (SHA512) of 123: ${hash.toHexString()}" } + + fun encryptThenDecrypt() { + val data = LibsodiumRandom.buf(2048) + val associatedData = LibsodiumRandom.buf(256) + val key = AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfKeygen() + val nonce = LibsodiumRandom.buf(crypto_aead_xchacha20poly1305_ietf_NPUBBYTES) + val encrypted = AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfEncrypt(data, associatedData, nonce, key) + println("Original data ${data.toHexString()}") + println("Encrypted ${encrypted.toHexString()}") + val decrypted = AuthenticatedEncryptionWithAssociatedData.xChaCha20Poly1305IetfDecrypt(encrypted, associatedData, nonce, key) + println("Decrypted ${decrypted.toHexString()}") + } } From fec0f36dc3cd47804e5d04bb01b37b0021898113 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Thu, 6 Oct 2022 12:26:35 +0200 Subject: [PATCH 3/4] Fix runners, use api because yarn breaks if same project has local sources and reference to build remote library --- .../kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 sample/src/linuxMain/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt diff --git a/sample/src/linuxMain/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt b/sample/src/linuxMain/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt new file mode 100644 index 0000000..3343ed0 --- /dev/null +++ b/sample/src/linuxMain/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt @@ -0,0 +1,5 @@ +import com.ionspin.kotlin.crypto.sample.Sample + +fun main() { + Sample.runSample() +} From c843ea5122921238932abf12bfdf3493f892744b Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Fri, 7 Oct 2022 20:00:59 +0200 Subject: [PATCH 4/4] Remove test dependencies from jvm main, clean up runners --- .../build.gradle.kts | 2 -- sample/build.gradle.kts | 1 + .../kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt | 11 ++--------- .../kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt | 4 ---- .../kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt | 3 --- sample/src/nativeMain/kotlin/Runner.kt | 7 ++++--- 6 files changed, 7 insertions(+), 21 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 2efa395..fb14645 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -566,8 +566,6 @@ kotlin { kotlin.srcDirs("src/jvmSpecific", "src/jvmMain/kotlin") dependencies { implementation(kotlin(Deps.Jvm.stdLib)) - implementation(kotlin(Deps.Jvm.test)) - implementation(kotlin(Deps.Jvm.testJUnit)) implementation(Deps.Jvm.resourceLoader) diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index b26e5c5..7aae6fc 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -184,6 +184,7 @@ kotlin { implementation(kotlin(Deps.Common.stdLib)) implementation(kotlin(Deps.Common.test)) implementation(Deps.Common.serialization) +// api(Deps.Common.libsodiumBindings) api(project(":multiplatform-crypto-libsodium-bindings")) implementation(Deps.Common.coroutines) } diff --git a/sample/src/linuxArm32HfpMain/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt b/sample/src/linuxArm32HfpMain/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt index 2c1979b..3343ed0 100644 --- a/sample/src/linuxArm32HfpMain/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt +++ b/sample/src/linuxArm32HfpMain/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt @@ -1,12 +1,5 @@ -import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegated -import kotlin.time.ExperimentalTime -import kotlin.time.measureTime - -@ExperimentalTime +import com.ionspin.kotlin.crypto.sample.Sample fun main() { - println("Test") -// Blake - val blake = Blake2bDelegated() - blake.digest() + Sample.runSample() } diff --git a/sample/src/linuxArm64Main/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt b/sample/src/linuxArm64Main/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt index bdb06de..3343ed0 100644 --- a/sample/src/linuxArm64Main/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt +++ b/sample/src/linuxArm64Main/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt @@ -1,9 +1,5 @@ import com.ionspin.kotlin.crypto.sample.Sample -import kotlin.time.ExperimentalTime -@ExperimentalTime fun main() { - Sample.runSample() - } diff --git a/sample/src/macosX64Main/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt b/sample/src/macosX64Main/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt index 04d9122..3343ed0 100644 --- a/sample/src/macosX64Main/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt +++ b/sample/src/macosX64Main/kotlin/com/ionspin/kotlin/crypto/sample/Runner.kt @@ -1,7 +1,4 @@ import com.ionspin.kotlin.crypto.sample.Sample -import kotlin.time.ExperimentalTime - -@ExperimentalTime fun main() { Sample.runSample() diff --git a/sample/src/nativeMain/kotlin/Runner.kt b/sample/src/nativeMain/kotlin/Runner.kt index 5520d1b..f79d706 100644 --- a/sample/src/nativeMain/kotlin/Runner.kt +++ b/sample/src/nativeMain/kotlin/Runner.kt @@ -1,5 +1,6 @@ import com.ionspin.kotlin.crypto.sample.Sample -fun main() : Unit { - Sample.runSample() -} +// Clashes with platform specific main() +//fun main() : Unit { +// Sample.runSample() +//}