#GPL #GPL libwhisker copyright 2000-2004 by rfp.labs #GPL #GPL This program is free software; you can redistribute it and/or #GPL modify it under the terms of the GNU General Public License #GPL as published by the Free Software Foundation; either version 2 #GPL of the License, or (at your option) any later version. #GPL #GPL This program is distributed in the hope that it will be useful, #GPL but WITHOUT ANY WARRANTY; without even the implied warranty of #GPL MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GPL GNU General Public License for more details. #GPL ######################################################################## { # start md5 packaged varbs my (@S,@T,@M); my $code=''; =item B Params: $data Return: $hex_md5_string This function takes a data scalar, and composes a MD5 hash of it, and returns it in a hex ascii string. It will use the fastest MD5 function available. =cut sub md5 { return undef if(!defined $_[0]); # oops, forgot the data return MD5->hexhash($_[0]) if(defined $AVAILABLE{'md5'}); # return unpack('H32', Net::SSLeay::MD5($_[0])) # if(defined $AVAILABLE{'net::ssleay'}); my $DATA=_md5_pad($_[0]); &_md5_init() if(!defined $M[0]); return _md5_perl_generated(\$DATA); } ######################################################################## sub _md5_init { return if(defined $S[0]); my $i; for($i=1; $i<=64; $i++){ $T[$i-1]=int((2**32)*abs(sin($i))); } my @t=(7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21); for($i=0; $i<64; $i++){ $S[$i]=$t[(int($i/16)*4)+($i%4)]; } @M=( 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12, 5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2, 0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9 ); &_md5_generate(); # check to see if it works correctly my $TEST=_md5_pad('foobar'); if( _md5_perl_generated(\$TEST) ne '3858f62230ac3c915f300c664312c63f'){ die('Error: MD5 self-test not successful.'); } } ######################################################################## # This function is from Digest::Perl::MD5, and bears the following # copyrights: # # Copyright 2000 Christian Lackas, Imperia Software Solutions # Copyright 1998-1999 Gisle Aas. # Copyright 1995-1996 Neil Winton. # Copyright 1991-1992 RSA Data Security, Inc. # sub _md5_pad { my $l = length(my $msg=shift() . chr(128)); $ msg .= "\0" x (($l%64<=56?56:120)-$l%64); $l=($l-1)*8; $msg .= pack 'VV',$l & 0xffffffff, ($l >> 16 >> 16); return $msg; } ######################################################################## sub _md5_generate { my $N='abcddabccdabbcda'; my ($i,$M)=(0,''); $M='&0xffffffff' if((1 << 16) << 16); # mask for 64bit systems $code=< Params: $data Return: $hex_md4_string This function takes a data scalar, and composes a MD4 hash of it, and returns it in a hex ascii string. It will use the fastest MD4 function available. =cut sub md4 { return undef if(!defined $_[0]); # oops, forgot the data my $DATA=_md5_pad($_[0]); &_md4_init() if(!defined $M[0]); return _md4_perl_generated(\$DATA); } ######################################################################## sub _md4_init { return if(defined $S[0]); my $i; my @t=(3,7,11,19,3,5,9,13,3,9,11,15); for($i=0; $i<48; $i++){ $S[$i]=$t[(int($i/16)*4)+($i%4)]; } @M=( 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15, 0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15 ); my $N='abcddabccdabbcda'; my $M=''; $M='&0xffffffff' if((1 << 16) << 16); # mask for 64bit systems $code=<