File: /var/www/vhost/disk-apps/magento.bikenow.co/vendor/laminas/laminas-crypt/src/Utils.php
<?php
/**
* @see https://github.com/laminas/laminas-crypt for the canonical source repository
* @copyright https://github.com/laminas/laminas-crypt/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-crypt/blob/master/LICENSE.md New BSD License
*/
namespace Laminas\Crypt;
/**
* Tools for cryptography
*/
class Utils
{
/**
* Compare two strings to avoid timing attacks
*
* C function memcmp() internally used by PHP, exits as soon as a difference
* is found in the two buffers. That makes possible of leaking
* timing information useful to an attacker attempting to iteratively guess
* the unknown string (e.g. password).
* The length will leak.
*
* @param string $expected
* @param string $actual
* @return bool
*/
public static function compareStrings($expected, $actual)
{
$expected = (string) $expected;
$actual = (string) $actual;
if (function_exists('hash_equals')) {
return hash_equals($expected, $actual);
}
$lenExpected = strlen($expected);
$lenActual = strlen($actual);
$len = min($lenExpected, $lenActual);
$result = 0;
for ($i = 0; $i < $len; $i++) {
$result |= ord($expected[$i]) ^ ord($actual[$i]);
}
$result |= $lenExpected ^ $lenActual;
return ($result === 0);
}
}