From 4ea04eb90d5f3526bee71caea254ebce1f0a749d Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Tue, 19 May 2020 23:48:59 +0200 Subject: [PATCH] Tests are back up --- jvmSample/out/test/classes/JvmTest.class | Bin 3617 -> 3791 bytes jvmSample/src/test/kotlin/JvmTest.kt | 3 +++ .../crypto/keyderivation/argon2/Argon2.kt | 25 +++++++++--------- .../keyderivation/argon2/Argon2Utils.kt | 13 +++++++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/jvmSample/out/test/classes/JvmTest.class b/jvmSample/out/test/classes/JvmTest.class index f609dc8686d06b6e0a3e50490001bbd211ee4904..69b089b80e9468e7f1ef4bc1234989fddcc0c235 100644 GIT binary patch delta 1508 zcmZux>r)d~6#w1qZgyD$4S@w#-Y5t{2=Z8QRS;UmRiKq;F?|?Gijk1mB%)YrY^#00 z?5%C>Q?yp?TWo>WPRp0hblU0oq2o;d06Wvq{R6aT16DtDCTH)t=l;&UzkAN_W~TUB ziTdl!?|%f)f^RRYzq3@%L@XHzM}0$G)5%b0JRX>qQOV#M4mH?sQrOxFg7_5h$Iyllz*EeZ6~9RdmY6&CN`*8 zkBtma(9S4&L}(LaZ04sN+cUdxZw5MXA44m}Tf`avO{9Hfp82FA^D1=D=Dyg_*aN9_2M{G7Z>N#U41d5T|?HTDeuODRih58k=jNw`;vg=5GYWJ2KXqol>A2WNI9^u7ELsM zMdqZ4%`^wikO@cZ9Wq>$4VK|)^{kWKo89`R91-nCo{?*M%p9UwT(Wlon+#3Q(LGwO zmZxd5r^C}Ri!H3r%r^_nLQ^+Z7)3_0QDT;wWmnNXs+Z}dT8UPy6=^GUT`$xN^!$13 z=&75-{k`?3eRW+loma7QR2QiR^B7#jFh7~un0iQZH!fh0>DKSj-QVFc2S$!(vJ1C< z)8$3%UBo_5$08z(35>bhsmSp@Ptp{xVrq0AhdhVpaMVjSho?HW|a@rcN`vY@h)+0TPk zZQ0uLux~1@naBHgB-d(-1Sm_ha4jL0camVkRElXd0)?2RuLGaq3QuHpj~nJ%bh6))pZ$F#zX=EWBsM`wI-^pyu5eDFzq5&So8r#v{b|M{=yKmX<1pX$!l zs^4F|_zeI*KEI&;$avi1Z)j#vM`D@y#Q10|omX%pgZ{NE)HWjyGgttqp*={~41(m(nr(zFo z=O-kO{|-d$h~Q3!%H=W^D!7}$Rko#LnWQ(IPh?~J(+L^(^53Nzwx9nkHM2Ocv;L~w zkEDtO9^n64kM|s4s9wG{n$M;($|#ljG~V6!%CC# z1fEp!IF9id<%nR3hIpeb!cOx;HqH8?3K5wvPuY^J@ByJ>fK*y9+_R`G!p&x(mrx_J zdDLGZvjrd0SqXv8Mp)4V7uMk;(kd3Np@Hnc43U*A3UMbz$#j#_TV#s!0L|V-B~J5aC-Ye1%cT;hV>p;m}v=j<0c- z1^bTK+03;cbh(6kN{G39CEUlDz?h?-noSM64jSSmjE~J>!gZ*K$qu3-rVU95SZ7ht zr6P`-6A|z+o!eo#1`ZGPDI+N33|k}_5fTe$m^oC?95{W9F-ZpfABze_m=ds|Jl+vh zQD`es8;z}Q5WZ;kaK9v!J9LM Qrm|qo;XRtb0!k&|KlWz?AOHXW 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() )