Xor directly from argon matrix without intermediary array
This commit is contained in:
parent
7e78bf6fa5
commit
76a2a3edf7
@ -25,10 +25,7 @@ import com.ionspin.kotlin.crypto.keyderivation.KeyDerivationFunction
|
|||||||
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.argonBlake2bArbitraryLenghtHash
|
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.compressionFunctionG
|
||||||
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.validateArgonParameters
|
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.validateArgonParameters
|
||||||
import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToUInt
|
import com.ionspin.kotlin.crypto.util.*
|
||||||
import com.ionspin.kotlin.crypto.util.hexColumsPrint
|
|
||||||
import com.ionspin.kotlin.crypto.util.toLittleEndianUByteArray
|
|
||||||
import com.ionspin.kotlin.crypto.util.xor
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ugljesa Jovanovic
|
* Created by Ugljesa Jovanovic
|
||||||
@ -330,10 +327,8 @@ class Argon2(
|
|||||||
//Temporary fold
|
//Temporary fold
|
||||||
val acc = matrix.getBlockAt(0, columnCount - 1).copyOf()
|
val acc = matrix.getBlockAt(0, columnCount - 1).copyOf()
|
||||||
for (i in 1 until parallelism) {
|
for (i in 1 until parallelism) {
|
||||||
acc.hexColumsPrint(1024)
|
(acc.xorWithBlock(matrix, i, columnCount - 1).copyInto(acc))
|
||||||
(acc xor matrix.getBlockAt(i, columnCount -1)).copyInto(acc)
|
|
||||||
}
|
}
|
||||||
acc.hexColumsPrint(1024)
|
|
||||||
//Hash the xored last blocks
|
//Hash the xored last blocks
|
||||||
val hash = argonBlake2bArbitraryLenghtHash(acc, tagLength)
|
val hash = argonBlake2bArbitraryLenghtHash(acc, tagLength)
|
||||||
matrix.clearMatrix()
|
matrix.clearMatrix()
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package com.ionspin.kotlin.crypto.keyderivation.argon2
|
package com.ionspin.kotlin.crypto.keyderivation.argon2
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2b
|
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2b
|
||||||
|
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.BLOCK_SIZE
|
||||||
import com.ionspin.kotlin.crypto.util.arrayChunked
|
import com.ionspin.kotlin.crypto.util.arrayChunked
|
||||||
import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToULong
|
import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToULong
|
||||||
import com.ionspin.kotlin.crypto.util.plus
|
import com.ionspin.kotlin.crypto.util.plus
|
||||||
@ -32,6 +33,7 @@ import com.ionspin.kotlin.crypto.util.xor
|
|||||||
* on 16-May-2020
|
* on 16-May-2020
|
||||||
*/
|
*/
|
||||||
object Argon2Utils {
|
object Argon2Utils {
|
||||||
|
const val BLOCK_SIZE = 1024
|
||||||
|
|
||||||
const val R1 = 32
|
const val R1 = 32
|
||||||
const val R2 = 24
|
const val R2 = 24
|
||||||
@ -185,4 +187,11 @@ object Argon2Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------ Arithmetic and other utils
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
|
fun UByteArray.xorWithBlock(other : Argon2Matrix, rowPosition: Int, columnPosition: Int) : UByteArray {
|
||||||
|
return UByteArray(BLOCK_SIZE) { this[it] xor other[rowPosition, columnPosition, it] }
|
||||||
}
|
}
|
@ -72,7 +72,7 @@ class Argon2MatrixTest {
|
|||||||
zeroesBlock.contentEquals(argon2Matrix.getBlockAt(0, 0)) &&
|
zeroesBlock.contentEquals(argon2Matrix.getBlockAt(0, 0)) &&
|
||||||
onesBlock.contentEquals(argon2Matrix.getBlockAt(0, 1)) &&
|
onesBlock.contentEquals(argon2Matrix.getBlockAt(0, 1)) &&
|
||||||
twosBlock.contentEquals(argon2Matrix.getBlockAt(1, 0)) &&
|
twosBlock.contentEquals(argon2Matrix.getBlockAt(1, 0)) &&
|
||||||
threesBlock.contentEquals(argon2Matrix.getBlockAt(1, 1))
|
threesBlock.contentEquals(argon2Matrix.getBlockAt(1, 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user