Cryptography Reference
In-Depth Information
Exercise 4.11 Implement the GFSbox and KeySbox tests of [12] and compare the
results obtained to the known answers given there.
4.5 Some Modes of Operation in Maple
Here we give Maple implementations of two of the modes discussed in the previous
section: OFB and CTR. Other modes can be similarly implemented but we will leave
this task as an exercise.
4.5.1 OFB and CTR in Maple
OFB and CTRmodes are similar in that encryption proceeds by Xor-ing the plaintext
blocks with the blocks of a key stream and hence we will use a unique function to
implement both.
4.5.1.1 A Couple of Preliminary Functions
In addition to the previous functions checkkey , KeyExpansion and
AESEncrypt , which were used in the AES implementation, we will need another
couple of functions that we shall define before giving the modes function. The first
is just a variant—which is more convenient for our purposes—of the BitXor oper-
ation given in Sect. 2.8 . This variant, called BitXorAL calls the previous function
bitXortable to compute the bitwise Xor of a 0..3, 0..3 array a with a list l of no
more than 16 terms, where the array is passed as the first argument and the list as the
second. If t is the length of l , then the output is the list of length t obtained byXor-ing
the elements of l with the first t elements of a with respect to Fortran_order (in
which the entries of the array are accessed in 'column-major' order, i.e., columnwise,
see Maple's help for details). Maple's built-in function ArrayTools:-Alias is
used here to view the 2-dimensional Array as a 1-dimensional Array with this order:
> BitXorAL := proc(a::Array, l::list)
local li, i, v;
li := l;
v := ArrayTools:-Alias(a, [16]);
for i to nops(l) do
li[i] := bitXortable[v[i], l[i]]
end do;
li
end proc:
To implement CTR mode we need a function to generate the counters which,
in turn, requires two ingredients. One of them is an algorithm to choose the initial
counter block corresponding to each encryption; this initial counter will be the IV and
we will later give functions to generate it. The other ingredient is a method to generate
the subsequent counters in such a way that their values are never repeated across
 
Search WWH ::




Custom Search