# Test against SHA-1 Sample Vectors from NIST use strict; my $MODULE; BEGIN { $MODULE = (-d "src") ? "Digest::SHA" : "Digest::SHA::PurePerl"; eval "require $MODULE" || die $@; $MODULE->import(qw()); } BEGIN { if ($ENV{PERL_CORE}) { chdir 't' if -d 't'; @INC = '../lib'; } } my $nist_hashes = <new(1); for (@lines) { next unless /^[\d ^]/; $message .= $_; next unless /\^\s*$/; my @vals = $message =~ /\d+/g; $message = ""; my $count = shift(@vals); my $bit = shift(@vals); my $bitstr = ""; while (@vals) { $bitstr .= $bit x shift(@vals); $bit = 1 - $bit; } print "not " unless uc($sha->add(pack("B*", $bitstr))->hexdigest) eq shift(@hashes); print "ok ", $testnum++, "\n"; }