summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-11-17 21:17:36 -0500
committerrsiddharth <s@ricketyspace.net>2020-11-17 21:17:36 -0500
commit7a9bf1d6e76adbf3ec0d85050c018d75b3879431 (patch)
tree28c0835ac1807b3ce8cd5a5e6215652a53ec3a26
parent0116d2c5a5e15d7a9e35eadb7ecc7f3fad55201b (diff)
lib: aes: add AddRoundKey
-rw-r--r--lib/aes.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/aes.go b/lib/aes.go
index a4c8ec2..389dc44 100644
--- a/lib/aes.go
+++ b/lib/aes.go
@@ -3,6 +3,30 @@
package lib
+func AddRoundKey(state, ks [][]byte) [][]byte {
+ if len(ks) != 4 {
+ return state
+ }
+ nb := 4
+
+ // Get tranpose of ks.
+ ks_t := make([][]byte, 4)
+ for i := 0; i < 4; i++ {
+ ks_t[i] = make([]byte, 4)
+ for j := 0; j < 4; j++ {
+ ks_t[i][j] = ks[j][i]
+ }
+ }
+
+ // Round key transformation.
+ for c := 0; c < nb; c++ {
+ for r := 0; r < 4; r++ {
+ state[r][c] = state[r][c] ^ ks_t[r][c]
+ }
+ }
+ return state
+}
+
// Makes and returns initial the state array from 16-byte input 'in'.
func MkState(in []byte) [][]byte {
if len(in) != 16 {