ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Crypt-Spritz/t/01_spritz.t
(Generate patch)

Comparing Crypt-Spritz/t/01_spritz.t (file contents):
Revision 1.2 by root, Sat Jan 10 04:14:17 2015 UTC vs.
Revision 1.3 by root, Sat Jan 10 04:56:38 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines