|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-03-06 21:33 UTC] andres at phalconphp dot com
Description:
------------
The hash generated by PHP 5.3.x is diferent than the generated by 5.4.x using the hashing algorithm tiger160,3
Test script:
---------------
PHP 5.3.x:
[#] php -v
PHP 5.3.8 (cli) (built: Feb 28 2012 10:44:41)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
[#] php -r 'echo hash("tiger160,3", "1awks!4090");'
f8d2f5f634cc0ec4f495ac1aeb45010e90e310a3
[#] php -v
PHP 5.4.1RC1-dev (cli) (built: Mar 6 2012 16:25:42) (DEBUG)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
[#] php -r 'echo hash("tiger160,3", "1awks!4090");'
c40ecc34f6f5d2f80e0145eb1aac95f43045295d
Expected result:
----------------
Hash values returned must be the same for the same value between php versions
Patches61307-patch.diff (last revision 2012-03-06 23:59 UTC by me at ktamura dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 14:00:01 2025 UTC |
Sorry folks, here's a one-liner to re-create pre-PHP-5.4 hashes: implode("", array_map("bin2hex", array_map("strrev", str_split(hash("tiger192,3", $input, true), 8)))); Truncate the result to the length you need (128,160,192 bits). Make sure every array value is 16 hex digits long or else lpad it with literal 0s. If you used 192 bit tiger, you can use the following one-liner to create correct hashes from the wrong ones: implode("", array_map("bin2hex", array_map("strrev", array_map("hex2bin", str_split($wronghash,16)))));Here's something for the documentation team: /* calculate pre-php-5.4 tiger hashes with php-5.4 */ function old_tiger($data = "", $width=192, $rounds = 3) { return substr( implode( array_map( function ($h) { return str_pad(bin2hex(strrev($h)), 16, "0"); }, str_split(hash("tiger192,$rounds", $data, true), 8) ) ), 0, 48-(192-$width)/4 ); }