Bug #64745 [NEW]: hash_pbkdf2() truncates data when using default length and hex output

From: Date: Wed, 01 May 2013 00:18:46 +0000
Subject: Bug #64745 [NEW]: hash_pbkdf2() truncates data when using default length and hex output
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-178726@lists.php.net to get a copy of this message
From: ezzatron at gmail dot com Operating system: PHP version: 5.5.0beta4 Package: hash related Bug Type: Bug Bug description:hash_pbkdf2() truncates data when using default length and hex output Description: ------------ When passing 0 as the length to hash_pbkdf2(), the behaviour is inconsistent between raw output and hex-encoded output. See the test script for a concrete example. There are also no tests for the use case where length is defaulted in the current test suite (http://bit.ly/YcgMMu). I'm attempting to write a compatibility library for this function for PHP versions earlier that 5.5, so the test suite for https://github.com/eloquent/pbkdf2-compat and its build history in Travis CI may also be useful, as it documents the current behaviour more extensively. Test script: --------------- <?php $hash = hash_pbkdf2('sha1', 'password', 'salt', 1, 0); $rawHash = hash_pbkdf2('sha1', 'password', 'salt', 1, 0, true); var_dump($hash); var_dump(bin2hex($rawHash)); Expected result: ---------------- string(40) "0c60c80f961f0e71f3a9b524af6012062fe037a6" string(40) "0c60c80f961f0e71f3a9b524af6012062fe037a6" Actual result: -------------- string(20) "0c60c80f961f0e71f3a9" string(40) "0c60c80f961f0e71f3a9b524af6012062fe037a6" -- Edit bug report at https://bugs.php.net/bug.php?id=64745&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64745&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64745&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64745&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64745&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64745&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64745&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64745&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64745&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64745&r=support Expected behavior: https://bugs.php.net/fix.php?id=64745&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64745&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64745&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64745&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64745&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64745&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64745&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64745&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64745&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64745&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64745&r=mysqlcfg

« previous php.bugs (#178726) next »