summaryrefslogtreecommitdiffstats
path: root/lib/aes.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-12-06 14:48:55 -0500
committerrsiddharth <s@ricketyspace.net>2020-12-06 14:48:55 -0500
commitc0e9feb0e9d78d02c4fb71569db26f31e801d6e3 (patch)
treef242873695ef8bf8fe1b673d6e835b9b20d164c6 /lib/aes.go
parentcdfb7d117266b541f09ee731fe4ba075faf285bd (diff)
lib/aes: add aesCipher
Diffstat (limited to 'lib/aes.go')
-rw-r--r--lib/aes.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/aes.go b/lib/aes.go
index 4c0c86d..e9b97d3 100644
--- a/lib/aes.go
+++ b/lib/aes.go
@@ -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