Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu.../sodium_c.../src
File: Compat.php
* @psalm-suppress MixedArgument
[1500] Fix | Delete
*/
[1501] Fix | Delete
public static function crypto_generichash_init($key = '', $length = self::CRYPTO_GENERICHASH_BYTES)
[1502] Fix | Delete
{
[1503] Fix | Delete
/* Type checks: */
[1504] Fix | Delete
if (is_null($key)) {
[1505] Fix | Delete
$key = '';
[1506] Fix | Delete
}
[1507] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 1);
[1508] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 2);
[1509] Fix | Delete
[1510] Fix | Delete
/* Input validation: */
[1511] Fix | Delete
if (!empty($key)) {
[1512] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) < self::CRYPTO_GENERICHASH_KEYBYTES_MIN) {
[1513] Fix | Delete
throw new SodiumException('Unsupported key size. Must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes long.');
[1514] Fix | Delete
}
[1515] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) > self::CRYPTO_GENERICHASH_KEYBYTES_MAX) {
[1516] Fix | Delete
throw new SodiumException('Unsupported key size. Must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes long.');
[1517] Fix | Delete
}
[1518] Fix | Delete
}
[1519] Fix | Delete
[1520] Fix | Delete
if (self::useNewSodiumAPI()) {
[1521] Fix | Delete
return sodium_crypto_generichash_init($key, $length);
[1522] Fix | Delete
}
[1523] Fix | Delete
if (self::use_fallback('crypto_generichash_init')) {
[1524] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_generichash_init', $key, $length);
[1525] Fix | Delete
}
[1526] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1527] Fix | Delete
return ParagonIE_Sodium_Crypto32::generichash_init($key, $length);
[1528] Fix | Delete
}
[1529] Fix | Delete
return ParagonIE_Sodium_Crypto::generichash_init($key, $length);
[1530] Fix | Delete
}
[1531] Fix | Delete
[1532] Fix | Delete
/**
[1533] Fix | Delete
* Initialize a BLAKE2b hashing context, for use in a streaming interface.
[1534] Fix | Delete
*
[1535] Fix | Delete
* @param string|null $key If specified must be a string between 16 and 64 bytes
[1536] Fix | Delete
* @param int $length The size of the desired hash output
[1537] Fix | Delete
* @param string $salt Salt (up to 16 bytes)
[1538] Fix | Delete
* @param string $personal Personalization string (up to 16 bytes)
[1539] Fix | Delete
* @return string A BLAKE2 hashing context, encoded as a string
[1540] Fix | Delete
* (To be 100% compatible with ext/libsodium)
[1541] Fix | Delete
* @throws SodiumException
[1542] Fix | Delete
* @throws TypeError
[1543] Fix | Delete
* @psalm-suppress MixedArgument
[1544] Fix | Delete
*/
[1545] Fix | Delete
public static function crypto_generichash_init_salt_personal(
[1546] Fix | Delete
$key = '',
[1547] Fix | Delete
$length = self::CRYPTO_GENERICHASH_BYTES,
[1548] Fix | Delete
$salt = '',
[1549] Fix | Delete
$personal = ''
[1550] Fix | Delete
) {
[1551] Fix | Delete
/* Type checks: */
[1552] Fix | Delete
if (is_null($key)) {
[1553] Fix | Delete
$key = '';
[1554] Fix | Delete
}
[1555] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 1);
[1556] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 2);
[1557] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($salt, 'string', 3);
[1558] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($personal, 'string', 4);
[1559] Fix | Delete
$salt = str_pad($salt, 16, "\0", STR_PAD_RIGHT);
[1560] Fix | Delete
$personal = str_pad($personal, 16, "\0", STR_PAD_RIGHT);
[1561] Fix | Delete
[1562] Fix | Delete
/* Input validation: */
[1563] Fix | Delete
if (!empty($key)) {
[1564] Fix | Delete
/*
[1565] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) < self::CRYPTO_GENERICHASH_KEYBYTES_MIN) {
[1566] Fix | Delete
throw new SodiumException('Unsupported key size. Must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes long.');
[1567] Fix | Delete
}
[1568] Fix | Delete
*/
[1569] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) > self::CRYPTO_GENERICHASH_KEYBYTES_MAX) {
[1570] Fix | Delete
throw new SodiumException('Unsupported key size. Must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes long.');
[1571] Fix | Delete
}
[1572] Fix | Delete
}
[1573] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1574] Fix | Delete
return ParagonIE_Sodium_Crypto32::generichash_init_salt_personal($key, $length, $salt, $personal);
[1575] Fix | Delete
}
[1576] Fix | Delete
return ParagonIE_Sodium_Crypto::generichash_init_salt_personal($key, $length, $salt, $personal);
[1577] Fix | Delete
}
[1578] Fix | Delete
[1579] Fix | Delete
/**
[1580] Fix | Delete
* Update a BLAKE2b hashing context with additional data.
[1581] Fix | Delete
*
[1582] Fix | Delete
* @param string $ctx BLAKE2 hashing context. Generated by crypto_generichash_init().
[1583] Fix | Delete
* $ctx is passed by reference and gets updated in-place.
[1584] Fix | Delete
* @param-out string $ctx
[1585] Fix | Delete
* @param string $message The message to append to the existing hash state.
[1586] Fix | Delete
* @return void
[1587] Fix | Delete
* @throws SodiumException
[1588] Fix | Delete
* @throws TypeError
[1589] Fix | Delete
* @psalm-suppress MixedArgument
[1590] Fix | Delete
* @psalm-suppress ReferenceConstraintViolation
[1591] Fix | Delete
*/
[1592] Fix | Delete
public static function crypto_generichash_update(&$ctx, $message)
[1593] Fix | Delete
{
[1594] Fix | Delete
/* Type checks: */
[1595] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($ctx, 'string', 1);
[1596] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 2);
[1597] Fix | Delete
[1598] Fix | Delete
if (self::useNewSodiumAPI()) {
[1599] Fix | Delete
sodium_crypto_generichash_update($ctx, $message);
[1600] Fix | Delete
return;
[1601] Fix | Delete
}
[1602] Fix | Delete
if (self::use_fallback('crypto_generichash_update')) {
[1603] Fix | Delete
$func = '\\Sodium\\crypto_generichash_update';
[1604] Fix | Delete
$func($ctx, $message);
[1605] Fix | Delete
return;
[1606] Fix | Delete
}
[1607] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1608] Fix | Delete
$ctx = ParagonIE_Sodium_Crypto32::generichash_update($ctx, $message);
[1609] Fix | Delete
} else {
[1610] Fix | Delete
$ctx = ParagonIE_Sodium_Crypto::generichash_update($ctx, $message);
[1611] Fix | Delete
}
[1612] Fix | Delete
}
[1613] Fix | Delete
[1614] Fix | Delete
/**
[1615] Fix | Delete
* @return string
[1616] Fix | Delete
* @throws Exception
[1617] Fix | Delete
* @throws Error
[1618] Fix | Delete
*/
[1619] Fix | Delete
public static function crypto_generichash_keygen()
[1620] Fix | Delete
{
[1621] Fix | Delete
return random_bytes(self::CRYPTO_GENERICHASH_KEYBYTES);
[1622] Fix | Delete
}
[1623] Fix | Delete
[1624] Fix | Delete
/**
[1625] Fix | Delete
* @param int $subkey_len
[1626] Fix | Delete
* @param int $subkey_id
[1627] Fix | Delete
* @param string $context
[1628] Fix | Delete
* @param string $key
[1629] Fix | Delete
* @return string
[1630] Fix | Delete
* @throws SodiumException
[1631] Fix | Delete
*/
[1632] Fix | Delete
public static function crypto_kdf_derive_from_key(
[1633] Fix | Delete
$subkey_len,
[1634] Fix | Delete
$subkey_id,
[1635] Fix | Delete
$context,
[1636] Fix | Delete
$key
[1637] Fix | Delete
) {
[1638] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($subkey_len, 'int', 1);
[1639] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($subkey_id, 'int', 2);
[1640] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($context, 'string', 3);
[1641] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 4);
[1642] Fix | Delete
$subkey_id = (int) $subkey_id;
[1643] Fix | Delete
$subkey_len = (int) $subkey_len;
[1644] Fix | Delete
$context = (string) $context;
[1645] Fix | Delete
$key = (string) $key;
[1646] Fix | Delete
[1647] Fix | Delete
if ($subkey_len < self::CRYPTO_KDF_BYTES_MIN) {
[1648] Fix | Delete
throw new SodiumException('subkey cannot be smaller than SODIUM_CRYPTO_KDF_BYTES_MIN');
[1649] Fix | Delete
}
[1650] Fix | Delete
if ($subkey_len > self::CRYPTO_KDF_BYTES_MAX) {
[1651] Fix | Delete
throw new SodiumException('subkey cannot be larger than SODIUM_CRYPTO_KDF_BYTES_MAX');
[1652] Fix | Delete
}
[1653] Fix | Delete
if ($subkey_id < 0) {
[1654] Fix | Delete
throw new SodiumException('subkey_id cannot be negative');
[1655] Fix | Delete
}
[1656] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($context) !== self::CRYPTO_KDF_CONTEXTBYTES) {
[1657] Fix | Delete
throw new SodiumException('context should be SODIUM_CRYPTO_KDF_CONTEXTBYTES bytes');
[1658] Fix | Delete
}
[1659] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_KDF_KEYBYTES) {
[1660] Fix | Delete
throw new SodiumException('key should be SODIUM_CRYPTO_KDF_KEYBYTES bytes');
[1661] Fix | Delete
}
[1662] Fix | Delete
[1663] Fix | Delete
$salt = ParagonIE_Sodium_Core_Util::store64_le($subkey_id);
[1664] Fix | Delete
$state = self::crypto_generichash_init_salt_personal(
[1665] Fix | Delete
$key,
[1666] Fix | Delete
$subkey_len,
[1667] Fix | Delete
$salt,
[1668] Fix | Delete
$context
[1669] Fix | Delete
);
[1670] Fix | Delete
return self::crypto_generichash_final($state, $subkey_len);
[1671] Fix | Delete
}
[1672] Fix | Delete
[1673] Fix | Delete
/**
[1674] Fix | Delete
* @return string
[1675] Fix | Delete
* @throws Exception
[1676] Fix | Delete
* @throws Error
[1677] Fix | Delete
*/
[1678] Fix | Delete
public static function crypto_kdf_keygen()
[1679] Fix | Delete
{
[1680] Fix | Delete
return random_bytes(self::CRYPTO_KDF_KEYBYTES);
[1681] Fix | Delete
}
[1682] Fix | Delete
[1683] Fix | Delete
/**
[1684] Fix | Delete
* Perform a key exchange, between a designated client and a server.
[1685] Fix | Delete
*
[1686] Fix | Delete
* Typically, you would designate one machine to be the client and the
[1687] Fix | Delete
* other to be the server. The first two keys are what you'd expect for
[1688] Fix | Delete
* scalarmult() below, but the latter two public keys don't swap places.
[1689] Fix | Delete
*
[1690] Fix | Delete
* | ALICE | BOB |
[1691] Fix | Delete
* | Client | Server |
[1692] Fix | Delete
* |--------------------------------|-------------------------------------|
[1693] Fix | Delete
* | shared = crypto_kx( | shared = crypto_kx( |
[1694] Fix | Delete
* | alice_sk, | bob_sk, | <- contextual
[1695] Fix | Delete
* | bob_pk, | alice_pk, | <- contextual
[1696] Fix | Delete
* | alice_pk, | alice_pk, | <----- static
[1697] Fix | Delete
* | bob_pk | bob_pk | <----- static
[1698] Fix | Delete
* | ) | ) |
[1699] Fix | Delete
*
[1700] Fix | Delete
* They are used along with the scalarmult product to generate a 256-bit
[1701] Fix | Delete
* BLAKE2b hash unique to the client and server keys.
[1702] Fix | Delete
*
[1703] Fix | Delete
* @param string $my_secret
[1704] Fix | Delete
* @param string $their_public
[1705] Fix | Delete
* @param string $client_public
[1706] Fix | Delete
* @param string $server_public
[1707] Fix | Delete
* @param bool $dontFallback
[1708] Fix | Delete
* @return string
[1709] Fix | Delete
* @throws SodiumException
[1710] Fix | Delete
* @throws TypeError
[1711] Fix | Delete
* @psalm-suppress MixedArgument
[1712] Fix | Delete
*/
[1713] Fix | Delete
public static function crypto_kx($my_secret, $their_public, $client_public, $server_public, $dontFallback = false)
[1714] Fix | Delete
{
[1715] Fix | Delete
/* Type checks: */
[1716] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($my_secret, 'string', 1);
[1717] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($their_public, 'string', 2);
[1718] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($client_public, 'string', 3);
[1719] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($server_public, 'string', 4);
[1720] Fix | Delete
[1721] Fix | Delete
/* Input validation: */
[1722] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($my_secret) !== self::CRYPTO_BOX_SECRETKEYBYTES) {
[1723] Fix | Delete
throw new SodiumException('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.');
[1724] Fix | Delete
}
[1725] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($their_public) !== self::CRYPTO_BOX_PUBLICKEYBYTES) {
[1726] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.');
[1727] Fix | Delete
}
[1728] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($client_public) !== self::CRYPTO_BOX_PUBLICKEYBYTES) {
[1729] Fix | Delete
throw new SodiumException('Argument 3 must be CRYPTO_BOX_PUBLICKEYBYTES long.');
[1730] Fix | Delete
}
[1731] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($server_public) !== self::CRYPTO_BOX_PUBLICKEYBYTES) {
[1732] Fix | Delete
throw new SodiumException('Argument 4 must be CRYPTO_BOX_PUBLICKEYBYTES long.');
[1733] Fix | Delete
}
[1734] Fix | Delete
[1735] Fix | Delete
if (self::useNewSodiumAPI() && !$dontFallback) {
[1736] Fix | Delete
if (is_callable('sodium_crypto_kx')) {
[1737] Fix | Delete
return (string) sodium_crypto_kx(
[1738] Fix | Delete
$my_secret,
[1739] Fix | Delete
$their_public,
[1740] Fix | Delete
$client_public,
[1741] Fix | Delete
$server_public
[1742] Fix | Delete
);
[1743] Fix | Delete
}
[1744] Fix | Delete
}
[1745] Fix | Delete
if (self::use_fallback('crypto_kx')) {
[1746] Fix | Delete
return (string) call_user_func(
[1747] Fix | Delete
'\\Sodium\\crypto_kx',
[1748] Fix | Delete
$my_secret,
[1749] Fix | Delete
$their_public,
[1750] Fix | Delete
$client_public,
[1751] Fix | Delete
$server_public
[1752] Fix | Delete
);
[1753] Fix | Delete
}
[1754] Fix | Delete
if (PHP_INT_SIZE === 4) {
[1755] Fix | Delete
return ParagonIE_Sodium_Crypto32::keyExchange(
[1756] Fix | Delete
$my_secret,
[1757] Fix | Delete
$their_public,
[1758] Fix | Delete
$client_public,
[1759] Fix | Delete
$server_public
[1760] Fix | Delete
);
[1761] Fix | Delete
}
[1762] Fix | Delete
return ParagonIE_Sodium_Crypto::keyExchange(
[1763] Fix | Delete
$my_secret,
[1764] Fix | Delete
$their_public,
[1765] Fix | Delete
$client_public,
[1766] Fix | Delete
$server_public
[1767] Fix | Delete
);
[1768] Fix | Delete
}
[1769] Fix | Delete
[1770] Fix | Delete
/**
[1771] Fix | Delete
* @param string $seed
[1772] Fix | Delete
* @return string
[1773] Fix | Delete
* @throws SodiumException
[1774] Fix | Delete
*/
[1775] Fix | Delete
public static function crypto_kx_seed_keypair($seed)
[1776] Fix | Delete
{
[1777] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($seed, 'string', 1);
[1778] Fix | Delete
[1779] Fix | Delete
$seed = (string) $seed;
[1780] Fix | Delete
[1781] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($seed) !== self::CRYPTO_KX_SEEDBYTES) {
[1782] Fix | Delete
throw new SodiumException('seed must be SODIUM_CRYPTO_KX_SEEDBYTES bytes');
[1783] Fix | Delete
}
[1784] Fix | Delete
[1785] Fix | Delete
$sk = self::crypto_generichash($seed, '', self::CRYPTO_KX_SECRETKEYBYTES);
[1786] Fix | Delete
$pk = self::crypto_scalarmult_base($sk);
[1787] Fix | Delete
return $sk . $pk;
[1788] Fix | Delete
}
[1789] Fix | Delete
[1790] Fix | Delete
/**
[1791] Fix | Delete
* @return string
[1792] Fix | Delete
* @throws Exception
[1793] Fix | Delete
*/
[1794] Fix | Delete
public static function crypto_kx_keypair()
[1795] Fix | Delete
{
[1796] Fix | Delete
$sk = self::randombytes_buf(self::CRYPTO_KX_SECRETKEYBYTES);
[1797] Fix | Delete
$pk = self::crypto_scalarmult_base($sk);
[1798] Fix | Delete
return $sk . $pk;
[1799] Fix | Delete
}
[1800] Fix | Delete
[1801] Fix | Delete
/**
[1802] Fix | Delete
* @param string $keypair
[1803] Fix | Delete
* @param string $serverPublicKey
[1804] Fix | Delete
* @return array{0: string, 1: string}
[1805] Fix | Delete
* @throws SodiumException
[1806] Fix | Delete
*/
[1807] Fix | Delete
public static function crypto_kx_client_session_keys($keypair, $serverPublicKey)
[1808] Fix | Delete
{
[1809] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 1);
[1810] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($serverPublicKey, 'string', 2);
[1811] Fix | Delete
[1812] Fix | Delete
$keypair = (string) $keypair;
[1813] Fix | Delete
$serverPublicKey = (string) $serverPublicKey;
[1814] Fix | Delete
[1815] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_KX_KEYPAIRBYTES) {
[1816] Fix | Delete
throw new SodiumException('keypair should be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes');
[1817] Fix | Delete
}
[1818] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($serverPublicKey) !== self::CRYPTO_KX_PUBLICKEYBYTES) {
[1819] Fix | Delete
throw new SodiumException('public keys must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes');
[1820] Fix | Delete
}
[1821] Fix | Delete
[1822] Fix | Delete
$sk = self::crypto_kx_secretkey($keypair);
[1823] Fix | Delete
$pk = self::crypto_kx_publickey($keypair);
[1824] Fix | Delete
$h = self::crypto_generichash_init(null, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
[1825] Fix | Delete
self::crypto_generichash_update($h, self::crypto_scalarmult($sk, $serverPublicKey));
[1826] Fix | Delete
self::crypto_generichash_update($h, $pk);
[1827] Fix | Delete
self::crypto_generichash_update($h, $serverPublicKey);
[1828] Fix | Delete
$sessionKeys = self::crypto_generichash_final($h, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
[1829] Fix | Delete
return array(
[1830] Fix | Delete
ParagonIE_Sodium_Core_Util::substr(
[1831] Fix | Delete
$sessionKeys,
[1832] Fix | Delete
0,
[1833] Fix | Delete
self::CRYPTO_KX_SESSIONKEYBYTES
[1834] Fix | Delete
),
[1835] Fix | Delete
ParagonIE_Sodium_Core_Util::substr(
[1836] Fix | Delete
$sessionKeys,
[1837] Fix | Delete
self::CRYPTO_KX_SESSIONKEYBYTES,
[1838] Fix | Delete
self::CRYPTO_KX_SESSIONKEYBYTES
[1839] Fix | Delete
)
[1840] Fix | Delete
);
[1841] Fix | Delete
}
[1842] Fix | Delete
[1843] Fix | Delete
/**
[1844] Fix | Delete
* @param string $keypair
[1845] Fix | Delete
* @param string $clientPublicKey
[1846] Fix | Delete
* @return array{0: string, 1: string}
[1847] Fix | Delete
* @throws SodiumException
[1848] Fix | Delete
*/
[1849] Fix | Delete
public static function crypto_kx_server_session_keys($keypair, $clientPublicKey)
[1850] Fix | Delete
{
[1851] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 1);
[1852] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($clientPublicKey, 'string', 2);
[1853] Fix | Delete
[1854] Fix | Delete
$keypair = (string) $keypair;
[1855] Fix | Delete
$clientPublicKey = (string) $clientPublicKey;
[1856] Fix | Delete
[1857] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_KX_KEYPAIRBYTES) {
[1858] Fix | Delete
throw new SodiumException('keypair should be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes');
[1859] Fix | Delete
}
[1860] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($clientPublicKey) !== self::CRYPTO_KX_PUBLICKEYBYTES) {
[1861] Fix | Delete
throw new SodiumException('public keys must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes');
[1862] Fix | Delete
}
[1863] Fix | Delete
[1864] Fix | Delete
$sk = self::crypto_kx_secretkey($keypair);
[1865] Fix | Delete
$pk = self::crypto_kx_publickey($keypair);
[1866] Fix | Delete
$h = self::crypto_generichash_init(null, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
[1867] Fix | Delete
self::crypto_generichash_update($h, self::crypto_scalarmult($sk, $clientPublicKey));
[1868] Fix | Delete
self::crypto_generichash_update($h, $clientPublicKey);
[1869] Fix | Delete
self::crypto_generichash_update($h, $pk);
[1870] Fix | Delete
$sessionKeys = self::crypto_generichash_final($h, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
[1871] Fix | Delete
return array(
[1872] Fix | Delete
ParagonIE_Sodium_Core_Util::substr(
[1873] Fix | Delete
$sessionKeys,
[1874] Fix | Delete
self::CRYPTO_KX_SESSIONKEYBYTES,
[1875] Fix | Delete
self::CRYPTO_KX_SESSIONKEYBYTES
[1876] Fix | Delete
),
[1877] Fix | Delete
ParagonIE_Sodium_Core_Util::substr(
[1878] Fix | Delete
$sessionKeys,
[1879] Fix | Delete
0,
[1880] Fix | Delete
self::CRYPTO_KX_SESSIONKEYBYTES
[1881] Fix | Delete
)
[1882] Fix | Delete
);
[1883] Fix | Delete
}
[1884] Fix | Delete
[1885] Fix | Delete
/**
[1886] Fix | Delete
* @param string $kp
[1887] Fix | Delete
* @return string
[1888] Fix | Delete
* @throws SodiumException
[1889] Fix | Delete
*/
[1890] Fix | Delete
public static function crypto_kx_secretkey($kp)
[1891] Fix | Delete
{
[1892] Fix | Delete
return ParagonIE_Sodium_Core_Util::substr(
[1893] Fix | Delete
$kp,
[1894] Fix | Delete
0,
[1895] Fix | Delete
self::CRYPTO_KX_SECRETKEYBYTES
[1896] Fix | Delete
);
[1897] Fix | Delete
}
[1898] Fix | Delete
[1899] Fix | Delete
/**
[1900] Fix | Delete
* @param string $kp
[1901] Fix | Delete
* @return string
[1902] Fix | Delete
* @throws SodiumException
[1903] Fix | Delete
*/
[1904] Fix | Delete
public static function crypto_kx_publickey($kp)
[1905] Fix | Delete
{
[1906] Fix | Delete
return ParagonIE_Sodium_Core_Util::substr(
[1907] Fix | Delete
$kp,
[1908] Fix | Delete
self::CRYPTO_KX_SECRETKEYBYTES,
[1909] Fix | Delete
self::CRYPTO_KX_PUBLICKEYBYTES
[1910] Fix | Delete
);
[1911] Fix | Delete
}
[1912] Fix | Delete
[1913] Fix | Delete
/**
[1914] Fix | Delete
* @param int $outlen
[1915] Fix | Delete
* @param string $passwd
[1916] Fix | Delete
* @param string $salt
[1917] Fix | Delete
* @param int $opslimit
[1918] Fix | Delete
* @param int $memlimit
[1919] Fix | Delete
* @param int|null $alg
[1920] Fix | Delete
* @return string
[1921] Fix | Delete
* @throws SodiumException
[1922] Fix | Delete
* @throws TypeError
[1923] Fix | Delete
* @psalm-suppress MixedArgument
[1924] Fix | Delete
*/
[1925] Fix | Delete
public static function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $alg = null)
[1926] Fix | Delete
{
[1927] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($outlen, 'int', 1);
[1928] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($passwd, 'string', 2);
[1929] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($salt, 'string', 3);
[1930] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($opslimit, 'int', 4);
[1931] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($memlimit, 'int', 5);
[1932] Fix | Delete
[1933] Fix | Delete
if (self::useNewSodiumAPI()) {
[1934] Fix | Delete
if (!is_null($alg)) {
[1935] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($alg, 'int', 6);
[1936] Fix | Delete
return sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $alg);
[1937] Fix | Delete
}
[1938] Fix | Delete
return sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit);
[1939] Fix | Delete
}
[1940] Fix | Delete
if (self::use_fallback('crypto_pwhash')) {
[1941] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_pwhash', $outlen, $passwd, $salt, $opslimit, $memlimit);
[1942] Fix | Delete
}
[1943] Fix | Delete
// This is the best we can do.
[1944] Fix | Delete
throw new SodiumException(
[1945] Fix | Delete
'This is not implemented, as it is not possible to implement Argon2i with acceptable performance in pure-PHP'
[1946] Fix | Delete
);
[1947] Fix | Delete
}
[1948] Fix | Delete
[1949] Fix | Delete
/**
[1950] Fix | Delete
* !Exclusive to sodium_compat!
[1951] Fix | Delete
*
[1952] Fix | Delete
* This returns TRUE if the native crypto_pwhash API is available by libsodium.
[1953] Fix | Delete
* This returns FALSE if only sodium_compat is available.
[1954] Fix | Delete
*
[1955] Fix | Delete
* @return bool
[1956] Fix | Delete
*/
[1957] Fix | Delete
public static function crypto_pwhash_is_available()
[1958] Fix | Delete
{
[1959] Fix | Delete
if (self::useNewSodiumAPI()) {
[1960] Fix | Delete
return true;
[1961] Fix | Delete
}
[1962] Fix | Delete
if (self::use_fallback('crypto_pwhash')) {
[1963] Fix | Delete
return true;
[1964] Fix | Delete
}
[1965] Fix | Delete
return false;
[1966] Fix | Delete
}
[1967] Fix | Delete
[1968] Fix | Delete
/**
[1969] Fix | Delete
* @param string $passwd
[1970] Fix | Delete
* @param int $opslimit
[1971] Fix | Delete
* @param int $memlimit
[1972] Fix | Delete
* @return string
[1973] Fix | Delete
* @throws SodiumException
[1974] Fix | Delete
* @throws TypeError
[1975] Fix | Delete
* @psalm-suppress MixedArgument
[1976] Fix | Delete
*/
[1977] Fix | Delete
public static function crypto_pwhash_str($passwd, $opslimit, $memlimit)
[1978] Fix | Delete
{
[1979] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($passwd, 'string', 1);
[1980] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($opslimit, 'int', 2);
[1981] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($memlimit, 'int', 3);
[1982] Fix | Delete
[1983] Fix | Delete
if (self::useNewSodiumAPI()) {
[1984] Fix | Delete
return sodium_crypto_pwhash_str($passwd, $opslimit, $memlimit);
[1985] Fix | Delete
}
[1986] Fix | Delete
if (self::use_fallback('crypto_pwhash_str')) {
[1987] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_pwhash_str', $passwd, $opslimit, $memlimit);
[1988] Fix | Delete
}
[1989] Fix | Delete
// This is the best we can do.
[1990] Fix | Delete
throw new SodiumException(
[1991] Fix | Delete
'This is not implemented, as it is not possible to implement Argon2i with acceptable performance in pure-PHP'
[1992] Fix | Delete
);
[1993] Fix | Delete
}
[1994] Fix | Delete
[1995] Fix | Delete
/**
[1996] Fix | Delete
* Do we need to rehash this password?
[1997] Fix | Delete
*
[1998] Fix | Delete
* @param string $hash
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function