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