xref: /openbsd-src/gnu/usr.bin/perl/cpan/Digest-SHA/t/state.t (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1use strict;
2
3my $MODULE;
4
5BEGIN {
6	$MODULE = (-d "src") ? "Digest::SHA" : "Digest::SHA::PurePerl";
7	eval "require $MODULE" || die $@;
8	$MODULE->import(qw(sha384_hex sha512_hex));
9}
10
11BEGIN {
12	if ($ENV{PERL_CORE}) {
13		chdir 't' if -d 't';
14		@INC = '../lib';
15	}
16}
17
18my @sharsp = (
19	"34aa973cd4c4daa4f61eeb2bdbad27316534016f",
20	"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0",
21	"9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985",
22	"e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b"
23);
24
25my $numtests = scalar @sharsp;
26print "1..$numtests\n";
27
28my($state001, $state256, $state384, $state512) = ('', '', '', '');
29for (1 .. 8) { my $line = <DATA>; $state001 .= $line }
30for (1 .. 8) { my $line = <DATA>; $state256 .= $line }
31for (1 .. 8) { my $line = <DATA>; $state384 .= $line }
32for (1 .. 8) { my $line = <DATA>; $state512 .= $line }
33my @states = ($state001, $state256, $state384, $state512);
34
35my @alg = (1, 256, 384, 512);
36my $data = "a" x 990000;
37
38my $testnum = 1;
39while (@sharsp) {
40	my $skip = 0;
41	my $alg = shift @alg;
42	my $rsp = shift @sharsp;
43	if ($alg == 384) { $skip = sha384_hex("") ? 0 : 1 }
44	if ($alg == 512) { $skip = sha512_hex("") ? 0 : 1 }
45	if ($skip) {
46		print "ok ", $testnum++, " # skip: no 64-bit\n";
47		next;
48	}
49	my $digest;
50	my $state;
51	unless ($state = $MODULE->putstate(shift @states)) {
52		print "not ok ", $testnum++, "\n";
53		next;
54	}
55	my $statestr = $state->add_bits($data, 79984)->getstate;
56	$state->putstate($statestr)->add_bits($data, 16);
57	$digest = $state->hexdigest;
58	print "not " unless $digest eq $rsp;
59	print "ok ", $testnum++, "\n";
60}
61
62__DATA__
63alg:1
64H:9d6f7d2f:65e21307:c6f41af6:7c7fd3a9:8dec6058:00000000:00000000:00000000
65block: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
66blockcnt:384
67lenhh:0
68lenhl:0
69lenlh:0
70lenll:7920000
71alg:256
72H:2d6c0def:4244ade7:fc8c121c:108f4493:ec3fbec2:91425a6e:b8d30d2a:9db24273
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:384
80H:598147f4583a61f7:8d194a4d7c9008cb:39725c96557d600f:d7f2079ce8251f19:bd735d446f9a3c7c:234de90b9060898d:a5b481b9d635d190:81c6e74ee4556125
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: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
82blockcnt:384
83lenhh:0
84lenhl:0
85lenlh:0
86lenll:7920000
87alg:512
88H:0442fe29a02b8c30:13553e6dbedc2aa0:8f891a0cb2ac3107:6fa1762b40ac04dd:dcbf420d729eea79:34703e9672dcf145:7bf9aaa14d400433:2aa65f044825466d
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
95