Xor directly from argon matrix without intermediary array

This commit is contained in:
Ugljesa Jovanovic 2020-05-21 23:34:22 +02:00 committed by Ugljesa Jovanovic
parent 7e78bf6fa5
commit 76a2a3edf7
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
3 changed files with 12 additions and 8 deletions

View File

@ -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.compressionFunctionG
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.validateArgonParameters
import com.ionspin.kotlin.crypto.util.fromLittleEndianArrayToUInt
import com.ionspin.kotlin.crypto.util.hexColumsPrint
import com.ionspin.kotlin.crypto.util.toLittleEndianUByteArray
import com.ionspin.kotlin.crypto.util.xor
import com.ionspin.kotlin.crypto.util.*
/**
* Created by Ugljesa Jovanovic
@ -330,10 +327,8 @@ class Argon2(
//Temporary fold
val acc = matrix.getBlockAt(0, columnCount - 1).copyOf()
for (i in 1 until parallelism) {
acc.hexColumsPrint(1024)
(acc xor matrix.getBlockAt(i, columnCount -1)).copyInto(acc)
(acc.xorWithBlock(matrix, i, columnCount - 1).copyInto(acc))
}
acc.hexColumsPrint(1024)
//Hash the xored last blocks
val hash = argonBlake2bArbitraryLenghtHash(acc, tagLength)
matrix.clearMatrix()

View File

@ -19,6 +19,7 @@
package com.ionspin.kotlin.crypto.keyderivation.argon2
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.fromLittleEndianArrayToULong
import com.ionspin.kotlin.crypto.util.plus
@ -32,6 +33,7 @@ import com.ionspin.kotlin.crypto.util.xor
* on 16-May-2020
*/
object Argon2Utils {
const val BLOCK_SIZE = 1024
const val R1 = 32
const val R2 = 24
@ -186,3 +188,10 @@ 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] }
}