Implement mixColumns function

This commit is contained in:
Manuel Thalmann 2023-11-12 20:18:03 +01:00
parent ffe2b8ef9a
commit 6587c04608

View file

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