Commit: 540a5a52e89fce6da19d6f79dd1eda587a25b396 Author: Anthony Ferrara <ircmax...@gmail.com> Tue, 28 May 2013 15:30:45 -0400 Parents: 2f01e06786c6f4b2479fdb728bd26062d07208e0 Branches: PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=540a5a52e89fce6da19d6f79dd1eda587a25b396 Log: Fix #64745 hash_pbkdf2 truncation issue When using hash_pbkdf2 with hex output and 0 length (auto), it incorrectly truncates the result to 1/2 the expected result. Bugs: https://bugs.php.net/64745 Changed paths: M NEWS M ext/hash/hash.c A ext/hash/tests/bug64745.phpt Diff: diff --git a/NEWS b/NEWS index b9a2226..d2d8aae 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ PHP NEWS -FPM: . Fixed Bug #64915 (error_log ignored when daemonize=0). (Remi) +- Hash: + . Fixed Bug #64745 (hash_pbkdf2() truncates data when using default length + and hex output). (Anthony Ferrara) + 23 May 2013, PHP 5.5.0 Release Candidate 2 - Core: diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 9492387..9cede14 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -659,6 +659,9 @@ PHP_FUNCTION(hash_pbkdf2) /* Setup Main Loop to build a long enough result */ if (length == 0) { length = ops->digest_size; + if (!raw_output) { + length = length * 2; + } } digest_length = length; if (!raw_output) { diff --git a/ext/hash/tests/bug64745.phpt b/ext/hash/tests/bug64745.phpt new file mode 100644 index 0000000..427f89b --- /dev/null +++ b/ext/hash/tests/bug64745.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #64745 hash_pbkdf2() truncates data when using default length and hex output +--SKIPIF-- +<?php extension_loaded('hash') or die('skip'); ?> +--FILE-- +<?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)); + +?> +--EXPECT-- +string(40) "0c60c80f961f0e71f3a9b524af6012062fe037a6" +string(40) "0c60c80f961f0e71f3a9b524af6012062fe037a6" + -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php