Variable SODIUM_FIX_PHPConst
SODIUM_FIX_PHP: "\nif (!function_exists('cfw_sodium_installed')) {\n\t$__cfw_sodium = function_exists('vrzno_env') ? vrzno_env('cfwSodium') : null;\n\tif ($__cfw_sodium !== null) {\n\t\t$GLOBALS['__cfw_sodium'] = $__cfw_sodium;\n\n\t\tif (!class_exists('SodiumException')) {\n\t\t\tclass SodiumException extends Exception {}\n\t\t}\n\n\t\tfunction cfw_sodium_installed(): bool\n\t\t{\n\t\t\treturn true;\n\t\t}\n\n\t\t// __CFW_SODIUM_CONSTANTS__\n\n\t\t/**\n\t\t * Raises what ext-sodium raises.\n\t\t *\n\t\t * @param string $why\n\t\t * The message.\n\t\t *\n\t\t * @throws SodiumException\n\t\t */\n\t\tfunction cfw_sodium_fail($why): never\n\t\t{\n\t\t\tthrow new SodiumException($why);\n\t\t}\n\n\t\t/**\n\t\t * A string argument as the base64 the host reads, coerced the way an internal function\n\t\t * coerces it.\n\t\t *\n\t\t * @param string $fn\n\t\t * The function name, for the message.\n\t\t * @param int $at\n\t\t * The argument's zero-based position.\n\t\t * @param string $name\n\t\t * The parameter name.\n\t\t * @param mixed $v\n\t\t * What the caller passed.\n\t\t */\n\t\tfunction cfw_sodium_str($fn, $at, $name, $v): string\n\t\t{\n\t\t\tif (is_string($v)) {\n\t\t\t\treturn base64_encode($v);\n\t\t\t}\n\t\t\tif (is_int($v) || is_float($v) || is_bool($v) || $v === null) {\n\t\t\t\treturn base64_encode((string) $v);\n\t\t\t}\n\t\t\tif (is_object($v) && method_exists($v, '__toString')) {\n\t\t\t\treturn base64_encode((string) $v);\n\t\t\t}\n\t\t\tthrow new TypeError(\n\t\t\t\tsprintf(\n\t\t\t\t\t'%s(): Argument #%d ($%s) must be of type string, %s given',\n\t\t\t\t\t$fn,\n\t\t\t\t\t$at + 1,\n\t\t\t\t\t$name,\n\t\t\t\t\tget_debug_type($v),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * An int argument as the decimal string the host reads.\n\t\t *\n\t\t * @param string $fn\n\t\t * The function name, for the message.\n\t\t * @param int $at\n\t\t * The argument's zero-based position.\n\t\t * @param string $name\n\t\t * The parameter name.\n\t\t * @param mixed $v\n\t\t * What the caller passed.\n\t\t */\n\t\tfunction cfw_sodium_int($fn, $at, $name, $v): string\n\t\t{\n\t\t\tif (is_int($v)) {\n\t\t\t\treturn (string) $v;\n\t\t\t}\n\t\t\tif (is_bool($v) || $v === null) {\n\t\t\t\treturn (string) (int) $v;\n\t\t\t}\n\t\t\tif (is_float($v) && is_finite($v) && floor($v) === $v) {\n\t\t\t\treturn (string) (int) $v;\n\t\t\t}\n\t\t\tif (is_string($v) && is_numeric($v) && (string) (int) $v === trim($v)) {\n\t\t\t\treturn (string) (int) $v;\n\t\t\t}\n\t\t\tthrow new TypeError(\n\t\t\t\tsprintf(\n\t\t\t\t\t'%s(): Argument #%d ($%s) must be of type int, %s given',\n\t\t\t\t\t$fn,\n\t\t\t\t\t$at + 1,\n\t\t\t\t\t$name,\n\t\t\t\t\tget_debug_type($v),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * A by-reference state argument; anything but a string is not a state.\n\t\t *\n\t\t * @param string $fn\n\t\t * The function name, for the message.\n\t\t * @param int $at\n\t\t * The argument's zero-based position.\n\t\t * @param string $name\n\t\t * The parameter name.\n\t\t * @param mixed $v\n\t\t * What the caller passed.\n\t\t */\n\t\tfunction cfw_sodium_ref($fn, $at, $name, $v): string\n\t\t{\n\t\t\tif (!is_string($v)) {\n\t\t\t\tcfw_sodium_fail(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t'%s(): Argument #%d ($%s) must be a reference to a state',\n\t\t\t\t\t\t$fn,\n\t\t\t\t\t\t$at + 1,\n\t\t\t\t\t\t$name,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn base64_encode($v);\n\t\t}\n\n\t\t/**\n\t\t * Reads one tagged value out of a reply.\n\t\t *\n\t\t * @param array<string, mixed> $v\n\t\t * The tagged value.\n\t\t */\n\t\tfunction cfw_sodium_dec($v)\n\t\t{\n\t\t\tif (array_key_exists('s', $v)) {\n\t\t\t\t$out = base64_decode((string) $v['s'], true);\n\t\t\t\tif ($out === false) {\n\t\t\t\t\tcfw_sodium_fail('reply was not base64');\n\t\t\t\t}\n\t\t\t\treturn $out;\n\t\t\t}\n\t\t\tif (array_key_exists('b', $v)) {\n\t\t\t\treturn (bool) $v['b'];\n\t\t\t}\n\t\t\tif (array_key_exists('i', $v)) {\n\t\t\t\treturn (int) $v['i'];\n\t\t\t}\n\t\t\tif (array_key_exists('l', $v)) {\n\t\t\t\treturn array_map('cfw_sodium_dec', $v['l']);\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\n\t\t/**\n\t\t * One call over the bridge.\n\t\t *\n\t\t * @param string $fn\n\t\t * The sodium function.\n\t\t * @param array<int, string> $args\n\t\t * Its arguments, already base64 or decimal.\n\t\t *\n\t\t * @return array<string, mixed>\n\t\t * The successful reply.\n\t\t */\n\t\tfunction cfw_sodium_exchange($fn, array $args): array\n\t\t{\n\t\t\t$bridge = $GLOBALS['__cfw_sodium'];\n\t\t\t$reply = json_decode($bridge(json_encode(['f' => $fn, 'a' => $args])), true);\n\t\t\tif (!is_array($reply)) {\n\t\t\t\tcfw_sodium_fail('unreadable reply');\n\t\t\t}\n\t\t\tif (($reply['ok'] ?? false) !== true) {\n\t\t\t\t$why = (string) ($reply['m'] ?? 'no reason given');\n\t\t\t\tswitch ($reply['c'] ?? '') {\n\t\t\t\t\tcase 'TypeError':\n\t\t\t\t\t\tthrow new TypeError($why);\n\n\t\t\t\t\tcase 'ValueError':\n\t\t\t\t\t\tthrow new ValueError($why);\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new SodiumException($why);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn $reply;\n\t\t}\n\n\t\t/**\n\t\t * Runs one wrapper's call: coerces each argument by its declared kind, crosses the bridge,\n\t\t * and writes back any by-reference state.\n\t\t *\n\t\t * @param string $fn\n\t\t * The sodium function, from __FUNCTION__.\n\t\t * @param array<int, mixed> $args\n\t\t * The wrapper's arguments, by reference where the function takes a state.\n\t\t */\n\t\tfunction cfw_sodium_go($fn, array $args)\n\t\t{\n\t\t\t[$kinds, $names] = $GLOBALS['__cfw_sodium_sig'][$fn];\n\t\t\t$names = explode(',', $names);\n\t\t\t$wire = [];\n\t\t\tforeach ($args as $at => $v) {\n\t\t\t\t$kind = $kinds[$at];\n\t\t\t\t$wire[] =\n\t\t\t\t\t$kind === 'i'\n\t\t\t\t\t\t? cfw_sodium_int($fn, $at, $names[$at], $v)\n\t\t\t\t\t\t: ($kind === 'r'\n\t\t\t\t\t\t\t? cfw_sodium_ref($fn, $at, $names[$at], $v)\n\t\t\t\t\t\t\t: cfw_sodium_str($fn, $at, $names[$at], $v));\n\t\t\t}\n\t\t\t$reply = cfw_sodium_exchange($fn, $wire);\n\t\t\tforeach ($reply['refs'] ?? [] as $at => $value) {\n\t\t\t\t$args[(int) $at] = $value === null ? null : base64_decode((string) $value, true);\n\t\t\t}\n\t\t\treturn cfw_sodium_dec($reply['r']);\n\t\t}\n\n\t\t/**\n\t\t * The message for a by-reference argument that is not a string.\n\t\t *\n\t\t * @param mixed $v\n\t\t * The argument.\n\t\t */\n\t\tfunction cfw_sodium_string_ref($v): string\n\t\t{\n\t\t\tif (!is_string($v)) {\n\t\t\t\tcfw_sodium_fail('a PHP string is required');\n\t\t\t}\n\t\t\treturn $v;\n\t\t}\n\n\t\t/**\n\t\t * Two same-length arguments, or the refusal ext-sodium gives.\n\t\t *\n\t\t * @param string $fn\n\t\t * The function name.\n\t\t * @param string $a\n\t\t * The first string.\n\t\t * @param string $b\n\t\t * The second string.\n\t\t */\n\t\tfunction cfw_sodium_same_length($fn, $a, $b): void\n\t\t{\n\t\t\tif (strlen($a) !== strlen($b)) {\n\t\t\t\tcfw_sodium_fail(\n\t\t\t\t\t$fn .\n\t\t\t\t\t\t'(): Argument #1 ($string1) and argument #2 ($string_2) must have the same length',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// #region the functions that need no host\n\n\t\tfunction sodium_bin2hex(#[\\SensitiveParameter] $string)\n\t\t{\n\t\t\treturn bin2hex(cfw_sodium_arg('sodium_bin2hex', 0, 'string', $string));\n\t\t}\n\n\t\t/**\n\t\t * A string argument, coerced.\n\t\t *\n\t\t * @param string $fn\n\t\t * The function name.\n\t\t * @param int $at\n\t\t * The argument's zero-based position.\n\t\t * @param string $name\n\t\t * The parameter name.\n\t\t * @param mixed $v\n\t\t * The argument.\n\t\t */\n\t\tfunction cfw_sodium_arg($fn, $at, $name, $v): string\n\t\t{\n\t\t\treturn base64_decode(cfw_sodium_str($fn, $at, $name, $v), true);\n\t\t}\n\n\t\tfunction sodium_hex2bin(#[\\SensitiveParameter] $string, $ignore = '')\n\t\t{\n\t\t\t$fn = 'sodium_hex2bin';\n\t\t\t$string = cfw_sodium_arg($fn, 0, 'string', $string);\n\t\t\t$ignore = cfw_sodium_arg($fn, 1, 'ignore', $ignore);\n\t\t\t$out = '';\n\t\t\t$high = null;\n\t\t\tfor ($i = 0, $n = strlen($string); $i < $n; $i++) {\n\t\t\t\t$c = $string[$i];\n\t\t\t\tif (ctype_xdigit($c)) {\n\t\t\t\t\t$v = hexdec($c);\n\t\t\t\t\tif ($high === null) {\n\t\t\t\t\t\t$high = $v;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$out .= chr(($high << 4) | $v);\n\t\t\t\t\t\t$high = null;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif ($high === null && $ignore !== '' && strpos($ignore, $c) !== false) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t$high = 0;\n\t\t\t\t$i = $n + 1;\n\t\t\t}\n\t\t\tif ($high !== null) {\n\t\t\t\tcfw_sodium_fail(\n\t\t\t\t\t$fn . '(): Argument #1 ($string) must be a valid hexadecimal string',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn $out;\n\t\t}\n\n\t\t/**\n\t\t * The base64 variant flags: padded, URL-safe.\n\t\t *\n\t\t * @param string $fn\n\t\t * The function name.\n\t\t * @param mixed $id\n\t\t * The caller's variant.\n\t\t *\n\t\t * @return array{0: bool, 1: bool}\n\t\t */\n\t\tfunction cfw_sodium_variant($fn, $id): array\n\t\t{\n\t\t\t$id = (int) cfw_sodium_int($fn, 1, 'id', $id);\n\t\t\tif ($id !== 1 && $id !== 3 && $id !== 5 && $id !== 7) {\n\t\t\t\tcfw_sodium_fail(\n\t\t\t\t\t$fn . '(): Argument #2 ($id) must be a valid base64 variant identifier',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [($id & 2) === 0, ($id & 4) !== 0];\n\t\t}\n\n\t\tfunction sodium_bin2base64(#[\\SensitiveParameter] $string, $id)\n\t\t{\n\t\t\t$fn = 'sodium_bin2base64';\n\t\t\t$string = cfw_sodium_arg($fn, 0, 'string', $string);\n\t\t\t[$padded, $urlsafe] = cfw_sodium_variant($fn, $id);\n\t\t\t$out = base64_encode($string);\n\t\t\tif ($urlsafe) {\n\t\t\t\t$out = strtr($out, '+/', '-_');\n\t\t\t}\n\t\t\treturn $padded ? $out : rtrim($out, '=');\n\t\t}\n\n\t\tfunction sodium_base642bin(#[\\SensitiveParameter] $string, $id, $ignore = '')\n\t\t{\n\t\t\t$fn = 'sodium_base642bin';\n\t\t\t$string = cfw_sodium_arg($fn, 0, 'string', $string);\n\t\t\t[$padded, $urlsafe] = cfw_sodium_variant($fn, $id);\n\t\t\t$ignore = cfw_sodium_arg($fn, 2, 'ignore', $ignore);\n\t\t\t$alphabet =\n\t\t\t\t'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' .\n\t\t\t\t($urlsafe ? '-_' : '+/');\n\t\t\t$bad = $fn . '(): Argument #1 ($string) must be a valid base64 string';\n\t\t\t$out = '';\n\t\t\t$acc = 0;\n\t\t\t$bits = 0;\n\t\t\t$i = 0;\n\t\t\t$n = strlen($string);\n\t\t\tfor (; $i < $n; $i++) {\n\t\t\t\t$d = strpos($alphabet, $string[$i]);\n\t\t\t\tif ($d === false) {\n\t\t\t\t\tif ($ignore !== '' && strpos($ignore, $string[$i]) !== false) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t$acc = (($acc << 6) | $d) & 0xffff;\n\t\t\t\t$bits += 6;\n\t\t\t\tif ($bits >= 8) {\n\t\t\t\t\t$bits -= 8;\n\t\t\t\t\t$out .= chr(($acc >> $bits) & 0xff);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ($bits > 4 || ($acc & ((1 << $bits) - 1)) !== 0) {\n\t\t\t\tcfw_sodium_fail($bad);\n\t\t\t}\n\t\t\tif ($padded && $bits !== 0) {\n\t\t\t\t$want = intdiv($bits, 2);\n\t\t\t\tfor (; $i < $n; $i++) {\n\t\t\t\t\tif ($string[$i] === '=' && $want > 0) {\n\t\t\t\t\t\t$want--;\n\t\t\t\t\t} elseif ($ignore === '' || strpos($ignore, $string[$i]) === false) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ($want !== 0) {\n\t\t\t\t\tcfw_sodium_fail($bad);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ($i < $n) {\n\t\t\t\tcfw_sodium_fail($bad);\n\t\t\t}\n\t\t\treturn $out;\n\t\t}\n\n\t\tfunction sodium_pad(#[\\SensitiveParameter] $string, $block_size)\n\t\t{\n\t\t\t$fn = 'sodium_pad';\n\t\t\t$string = cfw_sodium_arg($fn, 0, 'string', $string);\n\t\t\t$size = (int) cfw_sodium_int($fn, 1, 'block_size', $block_size);\n\t\t\tif ($size <= 0) {\n\t\t\t\tcfw_sodium_fail($fn . '(): Argument #2 ($block_size) must be greater than 0');\n\t\t\t}\n\t\t\t$extra = $size - 1 - (strlen($string) % $size);\n\t\t\treturn $string . \"\\x80\" . str_repeat(\"\\0\", $extra);\n\t\t}\n\n\t\tfunction sodium_unpad(#[\\SensitiveParameter] $string, $block_size)\n\t\t{\n\t\t\t$fn = 'sodium_unpad';\n\t\t\t$string = cfw_sodium_arg($fn, 0, 'string', $string);\n\t\t\t$size = (int) cfw_sodium_int($fn, 1, 'block_size', $block_size);\n\t\t\tif ($size <= 0) {\n\t\t\t\tcfw_sodium_fail($fn . '(): Argument #2 ($block_size) must be greater than 0');\n\t\t\t}\n\t\t\t$len = strlen($string);\n\t\t\tif ($len < $size) {\n\t\t\t\tcfw_sodium_fail(\n\t\t\t\t\t$fn . '(): Argument #1 ($string) must be at least as long as the block size',\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor ($i = 0; $i < $size; $i++) {\n\t\t\t\t$c = ord($string[$len - 1 - $i]);\n\t\t\t\tif ($c === 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif ($c === 0x80) {\n\t\t\t\t\treturn substr($string, 0, $len - 1 - $i);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcfw_sodium_fail('invalid padding');\n\t\t}\n\n\t\tfunction sodium_memzero(#[\\SensitiveParameter] &$string)\n\t\t{\n\t\t\tcfw_sodium_string_ref($string);\n\t\t\t$string = null;\n\t\t}\n\n\t\tfunction sodium_memcmp(#[\\SensitiveParameter] $string1, #[\\SensitiveParameter] $string2)\n\t\t{\n\t\t\t$fn = 'sodium_memcmp';\n\t\t\t$a = cfw_sodium_arg($fn, 0, 'string1', $string1);\n\t\t\t$b = cfw_sodium_arg($fn, 1, 'string2', $string2);\n\t\t\tcfw_sodium_same_length($fn, $a, $b);\n\t\t\treturn hash_equals($a, $b) ? 0 : -1;\n\t\t}\n\n\t\tfunction sodium_compare(#[\\SensitiveParameter] $string1, #[\\SensitiveParameter] $string2)\n\t\t{\n\t\t\t$fn = 'sodium_compare';\n\t\t\t$a = cfw_sodium_arg($fn, 0, 'string1', $string1);\n\t\t\t$b = cfw_sodium_arg($fn, 1, 'string2', $string2);\n\t\t\tcfw_sodium_same_length($fn, $a, $b);\n\t\t\tfor ($i = strlen($a) - 1; $i >= 0; $i--) {\n\t\t\t\tif ($a[$i] !== $b[$i]) {\n\t\t\t\t\treturn ord($a[$i]) < ord($b[$i]) ? -1 : 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\n\t\tfunction sodium_increment(&$string)\n\t\t{\n\t\t\t$s = cfw_sodium_string_ref($string);\n\t\t\tfor ($i = 0, $n = strlen($s); $i < $n; $i++) {\n\t\t\t\t$v = (ord($s[$i]) + 1) & 0xff;\n\t\t\t\t$s[$i] = chr($v);\n\t\t\t\tif ($v !== 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t$string = $s;\n\t\t}\n\n\t\tfunction sodium_add(&$string1, $string2)\n\t\t{\n\t\t\t$fn = 'sodium_add';\n\t\t\tif (!is_string($string1)) {\n\t\t\t\tcfw_sodium_fail('PHP strings are required');\n\t\t\t}\n\t\t\t$a = $string1;\n\t\t\t$b = cfw_sodium_arg($fn, 1, 'string2', $string2);\n\t\t\tcfw_sodium_same_length($fn, $a, $b);\n\t\t\t$carry = 0;\n\t\t\tfor ($i = 0, $n = strlen($a); $i < $n; $i++) {\n\t\t\t\t$sum = ord($a[$i]) + ord($b[$i]) + $carry;\n\t\t\t\t$a[$i] = chr($sum & 0xff);\n\t\t\t\t$carry = $sum >> 8;\n\t\t\t}\n\t\t\t$string1 = $a;\n\t\t}\n\n\t\t// #endregion\n\n\t\t// __CFW_SODIUM_SIGNATURES__\n\n\t\t// __CFW_SODIUM_FUNCTIONS__\n\t}\n}\n"