Cryptography Reference
In-Depth Information
tag length. The output is either
VALID
if the tag corresponds to the message under
the given key or
INVALID
otherwise.
> GMACVer := proc(key::{list, string}, iv::string, message::string, tag::string,
messagetype::name := file)
local k, t;
uses StringTools;
k := checkkey(key);
if not (IsHexDigit(iv) and Length(iv) = 24) then
error "Incorrectly formatted IV"
end if;
if not (IsHexDigit(tag) and member(Length(tag), [seq(2*i, i = 12 .. 16)])) then
error "Incorrectly formatted tag"
end if;
t := iquo(Length(tag), 2);
if evalb(GMAC(k,LowerCase(iv),message,messagetype,':-t'=t) = LowerCase(tag)) then
VALID
else
INVALID
end if
end proc:
Examples 5.1
1. Test Case 1 in [138]. We compute the tag corresponding to the empty string with
the 0 string as IV and key, and then we verify the authenticity of the message:
> t0 := GMAC("00000000000000000000000000000000","000000000000000000000000","",hex);
"58e2fccefa7e3061367f1d57a4e7455a"
> GMACVer("00000000000000000000000000000000","000000000000000000000000","",t0,hex);
VALID
2. We generate a test file in the current directory, named
“cmacfile”
as follows:
> cmactxt := "This is the content of a file used to test GMAC":
bytestofile(convert(cmactxt, bytes), "cmacfile", false);
47 bytes saved to cmacfile
We compute the GMAC tag (with
"000102030405060708090a0b0
c0d0e0f"
as key and 0 as IV) for this file and then we verify that the tag is
valid, which means that the file has not been modified in between:
> t1:=GMAC("000102030405060708090a0b0c0d0e0f","000000000000000000000000","cmacfile");
"46daef78cd2295c531bf8b8a8271442b"
> GMACVer("000102030405060708090a0b0c0d0e0f","000000000000000000000000","cmacfile",
t1);
VALID
3. Finally, we compute the GMAC tag corresponding to the text string used to define
the file
cmacfile
and we observe that, as expected, the tag is the same as the
one for the file:
> GMAC("000102030405060708090a0b0c0d0e0f","000000000000000000000000",cmactxt,text);
"46daef78cd2295c531bf8b8a8271442b"
Exercise 5.11
Write aMaple program that makes a time comparison between
CMAC
and
GMAC
when applied to a file. Use it to compare the time taken by the two
algorithms on a 1MB file (
GMAC
should be about 4.5 times faster than
CMAC
).