hash.lib.php 586 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * The hash extension polyfills.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /* Compatibility with PHP < 5.6 */
  12. if (! function_exists('hash_equals')) {
  13. /**
  14. * Timing attack safe string comparison
  15. *
  16. * @param string $a first string
  17. * @param string $b second string
  18. *
  19. * @return boolean whether they are equal
  20. */
  21. function hash_equals($a, $b) {
  22. $ret = strlen($a) ^ strlen($b);
  23. $ret |= array_sum(unpack("C*", $a ^ $b));
  24. return ! $ret;
  25. }
  26. }