summaryrefslogtreecommitdiffstats
path: root/lib/aes.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-11-22 12:09:33 -0500
committerrsiddharth <s@ricketyspace.net>2020-11-22 12:09:33 -0500
commit32da174d1e7da3366ff8165c20cf7d063e5c40b0 (patch)
treeb4a90290821c37a5b18328d4b9f4b4d3122a042f /lib/aes.go
parent0fb8e1716dca936bc905bb9042f316e294cf0227 (diff)
lib: aes: add AESInvCipher
Diffstat (limited to 'lib/aes.go')
-rw-r--r--lib/aes.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/aes.go b/lib/aes.go
index 476b366..ebad334 100644
--- a/lib/aes.go
+++ b/lib/aes.go
@@ -3,6 +3,40 @@
package lib
+func AESInvCipher(in, ky []byte) []byte {
+ nb := 4
+ nr := 10
+
+ // Generate key schedule from key.
+ ks := KeyExpansion(ky)
+
+ // Make state from input and do first round key
+ // transformation.
+ state := MkState(in)
+ state = AddRoundKey(state, ks[(nr*nb):((nr+1)*nb)])
+
+ for round := nr - 1; round >= 1; round-- {
+ state = InvShiftRows(state)
+ state = InvSubBytes(state)
+ state = AddRoundKey(state, ks[(round*nb):((round+1)*nb)])
+ state = InvMixColumns(state)
+ }
+ state = InvShiftRows(state)
+ state = InvSubBytes(state)
+ state = AddRoundKey(state, ks[0: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 InvMixColumns(state [][]byte) [][]byte {
// Initialize new state.