From 48d81f257e75d7d876a138f603ad57cc9788a5c8 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Sat, 14 Nov 2020 13:27:42 +0100 Subject: [PATCH 01/11] Add more doc copied from libsodium --- README.md | 2 + doc/res/libsodium_api_mapping.svg | 91 +++++++++++++++++++ .../com.ionspin.kotlin.crypto/box/Box.kt | 36 +++++++- .../kotlin/crypto/sample/DataPackage.kt | 36 ++++++++ .../kotlin/crypto/sample/FileWrapper.kt | 11 +++ .../crypto/sample/ui/LandingController.kt | 1 + .../sample/workbench/WorkbenchController.kt | 7 ++ .../sample/workbench/WorkbenchElement.kt | 10 ++ .../crypto/sample/workbench/WorkbenchView.kt | 10 ++ 9 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 doc/res/libsodium_api_mapping.svg create mode 100644 sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/DataPackage.kt create mode 100644 sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/FileWrapper.kt create mode 100644 sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchController.kt create mode 100644 sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchElement.kt create mode 100644 sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchView.kt diff --git a/README.md b/README.md index 5b76552..0abc43b 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ And here is the usage sample The functions are mapped from libsodium to kotiln objects, so `crypto_secretstream_xchacha20poly1305_init_push` becomes `SecretStream.xChaCha20Poly1305InitPush` +![Alt text](./doc/res/libsodium_api_mapping.svg) At the moment you should refer to original libsodium documentation for instructions on how to use the library @@ -139,6 +140,7 @@ Currently supported native platforms: - Android testing - Fix browser testing, both locally and in CI/CD - LobsodiumUtil `unpad` and `fromBase64` native implementations use a nasty hack to support shared native sourceset. The hack either needs to be removed and replaced with another solution or additional safeguards need to be added. +- Complete exposing libsodium constants diff --git a/doc/res/libsodium_api_mapping.svg b/doc/res/libsodium_api_mapping.svg new file mode 100644 index 0000000..a4ab378 --- /dev/null +++ b/doc/res/libsodium_api_mapping.svg @@ -0,0 +1,91 @@ + + + + + + + + image/svg+xml + + + + + + + crypto_secretstream_xchacha20poly1305_init_push + SecretStream.xChaCha20Poly1305InitPush + + diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.kt index fdbc907..6afa9b8 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.kt @@ -19,6 +19,40 @@ data class BoxEncryptedDataAndTag(val ciphertext: UByteArray, val tag: UByteArra class BoxCorruptedOrTamperedDataException() : RuntimeException("MAC validation failed. Data is corrupted or tampered with.") +/** + * Authenticated encryption (crypto_box_* API) + * + * Using public-key authenticated encryption, Bob can encrypt a confidential message specifically for Alice, using Alice's public key. + * Using Bob's public key, Alice can compute a shared secret key. Using Alice's public key and his secret key, + * Bob can compute the exact same shared secret key. That shared secret key can be used to verify that the encrypted + * message was not tampered with, before eventually decrypting it. + * Alice only needs Bob's public key, the nonce and the ciphertext. Bob should never ever share his secret key, + * even with Alice. + * And in order to send messages to Alice, Bob only needs Alice's public key. Alice should never ever share her secret + * key either, even with Bob. + * Alice can reply to Bob using the same system, without having to generate a distinct key pair. + * The nonce doesn't have to be confidential, but it should be used with just one invocation of crypto_box_easy() for a + * particular pair of public and secret keys. + * One easy way to generate a nonce is to use randombytes_buf(), considering the size of the nonces the risk of any + * random collisions is negligible. For some applications, if you wish to use nonces to detect missing messages or to + * ignore replayed messages, it is also acceptable to use a simple incrementing counter as a nonce. A better alternative + * is to use the crypto_secretstream() API. + * When doing so you must ensure that the same value can never be re-used (for example you may have multiple threads + * or even hosts generating messages using the same key pairs). + * As stated above, senders can decrypt their own messages, and compute a valid authentication tag for any messages + * encrypted with a given shared secret key. This is generally not an issue for online protocols. If this is not + * acceptable, check out the Sealed Boxes section, as well as the Key Exchange section in this documentation. + * + * + * Sealed boxes (crypto_box_seal_* API) + * + * Sealed boxes are designed to anonymously send messages to a recipient given its public key. + * Only the recipient can decrypt these messages, using its private key. While the recipient can verify the integrity + * of the message, it cannot verify the identity of the sender. + * A message is encrypted using an ephemeral key pair, whose secret part is destroyed right after the encryption process. + * Without knowing the secret key used for a given message, the sender cannot decrypt its own message later. + * And without additional data, a message cannot be correlated with the identity of its sender. + */ expect object Box { /** * The crypto_box_keypair() function randomly generates a secret key and a corresponding public key. @@ -87,4 +121,4 @@ expect object Box { fun sealOpen(ciphertext: UByteArray, recipientsPublicKey: UByteArray, recipientsSecretKey: UByteArray) : UByteArray -} \ No newline at end of file +} diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/DataPackage.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/DataPackage.kt new file mode 100644 index 0000000..b6e85ca --- /dev/null +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/DataPackage.kt @@ -0,0 +1,36 @@ +package com.ionspin.kotlin.crypto.sample + +import com.ionspin.kotlin.crypto.util.encodeToUByteArray +import com.ionspin.kotlin.crypto.util.hexStringToUByteArray + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 30-Oct-2020 + */ +interface DataPackage { + fun getContentAsUByteArray() : UByteArray + fun getStringRepresentation() : String +} + +data class Utf8StringData(val content: String) : DataPackage { + override fun getContentAsUByteArray(): UByteArray { + return content.encodeToUByteArray() + } + + override fun getStringRepresentation(): String { + return content + } +} + +data class HexadecimalStringData(val content: String) : DataPackage { + override fun getContentAsUByteArray(): UByteArray { + return content.hexStringToUByteArray() + } + + override fun getStringRepresentation(): String { + return content + } +} + +data class FileData(val filePath: ) diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/FileWrapper.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/FileWrapper.kt new file mode 100644 index 0000000..bc3411a --- /dev/null +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/FileWrapper.kt @@ -0,0 +1,11 @@ +package com.ionspin.kotlin.crypto.sample + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 30-Oct-2020 + */ +expect class FileWrapper(path: String) { + fun exists() : Boolean + fun rea +} diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/ui/LandingController.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/ui/LandingController.kt index 3166bc3..730bfb7 100644 --- a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/ui/LandingController.kt +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/ui/LandingController.kt @@ -7,4 +7,5 @@ package com.ionspin.kotlin.crypto.sample.ui */ class LandingController { + } diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchController.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchController.kt new file mode 100644 index 0000000..3fb409d --- /dev/null +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchController.kt @@ -0,0 +1,7 @@ +package com.ionspin.kotlin.crypto.sample.workbench + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 30-Oct-2020 + */ diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchElement.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchElement.kt new file mode 100644 index 0000000..95f831f --- /dev/null +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchElement.kt @@ -0,0 +1,10 @@ +package com.ionspin.kotlin.crypto.sample.workbench + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 30-Oct-2020 + */ +interface WorkbenchElement { + +} diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchView.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchView.kt new file mode 100644 index 0000000..59ad00f --- /dev/null +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/workbench/WorkbenchView.kt @@ -0,0 +1,10 @@ +package com.ionspin.kotlin.crypto.sample.workbench + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 30-Oct-2020 + */ +interface WorkbenchView { + +} From 6a87267ed6de88caa048aec2e391f8da4c2d56eb Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Sun, 15 Nov 2020 19:43:08 +0100 Subject: [PATCH 02/11] Add html dokka and ubyte array decode extension --- .../build.gradle.kts | 10 ++++++++++ .../kotlin/com.ionspin.kotlin.crypto/util/Util.kt | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index b06227f..fb12465 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -601,6 +601,16 @@ tasks { } + + dokkaHtml { + println("Dokka Html!") + dokkaSourceSets { + create("commonMain") { + displayName = "common" + platform = "common" + } + } + } if (getHostOsName() == "linux" && getHostArchitecture() == "x86-64") { val jvmTest by getting(Test::class) { testLogging { diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/util/Util.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/util/Util.kt index b3034e7..97cb9f7 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/util/Util.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/util/Util.kt @@ -9,10 +9,14 @@ fun String.hexStringToUByteArray() : UByteArray { return this.chunked(2).map { it.toUByte(16) }.toUByteArray() } -fun String.encodeToUByteArray() : UByteArray{ + fun String.encodeToUByteArray() : UByteArray{ return encodeToByteArray().asUByteArray() } + fun UByteArray.decodeFromUByteArray() : String { + return asByteArray().decodeToString() +} + fun UByteArray.toHexString() : String { return this.joinToString(separator = "") { if (it <= 0x0FU) { From a70bb5243cf148cbce26afacd427ec280c7ef5b8 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Tue, 17 Nov 2020 23:27:49 +0100 Subject: [PATCH 03/11] Bump dokka, update dokka calls, add test md package and module docs --- buildSrc/src/main/kotlin/Deps.kt | 4 ++-- multiplatform-crypto-api/build.gradle.kts | 7 +++--- .../build.gradle.kts | 7 +++--- .../build.gradle.kts | 22 ++++++++++++++----- .../com.ionspin.kotlin.crypto/CryptoModule.md | 3 +++ .../com.ionspin.kotlin.crypto/aead/Aead.md | 4 ++++ multiplatform-crypto/build.gradle.kts | 7 +++--- .../kotlin/crypto/sample/DataPackage.kt | 2 +- .../kotlin/crypto/sample/FileWrapper.kt | 8 +++---- 9 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md create mode 100644 multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 395c929..e52ba03 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -15,13 +15,13 @@ */ object Versions { - val kotlinCoroutines = "1.3.9" + val kotlinCoroutines = "1.4.1" val kotlin = "1.4.10" val kotlinSerialization = "1.0.0" val kotlinSerializationPlugin = "1.4.10" val atomicfu = "0.14.3-M2-2-SNAPSHOT" //NOTE: my linux arm32 and arm64 build val nodePlugin = "1.3.0" - val dokkaPlugin = "1.4.0-rc" + val dokkaPlugin = "1.4.0" val taskTreePlugin = "1.5" val kotlinBigNumVersion = "0.2.2" val lazySodium = "4.3.1-SNAPSHOT" diff --git a/multiplatform-crypto-api/build.gradle.kts b/multiplatform-crypto-api/build.gradle.kts index 7cb696a..4c655f0 100644 --- a/multiplatform-crypto-api/build.gradle.kts +++ b/multiplatform-crypto-api/build.gradle.kts @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest +import org.jetbrains.dokka.Platform plugins { kotlin(PluginsDeps.multiplatform) @@ -275,9 +276,9 @@ tasks { dokkaJavadoc { println("Dokka !") dokkaSourceSets { - create("commonMain") { - displayName = "common" - platform = "common" + named("commonMain") { + displayName.set("common") + platform.set(Platform.common) } } diff --git a/multiplatform-crypto-delegated/build.gradle.kts b/multiplatform-crypto-delegated/build.gradle.kts index 77b5912..0515eff 100644 --- a/multiplatform-crypto-delegated/build.gradle.kts +++ b/multiplatform-crypto-delegated/build.gradle.kts @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest +import org.jetbrains.dokka.Platform plugins { kotlin(PluginsDeps.multiplatform) @@ -566,9 +567,9 @@ tasks { dokkaJavadoc { println("Dokka !") dokkaSourceSets { - create("commonMain") { - displayName = "common" - platform = "common" + named("commonMain") { + displayName.set("common") + platform.set(Platform.common) } } diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index fb12465..5c00c55 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest +import org.jetbrains.dokka.Platform plugins { kotlin(PluginsDeps.multiplatform) @@ -593,9 +594,9 @@ tasks { dokkaJavadoc { println("Dokka !") dokkaSourceSets { - create("commonMain") { - displayName = "common" - platform = "common" + named("commonMain") { + displayName.set("common") + platform.set(Platform.common) } } @@ -605,9 +606,18 @@ tasks { dokkaHtml { println("Dokka Html!") dokkaSourceSets { - create("commonMain") { - displayName = "common" - platform = "common" + named("commonMain") { +// displayName.set("common") +// platform.set(Platform.common) + moduleDisplayName.set("Kotlin Multiplatform Libsodium Bindings") + includes.from("src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md", + "src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md") + displayName.set("Kotlin multiplatform") + } + configureEach { + if (name != "commonMain") { + suppress.set(true) + } } } } diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md new file mode 100644 index 0000000..2c3c0a5 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md @@ -0,0 +1,3 @@ +# Module Kotlin Multiplatform Libsodium Bindings + +Test test test diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md new file mode 100644 index 0000000..b302ce5 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md @@ -0,0 +1,4 @@ +# Package com.ionspin.kotlin.crypto.aead + +Package AEAD stuff here + diff --git a/multiplatform-crypto/build.gradle.kts b/multiplatform-crypto/build.gradle.kts index d458d71..f7dd2a6 100644 --- a/multiplatform-crypto/build.gradle.kts +++ b/multiplatform-crypto/build.gradle.kts @@ -18,6 +18,7 @@ @file:Suppress("UnstableApiUsage") import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest +import org.jetbrains.dokka.Platform plugins { kotlin(PluginsDeps.multiplatform) @@ -401,9 +402,9 @@ tasks { dokkaJavadoc { println("Dokka !") dokkaSourceSets { - create("commonMain") { - displayName = "common" - platform = "common" + named("commonMain") { + displayName.set("common") + platform.set(Platform.common) } } diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/DataPackage.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/DataPackage.kt index b6e85ca..9dca8ac 100644 --- a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/DataPackage.kt +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/DataPackage.kt @@ -33,4 +33,4 @@ data class HexadecimalStringData(val content: String) : DataPackage { } } -data class FileData(val filePath: ) +//data class FileData(val filePath: ) diff --git a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/FileWrapper.kt b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/FileWrapper.kt index bc3411a..8e874a2 100644 --- a/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/FileWrapper.kt +++ b/sample/src/commonMain/kotlin/com/ionspin/kotlin/crypto/sample/FileWrapper.kt @@ -5,7 +5,7 @@ package com.ionspin.kotlin.crypto.sample * ugljesa.jovanovic@ionspin.com * on 30-Oct-2020 */ -expect class FileWrapper(path: String) { - fun exists() : Boolean - fun rea -} +//expect class FileWrapper(path: String) { +// fun exists() : Boolean +//// fun rea +//} From 6183a2eb6bea4c4fb570b5d2d175f1c363538604 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Wed, 18 Nov 2020 21:03:21 +0100 Subject: [PATCH 04/11] Aead docs --- .../com.ionspin.kotlin.crypto/aead/Aead.md | 25 +++++++++++++++- ...thenticatedEncryptionWithAssociatedData.kt | 29 +++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md index b302ce5..0c325af 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md @@ -1,4 +1,27 @@ # Package com.ionspin.kotlin.crypto.aead -Package AEAD stuff here +## Authenticated encryption with associated data + +This is a form of symmetric encryption, that assures both confidentiality and authenticity of the data. + +In general it works like this: + +Inputs: +- Message to encrypt and authenticate +- Key to use for encryption +- **Unique** nonce +- Additional data that is not encrypted but also authenticated + +Simplified encryption algorithm: +1. Encrypt message with key and nonce +1. Apply MAC to encrypted message + unencrypted associated data to generate authentication data (tag) +1. Send the encrypted data + associated data + authentication data + nonce + +Simplified decryption algorithm: +1. Apply MAC to encrypted message + unencrypted associated data to generate authentication data +1. If the generated authenticated data, and the received authentication data match, proceed, otherwise sound the alarm and stop. +1. Decrypt the encrypted data +1. Return the decrypted data and associated data to the user + + diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 6388806..e19d781 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -22,11 +22,36 @@ val crypto_aead_chacha20poly1305_KEYBYTES = 32 val crypto_aead_chacha20poly1305_NPUBBYTES = 8 val crypto_aead_chacha20poly1305_ABYTES = 16 - +/** + * A data class wrapping returned encrypted data and and tag from aead encrypt functions. + */ data class AeadEncryptedDataAndTag(val data: UByteArray, val tag: UByteArray) -class AeadCorrupedOrTamperedDataException() : RuntimeException("MAC validation failed. Data is corrupted or tampered with.") +/** + * An exception thrown when tag generated from received data and key doesn't match the received tag + */ +class AeadCorrupedOrTamperedDataException() : RuntimeException("Tag (authentication data) validation failed. Data is corrupted or tampered with.") +/** + * This is a form of symmetric encryption, that assures both confidentiality and authenticity of the data. + * + * Offered here are three implementations of (x)ChaCha20-Poly1305 construction: + * - ChaCha20Poly1305 - uses 64bit nonce + * - ChaCha20Poly1305-IETF - uses 96bit nonce (standardised by [RFC8439](https://tools.ietf.org/html/rfc8439) + * - XChaCha20Poly1305 - uses 192bit nonce - recommended choice + * + * The only difference is the size of the nonce, and how is the nonce used. + * + * (x)ChaCha20 is a streaming cipher develop by Daniel J. Bernstein. He is also the author of Poly1305 a fast Message + * Authentication Code system + * + * Libsodium offers two additional variants for each of the aforementioned variants: + * - Combined + * - Detached + * + * Combined mode returns encrypted data and tag as one UByteArray, while detached mode returns them as separate UByteArrays. + * To be kotlin idiomatic we are returning detached tag and encrypted data inside a wrapper data class [AeadEncryptedDataAndTag] + */ expect object AuthenticatedEncryptionWithAssociatedData { // X - Ietf fun xChaCha20Poly1305IetfEncrypt( From 1cfff4dd433058fec77823c976b75ba1f9236cf1 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Wed, 18 Nov 2020 22:28:57 +0100 Subject: [PATCH 05/11] Started adding Auth doc, added aead doc for specific functions --- .../com.ionspin.kotlin.crypto/aead/Aead.md | 7 +- ...thenticatedEncryptionWithAssociatedData.kt | 169 ++++++++++++++++-- .../com.ionspin.kotlin.crypto/auth/Auth.kt | 20 ++- .../com.ionspin.kotlin.crypto/auth/Auth.md | 21 +++ ...thenticatedEncryptionWithAssociatedData.kt | 12 +- .../com/ionspin/kotlin/crypto/auth/Auth.kt | 13 +- ...thenticatedEncryptionWithAssociatedData.kt | 24 +-- .../com/ionspin/kotlin/crypto/auth/Auth.kt | 12 +- ...thenticatedEncryptionWithAssociatedData.kt | 24 +-- .../com/ionspin/kotlin/crypto/auth/Auth.kt | 12 +- 10 files changed, 242 insertions(+), 72 deletions(-) create mode 100644 multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.md diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md index 0c325af..b216ec6 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md @@ -2,7 +2,8 @@ ## Authenticated encryption with associated data -This is a form of symmetric encryption, that assures both confidentiality and authenticity of the data. +This is a form of symmetric encryption, that assures both confidentiality and authenticity of the data to be encrypted as well +as associated data that will not be encrypted. In general it works like this: @@ -14,11 +15,11 @@ Inputs: Simplified encryption algorithm: 1. Encrypt message with key and nonce -1. Apply MAC to encrypted message + unencrypted associated data to generate authentication data (tag) +1. Apply MAC algorithm to encrypted message + unencrypted associated data to generate authentication data (tag) 1. Send the encrypted data + associated data + authentication data + nonce Simplified decryption algorithm: -1. Apply MAC to encrypted message + unencrypted associated data to generate authentication data +1. Apply MAC algorithm to encrypted message + unencrypted associated data to generate authentication data 1. If the generated authenticated data, and the received authentication data match, proceed, otherwise sound the alarm and stop. 1. Decrypt the encrypted data 1. Return the decrypted data and associated data to the user diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index e19d781..3562073 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -30,13 +30,15 @@ data class AeadEncryptedDataAndTag(val data: UByteArray, val tag: UByteArray) /** * An exception thrown when tag generated from received data and key doesn't match the received tag */ -class AeadCorrupedOrTamperedDataException() : RuntimeException("Tag (authentication data) validation failed. Data is corrupted or tampered with.") +class AeadCorrupedOrTamperedDataException() : + RuntimeException("Tag (authentication data) validation failed. Data is corrupted or tampered with.") /** - * This is a form of symmetric encryption, that assures both confidentiality and authenticity of the data. + * This is a form of symmetric encryption, that assures both confidentiality and authenticity of the data to be encrypted as well +as associated data that will not be encrypted. * * Offered here are three implementations of (x)ChaCha20-Poly1305 construction: - * - ChaCha20Poly1305 - uses 64bit nonce + * - ChaCha20Poly1305 - uses 64bit nonce, safe to encrypt * - ChaCha20Poly1305-IETF - uses 96bit nonce (standardised by [RFC8439](https://tools.ietf.org/html/rfc8439) * - XChaCha20Poly1305 - uses 192bit nonce - recommended choice * @@ -51,9 +53,21 @@ class AeadCorrupedOrTamperedDataException() : RuntimeException("Tag (authenticat * * Combined mode returns encrypted data and tag as one UByteArray, while detached mode returns them as separate UByteArrays. * To be kotlin idiomatic we are returning detached tag and encrypted data inside a wrapper data class [AeadEncryptedDataAndTag] + * + * Also provided are key generation convenience functions for each variant. (Which is in practice the same, since the keys + * same length for each variant) */ expect object AuthenticatedEncryptionWithAssociatedData { // X - Ietf + /** + * Encrypt the message and return encrypted data and tag using xChaChaPoly1305 (192 bit nonce) + * + * @param message message to encrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a **unique** nonce + * @param key secret key + * @return encrypted data and tag (in that order) + */ fun xChaCha20Poly1305IetfEncrypt( message: UByteArray, associatedData: UByteArray, @@ -61,13 +75,34 @@ expect object AuthenticatedEncryptionWithAssociatedData { key: UByteArray ): UByteArray + /** + * Check if authentication data (tag) is correct, then decrypt the message and return decrypted data. + * Using xChaChaPoly1305 (192 bit nonce) + * + * @param ciphertextAndTag message to decrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a nonce used to encrypt the message + * @param key secret key + * @return decrypted data + * @throws AeadCorrupedOrTamperedDataException if authentication data (tag) cannot be verified + */ fun xChaCha20Poly1305IetfDecrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray + /** + * Encrypt the message and return encrypted data and tag using xChaChaPoly1305 (192 bit nonce) as + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * + * @param message message to encrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a **unique** nonce + * @param key secret key + * @return encrypted data and tag wrapped inside [AeadEncryptedDataAndTag] data class instance + */ fun xChaCha20Poly1305IetfEncryptDetached( message: UByteArray, associatedData: UByteArray, @@ -75,6 +110,18 @@ expect object AuthenticatedEncryptionWithAssociatedData { key: UByteArray ): AeadEncryptedDataAndTag + /** + * Check if authentication data (tag) is correct, then decrypt the message and return decrypted data. + * Using xChaChaPoly1305 (192 bit nonce) + * + * @param ciphertext message to decrypt + * @param tag authenticatoin data (tag) + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a nonce used to encrypt the message + * @param key secret key + * @return decrypted data + * @throws AeadCorrupedOrTamperedDataException if authentication data (tag) cannot be verified + */ fun xChaCha20Poly1305IetfDecryptDetached( ciphertext: UByteArray, tag: UByteArray, @@ -84,21 +131,48 @@ expect object AuthenticatedEncryptionWithAssociatedData { ): UByteArray // Ietf - + /** + * Encrypt the message and return encrypted data and tag using ChaChaPoly1305-IETF (96 bit nonce) + * + * @param message message to encrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a **unique** nonce + * @param key secret key + * @return encrypted data and tag (in that order) + */ fun chaCha20Poly1305IetfEncrypt( message: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray - + /** + * Check if authentication data (tag) is correct, then decrypt the message and return decrypted data. + * Using ChaChaPoly1305-IETF (96 bit nonce) + * + * @param ciphertextAndTag message to decrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a nonce used to encrypt the message + * @param key secret key + * @return decrypted data + * @throws AeadCorrupedOrTamperedDataException if authentication data (tag) cannot be verified + */ fun chaCha20Poly1305IetfDecrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray - + /** + * Encrypt the message and return encrypted data and tag using ChaChaPoly1305-IETF (96 bit nonce) as + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * + * @param message message to encrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a **unique** nonce + * @param key secret key + * @return encrypted data and tag wrapped inside [AeadEncryptedDataAndTag] data class instance + */ fun chaCha20Poly1305IetfEncryptDetached( message: UByteArray, associatedData: UByteArray, @@ -106,6 +180,18 @@ expect object AuthenticatedEncryptionWithAssociatedData { key: UByteArray ): AeadEncryptedDataAndTag + /** + * Check if authentication data (tag) is correct, then decrypt the message and return decrypted data. + * Using xChaChaPoly1305 (96 bit nonce) + * + * @param ciphertext message to decrypt + * @param tag authenticatoin data (tag) + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a nonce used to encrypt the message + * @param key secret key + * @return decrypted data + * @throws AeadCorrupedOrTamperedDataException if authentication data (tag) cannot be verified + */ fun chaCha20Poly1305IetfDecryptDetached( ciphertext: UByteArray, tag: UByteArray, @@ -115,28 +201,66 @@ expect object AuthenticatedEncryptionWithAssociatedData { ): UByteArray // Original chacha20poly1305 - + /** + * Encrypt the message and return encrypted data and tag using ChaChaPoly1305 (64 bit nonce) + * + * @param message message to encrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a **unique** nonce + * @param key secret key + * @return encrypted data and tag (in that order) + */ fun chaCha20Poly1305Encrypt( message: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray - + /** + * Check if authentication data (tag) is correct, then decrypt the message and return decrypted data. + * Using ChaChaPoly1305 (64 bit nonce) + * + * @param ciphertextAndTag message to decrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a nonce used to encrypt the message + * @param key secret key + * @return decrypted data + * @throws AeadCorrupedOrTamperedDataException if authentication data (tag) cannot be verified + */ fun chaCha20Poly1305Decrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray - + /** + * Encrypt the message and return encrypted data and tag using ChaChaPoly1305 (64 bit nonce) as + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * + * @param message message to encrypt + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a **unique** nonce + * @param key secret key + * @return encrypted data and tag wrapped inside [AeadEncryptedDataAndTag] data class instance + */ fun chaCha20Poly1305EncryptDetached( message: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): AeadEncryptedDataAndTag - + /** + * Check if authentication data (tag) is correct, then decrypt the message and return decrypted data. + * Using xChaChaPoly1305 (64 bit nonce) + * + * @param ciphertext message to decrypt + * @param tag authenticatoin data (tag) + * @param associatedData associated data the won't be encrypted, but will be authenticated + * @param nonce a nonce used to encrypt the message + * @param key secret key + * @return decrypted data + * @throws AeadCorrupedOrTamperedDataException if authentication data (tag) cannot be verified + */ fun chaCha20Poly1305DecryptDetached( ciphertext: UByteArray, tag: UByteArray, @@ -145,9 +269,20 @@ expect object AuthenticatedEncryptionWithAssociatedData { key: UByteArray ): UByteArray - - fun xChaCha20Poly1305IetfKeygen() : UByteArray - fun chaCha20Poly1305IetfKeygen() : UByteArray - fun chaCha20Poly1305Keygen() : UByteArray + /** + * Generate a random 32byte key for use with xChaCha20Poly1305 + * @return secret key + */ + fun xChaCha20Poly1305IetfKeygen(): UByteArray + /** + * Generate a random 32 byte key for use with ChaCha20Poly1305-IETF + * @return secret key + */ + fun chaCha20Poly1305IetfKeygen(): UByteArray + /** + * Generate a random 32 byte key for use with ChaCha20Poly1305 + * @return secret key + */ + fun chaCha20Poly1305Keygen(): UByteArray } diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt index 2b0d120..69a2d70 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt @@ -19,18 +19,32 @@ val crypto_auth_hmacsha256_BYTES = 32 val crypto_auth_hmacsha512_KEYBYTES = 32 val crypto_auth_hmacsha512_BYTES = 64 +/** + * Authentication is a process of generating authentication data (tag) for a certain message. Its purpose is to assure + * that the data hasn't been corrupted or tampered with during the transport. + * + * We support 3 variants: + * - without suffix - HMAC-SHA512-256 (HMAC SHA512 with just the first 256 bits used) + * - *HmacSha256 - HMAC-SHA256 + * - *HmacSha512 - HMAC-SHA512 + * + * Each variant supports three operations: + * - keygen - generate appropriate key for MAC function + * - auth - generate the authentication data (tag/mac) + * - verify - verify that the authenticatoin data (tag/mac) is correct + */ expect object Auth { fun authKeygen() : UByteArray fun auth(message: UByteArray, key: UByteArray) : UByteArray - fun authVerify(mac: UByteArray, message: UByteArray, key: UByteArray) : Boolean + fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean fun authHmacSha256Keygen() : UByteArray fun authHmacSha256(message: UByteArray, key: UByteArray) : UByteArray - fun authHmacSha256Verify(mac: UByteArray, message: UByteArray, key: UByteArray) : Boolean + fun authHmacSha256Verify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean fun authHmacSha512Keygen() : UByteArray fun authHmacSha512(message: UByteArray, key: UByteArray) : UByteArray - fun authHmacSha512Verify(mac: UByteArray, message: UByteArray, key: UByteArray) : Boolean + fun authHmacSha512Verify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean } diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.md new file mode 100644 index 0000000..dd7fa29 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.md @@ -0,0 +1,21 @@ +# Package com.ionspin.kotlin.crypto.auth + +## Authentication + +Authentication is a process of generating authentication data (tag) for a certain message. Its purpose is to assure +that the data hasn't been corrupted or tampered with during the transport. + +In general, it works like this: + +Inputs: +- Message to authenticate +- Key to use for authentication + +Sending side algorithm: +1. Apply MAC to message +1. Send the message + authentication data (tag) + +Receiving side: +1. Apply the MAC to the received message +1. If the generated authenticated data (tag), and the received authentication data (received tag) match, proceed, otherwise sound the alarm and stop. +1. Return the message to the user diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 846ccb7..c74369b 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -26,7 +26,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun xChaCha20Poly1305IetfDecrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray @@ -34,7 +34,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { try { return getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt( null, - ciphertext.toUInt8Array(), + ciphertextAndTag.toUInt8Array(), associatedData.toUInt8Array(), nonce.toUInt8Array(), key.toUInt8Array() @@ -100,7 +100,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun chaCha20Poly1305IetfDecrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray @@ -108,7 +108,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { try { return getSodium().crypto_aead_chacha20poly1305_ietf_decrypt( null, - ciphertext.toUInt8Array(), + ciphertextAndTag.toUInt8Array(), associatedData.toUInt8Array(), nonce.toUInt8Array(), key.toUInt8Array() @@ -174,7 +174,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun chaCha20Poly1305Decrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray @@ -182,7 +182,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { try { return getSodium().crypto_aead_chacha20poly1305_decrypt( null, - ciphertext.toUInt8Array(), + ciphertextAndTag.toUInt8Array(), associatedData.toUInt8Array(), nonce.toUInt8Array(), key.toUInt8Array() diff --git a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt index 50cf35a..338cc3d 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jsMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt @@ -3,7 +3,6 @@ package com.ionspin.kotlin.crypto.auth import com.ionspin.kotlin.crypto.getSodium import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array -import org.khronos.webgl.Uint8Array actual object Auth { actual fun authKeygen(): UByteArray { @@ -18,9 +17,9 @@ actual object Auth { } - actual fun authVerify(mac: UByteArray, message: UByteArray, key: UByteArray): Boolean { + actual fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray): Boolean { return getSodium().crypto_auth_verify( - mac.toUInt8Array(), + tag.toUInt8Array(), message.toUInt8Array(), key.toUInt8Array() ) @@ -38,12 +37,12 @@ actual object Auth { } actual fun authHmacSha256Verify( - mac: UByteArray, + tag: UByteArray, message: UByteArray, key: UByteArray ): Boolean { return getSodium().crypto_auth_hmacsha256_verify( - mac.toUInt8Array(), + tag.toUInt8Array(), message.toUInt8Array(), key.toUInt8Array() ) @@ -61,12 +60,12 @@ actual object Auth { } actual fun authHmacSha512Verify( - mac: UByteArray, + tag: UByteArray, message: UByteArray, key: UByteArray ): Boolean { return getSodium().crypto_auth_hmacsha512_verify( - mac.toUInt8Array(), + tag.toUInt8Array(), message.toUInt8Array(), key.toUInt8Array() ) diff --git a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 8fa92fd..523fb9a 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -29,18 +29,18 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun xChaCha20Poly1305IetfDecrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray { - val message = UByteArray(ciphertext.size - crypto_aead_xchacha20poly1305_ietf_ABYTES) + val message = UByteArray(ciphertextAndTag.size - crypto_aead_xchacha20poly1305_ietf_ABYTES) val validationResult = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt( message.asByteArray(), null, null, - ciphertext.asByteArray(), - ciphertext.size.toLong(), + ciphertextAndTag.asByteArray(), + ciphertextAndTag.size.toLong(), associatedData.asByteArray(), associatedData.size.toLong(), nonce.asByteArray(), @@ -122,18 +122,18 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun chaCha20Poly1305IetfDecrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray { - val message = UByteArray(ciphertext.size - crypto_aead_chacha20poly1305_ietf_ABYTES) + val message = UByteArray(ciphertextAndTag.size - crypto_aead_chacha20poly1305_ietf_ABYTES) val validationResult = sodium.crypto_aead_chacha20poly1305_ietf_decrypt( message.asByteArray(), null, null, - ciphertext.asByteArray(), - ciphertext.size.toLong(), + ciphertextAndTag.asByteArray(), + ciphertextAndTag.size.toLong(), associatedData.asByteArray(), associatedData.size.toLong(), nonce.asByteArray(), @@ -215,18 +215,18 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun chaCha20Poly1305Decrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray { - val message = UByteArray(ciphertext.size - crypto_aead_chacha20poly1305_ABYTES) + val message = UByteArray(ciphertextAndTag.size - crypto_aead_chacha20poly1305_ABYTES) val validationResult = sodium.crypto_aead_chacha20poly1305_decrypt( message.asByteArray(), null, null, - ciphertext.asByteArray(), - ciphertext.size.toLong(), + ciphertextAndTag.asByteArray(), + ciphertextAndTag.size.toLong(), associatedData.asByteArray(), associatedData.size.toLong(), nonce.asByteArray(), diff --git a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt index afaec45..e6b6207 100644 --- a/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt +++ b/multiplatform-crypto-libsodium-bindings/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt @@ -20,9 +20,9 @@ actual object Auth { return mac } - actual fun authVerify(mac: UByteArray, message: UByteArray, key: UByteArray): Boolean { + actual fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray): Boolean { return sodium.crypto_auth_verify( - mac.asByteArray(), + tag.asByteArray(), message.asByteArray(), message.size.toLong(), key.asByteArray() @@ -47,12 +47,12 @@ actual object Auth { } actual fun authHmacSha256Verify( - mac: UByteArray, + tag: UByteArray, message: UByteArray, key: UByteArray ): Boolean { return sodium.crypto_auth_hmacsha256_verify( - mac.asByteArray(), + tag.asByteArray(), message.asByteArray(), message.size.toLong(), key.asByteArray() @@ -77,12 +77,12 @@ actual object Auth { } actual fun authHmacSha512Verify( - mac: UByteArray, + tag: UByteArray, message: UByteArray, key: UByteArray ): Boolean { return sodium.crypto_auth_hmacsha512_verify( - mac.asByteArray(), + tag.asByteArray(), message.asByteArray(), message.size.toLong(), key.asByteArray() diff --git a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 6d0531d..a73788b 100644 --- a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -62,17 +62,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun xChaCha20Poly1305IetfDecrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray { - val ciphertextPinned = ciphertext.pin() + val ciphertextPinned = ciphertextAndTag.pin() val associatedDataPinned = associatedData.pin() val noncePinned = nonce.pin() val keyPinned = key.pin() - val message = UByteArray(ciphertext.size - crypto_aead_xchacha20poly1305_ietf_ABYTES) + val message = UByteArray(ciphertextAndTag.size - crypto_aead_xchacha20poly1305_ietf_ABYTES) val messagePinned = message.pin() val validationResult = crypto_aead_xchacha20poly1305_ietf_decrypt( @@ -80,7 +80,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { null, null, ciphertextPinned.toPtr(), - ciphertext.size.convert(), + ciphertextAndTag.size.convert(), associatedDataPinned.toPtr(), associatedData.size.convert(), noncePinned.toPtr(), @@ -223,17 +223,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun chaCha20Poly1305IetfDecrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray { - val ciphertextPinned = ciphertext.pin() + val ciphertextPinned = ciphertextAndTag.pin() val associatedDataPinned = associatedData.pin() val noncePinned = nonce.pin() val keyPinned = key.pin() - val message = UByteArray(ciphertext.size - crypto_aead_chacha20poly1305_ietf_ABYTES) + val message = UByteArray(ciphertextAndTag.size - crypto_aead_chacha20poly1305_ietf_ABYTES) val messagePinned = message.pin() val validationResult = crypto_aead_chacha20poly1305_ietf_decrypt( @@ -241,7 +241,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { null, null, ciphertextPinned.toPtr(), - ciphertext.size.convert(), + ciphertextAndTag.size.convert(), associatedDataPinned.toPtr(), associatedData.size.convert(), noncePinned.toPtr(), @@ -384,17 +384,17 @@ actual object AuthenticatedEncryptionWithAssociatedData { } actual fun chaCha20Poly1305Decrypt( - ciphertext: UByteArray, + ciphertextAndTag: UByteArray, associatedData: UByteArray, nonce: UByteArray, key: UByteArray ): UByteArray { - val ciphertextPinned = ciphertext.pin() + val ciphertextPinned = ciphertextAndTag.pin() val associatedDataPinned = associatedData.pin() val noncePinned = nonce.pin() val keyPinned = key.pin() - val message = UByteArray(ciphertext.size - crypto_aead_chacha20poly1305_ABYTES) + val message = UByteArray(ciphertextAndTag.size - crypto_aead_chacha20poly1305_ABYTES) val messagePinned = message.pin() val validationResult = crypto_aead_chacha20poly1305_decrypt( @@ -402,7 +402,7 @@ actual object AuthenticatedEncryptionWithAssociatedData { null, null, ciphertextPinned.toPtr(), - ciphertext.size.convert(), + ciphertextAndTag.size.convert(), associatedDataPinned.toPtr(), associatedData.size.convert(), noncePinned.toPtr(), diff --git a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt index 1964240..ecfa2dc 100644 --- a/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt +++ b/multiplatform-crypto-libsodium-bindings/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/auth/Auth.kt @@ -43,8 +43,8 @@ actual object Auth { return mac } - actual fun authVerify(mac: UByteArray, message: UByteArray, key: UByteArray): Boolean { - val macPinned = mac.pin() + actual fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray): Boolean { + val macPinned = tag.pin() val messagePinned = message.pin() val keyPinned = key.pin() val verify = crypto_auth_verify( @@ -90,11 +90,11 @@ actual object Auth { } actual fun authHmacSha256Verify( - mac: UByteArray, + tag: UByteArray, message: UByteArray, key: UByteArray ): Boolean { - val macPinned = mac.pin() + val macPinned = tag.pin() val messagePinned = message.pin() val keyPinned = key.pin() @@ -141,11 +141,11 @@ actual object Auth { } actual fun authHmacSha512Verify( - mac: UByteArray, + tag: UByteArray, message: UByteArray, key: UByteArray ): Boolean { - val macPinned = mac.pin() + val macPinned = tag.pin() val messagePinned = message.pin() val keyPinned = key.pin() From b261a341dbb3241fa0c2e51e9d2d00821c23b5f5 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Wed, 18 Nov 2020 22:36:55 +0100 Subject: [PATCH 06/11] Added auth doc --- .../build.gradle.kts | 4 ++- .../com.ionspin.kotlin.crypto/CryptoModule.md | 9 +++++- ...thenticatedEncryptionWithAssociatedData.kt | 6 ++-- .../com.ionspin.kotlin.crypto/auth/Auth.kt | 30 ++++++++++++++++++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 5c00c55..1c28462 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -610,7 +610,9 @@ tasks { // displayName.set("common") // platform.set(Platform.common) moduleDisplayName.set("Kotlin Multiplatform Libsodium Bindings") - includes.from("src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md", + includes.from( + "src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md", + "src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.md", "src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md") displayName.set("Kotlin multiplatform") } diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md index 2c3c0a5..cffee3f 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md @@ -1,3 +1,10 @@ # Module Kotlin Multiplatform Libsodium Bindings -Test test test +### What +Kotlin Multiplatform Libsodium Bindings is a library providing kotlin idiomatic API to libsodium implementations on various platforms + +### Why +To provide easy to use cryptographic library, based on a well-known and audited libsodium library. T +### How +By using built from source libsodium to provide native implementations, LazySodium (JNA wrapper around libsodium) to provide +JVM and Android implementations and libsodium.js to provide node and browser implementation diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt index 3562073..d5737a0 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/AuthenticatedEncryptionWithAssociatedData.kt @@ -95,7 +95,7 @@ expect object AuthenticatedEncryptionWithAssociatedData { /** * Encrypt the message and return encrypted data and tag using xChaChaPoly1305 (192 bit nonce) as - * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag]) * * @param message message to encrypt * @param associatedData associated data the won't be encrypted, but will be authenticated @@ -165,7 +165,7 @@ expect object AuthenticatedEncryptionWithAssociatedData { ): UByteArray /** * Encrypt the message and return encrypted data and tag using ChaChaPoly1305-IETF (96 bit nonce) as - * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag]) * * @param message message to encrypt * @param associatedData associated data the won't be encrypted, but will be authenticated @@ -235,7 +235,7 @@ expect object AuthenticatedEncryptionWithAssociatedData { ): UByteArray /** * Encrypt the message and return encrypted data and tag using ChaChaPoly1305 (64 bit nonce) as - * separate arrays (but wrapped inside [AeadEncryptedDataAndTag] + * separate arrays (but wrapped inside [AeadEncryptedDataAndTag]) * * @param message message to encrypt * @param associatedData associated data the won't be encrypted, but will be authenticated diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt index 69a2d70..5ea7429 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.kt @@ -34,17 +34,45 @@ val crypto_auth_hmacsha512_BYTES = 64 * - verify - verify that the authenticatoin data (tag/mac) is correct */ expect object Auth { - + /** + * Generate a secret key, meant to be used with auth function. + */ fun authKeygen() : UByteArray + + /** + * Generate a HMAC-SHA512-256 authentication data - Message Authentication Code - tag + */ fun auth(message: UByteArray, key: UByteArray) : UByteArray + + /** + * Verify that given message, secret key and tag, a newly calculated tag matches the received HMAC-SHA512-256 tag. + */ fun authVerify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean + /** + * Generate a secret key, meant to be used with auth function. + */ fun authHmacSha256Keygen() : UByteArray + /** + * Generate a HMAC-SHA256 authentication data - Message Authentication Code - tag + */ fun authHmacSha256(message: UByteArray, key: UByteArray) : UByteArray + /** + * Verify that given message, secret key and tag, a newly calculated tag matches the received HMAC-SHA256 tag. + */ fun authHmacSha256Verify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean + /** + * Generate a secret key, meant to be used with auth function. + */ fun authHmacSha512Keygen() : UByteArray + /** + * Generate a HMAC-SHA512 authentication data - Message Authentication Code - tag + */ fun authHmacSha512(message: UByteArray, key: UByteArray) : UByteArray + /** + * Verify that given message, secret key and tag, a newly calculated tag matches the received HMAC-SHA512 tag. + */ fun authHmacSha512Verify(tag: UByteArray, message: UByteArray, key: UByteArray) : Boolean } From c0a3bd322d8133380bda725ed2073b0c0ca89d09 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Tue, 8 Dec 2020 20:09:44 +0100 Subject: [PATCH 07/11] Box documentation, kotlin 1.4.20 --- buildSrc/src/main/kotlin/Deps.kt | 4 +-- .../build.gradle.kts | 1 + .../com.ionspin.kotlin.crypto/box/Box.kt | 33 +------------------ .../com.ionspin.kotlin.crypto/box/Box.md | 29 ++++++++++++++++ 4 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index e52ba03..edf6f4a 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -16,8 +16,8 @@ object Versions { val kotlinCoroutines = "1.4.1" - val kotlin = "1.4.10" - val kotlinSerialization = "1.0.0" + val kotlin = "1.4.20" + val kotlinSerialization = "1.0.1" val kotlinSerializationPlugin = "1.4.10" val atomicfu = "0.14.3-M2-2-SNAPSHOT" //NOTE: my linux arm32 and arm64 build val nodePlugin = "1.3.0" diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index 1c28462..e71b398 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -613,6 +613,7 @@ tasks { includes.from( "src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md", "src/commonMain/kotlin/com.ionspin.kotlin.crypto/auth/Auth.md", + "src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md", "src/commonMain/kotlin/com.ionspin.kotlin.crypto/CryptoModule.md") displayName.set("Kotlin multiplatform") } diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.kt index 6afa9b8..847fe84 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.kt @@ -20,38 +20,7 @@ data class BoxEncryptedDataAndTag(val ciphertext: UByteArray, val tag: UByteArra class BoxCorruptedOrTamperedDataException() : RuntimeException("MAC validation failed. Data is corrupted or tampered with.") /** - * Authenticated encryption (crypto_box_* API) - * - * Using public-key authenticated encryption, Bob can encrypt a confidential message specifically for Alice, using Alice's public key. - * Using Bob's public key, Alice can compute a shared secret key. Using Alice's public key and his secret key, - * Bob can compute the exact same shared secret key. That shared secret key can be used to verify that the encrypted - * message was not tampered with, before eventually decrypting it. - * Alice only needs Bob's public key, the nonce and the ciphertext. Bob should never ever share his secret key, - * even with Alice. - * And in order to send messages to Alice, Bob only needs Alice's public key. Alice should never ever share her secret - * key either, even with Bob. - * Alice can reply to Bob using the same system, without having to generate a distinct key pair. - * The nonce doesn't have to be confidential, but it should be used with just one invocation of crypto_box_easy() for a - * particular pair of public and secret keys. - * One easy way to generate a nonce is to use randombytes_buf(), considering the size of the nonces the risk of any - * random collisions is negligible. For some applications, if you wish to use nonces to detect missing messages or to - * ignore replayed messages, it is also acceptable to use a simple incrementing counter as a nonce. A better alternative - * is to use the crypto_secretstream() API. - * When doing so you must ensure that the same value can never be re-used (for example you may have multiple threads - * or even hosts generating messages using the same key pairs). - * As stated above, senders can decrypt their own messages, and compute a valid authentication tag for any messages - * encrypted with a given shared secret key. This is generally not an issue for online protocols. If this is not - * acceptable, check out the Sealed Boxes section, as well as the Key Exchange section in this documentation. - * - * - * Sealed boxes (crypto_box_seal_* API) - * - * Sealed boxes are designed to anonymously send messages to a recipient given its public key. - * Only the recipient can decrypt these messages, using its private key. While the recipient can verify the integrity - * of the message, it cannot verify the identity of the sender. - * A message is encrypted using an ephemeral key pair, whose secret part is destroyed right after the encryption process. - * Without knowing the secret key used for a given message, the sender cannot decrypt its own message later. - * And without additional data, a message cannot be correlated with the identity of its sender. + * Box API uses public-key (asymmetric) encryption to */ expect object Box { /** diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md new file mode 100644 index 0000000..30372b0 --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md @@ -0,0 +1,29 @@ +# Package com.ionspin.kotlin.crypto.box + +## Box API - Asymmetric/Public-key authenticated encryption + +Public key encryption is a system that relies on a pair of keys to establish secure communication. + +A simplified overview of communication between Bob and Alice using public-key encryption: +- Key exchange +1. Alice creates 2 keys, one public, one private (public key is actually calculated from the private key) +1. Bob creates 2 keys, one public, one private +1. Alice sends her **public** key to Bob +1. Bob does the same and sends his **public** key to Alice +- Encryption + +Alice wants to establish a secure communication channel with Bob, they already changed public keys in previous steps. +1. Alice uses Bobs **private** key to encrypt a *secret value* (Usually just a key for symmetric encryption) +1. Alice sends encrypted data to Bob +1. Bob is the only one who has the matching private key, and can decrypt the data +1. Bob and Alice now posses the same *secret value* and can start communicating (i.e. by using XChaCha20Poly1305 +symmetric encryption and using the *secret value* as the symmetric key) + +Bob would do the same if he wanted to initiate the secure communication. + +This set of functions also contains another use case called `sealed boxes` in libsodium. +Sealed box is designed to anonymously send a message to a recipient. Libsodium documentation explains it as follows: +> A message is encrypted using an ephemeral key pair, whose secret part is destroyed right after the encryption process. + Without knowing the secret key used for a given message, the sender cannot decrypt its own message later. And without additional data, a message cannot be correlated with the identity of its sender. + + From 69183a0eb940a6ccac1c43544b40b7109ba739ad Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Tue, 5 Jan 2021 10:46:43 +0100 Subject: [PATCH 08/11] Full stack trace in tests --- .../build.gradle.kts | 10 +++++++++- .../generichash/GenericHash.md | 6 ++++++ sample/build.gradle.kts | 10 ++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.md diff --git a/multiplatform-crypto-libsodium-bindings/build.gradle.kts b/multiplatform-crypto-libsodium-bindings/build.gradle.kts index e71b398..7aee1fb 100644 --- a/multiplatform-crypto-libsodium-bindings/build.gradle.kts +++ b/multiplatform-crypto-libsodium-bindings/build.gradle.kts @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest +import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.jetbrains.dokka.Platform plugins { @@ -628,6 +629,9 @@ tasks { val jvmTest by getting(Test::class) { testLogging { events("PASSED", "FAILED", "SKIPPED") + exceptionFormat = TestExceptionFormat.FULL + showStandardStreams = true + showStackTraces = true } } @@ -635,14 +639,18 @@ tasks { testLogging { events("PASSED", "FAILED", "SKIPPED") + exceptionFormat = TestExceptionFormat.FULL showStandardStreams = true + showStackTraces = true } } val jsNodeTest by getting(KotlinJsTest::class) { testLogging { events("PASSED", "FAILED", "SKIPPED") -// showStandardStreams = true + exceptionFormat = TestExceptionFormat.FULL + showStandardStreams = true + showStackTraces = true } } diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.md new file mode 100644 index 0000000..99420aa --- /dev/null +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.md @@ -0,0 +1,6 @@ +# Package com.ionspin.kotlin.crypto.generichash + +## Generic hash + +Generic hash package provides a easy to use + diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index c03b151..295d20b 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest +import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask plugins { @@ -68,21 +69,20 @@ kotlin { } testTask { - enabled = false //Until I sort out testing on travis useKarma { useChrome() } } } nodejs { - testTask { useMocha() { timeout = "10s" } } } - binaries.executable() + +// binaries.executable() } @@ -476,7 +476,9 @@ tasks { testLogging { events("PASSED", "FAILED", "SKIPPED") - // showStandardStreams = true + exceptionFormat = TestExceptionFormat.FULL + showStandardStreams = true + showStackTraces = true } } From b0c6b43f2e6377ee99e575b98758999ba87c7089 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Sat, 9 Jan 2021 12:57:04 +0100 Subject: [PATCH 09/11] Add generic hash docs --- .../com.ionspin.kotlin.crypto/aead/Aead.md | 4 ++-- .../com.ionspin.kotlin.crypto/box/Box.md | 8 ++++--- .../generichash/GenericHash.kt | 24 +++++++++++++++++-- .../generichash/GenericHash.md | 19 ++++++++++++++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md index b216ec6..fea6376 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/aead/Aead.md @@ -5,7 +5,7 @@ This is a form of symmetric encryption, that assures both confidentiality and authenticity of the data to be encrypted as well as associated data that will not be encrypted. -In general it works like this: +In general, it works like this: Inputs: - Message to encrypt and authenticate @@ -14,7 +14,7 @@ Inputs: - Additional data that is not encrypted but also authenticated Simplified encryption algorithm: -1. Encrypt message with key and nonce +1. Encrypt a message with key and nonce 1. Apply MAC algorithm to encrypted message + unencrypted associated data to generate authentication data (tag) 1. Send the encrypted data + associated data + authentication data + nonce diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md index 30372b0..035c9d3 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/box/Box.md @@ -5,14 +5,16 @@ Public key encryption is a system that relies on a pair of keys to establish secure communication. A simplified overview of communication between Bob and Alice using public-key encryption: -- Key exchange +#### Key exchange 1. Alice creates 2 keys, one public, one private (public key is actually calculated from the private key) 1. Bob creates 2 keys, one public, one private 1. Alice sends her **public** key to Bob 1. Bob does the same and sends his **public** key to Alice -- Encryption -Alice wants to establish a secure communication channel with Bob, they already changed public keys in previous steps. +#### Encryption + +Alice wants to establish a secure communication channel with Bob, they already exchanged public keys in previous steps. + 1. Alice uses Bobs **private** key to encrypt a *secret value* (Usually just a key for symmetric encryption) 1. Alice sends encrypted data to Bob 1. Bob is the only one who has the matching private key, and can decrypt the data diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.kt b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.kt index c778647..4c5a829 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.kt +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.kt @@ -21,14 +21,34 @@ data class GenericHashState(val hashLength: Int, val internalState: GenericHashS expect object GenericHash { + /** + * Request computing a hash of message, with a specific hash length and optional key. The specific hash length can be + * between [crypto_generichash_blake2b_BYTES_MIN] and [crypto_generichash_blake2b_BYTES_MAX]. If the key is provided + * it needs the hash will be different for each different key. + */ + fun genericHash(message : UByteArray, requestedHashLength: Int = crypto_generichash_BYTES, key : UByteArray? = null) : UByteArray - fun genericHash(message : UByteArray, requestedHashLength: Int, key : UByteArray? = null) : UByteArray + /** + * Prepare a Generic Hash State object that will be used to compute hash of data with arbitrary length. Secific hash length + * can be requested + */ + fun genericHashInit(requestedHashLength: Int = crypto_generichash_BYTES, key : UByteArray? = null) : GenericHashState - fun genericHashInit(requestedHashLength: Int, key : UByteArray? = null) : GenericHashState + /** + * Feed another chunk of message to the updateable hash object + */ fun genericHashUpdate(state: GenericHashState, messagePart : UByteArray) + + /** + * Feed the last chunk of message to the updateable hash object. This returns the actual hash. + */ fun genericHashFinal(state : GenericHashState) : UByteArray + /** + * Generate a key of length [crypto_generichash_blake2b_KEYBYTES] that can be used with the generic hash funciton + */ fun genericHashKeygen() : UByteArray + // ---- Not present in LazySodium nor libsodium.js // fun blake2b(message : UByteArray, requestedHashLength: Int, key : UByteArray? = null) : UByteArray // diff --git a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.md b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.md index 99420aa..091c997 100644 --- a/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.md +++ b/multiplatform-crypto-libsodium-bindings/src/commonMain/kotlin/com.ionspin.kotlin.crypto/generichash/GenericHash.md @@ -2,5 +2,22 @@ ## Generic hash -Generic hash package provides a easy to use +Generic hash package provides a easy to use hashing API that computes fixed-length fingerprint for an arbitrary long message. +In this case hashing is a process of mapping a set of input bytes to a fixed length (32 bytes) output. Loosely speaking +hash function should be practically irreversible and resistant to collisions (a case where two different inputs result in a same output) + +Some examples of hash function usage: +- Verifying data integrity, i.e. downloading a file and it's hash and then recalculating the hash of the downloaded +file to verify that it hasn't changed +- Creating unique identifiers to index long data +- Password verification, i.e. server stores just the hash of the users password and then when user wants to log in, they send +the password, which server then hashes and compares to the stored hash. This way in case of breach of server security cleartext +passwords are not revealed. With that said **DONT USE GENERIC HASH FOR PASSWORD HASHING**. Use PasswordHash funcitons. + +Underneath this set of functions uses BLAKE2b secure hash function, Here is what Libsodium documentation says about it +>The crypto_generichash_* function set is implemented using BLAKE2b, a simple, standardized (RFC 7693) secure hash +>function that is as strong as SHA-3 but faster than SHA-1 and MD5. +>Unlike MD5, SHA-1 and SHA-256, this function is safe against hash length extension attacks. +>BLAKE2b is not suitable for hashing passwords. For this purpose, use the crypto_pwhash API documented +>in the Password Hashing section. From 85ae96165f6a808253ce4ee3ec097a35d4202afb Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Sat, 9 Jan 2021 13:36:37 +0100 Subject: [PATCH 10/11] Remove pure and delegated, leave api just to trigger fetching konan deps in advance, remove most of it later --- .gitlab-ci.yml | 3 - .travis.yml | 197 -- linuxBuild.sh | 4 +- linuxBuildAndPublish.sh | 4 +- macBuild-ios.sh | 4 - macBuild-mac.sh | 3 - macBuild-pure-ios.sh | 9 - macBuild-pure-mac.sh | 7 - macBuild-pure-tvos.sh | 7 - macBuild-pure-watchos.sh | 8 - macBuild-tvos.sh | 3 - macBuild-watchos.sh | 4 - macBuild.sh | 3 - macBuildAndPublish-ios.sh | 3 - macBuildAndPublish-mac.sh | 1 - macBuildAndPublish-pure-ios.sh | 8 - macBuildAndPublish-pure-mac.sh | 6 - macBuildAndPublish-pure-tvos.sh | 8 - macBuildAndPublish-pure-watchos.sh | 8 - macBuildAndPublish-tvos.sh | 8 - macBuildAndPublish-watchos.sh | 3 - macBuildAndPublishSnapshot-delegated.sh | 15 - .../build.gradle.kts | 698 ------- .../libsodium-wrappers-sumo-0.7.6.tgz | Bin 15788 -> 0 bytes .../com/ionspin/kotlin/crypto/Config.kt | 26 - .../com/ionspin/kotlin/crypto/Crypto.kt | 216 --- .../kotlin/crypto/NativeInlineClassEmitter.kt | 12 - .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 26 - .../DelegatedXChaCha20Poly1305.kt | 24 - .../crypto/hash/blake2b/Blake2bDelegated.kt | 31 - .../kotlin/crypto/hash/sha/Sha256Delegated.kt | 29 - .../kotlin/crypto/hash/sha/Sha512Delegated.kt | 29 - .../crypto/keyderivation/argon2/Argon2.kt | 10 - .../crypto/parallelization/Coroutines14.kt | 34 - .../com/ionspin/kotlin/crypto/util/Util.kt | 216 --- .../com/ionspin/kotlin/crypto/DebugTest.kt | 13 - .../com/ionspin/kotlin/crypto/SRNGTest.kt | 37 - .../authenticated/XChaCha20Poly1305Test.kt | 240 --- .../kotlin/crypto/hash/blake2b/Blake2bTest.kt | 46 - .../kotlin/crypto/hash/sha/Sha256Test.kt | 46 - .../kotlin/crypto/hash/sha/Sha512Test.kt | 48 - .../kotlin/crypto/highlevel/EncryptionTest.kt | 50 - .../ionspin/kotlin/crypto/util/TestUtil.kt | 37 - .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../com/ionspin/kotlin/crypto/Initializer.kt | 43 - .../kotlin/crypto/JsSodiumInterface.kt | 60 - .../ionspin/kotlin/crypto/JsSodiumLoader.kt | 56 - .../com/ionspin/kotlin/crypto/JsUtil.kt | 27 - .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 43 - .../XChaCha20Poly1305Delegated.kt | 130 -- .../crypto/hash/blake2b/Blake2bDelegated.kt | 60 - .../kotlin/crypto/hash/sha/Sha256Delegated.kt | 49 - .../kotlin/crypto/hash/sha/Sha512Delegated.kt | 47 - .../src/jsMain/kotlin/libsodium.kt | 28 - .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../com/ionspin/kotlin/crypto/SRNGJsTest.kt | 52 - .../kotlin/crypto/util/testBlocking.kt | 28 - .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../com/ionspin/kotlin/crypto/Initializer.kt | 25 - .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 34 - .../XChaCha20Poly1305Delegated.kt | 142 -- .../crypto/hash/blake2b/Blake2bDelegated.kt | 40 - .../kotlin/crypto/hash/sha/Sha256Delegated.kt | 41 - .../kotlin/crypto/hash/sha/Sha512Delegated.kt | 40 - .../kotlin/crypto/util/testBlocking.kt | 34 - .../com/ionspin/kotlin/crypto/Placeholder | 0 .../com/ionspin/kotlin/crypto/Placeholder | 0 .../com/ionspin/kotlin/crypto/Placeholder | 0 .../hash/sha/IntelliJCinteropResolverDebug.kt | 9 - .../com/ionspin/kotlin/crypto/Placeholder | 0 .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 44 - .../src/nativeInterop/cinterop/libsodium.def | 6 - .../com/ionspin/kotlin/crypto/Initializer.kt | 30 - .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 40 - .../XChaCha20Poly1305Delegated.kt | 164 -- .../crypto/hash/blake2b/Blake2bDelegated.kt | 61 - .../kotlin/crypto/hash/sha/Sha256Delegated.kt | 55 - .../kotlin/crypto/hash/sha/Sha512Delegated.kt | 50 - .../kotlin/crypto/util/ConversionUtil.kt | 13 - .../com/ionspin/kotlin/crypto/HelperTest.kt | 77 - .../kotlin/crypto/util/testBlocking.kt | 27 - multiplatform-crypto/build.gradle.kts | 522 ------ .../com/ionspin/kotlin/crypto/Config.kt | 26 - .../com/ionspin/kotlin/crypto/Crypto.kt | 155 -- .../kotlin/crypto/NativeInlineClassEmitter.kt | 12 - .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 26 - .../authenticated/ChaCha20Poly1305Pure.kt | 50 - .../authenticated/XChaCha20Poly1305Pure.kt | 203 --- .../kotlin/crypto/hash/blake2b/Blake2bPure.kt | 351 ---- .../kotlin/crypto/hash/sha/Sha256Pure.kt | 328 ---- .../kotlin/crypto/hash/sha/Sha512Pure.kt | 394 ---- .../crypto/keyderivation/argon2/Argon2.kt | 10 - .../keyderivation/argon2/Argon2Exceptions.kt | 31 - .../crypto/keyderivation/argon2/Argon2Pure.kt | 401 ----- .../keyderivation/argon2/Argon2Utils.kt | 167 -- .../keyderivation/argon2/ArgonMatrix.kt | 285 --- .../com/ionspin/kotlin/crypto/mac/Poly1305.kt | 118 -- .../ionspin/kotlin/crypto/symmetric/Aes.kt | 28 - .../kotlin/crypto/symmetric/AesCbcPure.kt | 243 --- .../kotlin/crypto/symmetric/AesCtrPure.kt | 209 --- .../kotlin/crypto/symmetric/AesPure.kt | 361 ---- .../kotlin/crypto/symmetric/ChaCha20Pure.kt | 99 - .../crypto/symmetric/LatinDancesCommon.kt | 55 - .../kotlin/crypto/symmetric/Salsa20Pure.kt | 122 -- .../kotlin/crypto/symmetric/XChaCha20Pure.kt | 179 -- .../kotlin/crypto/symmetric/XSalsa20Pure.kt | 105 -- .../com/ionspin/kotlin/crypto/util/Util.kt | 304 ---- .../com/ionspin/kotlin/crypto/ReadmeTest.kt | 168 -- .../com/ionspin/kotlin/crypto/SRNGTest.kt | 37 - .../com/ionspin/kotlin/crypto/UtilTest.kt | 114 -- .../authenticated/ChaCha20Poly1305Test.kt | 56 - .../authenticated/XChaCha20Poly1305Test.kt | 211 --- .../kotlin/crypto/hash/argon/Argon2KATTest.kt | 158 -- .../crypto/hash/argon/Argon2MatrixTest.kt | 142 -- .../kotlin/crypto/hash/argon/Argon2Test.kt | 403 ----- .../kotlin/crypto/hash/blake2b/Blake2BTest.kt | 295 --- .../hash/blake2b/Blake2bInstanceTest.kt | 94 - .../hash/blake2b/Blake2bKnowAnswerTests.kt | 1603 ----------------- .../kotlin/crypto/hash/sha/Sha256Test.kt | 82 - .../crypto/hash/sha/Sha256UpdateableTest.kt | 134 -- .../kotlin/crypto/hash/sha/Sha512Test.kt | 72 - .../crypto/hash/sha/Sha512UpdateableTest.kt | 87 - .../kotlin/crypto/highlevel/EncryptionTest.kt | 48 - .../ionspin/kotlin/crypto/mac/Poly1305Test.kt | 224 --- .../kotlin/crypto/symmetric/AesCbcTest.kt | 113 -- .../kotlin/crypto/symmetric/AesCtrTest.kt | 105 -- .../kotlin/crypto/symmetric/AesTest.kt | 270 --- .../kotlin/crypto/symmetric/ChaCha20Test.kt | 90 - .../kotlin/crypto/symmetric/Salsa20Test.kt | 395 ---- .../kotlin/crypto/symmetric/XChaCha20Test.kt | 341 ---- .../kotlin/crypto/symmetric/XSalsa20Test.kt | 44 - .../ionspin/kotlin/crypto/util/TestUtil.kt | 36 - .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 60 - .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../com/ionspin/kotlin/crypto/SRNGJsTest.kt | 49 - .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 34 - .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 43 - .../kotlin/com/ionspin/kotlin/crypto/SRNG.kt | 41 - .../ionspin/kotlin/bignum/integer/Placeholder | 0 settings.gradle.kts | 2 - windowsBuild-delegated.sh | 1 - windowsBuild-pure.sh | 6 - windowsBuildAndPublish-delegated.sh | 3 - windowsBuildAndPublish-pure.sh | 7 - 150 files changed, 2 insertions(+), 14089 deletions(-) delete mode 100644 .travis.yml delete mode 100755 macBuild-pure-ios.sh delete mode 100755 macBuild-pure-mac.sh delete mode 100755 macBuild-pure-tvos.sh delete mode 100755 macBuild-pure-watchos.sh delete mode 100755 macBuildAndPublish-pure-ios.sh delete mode 100755 macBuildAndPublish-pure-mac.sh delete mode 100755 macBuildAndPublish-pure-tvos.sh delete mode 100755 macBuildAndPublish-pure-watchos.sh delete mode 100755 macBuildAndPublish-tvos.sh delete mode 100755 macBuildAndPublishSnapshot-delegated.sh delete mode 100644 multiplatform-crypto-delegated/build.gradle.kts delete mode 100644 multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Config.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/NativeInlineClassEmitter.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/DelegatedXChaCha20Poly1305.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt delete mode 100644 multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/util/Util.kt delete mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/DebugTest.kt delete mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SRNGTest.kt delete mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt delete mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bTest.kt delete mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt delete mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt delete mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/highlevel/EncryptionTest.kt delete mode 100644 multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt delete mode 100644 multiplatform-crypto-delegated/src/iosMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto-delegated/src/iosTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/jsMain/kotlin/libsodium.kt delete mode 100644 multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/SRNGJsTest.kt delete mode 100644 multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt delete mode 100644 multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt delete mode 100644 multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt delete mode 100644 multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt delete mode 100644 multiplatform-crypto-delegated/src/linuxArm32HfpMain/kotlin/com/ionspin/kotlin/crypto/Placeholder delete mode 100644 multiplatform-crypto-delegated/src/linuxArm32HfpTest/kotlin/com/ionspin/kotlin/crypto/Placeholder delete mode 100644 multiplatform-crypto-delegated/src/linuxX64Main/kotlin/com/ionspin/kotlin/crypto/Placeholder delete mode 100644 multiplatform-crypto-delegated/src/linuxX64Main/kotlin/com/ionspin/kotlin/crypto/hash/sha/IntelliJCinteropResolverDebug.kt delete mode 100644 multiplatform-crypto-delegated/src/linuxX64Test/kotlin/com/ionspin/kotlin/crypto/Placeholder delete mode 100644 multiplatform-crypto-delegated/src/mingwX64Main/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeInterop/cinterop/libsodium.def delete mode 100644 multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/util/ConversionUtil.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/HelperTest.kt delete mode 100644 multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt delete mode 100644 multiplatform-crypto/build.gradle.kts delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Config.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/NativeInlineClassEmitter.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/ChaCha20Poly1305Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Exceptions.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Utils.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/ArgonMatrix.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/mac/Poly1305.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Aes.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCbcPure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCtrPure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesPure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/ChaCha20Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/LatinDancesCommon.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Salsa20Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/XChaCha20Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/XSalsa20Pure.kt delete mode 100644 multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/util/Util.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ReadmeTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SRNGTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/UtilTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/ChaCha20Poly1305Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2KATTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2MatrixTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2BTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bInstanceTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bKnowAnswerTests.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256UpdateableTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512UpdateableTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/highlevel/EncryptionTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/mac/Poly1305Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCbcTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCtrTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesTest.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/ChaCha20Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/Salsa20Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/XChaCha20Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/XSalsa20Test.kt delete mode 100644 multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt delete mode 100644 multiplatform-crypto/src/iosMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto/src/iosTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/SRNGJsTest.kt delete mode 100644 multiplatform-crypto/src/jvmMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto/src/linuxMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto/src/linuxTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100644 multiplatform-crypto/src/mingwX64Main/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt delete mode 100644 multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder delete mode 100755 windowsBuild-pure.sh delete mode 100755 windowsBuildAndPublish-pure.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d1d11f5..49e9027 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,7 +54,6 @@ macPublishToSnapshot: script: - ./macBuild.sh - ./macBuildAndPublishSnapshot-bindings.sh - - ./macBuildAndPublishSnapshot-delegated.sh only: - master tags: @@ -69,7 +68,6 @@ buildWindows: script: - $env:CHERE_INVOKING = 'yes' - C:\msys64\usr\bin\bash -lc "./windowsBuild-delegated.sh" - - C:\msys64\usr\bin\bash -lc "./windowsBuild-pure.sh" tags: - windowsX64 @@ -78,7 +76,6 @@ windowsPublishToSnapshot: script: - $env:CHERE_INVOKING = 'yes' - C:\msys64\usr\bin\bash -lc "./windowsBuildAndPublish-delegated.sh" - - C:\msys64\usr\bin\bash -lc "./windowsBuildAndPublish-pure.sh" only: - master tags: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 278043b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,197 +0,0 @@ -matrix: - include: - - os: linux - name: linux - language: java - jdk: openjdk12 - - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - #skip ./gradlew assemble that is normally invoked in installation step - install: - - sudo apt-get update - - sudo apt-get -y install automake - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./linuxBuild.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./linuxBuildAndPublish.sh; fi' - # OSX macos - - os: osx - name: osx-mac - osx_image: xcode11.4 - language: java - jdk: openjdk12 - install: true - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./macBuild-mac.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./macBuildAndPublish-mac.sh; fi' - # OSX ios - - os: osx - name: osx-ios - osx_image: xcode11.4 - language: java - jdk: openjdk12 - install: true - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./macBuild-ios.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./macBuildAndPublish-ios.sh; fi' - # OSX watchos - - os: osx - name: osx-watchos - osx_image: xcode11.4 - language: java - jdk: openjdk12 - install: true - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./macBuild-watchos.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./macBuildAndPublish-watchos.sh; fi' - # OSX tvos - - os: osx - name: osx-tvos - osx_image: xcode11.4 - language: java - jdk: openjdk12 - install: true - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./macBuild-tvos.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./macBuildAndPublish-tvos.sh; fi' - - # OSX macos PURE - - os: osx - name: osx-mac-pure - osx_image: xcode11.4 - language: java - jdk: openjdk12 - install: true - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./macBuild-pure-mac.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./macBuildAndPublish-pure-mac.sh; fi' - # OSX ios PURE - - os: osx - name: osx-ios-pure - osx_image: xcode11.4 - language: java - jdk: openjdk12 - install: true - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./macBuild-pure-ios.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./macBuildAndPublish-pure-ios.sh; fi' - # OSX watchos PURE - - os: osx - name: osx-watchos-pure - osx_image: xcode11.4 - language: java - jdk: openjdk12 - install: true - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./macBuild-pure-watchos.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./macBuildAndPublish-pure-watchos.sh; fi' - # OSX tvos PURE - - os: osx - name: osx-tvos-pure - osx_image: xcode11.4 - language: java - jdk: openjdk12 - install: true - env: - KBUILD=linux - JAVA_OPTS=-Xmx2g - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./macBuild-pure-tvos.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./macBuildAndPublish-pure-tvos.sh; fi' - - - os: windows - name: windows-pure - language: shell - jdk: openjdk12 - env: - - GRAVIS="https://raw.githubusercontent.com/DanySK/Gravis-CI/master/" - - JAVA_OPTS=-Xmx2g - - JDK="adopt-openj9@1.11" - before_install: - - curl "${GRAVIS}.install-jdk-travis.sh" --output ~/.install-jdk-travis.sh - - source ~/.install-jdk-travis.sh - install: true - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then $shell ./windowsBuild-pure.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then ./windowsBuildAndPublish-pure.sh; fi' - - os: windows - name: windows-delegated - language: shell - jdk: openjdk12 - env: - - GRAVIS="https://raw.githubusercontent.com/DanySK/Gravis-CI/master/" - - JAVA_OPTS=-Xmx2g - - JDK="adopt-openj9@1.11" - before_install: - - curl "${GRAVIS}.install-jdk-travis.sh" --output ~/.install-jdk-travis.sh - - source ~/.install-jdk-travis.sh - - |- - case $TRAVIS_OS_NAME in - windows) - [[ ! -f C:/tools/msys64/msys2_shell.cmd ]] && rm -rf C:/tools/msys64 - choco uninstall -y mingw - choco upgrade --no-progress -y msys2 bazel - export msys2='cmd //C RefreshEnv.cmd ' - export msys2+='& set MSYS=winsymlinks:nativestrict ' - export msys2+='& C:\\tools\\msys64\\msys2_shell.cmd -defterm -no-start' - export shell="$msys2 -mingw64 -full-path -here -c \$\* --" - export msys2+=" -msys2 -c \$\* --" - $msys2 pacman --sync --noconfirm --needed \ - autoconf \ - automake \ - mingw-w64-x86_64-libtool \ - mingw-w64-x86_64-toolchain \ - perl \ - unzip - taskkill //IM gpg-agent.exe //F - export CPPFLAGS=-D__USE_MINGW_ANSI_STDIO=1 - export PATH=/C/tools/msys64/mingw64/bin:$PATH - export GNU_MAKE=mingw32-make - export MAKE=mingw32-make - export AR=gcc-ar - export RANLIB=gcc-ranlib - export COVERITY_SCAN_BRANCH_PATTERN=disable_coverity_scan - ;; - esac - - export GIT=git - - g++ --version - - $GNU_MAKE --version - - $GIT --version - install: true - before_cache: - - $msys2 pacman --sync --clean --noconfirm - script: - - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then $shell ./windowsBuild-delegated.sh; fi' - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then $shell ./windowsBuildAndPublish-delegated.sh; fi' -cache: - directories: - - $HOME/.m2/ - - $HOME/.gradle - - $HOME/.konan - - $HOME/AppData/Local/Temp/chocolatey - - /C/tools/msys64 -branches: - only: - - master diff --git a/linuxBuild.sh b/linuxBuild.sh index 332984c..4e520d7 100755 --- a/linuxBuild.sh +++ b/linuxBuild.sh @@ -15,10 +15,8 @@ fi ./makeLinuxArm64.sh #now we can do the delegated build cd .. -./gradlew multiplatform-crypto-delegated:build + #build libsodium bindings ./gradlew multiplatform-crypto-libsodium-bindings:build -#and finally pure build -./gradlew multiplatform-crypto:build set +e diff --git a/linuxBuildAndPublish.sh b/linuxBuildAndPublish.sh index 719e4d5..d497cdb 100755 --- a/linuxBuildAndPublish.sh +++ b/linuxBuildAndPublish.sh @@ -15,11 +15,9 @@ fi ./makeLinuxArm64.sh #now we can do the delegated build cd .. -./gradlew multiplatform-crypto-delegated:build #build libsodium bindings ./gradlew multiplatform-crypto-libsodium-bindings:build -#and finally pure build -./gradlew multiplatform-crypto:build + ./gradlew publishJvmPublicationToSnapshotRepository publishJsPublicationToSnapshotRepository \ publishKotlinMultiplatformPublicationToSnapshotRepository publishLinuxX64PublicationToSnapshotRepository \ publishLinuxArm64PublicationToSnapshotRepository publishMetadataPublicationToSnapshotRepository diff --git a/macBuild-ios.sh b/macBuild-ios.sh index 2fbd792..d1143e4 100755 --- a/macBuild-ios.sh +++ b/macBuild-ios.sh @@ -8,10 +8,6 @@ cd sodiumWrapper ./makeIos.sh #now we can do the delegated build of ios and macos libraries cd .. -./gradlew multiplatform-crypto-delegated:iosArm32MainKlibrary multiplatform-crypto-delegated:iosArm32TestKlibrary \ -multiplatform-crypto-delegated:iosArm64MainKlibrary multiplatform-crypto-delegated:iosArm64TestKlibrary \ -multiplatform-crypto-delegated:iosX64MainKlibrary multiplatform-crypto-delegated:iosX64TestKlibrary -./gradlew multiplatform-crypto-delegated:iosX64Test ./gradlew multiplatform-crypto-libsodium-bindings:iosArm32MainKlibrary multiplatform-crypto-libsodium-bindings:iosArm32TestKlibrary \ multiplatform-crypto-libsodium-bindings:iosArm64MainKlibrary multiplatform-crypto-libsodium-bindings:iosArm64TestKlibrary \ diff --git a/macBuild-mac.sh b/macBuild-mac.sh index bb42c97..52498e1 100755 --- a/macBuild-mac.sh +++ b/macBuild-mac.sh @@ -8,9 +8,6 @@ cd sodiumWrapper ./makeIos.sh #now we can do the delegated build of ios and macos libraries cd .. -./gradlew multiplatform-crypto-delegated:macosX64MainKlibrary multiplatform-crypto-delegated:macosX64TestKlibrary -./gradlew multiplatform-crypto-delegated:macosX64Test - ./gradlew multiplatform-crypto-libsodium-bindings:macosX64MainKlibrary multiplatform-crypto-libsodium-bindings:macosX64TestKlibrary ./gradlew multiplatform-crypto-libsodium-bindings:macosX64Test set +e diff --git a/macBuild-pure-ios.sh b/macBuild-pure-ios.sh deleted file mode 100755 index 85dc166..0000000 --- a/macBuild-pure-ios.sh +++ /dev/null @@ -1,9 +0,0 @@ -set -e -#!/bin/sh -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:iosArm32MainKlibrary multiplatform-crypto:iosArm32TestKlibrary \ -multiplatform-crypto:iosArm64MainKlibrary multiplatform-crypto:iosArm64TestKlibrary \ -multiplatform-crypto:iosX64MainKlibrary multiplatform-crypto:iosX64TestKlibrary -./gradlew multiplatform-crypto:iosX64Test - -set +e diff --git a/macBuild-pure-mac.sh b/macBuild-pure-mac.sh deleted file mode 100755 index 66b5ae4..0000000 --- a/macBuild-pure-mac.sh +++ /dev/null @@ -1,7 +0,0 @@ -set -e -#!/bin/sh -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:macosX64MainKlibrary multiplatform-crypto:macosX64TestKlibrary -./gradlew multiplatform-crypto:macosX64Test - -set +e diff --git a/macBuild-pure-tvos.sh b/macBuild-pure-tvos.sh deleted file mode 100755 index b9c6e22..0000000 --- a/macBuild-pure-tvos.sh +++ /dev/null @@ -1,7 +0,0 @@ -set -e -#!/bin/sh -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:tvosArm64MainKlibrary multiplatform-crypto:tvosArm64TestKlibrary \ -multiplatform-crypto:tvosX64MainKlibrary multiplatform-crypto:tvosX64TestKlibrary -./gradlew multiplatform-crypto:tvosX64Test -set +e diff --git a/macBuild-pure-watchos.sh b/macBuild-pure-watchos.sh deleted file mode 100755 index 75dd98b..0000000 --- a/macBuild-pure-watchos.sh +++ /dev/null @@ -1,8 +0,0 @@ -set -e -#!/bin/sh -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:watchosArm32MainKlibrary multiplatform-crypto:watchosArm32TestKlibrary \ -multiplatform-crypto:watchosArm64MainKlibrary multiplatform-crypto:watchosArm64TestKlibrary \ -multiplatform-crypto:watchosX86MainKlibrary multiplatform-crypto:watchosX86TestKlibrary -./gradlew multiplatform-crypto:watchosX86Test -set +e diff --git a/macBuild-tvos.sh b/macBuild-tvos.sh index 0fbc520..154841d 100755 --- a/macBuild-tvos.sh +++ b/macBuild-tvos.sh @@ -7,9 +7,6 @@ cd sodiumWrapper ./makeTvos.sh #now we can do the delegated build of ios and macos libraries cd .. -./gradlew multiplatform-crypto-delegated:tvosArm64MainKlibrary multiplatform-crypto-delegated:tvosArm64TestKlibrary \ -multiplatform-crypto-delegated:tvosX64MainKlibrary multiplatform-crypto-delegated:tvosX64TestKlibrary -./gradlew multiplatform-crypto-delegated:tvosX64Test ./gradlew multiplatform-crypto-libsodium-bindings:tvosArm64MainKlibrary multiplatform-crypto-libsodium-bindings:tvosArm64TestKlibrary \ multiplatform-crypto-libsodium-bindings:tvosX64MainKlibrary multiplatform-crypto-libsodium-bindings:tvosX64TestKlibrary diff --git a/macBuild-watchos.sh b/macBuild-watchos.sh index 6935420..6311ae4 100755 --- a/macBuild-watchos.sh +++ b/macBuild-watchos.sh @@ -7,10 +7,6 @@ cd sodiumWrapper ./makeWatchos.sh #now we can do the delegated build of ios and macos libraries cd .. -./gradlew multiplatform-crypto-delegated:watchosArm32MainKlibrary multiplatform-crypto-delegated:watchosArm32TestKlibrary \ -multiplatform-crypto-delegated:watchosArm64MainKlibrary multiplatform-crypto-delegated:watchosArm64TestKlibrary \ -multiplatform-crypto-delegated:watchosX86MainKlibrary multiplatform-crypto-delegated:watchosX86TestKlibrary -./gradlew multiplatform-crypto-delegated:watchosX86Test ./gradlew multiplatform-crypto-libsodium-bindings:watchosArm32MainKlibrary multiplatform-crypto-libsodium-bindings:watchosArm32TestKlibrary \ multiplatform-crypto-libsodium-bindings:watchosArm64MainKlibrary multiplatform-crypto-libsodium-bindings:watchosArm64TestKlibrary \ diff --git a/macBuild.sh b/macBuild.sh index 23d0c7c..b12ed96 100755 --- a/macBuild.sh +++ b/macBuild.sh @@ -8,9 +8,6 @@ cd sodiumWrapper ./makeIosWatchosTvos.sh #now we can do the delegated build cd .. -./gradlew multiplatform-crypto-delegated:build -#pure build -./gradlew multiplatform-crypto:build #libsodium bindings ./gradlew multiplatform-crypto-libsodium-bindings:build set +e diff --git a/macBuildAndPublish-ios.sh b/macBuildAndPublish-ios.sh index d506639..ac8dbb1 100755 --- a/macBuildAndPublish-ios.sh +++ b/macBuildAndPublish-ios.sh @@ -8,9 +8,6 @@ cd sodiumWrapper ./makeIos.sh #now we can do the delegated build of ios and macos libraries cd .. -./gradlew multiplatform-crypto-delegated:publishIosArm32PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishIosArm64PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishIosX64PublicationToSnapshotRepository ./gradlew multiplatform-crypto-libsodium-bindings:publishIosArm32PublicationToSnapshotRepository \ multiplatform-crypto-libsodium-bindings:publishIosArm64PublicationToSnapshotRepository \ diff --git a/macBuildAndPublish-mac.sh b/macBuildAndPublish-mac.sh index c92cf58..df18499 100755 --- a/macBuildAndPublish-mac.sh +++ b/macBuildAndPublish-mac.sh @@ -7,7 +7,6 @@ cd sodiumWrapper ./makeMacosX86-64.sh #now we can do the delegated build of ios and macos libraries cd .. -./gradlew multiplatform-crypto-delegated:publishMacosX64PublicationToSnapshotRepository ./gradlew multiplatform-crypto-libsodium-bindings:publishMacosX64PublicationToSnapshotRepository set +e diff --git a/macBuildAndPublish-pure-ios.sh b/macBuildAndPublish-pure-ios.sh deleted file mode 100755 index 6095c54..0000000 --- a/macBuildAndPublish-pure-ios.sh +++ /dev/null @@ -1,8 +0,0 @@ -set -e -#!/bin/sh -#this will hopefully download all konan dependancies that we use in the build scripts -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:publishIosArm32PublicationToSnapshotRepository \ -multiplatform-crypto:publishIosArm64PublicationToSnapshotRepository \ -multiplatform-crypto:publishIosX64PublicationToSnapshotRepository -set +e diff --git a/macBuildAndPublish-pure-mac.sh b/macBuildAndPublish-pure-mac.sh deleted file mode 100755 index 6dc40b5..0000000 --- a/macBuildAndPublish-pure-mac.sh +++ /dev/null @@ -1,6 +0,0 @@ -set -e -#!/bin/sh -#this will hopefully download all konan dependancies that we use in the build scripts -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:publishMacosX64PublicationToSnapshotRepository -set +e diff --git a/macBuildAndPublish-pure-tvos.sh b/macBuildAndPublish-pure-tvos.sh deleted file mode 100755 index 1533e8d..0000000 --- a/macBuildAndPublish-pure-tvos.sh +++ /dev/null @@ -1,8 +0,0 @@ -set -e -#!/bin/sh -#this will hopefully download all konan dependancies that we use in the build scripts -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:publishTvosArm64PublicationToSnapshotRepository \ -multiplatform-crypto:publishTvosX64PublicationToSnapshotRepository - -set +e diff --git a/macBuildAndPublish-pure-watchos.sh b/macBuildAndPublish-pure-watchos.sh deleted file mode 100755 index 30724cd..0000000 --- a/macBuildAndPublish-pure-watchos.sh +++ /dev/null @@ -1,8 +0,0 @@ -set -e -#!/bin/sh -#this will hopefully download all konan dependancies that we use in the build scripts -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:publishWatchosArm32PublicationToSnapshotRepository \ -multiplatform-crypto:publishWatchosArm64PublicationToSnapshotRepository \ -multiplatform-crypto:publishWatchosX86PublicationToSnapshotRepository -set +e diff --git a/macBuildAndPublish-tvos.sh b/macBuildAndPublish-tvos.sh deleted file mode 100755 index 1533e8d..0000000 --- a/macBuildAndPublish-tvos.sh +++ /dev/null @@ -1,8 +0,0 @@ -set -e -#!/bin/sh -#this will hopefully download all konan dependancies that we use in the build scripts -./gradlew multiplatform-crypto-api:build -./gradlew multiplatform-crypto:publishTvosArm64PublicationToSnapshotRepository \ -multiplatform-crypto:publishTvosX64PublicationToSnapshotRepository - -set +e diff --git a/macBuildAndPublish-watchos.sh b/macBuildAndPublish-watchos.sh index 3125ec4..ee42802 100755 --- a/macBuildAndPublish-watchos.sh +++ b/macBuildAndPublish-watchos.sh @@ -7,9 +7,6 @@ cd sodiumWrapper ./makeWatchos.sh #now we can do the delegated build of ios and macos libraries cd .. -./gradlew multiplatform-crypto-delegated:publishWatchosArm32PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishWatchosArm64PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishWatchosX86PublicationToSnapshotRepository ./gradlew multiplatform-crypto-libsodium-bindings:publishWatchosArm32PublicationToSnapshotRepository \ multiplatform-crypto-libsodium-bindings:publishWatchosArm64PublicationToSnapshotRepository \ diff --git a/macBuildAndPublishSnapshot-delegated.sh b/macBuildAndPublishSnapshot-delegated.sh deleted file mode 100755 index 8fb7d2d..0000000 --- a/macBuildAndPublishSnapshot-delegated.sh +++ /dev/null @@ -1,15 +0,0 @@ -set -e -#!/bin/sh -./gradlew multiplatform-crypto-delegated:publishMacosX64PublicationToSnapshotRepository - -./gradlew multiplatform-crypto-delegated:publishIosArm32PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishIosArm64PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishIosX64PublicationToSnapshotRepository - -./gradlew multiplatform-crypto-delegated:publishWatchosArm32PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishWatchosArm64PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishWatchosX86PublicationToSnapshotRepository - -./gradlew multiplatform-crypto-delegated:publishTvosArm64PublicationToSnapshotRepository \ -multiplatform-crypto-delegated:publishTvosX64PublicationToSnapshotRepository -set +e diff --git a/multiplatform-crypto-delegated/build.gradle.kts b/multiplatform-crypto-delegated/build.gradle.kts deleted file mode 100644 index 0515eff..0000000 --- a/multiplatform-crypto-delegated/build.gradle.kts +++ /dev/null @@ -1,698 +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. - * - */ - -@file:Suppress("UnstableApiUsage") - -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest -import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest -import org.jetbrains.dokka.Platform - -plugins { - kotlin(PluginsDeps.multiplatform) - id(PluginsDeps.mavenPublish) - id(PluginsDeps.signing) - id(PluginsDeps.node) version Versions.nodePlugin - id(PluginsDeps.dokka) - id(PluginsDeps.taskTree) version Versions.taskTreePlugin -} - -val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/" - -val sonatypePassword: String? by project - -val sonatypeUsername: String? by project - -val sonatypePasswordEnv: String? = System.getenv()["SONATYPE_PASSWORD"] -val sonatypeUsernameEnv: String? = System.getenv()["SONATYPE_USERNAME"] - -repositories { - mavenCentral() - jcenter() - -} -group = ReleaseInfo.group -version = ReleaseInfo.version - -val ideaActive = isInIdea() -println("Idea active: $ideaActive") - - - -kotlin { - val hostOsName = getHostOsName() - runningOnLinuxx86_64 { - println("Configuring Linux X86-64 targets") - jvm() - js { - browser { - testTask { - isRunningInGitlabCi { - enabled = false //Until I sort out testing on travis - } - useKarma { - useChrome() - } - } - } - nodejs { - testTask { - useMocha() { - timeout = "10s" - } - } - } - - } - linuxX64() { - compilations.getByName("main") { - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-linux-x86-64/include/") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-linux-x86-64/lib/libsodium.a" - ) - } - binaries { - staticLib { - } - } - } - - - linuxArm64() { - binaries { - staticLib { - } - } - } - // Linux 32 is using target-sysroot-2-raspberrypi which is missing getrandom and explicit_bzero in stdlib - // so konanc can't build klib because getrandom missing will cause sodium_misuse() - // ld.lld: error: undefined symbol: explicit_bzero - // >>> referenced by utils.c - // >>> libsodium_la-utils.o:(sodium_memzero) in archive /tmp/included11051337748775083797/libsodium.a - // - // ld.lld: error: undefined symbol: getrandom - // >>> referenced by randombytes_sysrandom.c - // >>> libsodium_la-randombytes_sysrandom.o:(_randombytes_linux_getrandom) in archive /tmp/included11051337748775083797/libsodium.a - -// linuxArm32Hfp() { -// binaries { -// staticLib { -// } -// } -// compilations.getByName("main") { -// val libsodiumCinterop by cinterops.creating { -// defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) -// compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-arm32/include/") -// } -// kotlinOptions.freeCompilerArgs = listOf( -// "-include-binary", "${project.rootDir}/sodiumWrapper/static-arm32/lib/libsodium.a" -// ) -// } -// } - - - } - - - runningOnLinuxArm64 { - println("Configuring Linux Arm 64 targets") - - } - - runningOnLinuxArm32 { - println("Configuring Linux Arm 32 targets") - - } - - runningOnMacos { - println("Configuring macos targets") - iosX64() { - binaries { - framework { - optimized = true - } - } - } - iosArm64() { - binaries { - framework { - optimized = true - } - } - } - - iosArm32() { - binaries { - framework { - optimized = true - } - } - } - macosX64() { - binaries { - framework { - optimized = true - } - } - compilations.getByName("main") { - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-macos-x86-64/include") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-macos-x86-64/lib/libsodium.a" - ) - } - } - tvosX64() { - binaries { - framework { - optimized = true - } - } - } - - tvosArm64() { - binaries { - framework { - optimized = true - } - } - } - - watchosArm64() { - binaries { - framework { - optimized = true - } - } - } - - watchosArm32() { - binaries { - framework { - optimized = true - } - } - } - - watchosX86() { - binaries { - framework { - optimized = true - } - } - } - } - runningOnWindows { - println("Configuring Mingw targets") - mingwX64() { - binaries { - staticLib { - optimized = true - } - } - compilations.getByName("main") { - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-mingw-x86-64/include") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-mingw-x86-64/lib/libsodium.a" - ) - } - } - } - - println(targets.names) - - sourceSets { - val commonMain by getting { - dependencies { - implementation(kotlin(Deps.Common.stdLib)) - implementation(kotlin(Deps.Common.test)) - implementation(Deps.Common.kotlinBigNum) - api(project(Deps.Common.apiProject)) - } - } - val commonTest by getting { - dependencies { - implementation(kotlin(Deps.Common.test)) - implementation(kotlin(Deps.Common.testAnnotation)) - } - } - - val nativeDependencies = independentDependencyBlock { - } - - val nativeMain by creating { - dependsOn(commonMain) - isRunningInIdea { - kotlin.setSrcDirs(emptySet()) - } - dependencies { - nativeDependencies(this) - } - } - - val nativeTest by creating { - dependsOn(commonTest) - isRunningInIdea { - kotlin.setSrcDirs(emptySet()) - } - dependencies { - } - } - - //Set up shared source sets - //linux, linuxArm32Hfp, linuxArm64 - val linux64Bit = setOf( - "linuxX64" - ) - val linuxArm64Bit = setOf( - "linuxArm64" - ) - val linux32Bit = setOf( - "" // "linuxArm32Hfp" - ) - - //iosArm32, iosArm64, iosX64, macosX64, metadata, tvosArm64, tvosX64, watchosArm32, watchosArm64, watchosX86 - val macos64Bit = setOf( - "macosX64" - ) - val iosArm = setOf( - "iosArm64", "iosArm32" - ) - val iosSimulator = setOf( - "iosX64" - ) - val mingw64Bit = setOf( - "mingwX64" - ) - - val tvosArm = setOf( - "tvosArm64" - ) - val tvosSimulator = setOf( - "tvosX64" - ) - - val watchosArm = setOf( - "watchosArm32", "watchosArm64" - ) - val watchosSimulator = setOf( - "watchosX86" - ) - - targets.withType { - println("Target $name") - - compilations.getByName("main") { - if (linux64Bit.contains(this@withType.name)) { - defaultSourceSet.dependsOn(nativeMain) - } - if (linuxArm64Bit.contains(this@withType.name)) { - defaultSourceSet.dependsOn( - createWorkaroundNativeMainSourceSet( - this@withType.name, - nativeDependencies - ) - ) - - compilations.getByName("main") { - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-arm64/include/") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-arm64/lib/libsodium.a" - ) - } - } - if (linux32Bit.contains(this@withType.name)) { - defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies)) - } - if (macos64Bit.contains(this@withType.name)) { - defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies)) - } - //All ioses share the same static library - if (iosArm.contains(this@withType.name)) { - defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies)) - println("Setting ios cinterop for $this") - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-ios/include") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-ios/lib/libsodium.a" - ) - } - - if (iosSimulator.contains(this@withType.name)) { - defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies)) - println("Setting ios cinterop for $this") - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-ios-simulators/include") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-ios-simulators/lib/libsodium.a" - ) - } - - if (tvosArm.contains(this@withType.name)) { - defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies)) - println("Setting ios cinterop for $this") - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-tvos/include") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-tvos/lib/libsodium.a" - ) - } - - if (tvosSimulator.contains(this@withType.name)) { - defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies)) - println("Setting ios cinterop for $this") - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-tvos-simulators/include") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-tvos-simulators/lib/libsodium.a" - ) - } - - if (watchosArm.contains(this@withType.name)) { - defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies)) - println("Setting ios cinterop for $this") - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-watchos/include") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-watchos/lib/libsodium.a" - ) - } - - if (watchosSimulator.contains(this@withType.name)) { - defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies)) - println("Setting ios cinterop for $this") - val libsodiumCinterop by cinterops.creating { - defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) - compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-watchos-simulators/include") - } - kotlinOptions.freeCompilerArgs = listOf( - "-include-binary", "${project.rootDir}/sodiumWrapper/static-watchos-simulators/lib/libsodium.a" - ) - } - - - - } - compilations.getByName("test") { - println("Setting native test dep for $this@withType.name") - defaultSourceSet.dependsOn(nativeTest) - - - } - } - - - - - runningOnLinuxx86_64 { - println("Configuring Linux 64 Bit source sets") - val jvmMain by getting { - dependencies { - implementation(kotlin(Deps.Jvm.stdLib)) - implementation(kotlin(Deps.Jvm.test)) - implementation(kotlin(Deps.Jvm.testJUnit)) - - //lazysodium - implementation(Deps.Jvm.Delegated.lazysodium) - implementation(Deps.Jvm.Delegated.jna) - } - } - val jvmTest by getting { - dependencies { - implementation(kotlin(Deps.Jvm.test)) - implementation(kotlin(Deps.Jvm.testJUnit)) - implementation(kotlin(Deps.Jvm.reflection)) - } - } - val jsMain by getting { - dependencies { - implementation(kotlin(Deps.Js.stdLib)) - implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second)) - } - } - val jsTest by getting { - dependencies { - implementation(kotlin(Deps.Js.test)) - implementation(npm(Deps.Js.Npm.libsodiumWrappers.first, Deps.Js.Npm.libsodiumWrappers.second)) - } - } - val linuxX64Main by getting { - isRunningInIdea { - kotlin.srcDir("src/nativeMain/kotlin") - } - } - val linuxX64Test by getting { - dependsOn(nativeTest) - isRunningInIdea { - kotlin.srcDir("src/nativeTest/kotlin") - } - } - - } - - runningOnMacos { - println("Configuring Macos source sets") - val macosX64Main by getting { - dependsOn(nativeMain) - if (ideaActive) { - kotlin.srcDir("src/nativeMain/kotlin") - } - - } - val macosX64Test by getting { - dependsOn(nativeTest) - if (ideaActive) { - kotlin.srcDir("src/nativeTest/kotlin") - } - - } - - val tvosX64Main by getting { - dependsOn(commonMain) - } - - val tvosArm64Main by getting { - dependsOn(commonMain) - } - - val watchosX86Main by getting { - dependsOn(commonMain) - } - - val watchosArm64Main by getting { - dependsOn(commonMain) - } - - val watchosArm32Main by getting { - dependsOn(commonMain) - } - - } - - - if (hostOsName == "windows") { - val mingwX64Main by getting { - dependsOn(nativeMain) - if (ideaActive) { - kotlin.srcDir("src/nativeMain/kotlin") - } - } - - val mingwX64Test by getting { - dependsOn(nativeTest) - if (ideaActive) { - kotlin.srcDir("src/nativeTest/kotlin") - } - } - } - - - all { - languageSettings.enableLanguageFeature("InlineClasses") - languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") - languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi") - } - } - - -} - - - -tasks { - - - create("javadocJar") { - dependsOn(dokkaJavadoc) - archiveClassifier.set("javadoc") - from(dokkaJavadoc.get().outputDirectory) - } - - dokkaJavadoc { - println("Dokka !") - dokkaSourceSets { - named("commonMain") { - displayName.set("common") - platform.set(Platform.common) - } - } - - } - if (getHostOsName() == "linux" && getHostArchitecture() == "x86-64") { - val jvmTest by getting(Test::class) { - testLogging { - events("PASSED", "FAILED", "SKIPPED") - } - } - - val linuxX64Test by getting(KotlinNativeTest::class) { - - testLogging { - events("PASSED", "FAILED", "SKIPPED") - showStandardStreams = true - } - } - - val jsNodeTest by getting(KotlinJsTest::class) { - testLogging { - events("PASSED", "FAILED", "SKIPPED") -// showStandardStreams = true - } - } - -// val legacyjsNodeTest by getting(KotlinJsTest::class) { -// -// testLogging { -// events("PASSED", "FAILED", "SKIPPED") -// showStandardStreams = true -// } -// } - -// val jsIrBrowserTest by getting(KotlinJsTest::class) { -// testLogging { -// events("PASSED", "FAILED", "SKIPPED") -// showStandardStreams = true -// } -// } - } - - if (getHostOsName() == "windows") { - val mingwX64Test by getting(KotlinNativeTest::class) { - - testLogging { - events("PASSED", "FAILED", "SKIPPED") - showStandardStreams = true - } - } - } - -} - - - -signing { - isRequired = false - sign(publishing.publications) -} - -publishing { - publications.withType(MavenPublication::class) { - artifact(tasks["javadocJar"]) - pom { - name.set("Kotlin Multiplatform Crypto") - description.set("Kotlin Multiplatform Crypto library") - url.set("https://github.com/ionspin/kotlin-multiplatform-crypto") - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - developers { - developer { - id.set("ionspin") - name.set("Ugljesa Jovanovic") - email.set("opensource@ionspin.com") - } - } - scm { - url.set("https://github.com/ionspin/kotlin-multiplatform-crypto") - connection.set("scm:git:git://git@github.com:ionspin/kotlin-multiplatform-crypto.git") - developerConnection.set("scm:git:ssh://git@github.com:ionspin/kotlin-multiplatform-crypto.git") - - } - - } - } - repositories { - maven { - - url = uri(sonatypeStaging) - credentials { - username = sonatypeUsername ?: sonatypeUsernameEnv ?: "" - password = sonatypePassword ?: sonatypePasswordEnv ?: "" - } - } - - maven { - name = "snapshot" - url = uri(sonatypeSnapshots) - credentials { - username = sonatypeUsername ?: sonatypeUsernameEnv ?: "" - password = sonatypePassword ?: sonatypePasswordEnv ?: "" - } - } - } -} - -//configurations.forEach { -// -// if (it.name == "linuxCompileKlibraries") { -// println("Configuration name: ${it.name}") -// it.attributes { -// this.keySet().forEach { key -> -// val attribute = getAttribute(key) -// println(" |-- Attribute $key ${attribute}") -// attribute(org.jetbrains.kotlin.gradle.plugin.ProjectLocalConfigurations.ATTRIBUTE, "publicZ") -// } -// } -// } -//} - - diff --git a/multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz b/multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz deleted file mode 100644 index 97837caa202d8ac65b43e59fc5d42a9ecb41512f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15788 zcmV;dJyXITiwFP!000001MPi#f7>>)=>Dxw!D!DfmDaE#J5J)-QF;|eNxbzVYdLLm zd~;};ge+DPsgjT_HTC`McLo4S@J-szWA{YAHkOFjVBP}^z`0>gj7$3HV1I9LG#vcx zb9}np?$fO;E$caaHlB2!X@7hCM&tDDKpP&vKK-?SGSK#i+PjnE zU-n-OUTMw#5Pmnc{?RK9EA`)>zCAwCUhNO}4*L6tL#=;sph2sX{?Y0FVA%L||MabP zGI-NJf%?bL1Uid4KH58Y|7!o}4R5u7`0ijIhKO2g$FCcQgOk0t@U#DN|6u?010VSH z{^`+RIP5?N+R?E#_+@Z(stw;_Ckjk22in1Y|K-6zdwqP;=pTL1hVKS@`~3p~;GPWj zP6@ORzCr!HV^AgkdJla;9qm>Bu>S@@IMJ}F{Mq>RZU1z53?rVvtcLFoP7(UoC&!1{ z!SN6Q*4_^XFhKvbk4*t@0PK)xzrGy+XeS79|ESU5JKaA%!rCzC=}8|UI2yb;*ncxP z+8bcQV_y68_yj7x2dwf2MC+gI4{^lf_os-QW8NY3aWoJ;a&#jO017_--~=Xr*yp{z zj-$WR_}XH8>(5;3f0U?4AZ3dw_1FEy%zZSqFMN=?#cciBL*DlM&hP%M#wgPNo15LI zo101f|E#<9^t=B55}ya7g<~>MV=dbL6nxiMixSrU)C3Kzp{6xibN33An@5Zu>v+_# zRvpliPOB9*S6UnJ!ydJ|4|+YXqYEa|ZO3MU8eSP#vKB-Q^C_Lt;z4C)+W`ixQgODJR;cCB zOM}r06)Vr#qt?Q#(xbn)D6FLxgP4L?nsE{;5A} zXsWYIlBz;2TgWdY+_zRFY#B6BV-hMNo}d zmaheDsLvNFX{)tR(O=RcdqTO@Ye7>B5Rb<6hd*{b7H6dJQ5xv5#JA`8ce%Nxl-ie0 z{8tv8@G-Txho#RaI$EL7<;tn%*Qqw26c(eBOH|+rN(ZFHw2D%c5+^K*>n{E%r91i4 zxPQeTWoueqlvHl~p#UHYn}W&#k#h?~II(oS@*28r=2uEFM54TKgq+TE`dpR`x-1-Z znI2X+Qx_{nef?rFNjCvjJI>2^o@8a!o#vm!waACWmC79FYU^o*a`sazfsb zH{>_+io7PjkhkPd@;mv1{7U{w{zd+q{1>5=FiJd13`%rL97=pjOiElz#+1w{Sy5tB zGNoieiABj3C6|<3P%@%qM#+GZB_$I|hLoIAa!ttxN?uaZr{rf!4k_8E{-ESnO8!a7zbN@{O8$!y$_Qh`W5i%Y zXT)K|XT)U0Wn|3AoRJkHHX~C;7K~VoTrqOV$OR)KMrMo*7+EqhVPwe2DI?d6d|>1y zBYj4GX5^5OeMXKLIbh^HBgc&FF>=DlJ4W6x@*5+s7wR0w#_B`^LFQ;zKRC8*V%r&P~-emKtSDtM?U32PIo^2J%=CrCl+g#dW zl$G@?1N_7?V@Yvw2M`#S^dW1Mc2m+vMh6&Gyd1nfJ{cSxW)vOvlStxEa|wi{N5@Bd zgN#-{pM(9qY!HTn{z2yBy_3OdUX#JAjK@WboCOmtYL<vi3TxaQQ6!6 z@NH2!O#Wo>>iyo})o`zW&_5}vTVCV+(LUx7WK|i5p$;ZboEBHv2NO_IC5^>Ih2!_9 zd7VfE7eEr!$Oj~-kq1Xmo)1QBS*o-`9wB3us!%i5AitV~A52XymZB=TXo{-j;3=w* zkEl{|l~SvOScSAwm-EYt;(8~ec>gH7I1N}nQwuy|_8 zTIIu5pXxgZO^=UKmNBd9uz!%GdltdfZI+y(4BriRKQbn#JXU9dk1^G2@LLihEJziacef;SVR}<1L)a{dkqT+^;OH!dux+}SN(LZ>j z_fOs&A8qb$JT5AIl~ep`@Vfv0;51d1LA`j1N;p|^I5<4mKioeB-FG^`?7;nB2Kkk; z`i=^Vx<5RA1>K((^gSFL4fivLKYlkXhcT>_1!Gj00b^8{2V+enM2(DLgBtn6hc!yTu*%`E$^o&;A+hp7$=q%%40-wygrngf`o|7)58P|&?HN98wLi9bHi^TtNz7JTB$N12GD(mn0^a%l z(VMJj`Q6Fj^?t?RBdV@~@2lW{LIBL&f?4=^v+(&Wyw3a6*W0J=kmokFa8m7?8?VQ9 znYa36w8Rwk9-j1iZ#!(e?|H_mb@t;n`SBUq=x&SuH=cZK6Q@Tzi7c)b?G(7iZQ@sJ z5-?bsn7xc*OfYTf#36p0xLFm#G}M;KYwg-N%#6;=*&G_W?KV_gc+QP!FmsGY=%9kL zm`?HJ+rp7#EiT{gy3Z!>K&tFVM#>?JXP%QPCWJ@rUnE_V?V`+;ynK zpn`e^FF{!<*{e;wUY8iX;P8O)gOJm}uEI~EP5CjdV**tla-dm6(0XnW(wO-@|)ytmOt z4wn6kws9;7{0PSHU^4%noKnY_&!;O+e?n0nLavBNe+pBPv5EC4q=0LjnN zbeip(0NGxz*#wk!WfmKYMA+|f?04p#%UncL$Di6JVA+_$^a#%DANrahzO?kUjrN+s zC)$0`3lxG>1|R{!6EcQzESEo@_x!WS)8{^)Fcye<+1|DxcFe6@C^~US1VC;3bO>7w6e!kkZVVcJJI`KPm zcMdAWTkAP3AN7o&ju)|wk7%a7nZ!P6+Rl8z)I+1hBL*N4FzG<|&hwB#9UP^%{cNq} z^){Y71U>z+4d2%{x-VXAKU{zOWBd8@?Z2>`^|0{8ix*o^fhiS;zShfNh!*&x4~_O( zR*?bSY=;7%-*6iAJ{_OzzrkQ?XM+S^LGkJD`mgYG|ITCb{^VfTe?8cF5`0sOpWQ@C z!HuaS8c2-UNw?!_?Ln_+c7ibcT*wSU(neUozI?fB3-I zTmSIa_|atZr*5y;+I+~`KW*)7uC+`c$VPjo+a`0a+or8ChznWu7N|M`I(0BlzqJC2 zi*NIeVObva!Gb_{%6aDt+u0P8jOvhiAYdyJfCW>0`0x^@)-+v5W(-R^&}@eddSj4( z2YLeYq$u5Xn_RVYFbEOW<^pR%ZLq)oYA&$4fz_Kx=Laj$yD8duYfa5vusL3l;d(QJ z;Vl`ci;OD(#kiQ#rZ9e*?fA@aOw`9yp{SJs5CZ|D(Il+czR5sY$Etz8Pfd!~9Mfg2 zqMuh$U^!NIoUThUd2~04h#!6(i^<2a(fnb}Tl=B;(+}+%9MZk`otiANOn7!)>KUVV z%nLhs!U{MCIP}vE=+^G88>Jt+pmOvxMEIEu_0S4Ig?yPIiH_6!F} zCP5YxKr0fk#;T>jiHGPF$`L^s!qH9woPI=O4i=n+#vA}gGl{l5QYsI+67UBb(P*~R zKhm7b$vlWAlR1Z9#}uvZ$ae5v7QBfiPKepUXW9kT3{7^}mP}34Oih8Q12)zo)f4Lw z@DqVN6}H+AY*7zH34clP?O9MB)keMWNubh-+@FAiUgzzg|L*;E$EV^p1)?}PR@4+U z#te+LYoeAx!wh(3Vk)0zFsN}!cbY+!cAy!E7;T5%WVldQA?71ucXwH2@ff#w^o#+0 zJNn3@V2-3hje5D1>X#!GyCe~2nSzFk%z64V+!5{%3={- z*|TsY8>lQi3p$Xq4mu=ERZNlG|HO7uV#I#Z0jQlT*S0wDF}uXAi-tA%T|&(@PZ@o{ zM+2k7g8|_-f&JOF!71VBb9)H=F8=eNN5SoJ(RzU8GSPC0xI%YafU*gyJ2U~Nuq6;q z5XLJrum<*gOg%1?qHi!7$Sg8O$xh}rcr*mc&gz9CYdv2fnoYG!6bt6M8eeY&GcyJ- zSv!DZECw9$$&dkhOMF5GOlSl(4GyD0njjZ8BF32N=)mHf20bG&t5F+uAhrM-H(y+U ze;S~G53?i_FyCb}1F~Gm$?fWL1Tf+gIW^niPP3-=uZdbPy(IvxhtpeP#5v;;T@#Pd z2{4A_v;r7VKY+rCpg2uH0kxvRhcLJk4n7p4T}v0kTCYmdzrZp1(7O(F5vmH=<%iJq zDC|gHkkR@;I9XjXCKlj`QJ1IJ2DLQVU=(qvPieAuLW4uv9gkmD$hF+Y(>jEp! z3{x_~2svJ11Y8Gz(tzwnMD_ua-Hpf&wIZ@}L1_o@jU=xNk(z`erNcxycXBxNOp%)O z^u%nJZNb7WvT%k-RpVt{|+mWh<)YB%6&@WBxtUlplqVAxtBSi0f*!k&7CgS!B|~y8<>hCPmzTiOk-R_v z`!mRkdk1-$lp7kwu1Gfld1V}}yM#tX3I^vqE95+|y{$l6xWUQbyhvmM^|flNwjs|h zB&D^kNf>~}zO_kMRx$~Lm`NC9nuG~(`E5JMSH zs+QTWbLgnHNBR|zGqzlRdvUMP_gv#%IWB*p9-2`Vx#sr>Sh#fR^1 z+1;$hm-fvHtj6bzF;Z6JPJxDced=e4HeP;b>+fuRe{n~Q`|lWhWL_Qo7hU3K`J|vB3l?fG4VUb4eYjE^kwsw+up+`9Lt?M4 zP4MNTzN7E%@g0rFXZDY48IOC6`zjcZI)PvDi!(k;Dts4C)o|)qh_;x3E+$|EO@&bF38D5Qp_U2Sj)<9bl-r0?@w7v1 z^74HJ0ZX!oC0%4mJ%=St5faIT^u09;i@-Qc`C{($CUJBv(}3Hyyg1SoKQSM;;+`XUmEW8F<6 zp@(~t$lq=!k#Tg@lgQ}(YE>oj)m;4`dVq#gMgj3=$D~$01N14`S^!mG>^)Bo&Ss;r93Y_DGUKl*Pt%C{)PeX#p$b zaDS~1C5@@FCZ_U!#Q62PQ@onp0$~Vg^GC4IC8*;F>gYmaIY^b%mY@#^xYZo_Z5Y9J z$8!@A?G)_{`a+R8AxAR~Qw9UzF6DhOz)HeZzyNZ~(g{olH&afu@D>4Pk;__urIfE? z%`Ovwg=0m4S;D4Cz^rhokaMQHerwJg^hP0PI^kMfz3%w6C#?Z6CpV$Q3bvo-tr4(a z#GoMQ%ZNdLjaFiV%PBaED&7RLs-I9G3aj~{H^F#C;2(9ZGmCe4c^+^05eX8jnUXL3 z7+?6v7fFV-$f(@xE3_Xa2F_qgNqaw_JzwDU`2ug!>?fCZGtGW-E!QtL`*J1M54b}t z-G=7P#f`a1$V7f@7y2~E3PxL;sSN{P-7rWs43|WQ zv4{_Su}$C?cn$yj&Yb`L%;~P>aUH5Ym1`ru8)owzztm}%#c`*=ag!u_otCiIzjBPT zFvF6$oCI@4ca!X9SWcC>T)dH|B6E!s#wWpCZpuczrszViRV(PzY zZOO*-Y_fJ`qolVe&nAmGl{_1k;7etXES6`pilwy4lpek@tBPM%Qcq0$l4(6=uK3Bs zo^W?Jxw#vOUozt@Q@59t6!JhV$0g)}+j}noCkVFZ3{iy_Jo+`3{=Ve$UcnMx>GE}Az3wi{ z*G8Vu)mq2S;8fRNm@oOWDo;KL`ld+R)k+L{Y02=L=RoMZGiVuyR7r_&Y4v580tA;O zYowcs+vclgZj8&seOX!D#Y?Ix2>r5((C2w$W#blz{%tY}N`@=nVa@A65&ufNs`F}0 z?%!Fq6Z2CgJQD8;^E2JqT&O56;JXFl9bNqU4NS788k4iN@k(q~SCxVPWY0a<1Ou)r zH2b?yekGxtEv9vZa{3MMYb~L4=q2!4b%9*m$%-YQ{@k|Asz?n371K9E5|3I7vj$17 zzAJ~Xq#XRkMIGgE`8|^QLXlKNnEQ&PE^-&YMq=rUztk$6f2-*%W*5{`-Wu@NUjQ_1 z1K!{(eco-$RUf5c^o{^fv<|)*kl*Xh=q2QW2ljV{+)U!<<(OH0^U^#dk5M=;FStVDK z1|^%>qk=uGk=Vfk>cgB6r!^?ytL-Wf!W4LQV`puHymLQ1)1u~_N84V?Hk57UtXV4P z(=VpRgl=BoTk%-N0%9^N$F}0@mWG;=6YfEoY#AIZ;HpPTo*9TfebkizB0*ydR<)*xFw9sWg=wJb3+ytjUyY;hO)_`Fs0?m zS8HI31?q^zQ3SJOqhL_DBg5(Ahhl?Qp2W6kq}W7TG?Cr<(g-#sf*(J5)>d&_gi+hE znRw@3gi^O>#t`V1AaGg3$yUd%bEqfLuEyD(NiCTO_u-P~addOMa3+G($x}I?%exQq zalDvY2Hyh4ES=ybR0(YI*GnmvdRGet6pQLan^WaG1wtof?GQw(2WDCnxotFgx=}Y` z7O{{YbNAhn70=TzFumk4DZh%atMK1K*!y2b8e&I; zYfA$j555m+`1wAiAvUGj(txc$gESnLNW*4#yOJ~@cz2VA{jVww2>≷V6ih(mAaF zxOwY{$*dkR@o`vKA7h@%UYn^jD;XvAsy-vQ84@Cr^!xW92-91}TJ!&QagBs~qvMAU zgScvaBgpJBvqKvhUi0uO3ZBn}(7pUK1oS>*svMy@sNu54r(Eu; z%K9~2)b|xqm8Ldz*tPqO@@gxeaY;@N%5KKWCCKM z(@Lp`)Vrcy5+5mUEzXHeB_zf>t(caWnz)azmQ^_>^Q>TEWudH(#Il2vyX*kX1wMmb zkQsfDl?hLfTB!>RpF|4g$#Q2z#Mjg1&hjR?$Tcikl)26h(r=;>X_Yu8jPO5VB zs{vr ze&85aO5j1=4SiQ>R$+%}tlrx{H+=uv^{ggW$;n&$$I7k!xa*m-cRRlp%SG8c#mTGt zv0Cboi5qU|kHqEt?%Y4HXEw{kgU<1wBOc(Z9^oNqRk}39uk)YLS^gLfAH%^h;Hwjj z5wxl>hEJNt^wRZgHlAe;;`2d#90b1l(I8>73Ir|M*>-cC8$mR_eck0Z?01O;i0=wT zqV8WOuGb%m>-F=m9E)*!&g$Q7_}r|==dOAQxyt9`h|kTKJ8UNSJm~`me9nJDJ>S^u zZp$r$9Oh3hsKuFo6+7R)64<#N^P4r8-@GOBn^l>ASESk~Y?(L@79Fb3X3I<*11nOI z&BKrTa$b#}5=*QVPD<|k{=HZyhuSiHHA-At(v-H8DS3*172JezOH#K=RcDk?+u)Qi zkP`6KxRt8Y`Ei>%dep0?K~}&Ek3uEl+Ps;{|fh!lXjm5(|03jH`-8blc2G zWai$2b^IEvldD_f`TD>#62}C_E4KC-vN{!%$w9%%t-x1Db#FyCrgQiOgQ{ zM7Crpz(O~62@?CV_oa&c=Ff8ZSbk1gG-$OA=2T`{!KSiVci%VyM!l-J^1gA@JiKsG z>=`HSCgc0Ycti7&h>MDLMzuGL_3zAa7v@m!(aoZItxM^m4*1Q4_jQ-9!>VtAW?`y) z12opE#`dSrq6O5_i^Ai#A{O5j9$j6VJffIIq@vrxV;9)w-xaR1eDW@}9F{M*DLldQ z`L~2ma<2!^Wch;Y!6&!Bw7&5A?+A|g4YEUi?WW6jjVj#+e(kx=W!;Mw%{=W^`ToBw ze!0I(0E_OlFV~dGD*&@^w$Hf!Z<2fOUzw&%-upMX)rEg~nzHh(e+jPQ>aynDf4AZ% zw=8BDQ^TUUF#{hAojYTe@zPe&wn}OQuUI8?$WPuXf#tsQxt?qmX8e>ugGoU8e8Klf zlz?E~8^>aSc}e2dxHxW}7#91RG5{@b691x3%LtuG^R< zjf!kskQ7{90eKXUxKYf&1SR^Qt6XZ9?TLJrL~pJ*61O$nf0}nR$}QFpgSPjS;%(J2 zM;X|uV0qM5HH^&FSE0KPh6MgDH@ChJ3n&BLfg6-=?ujuj?;ZW+tNWl)KkwUT1Mt=o zgWl!>e{6`jMq6|r2*3DGM0jenTktqG3s+O_5#giaAcd$QGa&FMew=Agzz%t8HHD`vUk3yAMmc%lU zp1%x)&G?~0ctXYDFjv}_XwfHr#L!G#xHm2_Gs9aimLPlv3`CXnlDuiFxJ@0o4*H27 zwpLe0lo#eC(vecznwhrG$luk>$VGBv%jdZXUkZI>!WZ6!=;o(;ot6YMWp@$r0V`fY zly|QFx=uiqtx@aU50NQqHExLD?eBg^gw#!SFNye2nw!LzSq=lAH`F%SVxaEVo6iF! z6YC?nNLW2HubL<%H~5Rw^4yq?bAzLl=~uud&&L}JJo%vpSK<5#^ z=r`dzj{>C@zV|KEA@SX#?7Y2~#b&wS>W`#}{0x_WRPbZUum8xAy2=-Tg!8M5SOg5kSEe>P5f!MRZLsTdpwVwei7cho@q@U%FcNc zUWKFCd?;a5qu9E_;q1dQXU1Ky+Q(HLrCCY-e&`!ba_^&&OU%IvbIvke(np#kucFEJ zjtUdL5(DSuz*I>4N;yZXPzBMr>W^-C&jp0v?~ch;ez1L&akKlSa*ty5L^+;}s^3q# zTmpMGWuq^eIhQs5XV0)qX36zR09v|UJX`Me$#O?^Qqod{F3w6T%=W26=wy;wcH&Qz zrZ!TN)WDMm^DNS%>m2h*G%nFd85wHHTOZ0;tKhc&RMt_!ZT)WXZT%HkOSjF|B-}B? z)4A4N?&m+K6AI;O?Fu_g>9%#Qqx>e+-B;9f-;$EMNBwsEjp(=kRjTb<(rWjw(Dv#p zv|H%0dg|+>K1|EIXxZg0)$F^ksb-g7QO{;!`>QG1<>%0}Z@#XkEhp}OlB&&Qr>~`J zm!DDD{+79hDD%w18C6|lFoHG}lK6Br*j8_jj=rVB=W#ab6 z=%U8rWw+W>)2mG_TGv*VU&DnmbvEkqYr&RXeEGFxvyR61<)TfwG$wIDih48Kv3&+C zh4)E0K~{;_fJ^MZMVCx+TZkqw*{wNsecDp5b_}cT3fq}zAm3%$e(~Z(HyZBjBcM^a zsxb4Y?Fclhpe*z`Gp1A5Y;A5KhPu1X^QXJc+FIM|_>}!(Oc%7JuWkLq0eDXq4&IiC zD0(diXwkE?rX9SP*}zA-W6WriGzEN3T&1-=__J_q7#AM^2Aghg_sVOowmCNjMagPwHsQF6D~WglNQplHKTdI6OI0qKVl4qT#rD2y*^3!2qw*_{#qAm`6tu)$E~-}~ zSV;bycIKYTT%216wCZ~Ra=Y(&#;O+#8IFg76qUEw*!HDphMiMns#cKT-SHO}MpQRA zW}*IAQ+sI>dP6w-MT2uXff;zvqJTi38DP_Z2oW3)AF}L%cAJeo_gX`+agSnv8-K0l zu`^vMwZgW(W&*Kb>`*g#(JSVRUKb2xS8QVj>L@799;feJE|6D!!3$&KitAEYO` zy96Z_JJz3jyE;gv@!~~qn;2_7dZvF|WAG2bZ@tYYPaYbG96Y1`bV~>LYy&#)neYtX zoNjpZt04{eT!Mh8gK?Gp4OWOG-fz?yfMQ#KGut$#5=R*W1lr95q8PmmAWW2kxW2A| z?6keVdWgGq#NCS*+Yb$5JnXgb(f{D1_WA}q4Vczj^VW>@4a6>g(}_TF0-LPo2A3Fs zmkBz91Uuo6{}Clda@P`EN(s-St?)pi*|S<(=;+~}VC3i}jDgV#XHQSjscfDWb7_K8p@LUUveIxM=t{-F_t=f-ABbI z+lS4NJX0{5Vas5!p3;RWy8x;=ab?pITW!P$i7=*1g#t3XB&e)O;2cFaNhHy}8E%^S zF?>hfQ?N%H;X8Z+BWEKO3OGi?MkH{0iKAk)OZ>ok72wkk@aZJ*X=LJ)ffJZUnSq)- zK$+0~Jz&I6==8^MSfmkdEBN6^G0|k8u$~ejprLSj&y8IVbR6S4j-ih8P`!CVz43|I zzK*wwe0H$SF*PR%kh{46|HVNKxCrAA4(!yv5UkN-@M}hA=4}4IQweufC2Ty`cMbF~ z5pBlD|6%ZtiaYN{VC#zz`r4jnkU4~vf!$>QD?MW$dtC&~T`*i8Kv&EF`>J?BVhU%? z1rEpk8t`)YsbxHiyhO*BtKH^D>}PJ&@nUkO2cGnZDi^#eEd-Ip%YC22|55v(EqMJC z&A0!gVfz<&SxwxAajWEm6*U1dn42FevT=BjjJ1_yieO(q)SMw|=TSbrnp?jH9qi7Z zuXg7=>X2vu<{yDM%#Xxe>%r&`|6i;1^vRRQPad{f?t0Hh7kF#?FBkqi-sFEap8n;w zx!vA)8tU`7eg=#~2pqu>&V<23DFC6tif4m`6;yNOMCNK-V6GO{j= zjh~Y=d3a4u5G!Mmvj+Y==I4DE@Ygne~(S+B$2}B_h%X6%yK%b$>B) zn;!w+J8AetbpS7Q1EVPEIIcyHAkz2=B3B^yoqzfm zIhw5ZDQ4-wg~4kY<%~IrIuO-3t(HohR#2mT({A7J=&!xo_}dr#%nfs5T+&DKZ|8U4 zb?$qNZnyh%YfH;|4xf!@n_ca1kDom4Zfrb#+J$=X<;m7l_&o;)0%v#YDZI8{@OEenZ_5qPq30)J;8e2&a=)_@zkQe>DhB8OHLtlAM!3V zu>gGu9gS^MgRVWpTXEmWo>EI=t~ST~y?+{4#*lZRwSrNJhQn$ydT)!7W`@m&uxy__ znz`0uN(Fe2(qID{i$)_D%ZFBH@I$ND7OJa4(S%1Id7mDgyS~j_Zv`EH5;ak;AaIv9 z3mPxHDLxr9HurZPJ%W<);sVviqu(jOVX}>Aa2TP3O`+wDMC%-aE9#gw2VahoP)Q*r z!e*f1@xE4N#)1j~Ormx0E9@?K;27pK_#SK+gt(9gz{B$JY*p|i$ZeHBFQ&$XZiXX^ zW3Rza!@G2yu#lQ&gkF3L4LBPxx&C-&SlUbKXontrY5kv<2D2yQp}X*G$rPsRfd0K$ z05z0JzxE7gqP?Py?L(^o-R)qwla+z5TJ^!Xf#QqB;#s%bjsTe2CUtyH&i&z@80TVf zsnDS&X&>3XzW_RhWE#6OI>%j<8l6Zuz@_o27lATDutvtzr`UVrrmp-4`u}9me|0$M z%&gC#V+!^E#xqd-N&Vk_g7v@a|Ih#VyQVT(qw)8@YsaAJuWWkVXrMMf6NMjJl^C@x z)qbGw8>+tlm0t9HpUy5I7&RO#rT-T`IBAWu!AzJG>SPW&fwBp89?`H`n?U@^#tqOM zE<~dkk;4d=)S;e%8zO;bM;KN)U|sSb-Ok1a{Co}m?#Nx@lTG}6=t9q6$BhvfU=6R0IUZu+ zcBiYg+$mo470g1LdtgmXzQ839pooQ7zYQH7fqVVWA$&Oo^c#HmC-6&l3_qXN=?^FZ z`W*ff>np|uzz7t?-2y=Hp5VLwyM5pW@Hoa{O+eI?at_gqhHuYoypdLHSK%s7fHT1D zFgR7MIn~y`o+SYGEK;k-vOSQ zuQ)Eb%cS8_DUhD>buQ*NARrC;0ha{vz5+9>DKZ0$wyvE8*t`S8kAgnhjZl^h4Rynm zt|N33Xn@vW$^t9aw4^X=XkLM&`z)HY3EapJMTyW2WO0GS3?ee9t-#MctoxV*?+9kX z=deIEL>VF#Q4M6cvfYI*Cq(3o0)T-LBIt-j2B1L$RYU{ufkuK`7mnqc3$ez`pYr)g zXZJ2MkzFX%$Uz|CaKKEVj@ZiuHUZjTybnJNM1kn6(>PB%-sk+lAD~6lNii561YArl z-kp^3#}?o4g9pLQdppc=;bDXPmx($>gdT%&+L z=W1XWK~+9z0=5as;VbtF9GoLMmOQ6#OBqAd1JjE=MlQhJgSm#2% z=Sx6}2x;eH`Q^L;mIWHJ)eby_?=#z{Lf(S4Kv4Vc^oqh)P!e(%T7mLsdb59JM053Ud=wDyBDFi_O9&cOq@k@7og0<-HRWg<1^^L!%GMb z)sZDZBXgtf;9@^G9EyiRvIAw0ul0k>Ueq>z03VT`sa3018|$?HMn4=3hy6E$aGK`k z=Z1Lmju5}zKk6Su1QsKMqP!iI@tRXkGoq=~_HIEq=qdn)0OcdjnQegmGcGqc!^lp< zW$2c-5nOc$c!3{KGvpud7SxD?v8jNu$-&sn0b^4IV^e}5h13OgG<7dqGcl{!BOKwT zjUty+cuCivXjirYkI;%;fYxmb^Kc%j%yaIdMRCRj_^Di5;Y%MPFpQ^omZ^04!Vr)AmEhN*M13S5**2I17IYrnAux06GtJuC&h3M6B0ySB#%OpSl;u zRKrC^AIu09(Ha&tM(%X#UZYDBYG?E!&&3|W`HpZ%!`Gv@94VSH!j&5=k^rOQfShU@ zQ~S@fW*)QIwDDZ{STDFZ!H|}F-3fK7SWLl>+?|L9Z3TgCR0luEE8`T~@t70*61?{B z=@!Y9a7KOhLz{C*^ig>wV!AP1^1DpKsyF=G&2HoQqhLC6UYhTjy=Jspq;Z11i0VnU z)B2WWV>(4@V}N+Br1Z4f=R`XXw}#-S44xbad}LFQFBc^bDhD5+BH3$)c1PHJpzK2CY5}_;&e_{pP4SX(kDqj%od9?5Nf>#&Yg?SaQ z1Cb&=tdMh#_Q>0w03=>moorkM=YJCBat(&ckFF-Xi>kVGMY` z7dFGCmh~xKhAzW&AHq%tiLDn_4noIW|0Elw>d5*sr+^{SGsAU0^ z*KYQRzA|KNz(#DqD;^NbS&5vSG@^;1nxBafPD@m3*cKN#P(%4{{`B?wHV6X*Abybi9AHDVO?m8K`Gk6G;0|}pkxm{ONVpf_ zb)G*DKD_*JIvBQvpN7veoTBh9*u+-<8TdTlZ#*X2*2lK+t)hN1yqd5dVMPLOjO+G& zF;$V6qw)2Ig=7B#`uIXnP|%Lx>L-+jArlv>3@S$00vi~-+@PJpTq*uz2=-k_r&yBFrxW8>MylOMOAZa#gs_2Z8lTh>$K zG3`EnOf8I&8qq7}9F7Iuz@$TuhwED1nI#rr!v>7w+kY;ehCMC!uRTX~9KG z+7HqGGpIr3#wD$#JHrNkK#Zw-z@%hD; zdCvub)y2T`hO%Pbj@G1t2u#Lb>E%<#SF~`E6_+Zl22umvgqaK883alJ4f|7`p2xtZ zPFDiyO`aGKz)BRp5>PkJ(~Hv?pv&j#iod!l-QYG=q??JI0&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 Unit) { - Initializer.initializeWithCallback(done) - } - - override fun isInitialized(): Boolean { - return Initializer.isInitialized() - } -} - -object CryptoPrimitives : PrimitivesApi { - - object Blake2b { - fun updateable(key: UByteArray? = null, hashLength: Int = Blake2bProperties.MAX_HASH_BYTES): com.ionspin.kotlin.crypto.hash.blake2b.Blake2bMultipart { - checkInitialization() - return Blake2bDelegated(key, hashLength) - } - - fun stateless(message: UByteArray, key: UByteArray = ubyteArrayOf(), hashLength: Int = Blake2bProperties.MAX_HASH_BYTES): UByteArray { - checkInitialization() - return Blake2bDelegatedStateless.digest(message, key, hashLength) - } - } - - object Sha256 { - fun updateable(): com.ionspin.kotlin.crypto.hash.sha.Sha256 { - checkInitialization() - return Sha256Delegated() - } - - fun stateless(message: UByteArray) : UByteArray{ - checkInitialization() - return Sha256StatelessDelegated.digest(inputMessage = message) - } - } - - object Sha512 { - fun updateable(): Sha512Multipart { - checkInitialization() - return Sha512Delegated() - } - - fun stateless(message: UByteArray) : UByteArray { - checkInitialization() - return Sha512StatelessDelegated.digest(inputMessage = message) - } - } - - private fun checkInitialization() { - if (!Initializer.isInitialized()) { - throw RuntimeException("Platform library not initialized, check if you called Initializer.initialize()") - } - } - - override fun hashBlake2bMultipart(key: UByteArray?, hashLength: Int): Blake2bMultipart { - checkInitialization() - return Blake2bDelegated(key, hashLength) - } - - override fun hashBlake2b(message: UByteArray, key: UByteArray, hashLength: Int): UByteArray { - checkInitialization() - return Blake2bDelegatedStateless.digest(message, key, hashLength) - } - - override fun hashSha256Multipart(): com.ionspin.kotlin.crypto.hash.sha.Sha256 { - checkInitialization() - return Sha256Delegated() - } - - override fun hashSha256(message: UByteArray): UByteArray { - checkInitialization() - return Sha256StatelessDelegated.digest(inputMessage = message) - } - - override fun hashSha512Multipart(): com.ionspin.kotlin.crypto.hash.sha.Sha512Multipart { - checkInitialization() - return Sha512Delegated() - } - - override fun hashSha512(message: UByteArray): UByteArray { - checkInitialization() - return Sha512StatelessDelegated.digest(inputMessage = message) - } - - override fun deriveKey( - password: String, - salt: String?, - key: String, - associatedData: String, - parallelism: Int, - tagLength: Int, - memory: Int, - numberOfIterations: Int - ): ArgonResult { -// return Argon2Delegated.derive( -// password, -// salt, -// key, -// associatedData, -// parallelism -// tagLength, -// memory, -// numberOfIterations -// ) - TODO() - } - -} - - -fun SymmetricKey.Companion.randomKey() : SymmetricKey { - return SymmetricKey(SRNG.getRandomBytes(32)) -} - -object Crypto { - - object Hash : HashApi { - override fun hash(data: UByteArray, key : UByteArray) : HashedData { - return HashedData(Blake2bDelegatedStateless.digest(data, key)) - } - - override fun multipartHash(key: UByteArray?) : com.ionspin.kotlin.crypto.hash.MultipartHash { - return Blake2bDelegated(key) - } - } - - object Encryption : EncryptionApi { - override fun encrypt(key: SymmetricKey, data : Encryptable<*>, associatedData : UByteArray) : EncryptedData { - if (key.value.size != 32) { - throw RuntimeException("Invalid key size! Required 32, supplied ${key.value.size}") - } - val nonce = SRNG.getRandomBytes(24) - return EncryptedData(XChaCha20Poly1305Delegated.encrypt(key.value, nonce, data.toEncryptableForm(), associatedData), nonce) - - } - - override fun > decrypt(key: SymmetricKey, encryptedData : EncryptedData, associatedData: UByteArray, byteArrayDeserializer : (UByteArray) -> T) : T { - return byteArrayDeserializer(XChaCha20Poly1305Delegated.decrypt(key.value, encryptedData.nonce, encryptedData.ciphertext, associatedData)) - - } - - override fun createMultipartEncryptor(key: SymmetricKey): MultipartAuthenticatedEncryption { - return MultipartAuthenticatedEncryptor(key) - } - - override fun createMultipartDecryptor(key: SymmetricKey, header: MultipartEncryptionHeader) : MultipartAuthenticatedDecryption { - val decryptor = XChaCha20Poly1305Delegated() - decryptor.initializeForDecryption(key.value, header.nonce) - return MultipartAuthenticatedDecryptor(decryptor) - } - - - } -} - -class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKey) : MultipartAuthenticatedEncryption { - - val header : MultipartEncryptionHeader - val primitive = XChaCha20Poly1305Delegated() - init { - header = MultipartEncryptionHeader(primitive.initializeForEncryption(key.value)) - } - - override fun startEncryption(): MultipartEncryptionHeader { - return header - } - - override fun encryptPartialData(data: UByteArray, associatedData: UByteArray): EncryptedDataPart { - return EncryptedDataPart(primitive.encrypt(data, associatedData)) - } - - override fun cleanup() { - primitive.cleanup() - } -} - - -class MultipartAuthenticatedDecryptor internal constructor(val decryptor: XChaCha20Poly1305Delegated) : MultipartAuthenticatedDecryption { - override fun decryptPartialData(data: EncryptedDataPart, associatedData: UByteArray): DecryptedDataPart { - return DecryptedDataPart(decryptor.decrypt(data.data, associatedData)) - } - - override fun cleanup() { - decryptor.cleanup() - } - -} - -expect object Initializer { - fun isInitialized() : Boolean - - suspend fun initialize() - - fun initializeWithCallback(done: () -> (Unit)) -} - diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/NativeInlineClassEmitter.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/NativeInlineClassEmitter.kt deleted file mode 100644 index deda2be..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/NativeInlineClassEmitter.kt +++ /dev/null @@ -1,12 +0,0 @@ -package _multiplatform_crypto_delegated - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 24-May-2020 - */ -//Workaround for https://youtrack.jetbrains.com/issue/KT-36878 -val byteArray = byteArrayOf(0) -val byte = 0.toByte() -val longArray = longArrayOf(0) -val long = 0L \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index 80e6f05..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -1,26 +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 - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -expect object SRNG { - fun getRandomBytes(amount : Int) : UByteArray -} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/DelegatedXChaCha20Poly1305.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/DelegatedXChaCha20Poly1305.kt deleted file mode 100644 index 5f92fc8..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/DelegatedXChaCha20Poly1305.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jun-2020 - */ -expect class XChaCha20Poly1305Delegated internal constructor() { - internal constructor(key: UByteArray, testState : UByteArray, testHeader: UByteArray, isDecryptor: Boolean) - companion object { - fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, associatedData: UByteArray) : UByteArray - fun decrypt(key: UByteArray, nonce: UByteArray, ciphertext: UByteArray, associatedData: UByteArray) : UByteArray - } - fun initializeForEncryption(key: UByteArray) : UByteArray - fun initializeForDecryption(key: UByteArray, header: UByteArray) - fun encrypt(data: UByteArray, associatedData: UByteArray = ubyteArrayOf()) : UByteArray - fun decrypt(data: UByteArray, associatedData: UByteArray = ubyteArrayOf()) : UByteArray - fun cleanup() - - -} - - diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt deleted file mode 100644 index 4887631..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ /dev/null @@ -1,31 +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.hash.blake2b - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jul-2019 - */ - - -expect class Blake2bDelegated(key: UByteArray? = null, hashLength: Int = Blake2bProperties.MAX_HASH_BYTES) : Blake2bMultipart - - -expect object Blake2bDelegatedStateless : Blake2b - - diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt deleted file mode 100644 index b53b3df..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ /dev/null @@ -1,29 +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.hash.sha - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - -expect class Sha256Delegated() : Sha256 - -expect object Sha256StatelessDelegated : StatelessSha256 \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt deleted file mode 100644 index 8d5b857..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ /dev/null @@ -1,29 +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.hash.sha - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - -expect class Sha512Delegated() : Sha512Multipart - -expect object Sha512StatelessDelegated : Sha512 diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt deleted file mode 100644 index 707a664..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ionspin.kotlin.crypto.keyderivation.argon2 - -import com.ionspin.kotlin.crypto.keyderivation.KeyDerivationFunction - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 24-May-2020 - */ -interface Argon2 : KeyDerivationFunction \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt deleted file mode 100644 index 6a05cbb..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/parallelization/Coroutines14.kt +++ /dev/null @@ -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 { -// val argon = Argon2() -// argon - println("Placeholder") - return emptyArray() - } -} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/util/Util.kt b/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/util/Util.kt deleted file mode 100644 index b24e406..0000000 --- a/multiplatform-crypto-delegated/src/commonMain/kotlin/com/ionspin/kotlin/crypto/util/Util.kt +++ /dev/null @@ -1,216 +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. - */ - -@file:Suppress("EXPERIMENTAL_API_USAGE") - -package com.ionspin.kotlin.crypto.util - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 15-Jul-2019 - */ - - -inline fun Array.chunked(sliceSize: Int): Array> { - val last = this.size % sliceSize - val hasLast = last != 0 - val numberOfSlices = this.size / sliceSize - - - val result : MutableList> = MutableList>(0) { emptyList() } - - for (i in 0 until numberOfSlices) { - result.add(this.slice(i * sliceSize until (i + 1) * sliceSize)) - } - if (hasLast) { - result.add(this.slice(numberOfSlices * sliceSize until this.size)) - } - - return result.map { it.toTypedArray() }.toTypedArray() - -} - - -infix fun UInt.rotateRight(places: Int): UInt { - return (this shr places) xor (this shl (32 - places)) -} - - -infix fun ULong.rotateRight(places: Int): ULong { - return (this shr places) xor (this shl (64 - places)) -} - - -infix fun Array.xor(other : Array) : Array { - if (this.size != other.size) { - throw RuntimeException("Operands of different sizes are not supported yet") - } - return Array(this.size) { this[it] xor other[it] } -} - - -infix fun UByteArray.xor(other : UByteArray) : UByteArray { - if (this.size != other.size) { - throw RuntimeException("Operands of different sizes are not supported yet") - } - return UByteArray(this.size) { this[it] xor other[it] } -} - - - - - -// UInt / Array utils - -fun UInt.toBigEndianUByteArray() : Array { - return Array (4) { - ((this shr (24 - (it * 8))) and 0xFFU).toUByte() - } -} - -fun UInt.toLittleEndianTypedUByteArray() : Array { - return Array (4) { - ((this shr (it * 8)) and 0xFFU).toUByte() - } -} - - -fun UInt.toLittleEndianUByteArray() : UByteArray { - return UByteArray (4) { - ((this shr (it * 8)) and 0xFFU).toUByte() - } -} - -// UInt / Array utils - -fun ULong.toBigEndianUByteArray() : Array { - return Array (8) { - ((this shr (56 - (it * 8))) and 0xFFU).toUByte() - } -} - -fun ULong.toLittleEndianTypedUByteArray() : Array { - return Array (8) { - ((this shr (it * 8)) and 0xFFU).toUByte() - } -} - - -fun ULong.toLittleEndianUByteArray() :UByteArray { - return UByteArray (8) { - ((this shr (it * 8)) and 0xFFU).toUByte() - } -} - - -fun Array.fromLittleEndianArrayToULong() : ULong { - if (this.size > 8) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var ulong = this.foldIndexed(0UL) { index, acc, uByte -> acc or (uByte.toULong() shl (index * 8))} - return ulong -} - - -fun UByteArray.fromLittleEndianArrayToULong() : ULong { - if (this.size > 8) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var ulong = this.foldIndexed(0UL) { index, acc, uByte -> acc or (uByte.toULong() shl (index * 8))} - return ulong -} - -fun UByteArray.arrayChunked(sliceSize: Int): List { - val last = this.size % sliceSize - val hasLast = last != 0 - val numberOfSlices = this.size / sliceSize - - - val result : MutableList = MutableList(0) { ubyteArrayOf() } - - for (i in 0 until numberOfSlices) { - result.add(this.sliceArray(i * sliceSize until (i + 1) * sliceSize)) - } - if (hasLast) { - result.add(this.sliceArray(numberOfSlices * sliceSize until this.size)) - } - - return result -} - - - -fun Array.fromBigEndianArrayToULong() : ULong { - if (this.size > 8) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var ulong = this.foldIndexed(0UL) { - index, acc, uByte -> - val res = acc or (uByte.toULong() shl (56 - (index * 8))) - res - - } - return ulong -} - - -fun Array.fromLittleEndianArrayToUInt() : UInt { - if (this.size > 4) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var uint = this.foldIndexed(0U) { index, acc, uByte -> acc or (uByte.toUInt() shl (index * 8))} - return uint -} - - -fun UByteArray.fromLittleEndianArrayToUInt() : UInt { - if (this.size > 4) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var uint = this.foldIndexed(0U) { index, acc, uByte -> acc or (uByte.toUInt() shl (index * 8))} - return uint -} - - - - - -fun Array.fromBigEndianArrayToUInt() : UInt { - if (this.size > 4) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var uint = this.foldIndexed(0U) { index, acc, uByte -> acc or (uByte.toUInt() shl (24 - (index * 8))) } - return uint -} - - -operator fun UInt.plus(other : UByteArray) : UByteArray { - return this.toLittleEndianUByteArray() + other -} - -//AES Flatten -fun Collection.flattenToUByteArray(): UByteArray { - val result = UByteArray(sumBy { it.size }) - var position = 0 - for (element in this) { - element.forEach { uByte -> - result[position] = uByte - position++ - } - } - return result -} diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/DebugTest.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/DebugTest.kt deleted file mode 100644 index 07bd5fd..0000000 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/DebugTest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.ionspin.kotlin.crypto - -import kotlin.test.Test - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2020 - */ -class DebugTest { - - -} diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SRNGTest.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SRNGTest.kt deleted file mode 100644 index 0e2235f..0000000 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SRNGTest.kt +++ /dev/null @@ -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 - -import com.ionspin.kotlin.crypto.util.testBlocking -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -class SRNGTest { - @Test - fun testSrng() = testBlocking { - CryptoInitializerDelegated.initialize() - //Just a sanity test, need to add better srng tests. - val randomBytes1 = SRNG.getRandomBytes(10) - val randomBytes2 = SRNG.getRandomBytes(10) - assertTrue { !randomBytes1.contentEquals(randomBytes2) } - } -} diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt deleted file mode 100644 index f9006e6..0000000 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt +++ /dev/null @@ -1,240 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - -import com.ionspin.kotlin.crypto.CryptoInitializerDelegated -import com.ionspin.kotlin.crypto.Initializer -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexColumsPrint -import com.ionspin.kotlin.crypto.util.testBlocking -import kotlin.test.Ignore -import kotlin.test.Test -import kotlin.test.assertFails -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jun-2020 - */ -class XChaCha20Poly1305Test { - - - @Test - fun xChaCha20Poly1305() = testBlocking { - CryptoInitializerDelegated.initialize() - - assertTrue { - val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + - "only one tip for the future, sunscreen would be it.").encodeToUByteArray() - - val associatedData = ubyteArrayOf( - 0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U - ) - val key = ubyteArrayOf( - 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, - 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, - 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, - 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU, - ) - - val nonce = ubyteArrayOf( - 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, - 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, - 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, - ) - - val expected = ubyteArrayOf( - 0xbdU, 0x6dU, 0x17U, 0x9dU, 0x3eU, 0x83U, 0xd4U, 0x3bU, - 0x95U, 0x76U, 0x57U, 0x94U, 0x93U, 0xc0U, 0xe9U, 0x39U, - 0x57U, 0x2aU, 0x17U, 0x00U, 0x25U, 0x2bU, 0xfaU, 0xccU, - 0xbeU, 0xd2U, 0x90U, 0x2cU, 0x21U, 0x39U, 0x6cU, 0xbbU, - 0x73U, 0x1cU, 0x7fU, 0x1bU, 0x0bU, 0x4aU, 0xa6U, 0x44U, - 0x0bU, 0xf3U, 0xa8U, 0x2fU, 0x4eU, 0xdaU, 0x7eU, 0x39U, - 0xaeU, 0x64U, 0xc6U, 0x70U, 0x8cU, 0x54U, 0xc2U, 0x16U, - 0xcbU, 0x96U, 0xb7U, 0x2eU, 0x12U, 0x13U, 0xb4U, 0x52U, - 0x2fU, 0x8cU, 0x9bU, 0xa4U, 0x0dU, 0xb5U, 0xd9U, 0x45U, - 0xb1U, 0x1bU, 0x69U, 0xb9U, 0x82U, 0xc1U, 0xbbU, 0x9eU, - 0x3fU, 0x3fU, 0xacU, 0x2bU, 0xc3U, 0x69U, 0x48U, 0x8fU, - 0x76U, 0xb2U, 0x38U, 0x35U, 0x65U, 0xd3U, 0xffU, 0xf9U, - 0x21U, 0xf9U, 0x66U, 0x4cU, 0x97U, 0x63U, 0x7dU, 0xa9U, - 0x76U, 0x88U, 0x12U, 0xf6U, 0x15U, 0xc6U, 0x8bU, 0x13U, - 0xb5U, 0x2eU, 0xc0U, 0x87U, 0x59U, 0x24U, 0xc1U, 0xc7U, - 0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU, - 0xcfU, 0x49U - ) - val encrypted = XChaCha20Poly1305Delegated.encrypt(key, nonce, message, associatedData) - encrypted.hexColumsPrint() - val decrypted = XChaCha20Poly1305Delegated.decrypt(key, nonce, encrypted, associatedData) - println("Decrypted") - decrypted.hexColumsPrint() - println("----------") - encrypted.contentEquals(expected) && decrypted.contentEquals(message) - } - - assertTrue { - val message = ubyteArrayOf( - 0x00U - ) - val associatedData = ubyteArrayOf( - 0x00U - ) - val key = ubyteArrayOf( - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - ) - - val nonce = ubyteArrayOf( - 0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U, 0x09U, 0x0aU, 0x0bU, - 0x0cU, 0x0dU, 0x0eU, 0x0fU, 0x10U, 0x11U, 0x12U, 0x13U, 0x14U, 0x15U, 0x16U, 0x17U, - ) - - val expected = ubyteArrayOf( - 0xbdU, 0x3bU, 0x8aU, 0xd7U, 0xa1U, 0x9dU, 0xe8U, 0xc4U, 0x55U, - 0x84U, 0x6fU, 0xfcU, 0x75U, 0x31U, 0xbfU, 0x0cU, 0x2dU - ) - val encrypted = XChaCha20Poly1305Delegated.encrypt(key, nonce, message, associatedData) - val decrypted = XChaCha20Poly1305Delegated.decrypt(key, nonce, encrypted, associatedData) - - encrypted.contentEquals(expected) && decrypted.contentEquals(message) - } - - - } - - @Ignore() //"Will fail because nonce is not a parameter any more" - @Test - fun updateableXChaCha20Poly1305() { - assertTrue { - val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + - "only one tip for the future, sunscreen would be it.").encodeToUByteArray() - - val associatedData = ubyteArrayOf( - 0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U - ) - val key = ubyteArrayOf( - 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, - 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, - 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, - 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU, - ) - - val nonce = ubyteArrayOf( - 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, - 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, - 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, - ) - - val expected = ubyteArrayOf( - 0xbdU, 0x6dU, 0x17U, 0x9dU, 0x3eU, 0x83U, 0xd4U, 0x3bU, - 0x95U, 0x76U, 0x57U, 0x94U, 0x93U, 0xc0U, 0xe9U, 0x39U, - 0x57U, 0x2aU, 0x17U, 0x00U, 0x25U, 0x2bU, 0xfaU, 0xccU, - 0xbeU, 0xd2U, 0x90U, 0x2cU, 0x21U, 0x39U, 0x6cU, 0xbbU, - 0x73U, 0x1cU, 0x7fU, 0x1bU, 0x0bU, 0x4aU, 0xa6U, 0x44U, - 0x0bU, 0xf3U, 0xa8U, 0x2fU, 0x4eU, 0xdaU, 0x7eU, 0x39U, - 0xaeU, 0x64U, 0xc6U, 0x70U, 0x8cU, 0x54U, 0xc2U, 0x16U, - 0xcbU, 0x96U, 0xb7U, 0x2eU, 0x12U, 0x13U, 0xb4U, 0x52U, - 0x2fU, 0x8cU, 0x9bU, 0xa4U, 0x0dU, 0xb5U, 0xd9U, 0x45U, - 0xb1U, 0x1bU, 0x69U, 0xb9U, 0x82U, 0xc1U, 0xbbU, 0x9eU, - 0x3fU, 0x3fU, 0xacU, 0x2bU, 0xc3U, 0x69U, 0x48U, 0x8fU, - 0x76U, 0xb2U, 0x38U, 0x35U, 0x65U, 0xd3U, 0xffU, 0xf9U, - 0x21U, 0xf9U, 0x66U, 0x4cU, 0x97U, 0x63U, 0x7dU, 0xa9U, - 0x76U, 0x88U, 0x12U, 0xf6U, 0x15U, 0xc6U, 0x8bU, 0x13U, - 0xb5U, 0x2eU, 0xc0U, 0x87U, 0x59U, 0x24U, 0xc1U, 0xc7U, - 0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU, - 0xcfU, 0x49U - ) -// val xChaChaPoly = XChaCha20Poly1305Delegated(key, associatedData) -// val firstChunk = xChaChaPoly.encrypt(message) -// val finalChunk = xChaChaPoly.finishEncryption().first -// val result = firstChunk + finalChunk - -// result.contentEquals(expected) - 1 == 1 - } - - assertTrue { - val message = ubyteArrayOf( - 0x00U - ) - val associatedData = ubyteArrayOf( - 0x00U - ) - val key = ubyteArrayOf( - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - ) - - val nonce = ubyteArrayOf( - 0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U, 0x09U, 0x0aU, 0x0bU, - 0x0cU, 0x0dU, 0x0eU, 0x0fU, 0x10U, 0x11U, 0x12U, 0x13U, 0x14U, 0x15U, 0x16U, 0x17U, - ) - - val expected = ubyteArrayOf( - 0xbdU, 0x3bU, 0x8aU, 0xd7U, 0xa1U, 0x9dU, 0xe8U, 0xc4U, 0x55U, - 0x84U, 0x6fU, 0xfcU, 0x75U, 0x31U, 0xbfU, 0x0cU, 0x2dU - ) -// val xChaChaPoly = XChaCha20Poly1305Delegated(key, associatedData) -// val firstChunk = xChaChaPoly.encrypt(message) -// val finalChunk = xChaChaPoly.finishEncryption().first -// val result = firstChunk + finalChunk -// result.contentEquals(expected) - 1 == 1 - } - - - } - - @Test - fun testStreamingImpl() = testBlocking { - Initializer.initialize() - val key = UByteArray(32) { 0U } - val state = ubyteArrayOf( - 0x2DU, 0xDBU, 0xC7U, 0xB2U, 0x03U, 0xBCU, 0xC3U, 0x22U, 0xBDU, 0x0CU, 0xBAU, 0x82U, 0xADU, 0x77U, 0x79U, 0x44U, - 0xE6U, 0x8FU, 0xA9U, 0x94U, 0x89U, 0xB1U, 0xDFU, 0xBEU, 0x00U, 0x9FU, 0x69U, 0xECU, 0x21U, 0x88U, 0x47U, 0x55U, - 0x01U, 0x00U, 0x00U, 0x00U, 0xC5U, 0x55U, 0x06U, 0x38U, 0xEBU, 0xA3U, 0x12U, 0x7BU, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, - ) - val header = ubyteArrayOf( - 0x49U, 0x62U, 0x22U, 0x03U, 0xB7U, 0x46U, 0x11U, 0x97U, 0x8FU, 0x46U, 0x4AU, 0x3BU, 0x2FU, 0x2AU, 0x81U, 0x03U, - 0xC5U, 0x55U, 0x06U, 0x38U, 0xEBU, 0xA3U, 0x12U, 0x7BU, - ) - val expected = ubyteArrayOf( - 0xAFU, 0xD3U, 0x2DU, 0x59U, 0xB8U, 0xC4U, 0x66U, 0x2EU, 0x47U, 0x29U, 0xC6U, 0xF9U, 0x93U, 0x4BU, 0x09U, 0x27U, - 0x24U, 0xDDU, 0xF3U, 0x05U, 0x48U, 0x94U, 0x67U, 0x10U, 0x00U, 0x21U, 0x85U, 0x22U, 0x96U, 0x3CU, 0xCEU, 0x8EU, - 0xB7U, 0x53U, 0x9DU, 0x46U, 0xF5U, 0x3CU, 0x5EU, 0x48U, 0x9BU, 0x8CU, 0x13U, 0xB7U, 0x28U, 0x6BU, 0xB3U, 0x6CU, - 0x3AU, 0x04U, 0xB7U, 0x25U, 0xB9U, 0x50U, 0x45U, 0x08U, 0x0BU, 0x89U, 0xA2U, 0x0FU, 0x70U, 0xCCU, 0x60U, 0x1BU, - 0xC3U, 0x17U, 0x35U, 0x9FU, 0xAEU, 0x82U, 0x51U, 0x43U, 0x1BU, 0x9DU, 0x53U, 0x9EU, 0xE2U, 0xAFU, 0x20U, 0x1FU, - 0xFDU, 0x03U, 0x59U, 0x11U, 0x51U, 0x9EU, 0xACU, 0x83U, 0xCDU, 0x78U, 0xD1U, 0xD0U, 0xE5U, 0xD7U, 0x0EU, 0x41U, - 0xDEU, 0xFBU, 0x5CU, 0x7FU, 0x1CU, 0x26U, 0x32U, 0x2CU, 0x51U, 0xF6U, 0xEFU, 0xC6U, 0x34U, 0xC4U, 0xACU, 0x6CU, - 0xE8U, 0xF9U, 0x4BU, 0xABU, 0xA3U, - ) - val encryptor = XChaCha20Poly1305Delegated(key, state, header, false) - val decryptor = XChaCha20Poly1305Delegated(key, state, header, true) - val data = UByteArray(100) { 0U } - val result = encryptor.encrypt(data) - val decrypted = decryptor.decrypt(result) - println("Encrypted -----------") - result.hexColumsPrint() - println("Encrypted end -----------") - println("Decrypted -----------") - decrypted.hexColumsPrint() - println("Decrypted end -----------") - assertTrue { - expected.contentEquals(result) && decrypted.contentEquals(data) - } - val messedUpTag = result.copyOf() - messedUpTag[messedUpTag.size - 3] = 0U - messedUpTag[messedUpTag.size - 2] = 0U - messedUpTag[messedUpTag.size - 1] = 0U - assertFails { - val decryptorForWrongTag = XChaCha20Poly1305Delegated(key, state, header, true) - val plaintext = decryptorForWrongTag.decrypt(messedUpTag) - println("Decrypted with wrong tag -----------") - plaintext.hexColumsPrint() - println("Decrypted with wrong tag end -----------") - } - } -} diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bTest.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bTest.kt deleted file mode 100644 index 1fea8a7..0000000 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bTest.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.blake2b - -import com.ionspin.kotlin.crypto.Crypto -import com.ionspin.kotlin.crypto.CryptoPrimitives -import com.ionspin.kotlin.crypto.Initializer -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.testBlocking -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.BeforeTest -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 09-Jun-2020 - */ -class Blake2bTest { - - - - @Test - fun statelessSimpleTest() = testBlocking { - Initializer.initialize() - val expected = "a71079d42853dea26e453004338670a53814b78137ffbed07603a41d76a483aa9bc33b582f77d30a65e6f29a89" + - "6c0411f38312e1d66e0bf16386c86a89bea572" - val result = CryptoPrimitives.Blake2b.stateless("test".encodeToUByteArray()).toHexString() -// println("Result: $result") - assertTrue { result == expected } - } - - //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() = testBlocking { - Initializer.initialize() - val expected = "a71079d42853dea26e453004338670a53814b78137ffbed07603a41d76a483aa9bc33b582f77d30a65e6f29a89" + - "6c0411f38312e1d66e0bf16386c86a89bea572" - val blake2b = CryptoPrimitives.Blake2b.updateable() - blake2b.update("t".encodeToUByteArray()) - blake2b.update(("est".encodeToUByteArray())) - val result = blake2b.digest().toHexString() -// println("Result: $result") - assertTrue { result == expected } - } -} diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt deleted file mode 100644 index 2068b0f..0000000 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -import com.ionspin.kotlin.crypto.Crypto -import com.ionspin.kotlin.crypto.CryptoPrimitives -import com.ionspin.kotlin.crypto.Initializer -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.testBlocking -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.BeforeTest -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 07-Jun-2020 - */ -class Sha256Test { - @BeforeTest - fun beforeTest() = testBlocking { - Initializer.initialize() - } - - @Test - fun statelessSimpleTest() = testBlocking { - Initializer.initialize() - val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" - val result = CryptoPrimitives.Sha256.stateless("test".encodeToUByteArray()).toHexString() -// println("Result: $result") - assertTrue { result == expected } - } - - //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() = testBlocking { - Initializer.initialize() - val expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" - val sha256 = CryptoPrimitives.Sha256.updateable() - sha256.update("t".encodeToUByteArray()) - sha256.update(("est".encodeToUByteArray())) - val result = sha256.digest().toHexString() -// println("Result: $result") - assertTrue { result == expected } - } -} diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt deleted file mode 100644 index 44a0375..0000000 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -import com.ionspin.kotlin.crypto.Crypto -import com.ionspin.kotlin.crypto.CryptoPrimitives -import com.ionspin.kotlin.crypto.Initializer -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.testBlocking -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.BeforeTest -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 07-Jun-2020 - */ -class Sha512Test { - @BeforeTest - fun beforeTest() = testBlocking { - Initializer.initialize() - } - - @Test - fun statelessSimpleTest() = testBlocking { - Initializer.initialize() - val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" + - "b143732c304cc5fa9ad8e6f57f50028a8ff" - val result = CryptoPrimitives.Sha512.stateless("test".encodeToUByteArray()).toHexString() -// println("Result: $result") - assertTrue { result == expected } - } - - //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() = testBlocking { - Initializer.initialize() - val expected = "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67" + - "b143732c304cc5fa9ad8e6f57f50028a8ff" - val sha512 = CryptoPrimitives.Sha512.updateable() - sha512.update("t".encodeToUByteArray()) - sha512.update(("est".encodeToUByteArray())) - val result = sha512.digest().toHexString() -// println("Result: $result") - assertTrue { result == expected } - } -} diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/highlevel/EncryptionTest.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/highlevel/EncryptionTest.kt deleted file mode 100644 index 9573fcc..0000000 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/highlevel/EncryptionTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.ionspin.kotlin.crypto.highlevel - -import com.ionspin.kotlin.crypto.Crypto -import com.ionspin.kotlin.crypto.Initializer -import com.ionspin.kotlin.crypto.SymmetricKey -import com.ionspin.kotlin.crypto.hash.decodeToString -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexColumsPrint -import com.ionspin.kotlin.crypto.util.testBlocking -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 09-Jul-2020 - */ -class EncryptionTest { - @Test - fun testMultipartEncryption() = testBlocking { - Initializer.initialize() - val plaintext = ("pUoR4JVXJUeMKNkt6ZGGzEdTo33ajNGXwXpivBKA0XKs8toGRYI9Eul4bELRDkaQDNhd4vZseEFU" + - "ojsAn3c9zIifIrMnydSivHVZ2pBtpAQwYoJhYmEsfE0tROGnOwFWyB9K6LRSv1gB3YqKR9VyM8mpRoUM3UCRRjyiX7bnKdCE1" + - "EiX0myiwcY1nUKTgB3keERWtMU07hX7bCtao5nRvDofSj3o3IInHRQh6opltr5asQwn4m1qn029QF").encodeToUByteArray() - val associatedData = "Additional data 1".encodeToUByteArray() - val keyValue = UByteArray(32) { it.toUByte() } - val key = SymmetricKey(keyValue) - val encryptor = Crypto.Encryption.createMultipartEncryptor(key) - val header = encryptor.startEncryption() - val ciphertext1 = encryptor.encryptPartialData(plaintext.sliceArray(0 until 100), associatedData) - val ciphertext2 = encryptor.encryptPartialData(plaintext.sliceArray(100 until 200)) - val ciphertext3 = encryptor.encryptPartialData(plaintext.sliceArray(200 until 250)) - //decrypt - val decryptor = Crypto.Encryption.createMultipartDecryptor(key, header) - val plaintext1 = decryptor.decryptPartialData(ciphertext1, associatedData) - val plaintext2 = decryptor.decryptPartialData(ciphertext2) - val plaintext3 = decryptor.decryptPartialData(ciphertext3) - - val combinedPlaintext = plaintext1.data + plaintext2.data + plaintext3.data - assertTrue { - plaintext.contentEquals(combinedPlaintext) - } - encryptor.cleanup() - decryptor.cleanup() - - - - - } -} diff --git a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt b/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt deleted file mode 100644 index 7d938dd..0000000 --- a/multiplatform-crypto-delegated/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt +++ /dev/null @@ -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.util - -import kotlin.coroutines.Continuation -import kotlin.coroutines.EmptyCoroutineContext -import kotlin.coroutines.startCoroutine - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ -fun testBlocking(block : suspend () -> Unit) { - val continuation = Continuation(EmptyCoroutineContext) { - //Do nothing - if (it.isFailure) { - throw it.exceptionOrNull()!! - } - } - block.startCoroutine(continuation) -} diff --git a/multiplatform-crypto-delegated/src/iosMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto-delegated/src/iosMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/iosTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto-delegated/src/iosTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt deleted file mode 100644 index 9567243..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.ionspin.kotlin.crypto - -import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumInterface -import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumLoader -/* 1.4-M1 has some weirdness with static/objects, or I'm misusing something, not sure */ -lateinit var sodiumPointer : JsSodiumInterface -var sodiumLoaded: Boolean = false - -fun getSodium() : JsSodiumInterface = sodiumPointer - -//fun getSodiumAdvanced() : JsSodiumAdvancedInterface = js("sodiumPointer.libsodium") - -fun setSodiumPointer(jsSodiumInterface: JsSodiumInterface) { - js("sodiumPointer = jsSodiumInterface") -} - -fun getSodiumLoaded() : Boolean = sodiumLoaded - -fun setSodiumLoaded(loaded: Boolean) { - js("sodiumLoaded = loaded") -} - -actual object Initializer { - private var isPlatformInitialized = false - - actual suspend fun initialize() { - JsSodiumLoader.load() - isPlatformInitialized = true - } - - actual fun initializeWithCallback(done: () -> Unit) { - JsSodiumLoader.loadWithCallback { - isPlatformInitialized = true - done() - } - } - - actual fun isInitialized(): Boolean { - return isPlatformInitialized - } - - -} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt deleted file mode 100644 index b917faf..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumInterface.kt +++ /dev/null @@ -1,60 +0,0 @@ -package ext.libsodium.com.ionspin.kotlin.crypto - - -import org.khronos.webgl.Uint8Array - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 27-May-2020 - */ -interface JsSodiumInterface { - - fun randombytes_buf(numberOfBytes: Int): Uint8Array - - fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array,): Uint8Array - - fun crypto_hash_sha256(message: Uint8Array): Uint8Array - - fun crypto_hash_sha512(message: Uint8Array): Uint8Array - - //Updateable - - fun crypto_generichash_init(key : Uint8Array, hashLength: Int) : dynamic - - fun crypto_generichash_update(state: dynamic, inputMessage: Uint8Array) - - fun crypto_generichash_final(state: dynamic, hashLength: Int) : Uint8Array - - - fun crypto_hash_sha256_init() : dynamic - - fun crypto_hash_sha256_update(state: dynamic, message: Uint8Array) - - fun crypto_hash_sha256_final(state: dynamic): Uint8Array - - fun crypto_hash_sha512_init() : dynamic - - fun crypto_hash_sha512_update(state: dynamic, message: Uint8Array) - - fun crypto_hash_sha512_final(state: dynamic): Uint8Array - - //XChaCha20Poly1305 - fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array - fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, associatedData: 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, associatedData: Uint8Array, tag: UByte) : Uint8Array - - //decrypt - fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic - fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, associatedData: Uint8Array) : dynamic - - //util - fun memzero(array: Uint8Array) - - - -} diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt deleted file mode 100644 index b445487..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsSodiumLoader.kt +++ /dev/null @@ -1,56 +0,0 @@ -package ext.libsodium.com.ionspin.kotlin.crypto - -import com.ionspin.kotlin.crypto.getSodiumLoaded -import com.ionspin.kotlin.crypto.setSodiumPointer -import com.ionspin.kotlin.crypto.sodiumLoaded -import ext.libsodium.* -import kotlin.coroutines.Continuation -import kotlin.coroutines.suspendCoroutine - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 27-May-2020 - */ -object JsSodiumLoader { - - class _EmitJsSodiumFunction { - init { - println(::crypto_generichash) - println(::crypto_hash_sha256) - println(::crypto_hash_sha512) - println(::crypto_hash_sha256_init) - } - - } - - fun storeSodium(promisedSodium: dynamic, continuation: Continuation) { - setSodiumPointer(promisedSodium) - sodiumLoaded = true - continuation.resumeWith(Result.success(Unit)) - } - - suspend fun load() = suspendCoroutine { continuation -> - console.log(getSodiumLoaded()) - if (!getSodiumLoaded()) { - val libsodiumModule = js("\$module\$libsodium_wrappers_sumo") - _libsodiumPromise.then { storeSodium(libsodiumModule, continuation) } - } else { - continuation.resumeWith(Result.success(Unit)) - } - } - - fun loadWithCallback(doneCallback: () -> (Unit)) { - console.log(getSodiumLoaded()) - if (!getSodiumLoaded()) { - val libsodiumModule = js("\$module\$libsodium_wrappers_sumo") - _libsodiumPromise.then { - setSodiumPointer(libsodiumModule) - sodiumLoaded = true - doneCallback.invoke() - } - } else { - doneCallback.invoke() - } - } -} diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt deleted file mode 100644 index 1c001d2..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/JsUtil.kt +++ /dev/null @@ -1,27 +0,0 @@ -package ext.libsodium.com.ionspin.kotlin.crypto - -import org.khronos.webgl.Uint8Array -import org.khronos.webgl.get -import org.khronos.webgl.set - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 25-Jun-2020 - * - * TODO investigate using unsafe cast - */ -fun UByteArray.toUInt8Array() : Uint8Array { - val uint8Result = Uint8Array(toByteArray().toTypedArray()) - return uint8Result -} - - -fun Uint8Array.toUByteArray() : UByteArray { - val result = UByteArray(length) - for (i in 0 until length) { - result[i] = get(i).toUByte() - } - - return result -} 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 deleted file mode 100644 index 862aae9..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -1,43 +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 - -import org.khronos.webgl.get - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -actual object SRNG { - var counter = 0 - - actual fun getRandomBytes(amount: Int): UByteArray { - val randomBytes = getSodium().randombytes_buf(amount) - val randomBytesUByteArray = UByteArray(amount) { - 0U - } - for (i in 0 until amount) { - js(""" - randomBytesUByteArray[i] = randomBytes[i] - """) - } - return randomBytesUByteArray - } - - -} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt deleted file mode 100644 index faeea44..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt +++ /dev/null @@ -1,130 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - -import com.ionspin.kotlin.crypto.InvalidTagException -import com.ionspin.kotlin.crypto.getSodium -import com.ionspin.kotlin.crypto.util.hexColumsPrint -import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray -import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array -import org.khronos.webgl.Uint8Array - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 25-Jun-2020 - */ - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jun-2020 - */ -actual class XChaCha20Poly1305Delegated internal actual constructor() { - actual companion object { - actual fun encrypt( - key: UByteArray, - nonce: UByteArray, - message: UByteArray, - associatedData: UByteArray - ): UByteArray { - val encrypted = getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt( - message.toUInt8Array(), - associatedData.toUInt8Array(), - Uint8Array(0), - nonce.toUInt8Array(), - key.toUInt8Array() - ) - return encrypted.toUByteArray() - } - - actual fun decrypt( - key: UByteArray, - nonce: UByteArray, - ciphertext: UByteArray, - associatedData: UByteArray - ): UByteArray { - val decrypted = getSodium().crypto_aead_xchacha20poly1305_ietf_decrypt( - Uint8Array(0), - ciphertext.toUInt8Array(), - associatedData.toUInt8Array(), - nonce.toUInt8Array(), - key.toUInt8Array() - ) - return decrypted.toUByteArray() - } - } - - var state : dynamic = null - var isInitialized = false - var isEncryptor = false - - actual fun initializeForEncryption(key: UByteArray) : UByteArray { - println("Initializaing for encryption") - val stateAndHeader = getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array()) - state = stateAndHeader.state - val header = stateAndHeader.header as Uint8Array - console.log(state) - console.log(header) - println("Done initializaing for encryption") - isInitialized = true - isEncryptor = true - return header.toUByteArray() - } - - actual fun initializeForDecryption(key: UByteArray, header: UByteArray) { - println("Initializing for decryption") - header.hexColumsPrint() - state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(), key.toUInt8Array()) - console.log(state) - isInitialized = true - isEncryptor = false - } - - internal actual constructor( - key: UByteArray, - testState: UByteArray, - testHeader: UByteArray, - isDecryptor: Boolean - ) : this() { - state = getSodium().crypto_secretstream_xchacha20poly1305_init_pull(testHeader.toUInt8Array(), key.toUInt8Array()) - console.log(state) - println("Done initializaing test state") - isInitialized = true - isEncryptor = !isDecryptor - } - - actual fun encrypt(data: UByteArray, associatedData: UByteArray): UByteArray { - if (!isInitialized) { - throw RuntimeException("Not initalized!") - } - if (!isEncryptor) { - throw RuntimeException("Initialized as decryptor, attempted to use as encryptor") - } - val encrypted = getSodium().crypto_secretstream_xchacha20poly1305_push(state, data.toUInt8Array(), associatedData.toUInt8Array(), 0U) - return encrypted.toUByteArray() - } - - actual fun decrypt(data: UByteArray, associatedData: UByteArray): UByteArray { - if (!isInitialized) { - throw RuntimeException("Not initalized!") - } - if (isEncryptor) { - throw RuntimeException("Initialized as encryptor, attempted to use as decryptor") - } - val decryptedWithTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(state, data.toUInt8Array(), associatedData.toUInt8Array()) - val decrypted = decryptedWithTag.message as Uint8Array - val validTag = decryptedWithTag.tag - - if (validTag != 0U) { - println("Tag validation failed") - throw InvalidTagException() - } - return decrypted.toUByteArray() - } - - actual fun cleanup() { - //TODO JS cleanup - } - - - -} 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 deleted file mode 100644 index fa53403..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.blake2b - -import com.ionspin.kotlin.crypto.getSodium -import org.khronos.webgl.Uint8Array -import org.khronos.webgl.get - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jul-2019 - */ - - -actual class Blake2bDelegated actual constructor(key: UByteArray?, val hashLength: Int) : Blake2bMultipart { - override val MAX_HASH_BYTES: Int = 64 - - - val state : dynamic - - init { - state = getSodium().crypto_generichash_init( - Uint8Array(key?.toByteArray()?.toTypedArray() ?: arrayOf()), - hashLength - ) - } - - override fun update(data: UByteArray) { - getSodium().crypto_generichash_update(state, Uint8Array(data.toByteArray().toTypedArray())) - } - - override fun digest(): UByteArray { - val hashed = getSodium().crypto_generichash_final(state, hashLength) - val hash = UByteArray(hashLength) - for (i in 0 until hashLength) { - hash[i] = hashed[i].toUByte() - } - return hash - } - -} - - - -actual object Blake2bDelegatedStateless : Blake2b { - override val MAX_HASH_BYTES: Int = 64 - - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { - val hashed = getSodium().crypto_generichash(hashLength, - Uint8Array(inputMessage.toByteArray().toTypedArray()), - Uint8Array(key.toByteArray().toTypedArray()) - ) - val hash = UByteArray(hashLength) - for (i in 0 until hashLength) { - 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 deleted file mode 100644 index 935e18a..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -import com.ionspin.kotlin.crypto.getSodium - -import org.khronos.webgl.Uint8Array -import org.khronos.webgl.get - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - -actual class Sha256Delegated : Sha256 { - - val state : dynamic - - init { - state = getSodium().crypto_hash_sha256_init() - } - - override fun update(data: UByteArray) { - getSodium().crypto_hash_sha256_update(state, Uint8Array(data.toByteArray().toTypedArray())) - } - - override fun digest(): UByteArray { - 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 - } - -} - -actual object Sha256StatelessDelegated : StatelessSha256 { - - override fun digest(inputMessage: UByteArray): UByteArray { - val hashed = getSodium().crypto_hash_sha256(Uint8Array(inputMessage.toByteArray().toTypedArray())) - val hash = UByteArray(MAX_HASH_BYTES) - for (i in 0 until 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/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt deleted file mode 100644 index 552932b..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -import com.ionspin.kotlin.crypto.getSodium - -import org.khronos.webgl.Uint8Array -import org.khronos.webgl.get - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - -actual class Sha512Delegated : Sha512Multipart { - val state : dynamic - - init { - state = getSodium().crypto_hash_sha512_init() - } - - override fun update(data: UByteArray) { - getSodium().crypto_hash_sha512_update(state, Uint8Array(data.toByteArray().toTypedArray())) - } - - override fun digest(): UByteArray { - 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 - } - -} - -actual object Sha512StatelessDelegated : Sha512 { - - override fun digest(inputMessage: UByteArray): UByteArray { - 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 - } -} diff --git a/multiplatform-crypto-delegated/src/jsMain/kotlin/libsodium.kt b/multiplatform-crypto-delegated/src/jsMain/kotlin/libsodium.kt deleted file mode 100644 index f37c329..0000000 --- a/multiplatform-crypto-delegated/src/jsMain/kotlin/libsodium.kt +++ /dev/null @@ -1,28 +0,0 @@ -@file:JsModule("libsodium-wrappers-sumo") -@file:JsNonModule -package ext.libsodium - -import org.khronos.webgl.Uint8Array -import kotlin.js.Promise - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 25-May-2020 - */ - -@JsName("ready") -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/jsTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/SRNGJsTest.kt b/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/SRNGJsTest.kt deleted file mode 100644 index 9324d37..0000000 --- a/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/SRNGJsTest.kt +++ /dev/null @@ -1,52 +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 - -import com.ionspin.kotlin.crypto.util.testBlocking -import ext.libsodium.com.ionspin.kotlin.crypto.JsSodiumLoader -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 05-Jan-2020 - */ - -class SRNGJsTest { - - @Test - fun testJsSrng() = testBlocking { - JsSodiumLoader.load() - val bytes1 = SRNG.getRandomBytes(10) - val bytes2 = SRNG.getRandomBytes(10) -// println("BYTES1\n") -// bytes1.forEach { -// print(it.toString(16).padStart(2, '0')) -// } -// println("BYTES2\n") -// bytes2.forEach { -// print(it.toString(16).padStart(2, '0')) -// } - assertTrue { - !bytes1.contentEquals(bytes2) && - bytes1.size == 10 && - bytes2.size == 10 - } - - } -} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt deleted file mode 100644 index a366756..0000000 --- a/multiplatform-crypto-delegated/src/jsTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ /dev/null @@ -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() } diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt deleted file mode 100644 index 082ea90..0000000 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.ionspin.kotlin.crypto - -import com.goterl.lazycode.lazysodium.SodiumJava - -actual object Initializer { - private var isPlatformInitialized = false - - lateinit var sodium : SodiumJava - actual suspend fun initialize() { - sodium = SodiumJava() - isPlatformInitialized = true - } - - actual fun initializeWithCallback(done: () -> Unit) { - sodium = SodiumJava() - isPlatformInitialized = true - done() - } - - actual fun isInitialized(): Boolean { - return isPlatformInitialized - } - - -} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index 3d50e6f..0000000 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -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 - -import java.security.SecureRandom - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ - -actual object SRNG { - val secureRandom = SecureRandom() - actual fun getRandomBytes(amount: Int): UByteArray { - val byteArray = ByteArray(amount) - secureRandom.nextBytes(byteArray) - return byteArray.asUByteArray() - } -} diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt deleted file mode 100644 index cb2cdfe..0000000 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt +++ /dev/null @@ -1,142 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - -import com.goterl.lazycode.lazysodium.SodiumJava -import com.goterl.lazycode.lazysodium.interfaces.SecretStream -import com.ionspin.kotlin.crypto.InvalidTagException -import com.ionspin.kotlin.crypto.util.hexColumsPrint - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jun-2020 - */ -actual class XChaCha20Poly1305Delegated internal actual constructor() { - actual companion object { - actual fun encrypt( - key: UByteArray, - nonce: UByteArray, - message: UByteArray, - associatedData: UByteArray - ): UByteArray { - val ciphertext = ByteArray(message.size + 16) - SodiumJava().crypto_aead_xchacha20poly1305_ietf_encrypt( - ciphertext, - longArrayOf(ciphertext.size.toLong()), - message.toByteArray(), - message.size.toLong(), - associatedData.toByteArray(), - associatedData.size.toLong(), - null, - nonce.toByteArray(), - key.toByteArray() - - ) - return ciphertext.asUByteArray() - } - - actual fun decrypt( - key: UByteArray, - nonce: UByteArray, - ciphertext: UByteArray, - associatedData: UByteArray - ): UByteArray { - val message = ByteArray(ciphertext.size - 16) - SodiumJava().crypto_aead_xchacha20poly1305_ietf_decrypt( - message, - longArrayOf(ciphertext.size.toLong()), - null, - ciphertext.toByteArray(), - ciphertext.size.toLong(), - associatedData.toByteArray(), - associatedData.size.toLong(), - nonce.toByteArray(), - key.toByteArray() - - ) - return message.asUByteArray() - } - } - - val state : SecretStream.State = SecretStream.State() - val sodium = SodiumJava() - - var isInitialized = false - var isEncryptor = false - - internal actual constructor( - key: UByteArray, - testState: UByteArray, - testHeader: UByteArray, - isDecryptor: Boolean - ) : this() { - state.k = testState.sliceArray(0 until 32).toByteArray() - state.nonce = testState.sliceArray(32 until 44).toByteArray() - isInitialized = true - isEncryptor = !isDecryptor - } - - actual fun initializeForEncryption(key: UByteArray) : UByteArray { - val header = UByteArray(24) - sodium.crypto_secretstream_xchacha20poly1305_init_push(state, header.asByteArray(), key.asByteArray()) - isInitialized = true - isEncryptor = true - return header - } - - actual fun initializeForDecryption(key: UByteArray, header: UByteArray) { - sodium.crypto_secretstream_xchacha20poly1305_init_pull(state, header.asByteArray(), key.asByteArray()) - isInitialized = true - isEncryptor = false - } - - actual fun encrypt(data: UByteArray, associatedData: UByteArray): UByteArray { - if (!isInitialized) { - throw RuntimeException("Not initalized!") - } - if (!isEncryptor) { - throw RuntimeException("Initialized as decryptor, attempted to use as encryptor") - } - val ciphertext = ByteArray(1 + data.size + 16) - sodium.crypto_secretstream_xchacha20poly1305_push( - state, ciphertext, null, - data.asByteArray(), data.size.toLong(), - associatedData.asByteArray(), associatedData.size.toLong(), - 0 - ) - return ciphertext.asUByteArray() - } - - actual fun decrypt(data: UByteArray, associatedData: UByteArray): UByteArray { - if (!isInitialized) { - throw RuntimeException("Not initalized!") - } - if (isEncryptor) { - throw RuntimeException("Initialized as encryptor, attempted to use as decryptor") - } - val plaintext = ByteArray(data.size - 17) - - val validTag = sodium.crypto_secretstream_xchacha20poly1305_pull( - state, plaintext, null, - null, - data.asByteArray(), - (data.size).toLong(), - associatedData.asByteArray(), - associatedData.size.toLong() - ) - if (validTag != 0) { - println("Tag validation failed") - throw InvalidTagException() - } - return plaintext.asUByteArray() - - } - - actual fun cleanup() { - sodium.sodium_memzero(state.k, 32) - sodium.sodium_memzero(state.nonce, 12) - } - - - - -} 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 deleted file mode 100644 index bc46c5b..0000000 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.blake2b - -import com.ionspin.kotlin.crypto.Initializer.sodium -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jul-2019 - */ - - -actual class Blake2bDelegated actual constructor(key: UByteArray?, val hashLength: Int) : Blake2bMultipart { - - val state = ByteArray(sodium.crypto_generichash_statebytes()) - - init { - sodium.crypto_generichash_init(state,key?.toByteArray() ?: byteArrayOf(), key?.size ?: 0, hashLength) - } - - override fun update(data: UByteArray) { - sodium.crypto_generichash_update(state, data.toByteArray(), data.size.toLong()) - } - - override fun digest(): UByteArray { - val hashed = ByteArray(hashLength) - sodium.crypto_generichash_final(state, hashed, hashLength) - return hashed.asUByteArray() - } - -} - -actual object Blake2bDelegatedStateless : Blake2b { - - - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { - val hashed = ByteArray(hashLength) - sodium.crypto_generichash(hashed, hashed.size, inputMessage.toByteArray(), inputMessage.size.toLong(), key.toByteArray(), key.size) - return hashed.asUByteArray() - } - -} diff --git a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt b/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt deleted file mode 100644 index ff8faa9..0000000 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -import com.goterl.lazycode.lazysodium.interfaces.Hash -import com.ionspin.kotlin.crypto.Initializer.sodium - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - -actual class Sha256Delegated actual constructor() : Sha256 { - - val state = Hash.State256() - - init { - sodium.crypto_hash_sha256_init(state) - } - - override fun update(data: UByteArray) { - sodium.crypto_hash_sha256_update(state, data.toByteArray(), data.size.toLong()) - } - - override fun digest(): UByteArray { - val hashed = ByteArray(Sha256Properties.MAX_HASH_BYTES) - sodium.crypto_hash_sha256_final(state, hashed) - return hashed.asUByteArray() - } - -} - -actual object Sha256StatelessDelegated : StatelessSha256 { - - override fun digest(inputMessage: UByteArray): UByteArray { - val hashed = ByteArray(Sha256Properties.MAX_HASH_BYTES) - sodium.crypto_hash_sha256(hashed, inputMessage.toByteArray(), inputMessage.size.toLong()) - return hashed.asUByteArray() - } -} 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 deleted file mode 100644 index adbb1b4..0000000 --- a/multiplatform-crypto-delegated/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -import com.goterl.lazycode.lazysodium.interfaces.Hash -import com.ionspin.kotlin.crypto.Initializer - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - -actual class Sha512Delegated : Sha512Multipart { - - val state = Hash.State512() - - init { - Initializer.sodium.crypto_hash_sha512_init(state) - } - - override fun update(data: UByteArray) { - Initializer.sodium.crypto_hash_sha512_update(state, data.toByteArray(), data.size.toLong()) - } - - override fun digest(): UByteArray { - val hashed = ByteArray(Sha512Properties.MAX_HASH_BYTES) - Initializer.sodium.crypto_hash_sha512_final(state, hashed) - return hashed.asUByteArray() - } - -} - -actual object Sha512StatelessDelegated : Sha512 { - - override fun digest(inputMessage: UByteArray): UByteArray { - val hashed = ByteArray(Sha512Properties.MAX_HASH_BYTES) - Initializer.sodium.crypto_hash_sha512(hashed, inputMessage.toByteArray(), inputMessage.size.toLong()) - return hashed.asUByteArray() - } -} diff --git a/multiplatform-crypto-delegated/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto-delegated/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt deleted file mode 100644 index 5c561f7..0000000 --- a/multiplatform-crypto-delegated/src/jvmTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ /dev/null @@ -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.util - -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) { -// val continuation = Continuation(EmptyCoroutineContext) { -// println("Done") -// } -// block.startCoroutine(continuation) -// -//} diff --git a/multiplatform-crypto-delegated/src/linuxArm32HfpMain/kotlin/com/ionspin/kotlin/crypto/Placeholder b/multiplatform-crypto-delegated/src/linuxArm32HfpMain/kotlin/com/ionspin/kotlin/crypto/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/linuxArm32HfpTest/kotlin/com/ionspin/kotlin/crypto/Placeholder b/multiplatform-crypto-delegated/src/linuxArm32HfpTest/kotlin/com/ionspin/kotlin/crypto/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/linuxX64Main/kotlin/com/ionspin/kotlin/crypto/Placeholder b/multiplatform-crypto-delegated/src/linuxX64Main/kotlin/com/ionspin/kotlin/crypto/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/linuxX64Main/kotlin/com/ionspin/kotlin/crypto/hash/sha/IntelliJCinteropResolverDebug.kt b/multiplatform-crypto-delegated/src/linuxX64Main/kotlin/com/ionspin/kotlin/crypto/hash/sha/IntelliJCinteropResolverDebug.kt deleted file mode 100644 index 3d7a4b1..0000000 --- a/multiplatform-crypto-delegated/src/linuxX64Main/kotlin/com/ionspin/kotlin/crypto/hash/sha/IntelliJCinteropResolverDebug.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 07-Jun-2020 - */ -import platform.posix.* -//import cin \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/linuxX64Test/kotlin/com/ionspin/kotlin/crypto/Placeholder b/multiplatform-crypto-delegated/src/linuxX64Test/kotlin/com/ionspin/kotlin/crypto/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/mingwX64Main/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto-delegated/src/mingwX64Main/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index 1a83ce8..0000000 --- a/multiplatform-crypto-delegated/src/mingwX64Main/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -1,44 +0,0 @@ -//We'll handle SRNG through libsodium -///* -// * 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 -// -//import kotlinx.cinterop.* -//import platform.windows.* -// -///** -// * Created by Ugljesa Jovanovic -// * ugljesa.jovanovic@ionspin.com -// * on 21-Sep-2019 -// */ -//actual object SRNG { -// private val advapi by lazy { LoadLibraryA("ADVAPI32.DLL")} -// -// private val advapiRandom by lazy { -// GetProcAddress(advapi, "SystemFunction036")?.reinterpret, ULong, Int>>>() ?: error("Failed getting advapi random") -// } -// -// @Suppress("EXPERIMENTAL_UNSIGNED_LITERALS") -// actual fun getRandomBytes(amount: Int): UByteArray { -// memScoped { -// val randArray = allocArray(amount) -// val pointer = randArray.getPointer(this) -// val status = advapiRandom(pointer.reinterpret(), amount.convert()) -// return UByteArray(amount) { pointer[it].toUByte() } -// } -// } -//} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/nativeInterop/cinterop/libsodium.def b/multiplatform-crypto-delegated/src/nativeInterop/cinterop/libsodium.def deleted file mode 100644 index 0b00392..0000000 --- a/multiplatform-crypto-delegated/src/nativeInterop/cinterop/libsodium.def +++ /dev/null @@ -1,6 +0,0 @@ -headers = sodium.h -headerFilter = sodium.h sodium/** -#staticLibraries = libsodium.a -#libraryPaths = sodiumWrapper/lib -#compilerOpts = -I./sodiumWrapper/include -linkerOpts = \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt deleted file mode 100644 index 944c199..0000000 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/Initializer.kt +++ /dev/null @@ -1,30 +0,0 @@ -@file:Suppress("VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL") - -package com.ionspin.kotlin.crypto - -import libsodium.sodium_init -import kotlin.native.concurrent.AtomicInt - -actual object Initializer { - - private var isPlatformInitialized : AtomicInt = AtomicInt(0) - - actual suspend fun initialize() { - if (isPlatformInitialized.compareAndSet(0, 1)) { - sodium_init() - } - - - } - - actual fun initializeWithCallback(done: () -> Unit) { - if (isPlatformInitialized.compareAndSet(0, 1)) { - sodium_init() - } - done() - } - - actual fun isInitialized(): Boolean { - return isPlatformInitialized.value != 0 - } -} diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index 78a112a..0000000 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -1,40 +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 - -import kotlinx.cinterop.* -import libsodium.randombytes_buf -import platform.posix.* -//import libsod - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -actual object SRNG { - @Suppress("EXPERIMENTAL_UNSIGNED_LITERALS") - actual fun getRandomBytes(amount: Int): UByteArray { - memScoped { - val array = allocArray(amount) - randombytes_buf(array, amount.convert()) - return UByteArray(amount) { - array[it] - } - } - } -} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt deleted file mode 100644 index eb7f836..0000000 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Delegated.kt +++ /dev/null @@ -1,164 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - -import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint -import com.ionspin.kotlin.crypto.InvalidTagException -import com.ionspin.kotlin.crypto.util.toPtr -import kotlinx.cinterop.* -import libsodium.* - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jun-2020 - */ -actual class XChaCha20Poly1305Delegated internal actual constructor() { - actual companion object { - actual fun encrypt( - key: UByteArray, - nonce: UByteArray, - message: UByteArray, - associatedData: UByteArray - ): UByteArray { - val ciphertextLength = message.size + crypto_aead_xchacha20poly1305_IETF_ABYTES.toInt() - val ciphertext = UByteArray(ciphertextLength) - val ciphertextPinned = ciphertext.pin() - crypto_aead_xchacha20poly1305_ietf_encrypt( - ciphertextPinned.toPtr(), - ulongArrayOf(ciphertextLength.convert()).toCValues(), - message.toCValues(), - message.size.convert(), - associatedData.toCValues(), - associatedData.size.convert(), - null, - nonce.toCValues(), - key.toCValues() - ) - ciphertextPinned.unpin() - return ciphertext - } - - actual fun decrypt( - key: UByteArray, - nonce: UByteArray, - ciphertext: UByteArray, - associatedData: UByteArray - ): UByteArray { - val messageLength = ciphertext.size - crypto_aead_xchacha20poly1305_IETF_ABYTES.toInt() - val message = UByteArray(messageLength) - val messagePinned = message.pin() - crypto_aead_xchacha20poly1305_ietf_decrypt( - messagePinned.toPtr(), - ulongArrayOf(messageLength.convert()).toCValues(), - null, - ciphertext.toCValues(), - ciphertext.size.convert(), - associatedData.toCValues(), - associatedData.size.convert(), - nonce.toCValues(), - key.toCValues() - ) - messagePinned.unpin() - return message - } - } - - var state = - sodium_malloc(crypto_secretstream_xchacha20poly1305_state.size.convert())!! - .reinterpret() - .pointed - val header = UByteArray(crypto_secretstream_xchacha20poly1305_HEADERBYTES.toInt()) { 0U } - - var isInitialized = false - var isEncryptor = false - - actual internal constructor( - key: UByteArray, - testState: UByteArray, - testHeader: UByteArray, - isDecryptor: Boolean - ) : this() { - val pointer = state.ptr.reinterpret() - for (i in 0 until crypto_secretstream_xchacha20poly1305_state.size.toInt()) { - pointer[i] = testState[i] - } - println("state after setting-----------") - state.ptr.readBytes(crypto_secretstream_xchacha20poly1305_state.size.toInt()).asUByteArray().hexColumsPrint() - println("state after setting-----------") - println("header after setting-----------") - testHeader.copyInto(header) - header.hexColumsPrint() - println("header after setting-----------") - isInitialized = true - isEncryptor = !isDecryptor - } - - - - actual fun initializeForEncryption(key: UByteArray) : UByteArray { - val pinnedHeader = header.pin() - crypto_secretstream_xchacha20poly1305_init_push(state.ptr, pinnedHeader.toPtr(), key.toCValues()) - println("state-----------") - state.ptr.readBytes(crypto_secretstream_xchacha20poly1305_state.size.toInt()).asUByteArray().hexColumsPrint() - println("state-----------") - println("--------header-----------") - header.hexColumsPrint() - println("--------header-----------") - pinnedHeader.unpin() - return header - } - - actual fun initializeForDecryption(key: UByteArray, header: UByteArray) { - crypto_secretstream_xchacha20poly1305_init_pull(state.ptr, header.toCValues(), key.toCValues()) - } - - - actual fun encrypt(data: UByteArray, associatedData: UByteArray): UByteArray { - val ciphertextWithTag = UByteArray(data.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt()) - val ciphertextWithTagPinned = ciphertextWithTag.pin() - crypto_secretstream_xchacha20poly1305_push( - state.ptr, - ciphertextWithTagPinned.toPtr(), - null, - data.toCValues(), - data.size.convert(), - associatedData.toCValues(), - associatedData.size.convert(), - 0U, - ) - println("Encrypt partial") - ciphertextWithTag.hexColumsPrint() - println("Encrypt partial end") - ciphertextWithTagPinned.unpin() - return ciphertextWithTag - } - - actual fun decrypt(data: UByteArray, associatedData: UByteArray): UByteArray { - val plaintext = UByteArray(data.size - crypto_secretstream_xchacha20poly1305_ABYTES.toInt()) - val plaintextPinned = plaintext.pin() - val validTag = crypto_secretstream_xchacha20poly1305_pull( - state.ptr, - plaintextPinned.toPtr(), - null, - null, - data.toCValues(), - data.size.convert(), - associatedData.toCValues(), - associatedData.size.convert() - ) - plaintextPinned.unpin() - println("tag: $validTag") - if (validTag != 0) { - println("Tag validation failed") - throw InvalidTagException() - } - return plaintext - } - - actual fun cleanup() { - sodium_free(state.ptr) - } - - - - -} 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 deleted file mode 100644 index d819606..0000000 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.blake2b -import com.ionspin.kotlin.crypto.util.toHexString -import com.ionspin.kotlin.crypto.util.toPtr -import kotlinx.cinterop.* -import libsodium.* -import platform.posix.free -import platform.posix.malloc -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jul-2019 - */ - - -actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: Int) : Blake2bMultipart { - override val MAX_HASH_BYTES: Int = 64 - - val requestedHashLength : Int - val state : crypto_generichash_state - init { - requestedHashLength = hashLength - val allocated = malloc(crypto_generichash_state.size.convert())!! - state = allocated.reinterpret().pointed - crypto_generichash_init(state.ptr, key?.run { this.toCValues() }, key?.size?.convert() ?: 0UL.convert(), hashLength.convert()) - } - - override fun update(data: UByteArray) { - crypto_generichash_update(state.ptr, data.toCValues(), data.size.convert()) - } - - override fun digest(): UByteArray { - val hashResult = UByteArray(requestedHashLength) - val hashResultPinned = hashResult.pin() - crypto_generichash_final(state.ptr, hashResultPinned.toPtr(), requestedHashLength.convert()) - free(state.ptr) - return hashResult - } - -} - -@Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS") -actual object Blake2bDelegatedStateless : Blake2b { - - override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray { - val hashResult = UByteArray(MAX_HASH_BYTES) - val hashResultPinned = hashResult.pin() - crypto_generichash( - hashResultPinned.toPtr(), - hashLength.convert(), - inputMessage.toCValues(), - inputMessage.size.convert(), - key.toCValues(), - key.size.convert() - ) - hashResultPinned.unpin() - return hashResult - - } - - -} 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 deleted file mode 100644 index 32c1e5d..0000000 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Delegated.kt +++ /dev/null @@ -1,55 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegatedStateless -import com.ionspin.kotlin.crypto.util.toPtr -import kotlinx.cinterop.* -import libsodium.* -import platform.posix.free -import platform.posix.malloc - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - -actual class Sha256Delegated : Sha256 { - - val state : crypto_hash_sha256_state - - init { - val allocated = sodium_malloc(crypto_hash_sha256_state.size.convert())!! - state = allocated.reinterpret().pointed - crypto_hash_sha256_init(state.ptr) - } - - override fun update(data: UByteArray) { - crypto_hash_sha256_update(state.ptr, data.toCValues(), data.size.convert()) - } - - - - override fun digest(): UByteArray { - val hashResult = UByteArray(Sha256Properties.MAX_HASH_BYTES) - val hashResultPinned = hashResult.pin() - crypto_hash_sha256_final(state.ptr, hashResultPinned.toPtr()) - sodium_free(state.ptr) - return hashResult - } - - - - -} -actual object Sha256StatelessDelegated : StatelessSha256 { - - override fun digest(inputMessage: UByteArray): UByteArray { - val hashResult = UByteArray(MAX_HASH_BYTES) - val hashResultPinned = hashResult.pin() - crypto_hash_sha256(hashResultPinned.toPtr(), inputMessage.toCValues(), inputMessage.size.convert()) - hashResultPinned.unpin() - return hashResult - } - -} 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 deleted file mode 100644 index a700b04..0000000 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Delegated.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.ionspin.kotlin.crypto.hash.sha - -import com.ionspin.kotlin.crypto.util.toPtr -import kotlinx.cinterop.* -import libsodium.* -import platform.posix.free -import platform.posix.malloc - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - -actual class Sha512Delegated : Sha512Multipart { - val state : crypto_hash_sha512_state - - init { - val allocated = malloc(crypto_hash_sha512_state.size.convert())!! - state = allocated.reinterpret().pointed - crypto_hash_sha512_init(state.ptr) - } - - override fun update(data: UByteArray) { - crypto_hash_sha512_update(state.ptr, data.toCValues(), data.size.convert()) - } - - - - override fun digest(): UByteArray { - val hashResult = UByteArray(Sha512Properties.MAX_HASH_BYTES) - val hashResultPinned = hashResult.pin() - crypto_hash_sha512_final(state.ptr, hashResultPinned.toPtr()) - free(state.ptr) - return hashResult - } - -} - -actual object Sha512StatelessDelegated : Sha512 { - - override fun digest(inputMessage: UByteArray): UByteArray { - val hashResult = UByteArray(Sha512StatelessDelegated.MAX_HASH_BYTES) - val hashResultPinned = hashResult.pin() - crypto_hash_sha512(hashResultPinned.toPtr(), inputMessage.toCValues(), inputMessage.size.convert()) - hashResultPinned.unpin() - return hashResult - } -} diff --git a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/util/ConversionUtil.kt b/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/util/ConversionUtil.kt deleted file mode 100644 index 7a0d892..0000000 --- a/multiplatform-crypto-delegated/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/util/ConversionUtil.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.ionspin.kotlin.crypto.util - -import kotlinx.cinterop.CPointer -import kotlinx.cinterop.Pinned -import kotlinx.cinterop.UByteVar -import kotlinx.cinterop.addressOf - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 27-Aug-2020 - */ -fun Pinned.toPtr() : CPointer = addressOf(0) diff --git a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/HelperTest.kt b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/HelperTest.kt deleted file mode 100644 index 4bc8bcd..0000000 --- a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/HelperTest.kt +++ /dev/null @@ -1,77 +0,0 @@ -package com.ionspin.kotlin.crypto - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.toHexString -import com.ionspin.kotlin.crypto.util.toPtr -import kotlinx.cinterop.* -import libsodium.* -import platform.posix.free -import platform.posix.malloc -import kotlin.test.Ignore -import kotlin.test.Test - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 13-Jul-2020 - */ -class HelperTest { - @Ignore //Just used for debugging pure implementation - @Test - fun longSha256() { - for (target in 0L until 10L) { - generateForRounds256(target) - } - for (target in 0L until 16_777_216L step 1_000_000L) { - generateForRounds256(target) - } - generateForRounds256(16_777_216L) - } - - fun generateForRounds256(target: Long) { - val updateValue = - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno".encodeToUByteArray().toCValues() - val state = malloc(crypto_hash_sha256_state.size.convert())!! - .reinterpret() - - crypto_hash_sha256_init(state) - for (i in 0 until target) { - crypto_hash_sha256_update(state, updateValue, updateValue.size.convert()) - } - val result = UByteArray(32) - val resultPinned = result.pin() - crypto_hash_sha256_final(state, resultPinned.toPtr()) - println("$target to \"${result.toHexString()}\",") - free(state) - } - @Ignore //Just used for debugging pure implementation - @Test - fun longSha512() { - - for (target in 0L until 10L) { - generateForRounds512(target) - } - for (target in 0L until 16_777_216L step 1_000_000L) { - generateForRounds512(target) - } - generateForRounds512(16_777_216L) - } - - fun generateForRounds512(target: Long) { - println("Wut") - val updateValue = - "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno".encodeToUByteArray().toCValues() - val state = malloc(crypto_hash_sha512_state.size.convert())!! - .reinterpret() - - crypto_hash_sha512_init(state) - for (i in 0 until target) { - crypto_hash_sha512_update(state, updateValue, updateValue.size.convert()) - } - val result = UByteArray(32) - val resultPinned = result.pin() - crypto_hash_sha512_final(state, resultPinned.toPtr()) - println("$target to \"${result.toHexString()}\",") - free(state) - } -} diff --git a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt b/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt deleted file mode 100644 index 8101dca..0000000 --- a/multiplatform-crypto-delegated/src/nativeTest/kotlin/com/ionspin/kotlin/crypto/util/testBlocking.kt +++ /dev/null @@ -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() } diff --git a/multiplatform-crypto/build.gradle.kts b/multiplatform-crypto/build.gradle.kts deleted file mode 100644 index f7dd2a6..0000000 --- a/multiplatform-crypto/build.gradle.kts +++ /dev/null @@ -1,522 +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. - * - */ - -@file:Suppress("UnstableApiUsage") -import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest -import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest -import org.jetbrains.dokka.Platform - -plugins { - kotlin(PluginsDeps.multiplatform) - id(PluginsDeps.mavenPublish) - id(PluginsDeps.signing) - id(PluginsDeps.node) version Versions.nodePlugin - id(PluginsDeps.dokka) -} - -val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/" - -val sonatypePassword: String? by project - -val sonatypeUsername: String? by project - -val sonatypePasswordEnv: String? = System.getenv()["SONATYPE_PASSWORD"] -val sonatypeUsernameEnv: String? = System.getenv()["SONATYPE_USERNAME"] - -repositories { - mavenCentral() - jcenter() - -} -group = ReleaseInfo.group -version = ReleaseInfo.version - -val ideaActive = System.getProperty("idea.active") == "true" - -kotlin { - val hostOsName = getHostOsName() - val bla =1 - runningOnLinuxx86_64 { - jvm() - js { - - browser { - - testTask { -// isRunningInTravis { - enabled = false //Until I sort out testing on travis, and figure out how to increase karma timeout -// } - useKarma { - useChrome() - - } - } - } - nodejs { - testTask { - useMocha() { - timeout = "10s" - } - } - } - - } - linuxX64("linux") { - binaries { - staticLib { - optimized = true - } - } - } - - linuxArm64() { - binaries { - staticLib { - } - } - } - - linuxArm32Hfp() { - binaries { - staticLib { - } - } - } - - - - } - - runningOnMacos { - iosX64() { - binaries { - framework { - optimized = true - } - } - } - iosArm64() { - binaries { - framework { - optimized = true - } - } - } - - iosArm32() { - binaries { - framework { - optimized = true - } - } - } - macosX64() { - binaries { - framework { - optimized = true - } - } - } - tvosX64() { - binaries { - framework { - optimized = true - } - } - } - - tvosArm64() { - binaries { - framework { - optimized = true - } - } - } - - watchosArm64() { - binaries { - framework { - optimized = true - } - } - } - - watchosArm32() { - binaries { - framework { - optimized = true - } - } - } - - watchosX86() { - binaries { - framework { - optimized = true - } - } - } - } - runningOnWindows { - - mingwX64() { - binaries { - staticLib { - optimized = true - } - } - } - } -// No coroutines support for mingwX86 -// mingwX86() { -// binaries { -// staticLib { -// -// } -// } -// } - - - println(targets.names) - - sourceSets { - val commonMain by getting { - dependencies { - implementation(kotlin(Deps.Common.stdLib)) - implementation(kotlin(Deps.Common.test)) - implementation(Deps.Common.kotlinBigNum) - implementation(project(Deps.Common.apiProject)) - } - } - val commonTest by getting { - dependencies { - implementation(kotlin(Deps.Common.test)) - implementation(kotlin(Deps.Common.testAnnotation)) - } - } - - - val nativeMain by creating { - dependsOn(commonMain) - dependencies { - } - isRunningInIdea { - kotlin.setSrcDirs(emptySet()) - } - } - - - val nativeTest by creating { - dependsOn(commonTest) - dependencies { - } - } - - targets.withType { - compilations.getByName("main") { - println("Setting native sourceset dependancy for $name") - if ((this@withType.name.contains("ios") || - this@withType.name.contains("mingw")).not() - ) { - println("Setting native sourceset dependancy for $this@withType.name") - defaultSourceSet.dependsOn(nativeMain) - } - } - compilations.getByName("test") { - println("Setting native sourceset dependancy for $name") - if ((this@withType.name.contains("ios") || - this@withType.name.contains("mingw")).not() - ) { - println("Setting native sourceset dependancy for $this@withType.name") - defaultSourceSet.dependsOn(nativeTest) - } - } - } - - - - runningOnLinuxx86_64 { - val jvmMain by getting { - dependencies { - implementation(kotlin(Deps.Jvm.stdLib)) - implementation(kotlin(Deps.Jvm.test)) - implementation(kotlin(Deps.Jvm.testJUnit)) - } - } - val jvmTest by getting { - dependencies { - implementation(kotlin(Deps.Jvm.test)) - implementation(kotlin(Deps.Jvm.testJUnit)) - implementation(kotlin(Deps.Jvm.reflection)) - } - } - val jsMain by getting { - dependencies { - implementation(kotlin(Deps.Js.stdLib)) - } - } - val jsTest by getting { - dependencies { - implementation(kotlin(Deps.Js.test)) - } - } - val linuxMain by getting { - dependsOn(nativeMain) - //Force idea to consider native sourceset - if (ideaActive) { - kotlin.srcDir("src/nativeMain/kotlin") - } - } - val linuxTest by getting { - dependsOn(nativeTest) -// Force idea to consider native sourceset - if (ideaActive) { - kotlin.srcDir("src/nativeTest/kotlin") - } - } - - val linuxArm64Main by getting { - dependsOn(nativeMain) - } - - val linuxArm64Test by getting { - dependsOn(nativeTest) - } - - val linuxArm32HfpMain by getting { - dependsOn(nativeMain) - } - - val linuxArm32HfpTest by getting { - dependsOn(nativeTest) - } - - } - - - runningOnMacos{ - - val iosX64Main by getting { - dependsOn(nativeMain) - } - val iosX64Test by getting { - dependsOn(nativeTest) - } - - val iosArm64Main by getting { - dependsOn(nativeMain) - } - val iosArm64Test by getting { - dependsOn(nativeTest) - } - - val iosArm32Main by getting { - dependsOn(nativeMain) - } - val iosArm32Test by getting { - dependsOn(nativeTest) - } - - val macosX64Main by getting { - dependsOn(commonMain) - if (ideaActive) { - kotlin.srcDir("src/nativeMain/kotlin") - } - } - val macosX64Test by getting { - dependsOn(commonTest) - if (ideaActive) { - kotlin.srcDir("src/nativeTest/kotlin") - } - } - } - -// Coroutines don't support mingwx86 yet -// val mingwX86Main by getting { -// dependsOn(commonMain) -// dependencies { -// } -// } - -// val mingwX86Test by getting { -// dependsOn(commonTest) -// } -// - runningOnWindows { - val mingwX64Main by getting { - dependsOn(commonMain) - dependencies { - } - } - - val mingwX64Test by getting { - dependsOn(commonTest) - } - } - - - all { - languageSettings.enableLanguageFeature("InlineClasses") - languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") - languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi") - } - } - - -} - - - -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 { - - - create("javadocJar") { - dependsOn(dokkaJavadoc) - archiveClassifier.set("javadoc") - from(dokkaJavadoc.get().outputDirectory) - } - - dokkaJavadoc { - println("Dokka !") - dokkaSourceSets { - named("commonMain") { - displayName.set("common") - platform.set(Platform.common) - } - } - - - - } - if (getHostOsName() == "linux" && getHostArchitecture() == "x86-64") { - - val jvmTest by getting(Test::class) { - testLogging { - events("PASSED", "FAILED", "SKIPPED") - } - } - - val linuxTest by getting(KotlinNativeTest::class) { - - testLogging { - events("PASSED", "FAILED", "SKIPPED") -// showStandardStreams = true - } - } - - val jsNodeTest by getting(KotlinJsTest::class) { - testLogging { - events("PASSED", "FAILED", "SKIPPED") - showStandardStreams = true - } - } - -// val legacyjsNodeTest by getting(KotlinJsTest::class) { -// -// testLogging { -// events("PASSED", "FAILED", "SKIPPED") -// showStandardStreams = true -// } -// } - -// val jsIrBrowserTest by getting(KotlinJsTest::class) { -// testLogging { -// events("PASSED", "FAILED", "SKIPPED") -// showStandardStreams = true -// } -// } - } - - if (getHostOsName() == "windows") { - val mingwX64Test by getting(KotlinNativeTest::class) { - - testLogging { - events("PASSED", "FAILED", "SKIPPED") - showStandardStreams = true - } - } - } - -} - - - -signing { - isRequired = false - sign(publishing.publications) -} - -publishing { - publications.withType(MavenPublication::class) { - artifact(tasks["javadocJar"]) - pom { - name.set("Kotlin Multiplatform Crypto") - description.set("Kotlin Multiplatform Crypto library") - url.set("https://github.com/ionspin/kotlin-multiplatform-crypto") - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - developers { - developer { - id.set("ionspin") - name.set("Ugljesa Jovanovic") - email.set("opensource@ionspin.com") - } - } - scm { - url.set("https://github.com/ionspin/kotlin-multiplatform-crypto") - connection.set("scm:git:git://git@github.com:ionspin/kotlin-multiplatform-crypto.git") - developerConnection.set("scm:git:ssh://git@github.com:ionspin/kotlin-multiplatform-crypto.git") - - } - - } - } - repositories { - maven { - - url = uri(sonatypeStaging) - credentials { - username = sonatypeUsername ?: sonatypeUsernameEnv ?: "" - password = sonatypePassword ?: sonatypePasswordEnv ?: "" - } - } - - maven { - name = "snapshot" - url = uri(sonatypeSnapshots) - credentials { - username = sonatypeUsername ?: sonatypeUsernameEnv ?: "" - password = sonatypePassword ?: sonatypePasswordEnv ?: "" - } - } - } -} - - diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Config.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Config.kt deleted file mode 100644 index eb058b8..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Config.kt +++ /dev/null @@ -1,26 +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 - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ -object Config { - const val DEBUG = false -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt deleted file mode 100644 index d13f8ca..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/Crypto.kt +++ /dev/null @@ -1,155 +0,0 @@ -package com.ionspin.kotlin.crypto - -import com.ionspin.kotlin.crypto.authenticated.* -import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bMultipart -import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bPure -import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure -import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure -import com.ionspin.kotlin.crypto.keyderivation.ArgonResult -import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Pure - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 24-May-2020 - */ -object CryptoInitializerPure : CryptoInitializer { - override suspend fun initialize() { - //Nothing to do atm. - } - - fun initializeWithCallback(done: () -> Unit) { - done() - } - - override fun isInitialized(): Boolean { - return true - } -} - -object CryptoPrimitives : PrimitivesApi { - private fun checkInitialization() { - CryptoInitializerPure.isInitialized() - } - - override fun hashBlake2bMultipart(key: UByteArray?, hashLength: Int): Blake2bMultipart { - checkInitialization() - return Blake2bPure(key, hashLength) - } - - override fun hashBlake2b(message: UByteArray, key: UByteArray, hashLength: Int): UByteArray { - checkInitialization() - return Blake2bPure.digest(message, key, hashLength) - } - - override fun hashSha256Multipart(): com.ionspin.kotlin.crypto.hash.sha.Sha256 { - checkInitialization() - return Sha256Pure() - } - - override fun hashSha256(message: UByteArray): UByteArray { - checkInitialization() - return Sha256Pure.digest(inputMessage = message) - } - - override fun hashSha512Multipart(): com.ionspin.kotlin.crypto.hash.sha.Sha512Multipart { - checkInitialization() - return Sha512Pure() - } - - override fun hashSha512(message: UByteArray): UByteArray { - checkInitialization() - return Sha512Pure.digest(inputMessage = message) - } - - override fun deriveKey( - password: String, - salt: String?, - key: String, - associatedData: String, - parallelism: Int, - tagLength: Int, - memory: Int, - numberOfIterations: Int - ): ArgonResult { - return Argon2Pure.derive( - password, - salt, - key, - associatedData, - parallelism, - tagLength, - memory, - numberOfIterations - ) - } -} - -fun SymmetricKey.Companion.randomKey() : SymmetricKey { - return SymmetricKey(SRNG.getRandomBytes(32)) -} - -object Crypto { - - object Hash : HashApi { - override fun hash(data: UByteArray, key : UByteArray) : HashedData { - return HashedData(Blake2bPure.digest(data, key)) - } - - override fun multipartHash(key: UByteArray?) : com.ionspin.kotlin.crypto.hash.MultipartHash { - return Blake2bPure(key) - } - } - - object Encryption : EncryptionApi { - override fun encrypt(key: SymmetricKey, data : Encryptable<*>, associatedData : UByteArray) : EncryptedData { - if (key.value.size != 32) { - throw RuntimeException("Invalid key size! Required 32, supplied ${key.value.size}") - } - val nonce = SRNG.getRandomBytes(24) - return EncryptedData(XChaCha20Poly1305Pure.encrypt(key.value, nonce, data.toEncryptableForm(), associatedData), nonce) - - } - - override fun > decrypt(key: SymmetricKey, encryptedData : EncryptedData, associatedData: UByteArray, byteArrayDeserializer : (UByteArray) -> T) : T { - return byteArrayDeserializer(XChaCha20Poly1305Pure.decrypt(key.value, encryptedData.nonce, encryptedData.ciphertext, associatedData)) - - } - - override fun createMultipartEncryptor(key: SymmetricKey) : MultipartAuthenticatedEncryption { - return MultipartAuthenticatedEncryptor(key) - } - - override fun createMultipartDecryptor(key: SymmetricKey, header: MultipartEncryptionHeader) : MultipartAuthenticatedDecryption { - val decryptor = XChaCha20Poly1305Pure(key.value, header.nonce) - return MultipartAuthenticatedDecryptor(decryptor) - } - } -} - -class MultipartAuthenticatedEncryptor internal constructor(val key : SymmetricKey) : MultipartAuthenticatedEncryption { - val header = MultipartEncryptionHeader(SRNG.getRandomBytes(24)) - val primitive = XChaCha20Poly1305Pure(key.value, header.nonce) - override fun encryptPartialData(data: UByteArray, associatedData: UByteArray): EncryptedDataPart { - return EncryptedDataPart(primitive.streamEncrypt(data, associatedData, 0U)) - } - - override fun startEncryption(): MultipartEncryptionHeader { - return header.copy() - } - - override fun cleanup() { - primitive.cleanup() - } -} - -class MultipartAuthenticatedDecryptor internal constructor(val decryptor: XChaCha20Poly1305Pure) : MultipartAuthenticatedDecryption { - override fun decryptPartialData(data: EncryptedDataPart, associatedData: UByteArray): DecryptedDataPart { - return DecryptedDataPart(decryptor.streamDecrypt(data.data, associatedData, 0U)) - } - - override fun cleanup() { - decryptor.cleanup() - } - -} diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/NativeInlineClassEmitter.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/NativeInlineClassEmitter.kt deleted file mode 100644 index 8fec2b1..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/NativeInlineClassEmitter.kt +++ /dev/null @@ -1,12 +0,0 @@ -package _multiplatform_crypto - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 24-May-2020 - */ -//Workaround for https://youtrack.jetbrains.com/issue/KT-36878 -val byteArray = byteArrayOf(0) -val byte = 0.toByte() -val longArray = longArrayOf(0) -val long = 0L \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index 80e6f05..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -1,26 +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 - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -expect object SRNG { - fun getRandomBytes(amount : Int) : UByteArray -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/ChaCha20Poly1305Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/ChaCha20Poly1305Pure.kt deleted file mode 100644 index 1c35fd9..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/ChaCha20Poly1305Pure.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - -import com.ionspin.kotlin.crypto.mac.Poly1305 -import com.ionspin.kotlin.crypto.symmetric.ChaCha20Pure -import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToUIntWithPosition -import com.ionspin.kotlin.crypto.util.toLittleEndianUByteArray - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jun-2020 - */ -internal class ChaCha20Poly1305Pure { - companion object { - - fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, associatedData: UByteArray) : UByteArray { - val state = UIntArray(16) { - when (it) { - 0 -> ChaCha20Pure.sigma0_32 - 1 -> ChaCha20Pure.sigma1_32 - 2 -> ChaCha20Pure.sigma2_32 - 3 -> ChaCha20Pure.sigma3_32 - 4 -> key.fromLittleEndianArrayToUIntWithPosition(0) - 5 -> key.fromLittleEndianArrayToUIntWithPosition(4) - 6 -> key.fromLittleEndianArrayToUIntWithPosition(8) - 7 -> key.fromLittleEndianArrayToUIntWithPosition(12) - 8 -> key.fromLittleEndianArrayToUIntWithPosition(16) - 9 -> key.fromLittleEndianArrayToUIntWithPosition(20) - 10 -> key.fromLittleEndianArrayToUIntWithPosition(24) - 11 -> key.fromLittleEndianArrayToUIntWithPosition(28) - 12 -> 0U - 13 -> nonce.fromLittleEndianArrayToUIntWithPosition(0) - 14 -> nonce.fromLittleEndianArrayToUIntWithPosition(4) - 15 -> nonce.fromLittleEndianArrayToUIntWithPosition(8) - else -> 0U - } - } - val oneTimeKey = ChaCha20Pure.hash(state).sliceArray(0 until 32) - val cipherText = ChaCha20Pure.xorWithKeystream(key, nonce, message, 1U) - val associatedDataPad = UByteArray(16 - associatedData.size % 16) { 0U } - val cipherTextPad = UByteArray(16 - cipherText.size % 16) { 0U } - val macData = associatedData + associatedDataPad + - cipherText + cipherTextPad + - associatedData.size.toULong().toLittleEndianUByteArray() + - cipherText.size.toULong().toLittleEndianUByteArray() - val tag = Poly1305.poly1305Authenticate(oneTimeKey, macData) - return cipherText + tag - } - } -} diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Pure.kt deleted file mode 100644 index 34b8c01..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Pure.kt +++ /dev/null @@ -1,203 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - -import com.ionspin.kotlin.crypto.AuthenticatedEncryption -import com.ionspin.kotlin.crypto.InvalidTagException -import com.ionspin.kotlin.crypto.mac.Poly1305 -import com.ionspin.kotlin.crypto.symmetric.ChaCha20Pure -import com.ionspin.kotlin.crypto.symmetric.XChaCha20Pure -import com.ionspin.kotlin.crypto.util.* - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jun-2020 - */ -class XChaCha20Poly1305Pure(val key: UByteArray, val nonce: UByteArray) { - companion object : AuthenticatedEncryption { - - override fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray, associatedData: UByteArray) : UByteArray { - val subKey = XChaCha20Pure.hChacha(key, nonce) - val authKey = - ChaCha20Pure.xorWithKeystream( - subKey.toLittleEndianUByteArray(), - ubyteArrayOf(0U, 0U, 0U, 0U) + nonce.sliceArray(16 until 24), - UByteArray(64) { 0U }, - 0U // If this is moved as a default parameter in encrypt, and not here (in 1.4-M2) - // js compiler dies with: e: java.lang.NullPointerException - // at org.jetbrains.kotlin.ir.backend.js.lower.ConstTransformer$visitConst$1$3.invoke(ConstLowering.kt:28) - // at org.jetbrains.kotlin.ir.backend.js.lower.ConstTransformer.lowerConst(ConstLowering.kt:38) - ) - val cipherText = XChaCha20Pure.xorWithKeystream(key, nonce, message, 1U) - val associatedDataPad = UByteArray(16 - associatedData.size % 16) { 0U } - val cipherTextPad = UByteArray(16 - cipherText.size % 16) { 0U } - val macData = associatedData + associatedDataPad + - cipherText + cipherTextPad + - associatedData.size.toULong().toLittleEndianUByteArray() + - cipherText.size.toULong().toLittleEndianUByteArray() - val tag = Poly1305.poly1305Authenticate(authKey, macData) - return cipherText + tag - } - - override fun decrypt(key: UByteArray, nonce: UByteArray, cipherText: UByteArray, associatedData: UByteArray) : UByteArray { - val subKey = XChaCha20Pure.hChacha(key, nonce) - val authKey = - ChaCha20Pure.xorWithKeystream( - subKey.toLittleEndianUByteArray(), - ubyteArrayOf(0U, 0U, 0U, 0U) + nonce.sliceArray(16 until 24), - UByteArray(64) { 0U }, - 0U - ) - //2. Get the tag - val tag = cipherText.sliceArray(cipherText.size - 16 until cipherText.size) - //3. Verify tag is valid - val cipherTextWithoutTag = cipherText.sliceArray(0 until cipherText.size - 16) - val associatedDataPad = UByteArray(16 - associatedData.size % 16) { 0U } - val cipherTextPad = UByteArray(16 - cipherTextWithoutTag.size % 16) { 0U } - val macData = associatedData + associatedDataPad + - cipherTextWithoutTag + cipherTextPad + - associatedData.size.toULong().toLittleEndianUByteArray() + - cipherTextWithoutTag.size.toULong().toLittleEndianUByteArray() - val calculatedTag = Poly1305.poly1305Authenticate(authKey, macData) - if (!calculatedTag.contentEquals(tag)) { - throw InvalidTagException() - } - //4. Decrypt data - return XChaCha20Pure.xorWithKeystream(key, nonce, cipherTextWithoutTag, 1U) - } - - } - - - private val polyBuffer = UByteArray(16) - private var polyBufferByteCounter = 0 - - private var processedBytes = 0 - - internal val calcKey : UByteArray = UByteArray(32) - internal val calcNonce : UByteArray = UByteArray(12) - - init { - val calc = XChaCha20Pure.hChacha(key, nonce).toLittleEndianUByteArray() - calc.sliceArray(0 until 32).copyInto(calcKey) - nonce.sliceArray(16 until 24).copyInto(calcNonce, 4) - calcNonce[0] = 1U - calcNonce[1] = 0U - calcNonce[2] = 0U - calcNonce[3] = 0U - } - - fun streamEncrypt(data: UByteArray, associatedData: UByteArray, tag : UByte) : UByteArray { - //get encryption state - val block = UByteArray(64) { 0U } - ChaCha20Pure.xorWithKeystream(calcKey, calcNonce, block, 0U).copyInto(block) // This is equivalent to the first 64 bytes of keystream - val poly1305 = Poly1305(block) - block.overwriteWithZeroes() - if (associatedData.isNotEmpty()) { - val associatedDataPadded = associatedData + UByteArray(16 - associatedData.size % 16) { 0U } - processPolyBytes(poly1305, associatedDataPadded) - } - block[0] = tag - ChaCha20Pure.xorWithKeystream(calcKey, calcNonce, block, 1U).copyInto(block) // This just xors block[0] with keystream - processPolyBytes(poly1305, block) // but updates the mac with the full block! - // In libsodium c code, it now sets the first byte to be a tag, we'll just save it for now - val encryptedTag = block[0] - //And then encrypt the rest of the message - val ciphertext = ChaCha20Pure.xorWithKeystream(calcKey, calcNonce, data, 2U) // With appropriate counter - // Next we update the poly1305 with ciphertext and padding, BUT the padding in libsodium is not correctly calculated, so it doesn't - // pad correctly. https://github.com/jedisct1/libsodium/issues/976 - // We want to use libsodium in delegated flavour, so we will use the same incorrect padding here. - // From security standpoint there are no obvious drawbacks, as padding was initially added to decrease implementation complexity. - processPolyBytes(poly1305, ciphertext + UByteArray(((16U + data.size.toUInt() - block.size.toUInt()) % 16U).toInt()) { 0U } ) //TODO this is inefficient as it creates a new array and copies data - // Last 16byte block containing actual additional data nad ciphertext sizes - val finalMac = associatedData.size.toULong().toLittleEndianUByteArray() + (ciphertext.size + 64).toULong().toLittleEndianUByteArray() - processPolyBytes(poly1305, finalMac) - val mac = poly1305.finalizeMac(polyBuffer.sliceArray(0 until polyBufferByteCounter)) - calcNonce.xorWithPositionsAndInsertIntoArray(0, 12, mac, 0, calcNonce, 0) - return ubyteArrayOf(encryptedTag) + ciphertext + mac - } - - fun streamDecrypt(data: UByteArray, associatedData: UByteArray, tag: UByte) : UByteArray { - val block = UByteArray(64) { 0U } - ChaCha20Pure.xorWithKeystream(calcKey, calcNonce, block, 0U).copyInto(block) // This is equivalent to the first 64 bytes of keystream - val poly1305 = Poly1305(block) - block.overwriteWithZeroes() - if (associatedData.isNotEmpty()) { - val associatedDataPadded = associatedData + UByteArray(16 - associatedData.size % 16) { 0U } - processPolyBytes(poly1305, associatedDataPadded) - } - block[0] = data[0] - ChaCha20Pure.xorWithKeystream(calcKey, calcNonce, block, 1U).copyInto(block)// get the keystream xored with zeroes, but also decrypteg tag marker - val tag = block[0] //get the decrypted tag - block[0] = data[0] // this brings it back to state that is delivered to poly in encryption function - processPolyBytes(poly1305, block) - // Next we update the poly1305 with ciphertext and padding, BUT the padding in libsodium is not correctly calculated, so it doesn't - // pad correctly. https://github.com/jedisct1/libsodium/issues/976 - // We want to use libsodium in delegated flavour, so we will use the same incorrect padding here. - // From security standpoint there are no obvious drawbacks, as padding was initially added to decrease implementation complexity. - val ciphertext = data.sliceArray(1 until data.size - 16) - processPolyBytes(poly1305, ciphertext + UByteArray(((16U + ciphertext.size.toUInt() - block.size.toUInt()) % 16U).toInt()) { 0U } ) - val plaintext = ChaCha20Pure.xorWithKeystream(calcKey, calcNonce, ciphertext, 2U) - val finalMac = associatedData.size.toULong().toLittleEndianUByteArray() + (ciphertext.size + 64).toULong().toLittleEndianUByteArray() - processPolyBytes(poly1305, finalMac) - val mac = poly1305.finalizeMac(polyBuffer.sliceArray(0 until polyBufferByteCounter)) - val expectedMac = data.sliceArray(data.size - 16 until data.size) - - if (expectedMac.contentEquals(mac).not()){ - throw InvalidTagException() - } - calcNonce.xorWithPositionsAndInsertIntoArray(0, 12, mac, 0, calcNonce, 0) - return plaintext - } - - fun cleanup() { - key.overwriteWithZeroes() - nonce.overwriteWithZeroes() - calcKey.overwriteWithZeroes() - calcNonce.overwriteWithZeroes() - } - - - - private fun processPolyBytes(updateableMacPrimitive: Poly1305, data: UByteArray) { - if (polyBufferByteCounter == 0) { - val polyBlocks = data.size / 16 - val polyRemainder = data.size % 16 - for (i in 0 until polyBlocks) { - updateableMacPrimitive.updateMac(data.sliceArray(i * 16 until i * 16 + 16)) - } - if (polyRemainder != 0) { - for (i in 0 until polyRemainder) { - polyBuffer[i] = data[data.size - polyRemainder + i] - } - polyBufferByteCounter = polyRemainder - } - } else { - if (polyBufferByteCounter + data.size < 16) { - for (i in 0 until data.size) { - polyBuffer[polyBufferByteCounter + i] = data[i] - } - polyBufferByteCounter += data.size - } else { - val borrowed = 16 - polyBufferByteCounter - for (i in polyBufferByteCounter until 16) { - polyBuffer[i] = data[i - polyBufferByteCounter] - } - updateableMacPrimitive.updateMac(polyBuffer) - polyBufferByteCounter = 0 - val polyBlocks = (data.size - borrowed) / 16 - val polyRemainder = (data.size - borrowed) % 16 - for (i in 0 until polyBlocks) { - updateableMacPrimitive.updateMac(data.sliceArray(borrowed + i * 16 until borrowed + i * 16 + 16)) - } - if (polyRemainder != 0) { - for (i in 0 until polyRemainder) { - polyBuffer[i] = data[borrowed + i] - } - polyBufferByteCounter = polyRemainder - } - } - } - } - - -} 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 deleted file mode 100644 index 5e72b76..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bPure.kt +++ /dev/null @@ -1,351 +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.hash.blake2b - -import com.ionspin.kotlin.bignum.integer.BigInteger -import com.ionspin.kotlin.bignum.integer.toBigInteger -import com.ionspin.kotlin.crypto.* -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.rotateRight - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jul-2019 - */ - - -class Blake2bPure(val key: UByteArray? = null, val hashLength: Int = 64) : Blake2bMultipart { - - companion object : Blake2b { - //Hack start - //If this line is not included konanc 1.4-M1 fails to link because it cant find ByteArray which is - //a backing class for UByteArray - val byteArray: ByteArray = byteArrayOf(0, 1) - //Hack end - const val BITS_IN_WORD = 64 - const val ROUNDS_IN_COMPRESS = 12 - const val BLOCK_BYTES = 128 - override val MAX_HASH_BYTES = 64 - const val MIN_HASH_BYTES = 1 - const val MAX_KEY_BYTES = 64 - const val MIN_KEY_BYTES = 0 - val MAX_INPUT_BYTES = 2.toBigInteger() shl 128 - - private val sigma = arrayOf( - arrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), - arrayOf(14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3), - arrayOf(11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4), - arrayOf(7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8), - arrayOf(9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13), - arrayOf(2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9), - arrayOf(12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11), - arrayOf(13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10), - arrayOf(6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5), - arrayOf(10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0) - ) - - - private val iv = arrayOf( - 0X6A09E667F3BCC908UL, - 0XBB67AE8584CAA73BUL, - 0X3C6EF372FE94F82BUL, - 0XA54FF53A5F1D36F1UL, - 0X510E527FADE682D1UL, - 0X9B05688C2B3E6C1FUL, - 0X1F83D9ABFB41BD6BUL, - 0X5BE0CD19137E2179UL - ) - - const val R1 = 32 - const val R2 = 24 - const val R3 = 16 - const val R4 = 63 - - internal fun mixRound(input: Array, message: Array, round: Int): Array { - var v = input - val selectedSigma = sigma[round % 10] - v = mix(v, 0, 4, 8, 12, message[selectedSigma[0]], message[selectedSigma[1]]) - v = mix(v, 1, 5, 9, 13, message[selectedSigma[2]], message[selectedSigma[3]]) - v = mix(v, 2, 6, 10, 14, message[selectedSigma[4]], message[selectedSigma[5]]) - v = mix(v, 3, 7, 11, 15, message[selectedSigma[6]], message[selectedSigma[7]]) - v = mix(v, 0, 5, 10, 15, message[selectedSigma[8]], message[selectedSigma[9]]) - v = mix(v, 1, 6, 11, 12, message[selectedSigma[10]], message[selectedSigma[11]]) - v = mix(v, 2, 7, 8, 13, message[selectedSigma[12]], message[selectedSigma[13]]) - v = mix(v, 3, 4, 9, 14, message[selectedSigma[14]], message[selectedSigma[15]]) - return v - - } - - private fun mix(v: Array, a: Int, b: Int, c: Int, d: Int, x: ULong, y: ULong): Array { - v[a] = (v[a] + v[b] + x) - v[d] = (v[d] xor v[a]) rotateRight R1 - v[c] = (v[c] + v[d]) - v[b] = (v[b] xor v[c]) rotateRight R2 - v[a] = (v[a] + v[b] + y) - v[d] = (v[d] xor v[a]) rotateRight R3 - v[c] = (v[c] + v[d]) - v[b] = (v[b] xor v[c]) rotateRight R4 - return v - } - - fun compress( - h: Array, - input: UByteArray, - offsetCounter: BigInteger, - finalBlock: Boolean - ): Array { - var v = Array(16) { - when (it) { - in 0..7 -> h[it] - else -> iv[it - 8] - } - } - - val m = input.foldIndexed(Array(16) { 0UL }) { index, acc, byte -> - val slot = index / 8 - val position = index % 8 - acc[slot] = acc[slot] + (byte.toULong() shl ((position) * 8)) - acc - } - if (Config.DEBUG) { - val printout = m.map { it.toString(16) }.chunked(4) - printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) } - println("Offset ${offsetCounter}") - } - - v[12] = v[12] xor offsetCounter.ulongValue() - v[13] = v[13] xor (offsetCounter shr BITS_IN_WORD).ulongValue() - - if (finalBlock) { - v[14] = v[14].inv() - } - - for (i in 0 until ROUNDS_IN_COMPRESS) { - mixRound(v, m, i) - } - - for (i in 0..7) { - h[i] = h[i] xor v[i] xor v[i + 8] - } - return h - } - - - fun digest(inputString: String, key: String?, hashLength: Int): UByteArray { - val array = inputString.encodeToUByteArray() - val keyBytes = key?.run { - encodeToUByteArray() - } ?: ubyteArrayOf() - return digest(inputMessage = array, key = keyBytes, hashLength = hashLength) - - } - - override fun digest( - inputMessage: UByteArray, - key: UByteArray, - hashLength: Int - ): UByteArray { - if (hashLength > MAX_HASH_BYTES) { - throw RuntimeException("Invalid hash length. Requested length more than maximum length. Requested length $hashLength") - } - val chunkedMessage = inputMessage.chunked(BLOCK_BYTES).map { it.toUByteArray() }.toTypedArray() - - val h = iv.copyOf() - - h[0] = h[0] xor 0x01010000UL xor (key.size.toULong() shl 8) xor hashLength.toULong() - - - val message = if (key.isEmpty()) { - if (chunkedMessage.isEmpty()) { - Array(1) { - UByteArray(128) { - 0U - } - } - } else { - chunkedMessage - } - } else { - arrayOf(padToBlock(key), *chunkedMessage) - } - - if (message.size > 1) { - for (i in 0 until message.size - 1) { - compress(h, message[i], ((i + 1) * BLOCK_BYTES).toBigInteger(), false).copyInto(h) - } - } - - val lastSize = when (message.size) { - 0 -> 0 - 1 -> message[message.size - 1].size - else -> (message.size - 1) * BLOCK_BYTES + message[message.size - 1].size - - } - - val lastBlockPadded = if (message.isNotEmpty()) { - padToBlock(message[message.size - 1]) - } else { - UByteArray(16) { 0U } - } - - compress(h, lastBlockPadded, lastSize.toBigInteger(), true).copyInto(h) - - - return formatResult(h).copyOfRange(0, hashLength) - } - - private fun formatResult(h: Array): UByteArray { - return h.map { - arrayOf( - (it and 0xFFUL).toUByte(), - (it shr 8 and 0xFFUL).toUByte(), - (it shr 16 and 0xFFUL).toUByte(), - (it shr 24 and 0xFFUL).toUByte(), - (it shr 32 and 0xFFUL).toUByte(), - (it shr 40 and 0xFFUL).toUByte(), - (it shr 48 and 0xFFUL).toUByte(), - (it shr 56 and 0xFFUL).toUByte() - ) - }.flatMap { - it.toList() - }.toUByteArray() - } - - private fun padToBlock(unpadded: UByteArray): UByteArray { - if (unpadded.size == BLOCK_BYTES) { - return unpadded - } - - if (unpadded.size > BLOCK_BYTES) { - throw IllegalStateException("Block larger than 128 bytes") - } - - return UByteArray(BLOCK_BYTES) { - when (it) { - in 0 until unpadded.size -> unpadded[it] - else -> 0U - } - } - - } - } - - constructor( - key: String?, - requestedHashLenght: Int = 64 - ) : this( - (key?.encodeToUByteArray() ?: ubyteArrayOf()), - requestedHashLenght - ) - - override val MAX_HASH_BYTES: Int = Blake2bPure.MAX_HASH_BYTES - - var h = iv.copyOf() - var counter = BigInteger.ZERO - var bufferCounter = 0 - var buffer = UByteArray(BLOCK_BYTES) { 0U } - - - init { - h[0] = h[0] xor 0x01010000UL xor (key?.run { size.toULong() shl 8 } ?: 0UL) xor hashLength.toULong() - - if (!key.isNullOrEmpty()) { - appendToBuffer(padToBlock(key), bufferCounter) - } - } - - override fun update(data: UByteArray) { - if (data.isEmpty()) { - throw RuntimeException("Updating with empty array is not allowed. If you need empty hash, just call digest without updating") - } - - when { - bufferCounter + data.size < BLOCK_BYTES -> appendToBuffer(data, bufferCounter) - bufferCounter + data.size >= BLOCK_BYTES -> { - val chunked = data.chunked(BLOCK_BYTES).map { it.toUByteArray() } - chunked.forEach { chunk -> - if (bufferCounter + chunk.size < BLOCK_BYTES) { - appendToBuffer(chunk, bufferCounter) - } else { - chunk.copyInto( - destination = buffer, - destinationOffset = bufferCounter, - startIndex = 0, - endIndex = BLOCK_BYTES - bufferCounter - ) - counter += BLOCK_BYTES - consumeBlock(buffer) - buffer = UByteArray(BLOCK_BYTES) { - when (it) { - in (0 until (chunk.size - (BLOCK_BYTES - bufferCounter))) -> { - chunk[it + (BLOCK_BYTES - bufferCounter)] - } - else -> { - 0U - } - } - - } - bufferCounter = chunk.size - (BLOCK_BYTES - bufferCounter) - } - } - - } - } - - } - - fun update(data: String) { - update(data.encodeToUByteArray()) - } - - private fun appendToBuffer(array: UByteArray, start: Int) { - array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size) - bufferCounter += array.size - } - - private fun consumeBlock(block: UByteArray) { - h = compress(h, block, counter, false) - } - - override fun digest(): UByteArray { - val lastBlockPadded = padToBlock(buffer) - counter += bufferCounter - compress(h, lastBlockPadded, counter, true) - - val result = formatResult(h) - reset() - return result - - } - - - private fun reset() { - h = iv.copyOf() - counter = BigInteger.ZERO - bufferCounter = 0 - buffer = UByteArray(BLOCK_BYTES) { 0U } - } - - -} - - - - - 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 deleted file mode 100644 index eda11e8..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Pure.kt +++ /dev/null @@ -1,328 +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.hash.sha - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.rotateRight - - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - - - -class Sha256Pure : Sha256 { - - override val MAX_HASH_BYTES: Int = 32 - - - companion object : StatelessSha256 { - const val BLOCK_SIZE = 512 - const val BLOCK_SIZE_IN_BYTES = 64 - const val UINT_MASK = 0xFFFFFFFFU - const val BYTE_MASK_FROM_ULONG = 0xFFUL - const val BYTE_MASK_FROM_UINT = 0xFFU - - override val MAX_HASH_BYTES: Int = 32 - - val iv = arrayOf( - 0x6a09e667U, - 0xbb67ae85U, - 0x3c6ef372U, - 0xa54ff53aU, - 0x510e527fU, - 0x9b05688cU, - 0x1f83d9abU, - 0x5be0cd19U - ) - - val k = arrayOf( - 0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U, - 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U, - 0xe49b69c1U, 0xefbe4786U, 0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU, - 0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U, 0x06ca6351U, 0x14292967U, - 0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U, 0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U, - 0xa2bfe8a1U, 0xa81a664bU, 0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U, - 0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU, 0x5b9cca4fU, 0x682e6ff3U, - 0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U - ) - - - override fun digest(inputMessage: UByteArray): UByteArray { - - var h = iv.copyOf() - - val expansionArray = createExpansionArray(inputMessage.size.toLong()) - - val chunks = ( - inputMessage + - expansionArray + - (inputMessage.size * 8).toULong().toPaddedByteArray() - ) - .chunked(BLOCK_SIZE_IN_BYTES) - - chunks.forEach { chunk -> - val w = expandChunk(chunk.toUByteArray()) - mix(h, w).copyInto(h) - - } - - val digest = h[0].toPaddedByteArray() + - h[1].toPaddedByteArray() + - h[2].toPaddedByteArray() + - h[3].toPaddedByteArray() + - h[4].toPaddedByteArray() + - h[5].toPaddedByteArray() + - h[6].toPaddedByteArray() + - h[7].toPaddedByteArray() - return digest - } - - private fun scheduleSigma0(value: UInt): UInt { - return value.rotateRight(7) xor value.rotateRight(18) xor (value shr 3) - } - - private fun scheduleSigma1(value: UInt): UInt { - return value.rotateRight(17) xor value.rotateRight(19) xor (value shr 10) - } - - private fun compressionSigma0(a: UInt): UInt { - return (a rotateRight 2) xor (a rotateRight 13) xor (a rotateRight 22) - } - - private fun compressionSigma1(e: UInt): UInt { - return (e rotateRight 6) xor (e rotateRight 11) xor (e rotateRight 25) - } - - private fun ch(x: UInt, y: UInt, z: UInt): UInt { - return ((x and y) xor ((x xor UINT_MASK) and z)) - } - - private fun maj(x: UInt, y: UInt, z: UInt): UInt { - return (((x and y) xor (x and z) xor (y and z))) - } - - private fun expandChunk(chunk: UByteArray): Array { - val w = Array(BLOCK_SIZE_IN_BYTES) { - when (it) { - in 0 until 16 -> { - var collected = (chunk[(it * 4)].toUInt() shl 24) + - (chunk[(it * 4) + 1].toUInt() shl 16) + - (chunk[(it * 4) + 2].toUInt() shl 8) + - (chunk[(it * 4) + 3].toUInt()) - collected - } - else -> 0U - } - } - for (i in 16 until BLOCK_SIZE_IN_BYTES) { - val s0 = scheduleSigma0(w[i - 15]) - val s1 = scheduleSigma1(w[i - 2]) - w[i] = w[i - 16] + s0 + w[i - 7] + s1 - } - return w - } - - private fun mix(h: Array, w: Array): Array { - var paramA = h[0] - var paramB = h[1] - var paramC = h[2] - var paramD = h[3] - var paramE = h[4] - var paramF = h[5] - var paramG = h[6] - var paramH = h[7] - - for (i in 0 until BLOCK_SIZE_IN_BYTES) { - val s1 = compressionSigma1(paramE) - val ch = ch(paramE, paramF, paramG) - val temp1 = paramH + s1 + ch + k[i] + w[i] - val s0 = compressionSigma0(paramA) - val maj = maj(paramA, paramB, paramC) - val temp2 = s0 + maj - paramH = paramG - paramG = paramF - paramF = paramE - paramE = paramD + temp1 - paramD = paramC - paramC = paramB - paramB = paramA - paramA = temp1 + temp2 - } - - h[0] += paramA - h[1] += paramB - h[2] += paramC - h[3] += paramD - h[4] += paramE - h[5] += paramF - h[6] += paramG - h[7] += paramH - return h - } - - - fun createExpansionArray(originalSizeInBytes: Long): UByteArray { - val originalMessageSizeInBits = originalSizeInBytes * 8 - - - //K such that L + 1 + K + 64 is a multiple of 512 - val expandedRemainderOf512 = (originalMessageSizeInBits + BLOCK_SIZE_IN_BYTES + 1) % BLOCK_SIZE - val zeroAddAmount = when (expandedRemainderOf512) { - 0L -> 0 - else -> ((BLOCK_SIZE - expandedRemainderOf512) / 8).toInt() - } - val expansionArray = UByteArray(zeroAddAmount + 1) { - when (it) { - 0 -> 0b10000000U - else -> 0U - } - } - return expansionArray - } - - private fun ULong.toPaddedByteArray(): UByteArray { - val byteMask = BYTE_MASK_FROM_ULONG - return UByteArray(8) { - when (it) { - 7 -> (this and byteMask).toUByte() - 6 -> ((this shr 8) and byteMask).toUByte() - 5 -> ((this shr 16) and byteMask).toUByte() - 4 -> ((this shr 24) and byteMask).toUByte() - 3 -> ((this shr 32) and byteMask).toUByte() - 2 -> ((this shr 40) and byteMask).toUByte() - 1 -> ((this shr 48) and byteMask).toUByte() - 0 -> ((this shr 54) and byteMask).toUByte() - else -> throw RuntimeException("Invalid conversion") - } - } - } - - private fun UInt.toPaddedByteArray(): UByteArray { - val byteMask = BYTE_MASK_FROM_UINT - return UByteArray(4) { - when (it) { - 3 -> (this and byteMask).toUByte() - 2 -> ((this shr 8) and byteMask).toUByte() - 1 -> ((this shr 16) and byteMask).toUByte() - 0 -> ((this shr 24) and byteMask).toUByte() - else -> throw RuntimeException("Invalid conversion") - } - } - } - - } - - var h = iv.copyOf() - var counter = 0L - var bufferCounter = 0 - var buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { 0U } - var digested = false - - - fun update(data: String) { - if (digested) { - throw RuntimeException("This instance of updateable SHA256 was already finished once. You should use new instance") - } - return update(data.encodeToUByteArray()) - } - - override fun update(data: UByteArray) { - if (data.isEmpty()) { - throw RuntimeException("Updating with empty array is not allowed. If you need empty hash, just call digest without updating") - } - - when { - bufferCounter + data.size < BLOCK_SIZE_IN_BYTES -> appendToBuffer(data, bufferCounter) - bufferCounter + data.size == BLOCK_SIZE_IN_BYTES -> { - counter += BLOCK_SIZE_IN_BYTES - consumeBlock(data) - } - bufferCounter + data.size == BLOCK_SIZE_IN_BYTES -> { - counter += BLOCK_SIZE_IN_BYTES - consumeBlock(data) - } - bufferCounter + data.size >= BLOCK_SIZE_IN_BYTES -> { - val chunked = data.chunked(BLOCK_SIZE_IN_BYTES) - chunked.forEach { chunk -> - if (bufferCounter + chunk.size < BLOCK_SIZE_IN_BYTES) { - appendToBuffer(chunk.toUByteArray(), bufferCounter) - } else { - chunk.toUByteArray().copyInto( - destination = buffer, - destinationOffset = bufferCounter, - startIndex = 0, - endIndex = BLOCK_SIZE_IN_BYTES - bufferCounter - ) - counter += BLOCK_SIZE_IN_BYTES - consumeBlock(buffer) - buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { - when (it) { - in (0 until (chunk.size - (BLOCK_SIZE_IN_BYTES - bufferCounter))) -> { - chunk[it + (BLOCK_SIZE_IN_BYTES - bufferCounter)] - } - else -> { - 0U - } - } - - } - bufferCounter = chunk.size - (BLOCK_SIZE_IN_BYTES - bufferCounter) - } - } - - } - } - } - - private fun consumeBlock(block: UByteArray) { - val w = expandChunk(block) - mix(h, w).copyInto(h) - } - - override fun digest(): UByteArray { - val length = counter + bufferCounter - val expansionArray = createExpansionArray(length) - val finalBlock = - buffer.copyOfRange(0, bufferCounter) + expansionArray + (length * 8).toULong().toPaddedByteArray() - finalBlock.chunked(BLOCK_SIZE_IN_BYTES).forEach { - consumeBlock(it.toUByteArray()) - } - - - val digest = h[0].toPaddedByteArray() + - h[1].toPaddedByteArray() + - h[2].toPaddedByteArray() + - h[3].toPaddedByteArray() + - h[4].toPaddedByteArray() + - h[5].toPaddedByteArray() + - h[6].toPaddedByteArray() + - h[7].toPaddedByteArray() - digested = true - return digest - } - - private fun appendToBuffer(array: UByteArray, start: Int) { - array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size) - bufferCounter += array.size - } - - -} 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 deleted file mode 100644 index 2aba3af..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Pure.kt +++ /dev/null @@ -1,394 +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.hash.sha - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.rotateRight - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 18-Jul-2019 - */ - - -class Sha512Pure : Sha512Multipart { - - override val MAX_HASH_BYTES: Int = 32 - - companion object : Sha512 { - const val BLOCK_SIZE = 1024 - const val BLOCK_SIZE_IN_BYTES = 128 - const val CHUNK_SIZE = 80 - const val ULONG_MASK = 0xFFFFFFFFFFFFFFFFUL - - override val MAX_HASH_BYTES: Int = 32 - - val k = arrayOf( - 0x428a2f98d728ae22UL, - 0x7137449123ef65cdUL, - 0xb5c0fbcfec4d3b2fUL, - 0xe9b5dba58189dbbcUL, - 0x3956c25bf348b538UL, - 0x59f111f1b605d019UL, - 0x923f82a4af194f9bUL, - 0xab1c5ed5da6d8118UL, - 0xd807aa98a3030242UL, - 0x12835b0145706fbeUL, - 0x243185be4ee4b28cUL, - 0x550c7dc3d5ffb4e2UL, - 0x72be5d74f27b896fUL, - 0x80deb1fe3b1696b1UL, - 0x9bdc06a725c71235UL, - 0xc19bf174cf692694UL, - 0xe49b69c19ef14ad2UL, - 0xefbe4786384f25e3UL, - 0x0fc19dc68b8cd5b5UL, - 0x240ca1cc77ac9c65UL, - 0x2de92c6f592b0275UL, - 0x4a7484aa6ea6e483UL, - 0x5cb0a9dcbd41fbd4UL, - 0x76f988da831153b5UL, - 0x983e5152ee66dfabUL, - 0xa831c66d2db43210UL, - 0xb00327c898fb213fUL, - 0xbf597fc7beef0ee4UL, - 0xc6e00bf33da88fc2UL, - 0xd5a79147930aa725UL, - 0x06ca6351e003826fUL, - 0x142929670a0e6e70UL, - 0x27b70a8546d22ffcUL, - 0x2e1b21385c26c926UL, - 0x4d2c6dfc5ac42aedUL, - 0x53380d139d95b3dfUL, - 0x650a73548baf63deUL, - 0x766a0abb3c77b2a8UL, - 0x81c2c92e47edaee6UL, - 0x92722c851482353bUL, - 0xa2bfe8a14cf10364UL, - 0xa81a664bbc423001UL, - 0xc24b8b70d0f89791UL, - 0xc76c51a30654be30UL, - 0xd192e819d6ef5218UL, - 0xd69906245565a910UL, - 0xf40e35855771202aUL, - 0x106aa07032bbd1b8UL, - 0x19a4c116b8d2d0c8UL, - 0x1e376c085141ab53UL, - 0x2748774cdf8eeb99UL, - 0x34b0bcb5e19b48a8UL, - 0x391c0cb3c5c95a63UL, - 0x4ed8aa4ae3418acbUL, - 0x5b9cca4f7763e373UL, - 0x682e6ff3d6b2b8a3UL, - 0x748f82ee5defb2fcUL, - 0x78a5636f43172f60UL, - 0x84c87814a1f0ab72UL, - 0x8cc702081a6439ecUL, - 0x90befffa23631e28UL, - 0xa4506cebde82bde9UL, - 0xbef9a3f7b2c67915UL, - 0xc67178f2e372532bUL, - 0xca273eceea26619cUL, - 0xd186b8c721c0c207UL, - 0xeada7dd6cde0eb1eUL, - 0xf57d4f7fee6ed178UL, - 0x06f067aa72176fbaUL, - 0x0a637dc5a2c898a6UL, - 0x113f9804bef90daeUL, - 0x1b710b35131c471bUL, - 0x28db77f523047d84UL, - 0x32caab7b40c72493UL, - 0x3c9ebe0a15c9bebcUL, - 0x431d67c49c100d4cUL, - 0x4cc5d4becb3e42b6UL, - 0x597f299cfc657e2aUL, - 0x5fcb6fab3ad6faecUL, - 0x6c44198c4a475817UL - ) - - val iv = arrayOf( - 0x6a09e667f3bcc908UL, - 0xbb67ae8584caa73bUL, - 0x3c6ef372fe94f82bUL, - 0xa54ff53a5f1d36f1UL, - 0x510e527fade682d1UL, - 0x9b05688c2b3e6c1fUL, - 0x1f83d9abfb41bd6bUL, - 0x5be0cd19137e2179UL - ) - - - override fun digest(inputMessage: UByteArray): UByteArray { - - var h = iv.copyOf() - - val expansionArray = createExpansionArray(inputMessage.size.toLong()) - - val chunks = - (inputMessage + expansionArray + (inputMessage.size * 8).toULong().toPadded128BitByteArray()).chunked( - BLOCK_SIZE_IN_BYTES - ) - - chunks.forEach { chunk -> - val w = expandChunk(chunk.toUByteArray()) - mix(h, w) - - } - - val digest = - h[0].toPaddedByteArray() + - h[1].toPaddedByteArray() + - h[2].toPaddedByteArray() + - h[3].toPaddedByteArray() + - h[4].toPaddedByteArray() + - h[5].toPaddedByteArray() + - h[6].toPaddedByteArray() + - h[7].toPaddedByteArray() - return digest - } - - private fun scheduleSigma0(value: ULong): ULong { - return value.rotateRight(1) xor value.rotateRight(8) xor (value shr 7) - } - - private fun scheduleSigma1(value: ULong): ULong { - return value.rotateRight(19) xor value.rotateRight(61) xor (value shr 6) - } - - private fun compressionSigma0(e: ULong): ULong { - return (e rotateRight 28) xor (e rotateRight 34) xor (e rotateRight 39) - } - - private fun compressionSigma1(a: ULong): ULong { - return (a rotateRight 14) xor (a rotateRight 18) xor (a rotateRight 41) - } - - private fun ch(x: ULong, y: ULong, z: ULong): ULong { - return ((x and y) xor ((x xor ULONG_MASK) and z)) - } - - private fun maj(x: ULong, y: ULong, z: ULong): ULong { - return ((x and y) xor (x and z) xor (y and z)) - } - - private fun expandChunk(chunk: UByteArray): Array { - val w = Array(CHUNK_SIZE) { - when (it) { - in 0 until 16 -> { - var collected = (chunk[(it * 8)].toULong() shl 56) + - (chunk[(it * 8) + 1].toULong() shl 48) + - (chunk[(it * 8) + 2].toULong() shl 40) + - (chunk[(it * 8) + 3].toULong() shl 32) + - (chunk[(it * 8) + 4].toULong() shl 24) + - (chunk[(it * 8) + 5].toULong() shl 16) + - (chunk[(it * 8) + 6].toULong() shl 8) + - (chunk[(it * 8) + 7].toULong()) - collected - } - else -> 0UL - } - } - for (i in 16 until CHUNK_SIZE) { - val s0 = scheduleSigma0(w[i - 15]) - val s1 = scheduleSigma1(w[i - 2]) - w[i] = w[i - 16] + s0 + w[i - 7] + s1 - } - return w - } - - private fun mix(h: Array, w: Array): Array { - var paramA = h[0] - var paramB = h[1] - var paramC = h[2] - var paramD = h[3] - var paramE = h[4] - var paramF = h[5] - var paramG = h[6] - var paramH = h[7] - - for (i in 0 until CHUNK_SIZE) { - val s1 = compressionSigma1(paramE) - val ch = ch(paramE, paramF, paramG) - val temp1 = paramH + s1 + ch + k[i] + w[i] - val s0 = compressionSigma0(paramA) - val maj = maj(paramA, paramB, paramC) - val temp2 = s0 + maj - paramH = paramG - paramG = paramF - paramF = paramE - paramE = paramD + temp1 - paramD = paramC - paramC = paramB - paramB = paramA - paramA = temp1 + temp2 - } - - h[0] += paramA - h[1] += paramB - h[2] += paramC - h[3] += paramD - h[4] += paramE - h[5] += paramF - h[6] += paramG - h[7] += paramH - return h - } - - fun createExpansionArray(originalSizeInBytes: Long): UByteArray { - val originalMessageSizeInBits = originalSizeInBytes * 8 - - val expandedRemainderOf1024 = (originalMessageSizeInBits + 129) % BLOCK_SIZE - val zeroAddAmount = when (expandedRemainderOf1024) { - 0L -> 0 - else -> ((BLOCK_SIZE - expandedRemainderOf1024) / 8).toInt() - } - val expansionArray = UByteArray(zeroAddAmount + 1) { - when (it) { - 0 -> 0b10000000U - else -> 0U - } - } - return expansionArray - } - - - private fun ULong.toPaddedByteArray(): UByteArray { - val byteMask = 0xFFUL - //Ignore messages longer than 64 bits for now - return UByteArray(8) { - when (it) { - 7 -> (this and byteMask).toUByte() - 6 -> ((this shr 8) and byteMask).toUByte() - 5 -> ((this shr 16) and byteMask).toUByte() - 4 -> ((this shr 24) and byteMask).toUByte() - 3 -> ((this shr 32) and byteMask).toUByte() - 2 -> ((this shr 40) and byteMask).toUByte() - 1 -> ((this shr 48) and byteMask).toUByte() - 0 -> ((this shr 56) and byteMask).toUByte() - else -> 0U - } - } - } - - private fun ULong.toPadded128BitByteArray(): UByteArray { - val byteMask = 0xFFUL - //Ignore messages longer than 64 bits for now - return UByteArray(16) { - when (it) { - 15 -> (this and byteMask).toUByte() - 14 -> ((this shr 8) and byteMask).toUByte() - 13 -> ((this shr 16) and byteMask).toUByte() - 12 -> ((this shr 24) and byteMask).toUByte() - 11 -> ((this shr 32) and byteMask).toUByte() - 10 -> ((this shr 40) and byteMask).toUByte() - 9 -> ((this shr 48) and byteMask).toUByte() - 8 -> ((this shr 54) and byteMask).toUByte() - else -> 0U - } - } - } - } - - var h = iv.copyOf() - var counter = 0L - var bufferCounter = 0 - var buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { 0U } - var digested = false - - - fun update(data: String) { - return update(data.encodeToUByteArray()) - } - - override fun update(data: UByteArray) { - if (data.isEmpty()) { - throw RuntimeException("Updating with empty array is not allowed. If you need empty hash, just call digest without updating") - } - if (digested) { - throw RuntimeException("This instance of updateable SHA256 was already finished once. You should use new instance") - } - - when { - bufferCounter + data.size < BLOCK_SIZE_IN_BYTES -> appendToBuffer(data, bufferCounter) - bufferCounter + data.size >= BLOCK_SIZE_IN_BYTES -> { - val chunked = data.chunked(BLOCK_SIZE_IN_BYTES) - chunked.forEach { chunk -> - if (bufferCounter + chunk.size < BLOCK_SIZE_IN_BYTES) { - appendToBuffer(chunk.toUByteArray(), bufferCounter) - } else { - chunk.toUByteArray().copyInto( - destination = buffer, - destinationOffset = bufferCounter, - startIndex = 0, - endIndex = BLOCK_SIZE_IN_BYTES - bufferCounter - ) - counter += BLOCK_SIZE_IN_BYTES - consumeBlock(buffer) - buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { - when (it) { - in (0 until (chunk.size - (BLOCK_SIZE_IN_BYTES - bufferCounter))) -> { - chunk[it + (BLOCK_SIZE_IN_BYTES - bufferCounter)] - } - else -> { - 0U - } - } - - } - bufferCounter = chunk.size - (BLOCK_SIZE_IN_BYTES - bufferCounter) - } - } - - } - } - } - - private fun consumeBlock(block: UByteArray) { - val w = expandChunk(block) - mix(h, w).copyInto(h) - } - - override fun digest(): UByteArray { - val length = counter + bufferCounter - val expansionArray = createExpansionArray(length) - val finalBlock = - buffer.copyOfRange(0, bufferCounter) + expansionArray + (length * 8).toULong().toPadded128BitByteArray() - finalBlock.chunked(BLOCK_SIZE_IN_BYTES).forEach { - consumeBlock(it.toUByteArray()) - } - - - val digest = h[0].toPaddedByteArray() + - h[1].toPaddedByteArray() + - h[2].toPaddedByteArray() + - h[3].toPaddedByteArray() + - h[4].toPaddedByteArray() + - h[5].toPaddedByteArray() + - h[6].toPaddedByteArray() + - h[7].toPaddedByteArray() - digested = true - return digest - } - - private fun appendToBuffer(array: UByteArray, start: Int) { - array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size) - bufferCounter += array.size - } - - -} diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt deleted file mode 100644 index 707a664..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ionspin.kotlin.crypto.keyderivation.argon2 - -import com.ionspin.kotlin.crypto.keyderivation.KeyDerivationFunction - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 24-May-2020 - */ -interface Argon2 : KeyDerivationFunction \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Exceptions.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Exceptions.kt deleted file mode 100644 index 57c7ed4..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Exceptions.kt +++ /dev/null @@ -1,31 +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.keyderivation.argon2 - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 16-May-2020 - */ -class Argon2TagTooShort(tagLength: UInt) : RuntimeException("Too short tag (output) requested. Requested: $tagLength") -class Argon2TagTooLong(tagLength: UInt) : RuntimeException("Too long tag (output) requested. Requested: $tagLength") -class Argon2TimeTooShort(iterations: Int) : RuntimeException("Too short time parameter (Too few iterations). Requested iterations: $iterations") -class Argon2TimeTooLong(iterations: Int) : RuntimeException("Too long time parameter (Too many iterations). Requested iterations: $iterations") -class Argon2MemoryTooLitlle(requestedMemorySize: UInt) : RuntimeException("Requested memory size must be larger than 8 * parallelism. Requested size: $requestedMemorySize") -class Argon2MemoryTooMuch(requestedMemorySize: UInt) : RuntimeException("Requested memory size too large. Requested size: $requestedMemorySize") -class Argon2LanesTooFew(parallelism: Int) : RuntimeException("Too few, or invalid number of threads requested $parallelism") -class Argon2LanesTooMany(parallelism: Int) : RuntimeException("Too many threads requested (parallelism). Requested: $parallelism") \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Pure.kt deleted file mode 100644 index f32883f..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Pure.kt +++ /dev/null @@ -1,401 +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. - */ - -@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS") - -package com.ionspin.kotlin.crypto.keyderivation.argon2 - -import com.ionspin.kotlin.bignum.integer.toBigInteger - -import com.ionspin.kotlin.crypto.SRNG -import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bPure -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.keyderivation.ArgonResult -import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.argonBlake2bArbitraryLenghtHash -import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.compressionFunctionG -import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.validateArgonParameters -import com.ionspin.kotlin.crypto.util.* - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 16-May-2020 - */ - -enum class ArgonType(val typeId: Int) { - Argon2d(0), Argon2i(1), Argon2id(2) -} - -data class SegmentPosition( - val iteration: Int, - val lane: Int, - val slice: Int -) - - - - - - -class Argon2Pure( - private val password: UByteArray, - private val salt: UByteArray = ubyteArrayOf(), - private val parallelism: Int = 1, - private val tagLength: UInt = 64U, - requestedMemorySize: UInt = 0U, - private val numberOfIterations: Int = 1, - private val key: UByteArray = ubyteArrayOf(), - private val associatedData: UByteArray = ubyteArrayOf(), - private val argonType: ArgonType = ArgonType.Argon2id -) : Argon2 { - - companion object { - fun derive( - password: String, - salt: String? = null, - key: String, - associatedData: String, - parallelism: Int = 16, - tagLength: Int = 64, - memory: Int = 4096, - numberOfIterations: Int = 10, - ): ArgonResult { - val salt = SRNG.getRandomBytes(64) - val argon = Argon2Pure( - password.encodeToUByteArray(), - salt, - parallelism, - tagLength.toUInt(), - memory.toUInt(), - numberOfIterations, - key.encodeToUByteArray(), - associatedData.encodeToUByteArray(), - ArgonType.Argon2id - ) - val resultArray = argon.derive() - return ArgonResult(resultArray, salt) - } - } - - constructor( - password: String, - salt: String = "", - parallelism: Int = 1, - tagLength: UInt = 64U, - requestedMemorySize: UInt = 0U, - numberOfIterations: Int = 10, - key: String = "", - associatedData: String = "", - argonType: ArgonType = ArgonType.Argon2id - ) : this( - password.encodeToUByteArray(), - salt.encodeToUByteArray(), - parallelism, - tagLength, - requestedMemorySize, - numberOfIterations, - key.encodeToUByteArray(), - associatedData.encodeToUByteArray(), - argonType - ) - - //We support only the latest version - private val versionNumber: UInt = 0x13U - - //Use either requested memory size, or default, or throw exception if the requested amount is less than 8*parallelism - private val memorySize = if (requestedMemorySize == 0U) { - ((8 * parallelism) * 2).toUInt() - } else { - requestedMemorySize - } - private val blockCount = (memorySize / (4U * parallelism.toUInt())) * (4U * parallelism.toUInt()) - private val columnCount = (blockCount / parallelism.toUInt()).toInt() - private val segmentLength = columnCount / 4 - - private val useIndependentAddressing = argonType == ArgonType.Argon2id || argonType == ArgonType.Argon2i - - // State - private val matrix: ArgonMatrix - - init { - matrix = ArgonMatrix(columnCount, parallelism) - validateArgonParameters( - password, - salt, - parallelism, - tagLength, - requestedMemorySize, - numberOfIterations, - key, - associatedData, - argonType - ) - } - - - - private fun populateAddressBlock( - iteration: Int, - slice: Int, - lane: Int, - addressBlock: ArgonBlockPointer, - addressCounter: ULong - ): ArgonBlockPointer { - //Calculate first pass - val zeroesBlock = ArgonBlock() - val firstPass = compressionFunctionG( - zeroesBlock.getBlockPointer(), - ArgonBlock(iteration.toULong().toLittleEndianUByteArray() + - lane.toULong().toLittleEndianUByteArray() + - slice.toULong().toLittleEndianUByteArray() + - blockCount.toULong().toLittleEndianUByteArray() + - numberOfIterations.toULong().toLittleEndianUByteArray() + - argonType.typeId.toULong().toLittleEndianUByteArray() + - addressCounter.toLittleEndianUByteArray() + - UByteArray(968) { 0U } - ).getBlockPointer(), - addressBlock, - false - ) - val secondPass = compressionFunctionG( - zeroesBlock.getBlockPointer(), - firstPass, - firstPass, - false - ) - return secondPass - } - - - private fun computeReferenceBlockIndexes( - iteration: Int, - slice: Int, - lane: Int, - column: Int, - addressBlockPointer: ArgonBlockPointer? - ): Pair { - - val segmentIndex = (column % segmentLength) - val independentIndex = segmentIndex % 128 // 128 is the number of addresses in address block - val (j1, j2) = when (argonType) { - ArgonType.Argon2d -> { - val previousBlockStart = if (column == 0) { - matrix.getBlockPointer(lane, columnCount - 1) //Get last block in the SAME lane - } else { - matrix.getBlockPointer(lane, column - 1) - } - val first32Bit = matrix.sliceArray(previousBlockStart.asInt() until previousBlockStart.asInt() + 4).fromLittleEndianArrayToUInt() - val second32Bit = matrix.sliceArray(previousBlockStart.asInt() + 4 until previousBlockStart.asInt() + 8).fromLittleEndianArrayToUInt() - - Pair(first32Bit, second32Bit) - } - ArgonType.Argon2i -> { - val first32Bit = addressBlockPointer!!.getUIntFromPosition(independentIndex * 8) - val second32Bit = addressBlockPointer!!.getUIntFromPosition(independentIndex * 8 + 4) - Pair(first32Bit, second32Bit) - } - ArgonType.Argon2id -> { - if (iteration == 0 && (slice == 0 || slice == 1)) { - val first32Bit = addressBlockPointer!!.getUIntFromPosition(independentIndex * 8) - val second32Bit = addressBlockPointer!!.getUIntFromPosition(independentIndex * 8 + 4) - Pair(first32Bit, second32Bit) - } else { - val previousBlockStart = if (column == 0) { - matrix.getBlockPointer(lane, columnCount - 1) //Get last block in the SAME lane - } else { - matrix.getBlockPointer(lane, column - 1) - } - val first32Bit = matrix.sliceArray(previousBlockStart.asInt() until previousBlockStart.asInt() + 4).fromLittleEndianArrayToUInt() - val second32Bit = matrix.sliceArray(previousBlockStart.asInt() + 4 until previousBlockStart.asInt() + 8).fromLittleEndianArrayToUInt() - Pair(first32Bit, second32Bit) - } - - } - } - - //If this is first iteration and first slice, block is taken from the current lane - val l = if (iteration == 0 && slice == 0) { - lane - } else { - (j2.toBigInteger() % parallelism).intValue() - - } - - - val referenceAreaSize = if (iteration == 0) { - if (slice == 0) { - //All indices except the previous - segmentIndex - 1 - } else { - if (lane == l) { - //Same lane - column - 1 - } else { - slice * (columnCount / 4) + if (segmentIndex == 0) { // Check if column is first block of the SEGMENT - -1 - } else { - 0 - } - } - } - } else { - if (lane == l) { - columnCount - (columnCount / 4) + (segmentIndex - 1) - } else { - columnCount - (columnCount / 4) + if (segmentIndex == 0) { - -1 - } else { - 0 - } - } - } - - val x = (j1.toULong() * j1) shr 32 - val y = (referenceAreaSize.toULong() * x) shr 32 - val z = referenceAreaSize.toULong() - 1U - y - - val startPosition = if (iteration == 0) { - 0 - } else { - if (slice == 3) { - 0 - } else { - (slice + 1) * segmentLength - } - } - val absolutePosition = (startPosition + z.toInt()) % columnCount - - return Pair(l, absolutePosition) - } - - override fun derive(): UByteArray { - val blakeInput = parallelism.toUInt().toLittleEndianUByteArray() + - tagLength.toLittleEndianUByteArray() + - memorySize.toLittleEndianUByteArray() + - numberOfIterations.toUInt().toLittleEndianUByteArray() + - versionNumber.toLittleEndianUByteArray() + - argonType.typeId.toUInt().toLittleEndianUByteArray() + - password.size.toUInt().toLittleEndianUByteArray() + password + - salt.size.toUInt().toLittleEndianUByteArray() + salt + - key.size.toUInt().toLittleEndianUByteArray() + key + - associatedData.size.toUInt().toLittleEndianUByteArray() + associatedData - val h0 = Blake2bPure.digest( - blakeInput - ) - - //Compute B[i][0] - for (i in 0 until parallelism) { - matrix.setBlockAt(i, 0, - argonBlake2bArbitraryLenghtHash( - (h0 + 0.toUInt().toLittleEndianUByteArray() + i.toUInt().toLittleEndianUByteArray()).toUByteArray(), - 1024U - ) - ) - } - - //Compute B[i][1] - for (i in 0 until parallelism) { - matrix.setBlockAt(i, 1, - argonBlake2bArbitraryLenghtHash( - (h0 + 1.toUInt().toLittleEndianUByteArray() + i.toUInt().toLittleEndianUByteArray()).toUByteArray(), - 1024U - ) - ) - } - //Run all iterations over all lanes and all segments - executeArgonWithSingleThread() - - - val acc = ArgonBlock(matrix.getBlockAt(0, columnCount - 1)) - val accPointer = acc.getBlockPointer() - for (i in 1 until parallelism) { - accPointer.xorInplaceWith(matrix.getBlockPointer(i, columnCount - 1)) - } - //Hash the xored last blocks - val hash = argonBlake2bArbitraryLenghtHash(acc.storage, tagLength) - matrix.clearMatrix() - return hash - - - } - - private fun executeArgonWithSingleThread() { - for (iteration in 0 until numberOfIterations) { - for (slice in 0 until 4) { - for (lane in 0 until parallelism) { - val segmentPosition = SegmentPosition(iteration, lane, slice) - processSegment(segmentPosition) - } - } - } - } - - private fun processSegment(segmentPosition: SegmentPosition) { - val iteration = segmentPosition.iteration - val slice = segmentPosition.slice - val lane = segmentPosition.lane - - var addressBlock: ArgonBlockPointer? = null - var addressCounter = 1UL //Starts from 1 in each segment as defined by the spec - - //Generate initial segment address block - if (useIndependentAddressing) { - addressBlock = ArgonBlock().getBlockPointer() - addressBlock = populateAddressBlock(iteration, slice, lane, addressBlock, addressCounter) - addressCounter++ - } - val startColumn = if (iteration == 0 && slice == 0) { - 2 - } else { - slice * segmentLength - } - - - for (column in startColumn until (slice + 1) * segmentLength) { - val segmentIndex = column - (slice * segmentLength) - //Each address block contains 128 addresses, and we use one per iteration, - //so once we do 128 iterations we need to calculate a new address block - if (useIndependentAddressing && segmentIndex != 0 && segmentIndex % 128 == 0) { - addressBlock = populateAddressBlock(iteration, slice, lane, addressBlock!!, addressCounter) - addressCounter++ - } - val previousColumn = if (column == 0) { - columnCount - 1 - } else { - column - 1 - } - val (l, z) = computeReferenceBlockIndexes( - iteration, - slice, - lane, - column, - addressBlock - ) - - matrix.setBlockAt(lane, column, - compressionFunctionG( - matrix.getBlockPointer(lane, previousColumn), - matrix.getBlockPointer(l,z), - matrix.getBlockPointer(lane,column), - true - ).getAsUByteArray() - ) - } - - } - - -} diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Utils.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Utils.kt deleted file mode 100644 index 9647d7f..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/Argon2Utils.kt +++ /dev/null @@ -1,167 +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. - */ - -@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS") - -package com.ionspin.kotlin.crypto.keyderivation.argon2 - -import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bPure -import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.BLOCK_SIZE -import com.ionspin.kotlin.crypto.util.plus -import com.ionspin.kotlin.crypto.util.rotateRight - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 16-May-2020 - */ -object Argon2Utils { - const val BLOCK_SIZE = 1024 - - const val R1 = 32 - const val R2 = 24 - const val R3 = 16 - const val R4 = 63 - - //Based on Blake2b mix - internal fun inplaceMixRound(v : ULongArray) : ULongArray{ - mix(v, 0, 4, 8, 12) - mix(v, 1, 5, 9, 13) - mix(v, 2, 6, 10, 14) - mix(v, 3, 7, 11, 15) - mix(v, 0, 5, 10, 15) - mix(v, 1, 6, 11, 12) - mix(v, 2, 7, 8, 13) - mix(v, 3, 4, 9, 14) - return v //Just for chaining, array is mixed in place - } - - //Based on Blake2b mix - private fun mix(v: ULongArray, a: Int, b: Int, c: Int, d: Int) { - v[a] = (v[a] + v[b] + 2U * (v[a] and 0xFFFFFFFFUL) * (v[b] and 0xFFFFFFFFUL)) - v[d] = (v[d] xor v[a]) rotateRight R1 - v[c] = (v[c] + v[d] + 2U * (v[c] and 0xFFFFFFFFUL) * (v[d] and 0xFFFFFFFFUL)) - v[b] = (v[b] xor v[c]) rotateRight R2 - v[a] = (v[a] + v[b] + 2U * (v[a] and 0xFFFFFFFFUL) * (v[b] and 0xFFFFFFFFUL)) - v[d] = (v[d] xor v[a]) rotateRight R3 - v[c] = (v[c] + v[d] + 2U * (v[c] and 0xFFFFFFFFUL) * (v[d] and 0xFFFFFFFFUL)) - v[b] = (v[b] xor v[c]) rotateRight R4 - } - - internal fun extractColumnFromGBlock(gBlock: UByteArray, columnPosition: Int): UByteArray { - val result = UByteArray(128) { 0U } - for (i in 0..7) { - gBlock.copyOfRange(i * 128 + (columnPosition * 16), i * 128 + (columnPosition * 16) + 16) - .copyInto(result, i * 16) - } - return result - } - - - - internal fun compressionFunctionG( - previousBlock: ArgonBlockPointer, - referenceBlock: ArgonBlockPointer, - currentBlock: ArgonBlockPointer, - xorWithCurrentBlock: Boolean - ): ArgonBlockPointer { - val r = (referenceBlock xorBlocksAndGetPointerToNewBlock previousBlock).getBlockPointer() - //Since we are doing inplace xors, we don't need the Q that exists in specification - val z = ArgonBlock().getBlockPointer() - // Do the argon/blake2b mixing on rows - for (i in 0..7) { - z.setRowFromMixedULongs(i, inplaceMixRound(r.getRowOfULongsForMixing(i))) - } - // Do the argon/blake2b mixing on columns - for (i in 0..7) { - z.setColumnFromMixedULongs(i, inplaceMixRound(z.getColumnOfULongsForMixing(i))) - } - val final = if (xorWithCurrentBlock) { - (z xorInplaceWith r) xorInplaceWith currentBlock - } else { - z xorInplaceWith r - } - return final - } - - internal fun argonBlake2bArbitraryLenghtHash(input: UByteArray, length: UInt): UByteArray { - if (length <= 64U) { - return Blake2bPure.digest(inputMessage = length + input, hashLength = length.toInt()) - } - //We can cast to int because UInt even if MAX_VALUE divided by 32 is guaranteed not to overflow - val numberOf64ByteBlocks = (1U + ((length - 1U) / 32U) - 2U).toInt() // equivalent to ceil(length/32) - 2 - val v = Array(numberOf64ByteBlocks) { ubyteArrayOf() } - v[0] = Blake2bPure.digest(length + input) - for (i in 1 until numberOf64ByteBlocks) { - v[i] = Blake2bPure.digest(v[i - 1]) - } - val remainingPartOfInput = length.toInt() - numberOf64ByteBlocks * 32 - val vLast = Blake2bPure.digest(v[numberOf64ByteBlocks - 1], hashLength = remainingPartOfInput) - val concat = - (v.map { it.copyOfRange(0, 32) }) - .plus(listOf(vLast)) - .foldRight(ubyteArrayOf()) { arrayOfUBytes, acc -> arrayOfUBytes + acc } - - return concat - } - - /** - * Validates the argon 2 parameters. - * Since Kotlin arrays that we are currently using cannot have more than 2^31 bytes, we don't need to check - * sizes for password, salt, key and associated data. Also since UInt is 32bit we cant set more than 2^32-1 of - * tagLength, requested memory size and number of iterations, so no need to check for upper bound, just lower. - */ - internal fun validateArgonParameters( - password: UByteArray, - salt: UByteArray, - parallelism: Int , - tagLength: UInt, - requestedMemorySize: UInt , - numberOfIterations: Int , - key: UByteArray, - associatedData: UByteArray, - argonType: ArgonType - ) { - - //Parallelism - if (parallelism > 0xFFFFFF) { - throw Argon2LanesTooMany(parallelism) - } - if (parallelism <= 0) { - throw Argon2LanesTooFew(parallelism) - } - //Tag length - if (tagLength <= 0U) { - throw Argon2TagTooShort(tagLength) - } - //Requested memory - if (requestedMemorySize < 8U || requestedMemorySize < (8 * parallelism).toUInt()) { - throw Argon2MemoryTooLitlle(requestedMemorySize) - } - //Number of iterations - if (numberOfIterations <= 0) { - throw Argon2TimeTooShort(numberOfIterations) - } - - } -} - -// ------------ Arithmetic and other utils - - -fun UByteArray.xorWithBlock(other : ArgonMatrix, rowPosition: Int, columnPosition: Int) : UByteArray { - return UByteArray(BLOCK_SIZE) { this[it] xor other[rowPosition, columnPosition, it] } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/ArgonMatrix.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/ArgonMatrix.kt deleted file mode 100644 index 904c048..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/keyderivation/argon2/ArgonMatrix.kt +++ /dev/null @@ -1,285 +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. - */ - -@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS") - -package com.ionspin.kotlin.crypto.keyderivation.argon2 - -import com.ionspin.kotlin.crypto.util.xor - -/** - * Represents a pointer to a Argon2 Block, this abstracts what the backing structure is, a Argon 2 Matrix or - * or a UByteArray block - */ -interface ArgonBlockPointer { - companion object { - private val _emitLongArray : LongArray = longArrayOf(1L,2L) - } - val blockStartPosition: Int - - fun pointerArithmetic(block : (Int, Int) -> Int) : ArgonBlockPointer - - infix fun xorBlocksAndGetPointerToNewBlock(other: ArgonBlockPointer) : ArgonBlock - - operator fun get(blockPosition: Int) : UByte - - operator fun set(blockPosition: Int, value: UByte) - - infix fun xorInplaceWith(other: ArgonBlockPointer) : ArgonBlockPointer { - for (it in 0 until 1024) { - this[it] = this[it] xor other[it] - } - return this //For chaining - } - - fun asInt() : Int - - fun getAsUByteArray() : UByteArray -} - -fun ArgonBlockPointer._emitLongArray() : LongArray = longArrayOf(0,1) - -fun ArgonBlockPointer.getRowOfULongsForMixing(rowIndex: Int) : ULongArray { - // Each row has 16 unsigned longs (16 ulongs * 8 bytes = 128 bytes) -- Argon2 considers this as 2 word unsigned - // numbers, so strictly speaking argon representation is 8 * 8 matrix of 2 word unsigned numbers (registers - val ulongArray = ULongArray(16) - for (columnIndex in 0 until 16) { - var ulong = 0UL - //Now we create the ulong - for (bytePosition in 0 until 8) { - ulong = ulong or (this[rowIndex * 128 + columnIndex * 8 + bytePosition].toULong() shl (bytePosition * 8)) - } - ulongArray[columnIndex] = ulong - } - return ulongArray -} - -fun ArgonBlockPointer.setRowFromMixedULongs(rowIndex: Int, ulongs: ULongArray) { - // Each row has 16 unsigned longs (16 ulongs * 8 bytes = 128 bytes) -- Argon2 considers this as 2 word unsigned - // numbers, so strictly speaking argon representation is 8 * 8 matrix of 2 word unsigned numbers (registers - for (columnIndex in 0 until 16) { - val ulongToConvert = ulongs[columnIndex] - for (bytePosition in 0 until 8) { - this[rowIndex * 128 + columnIndex * 8 + bytePosition] = ((ulongToConvert shr (bytePosition * 8)) and 0xFFU).toUByte() - } - } -} - -fun ArgonBlockPointer.getColumnOfULongsForMixing(columnIndex: Int) : ULongArray { - //In Argon2 representation there are 8 double word registers (numbers, but we work with 16 single word ulongs - val ulongArray = ULongArray(16) - //There are 8 rows that consist of 2 words (registers, in our case ulongs) each - for (rowIndex in 0 until 8) { - var ulong = 0UL - //Now we create the ulong - for (bytePosition in 0 until 8) { - ulong = ulong or (this[rowIndex * 128 + columnIndex * 16 + bytePosition].toULong() shl (bytePosition * 8)) - } - ulongArray[rowIndex * 2] = ulong - ulong = 0UL - // But unlike in columns where we can directly iterate and get all TWO WORD registers, here we also need to grab - // the next word - for (bytePosition in 8 until 16) { - ulong = ulong or (this[rowIndex * 128 + columnIndex * 16 + bytePosition].toULong() shl (bytePosition * 8)) - } - ulongArray[rowIndex * 2 + 1] = ulong - } - return ulongArray -} - -fun ArgonBlockPointer.setColumnFromMixedULongs(columnIndex: Int, ulongs: ULongArray) { - //In Argon2 representation there are 8 double word registers (numbers, but we work with 16 single word ulongs - //There are 8 rows that consist of 2 words (registers, in our case ulongs) each - var ulongToConvert = 0UL - for (rowIndex in 0 until 8) { - ulongToConvert = ulongs[rowIndex * 2] - //Now we create the ulong - for (bytePosition in 0 until 8) { - this[rowIndex * 128 + columnIndex * 16 + bytePosition] = ((ulongToConvert shr (bytePosition * 8)) and 0xFFU).toUByte() - } - // But unlike in columns where we can directly iterate and get all TWO WORD registers, here we also need to set - // the next word - ulongToConvert = ulongs[rowIndex * 2 + 1] - for (bytePosition in 8 until 16) { - this[rowIndex * 128 + columnIndex * 16 + bytePosition] = ((ulongToConvert shr (bytePosition * 8)) and 0xFFU).toUByte() - } - } -} - -fun ArgonBlockPointer.getUIntFromPosition(positionInBlock: Int) : UInt { - var uint = 0U - for (i in 0 until 4) { - uint = uint or (this[positionInBlock + i].toUInt() shl (i * 8)) - } - return uint -} - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-May-2020 - */ - class ArgonMatrix(val columnCount: Int, val rowCount: Int) { - - internal val storage: UByteArray = UByteArray(columnCount * rowCount * 1024) - - operator fun get(rowPosition: Int, columnPosition: Int, inBlockPosition: Int) : UByte { - if (rowPosition > rowCount - 1) { - throw RuntimeException("Invalid row (lane) requested: $rowPosition, rowCount: $rowCount") - } - if (columnPosition > columnCount - 1) { - throw RuntimeException("Invalid column requested: $columnPosition, columnCount: $columnCount") - } - return storage[getBlockStartPositionPointer(rowPosition, columnPosition) + inBlockPosition] - } - - val size = storage.size - - operator fun get(absolutePosition: Int) : UByte { - return storage[absolutePosition] - } - - operator fun set(rowPosition: Int, columnPosition: Int, inBlockPosition: Int, value: UByte) { - storage[getBlockStartPositionPointer(rowPosition, columnPosition) + inBlockPosition] = value - } - - operator fun set(absolutePosition: Int, value: UByte) { - storage[absolutePosition] = value - } - - fun getBlockPointer(rowPosition: Int, columnPosition: Int) : ArgonBlockPointer { - return ArgonBlockPointerWithMatrix(getBlockStartPositionPointer(rowPosition, columnPosition), this) - } - - - fun sliceArray(indices: IntRange): UByteArray { - return storage.sliceArray(indices) - } - - fun getBlockAt(rowPosition: Int, columnPosition: Int) : UByteArray { - println("Expensive get") - return storage.copyOfRange( - getBlockStartPositionPointer(rowPosition, columnPosition), - getBlockStartPositionPointer(rowPosition, columnPosition) + 1024 - ) - } - - fun setBlockAt(rowPosition: Int, columnPosition: Int, blockValue: UByteArray) { - blockValue.copyInto( - storage, - getBlockStartPositionPointer(rowPosition, columnPosition) - ) - } - - private inline fun getBlockStartPositionPointer(rowPosition: Int, columnPosition: Int) : Int { - return rowPosition * columnCount * 1024 + columnPosition * 1024 - } - - internal fun clearMatrix() { - for( index in storage.indices) { storage[index] = 0U } - } - - private class ArgonBlockPointerWithMatrix constructor(override val blockStartPosition: Int, val matrix: ArgonMatrix) : ArgonBlockPointer { - - override fun pointerArithmetic(block: (Int, Int) -> Int): ArgonBlockPointer { - return ArgonBlockPointerWithMatrix(block(blockStartPosition, matrix.size), matrix) - } - - override fun asInt(): Int { - return blockStartPosition - } - - override operator fun get(blockPosition: Int) : UByte { - return matrix[blockStartPosition + blockPosition] - } - - override fun set(blockPosition: Int, value: UByte) { - matrix[blockStartPosition + blockPosition] = value - } - - override infix fun xorBlocksAndGetPointerToNewBlock(other: ArgonBlockPointer) : ArgonBlock { - return ArgonBlock(UByteArray(1024){ - matrix[blockStartPosition + it] xor other[it] - }) - } - - override fun getAsUByteArray(): UByteArray { - return matrix.storage.slice(blockStartPosition until blockStartPosition + 1024).toUByteArray() - } - } -} - - - - -@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") -inline class ArgonBlock internal constructor(internal val storage: UByteArray) { - constructor() : this(UByteArray(1024)) - operator fun get(index: Int) : UByte { - return storage.get(index) - } - operator fun set(index: Int, value: UByte) { - storage.set(index, value) - } - - val size: Int get() = storage.size - - internal fun getAsUByteArray() : UByteArray = storage - - fun getBlockPointer() : ArgonBlockPointer{ - return ArgonBlockPointerWithBlock( this) - } - - infix fun xorInplaceWith(other: ArgonBlock) : ArgonBlock { - storage.indices.forEach { - this[it] = this[it] xor other[it] - } - return this //For chaining - } - - - - private class ArgonBlockPointerWithBlock constructor(val storageBlock: ArgonBlock) : ArgonBlockPointer { - override val blockStartPosition: Int = 0 - - override fun pointerArithmetic(block: (Int, Int) -> Int): ArgonBlockPointer { - throw RuntimeException("Haven't really tought out pointer arithmetic with blocks") - } - - override fun asInt(): Int { - return blockStartPosition - } - override operator fun get(blockPosition: Int) : UByte { - return storageBlock[blockPosition] - } - - override fun set(blockPosition: Int, value: UByte) { - storageBlock[blockPosition] = value - } - - override infix fun xorBlocksAndGetPointerToNewBlock(other: ArgonBlockPointer) : ArgonBlock { - return ArgonBlock(UByteArray(1024){ - storageBlock[it] xor other[it] - }) - } - - override fun getAsUByteArray(): UByteArray { - return storageBlock.storage - } - - } - -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/mac/Poly1305.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/mac/Poly1305.kt deleted file mode 100644 index 406ebeb..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/mac/Poly1305.kt +++ /dev/null @@ -1,118 +0,0 @@ -package com.ionspin.kotlin.crypto.mac - -import com.ionspin.kotlin.bignum.Endianness -import com.ionspin.kotlin.bignum.integer.BigInteger -import com.ionspin.kotlin.bignum.integer.Sign -import com.ionspin.kotlin.crypto.util.fromLittleEndianUByteArrayToBigEndianUByteArray -import com.ionspin.kotlin.crypto.util.hexColumsPrint - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 18-Jun-2020 - */ -class Poly1305(key: UByteArray) { - companion object { - fun clampR(r: UByteArray) : UByteArray { - val clamped = UByteArray(16) { r[it] } - clamped[3] = r[3] and 0b00001111U - clamped[7] = r[7] and 0b00001111U - clamped[11] = r[11] and 0b00001111U - clamped[15] = r[15] and 0b00001111U - - clamped[4] = r[4] and 0b11111100U - clamped[8] = r[8] and 0b11111100U - clamped[12] = r[12] and 0b11111100U - return clamped - - } - - val P = BigInteger.fromUByteArray( - ubyteArrayOf( - 0x03U, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xffU, 0xfbU - ), - Sign.POSITIVE - ) - val powersOfTwo = Array(129) { - BigInteger.ONE shl it - } - val resultMask = (BigInteger.ONE shl 128) - 1 - //Doesn't have to be every power, just divisible by 8 - val twoToThe128 = BigInteger.ONE.shl(128) - - /** - * Limit - stop poly calculating tag at desired index, ignored if 0 - */ - fun poly1305Authenticate(key: UByteArray, message: UByteArray) : UByteArray { - val r = clampR(UByteArray(16) { key[it] }) - val s= UByteArray(16) { key[it + 16]} - - var accumulator = BigInteger.ZERO - val rAsBigInt = BigInteger.fromUByteArray(r.fromLittleEndianUByteArrayToBigEndianUByteArray(), Sign.POSITIVE) //TODO convert from little endian ubyte array to what BigInteger expects - val sAsBigInt = BigInteger.fromUByteArray(s.fromLittleEndianUByteArrayToBigEndianUByteArray(), Sign.POSITIVE) - val blocks = message.size / 16 - val remainder = message.size % 16 - - for (i in 0 until blocks) { - val slice = message.sliceArray(i * 16 until i * 16 + 16) - slice.hexColumsPrint() - val blockAsInt = BigInteger.fromUByteArray(slice.fromLittleEndianUByteArrayToBigEndianUByteArray(), Sign.POSITIVE) + powersOfTwo[128] - accumulator += blockAsInt - accumulator *= rAsBigInt - accumulator %= P - } - if (remainder != 0) { - val slice = message.sliceArray(blocks * 16 until blocks * 16 + remainder) - val blockAsInt = BigInteger.fromUByteArray(slice.fromLittleEndianUByteArrayToBigEndianUByteArray(), Sign.POSITIVE) + powersOfTwo[remainder * 8] - accumulator += blockAsInt - accumulator *= rAsBigInt - accumulator %= P - } - - accumulator += sAsBigInt - accumulator = accumulator and resultMask - val result = accumulator.toUByteArray() - result.reverse() - return result - - - } - } - var rAsBigInt = BigInteger.fromUByteArray( - clampR(key.sliceArray(0 until 16)).fromLittleEndianUByteArrayToBigEndianUByteArray(), - Sign.POSITIVE - ) - var sAsBigInt = BigInteger.fromUByteArray( - key.sliceArray(16 until 32).fromLittleEndianUByteArrayToBigEndianUByteArray(), - Sign.POSITIVE) - var accumulator = BigInteger.ZERO - - fun updateMac(data : UByteArray) { - if (data.size != 16) { - throw RuntimeException("Invalide block size, required 16, got ${data.size}") - } - val blockAsInt = BigInteger.fromUByteArray( - data.fromLittleEndianUByteArrayToBigEndianUByteArray(), Sign.POSITIVE - ) + powersOfTwo[128] - accumulator += blockAsInt - accumulator *= rAsBigInt - accumulator %= P - } - - fun finalizeMac(data: UByteArray = ubyteArrayOf()) : UByteArray{ - if (data.size != 0) { - val blockAsInt = BigInteger.fromUByteArray( - data.fromLittleEndianUByteArrayToBigEndianUByteArray(), - Sign.POSITIVE - ) + powersOfTwo[data.size * 8] - accumulator += blockAsInt - accumulator *= rAsBigInt - accumulator %= P - } - accumulator += sAsBigInt - accumulator = accumulator and resultMask - val result = accumulator.toUByteArray() - result.reverse() - return result - } -} diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Aes.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Aes.kt deleted file mode 100644 index 55ceeb7..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Aes.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 13-Jun-2020 - */ -internal sealed class InternalAesKey(val key: String, val keyLength: Int) { - val keyArray: UByteArray = key.hexStringToUByteArray() - val numberOf32BitWords = keyLength / 32 - - class Aes128Key(key: String) : InternalAesKey(key, 128) - class Aes192Key(key: String) : InternalAesKey(key, 192) - class Aes256Key(key: String) : InternalAesKey(key, 256) - - init { - checkKeyLength(key, keyLength) - } - - fun checkKeyLength(key: String, expectedLength: Int) { - if ((key.length / 2) != expectedLength / 8) { - throw RuntimeException("Invalid key length") - } - } -} - diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCbcPure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCbcPure.kt deleted file mode 100644 index ae9acbd..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCbcPure.kt +++ /dev/null @@ -1,243 +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.symmetric - -import com.ionspin.kotlin.crypto.SRNG -import com.ionspin.kotlin.crypto.util.xor - -/** - * Advanced encryption standard with cipher block chaining and PKCS #5 - * - * For bulk encryption/decryption use [AesCbcPure.encrypt] and [AesCbcPure.decrypt] - * - * To get an instance of AesCbc and then feed it data sequentially with [addData] use [createEncryptor] and [createDecryptor] - * - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ - -internal class AesCbcPure internal constructor(val aesKey: InternalAesKey, val mode: Mode, initializationVector: UByteArray? = null) { - - companion object { - const val BLOCK_BYTES = 16 - /** - * Creates and returns AesCbc instance that can be fed data using [addData]. Once you have submitted all - * data call [encrypt] - */ - fun createEncryptor(aesKey: InternalAesKey) : AesCbcPure { - return AesCbcPure(aesKey, Mode.ENCRYPT) - } - /** - * Creates and returns AesCbc instance that can be fed data using [addData]. Once you have submitted all - * data call [decrypt] - */ - fun createDecryptor(aesKey : InternalAesKey) : AesCbcPure { - return AesCbcPure(aesKey, Mode.DECRYPT) - } - - /** - * Bulk encryption, returns encrypted data and a random initialization vector - */ - fun encrypt(aesKey: InternalAesKey, data: UByteArray): EncryptedDataAndInitializationVector { - val aesCbc = AesCbcPure(aesKey, Mode.ENCRYPT) - aesCbc.addData(data) - return aesCbc.encrypt() - } - - /** - * Bulk decryption, returns decrypted data - */ - fun decrypt(aesKey: InternalAesKey, data: UByteArray, initialCounter: UByteArray? = null): UByteArray { - val aesCbc = AesCbcPure(aesKey, Mode.DECRYPT, initialCounter) - aesCbc.addData(data) - return aesCbc.decrypt() - } - - private fun padToBlock(unpadded: UByteArray): UByteArray { - val paddingSize = 16 - unpadded.size - if (unpadded.size == BLOCK_BYTES) { - return unpadded - } - - if (unpadded.size == BLOCK_BYTES) { - return UByteArray(BLOCK_BYTES) { - BLOCK_BYTES.toUByte() - } - } - - if (unpadded.size > BLOCK_BYTES) { - throw IllegalStateException("Block larger than 128 bytes") - } - - return UByteArray(BLOCK_BYTES) { - when (it) { - in unpadded.indices -> unpadded[it] - else -> paddingSize.toUByte() - } - } - - } - } - - var currentOutput: UByteArray = ubyteArrayOf() - var previousEncrypted: UByteArray = ubyteArrayOf() - val initVector = if (initializationVector.isNullOrEmpty()) { - SRNG.getRandomBytes(16) - } else { - initializationVector - } - - val output = MutableList(0) { ubyteArrayOf() } - - var buffer: UByteArray = UByteArray(16) { 0U } - var bufferCounter = 0 - - fun addData(data: UByteArray) { - //Padding - when { - bufferCounter + data.size < BLOCK_BYTES -> appendToBuffer(data, bufferCounter) - bufferCounter + data.size >= BLOCK_BYTES -> { - val chunked = data.chunked(BLOCK_BYTES) - chunked.forEach { chunk -> - if (bufferCounter + chunk.size < BLOCK_BYTES) { - appendToBuffer(chunk.toUByteArray(), bufferCounter) - } else { - chunk.toUByteArray().copyInto( - destination = buffer, - destinationOffset = bufferCounter, - startIndex = 0, - endIndex = BLOCK_BYTES - bufferCounter - ) - output += consumeBlock(buffer) - buffer = UByteArray(BLOCK_BYTES) { - when (it) { - in (0 until (chunk.size - (BLOCK_BYTES - bufferCounter))) -> { - chunk[it + (BLOCK_BYTES - bufferCounter)] - } - else -> { - 0U - } - } - - } - bufferCounter = chunk.size - (BLOCK_BYTES - bufferCounter) - } - } - - } - } - - } - - /** - * Encrypt fed data and return it alongside the randomly chosen initialization vector. - * This also applies correct PKCS#7 padding - * @return Encrypted data and initialization vector - */ - fun encrypt(): EncryptedDataAndInitializationVector { - if (bufferCounter > 0) { - val lastBlockPadded = padToBlock(buffer) - if (lastBlockPadded.size > BLOCK_BYTES) { - val chunks = lastBlockPadded.chunked(BLOCK_BYTES).map { it.toUByteArray() } - output += consumeBlock(chunks[0]) - output += consumeBlock(chunks[1]) - } else { - output += consumeBlock(lastBlockPadded) - } - } else { - output += consumeBlock(UByteArray(BLOCK_BYTES) { BLOCK_BYTES.toUByte()}) - } - return EncryptedDataAndInitializationVector( - output.reversed().foldRight(UByteArray(0) { 0U }) { arrayOfUBytes, acc -> acc + arrayOfUBytes }, - initVector - ) - } - - /** - * Decrypt data - * @return Decrypted data - */ - fun decrypt(): UByteArray { - val removePaddingCount = output.last().last() - - val removedPadding = if (removePaddingCount > 0U && removePaddingCount < 16U) { - output.last().dropLast(removePaddingCount.toInt() and 0x7F) - } else { - ubyteArrayOf() - }.toUByteArray() - val preparedOutput = (output.dropLast(1) + listOf(removedPadding)) - //JS compiler freaks out here if we don't supply exact type - val reversed : List = preparedOutput.reversed() as List - val folded : UByteArray = reversed.foldRight(UByteArray(0) { 0U }) { uByteArray, acc -> - acc + uByteArray - } - return folded - - } - - private fun appendToBuffer(array: UByteArray, start: Int) { - array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size) - bufferCounter += array.size - } - - private fun consumeBlock(data: UByteArray): UByteArray { - return when (mode) { - Mode.ENCRYPT -> { - currentOutput = if (currentOutput.isEmpty()) { - println("IV: $initVector") - AesPure.encrypt(aesKey, data xor initVector) - } else { - AesPure.encrypt(aesKey, data xor currentOutput) - } - currentOutput - } - Mode.DECRYPT -> { - if (currentOutput.isEmpty()) { - currentOutput = AesPure.decrypt(aesKey, data) xor initVector - } else { - currentOutput = AesPure.decrypt(aesKey, data) xor previousEncrypted - } - previousEncrypted = data - currentOutput - } - } - - } - -} - - -data class EncryptedDataAndInitializationVector(val encryptedData : UByteArray, val initializationVector : UByteArray) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || this::class != other::class) return false - - other as EncryptedDataAndInitializationVector - - if (!encryptedData.contentEquals(other.encryptedData)) return false - if (!initializationVector.contentEquals(other.initializationVector)) return false - - return true - } - - override fun hashCode(): Int { - var result = encryptedData.contentHashCode() - result = 31 * result + initializationVector.contentHashCode() - return result - } -} diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCtrPure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCtrPure.kt deleted file mode 100644 index 6b62b14..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCtrPure.kt +++ /dev/null @@ -1,209 +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.symmetric - -import com.ionspin.kotlin.bignum.Endianness -import com.ionspin.kotlin.bignum.integer.BigInteger -import com.ionspin.kotlin.bignum.integer.Sign -import com.ionspin.kotlin.bignum.modular.ModularBigInteger -import com.ionspin.kotlin.crypto.SRNG -import com.ionspin.kotlin.crypto.symmetric.AesCtrPure.Companion.encrypt -import com.ionspin.kotlin.crypto.util.xor - -/** - * - * Advanced encryption standard with counter mode - * - * For bulk encryption/decryption use [AesCtrPure.encrypt] and [AesCtrPure.decrypt] - * - * To get an instance of AesCtr and then feed it data sequentially with [addData] use [createEncryptor] and [createDecryptor] - * - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 22-Sep-2019 - */ - -internal class AesCtrPure internal constructor(val aesKey: InternalAesKey, val mode: Mode, initialCounter: UByteArray? = null) { - - companion object { - const val BLOCK_BYTES = 16 - - val modularCreator = ModularBigInteger.creatorForModulo(BigInteger.ONE.shl(128) - 1) - /** - * Creates and returns AesCtr instance that can be fed data using [addData]. Once you have submitted all - * data call [encrypt] - */ - fun createEncryptor(aesKey: InternalAesKey) : AesCtrPure { - return AesCtrPure(aesKey, Mode.ENCRYPT) - } - /** - * Creates and returns AesCtr instance that can be fed data using [addData]. Once you have submitted all - * data call [decrypt] - */ - fun createDecryptor(aesKey : InternalAesKey, initialCounter: UByteArray) : AesCtrPure { - return AesCtrPure(aesKey, Mode.DECRYPT, initialCounter) - } - /** - * Bulk encryption, returns encrypted data and a random initial counter - */ - fun encrypt(aesKey: InternalAesKey, data: UByteArray): EncryptedDataAndInitialCounter { - val aesCtr = AesCtrPure(aesKey, Mode.ENCRYPT) - aesCtr.addData(data) - return aesCtr.encrypt() - } - /** - * Bulk decryption, returns decrypted data - */ - fun decrypt(aesKey: InternalAesKey, data: UByteArray, initialCounter: UByteArray? = null): UByteArray { - val aesCtr = AesCtrPure(aesKey = aesKey, mode = Mode.DECRYPT, initialCounter = initialCounter) - aesCtr.addData(data) - return aesCtr.decrypt() - } - - } - - var currentOutput: UByteArray = ubyteArrayOf() - var previousEncrypted: UByteArray = ubyteArrayOf() - val counterStart = if (initialCounter.isNullOrEmpty()) { - SRNG.getRandomBytes(16) - } else { - initialCounter - } - var blockCounter = modularCreator.fromBigInteger(BigInteger.fromUByteArray(counterStart, Sign.POSITIVE)) - - val output = MutableList(0) { ubyteArrayOf() } - - var buffer: UByteArray = UByteArray(16) { 0U } - var bufferCounter = 0 - - fun addData(data: UByteArray) { - //Padding - when { - bufferCounter + data.size < BLOCK_BYTES -> appendToBuffer(data, bufferCounter) - bufferCounter + data.size >= BLOCK_BYTES -> { - val chunked = data.chunked(BLOCK_BYTES) - chunked.forEach { chunk -> - if (bufferCounter + chunk.size < BLOCK_BYTES) { - appendToBuffer(chunk.toUByteArray(), bufferCounter) - } else { - chunk.toUByteArray().copyInto( - destination = buffer, - destinationOffset = bufferCounter, - startIndex = 0, - endIndex = BLOCK_BYTES - bufferCounter - ) - output += consumeBlock(buffer, blockCounter) - blockCounter += 1 - buffer = UByteArray(BLOCK_BYTES) { - when (it) { - in (0 until (chunk.size - (BLOCK_BYTES - bufferCounter))) -> { - chunk[it + (BLOCK_BYTES - bufferCounter)] - } - else -> { - 0U - } - } - - } - bufferCounter = chunk.size - (BLOCK_BYTES - bufferCounter) - } - } - - } - } - - } - /** - * Encrypt fed data and return it alongside the randomly chosen initial counter state - * @return Encrypted data and initial counter state - */ - fun encrypt(): EncryptedDataAndInitialCounter { - if (bufferCounter > 0) { - output += consumeBlock(buffer, blockCounter) - } - return EncryptedDataAndInitialCounter( - output.reversed().foldRight(UByteArray(0) { 0U }) { arrayOfUBytes, acc -> acc + arrayOfUBytes }, - counterStart - ) - } - /** - * Decrypt data - * @return Decrypted data - */ - fun decrypt(): UByteArray { - if (bufferCounter > 0) { - output += consumeBlock(buffer, blockCounter) - } - //JS compiler freaks out here if we don't supply exact type - val reversed: List = output.reversed() as List - val folded: UByteArray = reversed.foldRight(UByteArray(0) { 0U }) { arrayOfUBytes, acc -> - acc + arrayOfUBytes - } - return folded - } - - private fun appendToBuffer(array: UByteArray, start: Int) { - array.copyInto(destination = buffer, destinationOffset = start, startIndex = 0, endIndex = array.size) - bufferCounter += array.size - } - - private fun consumeBlock(data: UByteArray, blockCount: ModularBigInteger): UByteArray { - val blockCountAsByteArray = blockCount.toUByteArray().expandCounterTo16Bytes() - return when (mode) { - Mode.ENCRYPT -> { - AesPure.encrypt(aesKey, blockCountAsByteArray) xor data - } - Mode.DECRYPT -> { - AesPure.encrypt(aesKey, blockCountAsByteArray) xor data - } - } - - } - - private fun UByteArray.expandCounterTo16Bytes() : UByteArray { - return if (this.size < 16) { - println("Expanding") - val diff = 16 - this.size - val pad = UByteArray(diff) { 0U } - pad + this - } else { - this - } - } - -} - -data class EncryptedDataAndInitialCounter(val encryptedData : UByteArray, val initialCounter : UByteArray) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || this::class != other::class) return false - - other as EncryptedDataAndInitialCounter - - if (!encryptedData.contentEquals(other.encryptedData)) return false - if (!initialCounter.contentEquals(other.initialCounter)) return false - - return true - } - - override fun hashCode(): Int { - var result = encryptedData.contentHashCode() - result = 31 * result + initialCounter.contentHashCode() - return result - } -} - diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesPure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesPure.kt deleted file mode 100644 index d20b8e4..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/AesPure.kt +++ /dev/null @@ -1,361 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.util.flattenToUByteArray - -/** - * Created by Ugljesa Jovanovic (jovanovic.ugljesa@gmail.com) on 07/Sep/2019 - */ - -internal class AesPure internal constructor(val aesKey: InternalAesKey, val input: UByteArray) { - companion object { - private val debug = false - - private val sBox: UByteArray = - ubyteArrayOf( - // @formatter:off - 0x63U, 0x7cU, 0x77U, 0x7bU, 0xf2U, 0x6bU, 0x6fU, 0xc5U, 0x30U, 0x01U, 0x67U, 0x2bU, 0xfeU, 0xd7U, 0xabU, 0x76U, - 0xcaU, 0x82U, 0xc9U, 0x7dU, 0xfaU, 0x59U, 0x47U, 0xf0U, 0xadU, 0xd4U, 0xa2U, 0xafU, 0x9cU, 0xa4U, 0x72U, 0xc0U, - 0xb7U, 0xfdU, 0x93U, 0x26U, 0x36U, 0x3fU, 0xf7U, 0xccU, 0x34U, 0xa5U, 0xe5U, 0xf1U, 0x71U, 0xd8U, 0x31U, 0x15U, - 0x04U, 0xc7U, 0x23U, 0xc3U, 0x18U, 0x96U, 0x05U, 0x9aU, 0x07U, 0x12U, 0x80U, 0xe2U, 0xebU, 0x27U, 0xb2U, 0x75U, - 0x09U, 0x83U, 0x2cU, 0x1aU, 0x1bU, 0x6eU, 0x5aU, 0xa0U, 0x52U, 0x3bU, 0xd6U, 0xb3U, 0x29U, 0xe3U, 0x2fU, 0x84U, - 0x53U, 0xd1U, 0x00U, 0xedU, 0x20U, 0xfcU, 0xb1U, 0x5bU, 0x6aU, 0xcbU, 0xbeU, 0x39U, 0x4aU, 0x4cU, 0x58U, 0xcfU, - 0xd0U, 0xefU, 0xaaU, 0xfbU, 0x43U, 0x4dU, 0x33U, 0x85U, 0x45U, 0xf9U, 0x02U, 0x7fU, 0x50U, 0x3cU, 0x9fU, 0xa8U, - 0x51U, 0xa3U, 0x40U, 0x8fU, 0x92U, 0x9dU, 0x38U, 0xf5U, 0xbcU, 0xb6U, 0xdaU, 0x21U, 0x10U, 0xffU, 0xf3U, 0xd2U, - 0xcdU, 0x0cU, 0x13U, 0xecU, 0x5fU, 0x97U, 0x44U, 0x17U, 0xc4U, 0xa7U, 0x7eU, 0x3dU, 0x64U, 0x5dU, 0x19U, 0x73U, - 0x60U, 0x81U, 0x4fU, 0xdcU, 0x22U, 0x2aU, 0x90U, 0x88U, 0x46U, 0xeeU, 0xb8U, 0x14U, 0xdeU, 0x5eU, 0x0bU, 0xdbU, - 0xe0U, 0x32U, 0x3aU, 0x0aU, 0x49U, 0x06U, 0x24U, 0x5cU, 0xc2U, 0xd3U, 0xacU, 0x62U, 0x91U, 0x95U, 0xe4U, 0x79U, - 0xe7U, 0xc8U, 0x37U, 0x6dU, 0x8dU, 0xd5U, 0x4eU, 0xa9U, 0x6cU, 0x56U, 0xf4U, 0xeaU, 0x65U, 0x7aU, 0xaeU, 0x08U, - 0xbaU, 0x78U, 0x25U, 0x2eU, 0x1cU, 0xa6U, 0xb4U, 0xc6U, 0xe8U, 0xddU, 0x74U, 0x1fU, 0x4bU, 0xbdU, 0x8bU, 0x8aU, - 0x70U, 0x3eU, 0xb5U, 0x66U, 0x48U, 0x03U, 0xf6U, 0x0eU, 0x61U, 0x35U, 0x57U, 0xb9U, 0x86U, 0xc1U, 0x1dU, 0x9eU, - 0xe1U, 0xf8U, 0x98U, 0x11U, 0x69U, 0xd9U, 0x8eU, 0x94U, 0x9bU, 0x1eU, 0x87U, 0xe9U, 0xceU, 0x55U, 0x28U, 0xdfU, - 0x8cU, 0xa1U, 0x89U, 0x0dU, 0xbfU, 0xe6U, 0x42U, 0x68U, 0x41U, 0x99U, 0x2dU, 0x0fU, 0xb0U, 0x54U, 0xbbU, 0x16U - // @formatter:on - ) - - private val inverseSBox: UByteArray = - ubyteArrayOf( - // @formatter:off - 0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U, 0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU, - 0x7cU, 0xe3U, 0x39U, 0x82U, 0x9bU, 0x2fU, 0xffU, 0x87U, 0x34U, 0x8eU, 0x43U, 0x44U, 0xc4U, 0xdeU, 0xe9U, 0xcbU, - 0x54U, 0x7bU, 0x94U, 0x32U, 0xa6U, 0xc2U, 0x23U, 0x3dU, 0xeeU, 0x4cU, 0x95U, 0x0bU, 0x42U, 0xfaU, 0xc3U, 0x4eU, - 0x08U, 0x2eU, 0xa1U, 0x66U, 0x28U, 0xd9U, 0x24U, 0xb2U, 0x76U, 0x5bU, 0xa2U, 0x49U, 0x6dU, 0x8bU, 0xd1U, 0x25U, - 0x72U, 0xf8U, 0xf6U, 0x64U, 0x86U, 0x68U, 0x98U, 0x16U, 0xd4U, 0xa4U, 0x5cU, 0xccU, 0x5dU, 0x65U, 0xb6U, 0x92U, - 0x6cU, 0x70U, 0x48U, 0x50U, 0xfdU, 0xedU, 0xb9U, 0xdaU, 0x5eU, 0x15U, 0x46U, 0x57U, 0xa7U, 0x8dU, 0x9dU, 0x84U, - 0x90U, 0xd8U, 0xabU, 0x00U, 0x8cU, 0xbcU, 0xd3U, 0x0aU, 0xf7U, 0xe4U, 0x58U, 0x05U, 0xb8U, 0xb3U, 0x45U, 0x06U, - 0xd0U, 0x2cU, 0x1eU, 0x8fU, 0xcaU, 0x3fU, 0x0fU, 0x02U, 0xc1U, 0xafU, 0xbdU, 0x03U, 0x01U, 0x13U, 0x8aU, 0x6bU, - 0x3aU, 0x91U, 0x11U, 0x41U, 0x4fU, 0x67U, 0xdcU, 0xeaU, 0x97U, 0xf2U, 0xcfU, 0xceU, 0xf0U, 0xb4U, 0xe6U, 0x73U, - 0x96U, 0xacU, 0x74U, 0x22U, 0xe7U, 0xadU, 0x35U, 0x85U, 0xe2U, 0xf9U, 0x37U, 0xe8U, 0x1cU, 0x75U, 0xdfU, 0x6eU, - 0x47U, 0xf1U, 0x1aU, 0x71U, 0x1dU, 0x29U, 0xc5U, 0x89U, 0x6fU, 0xb7U, 0x62U, 0x0eU, 0xaaU, 0x18U, 0xbeU, 0x1bU, - 0xfcU, 0x56U, 0x3eU, 0x4bU, 0xc6U, 0xd2U, 0x79U, 0x20U, 0x9aU, 0xdbU, 0xc0U, 0xfeU, 0x78U, 0xcdU, 0x5aU, 0xf4U, - 0x1fU, 0xddU, 0xa8U, 0x33U, 0x88U, 0x07U, 0xc7U, 0x31U, 0xb1U, 0x12U, 0x10U, 0x59U, 0x27U, 0x80U, 0xecU, 0x5fU, - 0x60U, 0x51U, 0x7fU, 0xa9U, 0x19U, 0xb5U, 0x4aU, 0x0dU, 0x2dU, 0xe5U, 0x7aU, 0x9fU, 0x93U, 0xc9U, 0x9cU, 0xefU, - 0xa0U, 0xe0U, 0x3bU, 0x4dU, 0xaeU, 0x2aU, 0xf5U, 0xb0U, 0xc8U, 0xebU, 0xbbU, 0x3cU, 0x83U, 0x53U, 0x99U, 0x61U, - 0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U, 0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU - // @formatter:on - ) - - val rcon: UByteArray = ubyteArrayOf(0x8DU, 0x01U, 0x02U, 0x04U, 0x08U, 0x10U, 0x20U, 0x40U, 0x80U, 0x1BU, 0x36U) - - fun encrypt(aesKey: InternalAesKey, input: UByteArray): UByteArray { - return AesPure(aesKey, input).encrypt() - } - - fun decrypt(aesKey: InternalAesKey, input: UByteArray): UByteArray { - return AesPure(aesKey, input).decrypt() - } - - } - - val state: Array = (0 until 4).map { outerCounter -> - UByteArray(4) { innerCounter -> input[innerCounter * 4 + outerCounter] } - }.toTypedArray() - - val numberOfRounds = when (aesKey) { - is InternalAesKey.Aes128Key -> 10 - is InternalAesKey.Aes192Key -> 12 - is InternalAesKey.Aes256Key -> 14 - } - - val expandedKey: Array = expandKey() - - - var round = 0 - var completed : Boolean = false - private set - - fun subBytes() { - state.forEachIndexed { indexRow, row -> - row.forEachIndexed { indexColumn, element -> - state[indexRow][indexColumn] = getSBoxValue(element) - } - } - } - - fun getSBoxValue(element: UByte): UByte { - val firstDigit = (element / 16U).toInt() - val secondDigit = (element % 16U).toInt() - return sBox[firstDigit * 16 + secondDigit] - } - - fun inverseSubBytes() { - state.forEachIndexed { indexRow, row -> - row.forEachIndexed { indexColumn, element -> - state[indexRow][indexColumn] = getInverseSBoxValue(element) - } - } - } - - fun getInverseSBoxValue(element: UByte): UByte { - val firstDigit = (element / 16U).toInt() - val secondDigit = (element % 16U).toInt() - return inverseSBox[firstDigit * 16 + secondDigit] - } - - fun shiftRows() { - state[0] = ubyteArrayOf(state[0][0], state[0][1], state[0][2], state[0][3]) - state[1] = ubyteArrayOf(state[1][1], state[1][2], state[1][3], state[1][0]) - state[2] = ubyteArrayOf(state[2][2], state[2][3], state[2][0], state[2][1]) - state[3] = ubyteArrayOf(state[3][3], state[3][0], state[3][1], state[3][2]) - } - - fun inversShiftRows() { - state[0] = ubyteArrayOf(state[0][0], state[0][1], state[0][2], state[0][3]) - state[1] = ubyteArrayOf(state[1][3], state[1][0], state[1][1], state[1][2]) - state[2] = ubyteArrayOf(state[2][2], state[2][3], state[2][0], state[2][1]) - state[3] = ubyteArrayOf(state[3][1], state[3][2], state[3][3], state[3][0]) - } - - fun mixColumns() { - val stateMixed: Array = (0 until 4).map { - UByteArray(4) { 0U } - }.toTypedArray() - for (c in 0..3) { - - stateMixed[0][c] = (2U gfm state[0][c]) xor (3U gfm state[1][c]) xor state[2][c] xor state[3][c] - stateMixed[1][c] = state[0][c] xor (2U gfm state[1][c]) xor (3U gfm state[2][c]) xor state[3][c] - stateMixed[2][c] = state[0][c] xor state[1][c] xor (2U gfm state[2][c]) xor (3U gfm state[3][c]) - stateMixed[3][c] = 3U gfm state[0][c] xor state[1][c] xor state[2][c] xor (2U gfm state[3][c]) - } - stateMixed.copyInto(state) - } - - fun inverseMixColumns() { - val stateMixed: Array = (0 until 4).map { - UByteArray(4) { 0U } - }.toTypedArray() - for (c in 0..3) { - stateMixed[0][c] = - (0x0eU gfm state[0][c]) xor (0x0bU gfm state[1][c]) xor (0x0dU gfm state[2][c]) xor (0x09U gfm state[3][c]) - stateMixed[1][c] = - (0x09U gfm state[0][c]) xor (0x0eU gfm state[1][c]) xor (0x0bU gfm state[2][c]) xor (0x0dU gfm state[3][c]) - stateMixed[2][c] = - (0x0dU gfm state[0][c]) xor (0x09U gfm state[1][c]) xor (0x0eU gfm state[2][c]) xor (0x0bU gfm state[3][c]) - stateMixed[3][c] = - (0x0bU gfm state[0][c]) xor (0x0dU gfm state[1][c]) xor (0x09U gfm state[2][c]) xor (0x0eU gfm state[3][c]) - } - stateMixed.copyInto(state) - } - - fun galoisFieldAdd(first: UByte, second: UByte): UByte { - return first xor second - } - - fun galoisFieldMultiply(first: UByte, second: UByte): UByte { - var result: UInt = 0U - var firstInt = first.toUInt() - var secondInt = second.toUInt() - var carry: UInt = 0U - for (i in 0..7) { - if (secondInt and 0x01U == 1U) { - result = result xor firstInt - } - carry = firstInt and 0x80U - firstInt = firstInt shl 1 - if (carry == 0x80U) { - firstInt = firstInt xor 0x001BU - } - secondInt = secondInt shr 1 - firstInt = firstInt and 0xFFU - } - return result.toUByte() - } - - fun addRoundKey() { - - for (i in 0 until 4) { - state[0][i] = state[0][i] xor expandedKey[round * 4 + i][0] - state[1][i] = state[1][i] xor expandedKey[round * 4 + i][1] - state[2][i] = state[2][i] xor expandedKey[round * 4 + i][2] - state[3][i] = state[3][i] xor expandedKey[round * 4 + i][3] - } - round++ - } - - fun inverseAddRoundKey() { - for (i in 0 until 4) { - state[0][i] = state[0][i] xor expandedKey[round * 4 + i][0] - state[1][i] = state[1][i] xor expandedKey[round * 4 + i][1] - state[2][i] = state[2][i] xor expandedKey[round * 4 + i][2] - state[3][i] = state[3][i] xor expandedKey[round * 4 + i][3] - } - round-- - } - - infix fun UInt.gfm(second: UByte): UByte { - return galoisFieldMultiply(this.toUByte(), second) - } - - fun expandKey(): Array { - val expandedKey = (0 until 4 * (numberOfRounds + 1)).map { - UByteArray(4) { 0U } - }.toTypedArray() - // First round - for (i in 0 until aesKey.numberOf32BitWords) { - expandedKey[i][0] = aesKey.keyArray[i * 4 + 0] - expandedKey[i][1] = aesKey.keyArray[i * 4 + 1] - expandedKey[i][2] = aesKey.keyArray[i * 4 + 2] - expandedKey[i][3] = aesKey.keyArray[i * 4 + 3] - } - - for (i in aesKey.numberOf32BitWords until 4 * (numberOfRounds + 1)) { - val temp = expandedKey[i - 1].copyOf() - if (i % aesKey.numberOf32BitWords == 0) { - //RotWord - val tempTemp = temp[0] - temp[0] = temp[1] - temp[1] = temp[2] - temp[2] = temp[3] - temp[3] = tempTemp - - //SubWord - temp[0] = getSBoxValue(temp[0]) - temp[1] = getSBoxValue(temp[1]) - temp[2] = getSBoxValue(temp[2]) - temp[3] = getSBoxValue(temp[3]) - - temp[0] = temp[0] xor rcon[i / aesKey.numberOf32BitWords] - - } else if (aesKey is InternalAesKey.Aes256Key && i % aesKey.numberOf32BitWords == 4) { - temp[0] = getSBoxValue(temp[0]) - temp[1] = getSBoxValue(temp[1]) - temp[2] = getSBoxValue(temp[2]) - temp[3] = getSBoxValue(temp[3]) - } - expandedKey[i] = expandedKey[i - aesKey.numberOf32BitWords].mapIndexed { index, it -> - it xor temp[index] - }.toUByteArray() - clearArray(temp) - } - return expandedKey - } - - fun encrypt(): UByteArray { - if (completed) { - throw RuntimeException("Encrypt can only be called once per Aes instance, since the state is cleared at the " + - "end of the operation") - } - printState() - addRoundKey() - printState() - for (i in 0 until numberOfRounds - 1) { - subBytes() - printState() - shiftRows() - printState() - mixColumns() - printState() - addRoundKey() - printState() - } - - subBytes() - printState() - shiftRows() - printState() - addRoundKey() - printState() - val transposedMatrix = (0 until 4).map { outerCounter -> - UByteArray(4) { 0U } - } - for (i in 0 until 4) { - for (j in 0 until 4) { - transposedMatrix[i][j] = state[j][i] - } - } - state.forEach { clearArray(it) } - completed = true - return transposedMatrix.flattenToUByteArray() - } - - fun decrypt(): UByteArray { - if (completed) { - throw RuntimeException("Decrypt can only be called once per Aes instance, since the state is cleared at the " + - "end of the operation") - } - round = numberOfRounds - printState() - inverseAddRoundKey() - printState() - for (i in 0 until numberOfRounds - 1) { - inversShiftRows() - printState() - inverseSubBytes() - printState() - inverseAddRoundKey() - printState() - inverseMixColumns() - printState() - } - - inversShiftRows() - printState() - inverseSubBytes() - printState() - inverseAddRoundKey() - printState() - - val transposedMatrix = (0 until 4).map { outerCounter -> - UByteArray(4) { 0U } - } - for (i in 0 until 4) { - for (j in 0 until 4) { - transposedMatrix[i][j] = state[j][i] - } - } - state.forEach { clearArray(it) } - completed = true - return transposedMatrix.flattenToUByteArray() - } - - private fun clearArray(array : UByteArray) { - array.indices.forEach { array[it] = 0U } - } - - - - private fun printState() { - if (!debug) { - return - } - println() - state.forEach { - println(it.joinToString(separator = " ") { it.toString(16) }) - } - } - - private fun printState(specific : List) { - if (!debug) { - return - } - println() - specific.forEach { - println(it.joinToString(separator = " ") { it.toString(16) }) - } - } - - -} - - - - diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/ChaCha20Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/ChaCha20Pure.kt deleted file mode 100644 index d475395..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/ChaCha20Pure.kt +++ /dev/null @@ -1,99 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.symmetric.LatinDancesCommon.littleEndianInverted -import com.ionspin.kotlin.crypto.util.* - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 16-Jun-2020 - */ -internal class ChaCha20Pure { - companion object { - fun quarterRound(input: UIntArray, aPosition: Int, bPosition: Int, cPosition: Int, dPosition: Int) { - input[aPosition] += input[bPosition] - input[dPosition] = input[dPosition] xor input[aPosition] - input[dPosition] = input[dPosition] rotateLeft 16 - - input[cPosition] += input[dPosition] - input[bPosition] = input[bPosition] xor input[cPosition] - input[bPosition] = input[bPosition] rotateLeft 12 - - input[aPosition] += input[bPosition] - input[dPosition] = input[dPosition] xor input[aPosition] - input[dPosition] = input[dPosition] rotateLeft 8 - - input[cPosition] += input[dPosition] - input[bPosition] = input[bPosition] xor input[cPosition] - input[bPosition] = input[bPosition] rotateLeft 7 - } - - fun doubleRound(input: UIntArray) { - quarterRound(input, 0, 4, 8, 12) - quarterRound(input, 1, 5, 9, 13) - quarterRound(input, 2, 6, 10, 14) - quarterRound(input, 3, 7, 11, 15) - - quarterRound(input, 0, 5, 10, 15) - quarterRound(input, 1, 6, 11, 12) - quarterRound(input, 2, 7, 8, 13) - quarterRound(input, 3, 4, 9, 14) - } - - fun hash(initialState: UIntArray): UByteArray { - val state = initialState.copyOf() - for (i in 0 until 10) { - doubleRound(state) - } - val result = UByteArray(64) - for (i in 0 until 16) { - littleEndianInverted(initialState[i] + state[i], result, i * 4) - } - return result - } - - val sigma0_32 = 1634760805U //ubyteArrayOf(101U, 120U, 112U, 97U) - val sigma1_32 = 857760878U //ubyteArrayOf(110U, 100U, 32U, 51U) - val sigma2_32 = 2036477234U //ubyteArrayOf(50U, 45U, 98U, 121U) - val sigma3_32 = 1797285236U //ubyteArrayOf(116U, 101U, 32U, 107U) - - fun xorWithKeystream(key: UByteArray, nonce: UByteArray, message: UByteArray, initialCounter: UInt): UByteArray { - val ciphertext = UByteArray(message.size) - val state = UIntArray(16) { - when (it) { - 0 -> sigma0_32 - 1 -> sigma1_32 - 2 -> sigma2_32 - 3 -> sigma3_32 - 4 -> key.fromLittleEndianArrayToUIntWithPosition(0) - 5 -> key.fromLittleEndianArrayToUIntWithPosition(4) - 6 -> key.fromLittleEndianArrayToUIntWithPosition(8) - 7 -> key.fromLittleEndianArrayToUIntWithPosition(12) - 8 -> key.fromLittleEndianArrayToUIntWithPosition(16) - 9 -> key.fromLittleEndianArrayToUIntWithPosition(20) - 10 -> key.fromLittleEndianArrayToUIntWithPosition(24) - 11 -> key.fromLittleEndianArrayToUIntWithPosition(28) - 12 -> initialCounter - 13 -> nonce.fromLittleEndianArrayToUIntWithPosition(0) - 14 -> nonce.fromLittleEndianArrayToUIntWithPosition(4) - 15 -> nonce.fromLittleEndianArrayToUIntWithPosition(8) - else -> 0U - } - } - val blocks = message.size / 64 - val remainder = message.size % 64 - for (i in 0 until blocks) { - hash(state).xorWithPositionsAndInsertIntoArray(0, 64, message, i * 64, ciphertext, i * 64) - state[12] += 1U - } - - hash(state).xorWithPositionsAndInsertIntoArray( - 0, remainder, - message, blocks * 64, - ciphertext, blocks * 64 - ) - state.overwriteWithZeroes() - return ciphertext - } - } -} diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/LatinDancesCommon.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/LatinDancesCommon.kt deleted file mode 100644 index 202cf62..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/LatinDancesCommon.kt +++ /dev/null @@ -1,55 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 16-Jun-2020 - */ - - - - -object LatinDancesCommon { - - val _emitIntArray: IntArray = intArrayOf(1) - - fun littleEndian( - input: UByteArray, - byte0Position: Int, - byte1Position: Int, - byte2Position: Int, - byte3Position: Int - ): UInt { - var uint = 0U - uint = input[byte0Position].toUInt() - uint = uint or (input[byte1Position].toUInt() shl 8) - uint = uint or (input[byte2Position].toUInt() shl 16) - uint = uint or (input[byte3Position].toUInt() shl 24) - - return uint - } - - fun littleEndianInverted( - input: UIntArray, - startingPosition: Int, - output: UByteArray, - outputPosition: Int - ) { - output[outputPosition] = (input[startingPosition] and 0xFFU).toUByte() - output[outputPosition + 1] = ((input[startingPosition] shr 8) and 0xFFU).toUByte() - output[outputPosition + 2] = ((input[startingPosition] shr 16) and 0xFFU).toUByte() - output[outputPosition + 3] = ((input[startingPosition] shr 24) and 0xFFU).toUByte() - } - - fun littleEndianInverted( - input: UInt, - output: UByteArray, - outputPosition: Int - ) { - output[outputPosition] = (input and 0xFFU).toUByte() - output[outputPosition + 1] = ((input shr 8) and 0xFFU).toUByte() - output[outputPosition + 2] = ((input shr 16) and 0xFFU).toUByte() - output[outputPosition + 3] = ((input shr 24) and 0xFFU).toUByte() - } - -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Salsa20Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Salsa20Pure.kt deleted file mode 100644 index 2fc3761..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Salsa20Pure.kt +++ /dev/null @@ -1,122 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.symmetric.LatinDancesCommon.littleEndianInverted -import com.ionspin.kotlin.crypto.util.* - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jun-2020 - */ -internal class Salsa20Pure { - companion object { - fun quarterRound(input: UIntArray, y0position: Int, y1position: Int, y2position: Int, y3position: Int) { - input[y1position] = input[y1position] xor ((input[y0position] + input[y3position]) rotateLeft 7) - input[y2position] = input[y2position] xor ((input[y1position] + input[y0position]) rotateLeft 9) - input[y3position] = input[y3position] xor ((input[y2position] + input[y1position]) rotateLeft 13) - input[y0position] = input[y0position] xor ((input[y3position] + input[y2position]) rotateLeft 18) - } - - fun rowRound(input: UIntArray) { - quarterRound(input, 0, 1, 2, 3) - quarterRound(input, 5, 6, 7, 4) - quarterRound(input, 10, 11, 8, 9) - quarterRound(input, 15, 12, 13, 14) - } - - fun columnRound(input: UIntArray) { - quarterRound(input, 0, 4, 8, 12) - quarterRound(input, 5, 9, 13, 1) - quarterRound(input, 10, 14, 2, 6) - quarterRound(input, 15, 3, 7, 11) - } - - fun doubleRound(input: UIntArray) { - columnRound(input) - rowRound(input) - } - - - - fun hash(initialState: UIntArray): UByteArray { - val state = initialState.copyOf() - for (i in 0 until 10) { - doubleRound(state) - } - val result = UByteArray(64) - for (i in 0 until 16) { - littleEndianInverted(initialState[i] + state[i], result, i * 4) - } - return result - } - - internal var sigma0_32_uint = 1634760805U //ubyteArrayOf(101U, 120U, 112U, 97U) - internal var sigma1_32_uint = 857760878U //ubyteArrayOf(110U, 100U, 32U, 51U) - internal var sigma2_32_uint = 2036477234U //ubyteArrayOf(50U, 45U, 98U, 121U) - internal var sigma3_32_uint = 1797285236U //ubyteArrayOf(116U, 101U, 32U, 107U) - - val sigma0_32 = ubyteArrayOf(101U, 120U, 112U, 97U) - val sigma1_32 = ubyteArrayOf(110U, 100U, 32U, 51U) - val sigma2_32 = ubyteArrayOf(50U, 45U, 98U, 121U) - val sigma3_32 = ubyteArrayOf(116U, 101U, 32U, 107U) - - val tau0_16 = ubyteArrayOf(101U, 120U, 112U, 97U) - val tau1_16 = ubyteArrayOf(110U, 100U, 32U, 49U) - val tau2_16 = ubyteArrayOf(54U, 45U, 98U, 121U) - val tau3_16 = ubyteArrayOf(116U, 101U, 32U, 107U) - - fun expansion16(k: UByteArray, n: UByteArray) : UByteArray { - return hash((tau0_16 + k + tau1_16 + n + tau2_16 + k + tau3_16).fromLittleEndianToUInt()) - } - - fun expansion32(key :UByteArray, nonce : UByteArray) : UByteArray { - return hash((sigma0_32 + key.slice(0 until 16) + sigma1_32 + nonce + sigma2_32 + key.slice(16 until 32) + sigma3_32).fromLittleEndianToUInt()) - } - - fun encrypt(key : UByteArray, nonce: UByteArray, message: UByteArray) : UByteArray { - val ciphertext = UByteArray(message.size) - val state = UIntArray(16) { - when (it) { - 0 -> sigma0_32_uint - 1 -> key.fromLittleEndianArrayToUIntWithPosition(0) - 2 -> key.fromLittleEndianArrayToUIntWithPosition(4) - 3 -> key.fromLittleEndianArrayToUIntWithPosition(8) - 4 -> key.fromLittleEndianArrayToUIntWithPosition(12) - 5 -> sigma1_32_uint - 6 -> nonce.fromLittleEndianArrayToUIntWithPosition(0) - 7 -> nonce.fromLittleEndianArrayToUIntWithPosition(4) - 8 -> 0U - 9 -> 0U - 10 -> sigma2_32_uint - 11 -> key.fromLittleEndianArrayToUIntWithPosition(16) - 12 -> key.fromLittleEndianArrayToUIntWithPosition(20) - 13 -> key.fromLittleEndianArrayToUIntWithPosition(24) - 14 -> key.fromLittleEndianArrayToUIntWithPosition(28) - 15 -> sigma3_32_uint - else -> 0U - } - } - val blocks = message.size / 64 - val remainder = message.size % 64 - for (i in 0 until blocks) { - hash(state).xorWithPositionsAndInsertIntoArray(0, 64, message, i * 64, ciphertext, i * 64) - state[8] += 1U - if (state[8] == 0U) { - state[9] += 1U - } - } - - hash(state).xorWithPositionsAndInsertIntoArray( - 0, remainder, - message, blocks * 64, - ciphertext, blocks * 64) - state.overwriteWithZeroes() - return ciphertext - } - - fun decrypt(key : UByteArray, nonce: UByteArray, ciphertext: UByteArray) : UByteArray { - return encrypt(key, nonce, ciphertext) - } - } - -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/XChaCha20Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/XChaCha20Pure.kt deleted file mode 100644 index 5631cbd..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/XChaCha20Pure.kt +++ /dev/null @@ -1,179 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToUIntWithPosition -import com.ionspin.kotlin.crypto.util.overwriteWithZeroes -import com.ionspin.kotlin.crypto.util.xorWithPositionsAndInsertIntoArray - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jun-2020 - */ -class XChaCha20Pure(key: UByteArray, nonce: UByteArray, initialCounter: UInt = 0U) { - companion object { - - fun hChacha(key: UByteArray, nonce: UByteArray) : UIntArray { - val state = UIntArray(16) { - when (it) { - 0 -> ChaCha20Pure.sigma0_32 - 1 -> ChaCha20Pure.sigma1_32 - 2 -> ChaCha20Pure.sigma2_32 - 3 -> ChaCha20Pure.sigma3_32 - 4 -> key.fromLittleEndianArrayToUIntWithPosition(0) - 5 -> key.fromLittleEndianArrayToUIntWithPosition(4) - 6 -> key.fromLittleEndianArrayToUIntWithPosition(8) - 7 -> key.fromLittleEndianArrayToUIntWithPosition(12) - 8 -> key.fromLittleEndianArrayToUIntWithPosition(16) - 9 -> key.fromLittleEndianArrayToUIntWithPosition(20) - 10 -> key.fromLittleEndianArrayToUIntWithPosition(24) - 11 -> key.fromLittleEndianArrayToUIntWithPosition(28) - 12 -> nonce.fromLittleEndianArrayToUIntWithPosition(0) - 13 -> nonce.fromLittleEndianArrayToUIntWithPosition(4) - 14 -> nonce.fromLittleEndianArrayToUIntWithPosition(8) - 15 -> nonce.fromLittleEndianArrayToUIntWithPosition(12) - else -> 0U - } - } - for (i in 0 until 10) { - ChaCha20Pure.doubleRound(state) - } - - val result = UIntArray(8) { - when (it) { - 0 -> state[0] - 1 -> state[1] - 2 -> state[2] - 3 -> state[3] - 4 -> state[12] - 5 -> state[13] - 6 -> state[14] - 7 -> state[15] - else -> throw RuntimeException("Invalid index $it") - } - } - return result - - } - - fun xorWithKeystream(key: UByteArray, nonce: UByteArray, message: UByteArray, initialCounter: UInt = 0U): UByteArray { - - val ciphertext = UByteArray(message.size) - val hChaChaKey = hChacha(key, nonce) - val state = UIntArray(16) { - when (it) { - 0 -> ChaCha20Pure.sigma0_32 - 1 -> ChaCha20Pure.sigma1_32 - 2 -> ChaCha20Pure.sigma2_32 - 3 -> ChaCha20Pure.sigma3_32 - 4 -> hChaChaKey[0] - 5 -> hChaChaKey[1] - 6 -> hChaChaKey[2] - 7 -> hChaChaKey[3] - 8 -> hChaChaKey[4] - 9 -> hChaChaKey[5] - 10 -> hChaChaKey[6] - 11 -> hChaChaKey[7] - 12 -> initialCounter - 13 -> 0U - 14 -> nonce.fromLittleEndianArrayToUIntWithPosition(16) - 15 -> nonce.fromLittleEndianArrayToUIntWithPosition(20) - else -> 0U - } - } - hChaChaKey.overwriteWithZeroes() - val blocks = message.size / 64 - val remainder = message.size % 64 - for (i in 0 until blocks) { - ChaCha20Pure.hash(state).xorWithPositionsAndInsertIntoArray(0, 64, message, i * 64, ciphertext, i * 64) - state[12] += 1U - if (state[12] == 0U) { - state[13] += 1U - } - } - ChaCha20Pure.hash(state).xorWithPositionsAndInsertIntoArray( - 0, remainder, - message, blocks * 64, - ciphertext, blocks * 64 - ) - state.overwriteWithZeroes() - return ciphertext - } - - } - - val state: UIntArray - val keystreamBuffer = UByteArray(64) { 0U} - var keystreamRemainingCounter = 0 - var processedBytesSoFar = 0 - - init { - val hChaChaKey = hChacha(key, nonce) - state = UIntArray(16) { - when (it) { - 0 -> ChaCha20Pure.sigma0_32 - 1 -> ChaCha20Pure.sigma1_32 - 2 -> ChaCha20Pure.sigma2_32 - 3 -> ChaCha20Pure.sigma3_32 - 4 -> hChaChaKey[0] - 5 -> hChaChaKey[1] - 6 -> hChaChaKey[2] - 7 -> hChaChaKey[3] - 8 -> hChaChaKey[4] - 9 -> hChaChaKey[5] - 10 -> hChaChaKey[6] - 11 -> hChaChaKey[7] - 12 -> initialCounter - 13 -> 0U - 14 -> nonce.fromLittleEndianArrayToUIntWithPosition(16) - 15 -> nonce.fromLittleEndianArrayToUIntWithPosition(20) - else -> 0U - } - } - hChaChaKey.overwriteWithZeroes() - } - - fun xorWithKeystream(data: UByteArray) : UByteArray { - val ciphertext = UByteArray(data.size) { 0U } - //First use remaining keystream - var processedBytes = 0 - if (data.size > keystreamRemainingCounter) { - keystreamBuffer.xorWithPositionsAndInsertIntoArray( - 64 - keystreamRemainingCounter, 64, - data, 0, - ciphertext, 0 - ) - processedBytes += keystreamRemainingCounter - keystreamRemainingCounter = 0 - } - //Then do full blocks - var remainingBytes = data.size - processedBytes - for (i in 0 until remainingBytes / 64) { - ChaCha20Pure.hash(state).xorWithPositionsAndInsertIntoArray( - 0, 64, - data, processedBytes, - ciphertext, processedBytes - ) - state[12] += 1U - if (state[12] == 0U) { - state[13] += 1U - } - processedBytes += 64 - } - //Then do the remainder that didn't fit into 64byte blocks - remainingBytes = data.size - processedBytes - ChaCha20Pure.hash(state).copyInto(keystreamBuffer) - state[12] += 1U - if (state[12] == 0U) { - state[13] += 1U - } - keystreamBuffer.xorWithPositionsAndInsertIntoArray( - 0, remainingBytes, - data, processedBytes, - ciphertext, processedBytes - ) - keystreamRemainingCounter = 64 - remainingBytes - processedBytesSoFar += data.size - return ciphertext - } - -} diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/XSalsa20Pure.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/XSalsa20Pure.kt deleted file mode 100644 index ca83a60..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/XSalsa20Pure.kt +++ /dev/null @@ -1,105 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToUInt -import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToUIntWithPosition -import com.ionspin.kotlin.crypto.util.overwriteWithZeroes -import com.ionspin.kotlin.crypto.util.xorWithPositionsAndInsertIntoArray - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 16-Jun-2020 - */ -internal class XSalsa20Pure { - companion object { - fun hSalsa(key: UByteArray, nonce: UByteArray): UIntArray { - val state = UIntArray(16) { - when (it) { - 0 -> Salsa20Pure.sigma0_32.fromLittleEndianArrayToUInt() - 1 -> key.fromLittleEndianArrayToUIntWithPosition(0) - 2 -> key.fromLittleEndianArrayToUIntWithPosition(4) - 3 -> key.fromLittleEndianArrayToUIntWithPosition(8) - 4 -> key.fromLittleEndianArrayToUIntWithPosition(12) - 5 -> Salsa20Pure.sigma1_32.fromLittleEndianArrayToUInt() - 6 -> nonce.fromLittleEndianArrayToUIntWithPosition(0) - 7 -> nonce.fromLittleEndianArrayToUIntWithPosition(4) - 8 -> nonce.fromLittleEndianArrayToUIntWithPosition(8) - 9 -> nonce.fromLittleEndianArrayToUIntWithPosition(12) - 10 -> Salsa20Pure.sigma2_32.fromLittleEndianArrayToUInt() - 11 -> key.fromLittleEndianArrayToUIntWithPosition(16) - 12 -> key.fromLittleEndianArrayToUIntWithPosition(20) - 13 -> key.fromLittleEndianArrayToUIntWithPosition(24) - 14 -> key.fromLittleEndianArrayToUIntWithPosition(28) - 15 -> Salsa20Pure.sigma3_32.fromLittleEndianArrayToUInt() - else -> throw RuntimeException("Invalid index $it") - } - } - for (i in 0 until 10) { - Salsa20Pure.doubleRound(state) - } - val result = UIntArray(8) { - when (it) { - 0 -> state[0] - 1 -> state[5] - 2 -> state[10] - 3 -> state[15] - 4 -> state[6] - 5 -> state[7] - 6 -> state[8] - 7 -> state[9] - else -> throw RuntimeException("Invalid index $it") - } - } - return result - - } - - fun encrypt(key: UByteArray, nonce: UByteArray, message: UByteArray): UByteArray { - if (nonce.size != 24) { - throw RuntimeException("Invalid nonce size. required 192 bits, got ${nonce.size * 8}") - } - val ciphertext = UByteArray(message.size) - val hSalsaKey = hSalsa(key, nonce) - val state = UIntArray(16) { - when (it) { - 0 -> Salsa20Pure.sigma0_32_uint - 1 -> hSalsaKey[0] - 2 -> hSalsaKey[1] - 3 -> hSalsaKey[2] - 4 -> hSalsaKey[3] - 5 -> Salsa20Pure.sigma1_32_uint - 6 -> nonce.fromLittleEndianArrayToUIntWithPosition(16) //Last 63 bit of 192 bit nonce - 7 -> nonce.fromLittleEndianArrayToUIntWithPosition(20) - 8 -> 0U - 9 -> 0U - 10 -> Salsa20Pure.sigma2_32_uint - 11 -> hSalsaKey[4] - 12 -> hSalsaKey[5] - 13 -> hSalsaKey[6] - 14 -> hSalsaKey[7] - 15 -> Salsa20Pure.sigma3_32_uint - else -> 0U - } - } - hSalsaKey.overwriteWithZeroes() - val blocks = message.size / 64 - val remainder = message.size % 64 - for (i in 0 until blocks) { - Salsa20Pure.hash(state).xorWithPositionsAndInsertIntoArray(0, 64, message, i * 64, ciphertext, i * 64) - state[8] += 1U - if (state[8] == 0U) { - state[9] += 1U - } - } - - Salsa20Pure.hash(state).xorWithPositionsAndInsertIntoArray( - 0, remainder, - message, blocks * 64, - ciphertext, blocks * 64) - state.overwriteWithZeroes() - return ciphertext - } - - } - -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/util/Util.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/util/Util.kt deleted file mode 100644 index 1dc57f9..0000000 --- a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/util/Util.kt +++ /dev/null @@ -1,304 +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. - */ - -@file:Suppress("EXPERIMENTAL_API_USAGE") - -package com.ionspin.kotlin.crypto.util - -//TODO Reorganize this, currently it's just a pile of useful helper functions - -val _emitIntArray: IntArray = intArrayOf(1) -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 15-Jul-2019 - */ - -inline fun Array.chunked(sliceSize: Int): Array> { - val last = this.size % sliceSize - val hasLast = last != 0 - val numberOfSlices = this.size / sliceSize - - - val result : MutableList> = MutableList>(0) { emptyList() } - - for (i in 0 until numberOfSlices) { - result.add(this.slice(i * sliceSize until (i + 1) * sliceSize)) - } - if (hasLast) { - result.add(this.slice(numberOfSlices * sliceSize until this.size)) - } - - return result.map { it.toTypedArray() }.toTypedArray() - -} - - -infix fun UInt.rotateRight(places: Int): UInt { - return (this shr places) xor (this shl (32 - places)) -} - - -infix fun ULong.rotateRight(places: Int): ULong { - return (this shr places) xor (this shl (64 - places)) -} - -infix fun UInt.rotateLeft(places: Int): UInt { - return (this shl places) xor (this shr (32 - places)) -} - - -infix fun ULong.rotateLeft(places: Int): ULong { - return (this shl places) xor (this shr (64 - places)) -} - -infix fun Array.xor(other : Array) : Array { - if (this.size != other.size) { - throw RuntimeException("Operands of different sizes are not supported yet") - } - return Array(this.size) { this[it] xor other[it] } -} - - -infix fun UByteArray.xor(other : UByteArray) : UByteArray { - if (this.size != other.size) { - throw RuntimeException("Operands of different sizes are not supported yet") - } - return UByteArray(this.size) { this[it] xor other[it] } -} - -fun UByteArray.xorWithPositions(start: Int, end: Int, other : UByteArray, otherStart: Int) : UByteArray { - return UByteArray(end - start) { this[start + it] xor other[otherStart + it] } -} - -/** - * Start index is included, end index is excluded - */ -fun UByteArray.xorWithPositionsAndInsertIntoArray( - start: Int, end: Int, - other : UByteArray, otherStart: Int, - targetArray: UByteArray, targetStart : Int -) { - val length = end - start - for (i in 0 until length) { - targetArray[targetStart + i] = this[start + i] xor other[otherStart + i] - } -} - -// UInt / Array utils - -fun UInt.toBigEndianUByteArray() : Array { - return Array (4) { - ((this shr (24 - (it * 8))) and 0xFFU).toUByte() - } -} - -fun UInt.toLittleEndianTypedUByteArray() : Array { - return Array (4) { - ((this shr (it * 8)) and 0xFFU).toUByte() - } -} - - -fun UInt.toLittleEndianUByteArray() : UByteArray { - return UByteArray (4) { - ((this shr (it * 8)) and 0xFFU).toUByte() - } -} - - -fun UIntArray.toLittleEndianUByteArray() : UByteArray { - val result = UByteArray(size * 4) - for (i in 0 until size) { - val converted = this[i].toLittleEndianUByteArray() - result[i * 4] = converted[0] - result[i * 4 + 1] = converted[1] - result[i * 4 + 2] = converted[2] - result[i * 4 + 3] = converted[3] - } - return result -} - -// UInt / Array utils - -fun ULong.toBigEndianUByteArray() : Array { - return Array (8) { - ((this shr (56 - (it * 8))) and 0xFFU).toUByte() - } -} - -fun ULong.toLittleEndianTypedUByteArray() : Array { - return Array (8) { - ((this shr (it * 8)) and 0xFFU).toUByte() - } -} - - -fun ULong.toLittleEndianUByteArray() :UByteArray { - return UByteArray (8) { - ((this shr (it * 8)) and 0xFFU).toUByte() - } -} - - -fun Array.fromLittleEndianArrayToULong() : ULong { - if (this.size > 8) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var ulong = this.foldIndexed(0UL) { index, acc, uByte -> acc or (uByte.toULong() shl (index * 8))} - return ulong -} - - -fun UByteArray.fromLittleEndianArrayToULong() : ULong { - if (this.size > 8) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var ulong = this.foldIndexed(0UL) { index, acc, uByte -> acc or (uByte.toULong() shl (index * 8))} - return ulong -} - -fun UByteArray.arrayChunked(sliceSize: Int): List { - val last = this.size % sliceSize - val hasLast = last != 0 - val numberOfSlices = this.size / sliceSize - - - val result : MutableList = MutableList(0) { ubyteArrayOf() } - - for (i in 0 until numberOfSlices) { - result.add(this.sliceArray(i * sliceSize until (i + 1) * sliceSize)) - } - if (hasLast) { - result.add(this.sliceArray(numberOfSlices * sliceSize until this.size)) - } - - return result -} - - - -fun Array.fromBigEndianArrayToULong() : ULong { - if (this.size > 8) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var ulong = this.foldIndexed(0UL) { - index, acc, uByte -> - val res = acc or (uByte.toULong() shl (56 - (index * 8))) - res - - } - return ulong -} - - -fun Array.fromLittleEndianArrayToUInt() : UInt { - if (this.size > 4) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var uint = this.foldIndexed(0U) { index, acc, uByte -> acc or (uByte.toUInt() shl (index * 8))} - return uint -} - - -fun UByteArray.fromLittleEndianArrayToUInt() : UInt { - if (this.size > 4) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var uint = this.foldIndexed(0U) { index, acc, uByte -> acc or (uByte.toUInt() shl (index * 8))} - return uint -} - -fun UByteArray.fromLittleEndianArrayToUIntWithPosition(position: Int) : UInt{ - var uint = 0U - for (i in 0 until 4) { - uint = uint or (this[position + i].toUInt() shl (i * 8)) - } - return uint -} - -fun UByteArray.fromBigEndianArrayToUInt() : UInt{ - var uint = 0U - for (i in 0 until 4) { - uint = uint shl 8 or (this[i].toUInt()) - } - return uint -} - -fun UByteArray.fromBigEndianArrayToUIntWithPosition(position: Int) : UInt{ - var uint = 0U - for (i in 0 until 4) { - uint = uint shl 8 or (this[position + i].toUInt()) - } - return uint -} - -fun UByteArray.insertUIntAtPositionAsLittleEndian(position: Int, value: UInt) { - for (i in position until position + 4) { - this[i] = ((value shr (i * 8)) and 0xFFU).toUByte() - } -} - -fun UByteArray.insertUIntAtPositionAsBigEndian(position: Int, value: UInt) { - for (i in position until position + 4) { - this[i] = ((value shr (24 - i * 8)) and 0xFFU).toUByte() - } -} - -fun UByteArray.fromLittleEndianToUInt() : UIntArray { - if (size % 4 != 0) { - throw RuntimeException("Invalid size (not divisible by 4)") - } - return UIntArray(size / 4) { - fromLittleEndianArrayToUIntWithPosition(it * 4) - } -} - - -fun UByteArray.fromBigEndianToUInt() : UIntArray { - if (size % 4 != 0) { - throw RuntimeException("Invalid size (not divisible by 4)") - } - return UIntArray(size / 4) { - fromBigEndianArrayToUIntWithPosition(it * 4) - } -} - -fun Array.fromBigEndianArrayToUInt() : UInt { - if (this.size > 4) { - throw RuntimeException("ore than 8 bytes in input, potential overflow") - } - var uint = this.foldIndexed(0U) { index, acc, uByte -> acc or (uByte.toUInt() shl (24 - (index * 8))) } - return uint -} - - -operator fun UInt.plus(other : UByteArray) : UByteArray { - return this.toLittleEndianUByteArray() + other -} - -//AES Flatten -fun Collection.flattenToUByteArray(): UByteArray { - val result = UByteArray(sumBy { it.size }) - var position = 0 - for (element in this) { - element.forEach { uByte -> - result[position] = uByte - position++ - } - } - return result -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ReadmeTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ReadmeTest.kt deleted file mode 100644 index 301eeb2..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/ReadmeTest.kt +++ /dev/null @@ -1,168 +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 - -import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bPure -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure -import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure -import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Pure -import com.ionspin.kotlin.crypto.keyderivation.argon2.ArgonType -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import com.ionspin.kotlin.crypto.util.testBlocking -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue -import kotlin.time.ExperimentalTime -import kotlin.time.measureTime - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ - - -class ReadmeTest { - - @Test - fun blake2bObjectExample() { - val input = "abc" - val result = Blake2bPure.digest(input.encodeToUByteArray()) - //@formatter:off - val expectedResult = ubyteArrayOf( - 0xBAU,0x80U,0xA5U,0x3FU,0x98U,0x1CU,0x4DU,0x0DU,0x6AU,0x27U,0x97U,0xB6U,0x9FU,0x12U,0xF6U,0xE9U, - 0x4CU,0x21U,0x2FU,0x14U,0x68U,0x5AU,0xC4U,0xB7U,0x4BU,0x12U,0xBBU,0x6FU,0xDBU,0xFFU,0xA2U,0xD1U, - 0x7DU,0x87U,0xC5U,0x39U,0x2AU,0xABU,0x79U,0x2DU,0xC2U,0x52U,0xD5U,0xDEU,0x45U,0x33U,0xCCU,0x95U, - 0x18U,0xD3U,0x8AU,0xA8U,0xDBU,0xF1U,0x92U,0x5AU,0xB9U,0x23U,0x86U,0xEDU,0xD4U,0x00U,0x99U,0x23U - ) - //@formatter:on - - assertTrue { - result.contentEquals(expectedResult) - } - } - - @Test - fun blake2bInstanceExample() { - val test = "abc" - val key = "key" - val blake2b = Blake2bPure(key) - blake2b.update(test) - val result = blake2b.digest() - - assertTrue { - result.isNotEmpty() - } - val expectedResult = ("5c6a9a4ae911c02fb7e71a991eb9aea371ae993d4842d206e" + - "6020d46f5e41358c6d5c277c110ef86c959ed63e6ecaaaceaaff38019a43264ae06acf73b9550b1") - .hexStringToUByteArray() - - assertTrue { - result.contentEquals(expectedResult) - } - } - - - @Test - fun sha256Example() { - val input = "abc" - val result = Sha256Pure.digest(input.encodeToUByteArray()) - val expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - - - } - - - @Test - fun sha512Example() { - val input = "abc" - val result = Sha512Pure.digest(inputMessage = input.encodeToUByteArray()) - println(result.map { it.toString(16) }) - val expectedResult = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + - "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - - - } - - - @Test - fun sha256UpdatableExample() { - val sha256 = Sha256Pure() - sha256.update("abc") - val result = sha256.digest() - val expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - } - - - @Test - fun sha512UpdatableExample() { - val sha512 = Sha512Pure() - sha512.update("abc") - val result = sha512.digest() - val expectedResult = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + - "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - - - } - - @ExperimentalTime - @Test - fun argon2StringExample() = testBlocking { - val argon2Instance = Argon2Pure( - password = "Password", - salt = "RandomSalt", - parallelism = 1, - tagLength = 64U, - requestedMemorySize = 4096U, - numberOfIterations = 2, - key = "", - associatedData = "", - argonType = ArgonType.Argon2id - ) - val time = measureTime { - val tag = argon2Instance.derive() - val tagString = tag.map { it.toString(16).padStart(2, '0') }.joinToString(separator = "") - val expectedTagString = "c19db7e22d1480702b943872c863baf8c43b53d0c3e2c782cd07bfc613eda159233bd821a945c239c5085c70257f7c93d8a809f81c4af367f4ad8f0443a8fc47" - println("Tag: ${tagString}") - assertEquals(tagString, expectedTagString) - } - println("Time $time") - - } - - @Test - fun debugTest() { - val result = Blake2bPure.digest("test".encodeToUByteArray()) - println(result.toHexString()) - } - - -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SRNGTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SRNGTest.kt deleted file mode 100644 index dba842a..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/SRNGTest.kt +++ /dev/null @@ -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 - -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -class SRNGTest { - @Test - fun testSrng() { - //Just a sanity test, need to add better srng tests. - val randomBytes1 = SRNG.getRandomBytes(10) - val randomBytes2 = SRNG.getRandomBytes(10) - randomBytes1.forEach { println("RB1: $it")} - randomBytes2.forEach { println("RB2: $it")} - assertTrue { !randomBytes1.contentEquals(randomBytes2) } - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/UtilTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/UtilTest.kt deleted file mode 100644 index aa90414..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/UtilTest.kt +++ /dev/null @@ -1,114 +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 - -import com.ionspin.kotlin.crypto.util.chunked -import com.ionspin.kotlin.crypto.util.fromBigEndianArrayToULong -import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToULong -import com.ionspin.kotlin.crypto.util.toBigEndianUByteArray -import com.ionspin.kotlin.crypto.util.toLittleEndianTypedUByteArray -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - -class UtilTest { - - @Test - fun testSlicer() { - val array = arrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) - val chunked = array.chunked(2) - assertTrue { - chunked.size == 9 && chunked[8][0] == 17 - } - } - - @Test - fun testUIntToBigEndianArray() { - assertTrue { - val original = 1U - val converted = original.toBigEndianUByteArray() - converted[0] = 1U - true - } - assertTrue { - val original = 0xAABBCCDDU - val converted = original.toBigEndianUByteArray() - converted[0] == 0xAAU.toUByte() && - converted[1] == 0xBBU.toUByte() && - converted[2] == 0xCCU.toUByte() && - converted[3] == 0xDDU.toUByte() - - } - } - - @Test - fun testUIntToLittleEndianArray() { - assertTrue { - val original = 1U - val converted = original.toLittleEndianTypedUByteArray() - converted[3] = 1U - true - } - assertTrue { - val original = 0xAABBCCDDU - val converted = original.toLittleEndianTypedUByteArray() - converted[0] == 0xDDU.toUByte() && - converted[1] == 0xCCU.toUByte() && - converted[2] == 0xBBU.toUByte() && - converted[3] == 0xAAU.toUByte() - - } - assertTrue { - val original = 123456U - val converted = original.toLittleEndianTypedUByteArray() - converted[0] == 0x40U.toUByte() && - converted[1] == 0xE2U.toUByte() && - converted[2] == 0x01U.toUByte() && - converted[3] == 0x00U.toUByte() - - } - } - - @Test - fun testFromBigEndianByteArrayToLong() { - - assertTrue { - val ubyteArray = ubyteArrayOf(0xA1U, 0xA2U, 0xB1U, 0xB2U, 0xC1U, 0xC2U, 0xD1U, 0xD2U).toTypedArray() - val expected = 0xA1A2B1B2C1C2D1D2U - val reconstructed = ubyteArray.fromBigEndianArrayToULong(); - reconstructed == expected - } - - } - - @Test - fun testFromLittleEndianByteArrayToLong() { - - assertTrue { - val ubyteArray = ubyteArrayOf(0xA1U, 0xA2U, 0xB1U, 0xB2U, 0xC1U, 0xC2U, 0xD1U, 0xD2U).toTypedArray() - val expected = 0xD2D1C2C1B2B1A2A1UL - val reconstructed = ubyteArray.fromLittleEndianArrayToULong(); - reconstructed == expected - } - - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/ChaCha20Poly1305Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/ChaCha20Poly1305Test.kt deleted file mode 100644 index ca0a763..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/ChaCha20Poly1305Test.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexColumsPrint -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jun-2020 - */ -class ChaCha20Poly1305Test { - - - - @Test - fun chaCha20Poly1305() { - val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + - "only one tip for the future, sunscreen would be it.").encodeToUByteArray() - - val associatedData = ubyteArrayOf( - 0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U - ) - val key = ubyteArrayOf( - 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, - 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, - 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, - 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU, - ) - - val nonce = ubyteArrayOf( - 0x07U, 0x00U, 0x00U, 0x00U, 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U - ) - //Ciphertext + Poly1305TAG - val expected = ubyteArrayOf( - 0xd3U, 0x1aU, 0x8dU, 0x34U, 0x64U, 0x8eU, 0x60U, 0xdbU, 0x7bU, 0x86U, 0xafU, 0xbcU, 0x53U, 0xefU, 0x7eU, 0xc2U, - 0xa4U, 0xadU, 0xedU, 0x51U, 0x29U, 0x6eU, 0x08U, 0xfeU, 0xa9U, 0xe2U, 0xb5U, 0xa7U, 0x36U, 0xeeU, 0x62U, 0xd6U, - 0x3dU, 0xbeU, 0xa4U, 0x5eU, 0x8cU, 0xa9U, 0x67U, 0x12U, 0x82U, 0xfaU, 0xfbU, 0x69U, 0xdaU, 0x92U, 0x72U, 0x8bU, - 0x1aU, 0x71U, 0xdeU, 0x0aU, 0x9eU, 0x06U, 0x0bU, 0x29U, 0x05U, 0xd6U, 0xa5U, 0xb6U, 0x7eU, 0xcdU, 0x3bU, 0x36U, - 0x92U, 0xddU, 0xbdU, 0x7fU, 0x2dU, 0x77U, 0x8bU, 0x8cU, 0x98U, 0x03U, 0xaeU, 0xe3U, 0x28U, 0x09U, 0x1bU, 0x58U, - 0xfaU, 0xb3U, 0x24U, 0xe4U, 0xfaU, 0xd6U, 0x75U, 0x94U, 0x55U, 0x85U, 0x80U, 0x8bU, 0x48U, 0x31U, 0xd7U, 0xbcU, - 0x3fU, 0xf4U, 0xdeU, 0xf0U, 0x8eU, 0x4bU, 0x7aU, 0x9dU, 0xe5U, 0x76U, 0xd2U, 0x65U, 0x86U, 0xceU, 0xc6U, 0x4bU, - 0x61U, 0x16U, 0x1aU, 0xe1U, 0x0bU, 0x59U, 0x4fU, 0x09U, 0xe2U, 0x6aU, 0x7eU, 0x90U, 0x2eU, 0xcbU, 0xd0U, 0x60U, - 0x06U, 0x91U - ) - val result = ChaCha20Poly1305Pure.encrypt(key, nonce, message, associatedData) - result.hexColumsPrint() - assertTrue { - result.contentEquals(expected) - } - - } - - -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt deleted file mode 100644 index c186102..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/authenticated/XChaCha20Poly1305Test.kt +++ /dev/null @@ -1,211 +0,0 @@ -package com.ionspin.kotlin.crypto.authenticated - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexColumsPrint -import kotlin.test.Ignore -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jun-2020 - */ -class XChaCha20Poly1305Test { - - - @Test - fun xChaCha20Poly1305() { - assertTrue { - val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + - "only one tip for the future, sunscreen would be it.").encodeToUByteArray() - - val associatedData = ubyteArrayOf( - 0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U - ) - val key = ubyteArrayOf( - 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, - 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, - 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, - 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU, - ) - - val nonce = ubyteArrayOf( - 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, - 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, - 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, - ) - - val expected = ubyteArrayOf( - 0xbdU, 0x6dU, 0x17U, 0x9dU, 0x3eU, 0x83U, 0xd4U, 0x3bU, - 0x95U, 0x76U, 0x57U, 0x94U, 0x93U, 0xc0U, 0xe9U, 0x39U, - 0x57U, 0x2aU, 0x17U, 0x00U, 0x25U, 0x2bU, 0xfaU, 0xccU, - 0xbeU, 0xd2U, 0x90U, 0x2cU, 0x21U, 0x39U, 0x6cU, 0xbbU, - 0x73U, 0x1cU, 0x7fU, 0x1bU, 0x0bU, 0x4aU, 0xa6U, 0x44U, - 0x0bU, 0xf3U, 0xa8U, 0x2fU, 0x4eU, 0xdaU, 0x7eU, 0x39U, - 0xaeU, 0x64U, 0xc6U, 0x70U, 0x8cU, 0x54U, 0xc2U, 0x16U, - 0xcbU, 0x96U, 0xb7U, 0x2eU, 0x12U, 0x13U, 0xb4U, 0x52U, - 0x2fU, 0x8cU, 0x9bU, 0xa4U, 0x0dU, 0xb5U, 0xd9U, 0x45U, - 0xb1U, 0x1bU, 0x69U, 0xb9U, 0x82U, 0xc1U, 0xbbU, 0x9eU, - 0x3fU, 0x3fU, 0xacU, 0x2bU, 0xc3U, 0x69U, 0x48U, 0x8fU, - 0x76U, 0xb2U, 0x38U, 0x35U, 0x65U, 0xd3U, 0xffU, 0xf9U, - 0x21U, 0xf9U, 0x66U, 0x4cU, 0x97U, 0x63U, 0x7dU, 0xa9U, - 0x76U, 0x88U, 0x12U, 0xf6U, 0x15U, 0xc6U, 0x8bU, 0x13U, - 0xb5U, 0x2eU, 0xc0U, 0x87U, 0x59U, 0x24U, 0xc1U, 0xc7U, - 0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU, - 0xcfU, 0x49U - ) - val encrypted = XChaCha20Poly1305Pure.encrypt(key, nonce, message, associatedData) - val decrypted = XChaCha20Poly1305Pure.decrypt(key, nonce, encrypted, associatedData) - - encrypted.contentEquals(expected) && decrypted.contentEquals(message) - } - - assertTrue { - val message = ubyteArrayOf( - 0x00U - ) - val associatedData = ubyteArrayOf( - 0x00U - ) - val key = ubyteArrayOf( - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - ) - - val nonce = ubyteArrayOf( - 0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U, 0x09U, 0x0aU, 0x0bU, - 0x0cU, 0x0dU, 0x0eU, 0x0fU, 0x10U, 0x11U, 0x12U, 0x13U, 0x14U, 0x15U, 0x16U, 0x17U, - ) - - val expected = ubyteArrayOf( - 0xbdU, 0x3bU, 0x8aU, 0xd7U, 0xa1U, 0x9dU, 0xe8U, 0xc4U, 0x55U, - 0x84U, 0x6fU, 0xfcU, 0x75U, 0x31U, 0xbfU, 0x0cU, 0x2dU - ) - val encrypted = XChaCha20Poly1305Pure.encrypt(key, nonce, message, associatedData) - val decrypted = XChaCha20Poly1305Pure.decrypt(key, nonce, encrypted, associatedData) - - encrypted.contentEquals(expected) && decrypted.contentEquals(message) - } - - - } - @Ignore() //"Will fail because nonce is not a parameter any more" - @Test - fun updateableXChaCha20Poly1305() { - assertTrue { - val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " + - "only one tip for the future, sunscreen would be it.").encodeToUByteArray() - - val associatedData = ubyteArrayOf( - 0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U - ) - val key = ubyteArrayOf( - 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, - 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, - 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, - 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU, - ) - - val nonce = ubyteArrayOf( - 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, - 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, - 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, - ) - - val expected = ubyteArrayOf( - 0xbdU, 0x6dU, 0x17U, 0x9dU, 0x3eU, 0x83U, 0xd4U, 0x3bU, - 0x95U, 0x76U, 0x57U, 0x94U, 0x93U, 0xc0U, 0xe9U, 0x39U, - 0x57U, 0x2aU, 0x17U, 0x00U, 0x25U, 0x2bU, 0xfaU, 0xccU, - 0xbeU, 0xd2U, 0x90U, 0x2cU, 0x21U, 0x39U, 0x6cU, 0xbbU, - 0x73U, 0x1cU, 0x7fU, 0x1bU, 0x0bU, 0x4aU, 0xa6U, 0x44U, - 0x0bU, 0xf3U, 0xa8U, 0x2fU, 0x4eU, 0xdaU, 0x7eU, 0x39U, - 0xaeU, 0x64U, 0xc6U, 0x70U, 0x8cU, 0x54U, 0xc2U, 0x16U, - 0xcbU, 0x96U, 0xb7U, 0x2eU, 0x12U, 0x13U, 0xb4U, 0x52U, - 0x2fU, 0x8cU, 0x9bU, 0xa4U, 0x0dU, 0xb5U, 0xd9U, 0x45U, - 0xb1U, 0x1bU, 0x69U, 0xb9U, 0x82U, 0xc1U, 0xbbU, 0x9eU, - 0x3fU, 0x3fU, 0xacU, 0x2bU, 0xc3U, 0x69U, 0x48U, 0x8fU, - 0x76U, 0xb2U, 0x38U, 0x35U, 0x65U, 0xd3U, 0xffU, 0xf9U, - 0x21U, 0xf9U, 0x66U, 0x4cU, 0x97U, 0x63U, 0x7dU, 0xa9U, - 0x76U, 0x88U, 0x12U, 0xf6U, 0x15U, 0xc6U, 0x8bU, 0x13U, - 0xb5U, 0x2eU, 0xc0U, 0x87U, 0x59U, 0x24U, 0xc1U, 0xc7U, - 0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU, - 0xcfU, 0x49U - ) -// val xChaChaPoly = XChaCha20Poly1305Pure(key, associatedData) val firstChunk = -// xChaChaPoly.encryptPartialData(message) val finalChunk = xChaChaPoly.finishEncryption().first val result = -// firstChunk + finalChunk result.contentEquals(expected) - 1 == 1 - } - - assertTrue { - val message = ubyteArrayOf( - 0x00U - ) - val associatedData = ubyteArrayOf( - 0x00U - ) - val key = ubyteArrayOf( - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, - ) - - val nonce = ubyteArrayOf( - 0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U, 0x09U, 0x0aU, 0x0bU, - 0x0cU, 0x0dU, 0x0eU, 0x0fU, 0x10U, 0x11U, 0x12U, 0x13U, 0x14U, 0x15U, 0x16U, 0x17U, - ) - - val expected = ubyteArrayOf( - 0xbdU, 0x3bU, 0x8aU, 0xd7U, 0xa1U, 0x9dU, 0xe8U, 0xc4U, 0x55U, - 0x84U, 0x6fU, 0xfcU, 0x75U, 0x31U, 0xbfU, 0x0cU, 0x2dU - ) -// val xChaChaPoly = XChaCha20Poly1305Pure(key, associatedData) -// val firstChunk = xChaChaPoly.encryptPartialData(message) -// val finalChunk = xChaChaPoly.finishEncryption().first -// val result = firstChunk + finalChunk -// result.contentEquals(expected) - 1 == 1 - } - - - } - - @Test - fun multipartXChaCha20Poly1305() { - val key = UByteArray(32) { 0U} - - val state = ubyteArrayOf( - 0x2DU, 0xDBU, 0xC7U, 0xB2U, 0x03U, 0xBCU, 0xC3U, 0x22U, 0xBDU, 0x0CU, 0xBAU, 0x82U, 0xADU, 0x77U, 0x79U, 0x44U, - 0xE6U, 0x8FU, 0xA9U, 0x94U, 0x89U, 0xB1U, 0xDFU, 0xBEU, 0x00U, 0x9FU, 0x69U, 0xECU, 0x21U, 0x88U, 0x47U, 0x55U, - 0x01U, 0x00U, 0x00U, 0x00U, 0xC5U, 0x55U, 0x06U, 0x38U, 0xEBU, 0xA3U, 0x12U, 0x7BU, 0x00U, 0x00U, 0x00U, 0x00U, - 0x00U, 0x00U, 0x00U, 0x00U, - ) - val header = ubyteArrayOf( - 0x49U, 0x62U, 0x22U, 0x03U, 0xB7U, 0x46U, 0x11U, 0x97U, 0x8FU, 0x46U, 0x4AU, 0x3BU, 0x2FU, 0x2AU, 0x81U, 0x03U, - 0xC5U, 0x55U, 0x06U, 0x38U, 0xEBU, 0xA3U, 0x12U, 0x7BU, - ) - val expected = ubyteArrayOf( - 0xAFU, 0xD3U, 0x2DU, 0x59U, 0xB8U, 0xC4U, 0x66U, 0x2EU, 0x47U, 0x29U, 0xC6U, 0xF9U, 0x93U, 0x4BU, 0x09U, 0x27U, - 0x24U, 0xDDU, 0xF3U, 0x05U, 0x48U, 0x94U, 0x67U, 0x10U, 0x00U, 0x21U, 0x85U, 0x22U, 0x96U, 0x3CU, 0xCEU, 0x8EU, - 0xB7U, 0x53U, 0x9DU, 0x46U, 0xF5U, 0x3CU, 0x5EU, 0x48U, 0x9BU, 0x8CU, 0x13U, 0xB7U, 0x28U, 0x6BU, 0xB3U, 0x6CU, - 0x3AU, 0x04U, 0xB7U, 0x25U, 0xB9U, 0x50U, 0x45U, 0x08U, 0x0BU, 0x89U, 0xA2U, 0x0FU, 0x70U, 0xCCU, 0x60U, 0x1BU, - 0xC3U, 0x17U, 0x35U, 0x9FU, 0xAEU, 0x82U, 0x51U, 0x43U, 0x1BU, 0x9DU, 0x53U, 0x9EU, 0xE2U, 0xAFU, 0x20U, 0x1FU, - 0xFDU, 0x03U, 0x59U, 0x11U, 0x51U, 0x9EU, 0xACU, 0x83U, 0xCDU, 0x78U, 0xD1U, 0xD0U, 0xE5U, 0xD7U, 0x0EU, 0x41U, - 0xDEU, 0xFBU, 0x5CU, 0x7FU, 0x1CU, 0x26U, 0x32U, 0x2CU, 0x51U, 0xF6U, 0xEFU, 0xC6U, 0x34U, 0xC4U, 0xACU, 0x6CU, - 0xE8U, 0xF9U, 0x4BU, 0xABU, 0xA3U, - ) - - val xcha = XChaCha20Poly1305Pure(key, header) - //Verify the state is correctly created - assertTrue { - xcha.calcKey.contentEquals(state.sliceArray(0 until 32)) - xcha.calcNonce.contentEquals(state.sliceArray(32 until 44)) - } - val data = UByteArray(100) { 0U } - xcha.streamEncrypt(data, ubyteArrayOf(), 0U).hexColumsPrint() - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2KATTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2KATTest.kt deleted file mode 100644 index 6e86d56..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2KATTest.kt +++ /dev/null @@ -1,158 +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. - */ - -@file:Suppress("EXPERIMENTAL_UNSIGNED_LITERALS", "EXPERIMENTAL_API_USAGE") - -package com.ionspin.kotlin.crypto.hash.argon - -import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Pure -import com.ionspin.kotlin.crypto.keyderivation.argon2.ArgonType -import com.ionspin.kotlin.crypto.util.hexColumsPrint -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Known Answer.. TestTest - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 10-May-2020 - */ - -class Argon2KATTest { - - @Test - fun argon2dKATTest() { - val expected : UByteArray = ubyteArrayOf( - 0x51U, 0x2BU, 0x39U, 0x1BU, 0x6FU, 0x11U, 0x62U, 0x97U, - 0x53U, 0x71U, 0xD3U, 0x09U, 0x19U, 0x73U, 0x42U, 0x94U, - 0xF8U, 0x68U, 0xE3U, 0xBEU, 0x39U, 0x84U, 0xF3U, 0xC1U, - 0xA1U, 0x3AU, 0x4DU, 0xB9U, 0xFAU, 0xBEU, 0x4AU, 0xCBU - ) - - - val memory = 32U //KiB - val iterations = 3 - val parallelism = 4U - val tagLength = 32U - val password: UByteArray = ubyteArrayOf( - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U - ) - val salt: UByteArray = ubyteArrayOf(0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U) - val secret: UByteArray = ubyteArrayOf(0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U) - val associatedData: UByteArray = ubyteArrayOf(0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U) - - val digest = Argon2Pure( - password, - salt, - parallelism.toInt(), - tagLength, - memory, - iterations, - secret, - associatedData, - ArgonType.Argon2d - ) - val result = digest.derive() - result.hexColumsPrint(8) - assertTrue { expected.contentEquals(result) } - - } - - @Test - fun argon2iKATTest() { - val expected : UByteArray = ubyteArrayOf( - 0xc8U, 0x14U, 0xd9U, 0xd1U, 0xdcU, 0x7fU, 0x37U, 0xaaU, - 0x13U, 0xf0U, 0xd7U, 0x7fU, 0x24U, 0x94U, 0xbdU, 0xa1U, - 0xc8U, 0xdeU, 0x6bU, 0x01U, 0x6dU, 0xd3U, 0x88U, 0xd2U, - 0x99U, 0x52U, 0xa4U, 0xc4U, 0x67U, 0x2bU, 0x6cU, 0xe8U - ) - - - val memory = 32U //KiB - val iterations = 3 - val parallelism = 4U - val tagLength = 32U - val password: UByteArray = ubyteArrayOf( - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U - ) - val salt: UByteArray = ubyteArrayOf(0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U) - val secret: UByteArray = ubyteArrayOf(0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U) - val associatedData: UByteArray = ubyteArrayOf(0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U) - - val digest = Argon2Pure( - password, - salt, - parallelism.toInt(), - tagLength, - memory, - iterations, - secret, - associatedData, - ArgonType.Argon2i - ) - val result = digest.derive() - result.hexColumsPrint(8) - assertTrue { expected.contentEquals(result) } - - } - - @Test - fun argon2idKATTest() { - val expected : UByteArray = ubyteArrayOf( - 0x0dU, 0x64U, 0x0dU, 0xf5U, 0x8dU, 0x78U, 0x76U, 0x6cU, - 0x08U, 0xc0U, 0x37U, 0xa3U, 0x4aU, 0x8bU, 0x53U, 0xc9U, - 0xd0U, 0x1eU, 0xf0U, 0x45U, 0x2dU, 0x75U, 0xb6U, 0x5eU, - 0xb5U, 0x25U, 0x20U, 0xe9U, 0x6bU, 0x01U, 0xe6U, 0x59U - ) - - - val memory = 32U //KiB - val iterations = 3 - val parallelism = 4U - val tagLength = 32U - val password: UByteArray = ubyteArrayOf( - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, - 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U, 0x01U - ) - val salt: UByteArray = ubyteArrayOf(0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U, 0x02U) - val secret: UByteArray = ubyteArrayOf(0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U, 0x03U) - val associatedData: UByteArray = ubyteArrayOf(0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U, 0x04U) - - val digest = Argon2Pure( - password, - salt, - parallelism.toInt(), - tagLength, - memory, - iterations, - secret, - associatedData, - ArgonType.Argon2id - ) - val result = digest.derive() - result.hexColumsPrint(8) - assertTrue { expected.contentEquals(result) } - - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2MatrixTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2MatrixTest.kt deleted file mode 100644 index ad69c98..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2MatrixTest.kt +++ /dev/null @@ -1,142 +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. - */ - -@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS") - -package com.ionspin.kotlin.crypto.hash.argon - -import com.ionspin.kotlin.crypto.keyderivation.argon2.* -import com.ionspin.kotlin.crypto.util.arrayChunked -import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToULong -import kotlin.random.Random -import kotlin.random.nextUBytes -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-May-2020 - */ -class Argon2MatrixTest { - val zeroesBlock = UByteArray(1024) { 0U } - val onesBlock = UByteArray(1024) { 1U } - val twosBlock = UByteArray(1024) { 2U } - val threesBlock = UByteArray(1024) { 3U } - - val random = Random(1) - val randomBlockArray = random.nextUBytes(1024) - - - @Test - fun indexAccessTest() { - val argon2Matrix = ArgonMatrix(2, 2) - (zeroesBlock + onesBlock + twosBlock + threesBlock).copyInto(argon2Matrix.storage) - println(argon2Matrix[0, 0, 0]) - println(argon2Matrix[0, 1, 0]) - println(argon2Matrix[1, 0, 0]) - println(argon2Matrix[1, 1, 0]) -// argon2Matrix.storage.hexColumsPrint(1024) - var expectedByteValue = 0U.toUByte() - for (lane in 0 until 2) { - for (column in 0 until 2) { - for (blockPosition in 0 until 1024) { - assertTrue { - argon2Matrix[lane, column, blockPosition] == expectedByteValue - } - } - expectedByteValue++ - } - } - assertTrue { - argon2Matrix[0, 0, 0] == 0U.toUByte() && - argon2Matrix[0, 1, 0] == 1U.toUByte() && - argon2Matrix[1, 0, 0] == 2U.toUByte() && - argon2Matrix[1, 1, 0] == 3U.toUByte() - - } - } - - @Test - fun blockRetrievalTest() { - val argon2Matrix = ArgonMatrix(2, 2) - (zeroesBlock + onesBlock + twosBlock + threesBlock).copyInto(argon2Matrix.storage) - assertTrue { - zeroesBlock.contentEquals(argon2Matrix.getBlockAt(0, 0)) && - onesBlock.contentEquals(argon2Matrix.getBlockAt(0, 1)) && - twosBlock.contentEquals(argon2Matrix.getBlockAt(1, 0)) && - threesBlock.contentEquals(argon2Matrix.getBlockAt(1, 1)) - } - } - - @Test - fun blockColumnToUlongTest() { - val randomBlock = ArgonBlock(randomBlockArray) - for (columnIndex in 0 until 8) { - val startOfRow = (columnIndex * 8 * 16) - val endOfRow = startOfRow + (8 * 16) - val rowToMix = randomBlockArray.copyOfRange(startOfRow, endOfRow) - val expected = rowToMix.arrayChunked(8).map { it.fromLittleEndianArrayToULong() }.toULongArray() - - val result = randomBlock.getBlockPointer().getRowOfULongsForMixing(columnIndex) - - assertTrue { expected.contentEquals(result) } - } - } - - @Test - fun blockRowToULongTest() { - val randomBlock = ArgonBlock(randomBlockArray) - for (rowIndex in 0 until 8) { - val columnToMix = Argon2Utils.extractColumnFromGBlock(randomBlockArray, rowIndex) - val expected = columnToMix.arrayChunked(8).map { it.fromLittleEndianArrayToULong() }.toULongArray() - val result = randomBlock.getBlockPointer().getColumnOfULongsForMixing(rowIndex) - - assertTrue { expected.contentEquals(result) } - } - } - - @Test - fun blockSetMixedRowTest() { - val randomBlock = ArgonBlock(randomBlockArray) - val targetBlockArray = zeroesBlock.copyOf() - val targetBlock = ArgonBlock(targetBlockArray) - for (rowIndex in 0 until 8) { - val extracted = randomBlock.getBlockPointer().getRowOfULongsForMixing(rowIndex) - targetBlock.getBlockPointer().setRowFromMixedULongs(rowIndex, extracted) - } - - assertTrue { - randomBlockArray.contentEquals(targetBlock.storage) - } - } - - @Test - fun blockSetMixedColumnTest() { - val randomBlock = ArgonBlock(randomBlockArray) - val targetBlockArray = zeroesBlock.copyOf() - val targetBlock = ArgonBlock(targetBlockArray) - for (columnIndex in 0 until 8) { - val extracted = randomBlock.getBlockPointer().getColumnOfULongsForMixing(columnIndex) - targetBlock.getBlockPointer().setColumnFromMixedULongs(columnIndex, extracted) - } - - assertTrue { - randomBlockArray.contentEquals(targetBlock.storage) - } - } - -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2Test.kt deleted file mode 100644 index f513b7d..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/argon/Argon2Test.kt +++ /dev/null @@ -1,403 +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. - */ - -@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_UNSIGNED_LITERALS") - -package com.ionspin.kotlin.crypto.hash.argon - -import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils -import com.ionspin.kotlin.crypto.keyderivation.argon2.ArgonBlock -import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToULong -import kotlin.random.Random -import kotlin.random.nextUBytes -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-May-2020 - */ -class Argon2Test { - val seededRandom = Random(1L) - val randomBlockAsArray = seededRandom.nextUBytes(1024) - val randomBlockAsArray2 = seededRandom.nextUBytes(1024) - val randomBlockAsArray3 = seededRandom.nextUBytes(1024) - - @Test - fun mixRoundTest() { - val input = ubyteArrayOf( - 0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, - 0x08U, 0x09U, 0x0aU, 0x0bU, 0x0cU, 0x0dU, 0x0eU, 0x0fU, - 0x10U, 0x11U, 0x12U, 0x13U, 0x14U, 0x15U, 0x16U, 0x17U, - 0x18U, 0x19U, 0x1aU, 0x1bU, 0x1cU, 0x1dU, 0x1eU, 0x1fU, - 0x20U, 0x21U, 0x22U, 0x23U, 0x24U, 0x25U, 0x26U, 0x27U, - 0x28U, 0x29U, 0x2aU, 0x2bU, 0x2cU, 0x2dU, 0x2eU, 0x2fU, - 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, - 0x38U, 0x39U, 0x3aU, 0x3bU, 0x3cU, 0x3dU, 0x3eU, 0x3fU, - 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, - 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, - 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, - 0x58U, 0x59U, 0x5aU, 0x5bU, 0x5cU, 0x5dU, 0x5eU, 0x5fU, - 0x60U, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, 0x67U, - 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, 0x6fU, - 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, 0x77U, - 0x78U, 0x79U, 0x7aU, 0x7bU, 0x7cU, 0x7dU, 0x7eU, 0x7fU - ) - - val expected = arrayOf( - 16438755999881694465U, - 2631578750119870528U, - 8840261388583117524U, - 13886387434724287670U, - 14214935523062117944U, - 6768869593113706780U, - 12323449447979969623U, - 7512951229622659062U, - 9291745133539598579U, - 11220895723773995914U, - 2509429320847842905U, - 5637172405908834370U, - 8517838221434905893U, - 14206719563334097702U, - 6500029010075826286U, - 16957672821843227543U - ) - val preparedInput = input.chunked(8).map { it.toTypedArray().fromLittleEndianArrayToULong() }.toULongArray() - val result = Argon2Utils.inplaceMixRound(preparedInput) - assertTrue { - expected.contentEquals(result.toTypedArray()) - } - - } - - @Test - fun testExtractColumnFromGBlock() { - val expected = ubyteArrayOf( - 0x1AU, 0x2AU, 0xC5U, 0x23U, 0xB0U, 0x05U, 0xB1U, 0xA4U, - 0x61U, 0x48U, 0x93U, 0xE0U, 0x6DU, 0x33U, 0xB6U, 0xA0U, - 0x63U, 0x13U, 0xFFU, 0xEBU, 0x56U, 0x48U, 0xE7U, 0xD0U, - 0x47U, 0x58U, 0x8EU, 0xD7U, 0xDEU, 0x01U, 0xCFU, 0x96U, - 0xB4U, 0xE0U, 0x2AU, 0xF0U, 0x16U, 0x33U, 0x54U, 0xA9U, - 0xF3U, 0xC3U, 0x98U, 0x2CU, 0xB7U, 0xECU, 0x1AU, 0x66U, - 0xE0U, 0x6CU, 0xA5U, 0x66U, 0x73U, 0xE8U, 0x8AU, 0xF7U, - 0x50U, 0x96U, 0xB8U, 0x16U, 0x47U, 0x41U, 0xA6U, 0x4CU, - 0xAEU, 0x89U, 0xBAU, 0x5DU, 0x3CU, 0x49U, 0x33U, 0x23U, - 0xD3U, 0xFBU, 0xD4U, 0x04U, 0x11U, 0x8FU, 0x98U, 0x10U, - 0xDCU, 0xB7U, 0x06U, 0xE0U, 0x58U, 0xCFU, 0x48U, 0xE3U, - 0x1FU, 0x33U, 0xE6U, 0x66U, 0x20U, 0xD2U, 0x34U, 0x43U, - 0x62U, 0xA0U, 0x02U, 0x7FU, 0xE9U, 0x36U, 0xB3U, 0xB5U, - 0x6BU, 0x07U, 0x8CU, 0xA7U, 0xB1U, 0x11U, 0x28U, 0x6FU, - 0x6BU, 0xD0U, 0x09U, 0x4FU, 0xACU, 0x48U, 0x18U, 0xDCU, - 0x70U, 0xB6U, 0xD6U, 0x27U, 0x69U, 0x50U, 0x97U, 0x87U, - ) - val extracted = Argon2Utils.extractColumnFromGBlock(randomBlockAsArray, 0) - assertTrue { - expected.contentEquals(extracted) - } - - } - - @Test - fun testCompressionFunctionGWithoutXor() { - val expectedWithoutXor = ubyteArrayOf( - 0x94U, 0xE8U, 0x52U, 0x79U, 0xA7U, 0xE5U, 0x66U, 0xAAU, - 0xD7U, 0xE1U, 0x8EU, 0x72U, 0x42U, 0xA2U, 0xE1U, 0x50U, - 0x5FU, 0x77U, 0x7DU, 0xCDU, 0xE1U, 0xEFU, 0xAAU, 0xF5U, - 0x29U, 0x94U, 0x29U, 0x17U, 0x9DU, 0x79U, 0xA5U, 0x67U, - 0xD7U, 0x6CU, 0x11U, 0x18U, 0x6FU, 0xE0U, 0xA4U, 0x26U, - 0xCCU, 0xF4U, 0xFDU, 0xD1U, 0xE0U, 0x42U, 0xC1U, 0x6AU, - 0x33U, 0x99U, 0xC4U, 0x27U, 0x33U, 0x67U, 0xDDU, 0xC3U, - 0x57U, 0x81U, 0xF5U, 0xCDU, 0x05U, 0x22U, 0x2DU, 0x5FU, - 0x71U, 0x83U, 0xA9U, 0x54U, 0x1BU, 0x09U, 0x40U, 0x68U, - 0x6DU, 0x78U, 0x0FU, 0x23U, 0xE2U, 0x90U, 0xC1U, 0x2DU, - 0xBFU, 0x44U, 0x26U, 0xADU, 0x8BU, 0x77U, 0x0EU, 0xFBU, - 0x9AU, 0x95U, 0x7AU, 0x8DU, 0xEAU, 0xCAU, 0xA2U, 0x1BU, - 0xBDU, 0xC0U, 0x90U, 0x85U, 0x37U, 0xD9U, 0xF3U, 0x94U, - 0x59U, 0x9EU, 0xB4U, 0xC4U, 0xBCU, 0xC1U, 0x47U, 0x31U, - 0x66U, 0xE4U, 0x66U, 0x0EU, 0x86U, 0x11U, 0x4AU, 0x4CU, - 0x36U, 0xA1U, 0x1CU, 0xDEU, 0xE9U, 0xA4U, 0x03U, 0x1FU, - 0x9CU, 0x7AU, 0x1BU, 0x7AU, 0x8FU, 0x17U, 0xA3U, 0xD4U, - 0x5BU, 0x23U, 0x8AU, 0x55U, 0x53U, 0x86U, 0x64U, 0xEDU, - 0x24U, 0x97U, 0xFAU, 0x70U, 0xD4U, 0xF1U, 0x9AU, 0x10U, - 0xBCU, 0x24U, 0x03U, 0xACU, 0x24U, 0x91U, 0x83U, 0xFBU, - 0x66U, 0x02U, 0xC2U, 0x37U, 0xBEU, 0x63U, 0xCEU, 0x59U, - 0xEAU, 0x02U, 0xAFU, 0x6CU, 0x8DU, 0x14U, 0xECU, 0xFDU, - 0x5BU, 0x0AU, 0x0EU, 0xB6U, 0x51U, 0x2FU, 0x75U, 0xF1U, - 0xA9U, 0x88U, 0xD1U, 0x05U, 0x60U, 0xE6U, 0xEDU, 0x17U, - 0x4AU, 0x03U, 0x1FU, 0xF7U, 0x71U, 0x86U, 0x26U, 0x18U, - 0x7EU, 0xB3U, 0x31U, 0x78U, 0xD8U, 0xB7U, 0x2CU, 0xD0U, - 0x6DU, 0xB5U, 0xAEU, 0xDFU, 0x85U, 0xC6U, 0x87U, 0x9FU, - 0x18U, 0x85U, 0x1BU, 0x22U, 0x19U, 0x15U, 0x00U, 0xF8U, - 0x03U, 0xF7U, 0x48U, 0xA4U, 0xFCU, 0xE3U, 0xE4U, 0x93U, - 0x02U, 0x57U, 0x71U, 0xBCU, 0xF6U, 0x2DU, 0x45U, 0xBEU, - 0x87U, 0xC1U, 0x21U, 0x11U, 0x77U, 0x23U, 0x78U, 0xFCU, - 0x56U, 0xBFU, 0x92U, 0x49U, 0xA1U, 0x51U, 0xE9U, 0x22U, - 0x24U, 0x10U, 0x30U, 0x2EU, 0xE1U, 0xC1U, 0xF7U, 0x96U, - 0xB0U, 0x27U, 0xF7U, 0x6CU, 0x65U, 0x0CU, 0x1BU, 0xE1U, - 0xB2U, 0x12U, 0xD3U, 0xBCU, 0x8BU, 0xEDU, 0x9DU, 0x14U, - 0x81U, 0x82U, 0xB3U, 0x5BU, 0x70U, 0x2CU, 0x65U, 0x54U, - 0xF5U, 0x1FU, 0x1CU, 0x37U, 0xD2U, 0xD1U, 0x89U, 0x35U, - 0x57U, 0x52U, 0xDDU, 0xA7U, 0x02U, 0x81U, 0x14U, 0xF7U, - 0x6CU, 0x4CU, 0xB9U, 0x02U, 0x96U, 0x72U, 0xD2U, 0xFEU, - 0x30U, 0x66U, 0x8CU, 0x16U, 0x50U, 0xB1U, 0x51U, 0xE9U, - 0x48U, 0x48U, 0x83U, 0xA6U, 0x5CU, 0xF9U, 0x98U, 0x59U, - 0xBAU, 0x2DU, 0xE5U, 0x73U, 0xADU, 0xD1U, 0x6AU, 0x7AU, - 0x1FU, 0x6EU, 0xD8U, 0xC9U, 0xEDU, 0x00U, 0x9AU, 0xB1U, - 0x34U, 0x08U, 0x0AU, 0x81U, 0x3EU, 0xCCU, 0x44U, 0xB7U, - 0xD6U, 0xFEU, 0x0FU, 0x5CU, 0x19U, 0xD8U, 0x8FU, 0xEDU, - 0x46U, 0x88U, 0xF5U, 0x5DU, 0x6BU, 0xDAU, 0x4DU, 0x02U, - 0xA9U, 0xFCU, 0x67U, 0xBEU, 0x0CU, 0x09U, 0x38U, 0x98U, - 0x79U, 0x52U, 0x7DU, 0xA6U, 0x24U, 0xA8U, 0x3BU, 0xB1U, - 0xB2U, 0x52U, 0xC8U, 0x83U, 0x6CU, 0x02U, 0xD8U, 0xBDU, - 0x7FU, 0x98U, 0xCCU, 0x65U, 0x01U, 0x90U, 0x6EU, 0x60U, - 0xF8U, 0xB8U, 0x94U, 0xABU, 0x7BU, 0xA9U, 0x5FU, 0xE9U, - 0xDAU, 0xCCU, 0x94U, 0x00U, 0xEDU, 0x8FU, 0x03U, 0xA3U, - 0xCFU, 0xB3U, 0x14U, 0x38U, 0x94U, 0x91U, 0xF3U, 0x61U, - 0xEBU, 0x04U, 0xDEU, 0x9DU, 0x9DU, 0x05U, 0x98U, 0xF3U, - 0x71U, 0xB1U, 0xB3U, 0xB1U, 0x1DU, 0xA3U, 0x55U, 0x47U, - 0xF4U, 0xA3U, 0xF8U, 0x7AU, 0x11U, 0xBBU, 0x0DU, 0x9CU, - 0xB1U, 0x57U, 0xAAU, 0xC2U, 0x3CU, 0x0BU, 0xBEU, 0x77U, - 0xBCU, 0x25U, 0x03U, 0x8BU, 0x7FU, 0x81U, 0xA5U, 0x7EU, - 0xA9U, 0xB4U, 0x3FU, 0x5AU, 0x11U, 0x54U, 0x75U, 0x7DU, - 0x45U, 0x20U, 0x90U, 0x46U, 0x98U, 0x70U, 0xF5U, 0x5BU, - 0xA5U, 0x9DU, 0x46U, 0x63U, 0x62U, 0x3DU, 0x04U, 0x2FU, - 0xB9U, 0x67U, 0x31U, 0xC5U, 0x92U, 0x48U, 0x18U, 0x0FU, - 0xDCU, 0x52U, 0x78U, 0xCBU, 0x7CU, 0x86U, 0x58U, 0xDBU, - 0x0BU, 0x06U, 0xF2U, 0x93U, 0x83U, 0x26U, 0x99U, 0x5DU, - 0xBDU, 0xFBU, 0x87U, 0xC9U, 0x55U, 0x41U, 0xACU, 0x5FU, - 0xA3U, 0xF9U, 0x71U, 0x53U, 0x93U, 0x53U, 0xC5U, 0xE4U, - 0x3FU, 0x78U, 0x31U, 0x8FU, 0x7CU, 0x0BU, 0x77U, 0x84U, - 0x43U, 0xACU, 0x4DU, 0xD1U, 0xC9U, 0x9BU, 0x4BU, 0x60U, - 0x00U, 0xFEU, 0x41U, 0x10U, 0xEFU, 0xDFU, 0x80U, 0x95U, - 0x03U, 0x23U, 0xBEU, 0xF6U, 0x6BU, 0x60U, 0xE5U, 0x6FU, - 0x9EU, 0x6BU, 0x7CU, 0x24U, 0xA7U, 0xC1U, 0xF8U, 0xBBU, - 0x60U, 0x55U, 0x57U, 0x18U, 0x58U, 0x32U, 0x97U, 0xE8U, - 0x53U, 0x71U, 0x05U, 0x59U, 0xE3U, 0x94U, 0xB1U, 0x60U, - 0x8AU, 0x40U, 0x24U, 0xF6U, 0x29U, 0x49U, 0x65U, 0xADU, - 0x65U, 0xE3U, 0xCEU, 0x9FU, 0x4FU, 0x47U, 0xA0U, 0x07U, - 0x2FU, 0x1CU, 0xA7U, 0x3AU, 0x04U, 0x17U, 0x87U, 0x1BU, - 0x06U, 0xC5U, 0x93U, 0x63U, 0x3FU, 0x18U, 0x3BU, 0x8BU, - 0x3EU, 0xD4U, 0xC0U, 0xC9U, 0x7EU, 0xB6U, 0x32U, 0xD3U, - 0xC3U, 0x8BU, 0x55U, 0x2CU, 0x5BU, 0xB7U, 0xEBU, 0x88U, - 0x14U, 0x63U, 0xB8U, 0x3BU, 0xDBU, 0xFFU, 0x49U, 0x44U, - 0x79U, 0xD2U, 0x82U, 0xD8U, 0xA6U, 0x47U, 0x45U, 0xFBU, - 0xF5U, 0x4BU, 0x5AU, 0x43U, 0x19U, 0xD9U, 0xD5U, 0x52U, - 0x04U, 0x0CU, 0x4BU, 0x74U, 0x87U, 0x0DU, 0x11U, 0x8DU, - 0x51U, 0x9DU, 0x66U, 0x68U, 0x41U, 0xE0U, 0xFCU, 0x92U, - 0x24U, 0x7FU, 0x62U, 0xAFU, 0x8BU, 0x53U, 0xDEU, 0x84U, - 0xF0U, 0xA1U, 0x03U, 0xAAU, 0x17U, 0x6FU, 0xD3U, 0x10U, - 0x57U, 0x25U, 0xC6U, 0xA3U, 0x8FU, 0x1AU, 0xD3U, 0xD7U, - 0x0DU, 0x89U, 0x22U, 0x3CU, 0x17U, 0xC6U, 0xF7U, 0x02U, - 0x0CU, 0xD9U, 0x0FU, 0xABU, 0x27U, 0xA6U, 0xE3U, 0x20U, - 0xF4U, 0xB2U, 0x21U, 0x12U, 0x85U, 0xF5U, 0x98U, 0x45U, - 0x16U, 0x24U, 0xF7U, 0x46U, 0x5DU, 0x1FU, 0x41U, 0x9AU, - 0x0EU, 0x25U, 0x4AU, 0x99U, 0x27U, 0x5CU, 0x0BU, 0xC8U, - 0x33U, 0x99U, 0x65U, 0x3CU, 0xC9U, 0xDBU, 0x78U, 0x6DU, - 0x36U, 0xC6U, 0x37U, 0x35U, 0x2EU, 0x97U, 0x04U, 0x03U, - 0x26U, 0x78U, 0x5AU, 0x5AU, 0xD8U, 0xEAU, 0xF7U, 0xF1U, - 0xF9U, 0x22U, 0x9DU, 0xDEU, 0xB7U, 0x50U, 0xFEU, 0x91U, - 0xD4U, 0x5EU, 0xA1U, 0xC2U, 0x1BU, 0xE4U, 0x3FU, 0x19U, - 0x50U, 0x21U, 0x1FU, 0x38U, 0xA1U, 0x11U, 0xB1U, 0x08U, - 0x7DU, 0xA2U, 0xBBU, 0xE5U, 0xECU, 0x1BU, 0x9FU, 0x51U, - 0x77U, 0x6CU, 0xB9U, 0xA8U, 0xC2U, 0x76U, 0xD4U, 0xCBU, - 0x11U, 0x7DU, 0x4AU, 0x92U, 0xE2U, 0x0AU, 0x96U, 0x9AU, - 0x28U, 0x72U, 0xFFU, 0xAAU, 0xF8U, 0xD5U, 0x64U, 0x8AU, - 0x45U, 0x71U, 0xF3U, 0xB5U, 0xD7U, 0x2AU, 0x3BU, 0x7FU, - 0x5CU, 0xFCU, 0x2DU, 0x89U, 0xBCU, 0x64U, 0x2FU, 0x63U, - 0x87U, 0xE6U, 0x57U, 0xECU, 0x06U, 0xE3U, 0xDDU, 0x15U, - 0xB4U, 0x27U, 0xA8U, 0x6CU, 0x37U, 0x54U, 0xD3U, 0x37U, - 0xCFU, 0x4DU, 0x71U, 0x04U, 0x91U, 0x08U, 0x1AU, 0xC6U, - 0xBDU, 0xEBU, 0x86U, 0xC5U, 0x5AU, 0x63U, 0x19U, 0xD5U, - 0xC5U, 0xCBU, 0x82U, 0xC3U, 0x54U, 0x57U, 0xD8U, 0x6CU, - 0x8FU, 0x9AU, 0xF1U, 0x7BU, 0x08U, 0x61U, 0xFCU, 0x96U, - 0x1AU, 0xCEU, 0x8FU, 0x11U, 0xE2U, 0xDDU, 0x96U, 0xA3U, - 0x57U, 0xD7U, 0x0DU, 0x28U, 0x06U, 0x0AU, 0xC5U, 0x1FU, - 0xBBU, 0xC6U, 0x67U, 0xC8U, 0xB0U, 0xA7U, 0xDAU, 0x00U, - 0xC3U, 0x00U, 0x21U, 0xACU, 0xFFU, 0xE9U, 0x4FU, 0xB7U, - 0x9AU, 0xC9U, 0x77U, 0xC3U, 0x96U, 0x6EU, 0x1CU, 0xC4U, - 0x61U, 0xAEU, 0x6FU, 0x55U, 0x0CU, 0xDAU, 0x68U, 0x48U, - 0x97U, 0xEDU, 0x9CU, 0x90U, 0x17U, 0x2AU, 0x2DU, 0xC9U, - 0x2AU, 0x77U, 0x87U, 0xECU, 0x64U, 0xF5U, 0x78U, 0x99U, - 0xA9U, 0xB9U, 0x11U, 0x05U, 0xE9U, 0x7BU, 0x3BU, 0x49U, - 0xAEU, 0x61U, 0x70U, 0x0BU, 0xBFU, 0xB7U, 0x67U, 0xA8U, - 0x9FU, 0x02U, 0x30U, 0xD3U, 0x0BU, 0x14U, 0xF0U, 0x89U, - 0x95U, 0x87U, 0x5BU, 0x04U, 0xF3U, 0x27U, 0xEFU, 0x91U, - 0x4AU, 0xD4U, 0x7FU, 0x9EU, 0x73U, 0x95U, 0xE5U, 0x48U, - 0x7FU, 0xE4U, 0xF6U, 0x92U, 0x85U, 0x47U, 0xA5U, 0xFEU, - 0x12U, 0xD7U, 0xC4U, 0x9EU, 0xCFU, 0x8AU, 0xC2U, 0xD2U, - 0x10U, 0x94U, 0xE5U, 0x58U, 0xBBU, 0xE0U, 0xEEU, 0xD9U, - 0x6AU, 0x59U, 0xD9U, 0xBCU, 0xD5U, 0xCDU, 0xA0U, 0xBCU, - 0xD7U, 0x96U, 0xAAU, 0x23U, 0xA9U, 0x10U, 0x6CU, 0x7EU, - - ) - - val randomBlock1 = ArgonBlock(randomBlockAsArray).getBlockPointer() - val randomBlock2 = ArgonBlock(randomBlockAsArray2).getBlockPointer() - val randomBlock3 = ArgonBlock(randomBlockAsArray3).getBlockPointer() - val resultWithoutXorAndAllocations = Argon2Utils.compressionFunctionG(randomBlock1, randomBlock2, randomBlock3, false) - assertTrue { - expectedWithoutXor.contentEquals(resultWithoutXorAndAllocations.getAsUByteArray()) - } - } - - @Test - fun compressionFunctionGWithXor() { - val expectedWithXor = ubyteArrayOf( - - 0x44U, 0xD8U, 0x76U, 0x1AU, 0xD5U, 0x31U, 0xA5U, 0xEDU, - 0xFAU, 0xABU, 0x43U, 0x60U, 0x21U, 0xB6U, 0x7DU, 0x28U, - 0x65U, 0xF4U, 0xAFU, 0x07U, 0x1DU, 0x01U, 0xB4U, 0x50U, - 0x85U, 0x3DU, 0x03U, 0x4CU, 0x33U, 0x58U, 0x8FU, 0xDCU, - 0x10U, 0xDEU, 0x26U, 0xF4U, 0xEDU, 0x58U, 0xD1U, 0x84U, - 0x7AU, 0x0AU, 0x05U, 0xC7U, 0x6BU, 0xA4U, 0xADU, 0x31U, - 0x18U, 0x5DU, 0x11U, 0x10U, 0x5FU, 0x2FU, 0x5EU, 0x6CU, - 0x3DU, 0x7EU, 0x3BU, 0xA8U, 0x92U, 0x61U, 0x80U, 0x84U, - 0xD1U, 0x45U, 0x83U, 0x85U, 0xE6U, 0x14U, 0x4CU, 0x98U, - 0x30U, 0xC1U, 0xB5U, 0x7FU, 0x50U, 0x56U, 0x71U, 0x43U, - 0xEAU, 0x84U, 0x38U, 0x2AU, 0x42U, 0x95U, 0xF6U, 0x28U, - 0x97U, 0x6BU, 0x86U, 0x6AU, 0x67U, 0x83U, 0xD1U, 0x87U, - 0xA6U, 0x19U, 0x05U, 0x7AU, 0x11U, 0xA1U, 0x6EU, 0x10U, - 0xCFU, 0x51U, 0x6CU, 0xE6U, 0x63U, 0x32U, 0x45U, 0xBCU, - 0x6BU, 0x40U, 0xDBU, 0x8FU, 0x47U, 0x5BU, 0x4BU, 0x36U, - 0x3CU, 0xB4U, 0xC8U, 0xF2U, 0x0AU, 0xE1U, 0xE1U, 0xFEU, - 0x1FU, 0x8BU, 0xE4U, 0x36U, 0x75U, 0xEBU, 0x70U, 0x52U, - 0x1DU, 0xE8U, 0xDEU, 0xD0U, 0xC4U, 0x7CU, 0x9CU, 0x33U, - 0xC7U, 0x42U, 0x69U, 0x85U, 0x3FU, 0x99U, 0x75U, 0x59U, - 0x9BU, 0xBEU, 0x02U, 0xC0U, 0xBEU, 0xC7U, 0x24U, 0xD0U, - 0x66U, 0xD2U, 0x99U, 0xD5U, 0x43U, 0xECU, 0x8FU, 0xA2U, - 0x17U, 0x10U, 0x56U, 0x1DU, 0x23U, 0xBAU, 0x33U, 0xF9U, - 0x9AU, 0xEBU, 0x6BU, 0x0FU, 0x32U, 0x95U, 0x5BU, 0xB5U, - 0x74U, 0x1DU, 0x22U, 0x36U, 0x1FU, 0x49U, 0xD6U, 0xC2U, - 0xC0U, 0xEAU, 0xA1U, 0x07U, 0x73U, 0x9CU, 0x85U, 0x78U, - 0xD6U, 0x63U, 0x98U, 0x44U, 0x7FU, 0x98U, 0x80U, 0x6BU, - 0xC5U, 0x99U, 0x35U, 0xBCU, 0xB3U, 0xAAU, 0x8FU, 0xEBU, - 0x32U, 0x62U, 0xAEU, 0xF7U, 0xAEU, 0x23U, 0x96U, 0xCBU, - 0x58U, 0x84U, 0x50U, 0xA7U, 0x4CU, 0x85U, 0x7BU, 0xE3U, - 0x32U, 0xE4U, 0xFAU, 0x66U, 0x25U, 0x60U, 0x64U, 0xA2U, - 0x6FU, 0xE2U, 0x68U, 0xBDU, 0x61U, 0x5DU, 0x2CU, 0xD3U, - 0x58U, 0xE2U, 0xC5U, 0x8CU, 0x42U, 0xC9U, 0x9CU, 0xECU, - 0x62U, 0xE5U, 0xA9U, 0xC3U, 0x20U, 0x72U, 0x59U, 0x6AU, - 0xF1U, 0xEAU, 0x54U, 0xEAU, 0xE6U, 0x80U, 0x09U, 0x8BU, - 0x55U, 0x6CU, 0xDDU, 0x26U, 0x69U, 0xFDU, 0x25U, 0x97U, - 0xDCU, 0xAFU, 0x1BU, 0x04U, 0x08U, 0xC2U, 0x54U, 0xBAU, - 0xACU, 0xCBU, 0x97U, 0x7AU, 0xDBU, 0x59U, 0x8FU, 0x7DU, - 0x95U, 0xB4U, 0x41U, 0x8AU, 0xC9U, 0xB4U, 0xF3U, 0xC0U, - 0x5BU, 0x75U, 0x4EU, 0xE9U, 0x24U, 0x7FU, 0x8CU, 0xA1U, - 0x05U, 0x6EU, 0x3BU, 0x3EU, 0xBDU, 0x03U, 0xE4U, 0x41U, - 0x26U, 0x58U, 0x09U, 0xC1U, 0xE6U, 0x8EU, 0x22U, 0x59U, - 0x3BU, 0xEEU, 0x21U, 0x5BU, 0x43U, 0x37U, 0x65U, 0xD2U, - 0x13U, 0x6CU, 0xF8U, 0x06U, 0x48U, 0xADU, 0x09U, 0x9AU, - 0xE1U, 0xE5U, 0x0CU, 0x2DU, 0x52U, 0xADU, 0x3BU, 0xC7U, - 0xE7U, 0x78U, 0x7EU, 0xCDU, 0x1EU, 0xE9U, 0x7AU, 0x5DU, - 0x54U, 0x89U, 0x1EU, 0xEFU, 0xA2U, 0x44U, 0xF4U, 0x38U, - 0xE7U, 0xB5U, 0x0FU, 0xC8U, 0x1FU, 0x7EU, 0x9CU, 0x93U, - 0x88U, 0x71U, 0xAEU, 0x19U, 0x0DU, 0x0FU, 0xCFU, 0xF1U, - 0xCFU, 0x67U, 0x94U, 0x0FU, 0x5FU, 0xB2U, 0xC3U, 0x8FU, - 0xE8U, 0xC3U, 0x07U, 0x0EU, 0xECU, 0x99U, 0x36U, 0x57U, - 0x7AU, 0xA6U, 0xA9U, 0x44U, 0x5BU, 0x68U, 0x5AU, 0xB4U, - 0xBFU, 0xA9U, 0xC9U, 0xE5U, 0xC8U, 0x20U, 0x31U, 0xD2U, - 0xE9U, 0x3EU, 0x6FU, 0x09U, 0x8FU, 0x7DU, 0x75U, 0x0EU, - 0x35U, 0xE8U, 0x90U, 0x04U, 0xB8U, 0x4AU, 0x12U, 0xE5U, - 0xC0U, 0xCCU, 0x6AU, 0xB0U, 0x9FU, 0x8FU, 0xAFU, 0x8CU, - 0x83U, 0x13U, 0x43U, 0x8EU, 0x5FU, 0x8AU, 0x1EU, 0xD3U, - 0xF2U, 0x9AU, 0xE5U, 0x95U, 0x6DU, 0xAEU, 0x4DU, 0xDBU, - 0x0CU, 0x06U, 0xDEU, 0x5CU, 0xD0U, 0x68U, 0xFFU, 0x4CU, - 0xECU, 0x82U, 0xC8U, 0xAFU, 0x44U, 0xC0U, 0x3BU, 0x0BU, - 0x89U, 0xADU, 0x32U, 0xAEU, 0xE7U, 0x36U, 0x2AU, 0x05U, - 0x18U, 0x5FU, 0xB9U, 0xBDU, 0x52U, 0x7FU, 0x73U, 0x70U, - 0x5AU, 0x5BU, 0x88U, 0x20U, 0x16U, 0x84U, 0xECU, 0x91U, - 0xF7U, 0xD2U, 0x2FU, 0x6DU, 0x69U, 0x37U, 0xEAU, 0x2BU, - 0x24U, 0xA2U, 0x58U, 0xDAU, 0x01U, 0x32U, 0x91U, 0x94U, - 0x53U, 0x4DU, 0xBDU, 0x28U, 0xEAU, 0x70U, 0x75U, 0x77U, - 0xD7U, 0x5DU, 0xF0U, 0xAAU, 0x5AU, 0x39U, 0xB9U, 0xC7U, - 0xDBU, 0xC0U, 0xCFU, 0x72U, 0x6DU, 0xB0U, 0x04U, 0xBDU, - 0x34U, 0x58U, 0x2AU, 0x6BU, 0x46U, 0xEDU, 0x7DU, 0x1AU, - 0x15U, 0x85U, 0xD3U, 0x14U, 0xC6U, 0xF9U, 0x32U, 0x72U, - 0x9AU, 0xD9U, 0x1AU, 0xBFU, 0xBDU, 0x3CU, 0x45U, 0x46U, - 0x17U, 0x6DU, 0xAEU, 0x1EU, 0x12U, 0xE5U, 0x00U, 0x6DU, - 0xD4U, 0xC0U, 0x71U, 0x8BU, 0xAFU, 0x12U, 0x7BU, 0x1EU, - 0x73U, 0xD7U, 0x68U, 0x9EU, 0x45U, 0xC1U, 0x85U, 0xD9U, - 0x15U, 0x6EU, 0xCAU, 0xCCU, 0x75U, 0x62U, 0x20U, 0x27U, - 0x26U, 0x6AU, 0xFAU, 0x5FU, 0xB4U, 0x9FU, 0xDFU, 0x2EU, - 0x3DU, 0x5BU, 0xE5U, 0x2BU, 0xEEU, 0x56U, 0x5CU, 0x91U, - 0x28U, 0x56U, 0x7DU, 0x16U, 0x78U, 0x63U, 0xB5U, 0x3BU, - 0x51U, 0xA3U, 0x96U, 0x52U, 0xDAU, 0x8EU, 0xBBU, 0x92U, - 0xA0U, 0xD3U, 0xBDU, 0xB8U, 0xA1U, 0x4CU, 0x83U, 0xEDU, - 0x4EU, 0x29U, 0xBEU, 0x9FU, 0x73U, 0x55U, 0x47U, 0x7AU, - 0x31U, 0x30U, 0xFBU, 0x41U, 0x9DU, 0x89U, 0x26U, 0xF6U, - 0x19U, 0x48U, 0x6CU, 0xB9U, 0xD0U, 0x11U, 0x8DU, 0xF8U, - 0x8FU, 0x0FU, 0xB1U, 0x15U, 0x96U, 0xA9U, 0x06U, 0x4EU, - 0x01U, 0xCCU, 0x48U, 0xBDU, 0x65U, 0x2FU, 0x27U, 0x67U, - 0x74U, 0x89U, 0x54U, 0x24U, 0x88U, 0xF8U, 0x1EU, 0x90U, - 0xFBU, 0xFFU, 0xD1U, 0x57U, 0xE2U, 0x95U, 0x97U, 0x2BU, - 0x67U, 0x6EU, 0x6CU, 0xACU, 0x63U, 0x2CU, 0x96U, 0x61U, - 0xBEU, 0x58U, 0xD8U, 0xE4U, 0x0FU, 0x94U, 0x27U, 0x4AU, - 0x75U, 0x1CU, 0xE1U, 0x49U, 0xCDU, 0xFCU, 0x17U, 0xEAU, - 0x68U, 0x0EU, 0x1AU, 0x86U, 0xFBU, 0xF6U, 0x27U, 0x87U, - 0x48U, 0xBFU, 0x49U, 0x9AU, 0xB2U, 0x9EU, 0xAAU, 0xA9U, - 0x7DU, 0x30U, 0x0AU, 0x21U, 0x16U, 0xD5U, 0x82U, 0x86U, - 0x11U, 0x0EU, 0x9FU, 0xB0U, 0xC5U, 0x1CU, 0xBAU, 0xA7U, - 0xB1U, 0x31U, 0x49U, 0x41U, 0x27U, 0x26U, 0xCEU, 0xDDU, - 0xC4U, 0x45U, 0xA8U, 0xD5U, 0xC0U, 0x11U, 0xACU, 0xCCU, - 0x9CU, 0x2EU, 0x04U, 0xB0U, 0xF8U, 0x87U, 0x29U, 0x8EU, - 0x0FU, 0x53U, 0xF9U, 0xC9U, 0x69U, 0xFFU, 0x17U, 0x18U, - 0x25U, 0x95U, 0x9EU, 0x88U, 0x03U, 0xC7U, 0xE9U, 0xC5U, - 0xC6U, 0x2AU, 0xD0U, 0x91U, 0x7DU, 0x93U, 0xBDU, 0x77U, - 0xB8U, 0xF1U, 0x5FU, 0x8CU, 0x83U, 0xE1U, 0x85U, 0x65U, - 0x36U, 0xFAU, 0x43U, 0x90U, 0xBCU, 0x8EU, 0x12U, 0x1AU, - 0xF0U, 0xF3U, 0x04U, 0x1FU, 0x77U, 0x6FU, 0xB8U, 0x52U, - 0xFDU, 0xA3U, 0x6BU, 0x3DU, 0xFEU, 0xD8U, 0x86U, 0x14U, - 0x10U, 0xFFU, 0xCFU, 0xF2U, 0xC7U, 0x06U, 0xE9U, 0x02U, - 0x5CU, 0xFDU, 0x39U, 0xBBU, 0x3CU, 0x68U, 0xA2U, 0xBAU, - 0x84U, 0x02U, 0xDAU, 0xD2U, 0x10U, 0x80U, 0xD6U, 0xCAU, - 0xEAU, 0xDBU, 0xB9U, 0xAEU, 0xAEU, 0x85U, 0xBEU, 0xCDU, - 0x72U, 0xCFU, 0xCFU, 0x6CU, 0xA0U, 0xFBU, 0x5CU, 0x74U, - 0xADU, 0x4EU, 0x92U, 0x37U, 0xDBU, 0xD5U, 0x28U, 0x71U, - 0x35U, 0xD0U, 0xACU, 0xE7U, 0x71U, 0xE1U, 0xB7U, 0x9AU, - 0x2EU, 0x3FU, 0x8DU, 0xB8U, 0x10U, 0xC1U, 0xEEU, 0x35U, - 0x0BU, 0x83U, 0xA3U, 0xF0U, 0xBAU, 0xFCU, 0x75U, 0x43U, - 0x95U, 0x86U, 0x4CU, 0x0AU, 0x22U, 0xE8U, 0xDCU, 0x7DU, - 0x6EU, 0xB8U, 0xF8U, 0xE2U, 0x97U, 0x57U, 0x06U, 0xB4U, - 0x89U, 0xCAU, 0x9DU, 0xD5U, 0xDEU, 0xB6U, 0x48U, 0xCDU, - 0x29U, 0x3CU, 0xDFU, 0x7EU, 0x1EU, 0x37U, 0xCEU, 0x48U, - 0x20U, 0x5CU, 0xE3U, 0xCDU, 0x2FU, 0xA8U, 0xE5U, 0xC0U, - 0xB7U, 0xABU, 0xDFU, 0xDBU, 0x8DU, 0xD8U, 0x5DU, 0xF7U, - 0xA7U, 0x5CU, 0xF7U, 0xFFU, 0xD2U, 0x04U, 0xA5U, 0xE1U, - 0x35U, 0xE3U, 0x67U, 0xCEU, 0x42U, 0xC1U, 0x3EU, 0xABU, - 0x4AU, 0xFFU, 0x02U, 0x9AU, 0x94U, 0x9CU, 0x9AU, 0xC5U, - 0xDCU, 0xC1U, 0x50U, 0x52U, 0x1CU, 0x04U, 0xF9U, 0x23U, - 0x6DU, 0xA6U, 0x5AU, 0x9BU, 0xAAU, 0x5EU, 0x08U, 0xD1U, - 0xCCU, 0x35U, 0x29U, 0xF5U, 0x3DU, 0xAAU, 0xB3U, 0x25U, - 0xB6U, 0x07U, 0x29U, 0x4DU, 0x75U, 0x3CU, 0xADU, 0x17U, - 0xBEU, 0xD5U, 0xC0U, 0xDFU, 0x05U, 0xFEU, 0xB8U, 0x2DU, - 0x52U, 0xECU, 0xA7U, 0x67U, 0x6EU, 0xBAU, 0x32U, 0xE4U, - 0xD6U, 0x31U, 0x13U, 0x83U, 0xFDU, 0xEBU, 0xEBU, 0x91U, - - - ) - - val randomBlock1 = ArgonBlock(randomBlockAsArray).getBlockPointer() - val randomBlock2 = ArgonBlock(randomBlockAsArray2).getBlockPointer() - val randomBlock3 = ArgonBlock(randomBlockAsArray3).getBlockPointer() - val resultWithoutXorAndAllocations = Argon2Utils.compressionFunctionG(randomBlock1, randomBlock2, randomBlock3, true) - assertTrue { - expectedWithXor.contentEquals(resultWithoutXorAndAllocations.getAsUByteArray()) - } - } - - -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2BTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2BTest.kt deleted file mode 100644 index b90cbd6..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2BTest.kt +++ /dev/null @@ -1,295 +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.hash.blake2b - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import kotlin.test.Test -import kotlin.test.assertFailsWith -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jul-2019 - */ - - -class Blake2BTest { - - @Test - fun testMultipleBlocks() { - val test = "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" - - val result = Blake2bPure.digest(test.encodeToUByteArray()) - //Generated with b2sum 8.31 - val expectedResult = ubyteArrayOf( - //@formatter:off - 0x2fU, 0x49U, 0xaeU, 0xb6U, 0x13U, 0xe3U, 0x4eU, 0x92U, 0x4eU, 0x17U, 0x5aU, 0x6aU, 0xf2U, 0xfaU, 0xadU, - 0x7bU, 0xc7U, 0x82U, 0x35U, 0xf9U, 0xc5U, 0xe4U, 0x61U, 0xc6U, 0x8fU, 0xd5U, 0xb4U, 0x07U, 0xeeU, 0x8eU, - 0x2fU, 0x0dU, 0x2fU, 0xb4U, 0xc0U, 0x7dU, 0x7eU, 0x4aU, 0x72U, 0x40U, 0x46U, 0x12U, 0xd9U, 0x28U, 0x99U, - 0xafU, 0x8aU, 0x32U, 0x8fU, 0x3bU, 0x61U, 0x4eU, 0xd7U, 0x72U, 0x44U, 0xb4U, 0x81U, 0x15U, 0x1dU, 0x40U, - 0xb1U, 0x1eU, 0x32U, 0xa4U - //@formatter:on - ) - - assertTrue { - result.contentEquals(expectedResult) - } - } - - @Test - fun singleBlockTest() { - val test = "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" + - "1234567890" - - - val result = Blake2bPure.digest(test.encodeToUByteArray()) - val expectedResultString = "800bb78cd4da18995c8074713bb674" + - "3cd94b2b6490a693fe4000ed00833b88b7b474d94af9cfed246b1b" + - "4ce1935a76154d7ea7c410493557741d18ec3a08da75" - val expectedResult = expectedResultString.hexStringToUByteArray() - - assertTrue { - result.contentEquals(expectedResult) - } - } - - - @Test - fun testDigest() { - val test = "111111111122222222223333333333333" - - val result = Blake2bPure.digest(test.encodeToUByteArray()) - //Generated with b2sum 8.31 - val expectedResult = ubyteArrayOf( - //@formatter:off - 0xe0U, 0xabU, 0xb7U, 0x5dU, 0xb2U, 0xc8U, 0xe1U, 0x3cU, 0x5fU, 0x1dU, 0x9fU, 0x55U, 0xc8U, 0x4eU, 0xacU, 0xd7U, - 0xa8U, 0x44U, 0x57U, 0x9bU, 0xc6U, 0x9cU, 0x47U, 0x26U, 0xebU, 0xeaU, 0x2bU, 0xafU, 0x9eU, 0x44U, 0x16U, 0xebU, - 0xb8U, 0x0aU, 0xc5U, 0xfbU, 0xb0U, 0xe8U, 0xe5U, 0x6eU, 0xc5U, 0x49U, 0x0dU, 0x75U, 0x59U, 0x32U, 0x13U, 0xb4U, - 0x76U, 0x50U, 0x5eU, 0x6aU, 0xd8U, 0x74U, 0x67U, 0x14U, 0x64U, 0xb0U, 0xf8U, 0xb5U, 0x50U, 0x60U, 0x62U, 0xfbU - //@formatter:on - ) - - assertTrue { - result.contentEquals(expectedResult) - } - - } - - @Test - fun testFigestWithKey() { - val test = "abc" - val key = "key" - - val result = Blake2bPure.digest(test.encodeToUByteArray(), key.encodeToUByteArray()) - - assertTrue { - result.isNotEmpty() - } - val expectedResult = ("5c6a9a4ae911c02fb7e71a991eb9aea371ae993d4842d206e" + - "6020d46f5e41358c6d5c277c110ef86c959ed63e6ecaaaceaaff38019a43264ae06acf73b9550b1") - .hexStringToUByteArray() - - assertTrue { - result.contentEquals(expectedResult) - } - } - - - @Test - fun testDigestFromRfc() { - val test = "abc" - - val result = Blake2bPure.digest(test.encodeToUByteArray()) - //@formatter:off - val expectedResult = ubyteArrayOf( - - 0xBAU,0x80U,0xA5U,0x3FU,0x98U,0x1CU,0x4DU,0x0DU,0x6AU,0x27U,0x97U,0xB6U,0x9FU,0x12U,0xF6U,0xE9U, - 0x4CU,0x21U,0x2FU,0x14U,0x68U,0x5AU,0xC4U,0xB7U,0x4BU,0x12U,0xBBU,0x6FU,0xDBU,0xFFU,0xA2U,0xD1U, - 0x7DU,0x87U,0xC5U,0x39U,0x2AU,0xABU,0x79U,0x2DU,0xC2U,0x52U,0xD5U,0xDEU,0x45U,0x33U,0xCCU,0x95U, - 0x18U,0xD3U,0x8AU,0xA8U,0xDBU,0xF1U,0x92U,0x5AU,0xB9U,0x23U,0x86U,0xEDU,0xD4U,0x00U,0x99U,0x23U - - ) - //@formatter:on - assertTrue { - result.contentEquals(expectedResult) - } - - } - - val message = arrayOf( - 0x0000000000636261UL, 0x0000000000000000UL, 0x0000000000000000UL, - 0x0000000000000000UL, 0x0000000000000000UL, 0x0000000000000000UL, - 0x0000000000000000UL, 0x0000000000000000UL, 0x0000000000000000UL, - 0x0000000000000000UL, 0x0000000000000000UL, 0x0000000000000000UL, - 0x0000000000000000UL, 0x0000000000000000UL, 0x0000000000000000UL, - 0x0000000000000000UL - ) - - val mixChain = arrayOf( - arrayOf( - 0x6A09E667F2BDC948UL, 0xBB67AE8584CAA73BUL, 0x3C6EF372FE94F82BUL, - 0xA54FF53A5F1D36F1UL, 0x510E527FADE682D1UL, 0x9B05688C2B3E6C1FUL, - 0x1F83D9ABFB41BD6BUL, 0x5BE0CD19137E2179UL, 0x6A09E667F3BCC908UL, - 0xBB67AE8584CAA73BUL, 0x3C6EF372FE94F82BUL, 0xA54FF53A5F1D36F1UL, - 0x510E527FADE682D2UL, 0x9B05688C2B3E6C1FUL, 0xE07C265404BE4294UL, - 0x5BE0CD19137E2179UL - ), - arrayOf( - 0x86B7C1568029BB79UL, 0xC12CBCC809FF59F3UL, 0xC6A5214CC0EACA8EUL, - 0x0C87CD524C14CC5DUL, 0x44EE6039BD86A9F7UL, 0xA447C850AA694A7EUL, - 0xDE080F1BB1C0F84BUL, 0x595CB8A9A1ACA66CUL, 0xBEC3AE837EAC4887UL, - 0x6267FC79DF9D6AD1UL, 0xFA87B01273FA6DBEUL, 0x521A715C63E08D8AUL, - 0xE02D0975B8D37A83UL, 0x1C7B754F08B7D193UL, 0x8F885A76B6E578FEUL, - 0x2318A24E2140FC64UL - ), - arrayOf( - 0x53281E83806010F2UL, 0x3594B403F81B4393UL, 0x8CD63C7462DE0DFFUL, - 0x85F693F3DA53F974UL, 0xBAABDBB2F386D9AEUL, 0xCA5425AEC65A10A8UL, - 0xC6A22E2FF0F7AA48UL, 0xC6A56A51CB89C595UL, 0x224E6A3369224F96UL, - 0x500E125E58A92923UL, 0xE9E4AD0D0E1A0D48UL, 0x85DF9DC143C59A74UL, - 0x92A3AAAA6D952B7FUL, 0xC5FDF71090FAE853UL, 0x2A8A40F15A462DD0UL, - 0x572D17EFFDD37358UL - ), - arrayOf( - 0x60ED96AA7AD41725UL, 0xE46A743C71800B9DUL, 0x1A04B543A01F156BUL, - 0xA2F8716E775C4877UL, 0xDA0A61BCDE4267EAUL, 0xB1DD230754D7BDEEUL, - 0x25A1422779E06D14UL, 0xE6823AE4C3FF58A5UL, 0xA1677E19F37FD5DAUL, - 0x22BDCE6976B08C51UL, 0xF1DE8696BEC11BF1UL, 0xA0EBD586A4A1D2C8UL, - 0xC804EBAB11C99FA9UL, 0x8E0CEC959C715793UL, 0x7C45557FAE0D4D89UL, - 0x716343F52FDD265EUL - ), - arrayOf( - 0xBB2A77D3A8382351UL, 0x45EB47971F23B103UL, 0x98BE297F6E45C684UL, - 0xA36077DEE3370B89UL, 0x8A03C4CB7E97590AUL, 0x24192E49EBF54EA0UL, - 0x4F82C9401CB32D7AUL, 0x8CCD013726420DC4UL, 0xA9C9A8F17B1FC614UL, - 0x55908187977514A0UL, 0x5B44273E66B19D27UL, 0xB6D5C9FCA2579327UL, - 0x086092CFB858437EUL, 0x5C4BE2156DBEECF9UL, 0x2EFEDE99ED4EFF16UL, - 0x3E7B5F234CD1F804UL - ), - arrayOf( - 0xC79C15B3D423B099UL, 0x2DA2224E8DA97556UL, 0x77D2B26DF1C45C55UL, - 0x8934EB09A3456052UL, 0x0F6D9EEED157DA2AUL, 0x6FE66467AF88C0A9UL, - 0x4EB0B76284C7AAFBUL, 0x299C8E725D954697UL, 0xB2240B59E6D567D3UL, - 0x2643C2370E49EBFDUL, 0x79E02EEF20CDB1AEUL, 0x64B3EED7BB602F39UL, - 0xB97D2D439E4DF63DUL, 0xC718E755294C9111UL, 0x1F0893F2772BB373UL, - 0x1205EA4A7859807DUL - ), - arrayOf( - 0xE58F97D6385BAEE4UL, 0x7640AA9764DA137AUL, 0xDEB4C7C23EFE287EUL, - 0x70F6F41C8783C9F6UL, 0x7127CD48C76A7708UL, 0x9E472AF0BE3DB3F6UL, - 0x0F244C62DDF71788UL, 0x219828AA83880842UL, 0x41CCA9073C8C4D0DUL, - 0x5C7912BC10DF3B4BUL, 0xA2C3ABBD37510EE2UL, 0xCB5668CC2A9F7859UL, - 0x8733794F07AC1500UL, 0xC67A6BE42335AA6FUL, 0xACB22B28681E4C82UL, - 0xDB2161604CBC9828UL - ), - arrayOf( - 0x6E2D286EEADEDC81UL, 0xBCF02C0787E86358UL, 0x57D56A56DD015EDFUL, - 0x55D899D40A5D0D0AUL, 0x819415B56220C459UL, 0xB63C479A6A769F02UL, - 0x258E55E0EC1F362AUL, 0x3A3B4EC60E19DFDCUL, 0x04D769B3FCB048DBUL, - 0xB78A9A33E9BFF4DDUL, 0x5777272AE1E930C0UL, 0x5A387849E578DBF6UL, - 0x92AAC307CF2C0AFCUL, 0x30AACCC4F06DAFAAUL, 0x483893CC094F8863UL, - 0xE03C6CC89C26BF92UL - ), - arrayOf( - 0xFFC83ECE76024D01UL, 0x1BE7BFFB8C5CC5F9UL, 0xA35A18CBAC4C65B7UL, - 0xB7C2C7E6D88C285FUL, 0x81937DA314A50838UL, 0xE1179523A2541963UL, - 0x3A1FAD7106232B8FUL, 0x1C7EDE92AB8B9C46UL, 0xA3C2D35E4F685C10UL, - 0xA53D3F73AA619624UL, 0x30BBCC0285A22F65UL, 0xBCEFBB6A81539E5DUL, - 0x3841DEF6F4C9848AUL, 0x98662C85FBA726D4UL, 0x7762439BD5A851BDUL, - 0xB0B9F0D443D1A889UL - ), - arrayOf( - 0x753A70A1E8FAEADDUL, 0x6B0D43CA2C25D629UL, 0xF8343BA8B94F8C0BUL, - 0xBC7D062B0DB5CF35UL, 0x58540EE1B1AEBC47UL, 0x63C5B9B80D294CB9UL, - 0x490870ECAD27DEBDUL, 0xB2A90DDF667287FEUL, 0x316CC9EBEEFAD8FCUL, - 0x4A466BCD021526A4UL, 0x5DA7F7638CEC5669UL, 0xD9C8826727D306FCUL, - 0x88ED6C4F3BD7A537UL, 0x19AE688DDF67F026UL, 0x4D8707AAB40F7E6DUL, - 0xFD3F572687FEA4F1UL - ), - arrayOf( - 0xE630C747CCD59C4FUL, 0xBC713D41127571CAUL, 0x46DB183025025078UL, - 0x6727E81260610140UL, 0x2D04185EAC2A8CBAUL, 0x5F311B88904056ECUL, - 0x40BD313009201AABUL, 0x0099D4F82A2A1EABUL, 0x6DD4FBC1DE60165DUL, - 0xB3B0B51DE3C86270UL, 0x900AEE2F233B08E5UL, 0xA07199D87AD058D8UL, - 0x2C6B25593D717852UL, 0x37E8CA471BEAA5F8UL, 0x2CFC1BAC10EF4457UL, - 0x01369EC18746E775UL - ), - arrayOf( - 0xE801F73B9768C760UL, 0x35C6D22320BE511DUL, 0x306F27584F65495EUL, - 0xB51776ADF569A77BUL, 0xF4F1BE86690B3C34UL, 0x3CC88735D1475E4BUL, - 0x5DAC67921FF76949UL, 0x1CDB9D31AD70CC4EUL, 0x35BA354A9C7DF448UL, - 0x4929CBE45679D73EUL, 0x733D1A17248F39DBUL, 0x92D57B736F5F170AUL, - 0x61B5C0A41D491399UL, 0xB5C333457E12844AUL, 0xBD696BE010D0D889UL, - 0x02231E1A917FE0BDUL - ), - arrayOf( - 0x12EF8A641EC4F6D6UL, 0xBCED5DE977C9FAF5UL, 0x733CA476C5148639UL, - 0x97DF596B0610F6FCUL, 0xF42C16519AD5AFA7UL, 0xAA5AC1888E10467EUL, - 0x217D930AA51787F3UL, 0x906A6FF19E573942UL, 0x75AB709BD3DCBF24UL, - 0xEE7CE1F345947AA4UL, 0xF8960D6C2FAF5F5EUL, 0xE332538A36B6D246UL, - 0x885BEF040EF6AA0BUL, 0xA4939A417BFB78A3UL, 0x646CBB7AF6DCE980UL, - 0xE813A23C60AF3B82UL - ) - ) - - @Test - fun testMixRound() { - for (i in 0 until mixChain.size - 1) { - val inputRound = mixChain[i] - val round = i - val result = Blake2bPure.mixRound(inputRound, message, round) - val expectedResult = mixChain[i + 1] - assertTrue { - result.contentEquals(expectedResult) - } - } - - - } - - @Test - fun testInvalidHashLength() { - val test = "1234567890" - assertFailsWith(RuntimeException::class) { - val result = Blake2bPure.digest(test.encodeToUByteArray(), hashLength = 65) - } - } - -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bInstanceTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bInstanceTest.kt deleted file mode 100644 index 68cb23e..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bInstanceTest.kt +++ /dev/null @@ -1,94 +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.hash.blake2b - -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ - - -class Blake2bInstanceTest { - - @Test - fun testUpdatableBlake2b() { - val updates = 14 - val input = "1234567890" - val expectedResult = ubyteArrayOf( - //@formatter:off - 0x2fU, 0x49U, 0xaeU, 0xb6U, 0x13U, 0xe3U, 0x4eU, 0x92U, 0x4eU, 0x17U, 0x5aU, 0x6aU, 0xf2U, 0xfaU, 0xadU, - 0x7bU, 0xc7U, 0x82U, 0x35U, 0xf9U, 0xc5U, 0xe4U, 0x61U, 0xc6U, 0x8fU, 0xd5U, 0xb4U, 0x07U, 0xeeU, 0x8eU, - 0x2fU, 0x0dU, 0x2fU, 0xb4U, 0xc0U, 0x7dU, 0x7eU, 0x4aU, 0x72U, 0x40U, 0x46U, 0x12U, 0xd9U, 0x28U, 0x99U, - 0xafU, 0x8aU, 0x32U, 0x8fU, 0x3bU, 0x61U, 0x4eU, 0xd7U, 0x72U, 0x44U, 0xb4U, 0x81U, 0x15U, 0x1dU, 0x40U, - 0xb1U, 0x1eU, 0x32U, 0xa4U - //@formatter:on - ) - - val blake2b = Blake2bPure() - for (i in 0 until updates) { - blake2b.update(input) - } - val result = blake2b.digest() - - assertTrue { - result.contentEquals(expectedResult) - } - } - - @Test - fun testDigestToString() { - val updates = 14 - val input = "1234567890" - val expectedResult = "2F49AEB613E34E924E175A6AF2FAAD7BC78235F9C5E461C68FD5B407E".toLowerCase() + - "E8E2F0D2FB4C07D7E4A72404612D92899AF8A328F3B614ED77244B481151D40B11E32A4".toLowerCase() - - val blake2b = Blake2bPure() - for (i in 0 until updates) { - blake2b.update(input) - } - val result = blake2b.digest().toHexString() - assertTrue { - result == expectedResult - } - } - - @Test - fun testDigestWithKey() { - val test = "abc" - val key = "key" - val blake2b = Blake2bPure(key) - blake2b.update(test) - val result = blake2b.digest() - - assertTrue { - result.isNotEmpty() - } - val expectedResult = ("5c6a9a4ae911c02fb7e71a991eb9aea371ae993d4842d206e" + - "6020d46f5e41358c6d5c277c110ef86c959ed63e6ecaaaceaaff38019a43264ae06acf73b9550b1") - .hexStringToUByteArray() - - assertTrue { - result.contentEquals(expectedResult) - } - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bKnowAnswerTests.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bKnowAnswerTests.kt deleted file mode 100644 index 21fb963..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bKnowAnswerTests.kt +++ /dev/null @@ -1,1603 +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.hash.blake2b - -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 15-Jul-2019 - */ -data class KnownAnswerTest( - val input: String, - val key: String, - val hash: String -) - - - -class Blake2bKnowAnswerTests { - @Test - fun knownAnswerTest() { - kat.forEach { - val parsedInput = it.input.hexStringToUByteArray() - val result = Blake2bPure.digest( - inputMessage = parsedInput, - key = it.key.hexStringToUByteArray() - ) - assertTrue { - result.contentEquals(it.hash.hexStringToUByteArray()) - } - } - } - - @Test - fun knownAnswerTestInstance() { - - kat.forEach { kat -> - val parsedInput = kat.input.hexStringToUByteArray() - val chunkedInput = parsedInput.toList().chunked(128).map { it.toUByteArray() } - val blake2b = Blake2bPure(key = kat.key.hexStringToUByteArray()) - chunkedInput.forEach { blake2b.update(it) } - val result = blake2b.digest() - assertTrue("KAT ${kat.input} \nkey: ${kat.key} \nexpected: {${kat.hash}") { - result.contentEquals(kat.hash.hexStringToUByteArray()) - } - } - } - - val kat = arrayOf( - KnownAnswerTest( - input = "", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "10ebb67700b1868efb4417987acf4690ae9d972fb7a590c2f02871799aaa4786b5e996e8f0f4eb981fc214b005f42d2ff4233499391653df7aefcbc13fc51568" - ), - - KnownAnswerTest( - input = "00", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "961f6dd1e4dd30f63901690c512e78e4b45e4742ed197c3c5e45c549fd25f2e4187b0bc9fe30492b16b0d0bc4ef9b0f34c7003fac09a5ef1532e69430234cebd" - ), - - KnownAnswerTest( - input = "0001", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "da2cfbe2d8409a0f38026113884f84b50156371ae304c4430173d08a99d9fb1b983164a3770706d537f49e0c916d9f32b95cc37a95b99d857436f0232c88a965" - ), - - KnownAnswerTest( - input = "000102", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "33d0825dddf7ada99b0e7e307104ad07ca9cfd9692214f1561356315e784f3e5a17e364ae9dbb14cb2036df932b77f4b292761365fb328de7afdc6d8998f5fc1" - ), - - KnownAnswerTest( - input = "00010203", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "beaa5a3d08f3807143cf621d95cd690514d0b49efff9c91d24b59241ec0eefa5f60196d407048bba8d2146828ebcb0488d8842fd56bb4f6df8e19c4b4daab8ac" - ), - - KnownAnswerTest( - input = "0001020304", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "098084b51fd13deae5f4320de94a688ee07baea2800486689a8636117b46c1f4c1f6af7f74ae7c857600456a58a3af251dc4723a64cc7c0a5ab6d9cac91c20bb" - ), - - KnownAnswerTest( - input = "000102030405", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "6044540d560853eb1c57df0077dd381094781cdb9073e5b1b3d3f6c7829e12066bbaca96d989a690de72ca3133a83652ba284a6d62942b271ffa2620c9e75b1f" - ), - - KnownAnswerTest( - input = "00010203040506", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "7a8cfe9b90f75f7ecb3acc053aaed6193112b6f6a4aeeb3f65d3de541942deb9e2228152a3c4bbbe72fc3b12629528cfbb09fe630f0474339f54abf453e2ed52" - ), - - KnownAnswerTest( - input = "0001020304050607", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "380beaf6ea7cc9365e270ef0e6f3a64fb902acae51dd5512f84259ad2c91f4bc4108db73192a5bbfb0cbcf71e46c3e21aee1c5e860dc96e8eb0b7b8426e6abe9" - ), - - KnownAnswerTest( - input = "000102030405060708", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "60fe3c4535e1b59d9a61ea8500bfac41a69dffb1ceadd9aca323e9a625b64da5763bad7226da02b9c8c4f1a5de140ac5a6c1124e4f718ce0b28ea47393aa6637" - ), - - KnownAnswerTest( - input = "00010203040506070809", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "4fe181f54ad63a2983feaaf77d1e7235c2beb17fa328b6d9505bda327df19fc37f02c4b6f0368ce23147313a8e5738b5fa2a95b29de1c7f8264eb77b69f585cd" - ), - - KnownAnswerTest( - input = "000102030405060708090a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f228773ce3f3a42b5f144d63237a72d99693adb8837d0e112a8a0f8ffff2c362857ac49c11ec740d1500749dac9b1f4548108bf3155794dcc9e4082849e2b85b" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "962452a8455cc56c8511317e3b1f3b2c37df75f588e94325fdd77070359cf63a9ae6e930936fdf8e1e08ffca440cfb72c28f06d89a2151d1c46cd5b268ef8563" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "43d44bfa18768c59896bf7ed1765cb2d14af8c260266039099b25a603e4ddc5039d6ef3a91847d1088d401c0c7e847781a8a590d33a3c6cb4df0fab1c2f22355" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "dcffa9d58c2a4ca2cdbb0c7aa4c4c1d45165190089f4e983bb1c2cab4aaeff1fa2b5ee516fecd780540240bf37e56c8bcca7fab980e1e61c9400d8a9a5b14ac6" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "6fbf31b45ab0c0b8dad1c0f5f4061379912dde5aa922099a030b725c73346c524291adef89d2f6fd8dfcda6d07dad811a9314536c2915ed45da34947e83de34e" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "a0c65bddde8adef57282b04b11e7bc8aab105b99231b750c021f4a735cb1bcfab87553bba3abb0c3e64a0b6955285185a0bd35fb8cfde557329bebb1f629ee93" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f10", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f99d815550558e81eca2f96718aed10d86f3f1cfb675cce06b0eff02f617c5a42c5aa760270f2679da2677c5aeb94f1142277f21c7f79f3c4f0cce4ed8ee62b1" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f1011", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "95391da8fc7b917a2044b3d6f5374e1ca072b41454d572c7356c05fd4bc1e0f40b8bb8b4a9f6bce9be2c4623c399b0dca0dab05cb7281b71a21b0ebcd9e55670" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "04b9cd3d20d221c09ac86913d3dc63041989a9a1e694f1e639a3ba7e451840f750c2fc191d56ad61f2e7936bc0ac8e094b60caeed878c18799045402d61ceaf9" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f10111213", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ec0e0ef707e4ed6c0c66f9e089e4954b058030d2dd86398fe84059631f9ee591d9d77375355149178c0cf8f8e7c49ed2a5e4f95488a2247067c208510fadc44c" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f1011121314", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "9a37cce273b79c09913677510eaf7688e89b3314d3532fd2764c39de022a2945b5710d13517af8ddc0316624e73bec1ce67df15228302036f330ab0cb4d218dd" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "4cf9bb8fb3d4de8b38b2f262d3c40f46dfe747e8fc0a414c193d9fcf753106ce47a18f172f12e8a2f1c26726545358e5ee28c9e2213a8787aafbc516d2343152" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f10111213141516", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "64e0c63af9c808fd893137129867fd91939d53f2af04be4fa268006100069b2d69daa5c5d8ed7fddcb2a70eeecdf2b105dd46a1e3b7311728f639ab489326bc9" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f1011121314151617", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "5e9c93158d659b2def06b0c3c7565045542662d6eee8a96a89b78ade09fe8b3dcc096d4fe48815d88d8f82620156602af541955e1f6ca30dce14e254c326b88f" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "7775dff889458dd11aef417276853e21335eb88e4dec9cfb4e9edb49820088551a2ca60339f12066101169f0dfe84b098fddb148d9da6b3d613df263889ad64b" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f10111213141516171819", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f0d2805afbb91f743951351a6d024f9353a23c7ce1fc2b051b3a8b968c233f46f50f806ecb1568ffaa0b60661e334b21dde04f8fa155ac740eeb42e20b60d764" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "86a2af316e7d7754201b942e275364ac12ea8962ab5bd8d7fb276dc5fbffc8f9a28cae4e4867df6780d9b72524160927c855da5b6078e0b554aa91e31cb9ca1d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "10bdf0caa0802705e706369baf8a3f79d72c0a03a80675a7bbb00be3a45e516424d1ee88efb56f6d5777545ae6e27765c3a8f5e493fc308915638933a1dfee55" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b01781092b1748459e2e4ec178696627bf4ebafebba774ecf018b79a68aeb84917bf0b84bb79d17b743151144cd66b7b33a4b9e52c76c4e112050ff5385b7f0b" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c6dbc61dec6eaeac81e3d5f755203c8e220551534a0b2fd105a91889945a638550204f44093dd998c076205dffad703a0e5cd3c7f438a7e634cd59fededb539e" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "eba51acffb4cea31db4b8d87e9bf7dd48fe97b0253ae67aa580f9ac4a9d941f2bea518ee286818cc9f633f2a3b9fb68e594b48cdd6d515bf1d52ba6c85a203a7" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "86221f3ada52037b72224f105d7999231c5e5534d03da9d9c0a12acb68460cd375daf8e24386286f9668f72326dbf99ba094392437d398e95bb8161d717f8991" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "5595e05c13a7ec4dc8f41fb70cb50a71bce17c024ff6de7af618d0cc4e9c32d9570d6d3ea45b86525491030c0d8f2b1836d5778c1ce735c17707df364d054347" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ce0f4f6aca89590a37fe034dd74dd5fa65eb1cbd0a41508aaddc09351a3cea6d18cb2189c54b700c009f4cbf0521c7ea01be61c5ae09cb54f27bc1b44d658c82" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "7ee80b06a215a3bca970c77cda8761822bc103d44fa4b33f4d07dcb997e36d55298bceae12241b3fa07fa63be5576068da387b8d5859aeab701369848b176d42" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "940a84b6a84d109aab208c024c6ce9647676ba0aaa11f86dbb7018f9fd2220a6d901a9027f9abcf935372727cbf09ebd61a2a2eeb87653e8ecad1bab85dc8327" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "2020b78264a82d9f4151141adba8d44bf20c5ec062eee9b595a11f9e84901bf148f298e0c9f8777dcdbc7cc4670aac356cc2ad8ccb1629f16f6a76bcefbee760" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d1b897b0e075ba68ab572adf9d9c436663e43eb3d8e62d92fc49c9be214e6f27873fe215a65170e6bea902408a25b49506f47babd07cecf7113ec10c5dd31252" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223242526", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b14d0c62abfa469a357177e594c10c194243ed2025ab8aa5ad2fa41ad318e0ff48cd5e60bec07b13634a711d2326e488a985f31e31153399e73088efc86a5c55" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324252627", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "4169c5cc808d2697dc2a82430dc23e3cd356dc70a94566810502b8d655b39abf9e7f902fe717e0389219859e1945df1af6ada42e4ccda55a197b7100a30c30a1" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "258a4edb113d66c839c8b1c91f15f35ade609f11cd7f8681a4045b9fef7b0b24c82cda06a5f2067b368825e3914e53d6948ede92efd6e8387fa2e537239b5bee" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223242526272829", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "79d2d8696d30f30fb34657761171a11e6c3f1e64cbe7bebee159cb95bfaf812b4f411e2f26d9c421dc2c284a3342d823ec293849e42d1e46b0a4ac1e3c86abaa" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8b9436010dc5dee992ae38aea97f2cd63b946d94fedd2ec9671dcde3bd4ce9564d555c66c15bb2b900df72edb6b891ebcadfeff63c9ea4036a998be7973981e7" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c8f68e696ed28242bf997f5b3b34959508e42d613810f1e2a435c96ed2ff560c7022f361a9234b9837feee90bf47922ee0fd5f8ddf823718d86d1e16c6090071" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b02d3eee4860d5868b2c39ce39bfe81011290564dd678c85e8783f29302dfc1399ba95b6b53cd9ebbf400cca1db0ab67e19a325f2d115812d25d00978ad1bca4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "7693ea73af3ac4dad21ca0d8da85b3118a7d1c6024cfaf557699868217bc0c2f44a199bc6c0edd519798ba05bd5b1b4484346a47c2cadf6bf30b785cc88b2baf" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "a0e5c1c0031c02e48b7f09a5e896ee9aef2f17fc9e18e997d7f6cac7ae316422c2b1e77984e5f3a73cb45deed5d3f84600105e6ee38f2d090c7d0442ea34c46d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "41daa6adcfdb69f1440c37b596440165c15ada596813e2e22f060fcd551f24dee8e04ba6890387886ceec4a7a0d7fc6b44506392ec3822c0d8c1acfc7d5aebe8" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "14d4d40d5984d84c5cf7523b7798b254e275a3a8cc0a1bd06ebc0bee726856acc3cbf516ff667cda2058ad5c3412254460a82c92187041363cc77a4dc215e487" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d0e7a1e2b9a447fee83e2277e9ff8010c2f375ae12fa7aaa8ca5a6317868a26a367a0b69fbc1cf32a55d34eb370663016f3d2110230eba754028a56f54acf57c" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e771aa8db5a3e043e8178f39a0857ba04a3f18e4aa05743cf8d222b0b095825350ba422f63382a23d92e4149074e816a36c1cd28284d146267940b31f8818ea2" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "feb4fd6f9e87a56bef398b3284d2bda5b5b0e166583a66b61e538457ff0584872c21a32962b9928ffab58de4af2edd4e15d8b35570523207ff4e2a5aa7754caa" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "462f17bf005fb1c1b9e671779f665209ec2873e3e411f98dabf240a1d5ec3f95ce6796b6fc23fe171903b502023467dec7273ff74879b92967a2a43a5a183d33" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d3338193b64553dbd38d144bea71c5915bb110e2d88180dbc5db364fd6171df317fc7268831b5aef75e4342b2fad8797ba39eddcef80e6ec08159350b1ad696d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e1590d585a3d39f7cb599abd479070966409a6846d4377acf4471d065d5db94129cc9be92573b05ed226be1e9b7cb0cabe87918589f80dadd4ef5ef25a93d28e" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f8f3726ac5a26cc80132493a6fedcb0e60760c09cfc84cad178175986819665e76842d7b9fedf76dddebf5d3f56faaad4477587af21606d396ae570d8e719af2" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "30186055c07949948183c850e9a756cc09937e247d9d928e869e20bafc3cd9721719d34e04a0899b92c736084550186886efba2e790d8be6ebf040b209c439a4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536373839", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f3c4276cb863637712c241c444c5cc1e3554e0fddb174d035819dd83eb700b4ce88df3ab3841ba02085e1a99b4e17310c5341075c0458ba376c95a6818fbb3e2" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "0aa007c4dd9d5832393040a1583c930bca7dc5e77ea53add7e2b3f7c8e231368043520d4a3ef53c969b6bbfd025946f632bd7f765d53c21003b8f983f75e2a6a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "08e9464720533b23a04ec24f7ae8c103145f765387d738777d3d343477fd1c58db052142cab754ea674378e18766c53542f71970171cc4f81694246b717d7564" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d37ff7ad297993e7ec21e0f1b4b5ae719cdc83c5db687527f27516cbffa822888a6810ee5c1ca7bfe3321119be1ab7bfa0a502671c8329494df7ad6f522d440f" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "dd9042f6e464dcf86b1262f6accfafbd8cfd902ed3ed89abf78ffa482dbdeeb6969842394c9a1168ae3d481a017842f660002d42447c6b22f7b72f21aae021c9" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "bd965bf31e87d70327536f2a341cebc4768eca275fa05ef98f7f1b71a0351298de006fba73fe6733ed01d75801b4a928e54231b38e38c562b2e33ea1284992fa" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "65676d800617972fbd87e4b9514e1c67402b7a331096d3bfac22f1abb95374abc942f16e9ab0ead33b87c91968a6e509e119ff07787b3ef483e1dcdccf6e3022" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "939fa189699c5d2c81ddd1ffc1fa207c970b6a3685bb29ce1d3e99d42f2f7442da53e95a72907314f4588399a3ff5b0a92beb3f6be2694f9f86ecf2952d5b41c" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c516541701863f91005f314108ceece3c643e04fc8c42fd2ff556220e616aaa6a48aeb97a84bad74782e8dff96a1a2fa949339d722edcaa32b57067041df88cc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "987fd6e0d6857c553eaebb3d34970a2c2f6e89a3548f492521722b80a1c21a153892346d2cba6444212d56da9a26e324dccbc0dcde85d4d2ee4399eec5a64e8f" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ae56deb1c2328d9c4017706bce6e99d41349053ba9d336d677c4c27d9fd50ae6aee17e853154e1f4fe7672346da2eaa31eea53fcf24a22804f11d03da6abfc2b" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "49d6a608c9bde4491870498572ac31aac3fa40938b38a7818f72383eb040ad39532bc06571e13d767e6945ab77c0bdc3b0284253343f9f6c1244ebf2ff0df866" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "da582ad8c5370b4469af862aa6467a2293b2b28bd80ae0e91f425ad3d47249fdf98825cc86f14028c3308c9804c78bfeeeee461444ce243687e1a50522456a1d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243444546", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d5266aa3331194aef852eed86d7b5b2633a0af1c735906f2e13279f14931a9fc3b0eac5ce9245273bd1aa92905abe16278ef7efd47694789a7283b77da3c70f8" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344454647", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "2962734c28252186a9a1111c732ad4de4506d4b4480916303eb7991d659ccda07a9911914bc75c418ab7a4541757ad054796e26797feaf36e9f6ad43f14b35a4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e8b79ec5d06e111bdfafd71e9f5760f00ac8ac5d8bf768f9ff6f08b8f026096b1cc3a4c973333019f1e3553e77da3f98cb9f542e0a90e5f8a940cc58e59844b3" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243444546474849", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "dfb320c44f9d41d1efdcc015f08dd5539e526e39c87d509ae6812a969e5431bf4fa7d91ffd03b981e0d544cf72d7b1c0374f8801482e6dea2ef903877eba675e" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d88675118fdb55a5fb365ac2af1d217bf526ce1ee9c94b2f0090b2c58a06ca58187d7fe57c7bed9d26fca067b4110eefcd9a0a345de872abe20de368001b0745" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b893f2fc41f7b0dd6e2f6aa2e0370c0cff7df09e3acfcc0e920b6e6fad0ef747c40668417d342b80d2351e8c175f20897a062e9765e6c67b539b6ba8b9170545" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "6c67ec5697accd235c59b486d7b70baeedcbd4aa64ebd4eef3c7eac189561a726250aec4d48cadcafbbe2ce3c16ce2d691a8cce06e8879556d4483ed7165c063" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f1aa2b044f8f0c638a3f362e677b5d891d6fd2ab0765f6ee1e4987de057ead357883d9b405b9d609eea1b869d97fb16d9b51017c553f3b93c0a1e0f1296fedcd" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "cbaa259572d4aebfc1917acddc582b9f8dfaa928a198ca7acd0f2aa76a134a90252e6298a65b08186a350d5b7626699f8cb721a3ea5921b753ae3a2dce24ba3a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "fa1549c9796cd4d303dcf452c1fbd5744fd9b9b47003d920b92de34839d07ef2a29ded68f6fc9e6c45e071a2e48bd50c5084e96b657dd0404045a1ddefe282ed" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "5cf2ac897ab444dcb5c8d87c495dbdb34e1838b6b629427caa51702ad0f9688525f13bec503a3c3a2c80a65e0b5715e8afab00ffa56ec455a49a1ad30aa24fcd" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "9aaf80207bace17bb7ab145757d5696bde32406ef22b44292ef65d4519c3bb2ad41a59b62cc3e94b6fa96d32a7faadae28af7d35097219aa3fd8cda31e40c275" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "af88b163402c86745cb650c2988fb95211b94b03ef290eed9662034241fd51cf398f8073e369354c43eae1052f9b63b08191caa138aa54fea889cc7024236897" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "48fa7d64e1ceee27b9864db5ada4b53d00c9bc7626555813d3cd6730ab3cc06ff342d727905e33171bde6e8476e77fb1720861e94b73a2c538d254746285f430" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051525354", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "0e6fd97a85e904f87bfe85bbeb34f69e1f18105cf4ed4f87aec36c6e8b5f68bd2a6f3dc8a9ecb2b61db4eedb6b2ea10bf9cb0251fb0f8b344abf7f366b6de5ab" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "06622da5787176287fdc8fed440bad187d830099c94e6d04c8e9c954cda70c8bb9e1fc4a6d0baa831b9b78ef6648681a4867a11da93ee36e5e6a37d87fc63f6f" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253545556", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "1da6772b58fabf9c61f68d412c82f182c0236d7d575ef0b58dd22458d643cd1dfc93b03871c316d8430d312995d4197f0874c99172ba004a01ee295abac24e46" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051525354555657", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3cd2d9320b7b1d5fb9aab951a76023fa667be14a9124e394513918a3f44096ae4904ba0ffc150b63bc7ab1eeb9a6e257e5c8f000a70394a5afd842715de15f29" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "04cdc14f7434e0b4be70cb41db4c779a88eaef6accebcb41f2d42fffe7f32a8e281b5c103a27021d0d08362250753cdf70292195a53a48728ceb5844c2d98bab" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253545556575859", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "9071b7a8a075d0095b8fb3ae5113785735ab98e2b52faf91d5b89e44aac5b5d4ebbf91223b0ff4c71905da55342e64655d6ef8c89a4768c3f93a6dc0366b5bc8" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ebb30240dd96c7bc8d0abe49aa4edcbb4afdc51ff9aaf720d3f9e7fbb0f9c6d6571350501769fc4ebd0b2141247ff400d4fd4be414edf37757bb90a32ac5c65a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8532c58bf3c8015d9d1cbe00eef1f5082f8f3632fbe9f1ed4f9dfb1fa79e8283066d77c44c4af943d76b300364aecbd0648c8a8939bd204123f4b56260422dec" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "fe9846d64f7c7708696f840e2d76cb4408b6595c2f81ec6a28a7f2f20cb88cfe6ac0b9e9b8244f08bd7095c350c1d0842f64fb01bb7f532dfcd47371b0aeeb79" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "28f17ea6fb6c42092dc264257e29746321fb5bdaea9873c2a7fa9d8f53818e899e161bc77dfe8090afd82bf2266c5c1bc930a8d1547624439e662ef695f26f24" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ec6b7d7f030d4850acae3cb615c21dd25206d63e84d1db8d957370737ba0e98467ea0ce274c66199901eaec18a08525715f53bfdb0aacb613d342ebdceeddc3b" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b403d3691c03b0d3418df327d5860d34bbfcc4519bfbce36bf33b208385fadb9186bc78a76c489d89fd57e7dc75412d23bcd1dae8470ce9274754bb8585b13c5" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "31fc79738b8772b3f55cd8178813b3b52d0db5a419d30ba9495c4b9da0219fac6df8e7c23a811551a62b827f256ecdb8124ac8a6792ccfecc3b3012722e94463" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "bb2039ec287091bcc9642fc90049e73732e02e577e2862b32216ae9bedcd730c4c284ef3968c368b7d37584f97bd4b4dc6ef6127acfe2e6ae2509124e66c8af4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f53d68d13f45edfcb9bd415e2831e938350d5380d3432278fc1c0c381fcb7c65c82dafe051d8c8b0d44e0974a0e59ec7bf7ed0459f86e96f329fc79752510fd3" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8d568c7984f0ecdf7640fbc483b5d8c9f86634f6f43291841b309a350ab9c1137d24066b09da9944bac54d5bb6580d836047aac74ab724b887ebf93d4b32eca9" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c0b65ce5a96ff774c456cac3b5f2c4cd359b4ff53ef93a3da0778be4900d1e8da1601e769e8f1b02d2a2f8c5b9fa10b44f1c186985468feeb008730283a6657d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "4900bba6f5fb103ece8ec96ada13a5c3c85488e05551da6b6b33d988e611ec0fe2e3c2aa48ea6ae8986a3a231b223c5d27cec2eadde91ce07981ee652862d1e4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263646566", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c7f5c37c7285f927f76443414d4357ff789647d7a005a5a787e03c346b57f49f21b64fa9cf4b7e45573e23049017567121a9c3d4b2b73ec5e9413577525db45a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364656667", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ec7096330736fdb2d64b5653e7475da746c23a4613a82687a28062d3236364284ac01720ffb406cfe265c0df626a188c9e5963ace5d3d5bb363e32c38c2190a6" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "82e744c75f4649ec52b80771a77d475a3bc091989556960e276a5f9ead92a03f718742cdcfeaee5cb85c44af198adc43a4a428f5f0c2ddb0be36059f06d7df73" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263646566676869", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "2834b7a7170f1f5b68559ab78c1050ec21c919740b784a9072f6e5d69f828d70c919c5039fb148e39e2c8a52118378b064ca8d5001cd10a5478387b966715ed6" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "16b4ada883f72f853bb7ef253efcab0c3e2161687ad61543a0d2824f91c1f81347d86be709b16996e17f2dd486927b0288ad38d13063c4a9672c39397d3789b6" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "78d048f3a69d8b54ae0ed63a573ae350d89f7c6cf1f3688930de899afa037697629b314e5cd303aa62feea72a25bf42b304b6c6bcb27fae21c16d925e1fbdac3" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "0f746a48749287ada77a82961f05a4da4abdb7d77b1220f836d09ec814359c0ec0239b8c7b9ff9e02f569d1b301ef67c4612d1de4f730f81c12c40cc063c5caa" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f0fc859d3bd195fbdc2d591e4cdac15179ec0f1dc821c11df1f0c1d26e6260aaa65b79fafacafd7d3ad61e600f250905f5878c87452897647a35b995bcadc3a3" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "2620f687e8625f6a412460b42e2cef67634208ce10a0cbd4dff7044a41b7880077e9f8dc3b8d1216d3376a21e015b58fb279b521d83f9388c7382c8505590b9b" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "227e3aed8d2cb10b918fcb04f9de3e6d0a57e08476d93759cd7b2ed54a1cbf0239c528fb04bbf288253e601d3bc38b21794afef90b17094a182cac557745e75f" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "1a929901b09c25f27d6b35be7b2f1c4745131fdebca7f3e2451926720434e0db6e74fd693ad29b777dc3355c592a361c4873b01133a57c2e3b7075cbdb86f4fc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "5fd7968bc2fe34f220b5e3dc5af9571742d73b7d60819f2888b629072b96a9d8ab2d91b82d0a9aaba61bbd39958132fcc4257023d1eca591b3054e2dc81c8200" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "dfcce8cf32870cc6a503eadafc87fd6f78918b9b4d0737db6810be996b5497e7e5cc80e312f61e71ff3e9624436073156403f735f56b0b01845c18f6caf772e6" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "02f7ef3a9ce0fff960f67032b296efca3061f4934d690749f2d01c35c81c14f39a67fa350bc8a0359bf1724bffc3bca6d7c7bba4791fd522a3ad353c02ec5aa8" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071727374", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "64be5c6aba65d594844ae78bb022e5bebe127fd6b6ffa5a13703855ab63b624dcd1a363f99203f632ec386f3ea767fc992e8ed9686586aa27555a8599d5b808f" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f78585505c4eaa54a8b5be70a61e735e0ff97af944ddb3001e35d86c4e2199d976104b6ae31750a36a726ed285064f5981b503889fef822fcdc2898dddb7889a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273747576", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e4b5566033869572edfd87479a5bb73c80e8759b91232879d96b1dda36c012076ee5a2ed7ae2de63ef8406a06aea82c188031b560beafb583fb3de9e57952a7e" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071727374757677", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e1b3e7ed867f6c9484a2a97f7715f25e25294e992e41f6a7c161ffc2adc6daaeb7113102d5e6090287fe6ad94ce5d6b739c6ca240b05c76fb73f25dd024bf935" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "85fd085fdc12a080983df07bd7012b0d402a0f4043fcb2775adf0bad174f9b08d1676e476985785c0a5dcc41dbff6d95ef4d66a3fbdc4a74b82ba52da0512b74" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273747576777879", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "aed8fa764b0fbff821e05233d2f7b0900ec44d826f95e93c343c1bc3ba5a24374b1d616e7e7aba453a0ada5e4fab5382409e0d42ce9c2bc7fb39a99c340c20f0" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "7ba3b2e297233522eeb343bd3ebcfd835a04007735e87f0ca300cbee6d416565162171581e4020ff4cf176450f1291ea2285cb9ebffe4c56660627685145051c" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "de748bcf89ec88084721e16b85f30adb1a6134d664b5843569babc5bbd1a15ca9b61803c901a4fef32965a1749c9f3a4e243e173939dc5a8dc495c671ab52145" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "aaf4d2bdf200a919706d9842dce16c98140d34bc433df320aba9bd429e549aa7a3397652a4d768277786cf993cde2338673ed2e6b66c961fefb82cd20c93338f" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c408218968b788bf864f0997e6bc4c3dba68b276e2125a4843296052ff93bf5767b8cdce7131f0876430c1165fec6c4f47adaa4fd8bcfacef463b5d3d0fa61a0" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "76d2d819c92bce55fa8e092ab1bf9b9eab237a25267986cacf2b8ee14d214d730dc9a5aa2d7b596e86a1fd8fa0804c77402d2fcd45083688b218b1cdfa0dcbcb" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "72065ee4dd91c2d8509fa1fc28a37c7fc9fa7d5b3f8ad3d0d7a25626b57b1b44788d4caf806290425f9890a3a2a35a905ab4b37acfd0da6e4517b2525c9651e4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "64475dfe7600d7171bea0b394e27c9b00d8e74dd1e416a79473682ad3dfdbb706631558055cfc8a40e07bd015a4540dcdea15883cbbf31412df1de1cd4152b91" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "12cd1674a4488a5d7c2b3160d2e2c4b58371bedad793418d6f19c6ee385d70b3e06739369d4df910edb0b0a54cbff43d54544cd37ab3a06cfa0a3ddac8b66c89" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "60756966479dedc6dd4bcff8ea7d1d4ce4d4af2e7b097e32e3763518441147cc12b3c0ee6d2ecabf1198cec92e86a3616fba4f4e872f5825330adbb4c1dee444" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "a7803bcb71bc1d0f4383dde1e0612e04f872b715ad30815c2249cf34abb8b024915cb2fc9f4e7cc4c8cfd45be2d5a91eab0941c7d270e2da4ca4a9f7ac68663a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081828384", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b84ef6a7229a34a750d9a98ee2529871816b87fbe3bc45b45fa5ae82d5141540211165c3c5d7a7476ba5a4aa06d66476f0d9dc49a3f1ee72c3acabd498967414" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "fae4b6d8efc3f8c8e64d001dabec3a21f544e82714745251b2b4b393f2f43e0da3d403c64db95a2cb6e23ebb7b9e94cdd5ddac54f07c4a61bd3cb10aa6f93b49" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283848586", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "34f7286605a122369540141ded79b8957255da2d4155abbf5a8dbb89c8eb7ede8eeef1daa46dc29d751d045dc3b1d658bb64b80ff8589eddb3824b13da235a6b" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081828384858687", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3b3b48434be27b9eababba43bf6b35f14b30f6a88dc2e750c358470d6b3aa3c18e47db4017fa55106d8252f016371a00f5f8b070b74ba5f23cffc5511c9f09f0" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ba289ebd6562c48c3e10a8ad6ce02e73433d1e93d7c9279d4d60a7e879ee11f441a000f48ed9f7c4ed87a45136d7dccdca482109c78a51062b3ba4044ada2469" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283848586878889", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "022939e2386c5a37049856c850a2bb10a13dfea4212b4c732a8840a9ffa5faf54875c5448816b2785a007da8a8d2bc7d71a54e4e6571f10b600cbdb25d13ede3" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e6fec19d89ce8717b1a087024670fe026f6c7cbda11caef959bb2d351bf856f8055d1c0ebdaaa9d1b17886fc2c562b5e99642fc064710c0d3488a02b5ed7f6fd" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "94c96f02a8f576aca32ba61c2b206f907285d9299b83ac175c209a8d43d53bfe683dd1d83e7549cb906c28f59ab7c46f8751366a28c39dd5fe2693c9019666c8" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "31a0cd215ebd2cb61de5b9edc91e6195e31c59a5648d5c9f737e125b2605708f2e325ab3381c8dce1a3e958886f1ecdc60318f882cfe20a24191352e617b0f21" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "91ab504a522dce78779f4c6c6ba2e6b6db5565c76d3e7e7c920caf7f757ef9db7c8fcf10e57f03379ea9bf75eb59895d96e149800b6aae01db778bb90afbc989" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d85cabc6bd5b1a01a5afd8c6734740da9fd1c1acc6db29bfc8a2e5b668b028b6b3154bfb8703fa3180251d589ad38040ceb707c4bad1b5343cb426b61eaa49c1" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d62efbec2ca9c1f8bd66ce8b3f6a898cb3f7566ba6568c618ad1feb2b65b76c3ce1dd20f7395372faf28427f61c9278049cf0140df434f5633048c86b81e0399" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "7c8fdc6175439e2c3db15bafa7fb06143a6a23bc90f449e79deef73c3d492a671715c193b6fea9f036050b946069856b897e08c00768f5ee5ddcf70b7cd6d0e0" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "58602ee7468e6bc9df21bd51b23c005f72d6cb013f0a1b48cbec5eca299299f97f09f54a9a01483eaeb315a6478bad37ba47ca1347c7c8fc9e6695592c91d723" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "27f5b79ed256b050993d793496edf4807c1d85a7b0a67c9c4fa99860750b0ae66989670a8ffd7856d7ce411599e58c4d77b232a62bef64d15275be46a68235ff" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3957a976b9f1887bf004a8dca942c92d2b37ea52600f25e0c9bc5707d0279c00c6e85a839b0d2d8eb59c51d94788ebe62474a791cadf52cccf20f5070b6573fc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091929394", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "eaa2376d55380bf772ecca9cb0aa4668c95c707162fa86d518c8ce0ca9bf7362b9f2a0adc3ff59922df921b94567e81e452f6c1a07fc817cebe99604b3505d38" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c1e2c78b6b2734e2480ec550434cb5d613111adcc21d475545c3b1b7e6ff12444476e5c055132e2229dc0f807044bb919b1a5662dd38a9ee65e243a3911aed1a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293949596", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8ab48713389dd0fcf9f965d3ce66b1e559a1f8c58741d67683cd971354f452e62d0207a65e436c5d5d8f8ee71c6abfe50e669004c302b31a7ea8311d4a916051" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091929394959697", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "24ce0addaa4c65038bd1b1c0f1452a0b128777aabc94a29df2fd6c7e2f85f8ab9ac7eff516b0e0a825c84a24cfe492eaad0a6308e46dd42fe8333ab971bb30ca" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "5154f929ee03045b6b0c0004fa778edee1d139893267cc84825ad7b36c63de32798e4a166d24686561354f63b00709a1364b3c241de3febf0754045897467cd4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293949596979899", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e74e907920fd87bd5ad636dd11085e50ee70459c443e1ce5809af2bc2eba39f9e6d7128e0e3712c316da06f4705d78a4838e28121d4344a2c79c5e0db307a677" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "bf91a22334bac20f3fd80663b3cd06c4e8802f30e6b59f90d3035cc9798a217ed5a31abbda7fa6842827bdf2a7a1c21f6fcfccbb54c6c52926f32da816269be1" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d9d5c74be5121b0bd742f26bffb8c89f89171f3f934913492b0903c271bbe2b3395ef259669bef43b57f7fcc3027db01823f6baee66e4f9fead4d6726c741fce" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "50c8b8cf34cd879f80e2faab3230b0c0e1cc3e9dcadeb1b9d97ab923415dd9a1fe38addd5c11756c67990b256e95ad6d8f9fedce10bf1c90679cde0ecf1be347" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "0a386e7cd5dd9b77a035e09fe6fee2c8ce61b5383c87ea43205059c5e4cd4f4408319bb0a82360f6a58e6c9ce3f487c446063bf813bc6ba535e17fc1826cfc91" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "1f1459cb6b61cbac5f0efe8fc487538f42548987fcd56221cfa7beb22504769e792c45adfb1d6b3d60d7b749c8a75b0bdf14e8ea721b95dca538ca6e25711209" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e58b3836b7d8fedbb50ca5725c6571e74c0785e97821dab8b6298c10e4c079d4a6cdf22f0fedb55032925c16748115f01a105e77e00cee3d07924dc0d8f90659" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b929cc6505f020158672deda56d0db081a2ee34c00c1100029bdf8ea98034fa4bf3e8655ec697fe36f40553c5bb46801644a627d3342f4fc92b61f03290fb381" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "72d353994b49d3e03153929a1e4d4f188ee58ab9e72ee8e512f29bc773913819ce057ddd7002c0433ee0a16114e3d156dd2c4a7e80ee53378b8670f23e33ef56" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c70ef9bfd775d408176737a0736d68517ce1aaad7e81a93c8c1ed967ea214f56c8a377b1763e676615b60f3988241eae6eab9685a5124929d28188f29eab06f7" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c230f0802679cb33822ef8b3b21bf7a9a28942092901d7dac3760300831026cf354c9232df3e084d9903130c601f63c1f4a4a4b8106e468cd443bbe5a734f45f" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "6f43094cafb5ebf1f7a4937ec50f56a4c9da303cbb55ac1f27f1f1976cd96beda9464f0e7b9c54620b8a9fba983164b8be3578425a024f5fe199c36356b88972" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3745273f4c38225db2337381871a0c6aafd3af9b018c88aa02025850a5dc3a42a1a3e03e56cbf1b0876d63a441f1d2856a39b8801eb5af325201c415d65e97fe" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c50c44cca3ec3edaae779a7e179450ebdda2f97067c690aa6c5a4ac7c30139bb27c0df4db3220e63cb110d64f37ffe078db72653e2daacf93ae3f0a2d1a7eb2e" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8aef263e385cbc61e19b28914243262af5afe8726af3ce39a79c27028cf3ecd3f8d2dfd9cfc9ad91b58f6f20778fd5f02894a3d91c7d57d1e4b866a7f364b6be" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "28696141de6e2d9bcb3235578a66166c1448d3e905a1b482d423be4bc5369bc8c74dae0acc9cc123e1d8ddce9f97917e8c019c552da32d39d2219b9abf0fa8c8" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "2fb9eb2085830181903a9dafe3db428ee15be7662224efd643371fb25646aee716e531eca69b2bdc8233f1a8081fa43da1500302975a77f42fa592136710e9dc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aa", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "66f9a7143f7a3314a669bf2e24bbb35014261d639f495b6c9c1f104fe8e320aca60d4550d69d52edbd5a3cdeb4014ae65b1d87aa770b69ae5c15f4330b0b0ad8" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaab", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f4c4dd1d594c3565e3e25ca43dad82f62abea4835ed4cd811bcd975e46279828d44d4c62c3679f1b7f7b9dd4571d7b49557347b8c5460cbdc1bef690fb2a08c0" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabac", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8f1dc9649c3a84551f8f6e91cac68242a43b1f8f328ee92280257387fa7559aa6db12e4aeadc2d26099178749c6864b357f3f83b2fb3efa8d2a8db056bed6bcc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacad", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3139c1a7f97afd1675d460ebbc07f2728aa150df849624511ee04b743ba0a833092f18c12dc91b4dd243f333402f59fe28abdbbbae301e7b659c7a26d5c0f979" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadae", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "06f94a2996158a819fe34c40de3cf0379fd9fb85b3e363ba3926a0e7d960e3f4c2e0c70c7ce0ccb2a64fc29869f6e7ab12bd4d3f14fce943279027e785fb5c29" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c29c399ef3eee8961e87565c1ce263925fc3d0ce267d13e48dd9e732ee67b0f69fad56401b0f10fcaac119201046cca28c5b14abdea3212ae65562f7f138db3d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "4cec4c9df52eef05c3f6faaa9791bc7445937183224ecc37a1e58d0132d35617531d7e795f52af7b1eb9d147de1292d345fe341823f8e6bc1e5badca5c656108" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "898bfbae93b3e18d00697eab7d9704fa36ec339d076131cefdf30edbe8d9cc81c3a80b129659b163a323bab9793d4feed92d54dae966c77529764a09be88db45" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ee9bd0469d3aaf4f14035be48a2c3b84d9b4b1fff1d945e1f1c1d38980a951be197b25fe22c731f20aeacc930ba9c4a1f4762227617ad350fdabb4e80273a0f4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3d4d3113300581cd96acbf091c3d0f3c310138cd6979e6026cde623e2dd1b24d4a8638bed1073344783ad0649cc6305ccec04beb49f31c633088a99b65130267" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "95c0591ad91f921ac7be6d9ce37e0663ed8011c1cfd6d0162a5572e94368bac02024485e6a39854aa46fe38e97d6c6b1947cd272d86b06bb5b2f78b9b68d559d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "227b79ded368153bf46c0a3ca978bfdbef31f3024a5665842468490b0ff748ae04e7832ed4c9f49de9b1706709d623e5c8c15e3caecae8d5e433430ff72f20eb" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "5d34f3952f0105eef88ae8b64c6ce95ebfade0e02c69b08762a8712d2e4911ad3f941fc4034dc9b2e479fdbcd279b902faf5d838bb2e0c6495d372b5b7029813" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "7f939bf8353abce49e77f14f3750af20b7b03902e1a1e7fb6aaf76d0259cd401a83190f15640e74f3e6c5a90e839c7821f6474757f75c7bf9002084ddc7a62dc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "062b61a2f9a33a71d7d0a06119644c70b0716a504de7e5e1be49bd7b86e7ed6817714f9f0fc313d06129597e9a2235ec8521de36f7290a90ccfc1ffa6d0aee29" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f29e01eeae64311eb7f1c6422f946bf7bea36379523e7b2bbaba7d1d34a22d5ea5f1c5a09d5ce1fe682cced9a4798d1a05b46cd72dff5c1b355440b2a2d476bc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9ba", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ec38cd3bbab3ef35d7cb6d5c914298351d8a9dc97fcee051a8a02f58e3ed6184d0b7810a5615411ab1b95209c3c810114fdeb22452084e77f3f847c6dbaafe16" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babb", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c2aef5e0ca43e82641565b8cb943aa8ba53550caef793b6532fafad94b816082f0113a3ea2f63608ab40437ecc0f0229cb8fa224dcf1c478a67d9b64162b92d1" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbc", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "15f534efff7105cd1c254d074e27d5898b89313b7d366dc2d7d87113fa7d53aae13f6dba487ad8103d5e854c91fdb6e1e74b2ef6d1431769c30767dde067a35c" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbd", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "89acbca0b169897a0a2714c2df8c95b5b79cb69390142b7d6018bb3e3076b099b79a964152a9d912b1b86412b7e372e9cecad7f25d4cbab8a317be36492a67d7" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbe", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e3c0739190ed849c9c962fd9dbb55e207e624fcac1eb417691515499eea8d8267b7e8f1287a63633af5011fde8c4ddf55bfdf722edf88831414f2cfaed59cb9a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8d6cf87c08380d2d1506eee46fd4222d21d8c04e585fbfd08269c98f702833a156326a0724656400ee09351d57b440175e2a5de93cc5f80db6daf83576cf75fa" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "da24bede383666d563eeed37f6319baf20d5c75d1635a6ba5ef4cfa1ac95487e96f8c08af600aab87c986ebad49fc70a58b4890b9c876e091016daf49e1d322e" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f9d1d1b1e87ea7ae753a029750cc1cf3d0157d41805e245c5617bb934e732f0ae3180b78e05bfe76c7c3051e3e3ac78b9b50c05142657e1e03215d6ec7bfd0fc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "11b7bc1668032048aa43343de476395e814bbbc223678db951a1b03a021efac948cfbe215f97fe9a72a2f6bc039e3956bfa417c1a9f10d6d7ba5d3d32ff323e5" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b8d9000e4fc2b066edb91afee8e7eb0f24e3a201db8b6793c0608581e628ed0bcc4e5aa6787992a4bcc44e288093e63ee83abd0bc3ec6d0934a674a4da13838a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ce325e294f9b6719d6b61278276ae06a2564c03bb0b783fafe785bdf89c7d5acd83e78756d301b445699024eaeb77b54d477336ec2a4f332f2b3f88765ddb0c3" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "29acc30e9603ae2fccf90bf97e6cc463ebe28c1b2f9b4b765e70537c25c702a29dcbfbf14c99c54345ba2b51f17b77b5f15db92bbad8fa95c471f5d070a137cc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3379cbaae562a87b4c0425550ffdd6bfe1203f0d666cc7ea095be407a5dfe61ee91441cd5154b3e53b4f5fb31ad4c7a9ad5c7af4ae679aa51a54003a54ca6b2d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3095a349d245708c7cf550118703d7302c27b60af5d4e67fc978f8a4e60953c7a04f92fcf41aee64321ccb707a895851552b1e37b00bc5e6b72fa5bcef9e3fff" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "07262d738b09321f4dbccec4bb26f48cb0f0ed246ce0b31b9a6e7bc683049f1f3e5545f28ce932dd985c5ab0f43bd6de0770560af329065ed2e49d34624c2cbb" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b6405eca8ee3316c87061cc6ec18dba53e6c250c63ba1f3bae9e55dd3498036af08cd272aa24d713c6020d77ab2f3919af1a32f307420618ab97e73953994fb4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9ca", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "7ee682f63148ee45f6e5315da81e5c6e557c2c34641fc509c7a5701088c38a74756168e2cd8d351e88fd1a451f360a01f5b2580f9b5a2e8cfc138f3dd59a3ffc" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacb", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "1d263c179d6b268f6fa016f3a4f29e943891125ed8593c81256059f5a7b44af2dcb2030d175c00e62ecaf7ee96682aa07ab20a611024a28532b1c25b86657902" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcc", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "106d132cbdb4cd2597812846e2bc1bf732fec5f0a5f65dbb39ec4e6dc64ab2ce6d24630d0f15a805c3540025d84afa98e36703c3dbee713e72dde8465bc1be7e" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccd", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "0e79968226650667a8d862ea8da4891af56a4e3a8b6d1750e394f0dea76d640d85077bcec2cc86886e506751b4f6a5838f7f0b5fef765d9dc90dcdcbaf079f08" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdce", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "521156a82ab0c4e566e5844d5e31ad9aaf144bbd5a464fdca34dbd5717e8ff711d3ffebbfa085d67fe996a34f6d3e4e60b1396bf4b1610c263bdbb834d560816" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecf", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "1aba88befc55bc25efbce02db8b9933e46f57661baeabeb21cc2574d2a518a3cba5dc5a38e49713440b25f9c744e75f6b85c9d8f4681f676160f6105357b8406" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "5a9949fcb2c473cda968ac1b5d08566dc2d816d960f57e63b898fa701cf8ebd3f59b124d95bfbbedc5f1cf0e17d5eaed0c02c50b69d8a402cabcca4433b51fd4" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b0cead09807c672af2eb2b0f06dde46cf5370e15a4096b1a7d7cbb36ec31c205fbefca00b7a4162fa89fb4fb3eb78d79770c23f44e7206664ce3cd931c291e5d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "bb6664931ec97044e45b2ae420ae1c551a8874bc937d08e969399c3964ebdba8346cdd5d09caafe4c28ba7ec788191ceca65ddd6f95f18583e040d0f30d0364d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "65bc770a5faa3792369803683e844b0be7ee96f29f6d6a35568006bd5590f9a4ef639b7a8061c7b0424b66b60ac34af3119905f33a9d8c3ae18382ca9b689900" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "ea9b4dca333336aaf839a45c6eaa48b8cb4c7ddabffea4f643d6357ea6628a480a5b45f2b052c1b07d1fedca918b6f1139d80f74c24510dcbaa4be70eacc1b06" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "e6342fb4a780ad975d0e24bce149989b91d360557e87994f6b457b895575cc02d0c15bad3ce7577f4c63927ff13f3e381ff7e72bdbe745324844a9d27e3f1c01" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3e209c9b33e8e461178ab46b1c64b49a07fb745f1c8bc95fbfb94c6b87c69516651b264ef980937fad41238b91ddc011a5dd777c7efd4494b4b6ecd3a9c22ac0" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "fd6a3d5b1875d80486d6e69694a56dbb04a99a4d051f15db2689776ba1c4882e6d462a603b7015dc9f4b7450f05394303b8652cfb404a266962c41bae6e18a94" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "951e27517e6bad9e4195fc8671dee3e7e9be69cee1422cb9fecfce0dba875f7b310b93ee3a3d558f941f635f668ff832d2c1d033c5e2f0997e4c66f147344e02" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8eba2f874f1ae84041903c7c4253c82292530fc8509550bfdc34c95c7e2889d5650b0ad8cb988e5c4894cb87fbfbb19612ea93ccc4c5cad17158b9763464b492" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9da", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "16f712eaa1b7c6354719a8e7dbdfaf55e4063a4d277d947550019b38dfb564830911057d50506136e2394c3b28945cc964967d54e3000c2181626cfb9b73efd2" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadb", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c39639e7d5c7fb8cdd0fd3e6a52096039437122f21c78f1679cea9d78a734c56ecbeb28654b4f18e342c331f6f7229ec4b4bc281b2d80a6eb50043f31796c88c" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdc", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "72d081af99f8a173dcc9a0ac4eb3557405639a29084b54a40172912a2f8a395129d5536f0918e902f9e8fa6000995f4168ddc5f893011be6a0dbc9b8a1a3f5bb" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdd", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c11aa81e5efd24d5fc27ee586cfd8847fbb0e27601ccece5ecca0198e3c7765393bb74457c7e7a27eb9170350e1fb53857177506be3e762cc0f14d8c3afe9077" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcddde", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c28f2150b452e6c0c424bcde6f8d72007f9310fed7f2f87de0dbb64f4479d6c1441ba66f44b2accee61609177ed340128b407ecec7c64bbe50d63d22d8627727" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f63d88122877ec30b8c8b00d22e89000a966426112bd44166e2f525b769ccbe9b286d437a0129130dde1a86c43e04bedb594e671d98283afe64ce331de9828fd" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "348b0532880b88a6614a8d7408c3f913357fbb60e995c60205be9139e74998aede7f4581e42f6b52698f7fa1219708c14498067fd1e09502de83a77dd281150c" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "5133dc8bef725359dff59792d85eaf75b7e1dcd1978b01c35b1b85fcebc63388ad99a17b6346a217dc1a9622ebd122ecf6913c4d31a6b52a695b86af00d741a0" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "2753c4c0e98ecad806e88780ec27fccd0f5c1ab547f9e4bf1659d192c23aa2cc971b58b6802580baef8adc3b776ef7086b2545c2987f348ee3719cdef258c403" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b1663573ce4b9d8caefc865012f3e39714b9898a5da6ce17c25a6a47931a9ddb9bbe98adaa553beed436e89578455416c2a52a525cf2862b8d1d49a2531b7391" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "64f58bd6bfc856f5e873b2a2956ea0eda0d6db0da39c8c7fc67c9f9feefcff3072cdf9e6ea37f69a44f0c61aa0da3693c2db5b54960c0281a088151db42b11e8" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "0764c7be28125d9065c4b98a69d60aede703547c66a12e17e1c618994132f5ef82482c1e3fe3146cc65376cc109f0138ed9a80e49f1f3c7d610d2f2432f20605" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "f748784398a2ff03ebeb07e155e66116a839741a336e32da71ec696001f0ad1b25cd48c69cfca7265eca1dd71904a0ce748ac4124f3571076dfa7116a9cf00e9" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3f0dbc0186bceb6b785ba78d2a2a013c910be157bdaffae81bb6663b1a73722f7f1228795f3ecada87cf6ef0078474af73f31eca0cc200ed975b6893f761cb6d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d4762cd4599876ca75b2b8fe249944dbd27ace741fdab93616cbc6e425460feb51d4e7adcc38180e7fc47c89024a7f56191adb878dfde4ead62223f5a2610efe" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "cd36b3d5b4c91b90fcbba79513cfee1907d8645a162afd0cd4cf4192d4a5f4c892183a8eacdb2b6b6a9d9aa8c11ac1b261b380dbee24ca468f1bfd043c58eefe" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9ea", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "98593452281661a53c48a9d8cd790826c1a1ce567738053d0bee4a91a3d5bd92eefdbabebe3204f2031ca5f781bda99ef5d8ae56e5b04a9e1ecd21b0eb05d3e1" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaeb", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "771f57dd2775ccdab55921d3e8e30ccf484d61fe1c1b9c2ae819d0fb2a12fab9be70c4a7a138da84e8280435daade5bbe66af0836a154f817fb17f3397e725a3" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebec", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "c60897c6f828e21f16fbb5f15b323f87b6c8955eabf1d38061f707f608abdd993fac3070633e286cf8339ce295dd352df4b4b40b2f29da1dd50b3a05d079e6bb" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebeced", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "8210cd2c2d3b135c2cf07fa0d1433cd771f325d075c6469d9c7f1ba0943cd4ab09808cabf4acb9ce5bb88b498929b4b847f681ad2c490d042db2aec94214b06b" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedee", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "1d4edfffd8fd80f7e4107840fa3aa31e32598491e4af7013c197a65b7f36dd3ac4b478456111cd4309d9243510782fa31b7c4c95fa951520d020eb7e5c36e4ef" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeef", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "af8e6e91fab46ce4873e1a50a8ef448cc29121f7f74deef34a71ef89cc00d9274bc6c2454bbb3230d8b2ec94c62b1dec85f3593bfa30ea6f7a44d7c09465a253" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "29fd384ed4906f2d13aa9fe7af905990938bed807f1832454a372ab412eea1f5625a1fcc9ac8343b7c67c5aba6e0b1cc4644654913692c6b39eb9187ceacd3ec" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "a268c7885d9874a51c44dffed8ea53e94f78456e0b2ed99ff5a3924760813826d960a15edbedbb5de5226ba4b074e71b05c55b9756bb79e55c02754c2c7b6c8a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "0cf8545488d56a86817cd7ecb10f7116b7ea530a45b6ea497b6c72c997e09e3d0da8698f46bb006fc977c2cd3d1177463ac9057fdd1662c85d0c126443c10473" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b39614268fdd8781515e2cfebf89b4d5402bab10c226e6344e6b9ae000fb0d6c79cb2f3ec80e80eaeb1980d2f8698916bd2e9f747236655116649cd3ca23a837" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "74bef092fc6f1e5dba3663a3fb003b2a5ba257496536d99f62b9d73f8f9eb3ce9ff3eec709eb883655ec9eb896b9128f2afc89cf7d1ab58a72f4a3bf034d2b4a" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "3a988d38d75611f3ef38b8774980b33e573b6c57bee0469ba5eed9b44f29945e7347967fba2c162e1c3be7f310f2f75ee2381e7bfd6b3f0baea8d95dfb1dafb1" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "58aedfce6f67ddc85a28c992f1c0bd0969f041e66f1ee88020a125cbfcfebcd61709c9c4eba192c15e69f020d462486019fa8dea0cd7a42921a19d2fe546d43d" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "9347bd291473e6b4e368437b8e561e065f649a6d8ada479ad09b1999a8f26b91cf6120fd3bfe014e83f23acfa4c0ad7b3712b2c3c0733270663112ccd9285cd9" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "b32163e7c5dbb5f51fdc11d2eac875efbbcb7e7699090a7e7ff8a8d50795af5d74d9ff98543ef8cdf89ac13d0485278756e0ef00c817745661e1d59fe38e7537" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "1085d78307b1c4b008c57a2e7e5b234658a0a82e4ff1e4aaac72b312fda0fe27d233bc5b10e9cc17fdc7697b540c7d95eb215a19a1a0e20e1abfa126efd568c7" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fa", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "4e5c734c7dde011d83eac2b7347b373594f92d7091b9ca34cb9c6f39bdf5a8d2f134379e16d822f6522170ccf2ddd55c84b9e6c64fc927ac4cf8dfb2a17701f2" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafb", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "695d83bd990a1117b3d0ce06cc888027d12a054c2677fd82f0d4fbfc93575523e7991a5e35a3752e9b70ce62992e268a877744cdd435f5f130869c9a2074b338" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfc", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "a6213743568e3b3158b9184301f3690847554c68457cb40fc9a4b8cfd8d4a118c301a07737aeda0f929c68913c5f51c80394f53bff1c3e83b2e40ca97eba9e15" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfd", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "d444bfa2362a96df213d070e33fa841f51334e4e76866b8139e8af3bb3398be2dfaddcbc56b9146de9f68118dc5829e74b0c28d7711907b121f9161cb92b69a9" - ), - - KnownAnswerTest( - input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe", - key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", - hash = "142709d62e28fcccd0af97fad0f8465b971e82201dc51070faa0372aa43e92484be1c1e73ba10906d5d1853db6a4106e0a7bf9800d373d6dee2d46d62ef2a461" - ) - ) -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt deleted file mode 100644 index f77caf2..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256Test.kt +++ /dev/null @@ -1,82 +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.hash.sha - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - -class Sha256Test { - - - @Test - fun testWellKnownValue() { - - val result = Sha256Pure.digest("abc".encodeToUByteArray()) - val expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - - - } - - - @Test - fun testWellKnownDoubleBlock() { - - val resultDoubleBlock = Sha256Pure.digest("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".encodeToUByteArray()) - val expectedResultForDoubleBlock = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } - - - @Test - fun testWellKnown3() { //It's good that I'm consistent with names. - - - val resultDoubleBlock = Sha256Pure.digest("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu".encodeToUByteArray()) - println(resultDoubleBlock.map{ it.toString(16)}.joinToString(separator = "")) - val expectedResultForDoubleBlock = "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } - - - @Test - fun testWellKnownLong() { - val inputBuilder = StringBuilder() - for (i in 0 until 1000000) { - inputBuilder.append("a") - } - val resultDoubleBlock = Sha256Pure.digest(inputMessage = (inputBuilder.toString()).encodeToByteArray().map { it.toUByte() }.toUByteArray()) - val expectedResultForDoubleBlock = "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256UpdateableTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256UpdateableTest.kt deleted file mode 100644 index 8e18be7..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha256UpdateableTest.kt +++ /dev/null @@ -1,134 +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.hash.sha - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.Ignore -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ - -class Sha256UpdatableTest { - - - @Test - fun testWellKnownValue() { - val sha256 = Sha256Pure() - sha256.update("abc") - val result = sha256.digest() - val expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - } - - - @Test - fun testWellKnownDoubleBlock() { - val sha256 = Sha256Pure() - sha256.update(data = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") - val resultDoubleBlock = sha256.digest() - println(resultDoubleBlock.map{ it.toString(16)}.joinToString(separator = "")) - val expectedResultForDoubleBlock = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } - - - @Test - fun testWellKnown3() { //It's good that I'm consistent with names. - val sha256 = Sha256Pure() - sha256.update(data = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu") - val resultDoubleBlock = sha256.digest() - println(resultDoubleBlock.map{ it.toString(16)}.joinToString(separator = "")) - val expectedResultForDoubleBlock = "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } - - - @Test - fun testWellKnownLong() { - val sha256 = Sha256Pure() - for (i in 0 until 10000) { - sha256.update("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - } - val result = sha256.digest() - val expectedResult = "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - } - - @Ignore // Takes too long on native and js, but it now finishes correctly (and surprisingly quickly) on JVM - @Test - fun testWellKnownLonger() { - - //Obtained from libsodium runs - val roundsExpectedMap = mapOf( - 0 to "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - 1 to "2ff100b36c386c65a1afc462ad53e25479bec9498ed00aa5a04de584bc25301b", - 2 to "a9161e25f5e45eddf9a4cfa8b23456ba66be8098e474dc145bfceb2a99808b89", - 3 to "7bd37dc113762cb012b69105b6302638d414ebfcabde205669aab2b8bbe1f3c4", - 4 to "8fa352dc79b2482d1b55777b4932aff67f52e87bafdf9b9d45d57405a672de7a", - 5 to "a229ab9b1bce3f3281b9d06a592aadb7e765029472a6b9ebf5ecd6c45a31f2f6", - 6 to "09b49600c40293a902e52f89478d4886cf5771faabe38f53a63f3e9051b23e32", - 7 to "02372493fd93330a8371f1dea20f5c29e5411baa1b08ba6cb33c6ca745c364a1", - 8 to "e38b73d311ac89575d4e69a965763cdc618d0879142574231268f2b014fd0fec", - 9 to "37ed309f368eef8560c8cbfb1d8b619f3cc5460689984b8c687f46373ff62087", - 0 to "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - 1000000 to "7d9d6bcd4ffc9eb37899bbd7b5810e1762c55e4104f1b26b061349dbc67b5500", - 2000000 to "6b324148d357b3bb6549d339cec1a2a9ce45543eca0efcece78eecb3337097c2", - 3000000 to "3a52d0fb3383bca84dab55b2f41f0827d08325dbc65e3db4f15264597a8ac828", - 4000000 to "afd4587cf84fe7b6ffd7146a702d9b5dd4f0b754971eef36b7e0a6c4c3e84d58", - 5000000 to "d2b74e1a88652cce4450c3040decf40f9496ec92ad5e3443045922952db7894d", - 6000000 to "6e27932f14dfbbce11c9c9523e8b5a11616fd7864504d607639a98f81d5c0701", - 7000000 to "06e320b651981e13fb192805ff12a848815671d15885b636f99148b0089efabe", - 8000000 to "acc52c42ee92c046430f6e5454670e4f82da684a157eddd393a74c6883c881a5", - 9000000 to "493a7d3a40f3575bd5e5b4a5fec005f37392f3ce44565da314d173a062f499be", - 10000000 to "b3c6a178986ae0f5c81875ed68da2c72c8be961e9abc05e02982f723bd52a489", - 11000000 to "48387a098f9e919ea15ae5d1a347857f1043116e24bf9224b718120e0bfdaa9f", - 12000000 to "3ec9b9e64073f1c89f6d1c817a75610294d32c33d089af45540a352634e4a74a", - 13000000 to "cfb7c272408acdabf35c5cf1e2c0e2e81092d4e86bf8d51575a8a3baea2e7f8c", - 14000000 to "aa678e14a7d9a160177d52f153f30edd20c7f8a25fe36a3500fc1e11bd99029f", - 15000000 to "77c0a6256b17d6fdfd0926312ab168c6ac7357b11e93933e31f2f5fd5aefd400", - 16000000 to "28598fc683ac23a324e732ae398e093b5b80b03f01bdcf2f2d1b8e6bc76d183e", - 16777216 to "50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e", - ) - val encoded = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno".encodeToUByteArray() - for (roundsExpected in roundsExpectedMap) { - val sha256 = Sha256Pure() - for (i in 0 until roundsExpected.key) { - sha256.update(encoded) - } - val result = sha256.digest() - assertTrue("Failed on ${roundsExpected.key} rounds, expected ${roundsExpected.value}, but got result ${result.toHexString()}") { - result.contentEquals(roundsExpected.value.hexStringToUByteArray()) - } - } - - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt deleted file mode 100644 index 0378054..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512Test.kt +++ /dev/null @@ -1,72 +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.hash.sha - -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jul-2019 - */ -class Sha512Test { - - - @Test - fun testWellKnownValue() { - - val result = Sha512Pure.digest(inputMessage = "abc".encodeToByteArray().map { it.toUByte() }.toUByteArray()) - println(result.map {it.toString(16)}) - val expectedResult = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + - "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - - - } - - - - @Test - fun testWellKnown3() { - val sha512 = Sha512Pure() - sha512.update(data = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu") - val resultDoubleBlock = sha512.digest() - val expectedResultForDoubleBlock = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018" + - "501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } - - - @Test - fun testWellKnownLong() { - val inputBuilder = StringBuilder() - for (i in 0 until 1000000) { - inputBuilder.append("a") - } - val resultDoubleBlock = Sha512Pure.digest(inputMessage = (inputBuilder.toString()).encodeToByteArray().map { it.toUByte() }.toUByteArray()) - val expectedResultForDoubleBlock = "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512UpdateableTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512UpdateableTest.kt deleted file mode 100644 index 38aa37e..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/hash/sha/Sha512UpdateableTest.kt +++ /dev/null @@ -1,87 +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.hash.sha - -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import kotlin.test.Ignore -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Jul-2019 - */ -class Sha512UpdatableTest { - - @Test - fun testWellKnownValue() { - val sha512 = Sha512Pure() - sha512.update("abc") - val result = sha512.digest() - val expectedResult = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + - "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - - - } - - - @Test - fun testWellKnownDoubleBlock() { - val sha512 = Sha512Pure() - sha512.update(data = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu") - val resultDoubleBlock = sha512.digest() - println(resultDoubleBlock.map{ it.toString(16)}.joinToString(separator = "")) - val expectedResultForDoubleBlock = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018" + - "501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } - - - @Test - fun testWellKnownLong() { - val sha512 = Sha512Pure() - for (i in 0 until 10000) { - sha512.update("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - } - val resultDoubleBlock = sha512.digest() - val expectedResultForDoubleBlock = "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b" - assertTrue { - resultDoubleBlock.contentEquals(expectedResultForDoubleBlock.hexStringToUByteArray()) - } - } - - - @Ignore // Takes too long on native and js, but it now finishes correctly (and surprisingly quickly) on JVM - @Test - fun testWellKnownLonger() { - val sha512 = Sha512Pure() - for (i in 0 until 16_777_216) { - sha512.update("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno") - } - val result = sha512.digest() - val expectedResult = "b47c933421ea2db149ad6e10fce6c7f93d0752380180ffd7f4629a712134831d77be6091b819ed352c2967a2e2d4fa5050723c9630691f1a05a7281dbe6c1086" - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/highlevel/EncryptionTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/highlevel/EncryptionTest.kt deleted file mode 100644 index d8f05da..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/highlevel/EncryptionTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.ionspin.kotlin.crypto.highlevel - -import com.ionspin.kotlin.crypto.Crypto -import com.ionspin.kotlin.crypto.SymmetricKey -import com.ionspin.kotlin.crypto.hash.decodeToString -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexColumsPrint -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 09-Jul-2020 - */ -class EncryptionTest { - @Test - fun testMultipartEncryption() { - val plaintext = ("pUoR4JVXJUeMKNkt6ZGGzEdTo33ajNGXwXpivBKA0XKs8toGRYI9Eul4bELRDkaQDNhd4vZseEFU" + - "ojsAn3c9zIifIrMnydSivHVZ2pBtpAQwYoJhYmEsfE0tROGnOwFWyB9K6LRSv1gB3YqKR9VyM8mpRoUM3UCRRjyiX7bnKdCE1" + - "EiX0myiwcY1nUKTgB3keERWtMU07hX7bCtao5nRvDofSj3o3IInHRQh6opltr5asQwn4m1qn029QF").encodeToUByteArray() - plaintext.hexColumsPrint() - val associatedData = "Additional data 1".encodeToUByteArray() -// val associatedData = ubyteArrayOf() - val keyValue = UByteArray(32) { it.toUByte() } - val key = SymmetricKey(keyValue) - val encryptor = Crypto.Encryption.createMultipartEncryptor(key) - val header = encryptor.startEncryption() - val ciphertext1 = encryptor.encryptPartialData(plaintext.sliceArray(0 until 100), associatedData) - val ciphertext2 = encryptor.encryptPartialData(plaintext.sliceArray(100 until 200)) - val ciphertext3 = encryptor.encryptPartialData(plaintext.sliceArray(200 until 250)) - //decrypt - val decryptor = Crypto.Encryption.createMultipartDecryptor(key, header) - val plaintext1 = decryptor.decryptPartialData(ciphertext1, associatedData) - val plaintext2 = decryptor.decryptPartialData(ciphertext2) - val plaintext3 = decryptor.decryptPartialData(ciphertext3) - - val combinedPlaintext = plaintext1.data + plaintext2.data + plaintext3.data - - combinedPlaintext.hexColumsPrint() - assertTrue { - plaintext.contentEquals(combinedPlaintext) - } - - - - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/mac/Poly1305Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/mac/Poly1305Test.kt deleted file mode 100644 index b24c72e..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/mac/Poly1305Test.kt +++ /dev/null @@ -1,224 +0,0 @@ -package com.ionspin.kotlin.crypto.mac - -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 18-Jun-2020 - */ -class Poly1305Test { - - /** - * From RFC7539 - */ - @Test - fun testPoly1305() { - assertTrue { - val key = ubyteArrayOf( - 0x85U, 0xd6U, 0xbeU, 0x78U, 0x57U, 0x55U, 0x6dU, - 0x33U, 0x7fU, 0x44U, 0x52U, 0xfeU, 0x42U, 0xd5U, - 0x06U, 0xa8U, 0x01U, 0x03U, 0x80U, 0x8aU, 0xfbU, - 0x0dU, 0xb2U, 0xfdU, 0x4aU, 0xbfU, 0xf6U, 0xafU, - 0x41U, 0x49U, 0xf5U, 0x1bU - ) - val message = ubyteArrayOf( - 0x43U, 0x72U, 0x79U, 0x70U, 0x74U, 0x6fU, 0x67U, 0x72U, - 0x61U, 0x70U, 0x68U, 0x69U, 0x63U, 0x20U, 0x46U, 0x6fU, - 0x72U, 0x75U, 0x6dU, 0x20U, 0x52U, 0x65U, 0x73U, 0x65U, - 0x61U, 0x72U, 0x63U, 0x68U, 0x20U, 0x47U, 0x72U, 0x6fU, - 0x75U, 0x70U - ) - val expected = ubyteArrayOf( - 0xA8U, 0x06U, 0x1DU, 0xC1U, - 0x30U, 0x51U, 0x36U, 0xC6U, - 0xC2U, 0x2BU, 0x8BU, 0xAFU, - 0x0CU, 0x01U, 0x27U, 0xA9U, - ) - - val result = - Poly1305.poly1305Authenticate( - key, - message, - ) - expected.contentEquals(result) - } - assertTrue { - val key = ubyteArrayOf( - 0x85U, 0x1fU, 0xc4U, 0x0cU, 0x34U, 0x67U, 0xacU, 0x0bU, - 0xe0U, 0x5cU, 0xc2U, 0x04U, 0x04U, 0xf3U, 0xf7U, 0x00U, - 0x58U, 0x0bU, 0x3bU, 0x0fU, 0x94U, 0x47U, 0xbbU, 0x1eU, - 0x69U, 0xd0U, 0x95U, 0xb5U, 0x92U, 0x8bU, 0x6dU, 0xbcU - ) - val message = ubyteArrayOf( - 0xf3U, 0xf6U - ) - val expected = ubyteArrayOf( - 0xf4U, 0xc6U, 0x33U, 0xc3U, 0x04U, 0x4fU, 0xc1U, 0x45U, - 0xf8U, 0x4fU, 0x33U, 0x5cU, 0xb8U, 0x19U, 0x53U, 0xdeU - ) - - val result = - Poly1305.poly1305Authenticate( - key, - message, - ) - expected.contentEquals(result) - } - - assertTrue { - val key = ubyteArrayOf( - 0x75U, 0xdeU, 0xaaU, 0x25U, 0xc0U, 0x9fU, 0x20U, 0x8eU, - 0x1dU, 0xc4U, 0xceU, 0x6bU, 0x5cU, 0xadU, 0x3fU, 0xbfU, - 0xddU, 0x3fU, 0xabU, 0x22U, 0x51U, 0xf1U, 0x1aU, 0xc7U, - 0x59U, 0xf0U, 0x88U, 0x71U, 0x29U, 0xccU, 0x2eU, 0xe7U, - ) - val message = ubyteArrayOf( - - ) - val expected = ubyteArrayOf( - 0xddU, 0x3fU, 0xabU, 0x22U, 0x51U, 0xf1U, 0x1aU, 0xc7U, - 0x59U, 0xf0U, 0x88U, 0x71U, 0x29U, 0xccU, 0x2eU, 0xe7U - ) - - val result = - Poly1305.poly1305Authenticate( - key, - message, - ) - expected.contentEquals(result) - } - - assertTrue { - val key = ubyteArrayOf( - 0x12U, 0x97U, 0x6aU, 0x08U, 0xc4U, 0x42U, 0x6dU, 0x0cU, - 0xe8U, 0xa8U, 0x24U, 0x07U, 0xc4U, 0xf4U, 0x82U, 0x07U, - 0x80U, 0xf8U, 0xc2U, 0x0aU, 0xa7U, 0x12U, 0x02U, 0xd1U, - 0xe2U, 0x91U, 0x79U, 0xcbU, 0xcbU, 0x55U, 0x5aU, 0x57U - ) - val message = ubyteArrayOf( - 0xabU, 0x08U, 0x12U, 0x72U, 0x4aU, 0x7fU, 0x1eU, 0x34U, - 0x27U, 0x42U, 0xcbU, 0xedU, 0x37U, 0x4dU, 0x94U, 0xd1U, - 0x36U, 0xc6U, 0xb8U, 0x79U, 0x5dU, 0x45U, 0xb3U, 0x81U, - 0x98U, 0x30U, 0xf2U, 0xc0U, 0x44U, 0x91U, 0xfaU, 0xf0U, - 0x99U, 0x0cU, 0x62U, 0xe4U, 0x8bU, 0x80U, 0x18U, 0xb2U, - 0xc3U, 0xe4U, 0xa0U, 0xfaU, 0x31U, 0x34U, 0xcbU, 0x67U, - 0xfaU, 0x83U, 0xe1U, 0x58U, 0xc9U, 0x94U, 0xd9U, 0x61U, - 0xc4U, 0xcbU, 0x21U, 0x09U, 0x5cU, 0x1bU, 0xf9U, - ) - val expected = ubyteArrayOf( - 0x51U, 0x54U, 0xadU, 0x0dU, 0x2cU, 0xb2U, 0x6eU, 0x01U, - 0x27U, 0x4fU, 0xc5U, 0x11U, 0x48U, 0x49U, 0x1fU, 0x1bU - ) - - val result = - Poly1305.poly1305Authenticate( - key, - message, - ) - expected.contentEquals(result) - } - } - - @Test - fun testUpdateablePoly1305() { - assertTrue { - val key = ubyteArrayOf( - 0x85U, 0xd6U, 0xbeU, 0x78U, 0x57U, 0x55U, 0x6dU, - 0x33U, 0x7fU, 0x44U, 0x52U, 0xfeU, 0x42U, 0xd5U, - 0x06U, 0xa8U, 0x01U, 0x03U, 0x80U, 0x8aU, 0xfbU, - 0x0dU, 0xb2U, 0xfdU, 0x4aU, 0xbfU, 0xf6U, 0xafU, - 0x41U, 0x49U, 0xf5U, 0x1bU - ) - val message = ubyteArrayOf( - 0x43U, 0x72U, 0x79U, 0x70U, 0x74U, 0x6fU, 0x67U, 0x72U, - 0x61U, 0x70U, 0x68U, 0x69U, 0x63U, 0x20U, 0x46U, 0x6fU, - 0x72U, 0x75U, 0x6dU, 0x20U, 0x52U, 0x65U, 0x73U, 0x65U, - 0x61U, 0x72U, 0x63U, 0x68U, 0x20U, 0x47U, 0x72U, 0x6fU, - 0x75U, 0x70U - ) - val expected = ubyteArrayOf( - 0xA8U, 0x06U, 0x1DU, 0xC1U, - 0x30U, 0x51U, 0x36U, 0xC6U, - 0xC2U, 0x2BU, 0x8BU, 0xAFU, - 0x0CU, 0x01U, 0x27U, 0xA9U, - ) - val poly = Poly1305(key) - poly.updateMac(message.sliceArray(0 until 16)) - poly.updateMac(message.sliceArray(16 until 32)) - val result = poly.finalizeMac(message.sliceArray(32 until 34)) - - expected.contentEquals(result) - } - assertTrue { - val key = ubyteArrayOf( - 0x85U, 0x1fU, 0xc4U, 0x0cU, 0x34U, 0x67U, 0xacU, 0x0bU, - 0xe0U, 0x5cU, 0xc2U, 0x04U, 0x04U, 0xf3U, 0xf7U, 0x00U, - 0x58U, 0x0bU, 0x3bU, 0x0fU, 0x94U, 0x47U, 0xbbU, 0x1eU, - 0x69U, 0xd0U, 0x95U, 0xb5U, 0x92U, 0x8bU, 0x6dU, 0xbcU - ) - val message = ubyteArrayOf( - 0xf3U, 0xf6U - ) - val expected = ubyteArrayOf( - 0xf4U, 0xc6U, 0x33U, 0xc3U, 0x04U, 0x4fU, 0xc1U, 0x45U, - 0xf8U, 0x4fU, 0x33U, 0x5cU, 0xb8U, 0x19U, 0x53U, 0xdeU - ) - - val poly = Poly1305(key) - val result = poly.finalizeMac(message) - expected.contentEquals(result) - } - - assertTrue { - val key = ubyteArrayOf( - 0x75U, 0xdeU, 0xaaU, 0x25U, 0xc0U, 0x9fU, 0x20U, 0x8eU, - 0x1dU, 0xc4U, 0xceU, 0x6bU, 0x5cU, 0xadU, 0x3fU, 0xbfU, - 0xddU, 0x3fU, 0xabU, 0x22U, 0x51U, 0xf1U, 0x1aU, 0xc7U, - 0x59U, 0xf0U, 0x88U, 0x71U, 0x29U, 0xccU, 0x2eU, 0xe7U, - ) - val message = ubyteArrayOf( - - ) - val expected = ubyteArrayOf( - 0xddU, 0x3fU, 0xabU, 0x22U, 0x51U, 0xf1U, 0x1aU, 0xc7U, - 0x59U, 0xf0U, 0x88U, 0x71U, 0x29U, 0xccU, 0x2eU, 0xe7U - ) - - val poly = Poly1305(key) - val result = poly.finalizeMac(message) - expected.contentEquals(result) - } - - assertTrue { - val key = ubyteArrayOf( - 0x12U, 0x97U, 0x6aU, 0x08U, 0xc4U, 0x42U, 0x6dU, 0x0cU, - 0xe8U, 0xa8U, 0x24U, 0x07U, 0xc4U, 0xf4U, 0x82U, 0x07U, - 0x80U, 0xf8U, 0xc2U, 0x0aU, 0xa7U, 0x12U, 0x02U, 0xd1U, - 0xe2U, 0x91U, 0x79U, 0xcbU, 0xcbU, 0x55U, 0x5aU, 0x57U - ) - val message = ubyteArrayOf( - 0xabU, 0x08U, 0x12U, 0x72U, 0x4aU, 0x7fU, 0x1eU, 0x34U, - 0x27U, 0x42U, 0xcbU, 0xedU, 0x37U, 0x4dU, 0x94U, 0xd1U, - 0x36U, 0xc6U, 0xb8U, 0x79U, 0x5dU, 0x45U, 0xb3U, 0x81U, - 0x98U, 0x30U, 0xf2U, 0xc0U, 0x44U, 0x91U, 0xfaU, 0xf0U, - 0x99U, 0x0cU, 0x62U, 0xe4U, 0x8bU, 0x80U, 0x18U, 0xb2U, - 0xc3U, 0xe4U, 0xa0U, 0xfaU, 0x31U, 0x34U, 0xcbU, 0x67U, - 0xfaU, 0x83U, 0xe1U, 0x58U, 0xc9U, 0x94U, 0xd9U, 0x61U, - 0xc4U, 0xcbU, 0x21U, 0x09U, 0x5cU, 0x1bU, 0xf9U, - ) - val expected = ubyteArrayOf( - 0x51U, 0x54U, 0xadU, 0x0dU, 0x2cU, 0xb2U, 0x6eU, 0x01U, - 0x27U, 0x4fU, 0xc5U, 0x11U, 0x48U, 0x49U, 0x1fU, 0x1bU - ) - - val poly = Poly1305(key) - poly.updateMac(message.sliceArray(0 until 16)) - poly.updateMac(message.sliceArray(16 until 32)) - poly.updateMac(message.sliceArray(32 until 48)) - val result = poly.finalizeMac(message.sliceArray(48 until 63)) - expected.contentEquals(result) - } - } -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCbcTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCbcTest.kt deleted file mode 100644 index c84a345..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCbcTest.kt +++ /dev/null @@ -1,113 +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.symmetric - -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ - -class AesCbcTest { - - @Test - fun testCbcEncryption() { - assertTrue { - val key = "4278b840fb44aaa757c1bf04acbe1a3e" - val iv = "57f02a5c5339daeb0a2908a06ac6393f" - val plaintext = "3c888bbbb1a8eb9f3e9b87acaad986c466e2f7071c83083b8a557971918850e5" - val expectedCipherText = "479c89ec14bc98994e62b2c705b5014e" + - "175bd7832e7e60a1e92aac568a861eb7" + - "fc2dc2f4a527ce39f79c56b31432c779" - val aesCbc = - AesCbcPure(InternalAesKey.Aes128Key(key), mode = Mode.ENCRYPT, initializationVector = iv.hexStringToUByteArray()) - aesCbc.addData(plaintext.hexStringToUByteArray()) - val encrypted = aesCbc.encrypt() - println("Encrypted: ${encrypted.encryptedData.toHexString()}") - - expectedCipherText == encrypted.encryptedData.toHexString() && - iv == encrypted.initializationVector.toHexString() - } - - - - } - - @Test - fun testEncryptionApi() { - assertTrue { - val keyString = "4278b840fb44aaa757c1bf04acbe1a3e" - val key = InternalAesKey.Aes128Key(keyString) - - val plainText = "3c888bbbb1a8eb9f3e9b87acaad986c466e2f7071c83083b8a557971918850e5" - - val encryptedDataAndInitializationVector = AesCbcPure.encrypt(key, plainText.hexStringToUByteArray()) - val decrypted = AesCbcPure.decrypt( - key, - encryptedDataAndInitializationVector.encryptedData, - encryptedDataAndInitializationVector.initializationVector - ) - plainText == decrypted.toHexString() - } - } - - @Test - fun testCbcDecryption() { - assertTrue { - val key = "4278b840fb44aaa757c1bf04acbe1a3e" - val iv = "57f02a5c5339daeb0a2908a06ac6393f" - val cipherText = "479c89ec14bc98994e62b2c705b5014e" + - "175bd7832e7e60a1e92aac568a861eb7" + - "fc2dc2f4a527ce39f79c56b31432c779" - val expectedPlainText = "3c888bbbb1a8eb9f3e9b87acaad986c466e2f7071c83083b8a557971918850e5" - val aesCbc = - AesCbcPure(InternalAesKey.Aes128Key(key), mode = Mode.DECRYPT, initializationVector = iv.hexStringToUByteArray()) - aesCbc.addData(cipherText.hexStringToUByteArray()) - val decrypted = aesCbc.decrypt() - println("Decrypted: ${decrypted.toHexString()}") - - expectedPlainText == decrypted.toHexString() - } - - - - } - - @Test - fun testDecryptionApi() { - assertTrue { - val key = "4278b840fb44aaa757c1bf04acbe1a3e" - val iv = "57f02a5c5339daeb0a2908a06ac6393f" - val cipherText = "479c89ec14bc98994e62b2c705b5014e" + - "175bd7832e7e60a1e92aac568a861eb7" + - "fc2dc2f4a527ce39f79c56b31432c779" - val expectedPlainText = "3c888bbbb1a8eb9f3e9b87acaad986c466e2f7071c83083b8a557971918850e5" - val decrypted = AesCbcPure.decrypt(InternalAesKey.Aes128Key(key), cipherText.hexStringToUByteArray(), iv.hexStringToUByteArray()) - println("Decrypted: ${decrypted.toHexString()}") - - expectedPlainText == decrypted.toHexString() - } - } - - - -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCtrTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCtrTest.kt deleted file mode 100644 index 457e59c..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesCtrTest.kt +++ /dev/null @@ -1,105 +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.symmetric - -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ - -class AesCtrTest { - - @Test - fun testCtrEncryption() { - assertTrue { - val key = "2b7e151628aed2a6abf7158809cf4f3c" - val ic = "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" - val plaintext = - "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710" - val expectedCipherText = - "874d6191b620e3261bef6864990db6ce9806f66b7970fdff8617187bb9fffdff5ae4df3edbd5d35e5b4f09020db03eab1e031dda2fbe03d1792170a0f3009cee" - val aesCtr = AesCtrPure(InternalAesKey.Aes128Key(key), mode = Mode.ENCRYPT, initialCounter = ic.hexStringToUByteArray()) - aesCtr.addData( - plaintext.hexStringToUByteArray() - ) - val encrypted = aesCtr.encrypt() - println("Encrypted: ${encrypted.encryptedData.toHexString()}") - - expectedCipherText == encrypted.encryptedData.toHexString() && - ic == encrypted.initialCounter.toHexString() - } - - } - - @Test - fun testEncryptionApi() { - val keyString = "4278b840fb44aaa757c1bf04acbe1a3e" - val key = InternalAesKey.Aes128Key(keyString) - val plainText = "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710" - - val encryptedDataAndInitializationVector = AesCtrPure.encrypt(key, plainText.hexStringToUByteArray()) - val decrypted = AesCtrPure.decrypt( - key, - encryptedDataAndInitializationVector.encryptedData, - encryptedDataAndInitializationVector.initialCounter - ) - assertTrue { - plainText == decrypted.toHexString() - } - } - - @Test - fun testCtrDecryption() { - assertTrue { - val key = "2b7e151628aed2a6abf7158809cf4f3c" - val ic = "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" - val cipherText = - "874d6191b620e3261bef6864990db6ce9806f66b7970fdff8617187bb9fffdff5ae4df3edbd5d35e5b4f09020db03eab1e031dda2fbe03d1792170a0f3009cee" - val expectedPlainText = - "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710" - val aesCtr = AesCtrPure(InternalAesKey.Aes128Key(key), mode = Mode.DECRYPT, initialCounter = ic.hexStringToUByteArray()) - aesCtr.addData(cipherText.hexStringToUByteArray()) - val decrypted = aesCtr.decrypt() - println("Decrypted: ${decrypted.toHexString()}") - expectedPlainText == decrypted.toHexString() - } - - - - } - - @Test - fun testCtrDecryptionApi() { - assertTrue { - val key = "2b7e151628aed2a6abf7158809cf4f3c" - val ic = "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" - val cipherText = - "874d6191b620e3261bef6864990db6ce9806f66b7970fdff8617187bb9fffdff5ae4df3edbd5d35e5b4f09020db03eab1e031dda2fbe03d1792170a0f3009cee" - val expectedPlainText = - "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710" - val decrypted = AesCtrPure.decrypt(InternalAesKey.Aes128Key(key), cipherText.hexStringToUByteArray(), ic.hexStringToUByteArray()) - println("Decrypted: ${decrypted.toHexString()}") - expectedPlainText == decrypted.toHexString() - } - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesTest.kt deleted file mode 100644 index be3bbd8..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesTest.kt +++ /dev/null @@ -1,270 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic (jovanovic.ugljesa@gmail.com) on 10/Sep/2019 - */ - -class AesTest { - - val irrelevantKey = "01234567890123345678901234567890" - val irrelevantInput = UByteArray(16) { 0U } - - @Test - fun testSubBytes() { - val fakeState = arrayOf( - ubyteArrayOf(0x53U, 0U, 0U, 0U), - ubyteArrayOf(0U, 0U, 0U, 0U), - ubyteArrayOf(0U, 0U, 0U, 0U), - ubyteArrayOf(0U, 0U, 0U, 0U) - ) - val aes = AesPure(InternalAesKey.Aes128Key(irrelevantKey), irrelevantInput) - fakeState.copyInto(aes.state) - aes.subBytes() - assertTrue { - aes.state[0][0] == 0xEDU.toUByte() - } - } - - @Test - fun testShiftRows() { - val fakeState = arrayOf( - ubyteArrayOf(0U, 1U, 2U, 3U), - ubyteArrayOf(0U, 1U, 2U, 3U), - ubyteArrayOf(0U, 1U, 2U, 3U), - ubyteArrayOf(0U, 1U, 2U, 3U) - ) - val expectedState = arrayOf( - ubyteArrayOf(0U, 1U, 2U, 3U), - ubyteArrayOf(1U, 2U, 3U, 0U), - ubyteArrayOf(2U, 3U, 0U, 1U), - ubyteArrayOf(3U, 0U, 1U, 2U) - ) - val aes = AesPure(InternalAesKey.Aes128Key(irrelevantKey), irrelevantInput) - fakeState.copyInto(aes.state) - aes.shiftRows() - assertTrue { - aes.state.contentDeepEquals(expectedState) - } - } - - @Test - fun testGaloisMultiply() { - //Samples from FIPS-197 - assertTrue { - val a = 0x57U - val b = 0x83U - val aes = AesPure(InternalAesKey.Aes128Key(irrelevantKey), irrelevantInput) - val c = aes.galoisFieldMultiply(a.toUByte(), b.toUByte()) - c == 0xC1U.toUByte() - } - - assertTrue { - val a = 0x57U - val b = 0x13U - val aes = AesPure(InternalAesKey.Aes128Key(irrelevantKey), irrelevantInput) - val c = aes.galoisFieldMultiply(a.toUByte(), b.toUByte()) - c == 0xFEU.toUByte() - } - - - } - - @Test - fun testMixColumns() { - //Test vectors from wikipedia - val fakeState = arrayOf( - ubyteArrayOf(0xdbU, 0xf2U, 0x01U, 0xc6U), - ubyteArrayOf(0x13U, 0x0aU, 0x01U, 0xc6U), - ubyteArrayOf(0x53U, 0x22U, 0x01U, 0xc6U), - ubyteArrayOf(0x45U, 0x5cU, 0x01U, 0xc6U) - ) - - val expectedState = arrayOf( - ubyteArrayOf(0x8eU, 0x9fU, 0x01U, 0xc6U), - ubyteArrayOf(0x4dU, 0xdcU, 0x01U, 0xc6U), - ubyteArrayOf(0xa1U, 0x58U, 0x01U, 0xc6U), - ubyteArrayOf(0xbcU, 0x9dU, 0x01U, 0xc6U) - ) - - val aes = AesPure(InternalAesKey.Aes128Key(irrelevantKey), irrelevantInput) - fakeState.copyInto(aes.state) - aes.mixColumns() - assertTrue { - aes.state.contentDeepEquals(expectedState) - } - - } - - @Test - fun testKeyExpansion() { - assertTrue { - val key = "2b7e151628aed2a6abf7158809cf4f3c" - val expectedExpandedKey = uintArrayOf( - // @formatter:off - 0x2b7e1516U, 0x28aed2a6U, 0xabf71588U, 0x09cf4f3cU, 0xa0fafe17U, 0x88542cb1U, - 0x23a33939U, 0x2a6c7605U, 0xf2c295f2U, 0x7a96b943U, 0x5935807aU, 0x7359f67fU, - 0x3d80477dU, 0x4716fe3eU, 0x1e237e44U, 0x6d7a883bU, 0xef44a541U, 0xa8525b7fU, - 0xb671253bU, 0xdb0bad00U, 0xd4d1c6f8U, 0x7c839d87U, 0xcaf2b8bcU, 0x11f915bcU, - 0x6d88a37aU, 0x110b3efdU, 0xdbf98641U, 0xca0093fdU, 0x4e54f70eU, 0x5f5fc9f3U, - 0x84a64fb2U, 0x4ea6dc4fU, 0xead27321U, 0xb58dbad2U, 0x312bf560U, 0x7f8d292fU, - 0xac7766f3U, 0x19fadc21U, 0x28d12941U, 0x575c006eU, 0xd014f9a8U, 0xc9ee2589U, - 0xe13f0cc8U, 0xb6630ca6U - // @formatter:on - ).toTypedArray() - - - val aes = AesPure(InternalAesKey.Aes128Key(key), irrelevantInput) - val result = aes.expandedKey.map { - it.foldIndexed(0U) { index, acc, uByte -> - acc + (uByte.toUInt() shl (24 - index * 8)) - } - }.toTypedArray() - expectedExpandedKey.contentEquals(result) - } - - assertTrue { - val key = "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b" - val expectedExpandedKey = uintArrayOf( - // @formatter:off - 0x8e73b0f7U, 0xda0e6452U, 0xc810f32bU, 0x809079e5U, 0x62f8ead2U, 0x522c6b7bU, - 0xfe0c91f7U, 0x2402f5a5U, 0xec12068eU, 0x6c827f6bU, 0x0e7a95b9U, 0x5c56fec2U, 0x4db7b4bdU, 0x69b54118U, - 0x85a74796U, 0xe92538fdU, 0xe75fad44U, 0xbb095386U, 0x485af057U, 0x21efb14fU, 0xa448f6d9U, 0x4d6dce24U, - 0xaa326360U, 0x113b30e6U, 0xa25e7ed5U, 0x83b1cf9aU, 0x27f93943U, 0x6a94f767U, 0xc0a69407U, 0xd19da4e1U, - 0xec1786ebU, 0x6fa64971U, 0x485f7032U, 0x22cb8755U, 0xe26d1352U, 0x33f0b7b3U, 0x40beeb28U, 0x2f18a259U, - 0x6747d26bU, 0x458c553eU, 0xa7e1466cU, 0x9411f1dfU, 0x821f750aU, 0xad07d753U, 0xca400538U, 0x8fcc5006U, - 0x282d166aU, 0xbc3ce7b5U, 0xe98ba06fU, 0x448c773cU, 0x8ecc7204U, 0x01002202U - // @formatter:on - ).toTypedArray() - - - val aes = AesPure(InternalAesKey.Aes192Key(key), irrelevantInput) - val result = aes.expandedKey.map { - it.foldIndexed(0U) { index, acc, uByte -> - acc + (uByte.toUInt() shl (24 - index * 8)) - } - }.toTypedArray() - expectedExpandedKey.contentEquals(result) - } - - assertTrue { - val key = "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" - - val expectedExpandedKey = uintArrayOf( - // @formatter:off - 0x603deb10U, 0x15ca71beU, 0x2b73aef0U, 0x857d7781U, 0x1f352c07U, 0x3b6108d7U, 0x2d9810a3U, 0x0914dff4U, - 0x9ba35411U, 0x8e6925afU, 0xa51a8b5fU, 0x2067fcdeU, 0xa8b09c1aU, 0x93d194cdU, 0xbe49846eU, 0xb75d5b9aU, - 0xd59aecb8U, 0x5bf3c917U, 0xfee94248U, 0xde8ebe96U, 0xb5a9328aU, 0x2678a647U, 0x98312229U, 0x2f6c79b3U, - 0x812c81adU, 0xdadf48baU, 0x24360af2U, 0xfab8b464U, 0x98c5bfc9U, 0xbebd198eU, 0x268c3ba7U, 0x09e04214U, - 0x68007bacU, 0xb2df3316U, 0x96e939e4U, 0x6c518d80U, 0xc814e204U, 0x76a9fb8aU, 0x5025c02dU, 0x59c58239U, - 0xde136967U, 0x6ccc5a71U, 0xfa256395U, 0x9674ee15U, 0x5886ca5dU, 0x2e2f31d7U, 0x7e0af1faU, 0x27cf73c3U, - 0x749c47abU, 0x18501ddaU, 0xe2757e4fU, 0x7401905aU, 0xcafaaae3U, 0xe4d59b34U, 0x9adf6aceU, 0xbd10190dU, - 0xfe4890d1U, 0xe6188d0bU, 0x046df344U, 0x706c631eU - // @formatter:on - ).toTypedArray() - - - val aes = AesPure(InternalAesKey.Aes256Key(key), irrelevantInput) - val result = aes.expandedKey.map { - it.foldIndexed(0U) { index, acc, uByte -> - acc + (uByte.toUInt() shl (24 - index * 8)) - } - }.toTypedArray() - expectedExpandedKey.contentEquals(result) - } - - } - - @Test - fun testEncryption() { - val input = "3243f6a8885a308d313198a2e0370734" - val key = "2b7e151628aed2a6abf7158809cf4f3c" - val expectedResult = "3925841d02dc09fbdc118597196a0b32" - - val aes = AesPure(InternalAesKey.Aes128Key(key), input.hexStringToUByteArray()) - val result = aes.encrypt() - assertTrue { - result.contentEquals(expectedResult.hexStringToUByteArray()) - } - } - - @Test - fun testEncryptionAndDecryption() { - assertTrue { - val input = "3243f6a8885a308d313198a2e0370734" - val key = "2b7e151628aed2a6abf7158809cf4f3c" - val expectedResult = "3925841d02dc09fbdc118597196a0b32" - val original = input.hexStringToUByteArray() - val aes = AesPure(InternalAesKey.Aes128Key(key), original) - val encrypted = aes.encrypt() - assertTrue { - encrypted.contentEquals(expectedResult.hexStringToUByteArray()) - } - val decrypted = AesPure.decrypt(InternalAesKey.Aes128Key(key), encrypted) - - decrypted.contentEquals(original) - } - assertTrue { - val input = "00112233445566778899aabbccddeeff" - val key = "000102030405060708090a0b0c0d0e0f" - val expectedResult = "69c4e0d86a7b0430d8cdb78070b4c55a" - val original = input.hexStringToUByteArray() - val aes = AesPure(InternalAesKey.Aes128Key(key), original) - val encrypted = aes.encrypt() - assertTrue { - encrypted.contentEquals(expectedResult.hexStringToUByteArray()) - } - val aesDec = AesPure(InternalAesKey.Aes128Key(key), encrypted) - val decrypted = aesDec.decrypt() - assertTrue { - aesDec.expandedKey.contentDeepEquals(aes.expandedKey) - } - decrypted.contentEquals(original) - } - - assertTrue { - val input = "00112233445566778899aabbccddeeff" - val key = "000102030405060708090a0b0c0d0e0f" - val expectedResult = "69c4e0d86a7b0430d8cdb78070b4c55a" - val original = input.hexStringToUByteArray() - val encrypted = AesPure.encrypt(InternalAesKey.Aes128Key(key), original) - assertTrue { - encrypted.contentEquals(expectedResult.hexStringToUByteArray()) - } - val decrypted = AesPure.decrypt(InternalAesKey.Aes128Key(key), encrypted) - decrypted.contentEquals(original) - } - - assertTrue { - val input = "00112233445566778899aabbccddeeff" - val key = "000102030405060708090a0b0c0d0e0f1011121314151617" - val expectedResult = "dda97ca4864cdfe06eaf70a0ec0d7191" - val original = input.hexStringToUByteArray() - val encrypted = AesPure.encrypt(InternalAesKey.Aes192Key(key), original) - assertTrue { - encrypted.contentEquals(expectedResult.hexStringToUByteArray()) - } - val decrypted = AesPure.decrypt(InternalAesKey.Aes192Key(key), encrypted) - decrypted.contentEquals(original) - } - - assertTrue { - val input = "00112233445566778899aabbccddeeff" - val key = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" - val expectedResult = "8ea2b7ca516745bfeafc49904b496089" - val original = input.hexStringToUByteArray() - val encrypted = AesPure.encrypt(InternalAesKey.Aes256Key(key), original) - assertTrue { - encrypted.contentEquals(expectedResult.hexStringToUByteArray()) - } - val decrypted = AesPure.decrypt(InternalAesKey.Aes256Key(key), encrypted) - decrypted.contentEquals(original) - } - } - - - -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/ChaCha20Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/ChaCha20Test.kt deleted file mode 100644 index 4687643..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/ChaCha20Test.kt +++ /dev/null @@ -1,90 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 16-Jun-2020 - */ -class ChaCha20Test { - - - @Test - fun testQuarterRound() { - val a = 0x11111111U - val b = 0x01020304U - val c = 0x9b8d6f43U - val d = 0x01234567U - val input = uintArrayOf(a, b, c, d) - val aExpected = 0xea2a92f4U - val bExpected = 0xcb1cf8ceU - val cExpected = 0x4581472eU - val dExpected = 0x5881c4bbU - val expected = uintArrayOf(aExpected, bExpected, cExpected, dExpected) - ChaCha20Pure.quarterRound(input, 0, 1, 2, 3) - assertTrue { - input.contentEquals(expected) - } - } - - @Test - fun testBlockFunction() { - //From RFC 7539 - val state = uintArrayOf( - 0x61707865U, 0x3320646eU, 0x79622d32U, 0x6b206574U, - 0x03020100U, 0x07060504U, 0x0b0a0908U, 0x0f0e0d0cU, - 0x13121110U, 0x17161514U, 0x1b1a1918U, 0x1f1e1d1cU, - 0x00000001U, 0x09000000U, 0x4a000000U, 0x00000000U, - ) - val expected = ubyteArrayOf( - 0x10U, 0xf1U, 0xe7U, 0xe4U, 0xd1U, 0x3bU, 0x59U, 0x15U, 0x50U, 0x0fU, 0xddU, 0x1fU, 0xa3U, 0x20U, 0x71U, 0xc4U, - 0xc7U, 0xd1U, 0xf4U, 0xc7U, 0x33U, 0xc0U, 0x68U, 0x03U, 0x04U, 0x22U, 0xaaU, 0x9aU, 0xc3U, 0xd4U, 0x6cU, 0x4eU, - 0xd2U, 0x82U, 0x64U, 0x46U, 0x07U, 0x9fU, 0xaaU, 0x09U, 0x14U, 0xc2U, 0xd7U, 0x05U, 0xd9U, 0x8bU, 0x02U, 0xa2U, - 0xb5U, 0x12U, 0x9cU, 0xd1U, 0xdeU, 0x16U, 0x4eU, 0xb9U, 0xcbU, 0xd0U, 0x83U, 0xe8U, 0xa2U, 0x50U, 0x3cU, 0x4eU - ) - val result = ChaCha20Pure.hash(state) - assertTrue { - expected.contentEquals(result) - } - } - - @Test - fun testEncryption() { - - //From RFC 7539 - val key = ubyteArrayOf( - 0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, - 0x06U, 0x07U, 0x08U, 0x09U, 0x0aU, 0x0bU, - 0x0cU, 0x0dU, 0x0eU, 0x0fU, 0x10U, 0x11U, - 0x12U, 0x13U, 0x14U, 0x15U, 0x16U, 0x17U, - 0x18U, 0x19U, 0x1aU, 0x1bU, 0x1cU, 0x1dU, - 0x1eU, 0x1fU - ) - val nonce = ubyteArrayOf( - 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x4aU, 0x00U, 0x00U, 0x00U, 0x00U - ) - val message = - "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.".encodeToUByteArray() - val expected = ubyteArrayOf( - 0x6eU, 0x2eU, 0x35U, 0x9aU, 0x25U, 0x68U, 0xf9U, 0x80U, 0x41U, 0xbaU, 0x07U, 0x28U, 0xddU, 0x0dU, 0x69U, 0x81U, - 0xe9U, 0x7eU, 0x7aU, 0xecU, 0x1dU, 0x43U, 0x60U, 0xc2U, 0x0aU, 0x27U, 0xafU, 0xccU, 0xfdU, 0x9fU, 0xaeU, 0x0bU, - 0xf9U, 0x1bU, 0x65U, 0xc5U, 0x52U, 0x47U, 0x33U, 0xabU, 0x8fU, 0x59U, 0x3dU, 0xabU, 0xcdU, 0x62U, 0xb3U, 0x57U, - 0x16U, 0x39U, 0xd6U, 0x24U, 0xe6U, 0x51U, 0x52U, 0xabU, 0x8fU, 0x53U, 0x0cU, 0x35U, 0x9fU, 0x08U, 0x61U, 0xd8U, - 0x07U, 0xcaU, 0x0dU, 0xbfU, 0x50U, 0x0dU, 0x6aU, 0x61U, 0x56U, 0xa3U, 0x8eU, 0x08U, 0x8aU, 0x22U, 0xb6U, 0x5eU, - 0x52U, 0xbcU, 0x51U, 0x4dU, 0x16U, 0xccU, 0xf8U, 0x06U, 0x81U, 0x8cU, 0xe9U, 0x1aU, 0xb7U, 0x79U, 0x37U, 0x36U, - 0x5aU, 0xf9U, 0x0bU, 0xbfU, 0x74U, 0xa3U, 0x5bU, 0xe6U, 0xb4U, 0x0bU, 0x8eU, 0xedU, 0xf2U, 0x78U, 0x5eU, 0x42U, - 0x87U, 0x4dU, - ) - val result = ChaCha20Pure.xorWithKeystream(key, nonce, message, 1U) - assertTrue { - expected.contentEquals(result) - } - - - } - - -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/Salsa20Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/Salsa20Test.kt deleted file mode 100644 index 051722f..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/Salsa20Test.kt +++ /dev/null @@ -1,395 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.symmetric.LatinDancesCommon.littleEndian -import com.ionspin.kotlin.crypto.symmetric.LatinDancesCommon.littleEndianInverted -import com.ionspin.kotlin.crypto.util.fromLittleEndianToUInt -import com.ionspin.kotlin.crypto.util.hexStringToUByteArray -import com.ionspin.kotlin.crypto.util.rotateLeft -import com.ionspin.kotlin.crypto.util.toHexString -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 14-Jun-2020 - */ -class Salsa20Test { - - @Test - fun testRotateLeft() { - val a = 0xc0a8787eU - val b = a rotateLeft 5 - val expected = 0x150f0fd8U - assertEquals(b, expected) - } - - @Test - fun testQuarterRound() { - assertTrue { - val input = uintArrayOf(0U, 0U, 0U, 0U) - val expected = uintArrayOf(0U, 0U, 0U, 0U) - Salsa20Pure.quarterRound(input, 0, 1, 2, 3) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - - expected.contentEquals(input) - } - - assertTrue { - val input = uintArrayOf(1U, 0U, 0U, 0U) - val expected = uintArrayOf(0x08008145U, 0x00000080U, 0x00010200U, 0x20500000U) - Salsa20Pure.quarterRound(input, 0, 1, 2, 3) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - - expected.contentEquals(input) - } - - assertTrue { - val input = uintArrayOf(0U, 1U, 0U, 0U) - val expected = uintArrayOf(0x88000100U, 0x00000001U, 0x00000200U, 0x00402000U) - Salsa20Pure.quarterRound(input, 0, 1, 2, 3) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - - expected.contentEquals(input) - } - - assertTrue { - val input = uintArrayOf(0U, 0U, 1U, 0U) - val expected = uintArrayOf(0x80040000U, 0x00000000U, 0x00000001U, 0x00002000U) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - Salsa20Pure.quarterRound(input, 0, 1, 2, 3) - expected.contentEquals(input) - } - - assertTrue { - val input = uintArrayOf(0U, 0U, 0U, 1U) - val expected = uintArrayOf(0x00048044U, 0x00000080U, 0x00010000U, 0x20100001U) - Salsa20Pure.quarterRound(input, 0, 1, 2, 3) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - - expected.contentEquals(input) - } - - - assertTrue { - val input = uintArrayOf(0xd3917c5bU, 0x55f1c407U, 0x52a58a7aU, 0x8f887a3bU) - val expected = uintArrayOf(0x3e2f308cU, 0xd90a8f36U, 0x6ab2a923U, 0x2883524cU) - Salsa20Pure.quarterRound(input, 0, 1, 2, 3) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - expected.contentEquals(input) - } - } - - @Test - fun testRowRound() { - assertTrue { - val input = uintArrayOf( - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U - ) - val expected = uintArrayOf( - 0x08008145U, 0x00000080U, 0x00010200U, 0x20500000U, - 0x20100001U, 0x00048044U, 0x00000080U, 0x00010000U, - 0x00000001U, 0x00002000U, 0x80040000U, 0x00000000U, - 0x00000001U, 0x00000200U, 0x00402000U, 0x88000100U - ) - - Salsa20Pure.rowRound(input) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - expected.contentEquals(input) - } - assertTrue { - - val input = uintArrayOf( - 0x08521bd6U, 0x1fe88837U, 0xbb2aa576U, 0x3aa26365U, - 0xc54c6a5bU, 0x2fc74c2fU, 0x6dd39cc3U, 0xda0a64f6U, - 0x90a2f23dU, 0x067f95a6U, 0x06b35f61U, 0x41e4732eU, - 0xe859c100U, 0xea4d84b7U, 0x0f619bffU, 0xbc6e965aU - ) - val expected = uintArrayOf( - 0xa890d39dU, 0x65d71596U, 0xe9487daaU, 0xc8ca6a86U, - 0x949d2192U, 0x764b7754U, 0xe408d9b9U, 0x7a41b4d1U, - 0x3402e183U, 0x3c3af432U, 0x50669f96U, 0xd89ef0a8U, - 0x0040ede5U, 0xb545fbceU, 0xd257ed4fU, 0x1818882dU - ) - Salsa20Pure.rowRound(input) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - expected.contentEquals(input) - } - } - - @Test - fun testColumnRound() { - assertTrue { - val input = uintArrayOf( - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U - ) - val expected = uintArrayOf( - 0x10090288U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000101U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00020401U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x40a04001U, 0x00000000U, 0x00000000U, 0x00000000U - ) - - Salsa20Pure.columnRound(input) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - expected.contentEquals(input) - } - assertTrue { - - val input = uintArrayOf( - 0x08521bd6U, 0x1fe88837U, 0xbb2aa576U, 0x3aa26365U, - 0xc54c6a5bU, 0x2fc74c2fU, 0x6dd39cc3U, 0xda0a64f6U, - 0x90a2f23dU, 0x067f95a6U, 0x06b35f61U, 0x41e4732eU, - 0xe859c100U, 0xea4d84b7U, 0x0f619bffU, 0xbc6e965aU - ) - val expected = uintArrayOf( - 0x8c9d190aU, 0xce8e4c90U, 0x1ef8e9d3U, 0x1326a71aU, - 0x90a20123U, 0xead3c4f3U, 0x63a091a0U, 0xf0708d69U, - 0x789b010cU, 0xd195a681U, 0xeb7d5504U, 0xa774135cU, - 0x481c2027U, 0x53a8e4b5U, 0x4c1f89c5U, 0x3f78c9c8U - ) - Salsa20Pure.columnRound(input) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - expected.contentEquals(input) - } - } - - @Test - fun testDoubleRound() { - assertTrue { - val input = uintArrayOf( - 0x00000001U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U, - 0x00000000U, 0x00000000U, 0x00000000U, 0x00000000U - ) - val expected = uintArrayOf( - 0x8186a22dU, 0x0040a284U, 0x82479210U, 0x06929051U, - 0x08000090U, 0x02402200U, 0x00004000U, 0x00800000U, - 0x00010200U, 0x20400000U, 0x08008104U, 0x00000000U, - 0x20500000U, 0xa0000040U, 0x0008180aU, 0x612a8020U - ) - - Salsa20Pure.doubleRound(input) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - expected.contentEquals(input) - } - assertTrue { - - val input = uintArrayOf( - 0xde501066U, 0x6f9eb8f7U, 0xe4fbbd9bU, 0x454e3f57U, - 0xb75540d3U, 0x43e93a4cU, 0x3a6f2aa0U, 0x726d6b36U, - 0x9243f484U, 0x9145d1e8U, 0x4fa9d247U, 0xdc8dee11U, - 0x054bf545U, 0x254dd653U, 0xd9421b6dU, 0x67b276c1U - ) - val expected = uintArrayOf( - 0xccaaf672U, 0x23d960f7U, 0x9153e63aU, 0xcd9a60d0U, - 0x50440492U, 0xf07cad19U, 0xae344aa0U, 0xdf4cfdfcU, - 0xca531c29U, 0x8e7943dbU, 0xac1680cdU, 0xd503ca00U, - 0xa74b2ad6U, 0xbc331c5cU, 0x1dda24c7U, 0xee928277U - ) - Salsa20Pure.doubleRound(input) - println("Result ${input.joinToString { it.toString(16).padStart(2, '0') }}") - expected.contentEquals(input) - } - } - - @Test - fun littleEndianTest() { - assertTrue { - val input = ubyteArrayOf(86U, 75U, 30U, 9U) - val expected = 0x091e4b56U - val result = littleEndian(input, 0, 1, 2, 3) - result == expected - } - - assertTrue { - val input = ubyteArrayOf(255U, 255U, 255U, 250U) - val expected = 0xFAFFFFFFU - val result = littleEndian(input, 0, 1, 2, 3) - result == expected - } - } - - @Test - fun littleEndianInvertedArrayTest() { - assertTrue { - val expected = ubyteArrayOf(86U, 75U, 30U, 9U) - val input = uintArrayOf(0x091e4b56U) - val result = UByteArray(4) - littleEndianInverted(input, 0, result, 0) - result.contentEquals(expected) - } - - assertTrue { - val expected = ubyteArrayOf(255U, 255U, 255U, 250U) - val input = uintArrayOf(0xFAFFFFFFU) - val result = UByteArray(4) - littleEndianInverted(input, 0, result, 0) - result.contentEquals(expected) - } - } - - @Test - fun littleEndianInvertedTest() { - assertTrue { - val expected = ubyteArrayOf(86U, 75U, 30U, 9U) - val input = 0x091e4b56U - val result = UByteArray(4) - littleEndianInverted(input, result, 0) - result.contentEquals(expected) - } - - assertTrue { - val expected = ubyteArrayOf(255U, 255U, 255U, 250U) - val input = 0xFAFFFFFFU - val result = UByteArray(4) - littleEndianInverted(input, result, 0) - result.contentEquals(expected) - } - } - - @Test - fun salsa20HashTest() { - assertTrue { - val input = ubyteArrayOf( - 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, - 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, - 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, - 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U - ) - val expected = ubyteArrayOf( - 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, - 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, - 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, - 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U - ) - val result = Salsa20Pure.hash(input.fromLittleEndianToUInt()) - input.contentEquals(expected) - } - - assertTrue { - val input = ubyteArrayOf( - 211U, 159U, 13U, 115U, 76U, 55U, 82U, 183U, 3U, 117U, 222U, 37U, 191U, 187U, 234U, 136U, - 49U, 237U, 179U, 48U, 1U, 106U, 178U, 219U, 175U, 199U, 166U, 48U, 86U, 16U, 179U, 207U, - 31U, 240U, 32U, 63U, 15U, 83U, 93U, 161U, 116U, 147U, 48U, 113U, 238U, 55U, 204U, 36U, - 79U, 201U, 235U, 79U, 3U, 81U, 156U, 47U, 203U, 26U, 244U, 243U, 88U, 118U, 104U, 54U - ) - val expected = ubyteArrayOf( - 109U, 42U, 178U, 168U, 156U, 240U, 248U, 238U, 168U, 196U, 190U, 203U, 26U, 110U, 170U, 154U, - 29U, 29U, 150U, 26U, 150U, 30U, 235U, 249U, 190U, 163U, 251U, 48U, 69U, 144U, 51U, 57U, - 118U, 40U, 152U, 157U, 180U, 57U, 27U, 94U, 107U, 42U, 236U, 35U, 27U, 111U, 114U, 114U, - 219U, 236U, 232U, 135U, 111U, 155U, 110U, 18U, 24U, 232U, 95U, 158U, 179U, 19U, 48U, 202U - ) - val result = Salsa20Pure.hash(input.fromLittleEndianToUInt()) - result.contentEquals(expected) - } - - assertTrue { - val input = ubyteArrayOf( - 6U, 124U, 83U, 146U, 38U, 191U, 9U, 50U, 4U, 161U, 47U, 222U, 122U, 182U, 223U, 185U, - 75U, 27U, 0U, 216U, 16U, 122U, 7U, 89U, 162U, 104U, 101U, 147U, 213U, 21U, 54U, 95U, - 225U, 253U, 139U, 176U, 105U, 132U, 23U, 116U, 76U, 41U, 176U, 207U, 221U, 34U, 157U, 108U, - 94U, 94U, 99U, 52U, 90U, 117U, 91U, 220U, 146U, 190U, 239U, 143U, 196U, 176U, 130U, 186U - ) - val expected = ubyteArrayOf( - 8U, 18U, 38U, 199U, 119U, 76U, 215U, 67U, 173U, 127U, 144U, 162U, 103U, 212U, 176U, 217U, - 192U, 19U, 233U, 33U, 159U, 197U, 154U, 160U, 128U, 243U, 219U, 65U, 171U, 136U, 135U, 225U, - 123U, 11U, 68U, 86U, 237U, 82U, 20U, 155U, 133U, 189U, 9U, 83U, 167U, 116U, 194U, 78U, - 122U, 127U, 195U, 185U, 185U, 204U, 188U, 90U, 245U, 9U, 183U, 248U, 226U, 85U, 245U, 104U - ) - val result = (0 until 1_000_000).fold(input) { acc, _ -> - Salsa20Pure.hash(acc.fromLittleEndianToUInt()) - } - result.contentEquals(expected) - } - - } - - @Test - fun testExpansion() { - val k0 = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U, 16U) - val k1 = - ubyteArrayOf(201U, 202U, 203U, 204U, 205U, 206U, 207U, 208U, 209U, 210U, 211U, 212U, 213U, 214U, 215U, 216U) - val n = - ubyteArrayOf(101U, 102U, 103U, 104U, 105U, 106U, 107U, 108U, 109U, 110U, 111U, 112U, 113U, 114U, 115U, 116U) - - assertTrue { - val expected = ubyteArrayOf( - 69U, 37U, 68U, 39U, 41U, 15U, 107U, 193U, 255U, 139U, 122U, 6U, 170U, 233U, 217U, 98U, - 89U, 144U, 182U, 106U, 21U, 51U, 200U, 65U, 239U, 49U, 222U, 34U, 215U, 114U, 40U, 126U, - 104U, 197U, 7U, 225U, 197U, 153U, 31U, 2U, 102U, 78U, 76U, 176U, 84U, 245U, 246U, 184U, - 177U, 160U, 133U, 130U, 6U, 72U, 149U, 119U, 192U, 195U, 132U, 236U, 234U, 103U, 246U, 74U - ) - val result = Salsa20Pure.expansion32(k0 + k1, n) - result.contentEquals(expected) - } - - assertTrue { - val expected = ubyteArrayOf( - 39U, 173U, 46U, 248U, 30U, 200U, 82U, 17U, 48U, 67U, 254U, 239U, 37U, 18U, 13U, 247U, - 241U, 200U, 61U, 144U, 10U, 55U, 50U, 185U, 6U, 47U, 246U, 253U, 143U, 86U, 187U, 225U, - 134U, 85U, 110U, 246U, 161U, 163U, 43U, 235U, 231U, 94U, 171U, 51U, 145U, 214U, 112U, 29U, - 14U, 232U, 5U, 16U, 151U, 140U, 183U, 141U, 171U, 9U, 122U, 181U, 104U, 182U, 177U, 193U - ) - val result = Salsa20Pure.expansion16(k0, n) - result.contentEquals(expected) - } - } - - @Test - fun testSalsa20Encryption() { - assertTrue { - val key = "8000000000000000000000000000000000000000000000000000000000000000".hexStringToUByteArray() - val nonce = "0000000000000000".hexStringToUByteArray() - val expectedStartsWith = ( - "E3BE8FDD8BECA2E3EA8EF9475B29A6E7" + - "003951E1097A5C38D23B7A5FAD9F6844" + - "B22C97559E2723C7CBBD3FE4FC8D9A07" + - "44652A83E72A9C461876AF4D7EF1A117").toLowerCase() - val endsWith = ( - "696AFCFD0CDDCC83C7E77F11A649D79A" + - "CDC3354E9635FF137E929933A0BD6F53" + - "77EFA105A3A4266B7C0D089D08F1E855" + - "CC32B15B93784A36E56A76CC64BC8477" - ).toLowerCase() - - val ciphertext = Salsa20Pure.encrypt(key, nonce, UByteArray(512) { 0U }) - ciphertext.toHexString().toLowerCase().startsWith(expectedStartsWith) && - ciphertext.toHexString().toLowerCase().endsWith(endsWith) - } - - assertTrue { - val key = "0A5DB00356A9FC4FA2F5489BEE4194E73A8DE03386D92C7FD22578CB1E71C417".hexStringToUByteArray() - val nonce = "1F86ED54BB2289F0".hexStringToUByteArray() - val expectedStartsWith = ( - "3FE85D5BB1960A82480B5E6F4E965A44" + - "60D7A54501664F7D60B54B06100A37FF" + - "DCF6BDE5CE3F4886BA77DD5B44E95644" + - "E40A8AC65801155DB90F02522B644023").toLowerCase() - val endsWith = ( - "7998204FED70CE8E0D027B206635C08C" + - "8BC443622608970E40E3AEDF3CE790AE" + - "EDF89F922671B45378E2CD03F6F62356" + - "529C4158B7FF41EE854B1235373988C8" - ).toLowerCase() - - val ciphertext = Salsa20Pure.encrypt(key, nonce, UByteArray(131072) { 0U }) - println(ciphertext.slice(0 until 64).toTypedArray().toHexString()) - println(ciphertext.slice(131008 until 131072).toTypedArray().toHexString()) - ciphertext.slice(0 until 64).toTypedArray().toHexString().toLowerCase().startsWith(expectedStartsWith) && - ciphertext.slice(131008 until 131072).toTypedArray().toHexString().toLowerCase().contains(endsWith) - } - - - } - - -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/XChaCha20Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/XChaCha20Test.kt deleted file mode 100644 index 53c9d2a..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/XChaCha20Test.kt +++ /dev/null @@ -1,341 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import com.ionspin.kotlin.crypto.util.hexColumsPrint -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 17-Jun-2020 - */ -class XChaCha20Test { - - @Test - fun testHChaCha20() { - val key = ubyteArrayOf( - 0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U, 0x09U, - 0x0aU, 0x0bU, 0x0cU, 0x0dU, 0x0eU, 0x0fU, 0x10U, 0x11U, 0x12U, 0x13U, - 0x14U, 0x15U, 0x16U, 0x17U, 0x18U, 0x19U, 0x1aU, 0x1bU, 0x1cU, 0x1dU, - 0x1eU, 0x1fU - ) - - val nonce = ubyteArrayOf( - 0x00U, 0x00U, 0x00U, 0x09U, 0x00U, 0x00U, 0x00U, 0x4aU, - 0x00U, 0x00U, 0x00U, 0x00U, 0x31U, 0x41U, 0x59U, 0x27U - ) - - val expected = uintArrayOf( - 0x82413b42U, 0x27b27bfeU, 0xd30e4250U, 0x8a877d73U, - 0xa0f9e4d5U, 0x8a74a853U, 0xc12ec413U, 0x26d3ecdcU, - ) - - val result = XChaCha20Pure.hChacha(key, nonce) -// assertTrue { -// result.contentEquals(expected)//Returns little endia, expected big endian -// } - } - - @Test - fun testXChaCha20() { - val key = ubyteArrayOf( - 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, - 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, - 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, - 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU - ) - val nonce = ubyteArrayOf( - 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, - 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, - 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x58U - ) - val message = ubyteArrayOf( - 0x54U, 0x68U, 0x65U, 0x20U, 0x64U, 0x68U, 0x6fU, 0x6cU, - 0x65U, 0x20U, 0x28U, 0x70U, 0x72U, 0x6fU, 0x6eU, 0x6fU, - 0x75U, 0x6eU, 0x63U, 0x65U, 0x64U, 0x20U, 0x22U, 0x64U, - 0x6fU, 0x6cU, 0x65U, 0x22U, 0x29U, 0x20U, 0x69U, 0x73U, - 0x20U, 0x61U, 0x6cU, 0x73U, 0x6fU, 0x20U, 0x6bU, 0x6eU, - 0x6fU, 0x77U, 0x6eU, 0x20U, 0x61U, 0x73U, 0x20U, 0x74U, - 0x68U, 0x65U, 0x20U, 0x41U, 0x73U, 0x69U, 0x61U, 0x74U, - 0x69U, 0x63U, 0x20U, 0x77U, 0x69U, 0x6cU, 0x64U, 0x20U, - 0x64U, 0x6fU, 0x67U, 0x2cU, 0x20U, 0x72U, 0x65U, 0x64U, - 0x20U, 0x64U, 0x6fU, 0x67U, 0x2cU, 0x20U, 0x61U, 0x6eU, - 0x64U, 0x20U, 0x77U, 0x68U, 0x69U, 0x73U, 0x74U, 0x6cU, - 0x69U, 0x6eU, 0x67U, 0x20U, 0x64U, 0x6fU, 0x67U, 0x2eU, - 0x20U, 0x49U, 0x74U, 0x20U, 0x69U, 0x73U, 0x20U, 0x61U, - 0x62U, 0x6fU, 0x75U, 0x74U, 0x20U, 0x74U, 0x68U, 0x65U, - 0x20U, 0x73U, 0x69U, 0x7aU, 0x65U, 0x20U, 0x6fU, 0x66U, - 0x20U, 0x61U, 0x20U, 0x47U, 0x65U, 0x72U, 0x6dU, 0x61U, - 0x6eU, 0x20U, 0x73U, 0x68U, 0x65U, 0x70U, 0x68U, 0x65U, - 0x72U, 0x64U, 0x20U, 0x62U, 0x75U, 0x74U, 0x20U, 0x6cU, - 0x6fU, 0x6fU, 0x6bU, 0x73U, 0x20U, 0x6dU, 0x6fU, 0x72U, - 0x65U, 0x20U, 0x6cU, 0x69U, 0x6bU, 0x65U, 0x20U, 0x61U, - 0x20U, 0x6cU, 0x6fU, 0x6eU, 0x67U, 0x2dU, 0x6cU, 0x65U, - 0x67U, 0x67U, 0x65U, 0x64U, 0x20U, 0x66U, 0x6fU, 0x78U, - 0x2eU, 0x20U, 0x54U, 0x68U, 0x69U, 0x73U, 0x20U, 0x68U, - 0x69U, 0x67U, 0x68U, 0x6cU, 0x79U, 0x20U, 0x65U, 0x6cU, - 0x75U, 0x73U, 0x69U, 0x76U, 0x65U, 0x20U, 0x61U, 0x6eU, - 0x64U, 0x20U, 0x73U, 0x6bU, 0x69U, 0x6cU, 0x6cU, 0x65U, - 0x64U, 0x20U, 0x6aU, 0x75U, 0x6dU, 0x70U, 0x65U, 0x72U, - 0x20U, 0x69U, 0x73U, 0x20U, 0x63U, 0x6cU, 0x61U, 0x73U, - 0x73U, 0x69U, 0x66U, 0x69U, 0x65U, 0x64U, 0x20U, 0x77U, - 0x69U, 0x74U, 0x68U, 0x20U, 0x77U, 0x6fU, 0x6cU, 0x76U, - 0x65U, 0x73U, 0x2cU, 0x20U, 0x63U, 0x6fU, 0x79U, 0x6fU, - 0x74U, 0x65U, 0x73U, 0x2cU, 0x20U, 0x6aU, 0x61U, 0x63U, - 0x6bU, 0x61U, 0x6cU, 0x73U, 0x2cU, 0x20U, 0x61U, 0x6eU, - 0x64U, 0x20U, 0x66U, 0x6fU, 0x78U, 0x65U, 0x73U, 0x20U, - 0x69U, 0x6eU, 0x20U, 0x74U, 0x68U, 0x65U, 0x20U, 0x74U, - 0x61U, 0x78U, 0x6fU, 0x6eU, 0x6fU, 0x6dU, 0x69U, 0x63U, - 0x20U, 0x66U, 0x61U, 0x6dU, 0x69U, 0x6cU, 0x79U, 0x20U, - 0x43U, 0x61U, 0x6eU, 0x69U, 0x64U, 0x61U, 0x65U, 0x2eU, - ) - - val expected = ubyteArrayOf( - 0x7dU, 0x0aU, 0x2eU, 0x6bU, 0x7fU, 0x7cU, 0x65U, 0xa2U, - 0x36U, 0x54U, 0x26U, 0x30U, 0x29U, 0x4eU, 0x06U, 0x3bU, - 0x7aU, 0xb9U, 0xb5U, 0x55U, 0xa5U, 0xd5U, 0x14U, 0x9aU, - 0xa2U, 0x1eU, 0x4aU, 0xe1U, 0xe4U, 0xfbU, 0xceU, 0x87U, - 0xecU, 0xc8U, 0xe0U, 0x8aU, 0x8bU, 0x5eU, 0x35U, 0x0aU, - 0xbeU, 0x62U, 0x2bU, 0x2fU, 0xfaU, 0x61U, 0x7bU, 0x20U, - 0x2cU, 0xfaU, 0xd7U, 0x20U, 0x32U, 0xa3U, 0x03U, 0x7eU, - 0x76U, 0xffU, 0xdcU, 0xdcU, 0x43U, 0x76U, 0xeeU, 0x05U, - 0x3aU, 0x19U, 0x0dU, 0x7eU, 0x46U, 0xcaU, 0x1dU, 0xe0U, - 0x41U, 0x44U, 0x85U, 0x03U, 0x81U, 0xb9U, 0xcbU, 0x29U, - 0xf0U, 0x51U, 0x91U, 0x53U, 0x86U, 0xb8U, 0xa7U, 0x10U, - 0xb8U, 0xacU, 0x4dU, 0x02U, 0x7bU, 0x8bU, 0x05U, 0x0fU, - 0x7cU, 0xbaU, 0x58U, 0x54U, 0xe0U, 0x28U, 0xd5U, 0x64U, - 0xe4U, 0x53U, 0xb8U, 0xa9U, 0x68U, 0x82U, 0x41U, 0x73U, - 0xfcU, 0x16U, 0x48U, 0x8bU, 0x89U, 0x70U, 0xcaU, 0xc8U, - 0x28U, 0xf1U, 0x1aU, 0xe5U, 0x3cU, 0xabU, 0xd2U, 0x01U, - 0x12U, 0xf8U, 0x71U, 0x07U, 0xdfU, 0x24U, 0xeeU, 0x61U, - 0x83U, 0xd2U, 0x27U, 0x4fU, 0xe4U, 0xc8U, 0xb1U, 0x48U, - 0x55U, 0x34U, 0xefU, 0x2cU, 0x5fU, 0xbcU, 0x1eU, 0xc2U, - 0x4bU, 0xfcU, 0x36U, 0x63U, 0xefU, 0xaaU, 0x08U, 0xbcU, - 0x04U, 0x7dU, 0x29U, 0xd2U, 0x50U, 0x43U, 0x53U, 0x2dU, - 0xb8U, 0x39U, 0x1aU, 0x8aU, 0x3dU, 0x77U, 0x6bU, 0xf4U, - 0x37U, 0x2aU, 0x69U, 0x55U, 0x82U, 0x7cU, 0xcbU, 0x0cU, - 0xddU, 0x4aU, 0xf4U, 0x03U, 0xa7U, 0xceU, 0x4cU, 0x63U, - 0xd5U, 0x95U, 0xc7U, 0x5aU, 0x43U, 0xe0U, 0x45U, 0xf0U, - 0xccU, 0xe1U, 0xf2U, 0x9cU, 0x8bU, 0x93U, 0xbdU, 0x65U, - 0xafU, 0xc5U, 0x97U, 0x49U, 0x22U, 0xf2U, 0x14U, 0xa4U, - 0x0bU, 0x7cU, 0x40U, 0x2cU, 0xdbU, 0x91U, 0xaeU, 0x73U, - 0xc0U, 0xb6U, 0x36U, 0x15U, 0xcdU, 0xadU, 0x04U, 0x80U, - 0x68U, 0x0fU, 0x16U, 0x51U, 0x5aU, 0x7aU, 0xceU, 0x9dU, - 0x39U, 0x23U, 0x64U, 0x64U, 0x32U, 0x8aU, 0x37U, 0x74U, - 0x3fU, 0xfcU, 0x28U, 0xf4U, 0xddU, 0xb3U, 0x24U, 0xf4U, - 0xd0U, 0xf5U, 0xbbU, 0xdcU, 0x27U, 0x0cU, 0x65U, 0xb1U, - 0x74U, 0x9aU, 0x6eU, 0xffU, 0xf1U, 0xfbU, 0xaaU, 0x09U, - 0x53U, 0x61U, 0x75U, 0xccU, 0xd2U, 0x9fU, 0xb9U, 0xe6U, - 0x05U, 0x7bU, 0x30U, 0x73U, 0x20U, 0xd3U, 0x16U, 0x83U, - 0x8aU, 0x9cU, 0x71U, 0xf7U, 0x0bU, 0x5bU, 0x59U, 0x07U, - 0xa6U, 0x6fU, 0x7eU, 0xa4U, 0x9aU, 0xadU, 0xc4U, 0x09U, - - ) - - val result = XChaCha20Pure.xorWithKeystream(key, nonce, message, 1U) - assertTrue { - result.contentEquals(expected) - } - - } - - @Test - fun testXChaCha20Updateable() { - val key = ubyteArrayOf( - 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, - 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, - 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, - 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU - ) - val nonce = ubyteArrayOf( - 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, - 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, - 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x58U - ) - val message = ubyteArrayOf( - 0x54U, 0x68U, 0x65U, 0x20U, 0x64U, 0x68U, 0x6fU, 0x6cU, - 0x65U, 0x20U, 0x28U, 0x70U, 0x72U, 0x6fU, 0x6eU, 0x6fU, - 0x75U, 0x6eU, 0x63U, 0x65U, 0x64U, 0x20U, 0x22U, 0x64U, - 0x6fU, 0x6cU, 0x65U, 0x22U, 0x29U, 0x20U, 0x69U, 0x73U, - 0x20U, 0x61U, 0x6cU, 0x73U, 0x6fU, 0x20U, 0x6bU, 0x6eU, - 0x6fU, 0x77U, 0x6eU, 0x20U, 0x61U, 0x73U, 0x20U, 0x74U, - 0x68U, 0x65U, 0x20U, 0x41U, 0x73U, 0x69U, 0x61U, 0x74U, - 0x69U, 0x63U, 0x20U, 0x77U, 0x69U, 0x6cU, 0x64U, 0x20U, - 0x64U, 0x6fU, 0x67U, 0x2cU, 0x20U, 0x72U, 0x65U, 0x64U, - 0x20U, 0x64U, 0x6fU, 0x67U, 0x2cU, 0x20U, 0x61U, 0x6eU, - 0x64U, 0x20U, 0x77U, 0x68U, 0x69U, 0x73U, 0x74U, 0x6cU, - 0x69U, 0x6eU, 0x67U, 0x20U, 0x64U, 0x6fU, 0x67U, 0x2eU, - 0x20U, 0x49U, 0x74U, 0x20U, 0x69U, 0x73U, 0x20U, 0x61U, - 0x62U, 0x6fU, 0x75U, 0x74U, 0x20U, 0x74U, 0x68U, 0x65U, - 0x20U, 0x73U, 0x69U, 0x7aU, 0x65U, 0x20U, 0x6fU, 0x66U, - 0x20U, 0x61U, 0x20U, 0x47U, 0x65U, 0x72U, 0x6dU, 0x61U, - 0x6eU, 0x20U, 0x73U, 0x68U, 0x65U, 0x70U, 0x68U, 0x65U, - 0x72U, 0x64U, 0x20U, 0x62U, 0x75U, 0x74U, 0x20U, 0x6cU, - 0x6fU, 0x6fU, 0x6bU, 0x73U, 0x20U, 0x6dU, 0x6fU, 0x72U, - 0x65U, 0x20U, 0x6cU, 0x69U, 0x6bU, 0x65U, 0x20U, 0x61U, - 0x20U, 0x6cU, 0x6fU, 0x6eU, 0x67U, 0x2dU, 0x6cU, 0x65U, - 0x67U, 0x67U, 0x65U, 0x64U, 0x20U, 0x66U, 0x6fU, 0x78U, - 0x2eU, 0x20U, 0x54U, 0x68U, 0x69U, 0x73U, 0x20U, 0x68U, - 0x69U, 0x67U, 0x68U, 0x6cU, 0x79U, 0x20U, 0x65U, 0x6cU, - 0x75U, 0x73U, 0x69U, 0x76U, 0x65U, 0x20U, 0x61U, 0x6eU, - 0x64U, 0x20U, 0x73U, 0x6bU, 0x69U, 0x6cU, 0x6cU, 0x65U, - 0x64U, 0x20U, 0x6aU, 0x75U, 0x6dU, 0x70U, 0x65U, 0x72U, - 0x20U, 0x69U, 0x73U, 0x20U, 0x63U, 0x6cU, 0x61U, 0x73U, - 0x73U, 0x69U, 0x66U, 0x69U, 0x65U, 0x64U, 0x20U, 0x77U, - 0x69U, 0x74U, 0x68U, 0x20U, 0x77U, 0x6fU, 0x6cU, 0x76U, - 0x65U, 0x73U, 0x2cU, 0x20U, 0x63U, 0x6fU, 0x79U, 0x6fU, - 0x74U, 0x65U, 0x73U, 0x2cU, 0x20U, 0x6aU, 0x61U, 0x63U, - 0x6bU, 0x61U, 0x6cU, 0x73U, 0x2cU, 0x20U, 0x61U, 0x6eU, - 0x64U, 0x20U, 0x66U, 0x6fU, 0x78U, 0x65U, 0x73U, 0x20U, - 0x69U, 0x6eU, 0x20U, 0x74U, 0x68U, 0x65U, 0x20U, 0x74U, - 0x61U, 0x78U, 0x6fU, 0x6eU, 0x6fU, 0x6dU, 0x69U, 0x63U, - 0x20U, 0x66U, 0x61U, 0x6dU, 0x69U, 0x6cU, 0x79U, 0x20U, - 0x43U, 0x61U, 0x6eU, 0x69U, 0x64U, 0x61U, 0x65U, 0x2eU, - ) - - val expected = ubyteArrayOf( - 0x7dU, 0x0aU, 0x2eU, 0x6bU, 0x7fU, 0x7cU, 0x65U, 0xa2U, - 0x36U, 0x54U, 0x26U, 0x30U, 0x29U, 0x4eU, 0x06U, 0x3bU, - 0x7aU, 0xb9U, 0xb5U, 0x55U, 0xa5U, 0xd5U, 0x14U, 0x9aU, - 0xa2U, 0x1eU, 0x4aU, 0xe1U, 0xe4U, 0xfbU, 0xceU, 0x87U, - 0xecU, 0xc8U, 0xe0U, 0x8aU, 0x8bU, 0x5eU, 0x35U, 0x0aU, - 0xbeU, 0x62U, 0x2bU, 0x2fU, 0xfaU, 0x61U, 0x7bU, 0x20U, - 0x2cU, 0xfaU, 0xd7U, 0x20U, 0x32U, 0xa3U, 0x03U, 0x7eU, - 0x76U, 0xffU, 0xdcU, 0xdcU, 0x43U, 0x76U, 0xeeU, 0x05U, - 0x3aU, 0x19U, 0x0dU, 0x7eU, 0x46U, 0xcaU, 0x1dU, 0xe0U, - 0x41U, 0x44U, 0x85U, 0x03U, 0x81U, 0xb9U, 0xcbU, 0x29U, - 0xf0U, 0x51U, 0x91U, 0x53U, 0x86U, 0xb8U, 0xa7U, 0x10U, - 0xb8U, 0xacU, 0x4dU, 0x02U, 0x7bU, 0x8bU, 0x05U, 0x0fU, - 0x7cU, 0xbaU, 0x58U, 0x54U, 0xe0U, 0x28U, 0xd5U, 0x64U, - 0xe4U, 0x53U, 0xb8U, 0xa9U, 0x68U, 0x82U, 0x41U, 0x73U, - 0xfcU, 0x16U, 0x48U, 0x8bU, 0x89U, 0x70U, 0xcaU, 0xc8U, - 0x28U, 0xf1U, 0x1aU, 0xe5U, 0x3cU, 0xabU, 0xd2U, 0x01U, - 0x12U, 0xf8U, 0x71U, 0x07U, 0xdfU, 0x24U, 0xeeU, 0x61U, - 0x83U, 0xd2U, 0x27U, 0x4fU, 0xe4U, 0xc8U, 0xb1U, 0x48U, - 0x55U, 0x34U, 0xefU, 0x2cU, 0x5fU, 0xbcU, 0x1eU, 0xc2U, - 0x4bU, 0xfcU, 0x36U, 0x63U, 0xefU, 0xaaU, 0x08U, 0xbcU, - 0x04U, 0x7dU, 0x29U, 0xd2U, 0x50U, 0x43U, 0x53U, 0x2dU, - 0xb8U, 0x39U, 0x1aU, 0x8aU, 0x3dU, 0x77U, 0x6bU, 0xf4U, - 0x37U, 0x2aU, 0x69U, 0x55U, 0x82U, 0x7cU, 0xcbU, 0x0cU, - 0xddU, 0x4aU, 0xf4U, 0x03U, 0xa7U, 0xceU, 0x4cU, 0x63U, - 0xd5U, 0x95U, 0xc7U, 0x5aU, 0x43U, 0xe0U, 0x45U, 0xf0U, - 0xccU, 0xe1U, 0xf2U, 0x9cU, 0x8bU, 0x93U, 0xbdU, 0x65U, - 0xafU, 0xc5U, 0x97U, 0x49U, 0x22U, 0xf2U, 0x14U, 0xa4U, - 0x0bU, 0x7cU, 0x40U, 0x2cU, 0xdbU, 0x91U, 0xaeU, 0x73U, - 0xc0U, 0xb6U, 0x36U, 0x15U, 0xcdU, 0xadU, 0x04U, 0x80U, - 0x68U, 0x0fU, 0x16U, 0x51U, 0x5aU, 0x7aU, 0xceU, 0x9dU, - 0x39U, 0x23U, 0x64U, 0x64U, 0x32U, 0x8aU, 0x37U, 0x74U, - 0x3fU, 0xfcU, 0x28U, 0xf4U, 0xddU, 0xb3U, 0x24U, 0xf4U, - 0xd0U, 0xf5U, 0xbbU, 0xdcU, 0x27U, 0x0cU, 0x65U, 0xb1U, - 0x74U, 0x9aU, 0x6eU, 0xffU, 0xf1U, 0xfbU, 0xaaU, 0x09U, - 0x53U, 0x61U, 0x75U, 0xccU, 0xd2U, 0x9fU, 0xb9U, 0xe6U, - 0x05U, 0x7bU, 0x30U, 0x73U, 0x20U, 0xd3U, 0x16U, 0x83U, - 0x8aU, 0x9cU, 0x71U, 0xf7U, 0x0bU, 0x5bU, 0x59U, 0x07U, - 0xa6U, 0x6fU, 0x7eU, 0xa4U, 0x9aU, 0xadU, 0xc4U, 0x09U, - - ) - - val xChaCha = XChaCha20Pure(key, nonce, 1U) - val firstChunk = xChaCha.xorWithKeystream(message.sliceArray(0 until 5)) - val secondChunk = xChaCha.xorWithKeystream(message.sliceArray(5 until 90)) - val thirdChunk = xChaCha.xorWithKeystream(message.sliceArray(90 until message.size)) - val result = firstChunk + secondChunk + thirdChunk - assertTrue { - (result).contentEquals(expected) - } - - } - - @Test - fun testXChaCha20UpdateableLonger() { - val key = ubyteArrayOf( - 0x80U, 0x81U, 0x82U, 0x83U, 0x84U, 0x85U, 0x86U, 0x87U, - 0x88U, 0x89U, 0x8aU, 0x8bU, 0x8cU, 0x8dU, 0x8eU, 0x8fU, - 0x90U, 0x91U, 0x92U, 0x93U, 0x94U, 0x95U, 0x96U, 0x97U, - 0x98U, 0x99U, 0x9aU, 0x9bU, 0x9cU, 0x9dU, 0x9eU, 0x9fU - ) - val nonce = ubyteArrayOf( - 0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, - 0x48U, 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, - 0x50U, 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x58U - ) - val message = ("This is a longer message that should cover all cases in the updateable algorithm. This string is 112 bytes long." + - "This is a longer message that should cover all cases in the updateable algorithm. This string is 112 bytes long." + - "This is a longer message that should cover all cases in the updateable algorithm. This string is 112 bytes long." + - "This is a longer message that should cover all cases in the updateable algorithm. This string is 112 bytes long.").encodeToUByteArray() - - val expected = ubyteArrayOf( - 0x7DU, 0x0AU, 0x22U, 0x38U, 0x3BU, 0x7DU, 0x79U, 0xEEU, - 0x32U, 0x54U, 0x62U, 0x2FU, 0x35U, 0x46U, 0x0DU, 0x26U, - 0x2FU, 0xBAU, 0xB3U, 0x43U, 0xB2U, 0x94U, 0x51U, 0x9BU, - 0xEDU, 0x06U, 0x47U, 0xA2U, 0xB9U, 0xFBU, 0xD4U, 0x9CU, - 0xA3U, 0xDCU, 0xE0U, 0x9DU, 0xC4U, 0x1DU, 0x31U, 0x12U, - 0xB4U, 0x67U, 0x65U, 0x6EU, 0xF7U, 0x7EU, 0x7BU, 0x37U, - 0x25U, 0xECU, 0x92U, 0x12U, 0x61U, 0xA3U, 0x0CU, 0x2AU, - 0x6BU, 0xF4U, 0x99U, 0x8BU, 0x5FU, 0x6AU, 0xEEU, 0x44U, - 0x2AU, 0x13U, 0x0BU, 0x30U, 0x0AU, 0xDDU, 0x58U, 0xE5U, - 0x0DU, 0x47U, 0x85U, 0x16U, 0xC4U, 0xEDU, 0xC2U, 0x2AU, - 0xBAU, 0x51U, 0xB2U, 0x53U, 0x86U, 0xB8U, 0xF3U, 0x0FU, - 0xA5U, 0xB0U, 0x43U, 0x4CU, 0x78U, 0xC4U, 0x0BU, 0x52U, - 0x7CU, 0xC2U, 0x1DU, 0x46U, 0xA9U, 0x39U, 0x8CU, 0x71U, - 0xE3U, 0x4FU, 0xEDU, 0xB1U, 0x27U, 0x98U, 0x4EU, 0x38U, - 0x88U, 0x0DU, 0x48U, 0x82U, 0xCCU, 0x39U, 0xD6U, 0x8EU, - 0x69U, 0xB0U, 0x56U, 0xCDU, 0x37U, 0xBEU, 0xDAU, 0x12U, - 0x5CU, 0xB5U, 0x67U, 0x1CU, 0xC9U, 0x35U, 0xE1U, 0x61U, - 0xD1U, 0xC2U, 0x6FU, 0x4CU, 0xE5U, 0x9CU, 0xE2U, 0x4CU, - 0x55U, 0x2EU, 0xE8U, 0x3BU, 0x5FU, 0xB2U, 0x1EU, 0xC6U, - 0x4BU, 0xAEU, 0x7AU, 0x6BU, 0xE8U, 0xA3U, 0x08U, 0xBEU, - 0x45U, 0x62U, 0x23U, 0xCFU, 0x17U, 0x07U, 0x51U, 0x68U, - 0xABU, 0x36U, 0x1AU, 0xCEU, 0x68U, 0x61U, 0x60U, 0xEDU, - 0x6DU, 0x6FU, 0x5CU, 0x5FU, 0x87U, 0x6AU, 0xCBU, 0x05U, - 0xD8U, 0x4AU, 0xF3U, 0x1DU, 0xB7U, 0x9AU, 0x41U, 0x62U, - 0x8EU, 0xC6U, 0xFAU, 0x44U, 0x4FU, 0xB3U, 0x04U, 0xEDU, - 0xDCU, 0xB3U, 0xE8U, 0x99U, 0x85U, 0xDFU, 0xB8U, 0x73U, - 0xEBU, 0xD4U, 0xCCU, 0x0EU, 0x6FU, 0xE0U, 0x08U, 0xA2U, - 0x4EU, 0x66U, 0x13U, 0x60U, 0xD7U, 0x93U, 0xA8U, 0x2EU, - 0xE7U, 0xB7U, 0x39U, 0x0FU, 0x88U, 0xA0U, 0x57U, 0xD7U, - 0x60U, 0x5BU, 0x12U, 0x1EU, 0x43U, 0x72U, 0xC7U, 0x99U, - 0x7CU, 0x3DU, 0x2DU, 0x37U, 0x22U, 0x84U, 0x29U, 0x7EU, - 0x6BU, 0xEDU, 0x33U, 0xB9U, 0x89U, 0xF9U, 0x36U, 0xFFU, - 0xD4U, 0xE1U, 0xBBU, 0xCBU, 0x2BU, 0x4FU, 0x6BU, 0xA9U, - 0x75U, 0xC8U, 0x28U, 0xF1U, 0xE5U, 0xF2U, 0xF9U, 0x4AU, - 0x5BU, 0x7CU, 0x30U, 0xCBU, 0x9AU, 0x93U, 0xF7U, 0xB2U, - 0x10U, 0x6BU, 0x3AU, 0x3DU, 0x3AU, 0xCEU, 0x1BU, 0x81U, - 0xDEU, 0x9FU, 0x71U, 0xF8U, 0x0EU, 0x52U, 0x00U, 0x46U, - 0x89U, 0x69U, 0x7FU, 0xBFU, 0x97U, 0xB8U, 0xC9U, 0x4AU, - 0x3AU, 0x37U, 0x31U, 0x1EU, 0x88U, 0x68U, 0x35U, 0x98U, - 0x76U, 0x93U, 0xCDU, 0x91U, 0xF7U, 0x6AU, 0x59U, 0xE6U, - 0x82U, 0xB6U, 0x85U, 0x67U, 0x3FU, 0xF5U, 0x9EU, 0x82U, - 0x2DU, 0xFFU, 0x81U, 0x5EU, 0xEAU, 0x3BU, 0xCCU, 0xFBU, - 0x1BU, 0x87U, 0x4AU, 0x93U, 0x40U, 0x96U, 0x3CU, 0xB2U, - 0x8EU, 0xCCU, 0x38U, 0x00U, 0x3FU, 0xBAU, 0xCCU, 0x84U, - 0x88U, 0x2BU, 0xF0U, 0x11U, 0x09U, 0xD5U, 0xAAU, 0x54U, - 0x3AU, 0x5BU, 0x98U, 0xE6U, 0xADU, 0xC0U, 0xB9U, 0x95U, - 0x53U, 0xDFU, 0x9DU, 0x91U, 0x01U, 0x66U, 0x7CU, 0xB3U, - 0xD8U, 0x2BU, 0x2DU, 0xBCU, 0xE0U, 0x77U, 0x71U, 0x59U, - 0x36U, 0xACU, 0x6DU, 0x5EU, 0x55U, 0xC9U, 0x29U, 0x40U, - 0xD4U, 0xA2U, 0x5BU, 0xBDU, 0xC2U, 0xE2U, 0x98U, 0x3DU, - 0x8CU, 0x9FU, 0x07U, 0xE4U, 0x21U, 0x84U, 0x4CU, 0x12U, - 0x83U, 0x77U, 0x88U, 0x06U, 0xA4U, 0x6FU, 0xDFU, 0x9EU, - 0xF5U, 0xD3U, 0xE1U, 0xFCU, 0x49U, 0x66U, 0x36U, 0x96U, - 0x48U, 0xC7U, 0x32U, 0xBAU, 0x73U, 0xFFU, 0xEFU, 0xCCU, - 0x00U, 0xC2U, 0x56U, 0x9CU, 0xD0U, 0x70U, 0x2AU, 0x4FU, - 0x82U, 0xB4U, 0x0BU, 0x68U, 0xEAU, 0xC1U, 0x87U, 0xB3U, - - ) - - val xChaCha = XChaCha20Pure(key, nonce, 1U) - val firstChunk = xChaCha.xorWithKeystream(message.sliceArray(0 until 50)) - val secondChunk = xChaCha.xorWithKeystream(message.sliceArray(50 until 200)) - val thirdChunk = xChaCha.xorWithKeystream(message.sliceArray(200 until message.size)) - val result = (firstChunk + secondChunk + thirdChunk) - assertTrue { - result.contentEquals(expected) - } - - - - } - -} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/XSalsa20Test.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/XSalsa20Test.kt deleted file mode 100644 index 4f74b04..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/XSalsa20Test.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.ionspin.kotlin.crypto.symmetric - -import com.ionspin.kotlin.crypto.hash.encodeToUByteArray -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 16-Jun-2020 - */ -class XSalsa20Test { - @Test - fun testXSalsa20() { - // values from https://go.googlesource.com/crypto/+/master/salsa20/salsa20_test.go xSalsa20TestData - assertTrue { - val message = "Hello world!".encodeToUByteArray() - val nonce = "24-byte nonce for xsalsa".encodeToUByteArray() - val key = "this is 32-byte key for xsalsa20".encodeToUByteArray() - val expected = ubyteArrayOf(0x00U, 0x2dU, 0x45U, 0x13U, 0x84U, 0x3fU, 0xc2U, 0x40U, 0xc4U, 0x01U, 0xe5U, 0x41U) - val result = XSalsa20Pure.encrypt(key, nonce, message) - result.contentEquals(expected) - } - - assertTrue { - val message = UByteArray(64) { 0U } - val nonce = "24-byte nonce for xsalsa".encodeToUByteArray() - val key = "this is 32-byte key for xsalsa20".encodeToUByteArray() - val expected = ubyteArrayOf( - 0x48U, 0x48U, 0x29U, 0x7fU, 0xebU, 0x1fU, 0xb5U, 0x2fU, 0xb6U, - 0x6dU, 0x81U, 0x60U, 0x9bU, 0xd5U, 0x47U, 0xfaU, 0xbcU, 0xbeU, 0x70U, - 0x26U, 0xedU, 0xc8U, 0xb5U, 0xe5U, 0xe4U, 0x49U, 0xd0U, 0x88U, 0xbfU, - 0xa6U, 0x9cU, 0x08U, 0x8fU, 0x5dU, 0x8dU, 0xa1U, 0xd7U, 0x91U, 0x26U, - 0x7cU, 0x2cU, 0x19U, 0x5aU, 0x7fU, 0x8cU, 0xaeU, 0x9cU, 0x4bU, 0x40U, - 0x50U, 0xd0U, 0x8cU, 0xe6U, 0xd3U, 0xa1U, 0x51U, 0xecU, 0x26U, 0x5fU, - 0x3aU, 0x58U, 0xe4U, 0x76U, 0x48U - ) - val result = XSalsa20Pure.encrypt(key, nonce, message) - result.contentEquals(expected) - } - - - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt deleted file mode 100644 index 3cb5304..0000000 --- a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/util/TestUtil.kt +++ /dev/null @@ -1,36 +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 kotlin.coroutines.Continuation -import kotlin.coroutines.EmptyCoroutineContext -import kotlin.coroutines.startCoroutine - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 20-Jul-2019 - */ -fun testBlocking(block : suspend () -> Unit) { - val continuation = Continuation(EmptyCoroutineContext) { - //Do nothing - if (it.isFailure) { - throw it.exceptionOrNull()!! - } - } - block.startCoroutine(continuation) -} diff --git a/multiplatform-crypto/src/iosMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto/src/iosMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto/src/iosTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto/src/iosTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index d9ddbd0..0000000 --- a/multiplatform-crypto/src/jsMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -1,60 +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 - -import kotlin.browser.window - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -actual object SRNG { - var counter = 0 - - actual fun getRandomBytes(amount: Int): UByteArray { - val runningOnNode = jsTypeOf(window) == "undefined" - val randomBytes = if (runningOnNode) { - println("Running on node") - js("require('crypto')").randomBytes(amount).toJSON().data - } else { - println("Running in browser") - js( - """ - var randomArray = new Uint8Array(amount); - var crypto = (self.crypto || self.msCrypto); - crypto.getRandomValues(randomArray); - """ - ) - var randomArrayResult = js("Array.prototype.slice.call(randomArray);") - randomArrayResult - } - println("Random bytes: $randomBytes") - print("Byte at ${randomBytes[0]}") - val randomBytesUByteArray = UByteArray(amount) { - 0U - } - for (i in 0 until amount) { - js(""" - randomBytesUByteArray[i] = randomBytes[i] - """) - } - return randomBytesUByteArray - } - - -} \ No newline at end of file diff --git a/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/SRNGJsTest.kt b/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/SRNGJsTest.kt deleted file mode 100644 index 594e59f..0000000 --- a/multiplatform-crypto/src/jsTest/kotlin/com/ionspin/kotlin/crypto/SRNGJsTest.kt +++ /dev/null @@ -1,49 +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 - -import kotlin.test.Test -import kotlin.test.assertTrue - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 05-Jan-2020 - */ - -class SRNGJsTest { - - @Test - fun testJsSrng() { - val bytes1 = SRNG.getRandomBytes(10) - val bytes2 = SRNG.getRandomBytes(10) - println("BYTES1") - bytes1.forEach { - print(it.toString(16).padStart(2, '0')) - } - println("BYTES2") - bytes2.forEach { - print(it.toString(16).padStart(2, '0')) - } - assertTrue { - !bytes1.contentEquals(bytes2) && - bytes1.size == 10 && - bytes2.size == 10 - } - - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/jvmMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto/src/jvmMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index 3d50e6f..0000000 --- a/multiplatform-crypto/src/jvmMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -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 - -import java.security.SecureRandom - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ - -actual object SRNG { - val secureRandom = SecureRandom() - actual fun getRandomBytes(amount: Int): UByteArray { - val byteArray = ByteArray(amount) - secureRandom.nextBytes(byteArray) - return byteArray.asUByteArray() - } -} diff --git a/multiplatform-crypto/src/linuxMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto/src/linuxMain/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto/src/linuxTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto/src/linuxTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto/src/mingwX64Main/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto/src/mingwX64Main/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index c9172fd..0000000 --- a/multiplatform-crypto/src/mingwX64Main/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -1,43 +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 - -import kotlinx.cinterop.* -import platform.windows.* - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -actual object SRNG { - private val advapi by lazy { LoadLibraryA("ADVAPI32.DLL")} - - private val advapiRandom by lazy { - GetProcAddress(advapi, "SystemFunction036")?.reinterpret, ULong, Int>>>() ?: error("Failed getting advapi random") - } - - @Suppress("EXPERIMENTAL_UNSIGNED_LITERALS") - actual fun getRandomBytes(amount: Int): UByteArray { - memScoped { - val randArray = allocArray(amount) - val pointer = randArray.getPointer(this) - val status = advapiRandom(pointer.reinterpret(), amount.convert()) - return UByteArray(amount) { pointer[it].toUByte() } - } - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt b/multiplatform-crypto/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt deleted file mode 100644 index e76cf80..0000000 --- a/multiplatform-crypto/src/nativeMain/kotlin/com/ionspin/kotlin/crypto/SRNG.kt +++ /dev/null @@ -1,41 +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 - -import kotlinx.cinterop.* -import platform.posix.* - -/** - * Created by Ugljesa Jovanovic - * ugljesa.jovanovic@ionspin.com - * on 21-Sep-2019 - */ -actual object SRNG { - @Suppress("EXPERIMENTAL_UNSIGNED_LITERALS") - actual fun getRandomBytes(amount: Int): UByteArray { - memScoped { - val array = allocArray(amount) - val urandomFile = fopen("/dev/urandom", "rb") - if (urandomFile != null) { - fread(array, 1, amount.convert(), urandomFile) - } - return UByteArray(amount) { - array[it] - } - } - } -} \ No newline at end of file diff --git a/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto/src/nativeTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/settings.gradle.kts b/settings.gradle.kts index 085d14b..884beca 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -36,8 +36,6 @@ pluginManagement { enableFeaturePreview("GRADLE_METADATA") rootProject.name = "KotlinMultiplatformCrypto" include("multiplatform-crypto-api") -include("multiplatform-crypto") -include("multiplatform-crypto-delegated") include("multiplatform-crypto-libsodium-bindings") include("sample") diff --git a/windowsBuild-delegated.sh b/windowsBuild-delegated.sh index 67662a6..3a2bcbe 100755 --- a/windowsBuild-delegated.sh +++ b/windowsBuild-delegated.sh @@ -12,7 +12,6 @@ make -j4 -C libsodium install echo "completed libsodium build" #now we can do the delegated build cd .. -./gradlew --no-daemon multiplatform-crypto-delegated:build || exit 1 #and then libsodium bindings ./gradlew --no-daemon multiplatform-crypto-libsodium-bindings:build || exit 1 exit 0 diff --git a/windowsBuild-pure.sh b/windowsBuild-pure.sh deleted file mode 100755 index 9286a7d..0000000 --- a/windowsBuild-pure.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -./gradlew --no-daemon multiplatform-crypto-api:build || exit 1 -./gradlew --no-daemon multiplatform-crypto:build || exit 1 -exit 0 - - diff --git a/windowsBuildAndPublish-delegated.sh b/windowsBuildAndPublish-delegated.sh index 2215ea9..9281e98 100755 --- a/windowsBuildAndPublish-delegated.sh +++ b/windowsBuildAndPublish-delegated.sh @@ -12,9 +12,6 @@ make -j4 -C libsodium install echo "completed libsodium build" #now we can do the delegated build cd .. -./gradlew --no-daemon multiplatform-crypto-delegated:build || exit 1 -./gradlew --no-daemon multiplatform-crypto-delegated:publishMingwX64PublicationToSnapshotRepository || exit 1 - ./gradlew --no-daemon multiplatform-crypto-libsodium-bindings:build || exit 1 ./gradlew --no-daemon multiplatform-crypto-libsodium-bindings:publishMingwX64PublicationToSnapshotRepository || exit 1 exit 0 diff --git a/windowsBuildAndPublish-pure.sh b/windowsBuildAndPublish-pure.sh deleted file mode 100755 index 9f5bf76..0000000 --- a/windowsBuildAndPublish-pure.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -#this will hopefully download all konan dependancies that we use in the build scripts -./gradlew clean || exit 1 -./gradlew --no-daemon multiplatform-crypto-api:build || exit 1 -./gradlew --no-daemon multiplatform-crypto:build || exit 1 -./gradlew --no-daemon multiplatform-crypto:publishMingwX64PublicationToSnapshotRepository || exit 1 -exit 0 From 725c20d7249fbe1ff7e9e7a6bc18cad5910e85ef Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Sat, 9 Jan 2021 13:46:55 +0100 Subject: [PATCH 11/11] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0abc43b..4188c2b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![pipeline status](https://gitlab.com/ionspin-github-ci/kotlin-multiplatform-crypto-ci/badges/master/pipeline.svg)](https://gitlab.com/ionspin-github-ci/kotlin-multiplatform-crypto-ci/-/commits/master) +[![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) ![Danger: Experimental](https://camo.githubusercontent.com/275bc882f21b154b5537b9c123a171a30de9e6aa/68747470733a2f2f7261772e6769746875622e636f6d2f63727970746f7370686572652f63727970746f7370686572652f6d61737465722f696d616765732f6578706572696d656e74616c2e706e67)