From 4720e95cf253151e31c1a6ab3adde31649ed2c2a Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Tue, 14 Nov 2023 11:06:11 +0100
Subject: [PATCH] Implement AES algorithm

---
 aes/aes.cpp | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/aes/aes.cpp b/aes/aes.cpp
index 10f8de7..d41127a 100644
--- a/aes/aes.cpp
+++ b/aes/aes.cpp
@@ -161,9 +161,9 @@ void expandKey(uint8_t k[16], uint32_t ek[44]) {
 /* Adding expanded round key (prepared before) */
 void addRoundKey(t_state s, uint32_t ek[], short round) {
     s[0] ^= ek[round];
-	s[1] ^= ek[round + 1];
-	s[2] ^= ek[round + 2];
-	s[3] ^= ek[round + 3];
+    s[1] ^= ek[round + 1];
+    s[2] ^= ek[round + 2];
+    s[3] ^= ek[round + 3];
 }
 
 void aes(uint8_t *in, uint8_t *out, uint8_t *skey)
@@ -191,10 +191,25 @@ void aes(uint8_t *in, uint8_t *out, uint8_t *skey)
     addRoundKey(state, expKey, 0);
     printf("ARK: "); printstate(state);
 
-    /* ??? */
-    /* ??? */
-    /* ??? */
+    for (int i = 1; i <= 10; i++) {
+        subBytes(state);
+        printf("SB:  ");
+        printstate(state);
 
+        shiftRows(state);
+        printf("SR:  ");
+        printstate(state);
+
+        if (i < 10) {
+            mixColumns(state);
+            printf("MC:  ");
+            printstate(state);
+        }
+
+        addRoundKey(state, expKey, 4*i);
+        printf("ARK: ");
+        printstate(state);
+    }
 
     for (int i = 0; i < 16; i++) {
         if (i < 4) out[i] = wbyte(state[0], i % 4);