diff --git a/core/lib/Drupal/Component/Utility/Crypt.php b/core/lib/Drupal/Component/Utility/Crypt.php index 0a530e7..bd6c133 100644 --- a/core/lib/Drupal/Component/Utility/Crypt.php +++ b/core/lib/Drupal/Component/Utility/Crypt.php @@ -142,9 +142,12 @@ public static function randomBytesBase64($count = 32) { } /** - * Get a shortened sha256 hash. + * Generates a shortened sha256 hash. While there is always the risk of + * collision (when different $data generate the same hash), shortened hashes + * increase that risk. This function should only be used when that additional + * risk is acceptable. * - * @param string $name + * @param string $data * Message to be hashed. * @param string $key * Shared secret key. @@ -154,12 +157,12 @@ public static function randomBytesBase64($count = 32) { * @return string * A sha256 base 36 encoded shortened hash. */ - public static function shortHash($name, $key = NULL, $length = self::SHORT_HASH_LENGTH_DEFAULT) { + public static function shortHash($data, $key = NULL, $length = self::SHORT_HASH_LENGTH_DEFAULT) { if ($key) { - return substr(base_convert(hash_hmac('sha256', $name, $key), 16, 36), 0, $length); + return substr(base_convert(hash_hmac('sha256', $data, $key), 16, 36), 0, $length); } else { - return substr(base_convert(hash('sha256', $name), 16, 36), 0, $length); + return substr(base_convert(hash('sha256', $data), 16, 36), 0, $length); } }