Cryptography Reference
In-Depth Information
bytes (for hex messages) of the pseudo-randomly generated messages tested. The
parameter
format
specifies either
text
or
hex
messages and
verbose
whether
tested messages are to be printed. The test ends either by informing that it was
successful or printing the message for which it failed.
> PSSTest := proc(key::list, iterations::posint, maxlength::posint := 100,
{format::identical(text,hex) := hex, verbose::truefalse :=false})
local pk, sk, gen, valid, i, r, m;
pk := key[1];
sk := key[2];
if format = hex then
gen := 'xdigit'
else
gen := NULL
end if;
valid := true;
for i to iterations while valid do
r := rand(0 .. maxlength)();
if gen = 'xdigit' then
r:=2*r
end if;
m := StringTools:-LowerCase(StringTools:-Random(r, gen));
if verbose then
printf("%s%s\n", "Message: ", m)
end if;
valid := evalb(PSSVer(pk, m, PSSSign(sk, m, ':-messagetype' = format),
':-messagetype' = format) = "valid signature");
if not valid then
printf("verification failure for message:\n");
return m
end if
end do;
if valid then
printf("%d iterations successfully completed\n", iterations)
end if
end proc:
Let us use the test function with key
rsakey
, 3 iterations,
verbose = true
and default values for the remaining parameters:
> PSSTest(rsakey, 3, verbose = true);
Message 1: fcddbeb2d836fbbd97a4a1a0c5bcbf67fe1e5eb6eaacf64f06f6a7e8aeba22
Message 2: eeddb18da6b67863e44bab09bfdad1a9a12c9dd1628ebd4a8631be67ecf1afdeacb7c\
f2bc57cc5
Message 3: bde5fdd4aecd5d83f0d01c1e92ffac3363a3036dced8be
3 iterations successfully completed
Example 9.6
Let us verify the signature generated in Example 9.4. It is done as
follows:
> PSSVer(sk, M, S, messagetype = 'text');
"valid signature"
Exercise 9.15
Modify
PSSSign
and
PSSVer
so that both functions accept mes-
sages given as binary files and signatures are also saved to files.