There's a class for generating TTH compatible with DC clients (DC++, StrongDC, ...) which uses mhash() with tiger algorithm:
http://kupershtokh.blogspot.com/2007/12/on-phpclub.html
LXXXV. Hash Funktionen
Diese Funktionen arbeiten zusammen mit » mhash.
Dies ist eine Schnittstelle zu der Mhash Bibliothek. Mhash unterstützt eine breite Auswahl an Hash Algorithmen, wie MD5, SHA1, GOST, und viele andere.
Um sie zu verwenden, muss man die Mhash Distribution von » der Website downloaden und der beigefügten Instalationsanleitung folgen. PHP muss mit der Option --with-mhash kompiliert werden um diese Erweiterung zu aktivieren.
Mhash wird verwendet um z.B. Checksummen und Mehr zu erstellen.
Beispiel 1053. Berechne den MD5 Extrakt und gib es als Hex aus
<?php |
Die Ausgabe ist:
Der Hash ist d03cb659cbf9192dcd066272249f8412
Der hmac ist 750c783e6ab0b503eaa86e310a5db738
|
Eine komplette Liste aller unterstützen Hashes ist in der Dokumentation von Mhash enthalten. Die allgemeine Verwendung ist, dass man einen Hash Algorithmus von PHP mit MHASH_HASHNAME erreicht. Z.B., um HAVAL zu erreichen benutzt man die PHP Konstante MHASH_HAVAL.
Hier ist eine Liste von Hashs, die momentan von Mhash unterstützt werden. Wenn ein Hash ist hier nicht aufgeführt ist, aber von Mhash, laut Dokumentation, unterstützt wird, ist diese Dokumentation als veraltet anzusehen.
- MHASH_MD5
- MHASH_SHA1
- MHASH_HAVAL
- MHASH_RIPEMD160
- MHASH_RIPEMD128
- MHASH_SNEFRU
- MHASH_TIGER
- MHASH_GOST
- MHASH_CRC32
- MHASH_CRC32B
Inhaltsverzeichnis
- mhash_count — Gibt den höchstmöglichen Hash zurück
- mhash_get_block_size — Gibt die Blockgroesse von dem übergebenem Hash zurück
- mhash_get_hash_name — Gibt den Namen eines Hashs zurück
- mhash_keygen_s2k — Generates a key
- mhash — Hash berechnen
to robert at mediamonks dot com
This will work better, in your function you can just use the constant function to pull in the actual value of MHASH_SHA512 or whatever.
function getHashNotWorking($argStrHashMethod, $argStrString)
{
$strHashMethod = 'MHASH_' . $argStrHashMethod;
$strHashedString = bin2hex(mhash(constant($strHashMethod), $argStrString));
return $strHashedString;
}
now:
echo getHashNotWorking('SHA512', 'some string');
works how you want it.
function getHashNotWorking($argStrHashMethod, $argStrString)
{
$strHashMethod = 'MHASH_' . $argStrHashMethod;
$strHashedString = bin2hex(mhash($strHashMethod, $argStrString));
return $strHashedString;
}
echo getHashNotWorking('SHA512', 'some string');
This will return an error about the mhash function expecting a long type instead of a string.
=============================
for ($intI = 0; $intI <= mhash_count(); $intI++)
{
$arrHashTypes[mhash_get_hash_name($intI)] = $intI;
}
function getHashWorking($argStrType, $argStrString)
{
global $arrHashTypes;
$strHashedString = bin2hex(mhash($arrHashTypes[$argStrType], $argStrString));
return $strHashedString;
}
echo getHashWorking('SHA512', 'some string');
This will return the hash with the desired hash method
Since it seems that the tiger hash bug has been labeled "bogus" here is a fix to give a correct result. I'm not a binary expert so if you come up with a better fix please let us know. Just do your MHASH_TIGER as normal then send the unaltered binary into tigerfix and you get a proper HEX return.
function tigerfix ($binary_hash) {
$my_split = str_split($binary_hash,8);
$my_tiger ="";
foreach($my_split as $key => $value) {
$my_split[$key] = strrev($value);
$my_tiger .= $my_split[$key];
}
$my_tiger_hex = bin2hex($my_tiger);
return $my_tiger_hex;
}
To enable mhash on RHEL/Fedora Core/other RPM-based Linuxes without rebuilding PHP, get the php-mhash and mhash RPMs at http://phprpms.sourceforge.net/mhash
MHASH_HAVAL256 , MHASH_HAVAL192, etc...
refers to the HAVAL hash with 3 rounds.
To use HAVAL with 4 or 5 rounds, you have to
recompile the mhash library and either add
new hash names, or just change in mhash.c
the definitions of MHASH_HAVAL256,...
