You are here

public static function ParagonIE_Sodium_Core_Util::hashEquals in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core/Util.php \ParagonIE_Sodium_Core_Util::hashEquals()

Evaluate whether or not two strings are equal (in constant-time)

Parameters

string $left:

string $right:

Return value

bool

Throws

SodiumException

TypeError

8 calls to ParagonIE_Sodium_Core_Util::hashEquals()
ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash in vendor/paragonie/sodium_compat/src/Compat.php
Do we need to rehash this password?
ParagonIE_Sodium_Compat::crypto_scalarmult in vendor/paragonie/sodium_compat/src/Compat.php
Calculate the shared secret between your secret key and your recipient's public key.
ParagonIE_Sodium_Compat::crypto_scalarmult_base in vendor/paragonie/sodium_compat/src/Compat.php
Calculate an X25519 public key from an X25519 secret key.
ParagonIE_Sodium_Core_Util::memcmp in vendor/paragonie/sodium_compat/src/Core/Util.php
@internal You should not use this directly from another application
ParagonIE_Sodium_Core_Util::verify_16 in vendor/paragonie/sodium_compat/src/Core/Util.php
Compare a 16-character byte string in constant time.

... See full list

File

vendor/paragonie/sodium_compat/src/Core/Util.php, line 260

Class

ParagonIE_Sodium_Core_Util
Class ParagonIE_Sodium_Core_Util

Code

public static function hashEquals($left, $right) {

  /* Type checks: */
  if (!is_string($left)) {
    throw new TypeError('Argument 1 must be a string, ' . gettype($left) . ' given.');
  }
  if (!is_string($right)) {
    throw new TypeError('Argument 2 must be a string, ' . gettype($right) . ' given.');
  }
  if (is_callable('hash_equals')) {
    return hash_equals($left, $right);
  }
  $d = 0;

  /** @var int $len */
  $len = self::strlen($left);
  if ($len !== self::strlen($right)) {
    return false;
  }
  for ($i = 0; $i < $len; ++$i) {
    $d |= self::chrToInt($left[$i]) ^ self::chrToInt($right[$i]);
  }
  if ($d !== 0) {
    return false;
  }
  return $left === $right;
}