Doc #71918 [Opn]: hash_pbkdf2() strips trailing \0 in $password

From: Date: Fri, 01 Apr 2016 02:26:39 +0000
Subject: Doc #71918 [Opn]: hash_pbkdf2() strips trailing \0 in $password
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-13373@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71918&edit=1 ID: 71918 Updated by: yohgaki@php.net Reported by: gelenkig at runbox dot com Summary: hash_pbkdf2() strips trailing \0 in $password Status: Open Type: Documentation Problem Package: hash related Operating System: Linux PHP Version: 5.5.33 Block user comment: N Private report: N New Comment: IMO, \0 in supplied password text should raise error because user should never supply text contains \0. PHP developers must detect invalid strings by input validation, so this is minor issue though. Previous Comments: ------------------------------------------------------------------------ [2016-03-29 13:03:51] nikic@php.net 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) ------------------------------------------------------------------------ [2016-03-29 12:27:49] gelenkig at runbox dot com 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); ------------------------------------------------------------------------ [2016-03-29 12:25:13] 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 !== ... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71918&edit=1

« previous php.doc.bugs (#13373) next »