From 87f3102a451aabbb91d8342ece9a5f106cf57dd6 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 7 Nov 2023 19:25:49 +0100 Subject: [PATCH] Implement `shiftRows` --- aes/aes.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/aes/aes.cpp b/aes/aes.cpp index c5cde46..82ba954 100644 --- a/aes/aes.cpp +++ b/aes/aes.cpp @@ -85,7 +85,18 @@ void subBytes(t_state s) { void shiftRows(t_state s) { - /* ??? */ + for (uint8_t i = 0; i < 4; i++) { + uint32_t mask = 0xFF << (i * 8); + + for (uint8_t shiftCount = 0; shiftCount < i; shiftCount++) { + for (uint8_t currentByte = 0; currentByte < 3; currentByte++) { + // Swap s[currentByte] and s[currentByte + 1] + s[currentByte] = s[currentByte] ^ (mask & s[currentByte + 1]); + s[currentByte + 1] = s[currentByte + 1] ^ (mask & s[currentByte]); + s[currentByte] = s[currentByte] ^ (mask & s[currentByte + 1]); + } + } + } } uint8_t xtime(uint8_t a) {