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) {