diff options
author | rsiddharth <s@ricketyspace.net> | 2020-12-06 14:48:55 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-12-06 14:48:55 -0500 |
commit | c0e9feb0e9d78d02c4fb71569db26f31e801d6e3 (patch) | |
tree | f242873695ef8bf8fe1b673d6e835b9b20d164c6 /lib | |
parent | cdfb7d117266b541f09ee731fe4ba075faf285bd (diff) |
lib/aes: add aesCipher
Diffstat (limited to 'lib')
-rw-r--r-- | lib/aes.go | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -32,6 +32,42 @@ func AESDecryptECB(cipher, key []byte) []byte { return output } + +func aesCipher(in, ky []byte) []byte { + nb := 4 + nr := 10 + + // Generate key schedule from key. + ks := aesKeyExpansion(ky) + + // Make state from input and do first round key + // transformation. + state := aesMkState(in) + state = aesAddRoundKey(state, ks[0:4]) + + for round := 1; round <= nr-1; round++ { + state = aesSubBytes(state) + state = aesShiftRows(state) + state = aesMixColumns(state) + state = aesAddRoundKey(state, ks[(round*nb):((round+1)*nb)]) + } + state = aesSubBytes(state) + state = aesShiftRows(state) + state = aesAddRoundKey(state, ks[(nr*nb):((nr+1)*nb)]) + + // Make output. + output := make([]byte, 4*nb) + i := 0 + for c := 0; c < nb; c++ { + for r := 0; r < 4; r++ { + output[i] = state[r][c] + i++ + } + } + + return output +} + func aesInvCipher(in, ky []byte) []byte { nb := 4 nr := 10 |