Add shiftRows

This commit is contained in:
Ugljesa Jovanovic 2019-09-10 20:48:57 +02:00
parent 241df8d4a5
commit c86f60135a
No known key found for this signature in database
GPG Key ID: 33A5F353387711A5
2 changed files with 32 additions and 0 deletions

View File

@ -60,6 +60,13 @@ class Aes {
} }
} }
fun shiftRows() {
stateMatrix[0] = arrayOf(stateMatrix[0][0], stateMatrix[0][1], stateMatrix[0][2], stateMatrix[0][3])
stateMatrix[1] = arrayOf(stateMatrix[1][1], stateMatrix[1][2], stateMatrix[1][3], stateMatrix[1][0])
stateMatrix[2] = arrayOf(stateMatrix[2][2], stateMatrix[2][3], stateMatrix[2][0], stateMatrix[2][1])
stateMatrix[3] = arrayOf(stateMatrix[3][3], stateMatrix[3][0], stateMatrix[3][1], stateMatrix[3][2])
}
fun expandKey(key: AesKey) { fun expandKey(key: AesKey) {
} }

View File

@ -27,4 +27,29 @@ class AesTest {
aes.stateMatrix[0][0] == 0xEDU.toUByte() aes.stateMatrix[0][0] == 0xEDU.toUByte()
} }
} }
@Test
fun testShiftRows() {
val fakeState = arrayOf(
ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray(),
ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray(),
ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray(),
ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray()
)
val expectedState = arrayOf(
ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray(),
ubyteArrayOf(1U, 2U, 3U, 0U).toTypedArray(),
ubyteArrayOf(2U, 3U, 0U, 1U).toTypedArray(),
ubyteArrayOf(3U, 0U, 1U, 2U).toTypedArray()
)
val aes = Aes()
fakeState.copyInto(aes.stateMatrix)
aes.shiftRows()
aes.stateMatrix.forEach{
println(it.joinToString { it.toString(16) })
}
assertTrue {
aes.stateMatrix.contentDeepEquals(expectedState)
}
}
} }