note 109238 added to function.mhash-count
| From: | holdoffhunger at gmail dot com | Date: | Fri, 29 Jun 2012 00:37:02 +0000 |
| Subject: | note 109238 added to function.mhash-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188958@lists.php.net to get a copy of this message | ||
The MHash function mhash_count() returns the highest, evaluated, constant value representing a
hashing algorithm available within the current MHash install. For example, 0 indicates CRC32, 1
indicates MD5, 2 indicates SHA1, etc., etc.. You can get the evaluated number for any of these
algorithms by doing a print statement with any of the predefined, MHash constants, such as those
available here : http://www.php.net/manual/en/mhash.constants.php
.
The purpose of mhash_count() in MHash is similar to the purpose of hash_algos() in HASH Message
Digest Framework. Instead of providing an array of available hashing algorithms, it simply provides
the highest, evaluated, constant expression for the Algorithm Constants. The thinking, as indicated
in the sample code, is that you will parse a list of mhash algorithms in a for loop using a
condition of "$i <= mhash_count()".
However, there is a problem with that: there are several integers that are skipped in the listing of
evaluated constant expressions. While 2 indicates SHA1, 3 indicates HAVAL256, etc., there is
nothing for the numbers 4 and 6. They produce blank results when on that line of the for-loop and
you're calling functions like mhash_get_block_size() and mhash_get_hash_name(). These were
likely reserved for algorithms that were removed for one reason or another, either inefficiency or
lack of security, and the number-to-predefined-constant setup wasn't changed to make it
backward compatible with older code.
If you want to know what counts as a good constant and what doesn't, try running this code :
<?php
// Author: holdoffhunger@gmail.com
// Parse All Hashing Algorithms
// ---------------------------------------------------
for($i = 0; $i <= mhash_count(); $i++)
{
// Get Algorithm Information
// ---------------------------------------------------
$mhash_algorithm_block_size = mhash_get_block_size($i);
$mhash_algorithm_name = mhash_get_hash_name($i);
// Decide on Printing Algorithm Information
// ---------------------------------------------------
if(strlen($mhash_algorithm_name) < 1)
{
// There *IS* Available Algorithm Data
// ---------------------------------------------------
print("# $i --- NO ALGORITHM NAME / NO ALGORITHM BLOCKSIZE .<br><br>");
}
else
{
// There *IS NO* Available Algorithm Data
// ---------------------------------------------------
print("# $i --- $mhash_algorithm_name to $mhash_algorithm_block_size
.<br><br>");
}
}
?>
Sample Results
............................
# 0 --- CRC32 to 4 .
# 1 --- MD5 to 16 .
# 2 --- SHA1 to 20 .
# 3 --- HAVAL256 to 32 .
# 4 --- NO ALGORITHM NAME / NO ALGORITHM BLOCKSIZE .
# 5 --- RIPEMD160 to 20 .
# 6 --- NO ALGORITHM NAME / NO ALGORITHM BLOCKSIZE .
# 7 --- TIGER to 24 .
# 8 --- GOST to 32 .
...(and so on)...
----
Server IP: 69.147.83.197
Probable Submitter: 68.9.137.178
----
Manual Page -- http://www.php.net/manual/en/function.mhash-count.php
Edit -- https://master.php.net/note/edit/109238
Del: integrated -- https://master.php.net/note/delete/109238/integrated
Del: useless -- https://master.php.net/note/delete/109238/useless
Del: bad code -- https://master.php.net/note/delete/109238/bad+code
Del: spam -- https://master.php.net/note/delete/109238/spam
Del: non-english -- https://master.php.net/note/delete/109238/non-english
Del: in docs -- https://master.php.net/note/delete/109238/in+docs
Del: other reasons-- https://master.php.net/note/delete/109238
Reject -- https://master.php.net/note/reject/109238
Search -- https://master.php.net/manage/user-notes.php