diff --git a/jvmSample/out/test/classes/JvmTest.class b/jvmSample/out/test/classes/JvmTest.class index f609dc8..69b089b 100644 Binary files a/jvmSample/out/test/classes/JvmTest.class and b/jvmSample/out/test/classes/JvmTest.class differ diff --git a/jvmSample/src/test/kotlin/JvmTest.kt b/jvmSample/src/test/kotlin/JvmTest.kt index 6d763f9..9babc83 100644 --- a/jvmSample/src/test/kotlin/JvmTest.kt +++ b/jvmSample/src/test/kotlin/JvmTest.kt @@ -34,6 +34,9 @@ class JvmTest { fun testNothing() { JvmSample.nothing() assertTrue { true } + val arr = ubyteArrayOf(0U) + val bla = ubyteArrayOf(1U) + arr.copyInto(bla) } 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 index 06aa497..1632516 100644 --- 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 @@ -26,7 +26,6 @@ import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.argonBlake2bAr import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.compressionFunctionG import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.validateArgonParameters import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToUInt -import com.ionspin.kotlin.crypto.util.toLittleEndianTypedUByteArray import com.ionspin.kotlin.crypto.util.toLittleEndianUByteArray /** @@ -300,16 +299,18 @@ class Argon2( } 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 = Blake2b.digest( - parallelism.toUInt() - .toLittleEndianTypedUByteArray() + tagLength.toLittleEndianTypedUByteArray() + memorySize.toLittleEndianTypedUByteArray() + - numberOfIterations.toUInt() - .toLittleEndianTypedUByteArray() + versionNumber.toLittleEndianTypedUByteArray() + argonType.typeId.toUInt() - .toLittleEndianTypedUByteArray() + - password.size.toUInt().toLittleEndianTypedUByteArray() + password + - salt.size.toUInt().toLittleEndianTypedUByteArray() + salt + - key.size.toUInt().toLittleEndianTypedUByteArray() + key + - associatedData.size.toUInt().toLittleEndianTypedUByteArray() + associatedData + blakeInput.toTypedArray() ).toUByteArray() //Compute B[i][0] @@ -318,7 +319,7 @@ class Argon2( argonBlake2bArbitraryLenghtHash( (h0 + 0.toUInt().toLittleEndianUByteArray() + i.toUInt().toLittleEndianUByteArray()).toUByteArray(), 1024U - ).toUByteArray() + ) } //Compute B[i][1] @@ -327,7 +328,7 @@ class Argon2( argonBlake2bArbitraryLenghtHash( (h0 + 1.toUInt().toLittleEndianUByteArray() + i.toUInt().toLittleEndianUByteArray()).toUByteArray(), 1024U - ).toUByteArray() + ) } executeArgonWithSingleThread() 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 index 72b59cd..bfc000d 100644 --- 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 @@ -19,7 +19,12 @@ package com.ionspin.kotlin.crypto.keyderivation.argon2 import com.ionspin.kotlin.crypto.hash.blake2b.Blake2b -import com.ionspin.kotlin.crypto.util.* +import com.ionspin.kotlin.crypto.util.arrayChunked +import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToULong +import com.ionspin.kotlin.crypto.util.plus +import com.ionspin.kotlin.crypto.util.rotateRight +import com.ionspin.kotlin.crypto.util.toLittleEndianUByteArray +import com.ionspin.kotlin.crypto.util.xor /** * Created by Ugljesa Jovanovic @@ -95,6 +100,10 @@ object Argon2Utils { val endOfRow = startOfRow + (8 * 16) val rowToMix = r.copyOfRange(startOfRow, endOfRow) mixRound(rowToMix) + .map { it.toLittleEndianUByteArray() } + .flatMap { it.asIterable() } + .toUByteArray() + .copyInto(q, startOfRow) } // Do the argon/blake2b mixing on columns @@ -103,7 +112,7 @@ object Argon2Utils { z, i, mixRound(extractColumnFromGBlock(q, i)) - .map { it.toLittleEndianTypedUByteArray() } + .map { it.toLittleEndianUByteArray() } .flatMap { it.asIterable() } .toUByteArray() )