Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: squeamish ossifrage - SHA failing

by grep (Monsignor)
on Nov 26, 2006 at 17:50 UTC ( #586132=note: print w/ replies, xml ) Need Help??


in reply to squeamish ossifrage - SHA failing

I am not (even close) to an expert on SHA hash functions, but after looking at the Perlshop code, I wouldn't trust that code for production use. It also appears not to have been updated since '98 (use CGI or die;).

I would use Digest::SHA1

use strict; use warnings; use Digest::SHA1 qw(sha1_hex); my $data = "squeamish ossifrage\n"; print sha1_hex($data);
prints 820550664cf296792b38d1647a4d8c0e1966af57

If you are actually using Perlshop and can't switch quickly, refactor the SHA sub to use Digest::SHA1 then look at switching to Interchange which is actively developed.

For anyone who's interested here is the SHA sub in question (formatting intact):

sub SHA { ### This algorithm is based on the implementation +of SHA ### written by: John Allen (allen@grumman.com). ### &SHA("squeamish ossifrage\n"); ### Should return 82055066 4cf29679 2b38d164 7a4d8c0e 1966 +af57 my ($msg, $p, $l) = @_; #$p=0; $l=0 local $_; $temp = 'D9T4C`>_-JXF8NMS^$#)4=L/2X?!:@GF9;MGKH8\;O-S*8L\'6'; $m = 4294967296; ###$m=1+~0; @A=unpack"N*",unpack u,$temp; @K=splice@A,5,4; sub M{($x=pop)-($m)*int$x/$m}; sub L{$n=pop;($x=pop)<<$n|2**$n-1&$x>>32-$n} @F=(sub{$b&($c^$d)^$d},$S=sub{$b^$c^$d},sub{($b|$c)&$d|$b&$c},$S); do{ $msg=~s/.{0,64}//s;$_=$&; $l+=$r=length; $r++,$_.="\x80"if$r<64&&!$p++;@W=unpack N16,$_."\0"x7;$W[15]=$l*8 if$r<57; for(16..79){push@W,L$W[$_ -3]^$W[$_-8]^$W[$_-14]^$W[$_-16],1}($a,$b,$c,$d,$e)=@A; for(0..79){$t=M&{$F[$_/ 20]}+$e+$W[$_]+$K[$_/20]+L$a,5; $e=$d; $d=$c; $c=L$b,30; $b=$a; $a=$t}$v='a'; @A=map{ M$_+${$v++}}@A }while$r>56; return sprintf'%8x 'x4 . '%8x',@A; }

grep
XP matters not. Look at me. Judge me by my XP, do you?


Comment on Re: squeamish ossifrage - SHA failing
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://586132]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-09-18 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (107 votes), past polls