Implement AES algorithm

This commit is contained in:
Manuel Thalmann 2023-11-14 11:06:11 +01:00
parent afe36cebe6
commit 4720e95cf2

View file

@ -161,9 +161,9 @@ void expandKey(uint8_t k[16], uint32_t ek[44]) {
/* Adding expanded round key (prepared before) */ /* Adding expanded round key (prepared before) */
void addRoundKey(t_state s, uint32_t ek[], short round) { void addRoundKey(t_state s, uint32_t ek[], short round) {
s[0] ^= ek[round]; s[0] ^= ek[round];
s[1] ^= ek[round + 1]; s[1] ^= ek[round + 1];
s[2] ^= ek[round + 2]; s[2] ^= ek[round + 2];
s[3] ^= ek[round + 3]; s[3] ^= ek[round + 3];
} }
void aes(uint8_t *in, uint8_t *out, uint8_t *skey) void aes(uint8_t *in, uint8_t *out, uint8_t *skey)
@ -191,10 +191,25 @@ void aes(uint8_t *in, uint8_t *out, uint8_t *skey)
addRoundKey(state, expKey, 0); addRoundKey(state, expKey, 0);
printf("ARK: "); printstate(state); printf("ARK: "); printstate(state);
/* ??? */ for (int i = 1; i <= 10; i++) {
/* ??? */ subBytes(state);
/* ??? */ printf("SB: ");
printstate(state);
shiftRows(state);
printf("SR: ");
printstate(state);
if (i < 10) {
mixColumns(state);
printf("MC: ");
printstate(state);
}
addRoundKey(state, expKey, 4*i);
printf("ARK: ");
printstate(state);
}
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
if (i < 4) out[i] = wbyte(state[0], i % 4); if (i < 4) out[i] = wbyte(state[0], i % 4);