diff options
| author | rsiddharth <s@ricketyspace.net> | 2020-11-22 12:09:33 -0500 | 
|---|---|---|
| committer | rsiddharth <s@ricketyspace.net> | 2020-11-22 12:09:33 -0500 | 
| commit | 32da174d1e7da3366ff8165c20cf7d063e5c40b0 (patch) | |
| tree | b4a90290821c37a5b18328d4b9f4b4d3122a042f | |
| parent | 0fb8e1716dca936bc905bb9042f316e294cf0227 (diff) | |
lib: aes: add AESInvCipher
| -rw-r--r-- | lib/aes.go | 34 | 
1 files changed, 34 insertions, 0 deletions
@@ -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.  | 
