summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-11-16 20:02:53 -0500
committerrsiddharth <s@ricketyspace.net>2020-11-16 20:02:53 -0500
commitadc02291fa658ed47658312ddce8acbaffd2af79 (patch)
tree2ca4da0e4e28ab74056e75417ea19bc71366e2ba
parentd6c2957137c7292845c095cb798826fabd19e527 (diff)
lib: add MkState
-rw-r--r--lib/aes.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/aes.go b/lib/aes.go
index ea4a449..cfc06ff 100644
--- a/lib/aes.go
+++ b/lib/aes.go
@@ -3,6 +3,23 @@
package lib
+// Make and return initial state array from 16-byte input 'in'
+func MkState(in []byte) [][]byte {
+ if len(in) != 16 {
+ return [][]byte{}
+ }
+ nb := 4
+ state := make([][]byte, 4)
+
+ for r := 0; r < 4; r++ {
+ state[r] = make([]byte, nb)
+ for c := 0; c < nb; c++ {
+ state[r][c] = in[r+(4*c)]
+ }
+ }
+ return state
+}
+
// Returns a key schedule (176 bytes, 44 4-byte words) given a key 'k'
// (16 bytes, 4 4-byte words).
func KeyExpansion(k []byte) [][]byte {