diff options
author | rsiddharth <s@ricketyspace.net> | 2020-12-06 14:48:06 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-12-06 14:48:06 -0500 |
commit | cdfb7d117266b541f09ee731fe4ba075faf285bd (patch) | |
tree | ed57ded344bfdb0d2d34bed7f8fd0650311d450b | |
parent | 89238b1ebae839fb6d22d70dbe32dcdf205db158 (diff) |
lib/aes: add aesMixColumns
-rw-r--r-- | lib/aes.go | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -66,6 +66,25 @@ func aesInvCipher(in, ky []byte) []byte { return output } +func aesMixColumns(state [][]byte) [][]byte { + + // Initialize new state. + n_state := make([][]byte, 4) + nb := 4 + for r := 0; r < 4; r++ { + n_state[r] = make([]byte, nb) + } + + // Mix columns transformation. + for c := 0; c < nb; c++ { + n_state[0][c] = GFMultiply(0x02, state[0][c]) ^ GFMultiply(0x03, state[1][c]) ^ state[2][c] ^ state[3][c] + n_state[1][c] = state[0][c] ^ GFMultiply(0x02, state[1][c]) ^ GFMultiply(0x03, state[2][c]) ^ state[3][c] + n_state[2][c] = state[0][c] ^ state[1][c] ^ GFMultiply(0x02, state[2][c]) ^ GFMultiply(0x03, state[3][c]) + n_state[3][c] = GFMultiply(0x03, state[0][c]) ^ state[1][c] ^ state[2][c] ^ GFMultiply(0x02, state[3][c]) + } + return n_state +} + func aesInvMixColumns(state [][]byte) [][]byte { // Initialize new state. |