Файловый менеджер - Редактировать - /home/beautybuzzbeyond/public_html/private/lib.tar
Назад
ristretto255.php 0000604 00000017451 14717743061 0007566 0 ustar 00 <?php if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES')) { define( 'SODIUM_CRYPTO_CORE_RISTRETTO255_BYTES', ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_BYTES ); define('SODIUM_COMPAT_POLYFILLED_RISTRETTO255', true); } if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_HASHBYTES')) { define( 'SODIUM_CRYPTO_CORE_RISTRETTO255_HASHBYTES', ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_HASHBYTES ); } if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES')) { define( 'SODIUM_CRYPTO_CORE_RISTRETTO255_SCALARBYTES', ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_SCALARBYTES ); } if (!defined('SODIUM_CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES')) { define( 'SODIUM_CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES', ParagonIE_Sodium_Compat::CRYPTO_CORE_RISTRETTO255_NONREDUCEDSCALARBYTES ); } if (!defined('SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES')) { define( 'SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES', ParagonIE_Sodium_Compat::CRYPTO_SCALARMULT_RISTRETTO255_SCALARBYTES ); } if (!defined('SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_BYTES')) { define( 'SODIUM_CRYPTO_SCALARMULT_RISTRETTO255_BYTES', ParagonIE_Sodium_Compat::CRYPTO_SCALARMULT_RISTRETTO255_BYTES ); } if (!is_callable('sodium_crypto_core_ristretto255_add')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_add() * * @param string $p * @param string $q * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_add( #[\SensitiveParameter] $p, #[\SensitiveParameter] $q ) { return ParagonIE_Sodium_Compat::ristretto255_add($p, $q, true); } } if (!is_callable('sodium_crypto_core_ristretto255_from_hash')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_from_hash() * * @param string $s * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_from_hash( #[\SensitiveParameter] $s ) { return ParagonIE_Sodium_Compat::ristretto255_from_hash($s, true); } } if (!is_callable('sodium_crypto_core_ristretto255_is_valid_point')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_is_valid_point() * * @param string $s * @return bool * @throws SodiumException */ function sodium_crypto_core_ristretto255_is_valid_point( #[\SensitiveParameter] $s ) { return ParagonIE_Sodium_Compat::ristretto255_is_valid_point($s, true); } } if (!is_callable('sodium_crypto_core_ristretto255_random')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_random() * * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_random() { return ParagonIE_Sodium_Compat::ristretto255_random(true); } } if (!is_callable('sodium_crypto_core_ristretto255_scalar_add')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_scalar_add() * * @param string $x * @param string $y * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_scalar_add( #[\SensitiveParameter] $x, #[\SensitiveParameter] $y ) { return ParagonIE_Sodium_Compat::ristretto255_scalar_add($x, $y, true); } } if (!is_callable('sodium_crypto_core_ristretto255_scalar_complement')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_scalar_complement() * * @param string $s * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_scalar_complement( #[\SensitiveParameter] $s ) { return ParagonIE_Sodium_Compat::ristretto255_scalar_complement($s, true); } } if (!is_callable('sodium_crypto_core_ristretto255_scalar_invert')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_scalar_invert() * * @param string $p * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_scalar_invert( #[\SensitiveParameter] $p ) { return ParagonIE_Sodium_Compat::ristretto255_scalar_invert($p, true); } } if (!is_callable('sodium_crypto_core_ristretto255_scalar_mul')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_scalar_mul() * * @param string $x * @param string $y * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_scalar_mul( #[\SensitiveParameter] $x, #[\SensitiveParameter] $y ) { return ParagonIE_Sodium_Compat::ristretto255_scalar_mul($x, $y, true); } } if (!is_callable('sodium_crypto_core_ristretto255_scalar_negate')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_scalar_negate() * * @param string $s * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_scalar_negate( #[\SensitiveParameter] $s ) { return ParagonIE_Sodium_Compat::ristretto255_scalar_negate($s, true); } } if (!is_callable('sodium_crypto_core_ristretto255_scalar_random')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_scalar_random() * * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_scalar_random() { return ParagonIE_Sodium_Compat::ristretto255_scalar_random(true); } } if (!is_callable('sodium_crypto_core_ristretto255_scalar_reduce')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_scalar_reduce() * * @param string $s * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_scalar_reduce( #[\SensitiveParameter] $s ) { return ParagonIE_Sodium_Compat::ristretto255_scalar_reduce($s, true); } } if (!is_callable('sodium_crypto_core_ristretto255_scalar_sub')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_scalar_sub() * * @param string $x * @param string $y * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_scalar_sub( #[\SensitiveParameter] $x, #[\SensitiveParameter] $y ) { return ParagonIE_Sodium_Compat::ristretto255_scalar_sub($x, $y, true); } } if (!is_callable('sodium_crypto_core_ristretto255_sub')) { /** * @see ParagonIE_Sodium_Compat::ristretto255_sub() * * @param string $p * @param string $q * @return string * @throws SodiumException */ function sodium_crypto_core_ristretto255_sub( #[\SensitiveParameter] $p, #[\SensitiveParameter] $q ) { return ParagonIE_Sodium_Compat::ristretto255_sub($p, $q, true); } } if (!is_callable('sodium_crypto_scalarmult_ristretto255')) { /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult_ristretto255() * @param string $n * @param string $p * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_scalarmult_ristretto255( #[\SensitiveParameter] $n, #[\SensitiveParameter] $p ) { return ParagonIE_Sodium_Compat::scalarmult_ristretto255($n, $p, true); } } if (!is_callable('sodium_crypto_scalarmult_ristretto255_base')) { /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult_ristretto255_base() * @param string $n * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_scalarmult_ristretto255_base( #[\SensitiveParameter] $n ) { return ParagonIE_Sodium_Compat::scalarmult_ristretto255_base($n, true); } } stream-xchacha20.php 0000604 00000004033 14717743061 0010315 0 ustar 00 <?php if (!is_callable('sodium_crypto_stream_xchacha20')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20() * @param int $len * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_stream_xchacha20( $len, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_stream_xchacha20($len, $nonce, $key, true); } } if (!is_callable('sodium_crypto_stream_xchacha20_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20_keygen() * @return string * @throws Exception */ function sodium_crypto_stream_xchacha20_keygen() { return ParagonIE_Sodium_Compat::crypto_stream_xchacha20_keygen(); } } if (!is_callable('sodium_crypto_stream_xchacha20_xor')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor() * @param string $message * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_stream_xchacha20_xor( #[\SensitiveParameter] $message, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor($message, $nonce, $key, true); } } if (!is_callable('sodium_crypto_stream_xchacha20_xor_ic')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor_ic() * @param string $message * @param string $nonce * @param int $counter * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_stream_xchacha20_xor_ic( #[\SensitiveParameter] $message, $nonce, $counter, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor_ic($message, $nonce, $counter, $key, true); } } namespaced.php 0000644 00000002501 14717743061 0007365 0 ustar 00 <?php require_once dirname(dirname(__FILE__)) . '/autoload.php'; if (PHP_VERSION_ID < 50300) { return; } /* * This file is just for convenience, to allow developers to reduce verbosity when * they add this project to their libraries. * * Replace this: * * $x = ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_encrypt(...$args); * * with this: * * use ParagonIE\Sodium\Compat; * * $x = Compat::crypto_aead_xchacha20poly1305_encrypt(...$args); */ spl_autoload_register(function ($class) { if ($class[0] === '\\') { $class = substr($class, 1); } $namespace = 'ParagonIE\\Sodium'; // Does the class use the namespace prefix? $len = strlen($namespace); if (strncmp($namespace, $class, $len) !== 0) { // no, move to the next registered autoloader return false; } // Get the relative class name $relative_class = substr($class, $len); // Replace the namespace prefix with the base directory, replace namespace // separators with directory separators in the relative class name, append // with .php $file = dirname(dirname(__FILE__)) . '/namespaced/' . str_replace('\\', '/', $relative_class) . '.php'; // if the file exists, require it if (file_exists($file)) { require_once $file; return true; } return false; }); sodium_compat.php 0000604 00000065466 14717743061 0010147 0 ustar 00 <?php namespace Sodium; require_once dirname(dirname(__FILE__)) . '/autoload.php'; use ParagonIE_Sodium_Compat; /** * This file will monkey patch the pure-PHP implementation in place of the * PECL functions, but only if they do not already exist. * * Thus, the functions just proxy to the appropriate ParagonIE_Sodium_Compat * method. */ if (!is_callable('\\Sodium\\bin2hex')) { /** * @see ParagonIE_Sodium_Compat::bin2hex() * @param string $string * @return string * @throws \SodiumException * @throws \TypeError */ function bin2hex( #[\SensitiveParameter] $string ) { return ParagonIE_Sodium_Compat::bin2hex($string); } } if (!is_callable('\\Sodium\\compare')) { /** * @see ParagonIE_Sodium_Compat::compare() * @param string $a * @param string $b * @return int * @throws \SodiumException * @throws \TypeError */ function compare( #[\SensitiveParameter] $a, #[\SensitiveParameter] $b ) { return ParagonIE_Sodium_Compat::compare($a, $b); } } if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string|bool */ function crypto_aead_aes256gcm_decrypt( $message, $assocData, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key); } catch (\TypeError $ex) { return false; } catch (\SodiumException $ex) { return false; } } } if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_aead_aes256gcm_encrypt( #[\SensitiveParameter] $message, $assocData, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key); } } if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_is_available')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() * @return bool */ function crypto_aead_aes256gcm_is_available() { return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); } } if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string|bool */ function crypto_aead_chacha20poly1305_decrypt( $message, $assocData, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key); } catch (\TypeError $ex) { return false; } catch (\SodiumException $ex) { return false; } } } if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_aead_chacha20poly1305_encrypt( #[\SensitiveParameter] $message, $assocData, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key); } } if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_ietf_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string|bool */ function crypto_aead_chacha20poly1305_ietf_decrypt( $message, $assocData, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key); } catch (\TypeError $ex) { return false; } catch (\SodiumException $ex) { return false; } } } if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_ietf_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_aead_chacha20poly1305_ietf_encrypt( #[\SensitiveParameter] $message, $assocData, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key); } } if (!is_callable('\\Sodium\\crypto_auth')) { /** * @see ParagonIE_Sodium_Compat::crypto_auth() * @param string $message * @param string $key * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_auth( $message, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_auth($message, $key); } } if (!is_callable('\\Sodium\\crypto_auth_verify')) { /** * @see ParagonIE_Sodium_Compat::crypto_auth_verify() * @param string $mac * @param string $message * @param string $key * @return bool * @throws \SodiumException * @throws \TypeError */ function crypto_auth_verify( $mac, $message, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key); } } if (!is_callable('\\Sodium\\crypto_box')) { /** * @see ParagonIE_Sodium_Compat::crypto_box() * @param string $message * @param string $nonce * @param string $kp * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_box( #[\SensitiveParameter] $message, $nonce, #[\SensitiveParameter] $kp ) { return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $kp); } } if (!is_callable('\\Sodium\\crypto_box_keypair')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_keypair() * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_box_keypair() { return ParagonIE_Sodium_Compat::crypto_box_keypair(); } } if (!is_callable('\\Sodium\\crypto_box_keypair_from_secretkey_and_publickey')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() * @param string $sk * @param string $pk * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_box_keypair_from_secretkey_and_publickey( #[\SensitiveParameter] $sk, $pk ) { return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($sk, $pk); } } if (!is_callable('\\Sodium\\crypto_box_open')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_open() * @param string $message * @param string $nonce * @param string $kp * @return string|bool */ function crypto_box_open( #[\SensitiveParameter] $message, $nonce, #[\SensitiveParameter] $kp ) { try { return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp); } catch (\TypeError $ex) { return false; } catch (\SodiumException $ex) { return false; } } } if (!is_callable('\\Sodium\\crypto_box_publickey')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_publickey() * @param string $keypair * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_box_publickey( #[\SensitiveParameter] $keypair ) { return ParagonIE_Sodium_Compat::crypto_box_publickey($keypair); } } if (!is_callable('\\Sodium\\crypto_box_publickey_from_secretkey')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() * @param string $sk * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_box_publickey_from_secretkey( #[\SensitiveParameter] $sk ) { return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($sk); } } if (!is_callable('\\Sodium\\crypto_box_seal')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() * @param string $message * @param string $publicKey * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_box_seal( #[\SensitiveParameter] $message, $publicKey ) { return ParagonIE_Sodium_Compat::crypto_box_seal($message, $publicKey); } } if (!is_callable('\\Sodium\\crypto_box_seal_open')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() * @param string $message * @param string $kp * @return string|bool */ function crypto_box_seal_open( $message, #[\SensitiveParameter] $kp ) { try { return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp); } catch (\TypeError $ex) { return false; } catch (\SodiumException $ex) { return false; } } } if (!is_callable('\\Sodium\\crypto_box_secretkey')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() * @param string $keypair * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_box_secretkey( #[\SensitiveParameter] $keypair ) { return ParagonIE_Sodium_Compat::crypto_box_secretkey($keypair); } } if (!is_callable('\\Sodium\\crypto_generichash')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash() * @param string $message * @param string|null $key * @param int $outLen * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_generichash( $message, #[\SensitiveParameter] $key = null, $outLen = 32 ) { return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $outLen); } } if (!is_callable('\\Sodium\\crypto_generichash_final')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash_final() * @param string|null $ctx * @param int $outputLength * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_generichash_final( #[\SensitiveParameter] &$ctx, $outputLength = 32 ) { return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength); } } if (!is_callable('\\Sodium\\crypto_generichash_init')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash_init() * @param string|null $key * @param int $outLen * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_generichash_init( #[\SensitiveParameter] $key = null, $outLen = 32 ) { return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen); } } if (!is_callable('\\Sodium\\crypto_generichash_update')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash_update() * @param string|null $ctx * @param string $message * @return void * @throws \SodiumException * @throws \TypeError */ function crypto_generichash_update( #[\SensitiveParameter] &$ctx, $message = '' ) { ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message); } } if (!is_callable('\\Sodium\\crypto_kx')) { /** * @see ParagonIE_Sodium_Compat::crypto_kx() * @param string $my_secret * @param string $their_public * @param string $client_public * @param string $server_public * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_kx( #[\SensitiveParameter] $my_secret, $their_public, $client_public, $server_public ) { return ParagonIE_Sodium_Compat::crypto_kx( $my_secret, $their_public, $client_public, $server_public, true ); } } if (!is_callable('\\Sodium\\crypto_pwhash')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash() * @param int $outlen * @param string $passwd * @param string $salt * @param int $opslimit * @param int $memlimit * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_pwhash( $outlen, #[\SensitiveParameter] $passwd, $salt, $opslimit, $memlimit ) { return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit); } } if (!is_callable('\\Sodium\\crypto_pwhash_str')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_pwhash_str( #[\SensitiveParameter] $passwd, $opslimit, $memlimit ) { return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit); } } if (!is_callable('\\Sodium\\crypto_pwhash_str_verify')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify() * @param string $passwd * @param string $hash * @return bool * @throws \SodiumException * @throws \TypeError */ function crypto_pwhash_str_verify( #[\SensitiveParameter] $passwd, #[\SensitiveParameter] $hash ) { return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash); } } if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() * @param int $outlen * @param string $passwd * @param string $salt * @param int $opslimit * @param int $memlimit * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_pwhash_scryptsalsa208sha256( $outlen, #[\SensitiveParameter] $passwd, #[\SensitiveParameter] $salt, $opslimit, $memlimit ) { return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit); } } if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_pwhash_scryptsalsa208sha256_str( #[\SensitiveParameter] $passwd, $opslimit, $memlimit ) { return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit); } } if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str_verify')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify() * @param string $passwd * @param string $hash * @return bool * @throws \SodiumException * @throws \TypeError */ function crypto_pwhash_scryptsalsa208sha256_str_verify( #[\SensitiveParameter] $passwd, #[\SensitiveParameter] $hash ) { return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash); } } if (!is_callable('\\Sodium\\crypto_scalarmult')) { /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult() * @param string $n * @param string $p * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_scalarmult( #[\SensitiveParameter] $n, $p ) { return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p); } } if (!is_callable('\\Sodium\\crypto_scalarmult_base')) { /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() * @param string $n * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_scalarmult_base( #[\SensitiveParameter] $n ) { return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n); } } if (!is_callable('\\Sodium\\crypto_secretbox')) { /** * @see ParagonIE_Sodium_Compat::crypto_secretbox() * @param string $message * @param string $nonce * @param string $key * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_secretbox( #[\SensitiveParameter] $message, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key); } } if (!is_callable('\\Sodium\\crypto_secretbox_open')) { /** * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() * @param string $message * @param string $nonce * @param string $key * @return string|bool */ function crypto_secretbox_open( $message, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key); } catch (\TypeError $ex) { return false; } catch (\SodiumException $ex) { return false; } } } if (!is_callable('\\Sodium\\crypto_shorthash')) { /** * @see ParagonIE_Sodium_Compat::crypto_shorthash() * @param string $message * @param string $key * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_shorthash( $message, #[\SensitiveParameter] $key = '' ) { return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key); } } if (!is_callable('\\Sodium\\crypto_sign')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign() * @param string $message * @param string $sk * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign( $message, #[\SensitiveParameter] $sk ) { return ParagonIE_Sodium_Compat::crypto_sign($message, $sk); } } if (!is_callable('\\Sodium\\crypto_sign_detached')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_detached() * @param string $message * @param string $sk * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign_detached( $message, #[\SensitiveParameter] $sk ) { return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk); } } if (!is_callable('\\Sodium\\crypto_sign_keypair')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign_keypair() { return ParagonIE_Sodium_Compat::crypto_sign_keypair(); } } if (!is_callable('\\Sodium\\crypto_sign_open')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_open() * @param string $signedMessage * @param string $pk * @return string|bool */ function crypto_sign_open($signedMessage, $pk) { try { return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk); } catch (\TypeError $ex) { return false; } catch (\SodiumException $ex) { return false; } } } if (!is_callable('\\Sodium\\crypto_sign_publickey')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() * @param string $keypair * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign_publickey( #[\SensitiveParameter] $keypair ) { return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair); } } if (!is_callable('\\Sodium\\crypto_sign_publickey_from_secretkey')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() * @param string $sk * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign_publickey_from_secretkey( #[\SensitiveParameter] $sk ) { return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk); } } if (!is_callable('\\Sodium\\crypto_sign_secretkey')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() * @param string $keypair * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign_secretkey( #[\SensitiveParameter] $keypair ) { return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair); } } if (!is_callable('\\Sodium\\crypto_sign_seed_keypair')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() * @param string $seed * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign_seed_keypair( #[\SensitiveParameter] $seed ) { return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed); } } if (!is_callable('\\Sodium\\crypto_sign_verify_detached')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() * @param string $signature * @param string $message * @param string $pk * @return bool * @throws \SodiumException * @throws \TypeError */ function crypto_sign_verify_detached($signature, $message, $pk) { return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk); } } if (!is_callable('\\Sodium\\crypto_sign_ed25519_pk_to_curve25519')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() * @param string $pk * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign_ed25519_pk_to_curve25519($pk) { return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk); } } if (!is_callable('\\Sodium\\crypto_sign_ed25519_sk_to_curve25519')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() * @param string $sk * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_sign_ed25519_sk_to_curve25519( #[\SensitiveParameter] $sk ) { return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk); } } if (!is_callable('\\Sodium\\crypto_stream')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream() * @param int $len * @param string $nonce * @param string $key * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_stream( $len, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key); } } if (!is_callable('\\Sodium\\crypto_stream_xor')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream_xor() * @param string $message * @param string $nonce * @param string $key * @return string * @throws \SodiumException * @throws \TypeError */ function crypto_stream_xor( #[\SensitiveParameter] $message, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key); } } if (!is_callable('\\Sodium\\hex2bin')) { /** * @see ParagonIE_Sodium_Compat::hex2bin() * @param string $string * @return string * @throws \SodiumException * @throws \TypeError */ function hex2bin( #[\SensitiveParameter] $string ) { return ParagonIE_Sodium_Compat::hex2bin($string); } } if (!is_callable('\\Sodium\\memcmp')) { /** * @see ParagonIE_Sodium_Compat::memcmp() * @param string $a * @param string $b * @return int * @throws \SodiumException * @throws \TypeError */ function memcmp( #[\SensitiveParameter] $a, #[\SensitiveParameter] $b ) { return ParagonIE_Sodium_Compat::memcmp($a, $b); } } if (!is_callable('\\Sodium\\memzero')) { /** * @see ParagonIE_Sodium_Compat::memzero() * @param string $str * @return void * @throws \SodiumException * @throws \TypeError * * @psalm-suppress MissingParamType * @psalm-suppress MissingReturnType * @psalm-suppress ReferenceConstraintViolation */ function memzero( #[\SensitiveParameter] &$str ) { ParagonIE_Sodium_Compat::memzero($str); } } if (!is_callable('\\Sodium\\randombytes_buf')) { /** * @see ParagonIE_Sodium_Compat::randombytes_buf() * @param int $amount * @return string * @throws \TypeError */ function randombytes_buf($amount) { return ParagonIE_Sodium_Compat::randombytes_buf($amount); } } if (!is_callable('\\Sodium\\randombytes_uniform')) { /** * @see ParagonIE_Sodium_Compat::randombytes_uniform() * @param int $upperLimit * @return int * @throws \SodiumException * @throws \Error */ function randombytes_uniform($upperLimit) { return ParagonIE_Sodium_Compat::randombytes_uniform($upperLimit); } } if (!is_callable('\\Sodium\\randombytes_random16')) { /** * @see ParagonIE_Sodium_Compat::randombytes_random16() * @return int */ function randombytes_random16() { return ParagonIE_Sodium_Compat::randombytes_random16(); } } if (!defined('\\Sodium\\CRYPTO_AUTH_BYTES')) { require_once dirname(__FILE__) . '/constants.php'; } php72compat.php 0000604 00000134363 14717743061 0007441 0 ustar 00 <?php require_once dirname(dirname(__FILE__)) . '/autoload.php'; /** * This file will monkey patch the pure-PHP implementation in place of the * PECL functions and constants, but only if they do not already exist. * * Thus, the functions or constants just proxy to the appropriate * ParagonIE_Sodium_Compat method or class constant, respectively. */ foreach (array( 'BASE64_VARIANT_ORIGINAL', 'BASE64_VARIANT_ORIGINAL_NO_PADDING', 'BASE64_VARIANT_URLSAFE', 'BASE64_VARIANT_URLSAFE_NO_PADDING', 'CRYPTO_AEAD_AES256GCM_KEYBYTES', 'CRYPTO_AEAD_AES256GCM_NSECBYTES', 'CRYPTO_AEAD_AES256GCM_NPUBBYTES', 'CRYPTO_AEAD_AES256GCM_ABYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_ABYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES', 'CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES', 'CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NSECBYTES', 'CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES', 'CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES', 'CRYPTO_AUTH_BYTES', 'CRYPTO_AUTH_KEYBYTES', 'CRYPTO_BOX_SEALBYTES', 'CRYPTO_BOX_SECRETKEYBYTES', 'CRYPTO_BOX_PUBLICKEYBYTES', 'CRYPTO_BOX_KEYPAIRBYTES', 'CRYPTO_BOX_MACBYTES', 'CRYPTO_BOX_NONCEBYTES', 'CRYPTO_BOX_SEEDBYTES', 'CRYPTO_KDF_BYTES_MIN', 'CRYPTO_KDF_BYTES_MAX', 'CRYPTO_KDF_CONTEXTBYTES', 'CRYPTO_KDF_KEYBYTES', 'CRYPTO_KX_BYTES', 'CRYPTO_KX_KEYPAIRBYTES', 'CRYPTO_KX_PRIMITIVE', 'CRYPTO_KX_SEEDBYTES', 'CRYPTO_KX_PUBLICKEYBYTES', 'CRYPTO_KX_SECRETKEYBYTES', 'CRYPTO_KX_SESSIONKEYBYTES', 'CRYPTO_GENERICHASH_BYTES', 'CRYPTO_GENERICHASH_BYTES_MIN', 'CRYPTO_GENERICHASH_BYTES_MAX', 'CRYPTO_GENERICHASH_KEYBYTES', 'CRYPTO_GENERICHASH_KEYBYTES_MIN', 'CRYPTO_GENERICHASH_KEYBYTES_MAX', 'CRYPTO_PWHASH_SALTBYTES', 'CRYPTO_PWHASH_STRPREFIX', 'CRYPTO_PWHASH_ALG_ARGON2I13', 'CRYPTO_PWHASH_ALG_ARGON2ID13', 'CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE', 'CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE', 'CRYPTO_PWHASH_MEMLIMIT_MODERATE', 'CRYPTO_PWHASH_OPSLIMIT_MODERATE', 'CRYPTO_PWHASH_MEMLIMIT_SENSITIVE', 'CRYPTO_PWHASH_OPSLIMIT_SENSITIVE', 'CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES', 'CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRPREFIX', 'CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE', 'CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE', 'CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_SENSITIVE', 'CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_SENSITIVE', 'CRYPTO_SCALARMULT_BYTES', 'CRYPTO_SCALARMULT_SCALARBYTES', 'CRYPTO_SHORTHASH_BYTES', 'CRYPTO_SHORTHASH_KEYBYTES', 'CRYPTO_SECRETBOX_KEYBYTES', 'CRYPTO_SECRETBOX_MACBYTES', 'CRYPTO_SECRETBOX_NONCEBYTES', 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES', 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES', 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES', 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PUSH', 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PULL', 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY', 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL', 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX', 'CRYPTO_SIGN_BYTES', 'CRYPTO_SIGN_SEEDBYTES', 'CRYPTO_SIGN_PUBLICKEYBYTES', 'CRYPTO_SIGN_SECRETKEYBYTES', 'CRYPTO_SIGN_KEYPAIRBYTES', 'CRYPTO_STREAM_KEYBYTES', 'CRYPTO_STREAM_NONCEBYTES', 'CRYPTO_STREAM_XCHACHA20_KEYBYTES', 'CRYPTO_STREAM_XCHACHA20_NONCEBYTES', 'LIBRARY_MAJOR_VERSION', 'LIBRARY_MINOR_VERSION', 'LIBRARY_VERSION_MAJOR', 'LIBRARY_VERSION_MINOR', 'VERSION_STRING' ) as $constant ) { if (!defined("SODIUM_$constant") && defined("ParagonIE_Sodium_Compat::$constant")) { define("SODIUM_$constant", constant("ParagonIE_Sodium_Compat::$constant")); } } if (!is_callable('sodium_add')) { /** * @see ParagonIE_Sodium_Compat::add() * @param string $string1 * @param string $string2 * @return void * @throws SodiumException */ function sodium_add( #[\SensitiveParameter] &$string1, #[\SensitiveParameter] $string2 ) { ParagonIE_Sodium_Compat::add($string1, $string2); } } if (!is_callable('sodium_base642bin')) { /** * @see ParagonIE_Sodium_Compat::bin2base64() * @param string $string * @param int $variant * @param string $ignore * @return string * @throws SodiumException * @throws TypeError */ function sodium_base642bin( #[\SensitiveParameter] $string, $variant, $ignore ='' ) { return ParagonIE_Sodium_Compat::base642bin($string, $variant, $ignore); } } if (!is_callable('sodium_bin2base64')) { /** * @see ParagonIE_Sodium_Compat::bin2base64() * @param string $string * @param int $variant * @return string * @throws SodiumException * @throws TypeError */ function sodium_bin2base64( #[\SensitiveParameter] $string, $variant ) { return ParagonIE_Sodium_Compat::bin2base64($string, $variant); } } if (!is_callable('sodium_bin2hex')) { /** * @see ParagonIE_Sodium_Compat::hex2bin() * @param string $string * @return string * @throws SodiumException * @throws TypeError */ function sodium_bin2hex( #[\SensitiveParameter] $string ) { return ParagonIE_Sodium_Compat::bin2hex($string); } } if (!is_callable('sodium_compare')) { /** * @see ParagonIE_Sodium_Compat::compare() * @param string $string1 * @param string $string2 * @return int * @throws SodiumException * @throws TypeError */ function sodium_compare( #[\SensitiveParameter] $string1, #[\SensitiveParameter] $string2 ) { return ParagonIE_Sodium_Compat::compare($string1, $string2); } } if (!is_callable('sodium_crypto_aead_aes256gcm_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() * @param string $ciphertext * @param string $additional_data * @param string $nonce * @param string $key * @return string|bool */ function sodium_crypto_aead_aes256gcm_decrypt( $ciphertext, $additional_data, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt( $ciphertext, $additional_data, $nonce, $key ); } catch (Error $ex) { return false; } catch (Exception $ex) { if (($ex instanceof SodiumException) && ($ex->getMessage() === 'AES-256-GCM is not available')) { throw $ex; } return false; } } } if (!is_callable('sodium_crypto_aead_aes256gcm_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() * @param string $message * @param string $additional_data * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_aead_aes256gcm_encrypt( #[\SensitiveParameter] $message, $additional_data, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $additional_data, $nonce, $key); } } if (!is_callable('sodium_crypto_aead_aes256gcm_is_available')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() * @return bool */ function sodium_crypto_aead_aes256gcm_is_available() { return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); } } if (!is_callable('sodium_crypto_aead_chacha20poly1305_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() * @param string $ciphertext * @param string $additional_data * @param string $nonce * @param string $key * @return string|bool */ function sodium_crypto_aead_chacha20poly1305_decrypt( $ciphertext, $additional_data, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt( $ciphertext, $additional_data, $nonce, $key ); } catch (Error $ex) { return false; } catch (Exception $ex) { return false; } } } if (!is_callable('sodium_crypto_aead_chacha20poly1305_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() * @param string $message * @param string $additional_data * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_aead_chacha20poly1305_encrypt( #[\SensitiveParameter] $message, $additional_data, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt( $message, $additional_data, $nonce, $key ); } } if (!is_callable('sodium_crypto_aead_chacha20poly1305_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen() * @return string * @throws Exception */ function sodium_crypto_aead_chacha20poly1305_keygen() { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen(); } } if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() * @param string $message * @param string $additional_data * @param string $nonce * @param string $key * @return string|bool */ function sodium_crypto_aead_chacha20poly1305_ietf_decrypt( $message, $additional_data, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt( $message, $additional_data, $nonce, $key ); } catch (Error $ex) { return false; } catch (Exception $ex) { return false; } } } if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() * @param string $message * @param string $additional_data * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_aead_chacha20poly1305_ietf_encrypt( #[\SensitiveParameter] $message, $additional_data, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt( $message, $additional_data, $nonce, $key ); } } if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen() * @return string * @throws Exception */ function sodium_crypto_aead_chacha20poly1305_ietf_keygen() { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen(); } } if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt() * @param string $ciphertext * @param string $additional_data * @param string $nonce * @param string $key * @return string|bool */ function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt( $ciphertext, $additional_data, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt( $ciphertext, $additional_data, $nonce, $key, true ); } catch (Error $ex) { return false; } catch (Exception $ex) { return false; } } } if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt() * @param string $message * @param string $additional_data * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt( #[\SensitiveParameter] $message, $additional_data, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt( $message, $additional_data, $nonce, $key, true ); } } if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen() * @return string * @throws Exception */ function sodium_crypto_aead_xchacha20poly1305_ietf_keygen() { return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen(); } } if (!is_callable('sodium_crypto_auth')) { /** * @see ParagonIE_Sodium_Compat::crypto_auth() * @param string $message * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_auth( $message, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_auth($message, $key); } } if (!is_callable('sodium_crypto_auth_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_auth_keygen() * @return string * @throws Exception */ function sodium_crypto_auth_keygen() { return ParagonIE_Sodium_Compat::crypto_auth_keygen(); } } if (!is_callable('sodium_crypto_auth_verify')) { /** * @see ParagonIE_Sodium_Compat::crypto_auth_verify() * @param string $mac * @param string $message * @param string $key * @return bool * @throws SodiumException * @throws TypeError */ function sodium_crypto_auth_verify( $mac, $message, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key); } } if (!is_callable('sodium_crypto_box')) { /** * @see ParagonIE_Sodium_Compat::crypto_box() * @param string $message * @param string $nonce * @param string $key_pair * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_box( #[\SensitiveParameter] $message, $nonce, #[\SensitiveParameter] $key_pair ) { return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $key_pair); } } if (!is_callable('sodium_crypto_box_keypair')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_keypair() * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_box_keypair() { return ParagonIE_Sodium_Compat::crypto_box_keypair(); } } if (!is_callable('sodium_crypto_box_keypair_from_secretkey_and_publickey')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() * @param string $secret_key * @param string $public_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_box_keypair_from_secretkey_and_publickey( #[\SensitiveParameter] $secret_key, $public_key ) { return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($secret_key, $public_key); } } if (!is_callable('sodium_crypto_box_open')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_open() * @param string $ciphertext * @param string $nonce * @param string $key_pair * @return string|bool */ function sodium_crypto_box_open( $ciphertext, $nonce, #[\SensitiveParameter] $key_pair ) { try { return ParagonIE_Sodium_Compat::crypto_box_open($ciphertext, $nonce, $key_pair); } catch (Error $ex) { return false; } catch (Exception $ex) { return false; } } } if (!is_callable('sodium_crypto_box_publickey')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_publickey() * @param string $key_pair * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_box_publickey( #[\SensitiveParameter] $key_pair ) { return ParagonIE_Sodium_Compat::crypto_box_publickey($key_pair); } } if (!is_callable('sodium_crypto_box_publickey_from_secretkey')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() * @param string $secret_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_box_publickey_from_secretkey( #[\SensitiveParameter] $secret_key ) { return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($secret_key); } } if (!is_callable('sodium_crypto_box_seal')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_seal() * @param string $message * @param string $public_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_box_seal( #[\SensitiveParameter] $message, $public_key ) { return ParagonIE_Sodium_Compat::crypto_box_seal($message, $public_key); } } if (!is_callable('sodium_crypto_box_seal_open')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() * @param string $message * @param string $key_pair * @return string|bool * @throws SodiumException */ function sodium_crypto_box_seal_open( $message, #[\SensitiveParameter] $key_pair ) { try { return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $key_pair); } catch (SodiumException $ex) { if ($ex->getMessage() === 'Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.') { throw $ex; } return false; } } } if (!is_callable('sodium_crypto_box_secretkey')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() * @param string $key_pair * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_box_secretkey( #[\SensitiveParameter] $key_pair ) { return ParagonIE_Sodium_Compat::crypto_box_secretkey($key_pair); } } if (!is_callable('sodium_crypto_box_seed_keypair')) { /** * @see ParagonIE_Sodium_Compat::crypto_box_seed_keypair() * @param string $seed * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_box_seed_keypair( #[\SensitiveParameter] $seed ) { return ParagonIE_Sodium_Compat::crypto_box_seed_keypair($seed); } } if (!is_callable('sodium_crypto_generichash')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash() * @param string $message * @param string|null $key * @param int $length * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_generichash( $message, #[\SensitiveParameter] $key = null, $length = 32 ) { return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $length); } } if (!is_callable('sodium_crypto_generichash_final')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash_final() * @param string|null $state * @param int $outputLength * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_generichash_final(&$state, $outputLength = 32) { return ParagonIE_Sodium_Compat::crypto_generichash_final($state, $outputLength); } } if (!is_callable('sodium_crypto_generichash_init')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash_init() * @param string|null $key * @param int $length * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_generichash_init( #[\SensitiveParameter] $key = null, $length = 32 ) { return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $length); } } if (!is_callable('sodium_crypto_generichash_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash_keygen() * @return string * @throws Exception */ function sodium_crypto_generichash_keygen() { return ParagonIE_Sodium_Compat::crypto_generichash_keygen(); } } if (!is_callable('sodium_crypto_generichash_update')) { /** * @see ParagonIE_Sodium_Compat::crypto_generichash_update() * @param string|null $state * @param string $message * @return void * @throws SodiumException * @throws TypeError */ function sodium_crypto_generichash_update( #[\SensitiveParameter] &$state, $message = '' ) { ParagonIE_Sodium_Compat::crypto_generichash_update($state, $message); } } if (!is_callable('sodium_crypto_kdf_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_kdf_keygen() * @return string * @throws Exception */ function sodium_crypto_kdf_keygen() { return ParagonIE_Sodium_Compat::crypto_kdf_keygen(); } } if (!is_callable('sodium_crypto_kdf_derive_from_key')) { /** * @see ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key() * @param int $subkey_length * @param int $subkey_id * @param string $context * @param string $key * @return string * @throws Exception */ function sodium_crypto_kdf_derive_from_key( $subkey_length, $subkey_id, $context, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key( $subkey_length, $subkey_id, $context, $key ); } } if (!is_callable('sodium_crypto_kx')) { /** * @see ParagonIE_Sodium_Compat::crypto_kx() * @param string $my_secret * @param string $their_public * @param string $client_public * @param string $server_public * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_kx( #[\SensitiveParameter] $my_secret, $their_public, $client_public, $server_public ) { return ParagonIE_Sodium_Compat::crypto_kx( $my_secret, $their_public, $client_public, $server_public ); } } if (!is_callable('sodium_crypto_kx_seed_keypair')) { /** * @param string $seed * @return string * @throws Exception */ function sodium_crypto_kx_seed_keypair( #[\SensitiveParameter] $seed ) { return ParagonIE_Sodium_Compat::crypto_kx_seed_keypair($seed); } } if (!is_callable('sodium_crypto_kx_keypair')) { /** * @return string * @throws Exception */ function sodium_crypto_kx_keypair() { return ParagonIE_Sodium_Compat::crypto_kx_keypair(); } } if (!is_callable('sodium_crypto_kx_client_session_keys')) { /** * @param string $client_key_pair * @param string $server_key * @return array{0: string, 1: string} * @throws SodiumException */ function sodium_crypto_kx_client_session_keys( #[\SensitiveParameter] $client_key_pair, $server_key ) { return ParagonIE_Sodium_Compat::crypto_kx_client_session_keys($client_key_pair, $server_key); } } if (!is_callable('sodium_crypto_kx_server_session_keys')) { /** * @param string $server_key_pair * @param string $client_key * @return array{0: string, 1: string} * @throws SodiumException */ function sodium_crypto_kx_server_session_keys( #[\SensitiveParameter] $server_key_pair, $client_key ) { return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($server_key_pair, $client_key); } } if (!is_callable('sodium_crypto_kx_secretkey')) { /** * @param string $key_pair * @return string * @throws Exception */ function sodium_crypto_kx_secretkey( #[\SensitiveParameter] $key_pair ) { return ParagonIE_Sodium_Compat::crypto_kx_secretkey($key_pair); } } if (!is_callable('sodium_crypto_kx_publickey')) { /** * @param string $key_pair * @return string * @throws Exception */ function sodium_crypto_kx_publickey( #[\SensitiveParameter] $key_pair ) { return ParagonIE_Sodium_Compat::crypto_kx_publickey($key_pair); } } if (!is_callable('sodium_crypto_pwhash')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash() * @param int $length * @param string $passwd * @param string $salt * @param int $opslimit * @param int $memlimit * @param int|null $algo * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_pwhash( $length, #[\SensitiveParameter] $passwd, $salt, $opslimit, $memlimit, $algo = null ) { return ParagonIE_Sodium_Compat::crypto_pwhash($length, $passwd, $salt, $opslimit, $memlimit, $algo); } } if (!is_callable('sodium_crypto_pwhash_str')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_pwhash_str( #[\SensitiveParameter] $passwd, $opslimit, $memlimit ) { return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit); } } if (!is_callable('sodium_crypto_pwhash_str_needs_rehash')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash() * @param string $hash * @param int $opslimit * @param int $memlimit * @return bool * * @throws SodiumException */ function sodium_crypto_pwhash_str_needs_rehash( #[\SensitiveParameter] $hash, $opslimit, $memlimit ) { return ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit); } } if (!is_callable('sodium_crypto_pwhash_str_verify')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify() * @param string $passwd * @param string $hash * @return bool * @throws SodiumException * @throws TypeError */ function sodium_crypto_pwhash_str_verify( #[\SensitiveParameter] $passwd, #[\SensitiveParameter] $hash ) { return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash); } } if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() * @param int $length * @param string $passwd * @param string $salt * @param int $opslimit * @param int $memlimit * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_pwhash_scryptsalsa208sha256( $length, #[\SensitiveParameter] $passwd, $salt, $opslimit, $memlimit ) { return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256( $length, $passwd, $salt, $opslimit, $memlimit ); } } if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_pwhash_scryptsalsa208sha256_str( #[\SensitiveParameter] $passwd, $opslimit, $memlimit ) { return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit); } } if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str_verify')) { /** * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify() * @param string $passwd * @param string $hash * @return bool * @throws SodiumException * @throws TypeError */ function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify( #[\SensitiveParameter] $passwd, #[\SensitiveParameter] $hash ) { return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash); } } if (!is_callable('sodium_crypto_scalarmult')) { /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult() * @param string $n * @param string $p * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_scalarmult( #[\SensitiveParameter] $n, $p ) { return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p); } } if (!is_callable('sodium_crypto_scalarmult_base')) { /** * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() * @param string $n * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_scalarmult_base( #[\SensitiveParameter] $n ) { return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n); } } if (!is_callable('sodium_crypto_secretbox')) { /** * @see ParagonIE_Sodium_Compat::crypto_secretbox() * @param string $message * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_secretbox( #[\SensitiveParameter] $message, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key); } } if (!is_callable('sodium_crypto_secretbox_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_secretbox_keygen() * @return string * @throws Exception */ function sodium_crypto_secretbox_keygen() { return ParagonIE_Sodium_Compat::crypto_secretbox_keygen(); } } if (!is_callable('sodium_crypto_secretbox_open')) { /** * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() * @param string $ciphertext * @param string $nonce * @param string $key * @return string|bool */ function sodium_crypto_secretbox_open( $ciphertext, $nonce, #[\SensitiveParameter] $key ) { try { return ParagonIE_Sodium_Compat::crypto_secretbox_open($ciphertext, $nonce, $key); } catch (Error $ex) { return false; } catch (Exception $ex) { return false; } } } if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_push')) { /** * @param string $key * @return array<int, string> * @throws SodiumException */ function sodium_crypto_secretstream_xchacha20poly1305_init_push( #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_push($key); } } if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_push')) { /** * @param string $state * @param string $message * @param string $additional_data * @param int $tag * @return string * @throws SodiumException */ function sodium_crypto_secretstream_xchacha20poly1305_push( #[\SensitiveParameter] &$state, #[\SensitiveParameter] $message, $additional_data = '', $tag = 0 ) { return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_push( $state, $message, $additional_data, $tag ); } } if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_pull')) { /** * @param string $header * @param string $key * @return string * @throws Exception */ function sodium_crypto_secretstream_xchacha20poly1305_init_pull( $header, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_pull($header, $key); } } if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_pull')) { /** * @param string $state * @param string $ciphertext * @param string $additional_data * @return bool|array{0: string, 1: int} * @throws SodiumException */ function sodium_crypto_secretstream_xchacha20poly1305_pull( #[\SensitiveParameter] &$state, $ciphertext, $additional_data = '' ) { return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_pull( $state, $ciphertext, $additional_data ); } } if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_rekey')) { /** * @param string $state * @return void * @throws SodiumException */ function sodium_crypto_secretstream_xchacha20poly1305_rekey( #[\SensitiveParameter] &$state ) { ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_rekey($state); } } if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_keygen')) { /** * @return string * @throws Exception */ function sodium_crypto_secretstream_xchacha20poly1305_keygen() { return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_keygen(); } } if (!is_callable('sodium_crypto_shorthash')) { /** * @see ParagonIE_Sodium_Compat::crypto_shorthash() * @param string $message * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_shorthash( $message, #[\SensitiveParameter] $key = '' ) { return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key); } } if (!is_callable('sodium_crypto_shorthash_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_shorthash_keygen() * @return string * @throws Exception */ function sodium_crypto_shorthash_keygen() { return ParagonIE_Sodium_Compat::crypto_shorthash_keygen(); } } if (!is_callable('sodium_crypto_sign')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign() * @param string $message * @param string $secret_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign( $message, #[\SensitiveParameter] $secret_key ) { return ParagonIE_Sodium_Compat::crypto_sign($message, $secret_key); } } if (!is_callable('sodium_crypto_sign_detached')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_detached() * @param string $message * @param string $secret_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_detached( $message, #[\SensitiveParameter] $secret_key ) { return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $secret_key); } } if (!is_callable('sodium_crypto_sign_keypair_from_secretkey_and_publickey')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey() * @param string $secret_key * @param string $public_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_keypair_from_secretkey_and_publickey( #[\SensitiveParameter] $secret_key, $public_key ) { return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($secret_key, $public_key); } } if (!is_callable('sodium_crypto_sign_keypair')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_keypair() { return ParagonIE_Sodium_Compat::crypto_sign_keypair(); } } if (!is_callable('sodium_crypto_sign_open')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_open() * @param string $signedMessage * @param string $public_key * @return string|bool */ function sodium_crypto_sign_open($signedMessage, $public_key) { try { return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $public_key); } catch (Error $ex) { return false; } catch (Exception $ex) { return false; } } } if (!is_callable('sodium_crypto_sign_publickey')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() * @param string $key_pair * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_publickey( #[\SensitiveParameter] $key_pair ) { return ParagonIE_Sodium_Compat::crypto_sign_publickey($key_pair); } } if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() * @param string $secret_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_publickey_from_secretkey( #[\SensitiveParameter] $secret_key ) { return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($secret_key); } } if (!is_callable('sodium_crypto_sign_secretkey')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() * @param string $key_pair * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_secretkey( #[\SensitiveParameter] $key_pair ) { return ParagonIE_Sodium_Compat::crypto_sign_secretkey($key_pair); } } if (!is_callable('sodium_crypto_sign_seed_keypair')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() * @param string $seed * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_seed_keypair( #[\SensitiveParameter] $seed ) { return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed); } } if (!is_callable('sodium_crypto_sign_verify_detached')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() * @param string $signature * @param string $message * @param string $public_key * @return bool * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_verify_detached($signature, $message, $public_key) { return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $public_key); } } if (!is_callable('sodium_crypto_sign_ed25519_pk_to_curve25519')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() * @param string $public_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_ed25519_pk_to_curve25519($public_key) { return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($public_key); } } if (!is_callable('sodium_crypto_sign_ed25519_sk_to_curve25519')) { /** * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() * @param string $secret_key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_sign_ed25519_sk_to_curve25519( #[\SensitiveParameter] $secret_key ) { return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($secret_key); } } if (!is_callable('sodium_crypto_stream')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream() * @param int $length * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_stream( $length, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_stream($length, $nonce, $key); } } if (!is_callable('sodium_crypto_stream_keygen')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream_keygen() * @return string * @throws Exception */ function sodium_crypto_stream_keygen() { return ParagonIE_Sodium_Compat::crypto_stream_keygen(); } } if (!is_callable('sodium_crypto_stream_xor')) { /** * @see ParagonIE_Sodium_Compat::crypto_stream_xor() * @param string $message * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_stream_xor( #[\SensitiveParameter] $message, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key); } } require_once dirname(__FILE__) . '/stream-xchacha20.php'; if (!is_callable('sodium_hex2bin')) { /** * @see ParagonIE_Sodium_Compat::hex2bin() * @param string $string * @param string $ignore * @return string * @throws SodiumException * @throws TypeError */ function sodium_hex2bin( #[\SensitiveParameter] $string, $ignore = '' ) { return ParagonIE_Sodium_Compat::hex2bin($string, $ignore); } } if (!is_callable('sodium_increment')) { /** * @see ParagonIE_Sodium_Compat::increment() * @param string $string * @return void * @throws SodiumException * @throws TypeError */ function sodium_increment( #[\SensitiveParameter] &$string ) { ParagonIE_Sodium_Compat::increment($string); } } if (!is_callable('sodium_library_version_major')) { /** * @see ParagonIE_Sodium_Compat::library_version_major() * @return int */ function sodium_library_version_major() { return ParagonIE_Sodium_Compat::library_version_major(); } } if (!is_callable('sodium_library_version_minor')) { /** * @see ParagonIE_Sodium_Compat::library_version_minor() * @return int */ function sodium_library_version_minor() { return ParagonIE_Sodium_Compat::library_version_minor(); } } if (!is_callable('sodium_version_string')) { /** * @see ParagonIE_Sodium_Compat::version_string() * @return string */ function sodium_version_string() { return ParagonIE_Sodium_Compat::version_string(); } } if (!is_callable('sodium_memcmp')) { /** * @see ParagonIE_Sodium_Compat::memcmp() * @param string $string1 * @param string $string2 * @return int * @throws SodiumException * @throws TypeError */ function sodium_memcmp( #[\SensitiveParameter] $string1, #[\SensitiveParameter] $string2 ) { return ParagonIE_Sodium_Compat::memcmp($string1, $string2); } } if (!is_callable('sodium_memzero')) { /** * @see ParagonIE_Sodium_Compat::memzero() * @param string $string * @return void * @throws SodiumException * @throws TypeError * * @psalm-suppress ReferenceConstraintViolation */ function sodium_memzero( #[\SensitiveParameter] &$string ) { ParagonIE_Sodium_Compat::memzero($string); } } if (!is_callable('sodium_pad')) { /** * @see ParagonIE_Sodium_Compat::pad() * @param string $unpadded * @param int $block_size * @return string * @throws SodiumException * @throws TypeError */ function sodium_pad( #[\SensitiveParameter] $unpadded, $block_size ) { return ParagonIE_Sodium_Compat::pad($unpadded, $block_size, true); } } if (!is_callable('sodium_unpad')) { /** * @see ParagonIE_Sodium_Compat::pad() * @param string $padded * @param int $block_size * @return string * @throws SodiumException * @throws TypeError */ function sodium_unpad( #[\SensitiveParameter] $padded, $block_size ) { return ParagonIE_Sodium_Compat::unpad($padded, $block_size, true); } } if (!is_callable('sodium_randombytes_buf')) { /** * @see ParagonIE_Sodium_Compat::randombytes_buf() * @param int $amount * @return string * @throws Exception */ function sodium_randombytes_buf($amount) { return ParagonIE_Sodium_Compat::randombytes_buf($amount); } } if (!is_callable('sodium_randombytes_uniform')) { /** * @see ParagonIE_Sodium_Compat::randombytes_uniform() * @param int $upperLimit * @return int * @throws Exception */ function sodium_randombytes_uniform($upperLimit) { return ParagonIE_Sodium_Compat::randombytes_uniform($upperLimit); } } if (!is_callable('sodium_randombytes_random16')) { /** * @see ParagonIE_Sodium_Compat::randombytes_random16() * @return int * @throws Exception */ function sodium_randombytes_random16() { return ParagonIE_Sodium_Compat::randombytes_random16(); } } php72compat_const.php 0000644 00000010765 14717743061 0010652 0 ustar 00 <?php const SODIUM_LIBRARY_MAJOR_VERSION = 9; const SODIUM_LIBRARY_MINOR_VERSION = 1; const SODIUM_LIBRARY_VERSION = '1.0.8'; const SODIUM_BASE64_VARIANT_ORIGINAL = 1; const SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING = 3; const SODIUM_BASE64_VARIANT_URLSAFE = 5; const SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING = 7; const SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES = 32; const SODIUM_CRYPTO_AEAD_AES256GCM_NSECBYTES = 0; const SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES = 12; const SODIUM_CRYPTO_AEAD_AES256GCM_ABYTES = 16; const SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES = 32; const SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES = 0; const SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES = 8; const SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_ABYTES = 16; const SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES = 32; const SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES = 0; const SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES = 12; const SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES = 16; const SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES = 32; const SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NSECBYTES = 0; const SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES = 24; const SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES = 16; const SODIUM_CRYPTO_AUTH_BYTES = 32; const SODIUM_CRYPTO_AUTH_KEYBYTES = 32; const SODIUM_CRYPTO_BOX_SEALBYTES = 16; const SODIUM_CRYPTO_BOX_SECRETKEYBYTES = 32; const SODIUM_CRYPTO_BOX_PUBLICKEYBYTES = 32; const SODIUM_CRYPTO_BOX_KEYPAIRBYTES = 64; const SODIUM_CRYPTO_BOX_MACBYTES = 16; const SODIUM_CRYPTO_BOX_NONCEBYTES = 24; const SODIUM_CRYPTO_BOX_SEEDBYTES = 32; const SODIUM_CRYPTO_KDF_BYTES_MIN = 16; const SODIUM_CRYPTO_KDF_BYTES_MAX = 64; const SODIUM_CRYPTO_KDF_CONTEXTBYTES = 8; const SODIUM_CRYPTO_KDF_KEYBYTES = 32; const SODIUM_CRYPTO_KX_BYTES = 32; const SODIUM_CRYPTO_KX_PRIMITIVE = 'x25519blake2b'; const SODIUM_CRYPTO_KX_SEEDBYTES = 32; const SODIUM_CRYPTO_KX_KEYPAIRBYTES = 64; const SODIUM_CRYPTO_KX_PUBLICKEYBYTES = 32; const SODIUM_CRYPTO_KX_SECRETKEYBYTES = 32; const SODIUM_CRYPTO_KX_SESSIONKEYBYTES = 32; const SODIUM_CRYPTO_GENERICHASH_BYTES = 32; const SODIUM_CRYPTO_GENERICHASH_BYTES_MIN = 16; const SODIUM_CRYPTO_GENERICHASH_BYTES_MAX = 64; const SODIUM_CRYPTO_GENERICHASH_KEYBYTES = 32; const SODIUM_CRYPTO_GENERICHASH_KEYBYTES_MIN = 16; const SODIUM_CRYPTO_GENERICHASH_KEYBYTES_MAX = 64; const SODIUM_CRYPTO_PWHASH_SALTBYTES = 16; const SODIUM_CRYPTO_PWHASH_STRPREFIX = '$argon2id$'; const SODIUM_CRYPTO_PWHASH_ALG_ARGON2I13 = 1; const SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13 = 2; const SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE = 33554432; const SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE = 4; const SODIUM_CRYPTO_PWHASH_MEMLIMIT_MODERATE = 134217728; const SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE = 6; const SODIUM_CRYPTO_PWHASH_MEMLIMIT_SENSITIVE = 536870912; const SODIUM_CRYPTO_PWHASH_OPSLIMIT_SENSITIVE = 8; const SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES = 32; const SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRPREFIX = '$7$'; const SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE = 534288; const SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE = 16777216; const SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_SENSITIVE = 33554432; const SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_SENSITIVE = 1073741824; const SODIUM_CRYPTO_SCALARMULT_BYTES = 32; const SODIUM_CRYPTO_SCALARMULT_SCALARBYTES = 32; const SODIUM_CRYPTO_SHORTHASH_BYTES = 8; const SODIUM_CRYPTO_SHORTHASH_KEYBYTES = 16; const SODIUM_CRYPTO_SECRETBOX_KEYBYTES = 32; const SODIUM_CRYPTO_SECRETBOX_MACBYTES = 16; const SODIUM_CRYPTO_SECRETBOX_NONCEBYTES = 24; const SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES = 17; const SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES = 24; const SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES = 32; const SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PUSH = 0; const SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PULL = 1; const SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY = 2; const SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL = 3; const SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX = 0x3fffffff80; const SODIUM_CRYPTO_SIGN_BYTES = 64; const SODIUM_CRYPTO_SIGN_SEEDBYTES = 32; const SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES = 32; const SODIUM_CRYPTO_SIGN_SECRETKEYBYTES = 64; const SODIUM_CRYPTO_SIGN_KEYPAIRBYTES = 96; const SODIUM_CRYPTO_STREAM_KEYBYTES = 32; const SODIUM_CRYPTO_STREAM_NONCEBYTES = 24; const SODIUM_CRYPTO_STREAM_XCHACHA20_KEYBYTES = 32; const SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES = 24; constants.php 0000644 00000010101 14717743061 0007274 0 ustar 00 <?php namespace Sodium; require_once dirname(dirname(__FILE__)) . '/autoload.php'; use ParagonIE_Sodium_Compat; const CRYPTO_AEAD_AES256GCM_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_AES256GCM_KEYBYTES; const CRYPTO_AEAD_AES256GCM_NSECBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_AES256GCM_NSECBYTES; const CRYPTO_AEAD_AES256GCM_NPUBBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_AES256GCM_NPUBBYTES; const CRYPTO_AEAD_AES256GCM_ABYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_AES256GCM_ABYTES; const CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES; const CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES; const CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES; const CRYPTO_AEAD_CHACHA20POLY1305_ABYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_ABYTES; const CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES; const CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES; const CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES; const CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES; const CRYPTO_AUTH_BYTES = ParagonIE_Sodium_Compat::CRYPTO_AUTH_BYTES; const CRYPTO_AUTH_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_AUTH_KEYBYTES; const CRYPTO_BOX_SEALBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_SEALBYTES; const CRYPTO_BOX_SECRETKEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES; const CRYPTO_BOX_PUBLICKEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES; const CRYPTO_BOX_KEYPAIRBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES; const CRYPTO_BOX_MACBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_MACBYTES; const CRYPTO_BOX_NONCEBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_NONCEBYTES; const CRYPTO_BOX_SEEDBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_SEEDBYTES; const CRYPTO_KX_BYTES = ParagonIE_Sodium_Compat::CRYPTO_KX_BYTES; const CRYPTO_KX_SEEDBYTES = ParagonIE_Sodium_Compat::CRYPTO_KX_SEEDBYTES; const CRYPTO_KX_PUBLICKEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_KX_PUBLICKEYBYTES; const CRYPTO_KX_SECRETKEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_KX_SECRETKEYBYTES; const CRYPTO_GENERICHASH_BYTES = ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES; const CRYPTO_GENERICHASH_BYTES_MIN = ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MIN; const CRYPTO_GENERICHASH_BYTES_MAX = ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MAX; const CRYPTO_GENERICHASH_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES; const CRYPTO_GENERICHASH_KEYBYTES_MIN = ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES_MIN; const CRYPTO_GENERICHASH_KEYBYTES_MAX = ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES_MAX; const CRYPTO_SCALARMULT_BYTES = ParagonIE_Sodium_Compat::CRYPTO_SCALARMULT_BYTES; const CRYPTO_SCALARMULT_SCALARBYTES = ParagonIE_Sodium_Compat::CRYPTO_SCALARMULT_SCALARBYTES; const CRYPTO_SHORTHASH_BYTES = ParagonIE_Sodium_Compat::CRYPTO_SHORTHASH_BYTES; const CRYPTO_SHORTHASH_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_SHORTHASH_KEYBYTES; const CRYPTO_SECRETBOX_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_KEYBYTES; const CRYPTO_SECRETBOX_MACBYTES = ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_MACBYTES; const CRYPTO_SECRETBOX_NONCEBYTES = ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_NONCEBYTES; const CRYPTO_SIGN_BYTES = ParagonIE_Sodium_Compat::CRYPTO_SIGN_BYTES; const CRYPTO_SIGN_SEEDBYTES = ParagonIE_Sodium_Compat::CRYPTO_SIGN_SEEDBYTES; const CRYPTO_SIGN_PUBLICKEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_SIGN_PUBLICKEYBYTES; const CRYPTO_SIGN_SECRETKEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_SIGN_SECRETKEYBYTES; const CRYPTO_SIGN_KEYPAIRBYTES = ParagonIE_Sodium_Compat::CRYPTO_SIGN_KEYPAIRBYTES; const CRYPTO_STREAM_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_STREAM_KEYBYTES; const CRYPTO_STREAM_NONCEBYTES = ParagonIE_Sodium_Compat::CRYPTO_STREAM_NONCEBYTES; php84compat_const.php 0000604 00000000621 14717743061 0010637 0 ustar 00 <?php const SODIUM_CRYPTO_AEAD_AEGIS128L_KEYBYTES = 16; const SODIUM_CRYPTO_AEAD_AEGIS128L_NSECBYTES = 0; const SODIUM_CRYPTO_AEAD_AEGIS128L_NPUBBYTES = 32; const SODIUM_CRYPTO_AEAD_AEGIS128L_ABYTES = 32; const SODIUM_CRYPTO_AEAD_AEGIS256_KEYBYTES = 32; const SODIUM_CRYPTO_AEAD_AEGIS256_NSECBYTES = 0; const SODIUM_CRYPTO_AEAD_AEGIS256_NPUBBYTES = 32; const SODIUM_CRYPTO_AEAD_AEGIS256_ABYTES = 32; php84compat.php 0000604 00000007110 14717743061 0007431 0 ustar 00 <?php require_once dirname(dirname(__FILE__)) . '/autoload.php'; /** * This file will monkey patch the pure-PHP implementation in place of the * PECL functions and constants, but only if they do not already exist. * * Thus, the functions or constants just proxy to the appropriate * ParagonIE_Sodium_Compat method or class constant, respectively. */ foreach (array( 'CRYPTO_AEAD_AESGIS128L_KEYBYTES', 'CRYPTO_AEAD_AESGIS128L_NSECBYTES', 'CRYPTO_AEAD_AESGIS128L_NPUBBYTES', 'CRYPTO_AEAD_AESGIS128L_ABYTES', 'CRYPTO_AEAD_AESGIS256_KEYBYTES', 'CRYPTO_AEAD_AESGIS256_NSECBYTES', 'CRYPTO_AEAD_AESGIS256_NPUBBYTES', 'CRYPTO_AEAD_AESGIS256_ABYTES', ) as $constant ) { if (!defined("SODIUM_$constant") && defined("ParagonIE_Sodium_Compat::$constant")) { define("SODIUM_$constant", constant("ParagonIE_Sodium_Compat::$constant")); } } if (!is_callable('sodium_crypto_aead_aegis128l_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aegis128l_decrypt() * @param string $ciphertext * @param string $additional_data * @param string $nonce * @param string $key * @return string * @throws SodiumException */ function sodium_crypto_aead_aegis128l_decrypt( $ciphertext, $additional_data, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_aegis128l_decrypt( $ciphertext, $additional_data, $nonce, $key ); } } if (!is_callable('sodium_crypto_aead_aegis128l_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aegis128l_encrypt() * @param string $message * @param string $additional_data * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_aead_aegis128l_encrypt( #[\SensitiveParameter] $message, $additional_data, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_aegis128l_encrypt( $message, $additional_data, $nonce, $key ); } } if (!is_callable('sodium_crypto_aead_aegis256_decrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aegis256_encrypt() * @param string $ciphertext * @param string $additional_data * @param string $nonce * @param string $key * @return string * @throws SodiumException */ function sodium_crypto_aead_aegis256_decrypt( $ciphertext, $additional_data, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_aegis256_decrypt( $ciphertext, $additional_data, $nonce, $key ); } } if (!is_callable('sodium_crypto_aead_aegis256_encrypt')) { /** * @see ParagonIE_Sodium_Compat::crypto_aead_aegis256_encrypt() * @param string $message * @param string $additional_data * @param string $nonce * @param string $key * @return string * @throws SodiumException * @throws TypeError */ function sodium_crypto_aead_aegis256_encrypt( #[\SensitiveParameter] $message, $additional_data, $nonce, #[\SensitiveParameter] $key ) { return ParagonIE_Sodium_Compat::crypto_aead_aegis256_encrypt( $message, $additional_data, $nonce, $key ); } } class-aricolor.php 0000644 00000070056 14717764222 0010216 0 ustar 00 <?php // phpcs:ignoreFile // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } if ( ! class_exists( 'ariColor' ) ) { /** * The color calculations class. */ class ariColor { /** * An array of our instances. * * @static * @access public * @since 1.0.0 * @var array */ public static $instances = array(); /** * The color initially set. * * @access public * @since 1.0.0 * @var mixed */ public $color; /** * A fallback color in case of failure. * * @access public * @since 1.0.0 * @var mixed */ public $fallback = '#ffffff'; /** * Fallback object from the fallback color. * * @access public * @since 1.0.0 * @var object */ public $fallback_obj; /** * The mode we're using for this color. * * @access public * @since 1.0.0 * @var string */ public $mode = 'hex'; /** * An array containing all word-colors (white/blue/red etc) * and their corresponding HEX codes. * * @access public * @since 1.0.0 * @var array */ public $word_colors = array(); /** * The hex code of the color. * * @access public * @since 1.0.0 * @var string */ public $hex; /** * Red value. * * @access public * @since 1.0.0 * @var int */ public $red = 0; /** * Green value. * * @access public * @since 1.0.0 * @var int */ public $green = 0; /** * Blue value. * * @access public * @since 1.0.0 * @var int */ public $blue = 0; /** * Alpha value (min:0, max: 1) * * @access public * @since 1.0.0 * @var float */ public $alpha = 1; /** * Hue value. * * @access public * @since 1.0.0 * @var float */ public $hue; /** * Saturation value. * * @access public * @since 1.0.0 * @var float */ public $saturation; /** * Lightness value. * * @access public * @since 1.0.0 * @var float */ public $lightness; /** * Chroma value. * * @access public * @since 1.0.0 * @var float */ public $chroma; /** * An array containing brightnesses. * * @access public * @since 1.0.0 * @var array */ public $brightness = array(); /** * Luminance value. * * @access public * @since 1.0.0 * @var float */ public $luminance; /** * The class constructor. * * @access protected * @since 1.0.0 * @param string|array $color The color. * @param string $mode The color mode. Leave empty to auto-detect. */ protected function __construct( $color = '', $mode = 'auto' ) { $this->color = $color; if ( is_array( $color ) && isset( $color['fallback'] ) ) { $this->fallback = $color['fallback']; $this->fallback_obj = self::newColor( $this->fallback ); } if ( ! method_exists( $this, 'from_' . $mode ) ) { $mode = $this->get_mode( $color ); } $this->mode = $mode; if ( ! $mode ) { return; } $this->mode = $mode; $method = 'from_' . $mode; // Call the from_{$color_mode} method. $this->$method(); } /** * Gets an instance for this color. * We use a separate instance per color * because there's no need to create a completely new instance each time we call this class. * Instead using instances helps us improve performance & footprint. * * @static * @access public * @since 1.0.0 * @param string|array $color The color. * @param string $mode Mode to be used. * @return ariColor (object) */ public static function newColor( $color, $mode = 'auto' ) { // Get an md5 for this color. $color_md5 = ( is_array( $color ) ) ? md5( wp_json_encode( $color ) . $mode ) : md5( $color . $mode ); // Set the instance if it does not already exist. if ( ! isset( self::$instances[ $color_md5 ] ) ) { self::$instances[ $color_md5 ] = new self( $color, $mode ); } return self::$instances[ $color_md5 ]; } /** * Alias of the newColor method. * * @static * @access public * @since 1.1 * @param string|array $color The color. * @param string $mode Mode to be used. * @return ariColor (object) */ public static function new_color( $color, $mode = 'auto' ) { return self::newColor( $color, $mode ); } /** * Allows us to get a new instance by modifying a property of the existing one. * * @access public * @since 1.0.0 * @param string $property Can be one of the following: * red, * green, * blue, * alpha, * hue, * saturation, * lightness, * brightness. * @param int|float|string $value The new value. * @return ariColor|null */ public function getNew( $property = '', $value = '' ) { if ( in_array( $property, array( 'red', 'green', 'blue', 'alpha' ), true ) ) { // Check if we're changing any of the rgba values. $value = max( 0, min( 255, $value ) ); if ( 'red' === $property ) { return self::new_color( 'rgba(' . $value . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')', 'rgba' ); } elseif ( 'green' === $property ) { return self::new_color( 'rgba(' . $this->red . ',' . $value . ',' . $this->blue . ',' . $this->alpha . ')', 'rgba' ); } elseif ( 'blue' === $property ) { return self::new_color( 'rgba(' . $this->red . ',' . $this->green . ',' . $value . ',' . $this->alpha . ')', 'rgba' ); } elseif ( 'alpha' === $property ) { return self::new_color( 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $value . ')', 'rgba' ); } } elseif ( in_array( $property, array( 'hue', 'saturation', 'lightness' ), true ) ) { // Check if we're changing any of the hsl values. $value = ( 'hue' === $property ) ? max( 0, min( 360, $value ) ) : max( 0, min( 100, $value ) ); if ( 'hue' === $property ) { return self::new_color( 'hsla(' . $value . ',' . $this->saturation . '%,' . $this->lightness . '%,' . $this->alpha . ')', 'hsla' ); } elseif ( 'saturation' === $property ) { return self::new_color( 'hsla(' . $this->hue . ',' . $value . '%,' . $this->lightness . '%,' . $this->alpha . ')', 'hsla' ); } elseif ( 'lightness' === $property ) { return self::new_color( 'hsla(' . $this->hue . ',' . $this->saturation . '%,' . $value . '%,' . $this->alpha . ')', 'hsla' ); } } elseif ( 'brightness' === $property ) { // Check if we're changing the brightness. if ( $value < $this->brightness['total'] ) { $red = max( 0, min( 255, $this->red - ( $this->brightness['total'] - $value ) ) ); $green = max( 0, min( 255, $this->green - ( $this->brightness['total'] - $value ) ) ); $blue = max( 0, min( 255, $this->blue - ( $this->brightness['total'] - $value ) ) ); } elseif ( $value > $this->brightness['total'] ) { $red = max( 0, min( 255, $this->red + ( $value - $this->brightness['total'] ) ) ); $green = max( 0, min( 255, $this->green + ( $value - $this->brightness['total'] ) ) ); $blue = max( 0, min( 255, $this->blue + ( $value - $this->brightness['total'] ) ) ); } else { // If it's not smaller and it's not greater, then it's equal. return $this; } return self::new_color( 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $this->alpha . ')', 'rgba' ); } return null; } /** * Allias for the getNew method. * * @access public * @since 1.1.0 * @param string $property Can be one of the following: * red, * green, * blue, * alpha, * hue, * saturation, * lightness, * brightness. * @param int|float|string $value The new value. * @return ariColor|null */ public function get_new( $property = '', $value = '' ) { return $this->getNew( $property, $value ); } /** * Figure out what mode we're using. * * @access public * @since 1.0.0 * @param string|array $color The color we're querying. * @return string */ public function get_mode( $color ) { // Check if value is an array. if ( is_array( $color ) ) { // Does the array have an 'rgba' key? if ( isset( $color['rgba'] ) ) { $this->color = $color['rgba']; return 'rgba'; } elseif ( isset( $color['color'] ) ) { // Does the array have a 'color' key? $this->color = $color['color']; if ( is_string( $color['color'] ) && false !== strpos( $color['color'], 'rgba' ) ) { return 'rgba'; } return 'hex'; } // Is this a simple array with 4 items? if ( 4 === count( $color ) && isset( $color[0] ) && isset( $color[1] ) && isset( $color[2] ) && isset( $color[3] ) ) { $this->color = 'rgba(' . intval( $color[0] ) . ',' . intval( $color[1] ) . ',' . intval( $color[2] ) . ',' . intval( $color[3] ) . ')'; return 'rgba'; } elseif ( 3 === count( $color ) && isset( $color[0] ) && isset( $color[1] ) && isset( $color[2] ) ) { // Is this a simple array with 3 items? $this->color = 'rgba(' . intval( $color[0] ) . ',' . intval( $color[1] ) . ',' . intval( $color[2] ) . ',1)'; return 'rgba'; } // Check for other keys in the array and get values from there. $finders_keepers = array( 'r' => 'red', 'g' => 'green', 'b' => 'blue', 'a' => 'alpha', 'red' => 'red', 'green' => 'green', 'blue' => 'blue', 'alpha' => 'alpha', 'opacity' => 'alpha', ); $found = false; foreach ( $finders_keepers as $finder => $keeper ) { if ( isset( $color[ $finder ] ) ) { $found = true; $this->$keeper = $color[ $finder ]; } } // We failed, use fallback. if ( ! $found ) { $this->from_fallback(); return $this->mode; } // We did not fail, so use rgba values recovered above. $this->color = 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')'; return 'rgba'; } // If a string and 3 or 6 characters long, add # since it's a hex. if ( 3 === strlen( $this->color ) || 6 === strlen( $this->color ) && false === strpos( $this->color, '#' ) ) { $this->color = '#' . $this->color; $color = $this->color; } // If we got this far, it's not an array. // Check for key identifiers in the value. $finders_keepers = array( '#' => 'hex', 'rgba' => 'rgba', 'rgb' => 'rgb', 'hsla' => 'hsla', 'hsl' => 'hsl', ); foreach ( $finders_keepers as $finder => $keeper ) { if ( false !== strrpos( $color, $finder ) ) { // Make sure hex colors have 6 digits and not more. if ( '#' === $finder && 7 < strlen( $color ) ) { $this->color = substr( $color, 0, 7 ); } return $keeper; } } // Perhaps we're using a word like "orange"? $wordcolors = $this->get_word_colors(); if ( is_string( $color ) && array_key_exists( $color, $wordcolors ) ) { $this->color = '#' . $wordcolors[ $color ]; return 'hex'; } // Fallback to hex. $this->color = $this->fallback; return 'hex'; } /** * Starts with a HEX color and calculates all other properties. * * @access protected * @since 1.0.0 * @return null */ protected function from_hex() { if ( ! function_exists( 'sanitize_hex_color' ) ) { require_once wp_normalize_path( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); } // Is this perhaps a word-color? $word_colors = $this->get_word_colors(); if ( array_key_exists( $this->color, $word_colors ) ) { $this->color = '#' . $word_colors[ $this->color ]; } // Sanitize color. $this->hex = sanitize_hex_color( maybe_hash_hex_color( $this->color ) ); $hex = ltrim( $this->hex, '#' ); // Fallback if needed. if ( ! $hex || 3 > strlen( $hex ) ) { $this->from_fallback(); return; } // Make sure we have 6 digits for the below calculations. if ( 3 === strlen( $hex ) ) { $hex = ltrim( $this->hex, '#' ); $hex = substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) . substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) . substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ); } // Set red, green, blue. $this->red = hexdec( substr( $hex, 0, 2 ) ); $this->green = hexdec( substr( $hex, 2, 2 ) ); $this->blue = hexdec( substr( $hex, 4, 2 ) ); $this->alpha = 1; // Set other color properties. $this->set_brightness(); $this->set_hsl(); $this->set_luminance(); } /** * Starts with an RGB color and calculates all other properties. * * @access protected * @since 1.0.0 * @return null */ protected function from_rgb() { $value = explode( ',', str_replace( array( ' ', 'rgb', '(', ')' ), '', $this->color ) ); // Set red, green, blue. $this->red = ( isset( $value[0] ) ) ? intval( $value[0] ) : 255; $this->green = ( isset( $value[1] ) ) ? intval( $value[1] ) : 255; $this->blue = ( isset( $value[2] ) ) ? intval( $value[2] ) : 255; $this->alpha = 1; // Set the hex. $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); // Set other color properties. $this->set_brightness(); $this->set_hsl(); $this->set_luminance(); } /** * Starts with an RGBA color and calculates all other properties. * * @access protected * @since 1.0.0 * @return null */ protected function from_rgba() { // Set r, g, b, a properties. $value = explode( ',', str_replace( array( ' ', 'rgba', '(', ')' ), '', $this->color ) ); $this->red = ( isset( $value[0] ) ) ? intval( $value[0] ) : 255; $this->green = ( isset( $value[1] ) ) ? intval( $value[1] ) : 255; $this->blue = ( isset( $value[2] ) ) ? intval( $value[2] ) : 255; $this->alpha = ( isset( $value[3] ) ) ? filter_var( $value[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : 1; // Limit values in the range of 0 - 255. $this->red = max( 0, min( 255, $this->red ) ); $this->green = max( 0, min( 255, $this->green ) ); $this->blue = max( 0, min( 255, $this->blue ) ); // Limit values 0 - 1. $this->alpha = max( 0, min( 1, $this->alpha ) ); // Set hex. $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); // Set other color properties. $this->set_brightness(); $this->set_hsl(); $this->set_luminance(); } /** * Starts with an HSL color and calculates all other properties. * * @access protected * @since 1.0.0 * @return null */ protected function from_hsl() { $value = explode( ',', str_replace( array( ' ', 'hsl', '(', ')', '%' ), '', $this->color ) ); $this->hue = $value[0]; $this->saturation = $value[1]; $this->lightness = $value[2]; $this->from_hsl_array(); } /** * Starts with an HSLA color and calculates all other properties. * * @access protected * @since 1.0.0 * @return null */ protected function from_hsla() { $value = explode( ',', str_replace( array( ' ', 'hsla', '(', ')', '%' ), '', $this->color ) ); $this->hue = $value[0]; $this->saturation = $value[1]; $this->lightness = $value[2]; $this->alpha = $value[3]; $this->from_hsl_array(); } /** * Generates the HEX value of a color given values for $red, $green, $blue. * * @access protected * @since 1.0.0 * @param int|string $red The red value of this color. * @param int|string $green The green value of this color. * @param int|string $blue The blue value of this color. * @return string */ protected function rgb_to_hex( $red, $green, $blue ) { // Get hex values properly formatted. $hex_red = $this->dexhex_double_digit( $red ); $hex_green = $this->dexhex_double_digit( $green ); $hex_blue = $this->dexhex_double_digit( $blue ); return '#' . $hex_red . $hex_green . $hex_blue; } /** * Convert a decimal value to hex and make sure it's 2 characters. * * @access protected * @since 1.0.0 * @param int|string $value The value to convert. * @return string */ protected function dexhex_double_digit( $value ) { $value = dechex( $value ); if ( 1 === strlen( $value ) ) { $value = '0' . $value; } return $value; } /** * Calculates the red, green, blue values of an HSL color. * * @access protected * @since 1.0.0 * @see https://gist.github.com/brandonheyer/5254516 */ protected function from_hsl_array() { $h = $this->hue / 360; $s = $this->saturation / 100; $l = $this->lightness / 100; $r = $l; $g = $l; $b = $l; $v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s ); if ( $v > 0 ) { $m = $l + $l - $v; $sv = ( $v - $m ) / $v; $h *= 6.0; $sextant = floor( $h ); $fract = $h - $sextant; $vsf = $v * $sv * $fract; $mid1 = $m + $vsf; $mid2 = $v - $vsf; switch ( $sextant ) { case 0: $r = $v; $g = $mid1; $b = $m; break; case 1: $r = $mid2; $g = $v; $b = $m; break; case 2: $r = $m; $g = $v; $b = $mid1; break; case 3: $r = $m; $g = $mid2; $b = $v; break; case 4: $r = $mid1; $g = $m; $b = $v; break; case 5: $r = $v; $g = $m; $b = $mid2; break; } } $this->red = round( $r * 255, 0 ); $this->green = round( $g * 255, 0 ); $this->blue = round( $b * 255, 0 ); $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); $this->set_luminance(); } /** * Returns a CSS-formatted value for colors. * * @access public * @since 1.0.0 * @param string $mode The mode we're using. * @return string */ public function toCSS( $mode = 'hex' ) { $value = ''; switch ( $mode ) { case 'hex': $value = strtolower( $this->hex ); break; case 'rgba': $value = 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')'; break; case 'rgb': $value = 'rgb(' . $this->red . ',' . $this->green . ',' . $this->blue . ')'; break; case 'hsl': $value = 'hsl(' . $this->hue . ',' . round( $this->saturation ) . '%,' . round( $this->lightness ) . '%)'; break; case 'hsla': $value = 'hsla(' . $this->hue . ',' . round( $this->saturation ) . '%,' . round( $this->lightness ) . '%,' . $this->alpha . ')'; break; } return $value; } /** * Alias for the toCSS method. * * @access public * @since 1.1 * @param string $mode The mode we're using. * @return string */ public function to_css( $mode = 'hex' ) { return $this->toCSS( $mode ); } /** * Sets the HSL values of a color based on the values of red, green, blue. * * @access public * @since 1.0.0 */ protected function set_hsl() { $red = $this->red / 255; $green = $this->green / 255; $blue = $this->blue / 255; $max = max( $red, $green, $blue ); $min = min( $red, $green, $blue ); $lightness = ( $max + $min ) / 2; $difference = $max - $min; if ( ! $difference ) { $hue = $saturation = 0; // Achromatic. } else { $saturation = $difference / ( 1 - abs( 2 * $lightness - 1 ) ); switch ( $max ) { case $red: $hue = 60 * fmod( ( ( $green - $blue ) / $difference ), 6 ); if ( $blue > $green ) { $hue += 360; } break; case $green: $hue = 60 * ( ( $blue - $red ) / $difference + 2 ); break; case $blue: $hue = 60 * ( ( $red - $green ) / $difference + 4 ); break; } } $this->hue = round( $hue ); $this->saturation = round( $saturation * 100 ); $this->lightness = round( $lightness * 100 ); } /** * Sets the brightness of a color based on the values of red, green, blue. * * @access protected * @since 1.0.0 */ protected function set_brightness() { $this->brightness = array( 'red' => round( $this->red * .299 ), 'green' => round( $this->green * .587 ), 'blue' => round( $this->blue * .114 ), 'total' => intval( ( $this->red * .299 ) + ( $this->green * .587 ) + ( $this->blue * .114 ) ), ); } /** * Sets the luminance of a color (range:0-255) based on the values of red, green, blue. * * @access protected * @since 1.0.0 */ protected function set_luminance() { $lum = ( 0.2126 * $this->red ) + ( 0.7152 * $this->green ) + ( 0.0722 * $this->blue ); $this->luminance = round( $lum ); } /** * Gets an array of all the wordcolors. * * @access protected * @since 1.0.0 * @return array */ protected function get_word_colors() { return array( 'aliceblue' => 'F0F8FF', 'antiquewhite' => 'FAEBD7', 'aqua' => '00FFFF', 'aquamarine' => '7FFFD4', 'azure' => 'F0FFFF', 'beige' => 'F5F5DC', 'bisque' => 'FFE4C4', 'black' => '000000', 'blanchedalmond' => 'FFEBCD', 'blue' => '0000FF', 'blueviolet' => '8A2BE2', 'brown' => 'A52A2A', 'burlywood' => 'DEB887', 'cadetblue' => '5F9EA0', 'chartreuse' => '7FFF00', 'chocolate' => 'D2691E', 'coral' => 'FF7F50', 'cornflowerblue' => '6495ED', 'cornsilk' => 'FFF8DC', 'crimson' => 'DC143C', 'cyan' => '00FFFF', 'darkblue' => '00008B', 'darkcyan' => '008B8B', 'darkgoldenrod' => 'B8860B', 'darkgray' => 'A9A9A9', 'darkgreen' => '006400', 'darkgrey' => 'A9A9A9', 'darkkhaki' => 'BDB76B', 'darkmagenta' => '8B008B', 'darkolivegreen' => '556B2F', 'darkorange' => 'FF8C00', 'darkorchid' => '9932CC', 'darkred' => '8B0000', 'darksalmon' => 'E9967A', 'darkseagreen' => '8FBC8F', 'darkslateblue' => '483D8B', 'darkslategray' => '2F4F4F', 'darkslategrey' => '2F4F4F', 'darkturquoise' => '00CED1', 'darkviolet' => '9400D3', 'deeppink' => 'FF1493', 'deepskyblue' => '00BFFF', 'dimgray' => '696969', 'dimgrey' => '696969', 'dodgerblue' => '1E90FF', 'firebrick' => 'B22222', 'floralwhite' => 'FFFAF0', 'forestgreen' => '228B22', 'fuchsia' => 'FF00FF', 'gainsboro' => 'DCDCDC', 'ghostwhite' => 'F8F8FF', 'gold' => 'FFD700', 'goldenrod' => 'DAA520', 'gray' => '808080', 'green' => '008000', 'greenyellow' => 'ADFF2F', 'grey' => '808080', 'honeydew' => 'F0FFF0', 'hotpink' => 'FF69B4', 'indianred' => 'CD5C5C', 'indigo' => '4B0082', 'ivory' => 'FFFFF0', 'khaki' => 'F0E68C', 'lavender' => 'E6E6FA', 'lavenderblush' => 'FFF0F5', 'lawngreen' => '7CFC00', 'lemonchiffon' => 'FFFACD', 'lightblue' => 'ADD8E6', 'lightcoral' => 'F08080', 'lightcyan' => 'E0FFFF', 'lightgoldenrodyellow' => 'FAFAD2', 'lightgray' => 'D3D3D3', 'lightgreen' => '90EE90', 'lightgrey' => 'D3D3D3', 'lightpink' => 'FFB6C1', 'lightsalmon' => 'FFA07A', 'lightseagreen' => '20B2AA', 'lightskyblue' => '87CEFA', 'lightslategray' => '778899', 'lightslategrey' => '778899', 'lightsteelblue' => 'B0C4DE', 'lightyellow' => 'FFFFE0', 'lime' => '00FF00', 'limegreen' => '32CD32', 'linen' => 'FAF0E6', 'magenta' => 'FF00FF', 'maroon' => '800000', 'mediumaquamarine' => '66CDAA', 'mediumblue' => '0000CD', 'mediumorchid' => 'BA55D3', 'mediumpurple' => '9370D0', 'mediumseagreen' => '3CB371', 'mediumslateblue' => '7B68EE', 'mediumspringgreen' => '00FA9A', 'mediumturquoise' => '48D1CC', 'mediumvioletred' => 'C71585', 'midnightblue' => '191970', 'mintcream' => 'F5FFFA', 'mistyrose' => 'FFE4E1', 'moccasin' => 'FFE4B5', 'navajowhite' => 'FFDEAD', 'navy' => '000080', 'oldlace' => 'FDF5E6', 'olive' => '808000', 'olivedrab' => '6B8E23', 'orange' => 'FFA500', 'orangered' => 'FF4500', 'orchid' => 'DA70D6', 'palegoldenrod' => 'EEE8AA', 'palegreen' => '98FB98', 'paleturquoise' => 'AFEEEE', 'palevioletred' => 'DB7093', 'papayawhip' => 'FFEFD5', 'peachpuff' => 'FFDAB9', 'peru' => 'CD853F', 'pink' => 'FFC0CB', 'plum' => 'DDA0DD', 'powderblue' => 'B0E0E6', 'purple' => '800080', 'red' => 'FF0000', 'rosybrown' => 'BC8F8F', 'royalblue' => '4169E1', 'saddlebrown' => '8B4513', 'salmon' => 'FA8072', 'sandybrown' => 'F4A460', 'seagreen' => '2E8B57', 'seashell' => 'FFF5EE', 'sienna' => 'A0522D', 'silver' => 'C0C0C0', 'skyblue' => '87CEEB', 'slateblue' => '6A5ACD', 'slategray' => '708090', 'slategrey' => '708090', 'snow' => 'FFFAFA', 'springgreen' => '00FF7F', 'steelblue' => '4682B4', 'tan' => 'D2B48C', 'teal' => '008080', 'thistle' => 'D8BFD8', 'tomato' => 'FF6347', 'turquoise' => '40E0D0', 'violet' => 'EE82EE', 'wheat' => 'F5DEB3', 'white' => 'FFFFFF', 'whitesmoke' => 'F5F5F5', 'yellow' => 'FFFF00', 'yellowgreen' => '9ACD32', ); } /** * Use fallback object. * * @access protected * @since 1.2.0 */ protected function from_fallback() { $this->color = $this->fallback; if ( ! $this->fallback_obj ) { $this->fallback_obj = self::newColor( $this->fallback ); } $this->color = $this->fallback_obj->color; $this->mode = $this->fallback_obj->mode; $this->red = $this->fallback_obj->red; $this->green = $this->fallback_obj->green; $this->blue = $this->fallback_obj->blue; $this->alpha = $this->fallback_obj->alpha; $this->hue = $this->fallback_obj->hue; $this->saturation = $this->fallback_obj->saturation; $this->lightness = $this->fallback_obj->lightness; $this->luminance = $this->fallback_obj->luminance; $this->hex = $this->fallback_obj->hex; } /** * Handle non-existing public methods. * * @access public * @since 1.1.0 * @param string $name The method name. * @param mixed $arguments The method arguments. * @return mixed */ public function __call( $name, $arguments ) { if ( method_exists( $this, $name ) ) { call_user_func( array( $this, $name ), $arguments ); } else { return $arguments; } } /** * Handle non-existing public static methods. * * @static * @access public * @since 1.1.0 * @param string $name The method name. * @param mixed $arguments The method arguments. * @return mixed */ public static function __callStatic( $name, $arguments ) { if ( method_exists( __CLASS__, $name ) ) { call_user_func( array( __CLASS__, $name ), $arguments ); } else { return $arguments; } } } } class-kirki-color.php 0000644 00000025212 14717764222 0010623 0 ustar 00 <?php /** * Color Calculations class for Kirki * Initially built for the Shoestrap-3 theme and then tweaked for Kirki. * * @package Kirki * @category Core * @author Themeum * @copyright Copyright (c) 2023, Themeum * @license https://opensource.org/licenses/MIT * @since 1.0 */ // phpcs:ignoreFile // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Helper class for color manipulation. */ final class Kirki_Color extends ariColor { /** * A proxy for the sanitize_color method. * * @param string|array $color The color. * @param bool $hash Whether we want to include a hash (#) at the beginning or not. * @return string The sanitized hex color. */ public static function sanitize_hex( $color = '#FFFFFF', $hash = true ) { if ( ! $hash ) { return ltrim( self::sanitize_color( $color, 'hex' ), '#' ); } return self::sanitize_color( $color, 'hex' ); } /** * A proxy the sanitize_color method. * * @static * @access public * @param string $color The color. * @return string */ public static function sanitize_rgba( $color ) { return self::sanitize_color( $color, 'rgba' ); } /** * Sanitize colors. * Determine if the current value is a hex or an rgba color and call the appropriate method. * * @static * @access public * @since 0.8.5 * @param string|array $color The color. * @param string $mode The mode to be used. * @return string */ public static function sanitize_color( $color = '', $mode = 'auto' ) { if ( is_string( $color ) && 'transparent' == trim( $color ) ) { return 'transparent'; } $obj = ariColor::newColor( $color ); if ( 'auto' == $mode ) { $mode = $obj->mode; } return $obj->toCSS( $mode ); } /** * Gets the rgb value of a color. * * @static * @access public * @param string $color The color. * @param boolean $implode Whether we want to implode the values or not. * @return array|string */ public static function get_rgb( $color, $implode = false ) { $obj = ariColor::newColor( $color ); if ( $implode ) { return $obj->toCSS( 'rgb' ); } return array( $obj->red, $obj->green, $obj->blue ); } /** * A proxy for the sanitize_color method. * * @static * @access public * @param string|array $color The color to convert. * @return string The hex value of the color. */ public static function rgba2hex( $color ) { return self::sanitize_color( $color, 'hex' ); } /** * Get the alpha channel from an rgba color. * * @static * @access public * @param string $color The rgba color formatted like rgba(r,g,b,a). * @return int|float The alpha value of the color. */ public static function get_alpha_from_rgba( $color ) { $obj = ariColor::newColor( $color ); return $obj->alpha; } /** * Gets the rgba value of the $color. * * @static * @access public * @param string $color The hex value of a color. * @param int|float $alpha Opacity level (0-1). * @return string */ public static function get_rgba( $color = '#fff', $alpha = 1 ) { $obj = ariColor::newColor( $color ); if ( 1 == $alpha ) { return $obj->toCSS( 'rgba' ); } // Make sure that opacity is properly formatted. // Converts 1-100 values to 0-1. if ( $alpha > 1 || $alpha < -1 ) { // Divide by 100. $alpha /= 100; } // Get absolute value. $alpha = abs( $alpha ); // Max 1. if ( 1 < $alpha ) { $alpha = 1; } $new_obj = $obj->getNew( 'alpha', $alpha ); return $new_obj->toCSS( 'rgba' ); } /** * Strips the alpha value from an RGBA color string. * * @static * @access public * @param string $color The RGBA color string. * @return string The corresponding RGB string. */ public static function rgba_to_rgb( $color ) { $obj = ariColor::newColor( $color ); return $obj->toCSS( 'rgb' ); } /** * Gets the brightness of the $hex color. * * @static * @access public * @param string $hex The hex value of a color. * @return int Value between 0 and 255. */ public static function get_brightness( $hex ) { $hex = self::sanitize_hex( $hex, false ); // Returns brightness value from 0 to 255. return intval( ( ( hexdec( substr( $hex, 0, 2 ) ) * 299 ) + ( hexdec( substr( $hex, 2, 2 ) ) * 587 ) + ( hexdec( substr( $hex, 4, 2 ) ) * 114 ) ) / 1000 ); } /** * Adjusts brightness of the $hex color. * * @static * @access public * @param string $hex The hex value of a color. * @param integer $steps Should be between -255 and 255. Negative = darker, positive = lighter. * @return string Returns hex color. */ public static function adjust_brightness( $hex, $steps ) { $hex = self::sanitize_hex( $hex, false ); $steps = max( -255, min( 255, $steps ) ); // Adjust number of steps and keep it inside 0 to 255. $red = max( 0, min( 255, hexdec( substr( $hex, 0, 2 ) ) + $steps ) ); $green = max( 0, min( 255, hexdec( substr( $hex, 2, 2 ) ) + $steps ) ); $blue = max( 0, min( 255, hexdec( substr( $hex, 4, 2 ) ) + $steps ) ); $red_hex = str_pad( dechex( $red ), 2, '0', STR_PAD_LEFT ); $green_hex = str_pad( dechex( $green ), 2, '0', STR_PAD_LEFT ); $blue_hex = str_pad( dechex( $blue ), 2, '0', STR_PAD_LEFT ); return self::sanitize_hex( $red_hex . $green_hex . $blue_hex ); } /** * Mixes 2 hex colors. * The "percentage" variable is the percent of the first color. * to be used it the mix. default is 50 (equal mix). * * @static * @access public * @param string|false $hex1 Color. * @param string|false $hex2 Color. * @param int $percentage A value between 0 and 100. * @return string Returns hex color. */ public static function mix_colors( $hex1, $hex2, $percentage ) { $hex1 = self::sanitize_hex( $hex1, false ); $hex2 = self::sanitize_hex( $hex2, false ); $red = ( $percentage * hexdec( substr( $hex1, 0, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 0, 2 ) ) ) / 100; $green = ( $percentage * hexdec( substr( $hex1, 2, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 2, 2 ) ) ) / 100; $blue = ( $percentage * hexdec( substr( $hex1, 4, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 4, 2 ) ) ) / 100; $red_hex = str_pad( dechex( $red ), 2, '0', STR_PAD_LEFT ); $green_hex = str_pad( dechex( $green ), 2, '0', STR_PAD_LEFT ); $blue_hex = str_pad( dechex( $blue ), 2, '0', STR_PAD_LEFT ); return self::sanitize_hex( $red_hex . $green_hex . $blue_hex ); } /** * Convert hex color to hsv. * * @static * @access public * @param string $hex The hex value of color 1. * @return array Returns array( 'h', 's', 'v' ). */ public static function hex_to_hsv( $hex ) { $rgb = (array) (array) self::get_rgb( self::sanitize_hex( $hex, false ) ); return self::rgb_to_hsv( $rgb ); } /** * Convert hex color to hsv. * * @static * @access public * @param string $color The rgb color to convert array( 'r', 'g', 'b' ). * @return array Returns array( 'h', 's', 'v' ). */ public static function rgb_to_hsv( $color = array() ) { $var_r = ( $color[0] / 255 ); $var_g = ( $color[1] / 255 ); $var_b = ( $color[2] / 255 ); $var_min = min( $var_r, $var_g, $var_b ); $var_max = max( $var_r, $var_g, $var_b ); $del_max = $var_max - $var_min; $h = 0; $s = 0; $v = $var_max; if ( 0 != $del_max ) { $s = $del_max / $var_max; $del_r = ( ( ( $var_max - $var_r ) / 6 ) + ( $del_max / 2 ) ) / $del_max; $del_g = ( ( ( $var_max - $var_g ) / 6 ) + ( $del_max / 2 ) ) / $del_max; $del_b = ( ( ( $var_max - $var_b ) / 6 ) + ( $del_max / 2 ) ) / $del_max; if ( $var_r == $var_max ) { $h = $del_b - $del_g; } elseif ( $var_g == $var_max ) { $h = ( 1 / 3 ) + $del_r - $del_b; } elseif ( $var_b == $var_max ) { $h = ( 2 / 3 ) + $del_g - $del_r; } if ( $h < 0 ) { $h++; } if ( $h > 1 ) { $h--; } } return array( 'h' => round( $h, 2 ), 's' => round( $s, 2 ), 'v' => round( $v, 2 ), ); } /** * This is a very simple algorithm that works by summing up the differences between the three color components red, green and blue. * A value higher than 500 is recommended for good readability. * * @static * @access public * @param string $color_1 The 1st color. * @param string $color_2 The 2nd color. * @return string */ public static function color_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $r_diff = max( $color_1_rgb[0], $color_2_rgb[0] ) - min( $color_1_rgb[0], $color_2_rgb[0] ); $g_diff = max( $color_1_rgb[1], $color_2_rgb[1] ) - min( $color_1_rgb[1], $color_2_rgb[1] ); $b_diff = max( $color_1_rgb[2], $color_2_rgb[2] ) - min( $color_1_rgb[2], $color_2_rgb[2] ); $color_diff = $r_diff + $g_diff + $b_diff; return $color_diff; } /** * This function tries to compare the brightness of the colors. * A return value of more than 125 is recommended. * Combining it with the color_difference function above might make sense. * * @static * @access public * @param string $color_1 The 1st color. * @param string $color_2 The 2nd color. * @return string */ public static function brightness_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $br_1 = ( 299 * $color_1_rgb[0] + 587 * $color_1_rgb[1] + 114 * $color_1_rgb[2] ) / 1000; $br_2 = ( 299 * $color_2_rgb[0] + 587 * $color_2_rgb[1] + 114 * $color_2_rgb[2] ) / 1000; return intval( abs( $br_1 - $br_2 ) ); } /** * Uses the luminosity to calculate the difference between the given colors. * The returned value should be bigger than 5 for best readability. * * @static * @access public * @param string $color_1 The 1st color. * @param string $color_2 The 2nd color. * @return string */ public static function lumosity_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { $color_1 = self::sanitize_hex( $color_1, false ); $color_2 = self::sanitize_hex( $color_2, false ); $color_1_rgb = self::get_rgb( $color_1 ); $color_2_rgb = self::get_rgb( $color_2 ); $l1 = 0.2126 * pow( $color_1_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_1_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_1_rgb[2] / 255, 2.2 ); $l2 = 0.2126 * pow( $color_2_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_2_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_2_rgb[2] / 255, 2.2 ); $lum_diff = ( $l1 > $l2 ) ? ( $l1 + 0.05 ) / ( $l2 + 0.05 ) : ( $l2 + 0.05 ) / ( $l1 + 0.05 ); return round( $lum_diff, 2 ); } }
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка