ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Crypt-Spritz/t/01_spritz.t
Revision: 1.4
Committed: Sat Jan 10 07:10:46 2015 UTC (9 years, 5 months ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.3: +8 -7 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 BEGIN { $| = 1; print "1..82\n"; }
2
3 use Crypt::Spritz;
4
5 my $n = 0;
6
7 my $c1 = new Crypt::Spritz;
8
9 for (1..3) {
10 for (
11 [ABC => "779a8e01f9e9cbc0", "028fa2b48b934a18", "eb4765b22caa38ab", "a25b6e57fb35481b", "75ea088baadc803e"],
12 [spam => "f0609a1df143cebf", "acbba0813f300d3a", "433a025805dbb3b1", "e1eed00911069b9d", "782cf66ae9d1fdea"],
13 [arcfour => "1afa8b5ee337dbc7", "ff8cf268094c87b9", "c72e6cfc08b27d4a", "cac713dfba93cd79", "413397b795a75abf"],
14 ) {
15 my ($a, $r, $h, $m, $ec, $em) = @$_;
16
17 $c1->absorb ($a);
18 my $s = unpack "H*", $c1->squeeze (0.5 * length $r);
19 print $s eq $r ? "" : "not ", "ok ", ++$n, " # AS1 $a => $s (= $r)\n";
20
21 $c1->init;
22
23 my $c2 = new Crypt::Spritz;
24 $c2->absorb ($_) for split //, $a;
25 my $s = unpack "H*", join "", map $c2->squeeze (1), 1 .. 0.5 * length $r;
26 print $s eq $r ? "" : "not ", "ok ", ++$n, " # AS2 $a => $s (= $r)\n";
27
28 my $rng = new Crypt::Spritz::PRNG $a;
29 $rng = unpack "H*", $rng->get (0.5 * length $r);
30 print $rng eq $r ? "" : "not ", "ok ", ++$n, " # R $a => $rng (= $r)\n";
31
32 my $h1 = new Crypt::Spritz::Hash;
33 $h1->add ($a);
34 $h1 = unpack "H*", substr $h1->finish (32), 0, 0.5 * length $h;
35 print $h eq $h1 ? "" : "not ", "ok ", ++$n, " # H $a => $h1 (= $h)\n";
36
37 my $mac1 = new Crypt::Spritz::MAC $a;
38 $mac1->add ("schmorp");
39 $mac1 = unpack "H*", substr $mac1->finish (13), -8;
40 print $m eq $mac1 ? "" : "not ", "ok ", ++$n, " # M $a => $mac1 (= $m)\n";
41
42 my $cx1 = new Crypt::Spritz::Cipher::XOR $a;
43 $cx1 = unpack "H*", $cx1->crypt ("12345678") ^ "12345678";
44 print $r eq $cx1 ? "" : "not ", "ok ", ++$n, " # CX1 $a => $cx1 (= $r)\n";
45
46 my $cx2 = "98765432";
47 Crypt::Spritz::Cipher::XOR->new ($a)->crypt_inplace ($cx2);
48 $cx2 = unpack "H*", $cx2 ^ "98765432";
49 print $r eq $cx2 ? "" : "not ", "ok ", ++$n, " # CX2 $a => $cx2 (= $r)\n";
50
51 my $ae = new Crypt::Spritz::AEAD::XOR $a;
52 $ae->nonce (12);
53 $ae->associated_data (34);
54 my $ar = unpack "H*", $ae->crypt ("A2345678") ^ "A2345678";
55 print $ec eq $ar ? "" : "not ", "ok ", ++$n, " # AE1 $a => $ar (= $ec)\n";
56 $ae = unpack "H*", $ae->finish (8);
57 print $em eq $ae ? "" : "not ", "ok ", ++$n, " # AE2 $a => $ae (= $em)\n";
58 }
59 }
60
61 print "ok 82\n";
62