note 91568 added to function.hash
| From: | Sephi at osu1 dot php dot net | Date: | Wed, 17 Jun 2009 11:19:27 +0000 |
| Subject: | note 91568 added to function.hash | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156960@lists.php.net to get a copy of this message | ||
In response to Peter Kelly, 29-Jan-2007 01:32:
Here is a more complete emulation of the hash function using mhash.
<?php
f (!function_exists('hash_algos'))
{
function hash_algos()
{
$algos = array(
'md4', 'md5', 'crc32', 'crc32b',
'sha1', 'sha256',
'haval128,3', 'haval128,4', 'haval128,5',
'haval160,3', 'haval160,4', 'haval160,5',
'haval192,3', 'haval192,4', 'haval192,5',
'haval224,3', 'haval224,4', 'haval224,5',
'haval256,3', 'haval256,4', 'haval256,5',
'tiger128,3', 'tiger128,4',
'tiger160,3', 'tiger160,4',
'tiger192,3', 'tiger192,4',
'adler32', 'gost',
);
return $algos;
}
}
if (!function_exists('hash'))
{
function hash($algo, $data, $raw_output = false)
{
switch(strtolower($algo))
{
case 'md5':
return md5($data, $raw_output);
case 'sha1':
return sha1($data, $raw_output);
case 'crc32':
return crc32($data);
case 'sha256':
return $raw_output?mhash(MHASH_SHA256, $data):bin2hex(mhash(MHASH_SHA256, $data));
case 'haval128,3':
case 'haval128,4':
case 'haval128,5':
return $raw_output?mhash(MHASH_HAVAL128, $data):bin2hex(mhash(MHASH_HAVAL128, $data));
case 'haval160,3':
case 'haval160,4':
case 'haval160,5':
return $raw_output?mhash(MHASH_HAVAL160, $data):bin2hex(mhash(MHASH_HAVAL160, $data));
case 'haval192,3':
case 'haval192,4':
case 'haval192,5':
return $raw_output?mhash(MHASH_HAVAL192, $data):bin2hex(mhash(MHASH_HAVAL192, $data));
case 'haval224,3':
case 'haval224,4':
case 'haval224,5':
return $raw_output?mhash(MHASH_HAVAL224, $data):bin2hex(mhash(MHASH_HAVAL224, $data));
case 'haval256,3':
case 'haval256,4':
case 'haval256,5':
return $raw_output?mhash(MHASH_HAVAL256, $data):bin2hex(mhash(MHASH_HAVAL256, $data));
case 'tiger128,3':
case 'tiger128,4':
return $raw_output?mhash(MHASH_TIGER128, $data):bin2hex(mhash(MHASH_TIGER128, $data));
case 'tiger160,3':
case 'tiger160,4':
return $raw_output?mhash(MHASH_TIGER160, $data):bin2hex(mhash(MHASH_TIGER160, $data));
case 'tiger192,3':
case 'tiger192,4':
return $raw_output?mhash(MHASH_TIGER, $data):bin2hex(mhash(MHASH_TIGER, $data));
case 'adler32':
return $raw_output?mhash(MHASH_ADLER32, $data):bin2hex(mhash(MHASH_ADLER32, $data));
case 'gost':
return $raw_output?mhash(MHASH_GOST, $data):bin2hex(mhash(MHASH_GOST, $data));
case 'md4':
return $raw_output?mhash(MHASH_MD4, $data):bin2hex(mhash(MHASH_MD4, $data));
case 'ripemd160':
return $raw_output?mhash(MHASH_RIPEMD160, $data):bin2hex(mhash(MHASH_RIPEMD160, $data));
case 'crc32b':
return $raw_output?mhash(MHASH_CRC32B, $data):bin2hex(mhash(MHASH_CRC32B, $data));
default:
return false;
}
}
}
?>
----
Server IP: 217.13.201.10
Probable Submitter: 194.94.206.16
----
Manual Page -- http://www.php.net/manual/en/function.hash.php
Edit -- https://master.php.net/note/edit/91568
Del: integrated -- https://master.php.net/note/delete/91568/integrated
Del: useless -- https://master.php.net/note/delete/91568/useless
Del: bad code -- https://master.php.net/note/delete/91568/bad+code
Del: spam -- https://master.php.net/note/delete/91568/spam
Del: non-english -- https://master.php.net/note/delete/91568/non-english
Del: in docs -- https://master.php.net/note/delete/91568/in+docs
Del: other reasons-- https://master.php.net/note/delete/91568
Reject -- https://master.php.net/note/reject/91568
Search -- https://master.php.net/manage/user-notes.php