Bug #61098 [Ana]: crypt() hangs when using Blowfish salt with SHA512 hash
| From: | rasmus@php.net | Date: | Wed, 15 Feb 2012 21:16:28 +0000 |
| Subject: | Bug #61098 [Ana]: crypt() hangs when using Blowfish salt with SHA512 hash | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167556@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61098&edit=1
ID: 61098
Updated by: rasmus@php.net
Reported by: naryndel at hotmail dot com
Summary: crypt() hangs when using Blowfish salt with SHA512
hash
Status: Analyzed
Type: Bug
Package: *Encryption and hash functions
Operating System: RedHat Linux
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
I guess technically this isn't actually a bug. You are asking for a work factor of
31. Work factors are exponential and 31 is going to take a very very long time.
You could perhaps make a persuasive argument for not allowing work factors that
high.
Previous Comments:
------------------------------------------------------------------------
[2012-02-15 20:32:53] rasmus@php.net
Confirmed, this gets stuck in standard/crypt_blowfish.c because of this:
691 count = (BF_word)1 << ((setting[4] - '0') * 10 + (setting[5] -
'0'));
(gdb) p count
$1 = 2147483648
(gdb) p setting[4]
$2 = 51 '3'
(gdb) p setting[5]
$3 = 49 '1'
(gdb) p ((setting[4] - '0') * 10 + (setting[5] - '0'))
$4 = 31
And then there is a while(--count) loop further on that is thus going to take a
long time to complete.
------------------------------------------------------------------------
[2012-02-15 20:06:01] naryndel at hotmail dot com
Description:
------------
My hosting company recently upgraded from PHP 5.2.x to PHP 5.3.1.
Using crypt() with a salt following the CRYPT_BLOWFISH format (as shown on
http://ca.php.net/manual/en/function.crypt.php)
the script will hang and timeout
.
Previous to the upgrade the function would process successfully without warning
or error. A call to hash_algos() does list "Blowfish" as a registered hashing
algorithm.
On the documentation page for crypt(), the following note is stated: "As of PHP
5.3.0, PHP contains its own implementation and will use that if the system lacks
of support for one or more of the algorithms."
So rather than hanging PHP is expected to use an internal algorithm in place
where Blowfish is apparently not supported on the server.
This was further tested by using a sha512-formatted salt for the 2nd argument
(sha512 is listed in the result provided by hash_algos()), which processes
successfully. Also by calling crypt() using the Blowfish salt and attempting
with the 1st argument processed using the hash() function and without - both
instances cause the script to hang as well.
Test script:
---------------
crypt(hash("sha512","something"),'$2a$31$developer./.excellence$');
Expected result:
----------------
The expected result would be an encrypted string using an internal PHP algorithm
as described within the PHP documentation for the crypt() function.
Actual result:
--------------
The actual result is that the script will hang until the maximum process time on
the server is exceeded and the script times out, giving the following error
message:
[warn] mod_fcgid: stderr: PHP Fatal error: Maximum execution time of 30 seconds
exceeded in [script path] on line 30
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61098&edit=1