diff options
| author | rsiddharth <s@ricketyspace.net> | 2020-11-17 21:17:36 -0500 | 
|---|---|---|
| committer | rsiddharth <s@ricketyspace.net> | 2020-11-17 21:17:36 -0500 | 
| commit | 7a9bf1d6e76adbf3ec0d85050c018d75b3879431 (patch) | |
| tree | 28c0835ac1807b3ce8cd5a5e6215652a53ec3a26 /lib | |
| parent | 0116d2c5a5e15d7a9e35eadb7ecc7f3fad55201b (diff) | |
lib: aes: add AddRoundKey
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/aes.go | 24 | 
1 files changed, 24 insertions, 0 deletions
@@ -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 {  | 
