Working for all segments 2d variant

This commit is contained in:
Ugljesa Jovanovic 2020-05-15 23:50:18 +02:00 committed by Ugljesa Jovanovic
parent d92db320c3
commit 1904e2b9f2
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F

View File

@ -98,12 +98,12 @@ class Argon2 internal constructor(
fun compressionFunctionG( fun compressionFunctionG(
x: Array<UByte>, previousBlock: Array<UByte>,
y: Array<UByte>, referenceBlock: Array<UByte>,
currentBlock: Array<UByte>, currentBlock: Array<UByte>,
xorWithCurrentBlock: Boolean xorWithCurrentBlock: Boolean
): Array<UByte> { ): Array<UByte> {
val r = x xor y val r = referenceBlock xor previousBlock
// println("R = X xor Y") // println("R = X xor Y")
// r.hexColumsPrint(16) // r.hexColumsPrint(16)
// val r = Array<UByte>(1024) { 0U } // view as 8x8 matrix of 16 byte registers // val r = Array<UByte>(1024) { 0U } // view as 8x8 matrix of 16 byte registers
@ -138,7 +138,7 @@ class Argon2 internal constructor(
// z.hexColumsPrint(16) // z.hexColumsPrint(16)
val final = if (xorWithCurrentBlock) { val final = if (xorWithCurrentBlock) {
// println("Z xor R xor CURRENT") // println("Z xor R xor CURRENT")
(z xor r) xor ((x xor y) xor currentBlock) (z xor r) xor currentBlock
} else { } else {
// println("Z xor R") // println("Z xor R")
z xor r z xor r
@ -329,10 +329,11 @@ class Argon2 internal constructor(
// blocks in the last SL - 1 = 3 segments computed and finished in // blocks in the last SL - 1 = 3 segments computed and finished in
// lane l. If B[i][j] is the first block of a segment, then the // lane l. If B[i][j] is the first block of a segment, then the
// very last index from W is excluded. // very last index from W is excluded.
val segmentIndex = column - (slice * (columnCount / 4))
val referenceAreaSize = if (iteration == 0) { val referenceAreaSize = if (iteration == 0) {
if (slice == 0) { if (slice == 0) {
//All indices except the previous //All indices except the previous
column - 1 (column % (columnCount / 4)) - 1
} else { } else {
if (lane == l) { if (lane == l) {
//Same lane //Same lane
@ -347,9 +348,9 @@ class Argon2 internal constructor(
} }
} else { } else {
if (lane == l) { if (lane == l) {
columnCount - (columnCount / 4) + column - 1 columnCount - (columnCount / 4) + (column % (columnCount / 4) - 1)
} else { } else {
columnCount - (columnCount / 4) + if (column == 0) { columnCount - (columnCount / 4) + if (column % (columnCount / 4) == 0) {
-1 -1
} else { } else {
0 0
@ -575,16 +576,27 @@ class Argon2 internal constructor(
} }
} }
} else { } else {
val (l, z) = computeIndexNew(matrix, lane, 0, columnCount, parallelism.toInt(), iteration, slice, type) if (slice == 0) {
matrix[lane][0] = compressionFunctionG(matrix[lane][columnCount - 1], matrix[l][z], matrix[lane][0], true) val (l, z) = computeIndexNew(matrix, lane, 0, columnCount, parallelism.toInt(), iteration, slice, type)
for (column in 1..(slice * segmentLength)) { matrix[lane][0] = compressionFunctionG(matrix[lane][columnCount - 1], matrix[l][z], matrix[lane][0], true)
val (l, z) = computeIndexNew(matrix, lane, column, columnCount, parallelism.toInt(), iteration, slice, type) for (column in 1 until segmentLength) {
println("Calling compress for I: $iteration S: $slice Lane: $lane Column: $column with l: $l z: $z") val (l, z) = computeIndexNew(matrix, lane, column, columnCount, parallelism.toInt(), iteration, slice, type)
matrix[lane][column] = println("Calling compress for I: $iteration S: $slice Lane: $lane Column: $column with l: $l z: $z")
compressionFunctionG(matrix[lane][column - 1], matrix[l][z], matrix[lane][column], true) matrix[lane][column] =
compressionFunctionG(matrix[lane][column - 1], matrix[l][z], matrix[lane][column], true)
// matrix[lane][column].hexColumsPrint(16) // matrix[lane][column].hexColumsPrint(16)
}
} else {
for (column in slice * segmentLength until (slice + 1) * segmentLength) {
val (l, z) = computeIndexNew(matrix, lane, column, columnCount, parallelism.toInt(), iteration, slice, type)
println("Calling compress for I: $iteration S: $slice Lane: $lane Column: $column with l: $l z: $z")
matrix[lane][column] =
compressionFunctionG(matrix[lane][column - 1], matrix[l][z], matrix[lane][column], true)
// matrix[lane][column].hexColumsPrint(16)
}
} }
} }