Cryptography Reference
In-Depth Information
4.4.1.2 ShiftRows and its Inverse
The ShiftRows operation consists of shifting the rows of the state array by 0, 1,
2, 3 positions to the left, i.e., each row is shifted by the amount given by its index.
The inverse operation just shifts rows right by the same offsets. These operations are
not implemented "in place" as we need to use a copy of the state array inside the
corresponding function.
> ShiftRows := proc(state)
local st, i, j;
st := Array(state);
for i to 3 do
for j from 0 to 3 do
st[i, j] := state[i, (i+j mod 4)]
end do
end do;
st
end proc:
> InvShiftRows := proc(state)
local st, i, j;
st := Array(state);
for i to 3 do
for j from 0 to 3 do
st[i, j] := state[i, (j-i mod 4)]
end do
end do;
st
end proc:
4.4.1.3 MixColumns and its Inverse
The MixColumns operation makes heavy use of multiplication in
F 2 8 and hence,
for efficiency, it is convenient to implement this multiplication by means of a lookup
table. Here we use the function mult256 that was defined in Sect. 2.8.4 :
> multtable := Array(0 .. 255, 0 .. 255, (i, j) -> mult256(i,j)):
The next function implements the MixColumns operation. The input is the
state array and the output the modified version of the state obtained by carrying out
the matrix multiplication M ยท state , where M is the matrix with coefficients in
F 2 8
given by M = Matrix([seq(ListTools:-Rotate([2,3,1,1],-i),
i=0..3)]) .
For efficiency, we implement this matrix multiplication directly by using the func-
tion multtable and the addition table of
F 2 8 , bitXortable (given in Sect. 2.8 ) :
> MixColumns := proc(state)
local st, i;
st := Array(0..3, 0..3);
for i from 0 to 3 do
st[0,i]:=bitXortable[multtable[state[0,i],2], bitXortable[multtable[state[1,i],3],
bitXortable[state[2,i], state[3,i]]]]
end do;
for i from 0 to 3 do
st[1,i]:=bitXortable[state[0,i], bitXortable[multtable[state[1,i],2],
bitXortable[multtable[state[2, i], 3], state[3, i]]]]
Search WWH ::




Custom Search