Implement expandKey
This commit is contained in:
parent
6587c04608
commit
79d2776d41
18
aes/aes.cpp
18
aes/aes.cpp
|
@ -139,8 +139,24 @@ void mixColumns(t_state s) {
|
|||
* to 11 round keys (11*4*32b)
|
||||
* each round key is 4*32b
|
||||
*/
|
||||
// Taken from: https://www.brainkart.com/article/AES-Key-Expansion_8410/
|
||||
void expandKey(uint8_t k[16], uint32_t ek[44]) {
|
||||
/* ??? */
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
for (uint8_t j = 0; j < 4; j++) {
|
||||
*(((uint8_t*)(&(ek[i]))) + j) = k[i * 4 + j];
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 4; i < 44; i++) {
|
||||
uint32_t key = ek[i - 1];
|
||||
|
||||
if (i % 4 == 0) {
|
||||
key = (key >> 8) | (key << 24);
|
||||
key = subWord(key) ^ rCon[i / 4];
|
||||
}
|
||||
|
||||
ek[i] = ek[i - 4] ^ key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue