예제 #1
0
파일: bes.go 프로젝트: OpenWhiteBox/AES
// subBytes rewrites each byte of the state with the S-Box. unSubBytes and subBytes are the same.
func (constr *Construction) subBytes(in gfmatrix.Row) gfmatrix.Row {
	out := gfmatrix.NewRow(in.Size())

	for pos := 0; pos < in.Size(); pos++ {
		out[pos] = in[pos].Invert()
	}

	return out
}
예제 #2
0
파일: bes.go 프로젝트: OpenWhiteBox/AES
func (constr *Construction) decrypt(in gfmatrix.Row) gfmatrix.Row {
	roundKeys := constr.StretchedKey()

	state := in.Add(roundConst).Add(roundKeys[10])
	state = firstRound.Mul(state)
	state = constr.subBytes(state)

	for i := 9; i >= 1; i-- {
		state = state.Add(roundConst).Add(roundKeys[i])
		state = unRound.Mul(state)
		state = constr.subBytes(state)
	}

	state = state.Add(roundKeys[0])

	return state
}
예제 #3
0
파일: bes.go 프로젝트: OpenWhiteBox/AES
func (constr *Construction) encrypt(in gfmatrix.Row) gfmatrix.Row {
	roundKeys := constr.StretchedKey()

	state := in.Add(roundKeys[0])

	for i := 1; i <= 9; i++ {
		state = constr.subBytes(state)
		state = round.Mul(state)
		state = state.Add(roundConst).Add(roundKeys[i])
	}

	state = constr.subBytes(state)
	state = lastRound.Mul(state)
	state = state.Add(roundConst).Add(roundKeys[10])

	return state
}