Implement AES algorithm
This commit is contained in:
parent
afe36cebe6
commit
4720e95cf2
1 changed files with 21 additions and 6 deletions
27
aes/aes.cpp
27
aes/aes.cpp
|
@ -161,9 +161,9 @@ void expandKey(uint8_t k[16], uint32_t ek[44]) {
|
|||
/* Adding expanded round key (prepared before) */
|
||||
void addRoundKey(t_state s, uint32_t ek[], short round) {
|
||||
s[0] ^= ek[round];
|
||||
s[1] ^= ek[round + 1];
|
||||
s[2] ^= ek[round + 2];
|
||||
s[3] ^= ek[round + 3];
|
||||
s[1] ^= ek[round + 1];
|
||||
s[2] ^= ek[round + 2];
|
||||
s[3] ^= ek[round + 3];
|
||||
}
|
||||
|
||||
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);
|
||||
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++) {
|
||||
if (i < 4) out[i] = wbyte(state[0], i % 4);
|
||||
|
|
Loading…
Reference in a new issue