Implement mixColumns
function
This commit is contained in:
parent
ffe2b8ef9a
commit
6587c04608
1 changed files with 12 additions and 2 deletions
14
aes/aes.cpp
14
aes/aes.cpp
|
@ -116,12 +116,22 @@ uint8_t xtime(uint8_t a) {
|
||||||
|
|
||||||
// not mandatory - mix a single column
|
// not mandatory - mix a single column
|
||||||
uint32_t mixColumn(uint32_t c) {
|
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) {
|
void mixColumns(t_state s) {
|
||||||
/* ??? */
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
|
s[i] = mixColumn(s[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue