From adc02291fa658ed47658312ddce8acbaffd2af79 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Mon, 16 Nov 2020 20:02:53 -0500 Subject: lib: add MkState --- lib/aes.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib') 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 { -- cgit v1.2.3