This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Digest::SHA 5.45.
[perl5.git] / ext / Digest / SHA / t / dumpload.t
CommitLineData
747da336
RGS
1use strict;
2use FileHandle;
3
4my $MODULE;
5
6BEGIN {
7 $MODULE = (-e "SHA.pm") ? "Digest::SHA" : "Digest::SHA::PurePerl";
8 eval "require $MODULE" || die $@;
9 $MODULE->import(qw(sha384_hex sha512_hex));
10}
11
12BEGIN {
13 if ($ENV{PERL_CORE}) {
14 chdir 't' if -d 't';
15 @INC = '../lib';
16 }
17}
18
19my @sharsp = (
20 "34aa973cd4c4daa4f61eeb2bdbad27316534016f",
21 "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0",
22 "9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985",
23 "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b"
24);
25
26my $numtests = scalar @sharsp;
27print "1..$numtests\n";
28
29my @tempfiles;
30END { 1 while unlink @tempfiles }
31
32my @statefiles = ("dl001.tmp", "dl256.tmp", "dl384.tmp", "dl512.tmp");
33for (@statefiles) {
34 push @tempfiles, $_;
35 my $fh = FileHandle->new($_, "w");
36 for (1 .. 8) { my $line = <DATA>; print $fh $line }
37 $fh->close;
38}
39my $tmpfile = "dumpload.tmp";
40push @tempfiles, $tmpfile;
41
42my @alg = (1, 256, 384, 512);
43my $data = "a" x 990000;
44
45my $testnum = 1;
46while (@sharsp) {
47 my $skip = 0;
48 my $alg = shift @alg;
49 my $rsp = shift @sharsp;
50 my $file = shift @statefiles; push(@statefiles, $file);
51 if ($alg == 384) { $skip = sha384_hex("") ? 0 : 1 }
52 if ($alg == 512) { $skip = sha512_hex("") ? 0 : 1 }
53 if ($skip) {
54 print "ok ", $testnum++, " # skip: no 64 bit\n";
55 next;
56 }
57 my $digest;
58 my $state;
59 unless ($state = $MODULE->load($file)) {
60 print "not ok ", $testnum++, "\n";
61 next;
62 }
63 $state->add_bits($data, 79984)->dump($tmpfile);
64 $state->load($tmpfile)->add_bits($data, 16);
65 $digest = $state->hexdigest;
66 print "not " unless $digest eq $rsp;
67 print "ok ", $testnum++, "\n";
68}
69
70__DATA__
71alg:1
72H:9d6f7d2f:65e21307:c6f41af6:7c7fd3a9:8dec6058:00000000:00000000:00000000
73block:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
74blockcnt:384
75lenhh:0
76lenhl:0
77lenlh:0
78lenll:7920000
79alg:256
80H:2d6c0def:4244ade7:fc8c121c:108f4493:ec3fbec2:91425a6e:b8d30d2a:9db24273
81block:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
82blockcnt:384
83lenhh:0
84lenhl:0
85lenlh:0
86lenll:7920000
87alg:384
88H:598147f4583a61f7:8d194a4d7c9008cb:39725c96557d600f:d7f2079ce8251f19:bd735d446f9a3c7c:234de90b9060898d:a5b481b9d635d190:81c6e74ee4556125
89block:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
90blockcnt:384
91lenhh:0
92lenhl:0
93lenlh:0
94lenll:7920000
95alg:512
96H:0442fe29a02b8c30:13553e6dbedc2aa0:8f891a0cb2ac3107:6fa1762b40ac04dd:dcbf420d729eea79:34703e9672dcf145:7bf9aaa14d400433:2aa65f044825466d
97block:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:61:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
98blockcnt:384
99lenhh:0
100lenhl:0
101lenlh:0
102lenll:7920000