/** * Generate a random string of the specified size * * @param int $size The size of the requested random string * * @return string A string of the requested size */ public function generate($size) { $result = ''; while (Util::safeStrlen($result) < $size) { $result = uniqid($result, true); } return Util::safeSubstr($result, 0, $size); }
public function __construct() { $state = self::$state; if (function_exists('posix_times')) { $state .= serialize(posix_times()); } if (!defined('HHVM_VERSION') && function_exists('zend_thread_id')) { $state .= zend_thread_id(); } if (function_exists('hphp_get_thread_id')) { $state .= hphp_get_thread_id(); } $state .= getmypid() . memory_get_usage(); $state .= serialize($_ENV); $state .= serialize($_SERVER); $state .= count(debug_backtrace(false)); self::$state = hash('sha512', $state, true); if (is_null(self::$counter)) { list(, self::$counter) = unpack("i", Util::safeSubstr(self::$state, 0, 4)); $seed = $this->generate(Util::safeStrlen(dechex(PHP_INT_MAX))); list(, self::$counter) = unpack("i", $seed); } }
/** * Get the block size (the size of the individual blocks used for the mixing) * * @return int The block size */ protected function getPartSize() { return Util::safeStrlen(hash($this->hash, '', true)); }
private function str_split($string, $size) { $blocks = array(); $length = Util::safeStrlen($string); $parts = ceil($length / $size); for ($i = 0; $i < $parts; $i++) { $blocks[] = Util::safeSubstr($string, $i * $length, $length); } return $blocks; }