ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Crypt-Spritz/t/01_spritz.t
Revision: 1.6
Committed: Sat Jan 10 09:14:53 2015 UTC (9 years, 5 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_02, rel-1_0, rel-0_2, rel-1_01, HEAD
Changes since 1.5: +14 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.6 BEGIN { $| = 1; print "1..100\n"; }
2 root 1.1
3     use Crypt::Spritz;
4    
5     my $n = 0;
6 root 1.2
7 root 1.1 my $c1 = new Crypt::Spritz;
8    
9 root 1.3 for (1..3) {
10     for (
11 root 1.4 [ABC => "779a8e01f9e9cbc0", "028fa2b48b934a18", "eb4765b22caa38ab", "a25b6e57fb35481b", "75ea088baadc803e"],
12     [spam => "f0609a1df143cebf", "acbba0813f300d3a", "433a025805dbb3b1", "e1eed00911069b9d", "782cf66ae9d1fdea"],
13     [arcfour => "1afa8b5ee337dbc7", "ff8cf268094c87b9", "c72e6cfc08b27d4a", "cac713dfba93cd79", "413397b795a75abf"],
14 root 1.3 ) {
15 root 1.4 my ($a, $r, $h, $m, $ec, $em) = @$_;
16 root 1.3
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 root 1.5 my $c2 = $c1->clone;
24 root 1.3 $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 root 1.6 my $ci = new Crypt::Spritz::Cipher $a;
43     my $ci1 = $ci->encrypt ($m);
44     my $ci = new Crypt::Spritz::Cipher $a;
45     $ci1 = $ci->decrypt ($ci1);
46     print $m eq $ci1 ? "" : "not ", "ok ", ++$n, " # CI1 $a => $ci1 (= $m)\n";
47    
48 root 1.3 my $cx1 = new Crypt::Spritz::Cipher::XOR $a;
49     $cx1 = unpack "H*", $cx1->crypt ("12345678") ^ "12345678";
50     print $r eq $cx1 ? "" : "not ", "ok ", ++$n, " # CX1 $a => $cx1 (= $r)\n";
51    
52     my $cx2 = "98765432";
53     Crypt::Spritz::Cipher::XOR->new ($a)->crypt_inplace ($cx2);
54     $cx2 = unpack "H*", $cx2 ^ "98765432";
55     print $r eq $cx2 ? "" : "not ", "ok ", ++$n, " # CX2 $a => $cx2 (= $r)\n";
56    
57 root 1.6 my $ae = new Crypt::Spritz::AEAD $a; $ae->nonce (45); $ae->associated_data (67);
58     my $ar1 = $ae->encrypt ($m);
59     my $ae = new Crypt::Spritz::AEAD $a; $ae->nonce (45); $ae->associated_data (67);
60     $ar1 = $ae->decrypt ($ar1);
61     print $m eq $ar1 ? "" : "not ", "ok ", ++$n, " # AR1 $a => $ar1 (= $m)\n";
62    
63 root 1.3 my $ae = new Crypt::Spritz::AEAD::XOR $a;
64 root 1.4 $ae->nonce (12);
65     $ae->associated_data (34);
66 root 1.3 my $ar = unpack "H*", $ae->crypt ("A2345678") ^ "A2345678";
67 root 1.4 print $ec eq $ar ? "" : "not ", "ok ", ++$n, " # AE1 $a => $ar (= $ec)\n";
68 root 1.3 $ae = unpack "H*", $ae->finish (8);
69 root 1.4 print $em eq $ae ? "" : "not ", "ok ", ++$n, " # AE2 $a => $ae (= $em)\n";
70 root 1.3 }
71 root 1.1 }
72    
73 root 1.6 print "ok 100\n";
74 root 1.2