From ff9778c67d8f28d4802ed5d811161c2026f4e123 Mon Sep 17 00:00:00 2001 From: Dmitlantis Date: Sun, 4 May 2014 15:30:41 +0400 Subject: [PATCH] Hash algo fix for PHP 5.4 + --- protected/helpers/RandHash.php | 6 +++++- protected/helpers/bCrypt.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/protected/helpers/RandHash.php b/protected/helpers/RandHash.php index 0780f29..d1cc6ef 100644 --- a/protected/helpers/RandHash.php +++ b/protected/helpers/RandHash.php @@ -27,7 +27,11 @@ public static function get($prefix='abc') { // 12 rounds of HMAC must be reproduced / created verbatim, no known shortcuts. // Salsa20 returns more than enough bytes. for ($i = 0; $i < 12; $i++) { - $bytes = hash_hmac('salsa20', microtime() . $bytes, $key, true); + // Support for Salsa20 was removed in PHP 5.4.0 + if (version_compare(PHP_VERSION, '5.4.0') >= 0) + $bytes = hash_hmac('sha1', microtime() . $bytes, $key, true); + else + $bytes = hash_hmac('salsa20', microtime() . $bytes, $key, true); usleep(10); } } diff --git a/protected/helpers/bCrypt.php b/protected/helpers/bCrypt.php index f9b9c0f..ede9ace 100644 --- a/protected/helpers/bCrypt.php +++ b/protected/helpers/bCrypt.php @@ -54,7 +54,11 @@ private function getBytes() { // 12 rounds of HMAC must be reproduced / created verbatim, no known shortcuts. // Salsa20 returns more than enough bytes. for ($i = 0; $i < 12; $i++) { - $bytes = hash_hmac('salsa20', microtime() . $bytes, $key, true); + // Support for Salsa20 was removed in PHP 5.4.0 + if (version_compare(PHP_VERSION, '5.4.0') >= 0) + $bytes = hash_hmac('sha1', microtime() . $bytes, $key, true); + else + $bytes = hash_hmac('salsa20', microtime() . $bytes, $key, true); usleep(10); } }