|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-03-29 12:25 UTC] gelenkig at runbox dot com
Description:
------------
hash_pbkdf2() must return different hashes for different $password's but it returns the same hash no matter how many trailing NUL bytes $password has.
Test script:
---------------
// all 3 variables contain the same hash.
$h1 = hash_pbkdf2('sha256', "password", 'salt', 1000);
$h2 = hash_pbkdf2('sha256', "password\0", 'salt', 1000);
$h3 = hash_pbkdf2('sha256', "password\0\0", 'salt', 1000);
// prints TRUE, TRUE but it must be 3 separate hashes: FALSE, FALSE.
var_dump($h1===$h2, $h1===$h3);
Expected result:
----------------
hash of password !== hash of password\0 !== hash of password\0\0 !== ...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 07:00:01 2025 UTC |
Same problem with openssl_pbkdf2(). If it's expected behaviour it must be documented. // all 3 variables contain the same hash. $h1 = openssl_pbkdf2("password", 'salt', 40, 1000, 'sha256'); $h2 = openssl_pbkdf2("password\0", 'salt', 40, 1000, 'sha256'); $h3 = openssl_pbkdf2("password\0\0", 'salt', 40, 1000, 'sha256'); // TRUE, TRUE - wrong. var_dump($h1===$h2, $h1===$h3);Passwords with trailing null bytes up to the block length of the used hash function giving the same result is expected when using PKBDF2 with an HMAC as the PRF. Notably, quoting from RFC 2104, the first step of the HMAC construction is: (1) append zeros to the end of K to create a B byte string (e.g., if K is of length 20 bytes and B=64, then K will be appended with 44 zero bytes 0x00)