From 197aacac338230a999a896e93d428f88d008931a Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Tue, 9 Jun 2020 20:30:12 +0200 Subject: [PATCH] Built and included modified libsodium with additional wrappers, working blake, sha256/512 hashes --- EXTERNAL_LICENSES | 20 ++++++++++ buildSrc/src/main/kotlin/Deps.kt | 5 ++- .../com/ionspin/kotlin/crypto/hash/Hash.kt | 2 - .../ionspin/kotlin/crypto/hash/sha/Sha512.kt | 2 +- .../build.gradle.kts | 22 +---------- .../libsodium-wrappers-sumo-0.7.6.tgz | Bin 0 -> 15788 bytes .../com/ionspin/kotlin/crypto/Crypto.kt | 2 +- .../com/ionspin/kotlin/crypto/SRNGTest.kt | 2 - .../kotlin/crypto/hash/sha/Sha256Test.kt | 13 ++++++ .../kotlin/crypto/hash/sha/Sha512Test.kt | 37 ++++++++++++++++++ .../com/ionspin/kotlin/crypto/Initializer.kt | 2 + .../kotlin/crypto/JsSodiumInterface.kt | 23 +++++++++-- .../ionspin/kotlin/crypto/JsSodiumLoader.kt | 12 +++++- .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 2 - .../crypto/hash/blake2b/Blake2bDelegated.kt | 11 ++---- .../kotlin/crypto/hash/sha/Sha256Delegated.kt | 29 +++++++++----- .../kotlin/crypto/hash/sha/Sha512Delegated.kt | 30 +++++++++++--- .../src/jsMain/kotlin/libsodium.kt | 7 ++++ .../crypto/hash/blake2b/Blake2bDelegated.kt | 4 -- .../hash/sha/Sha256StatelessDelegated.kt | 4 -- .../kotlin/crypto/hash/sha/Sha512Delegated.kt | 4 -- .../crypto/hash/blake2b/Blake2bDelegated.kt | 5 --- .../kotlin/crypto/hash/sha/Sha256Delegated.kt | 4 +- .../kotlin/crypto/hash/sha/Sha512Delegated.kt | 4 +- .../crypto/hash/blake2b/Blake2bLinuxTest.kt | 2 +- .../hash/blake2b/Sha512DelegatedLinuxTest.kt | 2 +- .../kotlin/crypto/hash/blake2b/Blake2bPure.kt | 2 +- .../kotlin/crypto/hash/sha/Sha256Pure.kt | 2 +- .../kotlin/crypto/hash/sha/Sha512Pure.kt | 2 +- .../ionspin/kotlin/crypto/sample/Sample.kt | 3 +- 30 files changed, 170 insertions(+), 89 deletions(-) create mode 100644 multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz create mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt diff --git a/EXTERNAL_LICENSES b/EXTERNAL_LICENSES index 68bdf97..04005dc 100644 --- a/EXTERNAL_LICENSES +++ b/EXTERNAL_LICENSES @@ -21,3 +21,23 @@ Libsodium, licensed under ISC License * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +Libsodium.js (temporarily included libsodium-wrappers-sumo-0.7.6.tgz packed npm package with additional sha256 and sha512 multipart wrappers) + + +Copyright (c) 2015-2020 +Ahmad Ben Mrad +Frank Denis +Ryan Lester + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 7bd3d2f..5b04e3c 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -58,8 +58,9 @@ object Deps { val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Versions.kotlinSerialization}" object Npm { - val libsodium = Pair("libsodium-sumo", "0.7.6") - val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.6") + val libsodium = Pair("libsodium-wrappers-sumo", "0.7.6") +// val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.6") + val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "file:/home/ionspin/Projects/Future/kotlin-multiplatform-crypto/multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz") } } diff --git a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt index 0daec9d..8d9ebc3 100644 --- a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt +++ b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/Hash.kt @@ -30,8 +30,6 @@ interface Hash { interface UpdatableHash : Hash { fun update(data : UByteArray) - fun update(data : String) - fun digest() : UByteArray } diff --git a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512.kt b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512.kt index b77b567..f60e92d 100644 --- a/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512.kt +++ b/multiplatform-crypto-api/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512.kt @@ -17,7 +17,7 @@ interface Sha512 : UpdatableHash { } interface StatelessSha512 : StatelessHash { override val MAX_HASH_BYTES: Int - get() = Sha256Properties.MAX_HASH_BYTES + get() = Sha512Properties.MAX_HASH_BYTES fun digest( inputMessage: UByteArray = ubyteArrayOf() diff --git a/multiplatform-crypto-delegated/build.gradle.kts b/multiplatform-crypto-delegated/build.gradle.kts index 9b1391e..2698e6d 100644 --- a/multiplatform-crypto-delegated/build.gradle.kts +++ b/multiplatform-crypto-delegated/build.gradle.kts @@ -435,7 +435,6 @@ kotlin { dependencies { implementation(kotlin(Deps.Js.stdLib)) implementation(Deps.Js.coroutines) - implementation(npm(Deps.Js.Npm.libsodium.first, Deps.Js.Npm.libsodium.second)) implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second)) } } @@ -443,7 +442,7 @@ kotlin { dependencies { implementation(Deps.Js.coroutines) implementation(kotlin(Deps.Js.test)) - implementation(npm(Deps.Js.Npm.libsodium.first, Deps.Js.Npm.libsodium.second)) + implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second)) } } val linuxX64Main by getting { @@ -529,14 +528,6 @@ kotlin { -task("copyPackageJson") { - dependsOn("compileKotlinJs") - println("Copying package.json from $projectDir/core/src/jsMain/npm") - from("$projectDir/src/jsMain/npm") - println("Node modules dir ${node.nodeModulesDir}") - into("${node.nodeModulesDir}") -} - tasks { @@ -547,17 +538,6 @@ tasks { } dokka { - println("Dokka !") - impliedPlatforms = mutableListOf("Common") - kotlinTasks { - listOf() - } - sourceRoot { - println("Common !") - path = - "/home/ionspin/Projects/Future/kotlin-multiplatform-crypto/crypto/src/commonMain" //TODO remove static path! - platforms = listOf("Common") - } } if (getHostOsName() == "linux" && getHostArchitecture() == "x86-64") { val jvmTest by getting(Test::class) { diff --git a/multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz b/multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz new file mode 100644 index 0000000000000000000000000000000000000000..97837caa202d8ac65b43e59fc5d42a9ecb41512f GIT binary patch literal 15788 zcmV;dJyXITiwFP!000001MPi#f7>>)=>Dxw!D!DfmDaE#J5J)-QF;|eNxbzVYdLLm zd~;};ge+DPsgjT_HTC`McLo4S@J-szWA{YAHkOFjVBP}^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0&aOc`x5T}3^vPfX^sbG zGEP+&s7Yhtpb5hbGYdJ_H28NQzeEed6l~JXY#;aOl$ClB5=+*S@0=#3LH3J+0wIveIL1$dJP^V4|>HOsO!M2yS-(2kU*sSrC_fDtiKar=t;Ux@yR>Jo|&+5^YZU*LPQq_A_+upIx6c7;h2) { setSodiumPointer(promisedSodium) sodiumLoaded = true diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt index 5c5269e..862aae9 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt @@ -28,8 +28,6 @@ actual object SRNG { actual fun getRandomBytes(amount: Int): UByteArray { val randomBytes = getSodium().randombytes_buf(amount) - println("Random bytes: $randomBytes") - print("Byte at ${randomBytes[0]}") val randomBytesUByteArray = UByteArray(amount) { 0U } diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt index 0264c09..ce671a1 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt @@ -3,6 +3,7 @@ package com.ionspin.kotlin.crypto.hash.blake2b import com.ionspin.kotlin.crypto.getSodium import com.ionspin.kotlin.crypto.util.toHexString import org.khronos.webgl.Uint8Array +import org.khronos.webgl.get /** * Created by Ugljesa Jovanovic @@ -19,9 +20,7 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I TODO("not implemented yet") } - override fun update(data: String) { - TODO("not implemented yet") - } + override fun digest(): UByteArray { TODO("not implemented yet") @@ -38,11 +37,7 @@ actual object Blake2bDelegatedStateless : Blake2bStateless { val hashed = getSodium().crypto_generichash(64, Uint8Array(inputMessage.toByteArray().toTypedArray())) val hash = UByteArray(MAX_HASH_BYTES) for (i in 0 until MAX_HASH_BYTES) { - js( - """ - hash[i] = hashed[i] - """ - ) + hash[i] = hashed[i].toUByte() } return hash } diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt index 59646da..79806a7 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt @@ -2,7 +2,11 @@ package com.ionspin.kotlin.crypto.hash.sha import com.ionspin.kotlin.crypto.getSodium import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegatedStateless + +import ext.libsodium.crypto_hash_sha256_init + import org.khronos.webgl.Uint8Array +import org.khronos.webgl.get /** * Created by Ugljesa Jovanovic @@ -12,16 +16,25 @@ import org.khronos.webgl.Uint8Array actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: Int) : Sha256 { - override fun update(data: UByteArray) { - TODO("not implemented yet") + + val state : dynamic + + init { + state = getSodium().crypto_hash_sha256_init() } - override fun update(data: String) { - TODO("not implemented yet") + override fun update(data: UByteArray) { + getSodium().crypto_hash_sha256_update(state, Uint8Array(data.toByteArray().toTypedArray())) } override fun digest(): UByteArray { - TODO("not implemented yet") + val hashed = getSodium().crypto_hash_sha256_final(state) + val hash = UByteArray(Sha256StatelessDelegated.MAX_HASH_BYTES) + console.log(hashed) + for (i in 0 until Sha256StatelessDelegated.MAX_HASH_BYTES) { + hash[i] = hashed[i].toUByte() + } + return hash } } @@ -32,11 +45,7 @@ actual object Sha256StatelessDelegated : StatelessSha256 { val hashed = getSodium().crypto_hash_sha256(Uint8Array(inputMessage.toByteArray().toTypedArray())) val hash = UByteArray(MAX_HASH_BYTES) for (i in 0 until MAX_HASH_BYTES) { - js( - """ - hash[i] = hashed[i] - """ - ) + hash[i] = hashed[i].toUByte() } return hash } diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index e009d55..d5edc24 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -1,5 +1,11 @@ package com.ionspin.kotlin.crypto.hash.sha +import com.ionspin.kotlin.crypto.getSodium +import com.ionspin.kotlin.crypto.getSodium + +import org.khronos.webgl.Uint8Array +import org.khronos.webgl.get + /** * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com @@ -8,16 +14,23 @@ package com.ionspin.kotlin.crypto.hash.sha actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: Int) : Sha512 { - override fun update(data: UByteArray) { - TODO("not implemented yet") + val state : dynamic + + init { + state = getSodium().crypto_hash_sha512_init() } - override fun update(data: String) { - TODO("not implemented yet") + override fun update(data: UByteArray) { + getSodium().crypto_hash_sha512_update(state, Uint8Array(data.toByteArray().toTypedArray())) } override fun digest(): UByteArray { - TODO("not implemented yet") + val hashed = getSodium().crypto_hash_sha512_final(state) + val hash = UByteArray(Sha512StatelessDelegated.MAX_HASH_BYTES) + for (i in 0 until Sha512StatelessDelegated.MAX_HASH_BYTES) { + hash[i] = hashed[i].toUByte() + } + return hash } } @@ -25,6 +38,11 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In actual object Sha512StatelessDelegated : StatelessSha512 { override fun digest(inputMessage: UByteArray): UByteArray { - TODO("not implemented yet") + val hashed = getSodium().crypto_hash_sha512(Uint8Array(inputMessage.toByteArray().toTypedArray())) + val hash = UByteArray(Sha512StatelessDelegated.MAX_HASH_BYTES) + for (i in 0 until Sha512StatelessDelegated.MAX_HASH_BYTES) { + hash[i] = hashed[i].toUByte() + } + return hash } } \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/libsodium.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/libsodium.kt index 428b3bd..f37c329 100644 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/libsodium.kt +++ b/multiplatform-crypto-delegated/src/jsMain/kotlin/libsodium.kt @@ -18,4 +18,11 @@ external val _libsodiumPromise : Promise external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array +external fun crypto_hash_sha512(message: Uint8Array) : Uint8Array + +external fun crypto_hash_sha256_init(): dynamic + + + + diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt index b787229..68f65ae 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt @@ -13,10 +13,6 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I TODO("not implemented yet") } - override fun update(data: String) { - TODO("not implemented yet") - } - override fun digest(): UByteArray { TODO("not implemented yet") } diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt index 0b2e83c..caf5973 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256StatelessDelegated.kt @@ -15,10 +15,6 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun update(data: String) { - TODO("not implemented yet") - } - override fun digest(): UByteArray { TODO("not implemented yet") } diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index e009d55..8ee0645 100644 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -12,10 +12,6 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun update(data: String) { - TODO("not implemented yet") - } - override fun digest(): UByteArray { TODO("not implemented yet") } diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt index 98d765d..d6fd6ef 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt @@ -32,11 +32,6 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I crypto_generichash_update(state.ptr, data.toCValues(), data.size.convert()) } - override fun update(data: String) { - val ubyteArray = data.encodeToByteArray().toUByteArray() - crypto_generichash_update(state.ptr, ubyteArray.toCValues(), ubyteArray.size.convert()) - } - override fun digest(): UByteArray { val hashResult = UByteArray(requestedHashLength) val hashResultPinned = hashResult.pin() diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt index 52fa7ce..0b17a98 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt @@ -20,9 +20,7 @@ actual class Sha256Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun update(data: String) { - TODO("not implemented yet") - } + override fun digest(): UByteArray { TODO("not implemented yet") diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt index e009d55..00b54fa 100644 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt @@ -12,9 +12,7 @@ actual class Sha512Delegated actual constructor(key: UByteArray?, hashLength: In TODO("not implemented yet") } - override fun update(data: String) { - TODO("not implemented yet") - } + override fun digest(): UByteArray { TODO("not implemented yet") diff --git a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt index 25898a5..f50ecbf 100644 --- a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt +++ b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt @@ -27,7 +27,7 @@ class Blake2bLinuxTest { @Test fun testBlake2bUpdateable() = testBlocking { val blake2b = Crypto.Blake2b.updateable() - blake2b.update("test") + blake2b.update("test".encodeToUByteArray()) val result = blake2b.digest().toHexString() println(result) assertTrue { result.length > 2 } diff --git a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Sha512DelegatedLinuxTest.kt b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Sha512DelegatedLinuxTest.kt index b01796d..5dabed5 100644 --- a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Sha512DelegatedLinuxTest.kt +++ b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Sha512DelegatedLinuxTest.kt @@ -27,7 +27,7 @@ class Sha512DelegatedLinuxTest { @Test fun testBlake2bUpdateable() = testBlocking { val blake2b = Crypto.Blake2b.updateable() - blake2b.update("test") + blake2b.update("test".encodeToUByteArray()) val result = blake2b.digest().toHexString() println(result) assertTrue { result.length > 2 } diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt index dd8e75c..a3c5bef 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt @@ -309,7 +309,7 @@ class Blake2bPure(val key: UByteArray? = null, val hashLength: Int = 64) : Blake } - override fun update(data: String) { + fun update(data: String) { update(data.encodeToByteArray().toUByteArray()) } diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt index 9425620..0f0950f 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt @@ -235,7 +235,7 @@ class Sha256Pure : Sha256 { var buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { 0U } - override fun update(data: String) { + fun update(data: String) { return update(data.encodeToByteArray().toUByteArray()) } diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt index 3c839d6..7fe3eee 100644 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt @@ -309,7 +309,7 @@ class Sha512Pure : Sha512 { var buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { 0U } - override fun update(data: String) { + fun update(data: String) { return update(data.encodeToByteArray().toUByteArray()) } 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 d27e1dd..effa995 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 @@ -3,6 +3,7 @@ package com.ionspin.kotlin.crypto.sample import com.ionspin.kotlin.crypto.Crypto import com.ionspin.kotlin.crypto.CryptoProvider import com.ionspin.kotlin.crypto.hash.blake2b.Blake2b +import com.ionspin.kotlin.crypto.hash.encodeToUByteArray import com.ionspin.kotlin.crypto.util.toHexString import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -20,7 +21,7 @@ object Sample { fun blake2b() { println("Blake2b updateable") val blake2bUpdateable = Crypto.Blake2b.updateable() - blake2bUpdateable.update("test") + blake2bUpdateable.update("test".encodeToUByteArray()) println(blake2bUpdateable.digest().toHexString()) println("Blake2b stateless") val statelessResult = Crypto.Blake2b.stateless("test".encodeToByteArray().toUByteArray())