1use strict; 2use Digest::SHA; 3 4my $numtests = 4; 5print "1..$numtests\n"; 6 7 # Here's the bitstring to test against, and its SHA-1 digest 8 9my $ONEBITS = pack("B*", "1" x 80000); 10my $digest = "11003389959355c2773af6b0f36d842fe430ec49"; 11 12my $state = Digest::SHA->new("sHa1"); 13my $testnum = 1; 14 15$state->add_bits($ONEBITS, 80000); 16print "not " unless $state->hexdigest eq $digest; 17print "ok ", $testnum++, "\n"; 18 19 # buffer using a series of increasingly large bitstrings 20 21# Note that (1 + 2 + ... + 399) + 200 = 80000 22 23for (1 .. 399) { 24 $state->add_bits($ONEBITS, $_); 25} 26$state->add_bits($ONEBITS, 200); 27 28print "not " unless $state->hexdigest eq $digest; 29print "ok ", $testnum++, "\n"; 30 31 # create a buffer-alignment nuisance 32 33$state = Digest::SHA->new("1"); 34 35$state->add_bits($ONEBITS, 1); 36for (1 .. 99) { 37 $state->add_bits($ONEBITS, 800); 38} 39$state->add_bits($ONEBITS, 799); 40 41print "not " unless $state->hexdigest eq $digest; 42print "ok ", $testnum++, "\n"; 43 44 # buffer randomly-sized bitstrings 45 46my $reps = 80000; 47my $maxbits = 8 * 127; 48 49$state = Digest::SHA->new(1); 50 51while ($reps > $maxbits) { 52 my $num = int(rand($maxbits)); 53 $state->add_bits($ONEBITS, $num); 54 $reps -= $num; 55} 56$state->add_bits($ONEBITS, $reps); 57 58print "not " unless $state->hexdigest eq $digest; 59print "ok ", $testnum++, "\n"; 60