From 6587c0460850aa162d444a9e7257350e671449e8 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sun, 12 Nov 2023 20:18:03 +0100 Subject: [PATCH] Implement `mixColumns` function --- aes/aes.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/aes/aes.cpp b/aes/aes.cpp index 942f55b..95418b9 100644 --- a/aes/aes.cpp +++ b/aes/aes.cpp @@ -116,12 +116,22 @@ uint8_t xtime(uint8_t a) { // not mandatory - mix a single column uint32_t mixColumn(uint32_t c) { - return 0; /* ??? */ + uint32_t result = c; + uint8_t *source = (uint8_t*)(&c); + uint8_t *target = (uint8_t*)(&result); + uint8_t base = *source ^ *(source + 1) ^ *(source + 2) ^ *(source + 3); + *target ^= base ^ xtime(*source ^ *(source + 1)); + *(target + 1) ^= base ^ xtime(*(source + 1) ^ *(source + 2)); + *(target + 2) ^= base ^ xtime(*(source + 2) ^ *(source + 3)); + *(target + 3) ^= base ^ xtime(*(source + 3) ^ *source); + return result; } void mixColumns(t_state s) { - /* ??? */ + for (uint8_t i = 0; i < 4; i++) { + s[i] = mixColumn(s[i]); + } } /*