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]); + } } /*