Beispiel #1
0
// 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
}
Beispiel #2
0
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
}
Beispiel #3
0
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
}