Cryptography Reference
In-Depth Information
4.2.2.7 KeyExpansion in Maple
Next we implement KeyExpansion in Maple. We start by defining the round con-
stants Rcon whichwe shall give as a list of 4-byte lists. Herewe use themultiplication
in
F 2 8 , mult256 , which was defined in Sect. 2.8.4 .
> RconGen := proc()
local i, l;
l := [[1, 0, 0, 0]];
forito13do
l := [op(l), map(x -> mult256(2, x), l[-1])]
end do;
l
end proc:
The list of round constants, Rcon , is then:
> Rcon := RconGen();
[[1, 0, 0, 0], [2, 0, 0, 0], [4, 0, 0, 0], [8, 0, 0, 0], [16, 0, 0, 0],
[32, 0, 0, 0], [64, 0, 0, 0], [128, 0, 0, 0], [27, 0, 0, 0], [54, 0, 0, 0],
[108, 0, 0, 0], [216, 0, 0, 0], [171, 0, 0, 0], [77, 0, 0, 0]]
We will make use of the following function which takes as input an AES key given
either as a list of integers in the 0
255 range or as a hex string and checks whether
the supplied key is valid. In that case the function produces as output the list of bytes
corresponding to this key and otherwise returns an error message.
..
> checkkey := proc(key::{string, list(integer[0 .. 255])})
uses StringTools;
if type(key, list) then
if not member(nops(key), [16, 24, 32]) then
error "The supplied key does not have valid length"
end if;
return key
else
if not member(Length(key), [32, 48, 64]) then
error "The supplied key does not have valid length"
end if;
if not IsHexDigit(key) then
error "The supplied key is not a hex string"
end if;
return hexstringtobytes(LowerCase(key))
end if
end proc:
Let us now give the Maple function implementing KeyExpansion ,forwhich
we shall use this same name. The function takes as input an AES key, given as a list
or a hexadecimal string of 16, 24 or 32bytes. The output is a list of 0
3 arrays
(of Maple type Array ) whose entries are bytes; each one of these arrays is a round
subkey. The first 4, 6 or 8 columns of the first two arrays contain the key, which has
been mapped to the arrays columnwise, starting at the top of the leftmost column.
The functions RotWord and SubWord mentioned in Algorithm 4.2 are not defined
here because the first is simply a version of Rotate from the ListTools package
and the second consists of applying SubBytes to a 4-byte word, which is done here
by means of the previously defined function SB .
..
3-0
..
 
Search WWH ::




Custom Search