Edit File by line

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

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu.../sodium_c.../src
File: Compat.php
if (self::useNewSodiumAPI()) {
[3000] Fix | Delete
return sodium_crypto_stream($len, $nonce, $key);
[3001] Fix | Delete
}
[3002] Fix | Delete
if (self::use_fallback('crypto_stream')) {
[3003] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_stream', $len, $nonce, $key);
[3004] Fix | Delete
}
[3005] Fix | Delete
if (PHP_INT_SIZE === 4) {
[3006] Fix | Delete
return ParagonIE_Sodium_Core32_XSalsa20::xsalsa20($len, $nonce, $key);
[3007] Fix | Delete
}
[3008] Fix | Delete
return ParagonIE_Sodium_Core_XSalsa20::xsalsa20($len, $nonce, $key);
[3009] Fix | Delete
}
[3010] Fix | Delete
[3011] Fix | Delete
/**
[3012] Fix | Delete
* DANGER! UNAUTHENTICATED ENCRYPTION!
[3013] Fix | Delete
*
[3014] Fix | Delete
* Unless you are following expert advice, do not use this feature.
[3015] Fix | Delete
*
[3016] Fix | Delete
* Algorithm: XSalsa20
[3017] Fix | Delete
*
[3018] Fix | Delete
* This DOES NOT provide ciphertext integrity.
[3019] Fix | Delete
*
[3020] Fix | Delete
* @param string $message Plaintext message
[3021] Fix | Delete
* @param string $nonce Number to be used Once; must be 24 bytes
[3022] Fix | Delete
* @param string $key Encryption key
[3023] Fix | Delete
* @return string Encrypted text which is vulnerable to chosen-
[3024] Fix | Delete
* ciphertext attacks unless you implement some
[3025] Fix | Delete
* other mitigation to the ciphertext (i.e.
[3026] Fix | Delete
* Encrypt then MAC)
[3027] Fix | Delete
* @throws SodiumException
[3028] Fix | Delete
* @throws TypeError
[3029] Fix | Delete
* @psalm-suppress MixedArgument
[3030] Fix | Delete
*/
[3031] Fix | Delete
public static function crypto_stream_xor($message, $nonce, $key)
[3032] Fix | Delete
{
[3033] Fix | Delete
/* Type checks: */
[3034] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1);
[3035] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
[3036] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3);
[3037] Fix | Delete
[3038] Fix | Delete
/* Input validation: */
[3039] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_NONCEBYTES) {
[3040] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.');
[3041] Fix | Delete
}
[3042] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_KEYBYTES) {
[3043] Fix | Delete
throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.');
[3044] Fix | Delete
}
[3045] Fix | Delete
[3046] Fix | Delete
if (self::useNewSodiumAPI()) {
[3047] Fix | Delete
return sodium_crypto_stream_xor($message, $nonce, $key);
[3048] Fix | Delete
}
[3049] Fix | Delete
if (self::use_fallback('crypto_stream_xor')) {
[3050] Fix | Delete
return (string) call_user_func('\\Sodium\\crypto_stream_xor', $message, $nonce, $key);
[3051] Fix | Delete
}
[3052] Fix | Delete
if (PHP_INT_SIZE === 4) {
[3053] Fix | Delete
return ParagonIE_Sodium_Core32_XSalsa20::xsalsa20_xor($message, $nonce, $key);
[3054] Fix | Delete
}
[3055] Fix | Delete
return ParagonIE_Sodium_Core_XSalsa20::xsalsa20_xor($message, $nonce, $key);
[3056] Fix | Delete
}
[3057] Fix | Delete
[3058] Fix | Delete
/**
[3059] Fix | Delete
* Return a secure random key for use with crypto_stream
[3060] Fix | Delete
*
[3061] Fix | Delete
* @return string
[3062] Fix | Delete
* @throws Exception
[3063] Fix | Delete
* @throws Error
[3064] Fix | Delete
*/
[3065] Fix | Delete
public static function crypto_stream_keygen()
[3066] Fix | Delete
{
[3067] Fix | Delete
return random_bytes(self::CRYPTO_STREAM_KEYBYTES);
[3068] Fix | Delete
}
[3069] Fix | Delete
[3070] Fix | Delete
[3071] Fix | Delete
/**
[3072] Fix | Delete
* Expand a key and nonce into a keystream of pseudorandom bytes.
[3073] Fix | Delete
*
[3074] Fix | Delete
* @param int $len Number of bytes desired
[3075] Fix | Delete
* @param string $nonce Number to be used Once; must be 24 bytes
[3076] Fix | Delete
* @param string $key XChaCha20 key
[3077] Fix | Delete
* @param bool $dontFallback
[3078] Fix | Delete
* @return string Pseudorandom stream that can be XORed with messages
[3079] Fix | Delete
* to provide encryption (but not authentication; see
[3080] Fix | Delete
* Poly1305 or crypto_auth() for that, which is not
[3081] Fix | Delete
* optional for security)
[3082] Fix | Delete
* @throws SodiumException
[3083] Fix | Delete
* @throws TypeError
[3084] Fix | Delete
* @psalm-suppress MixedArgument
[3085] Fix | Delete
*/
[3086] Fix | Delete
public static function crypto_stream_xchacha20($len, $nonce, $key, $dontFallback = false)
[3087] Fix | Delete
{
[3088] Fix | Delete
/* Type checks: */
[3089] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($len, 'int', 1);
[3090] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
[3091] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3);
[3092] Fix | Delete
[3093] Fix | Delete
/* Input validation: */
[3094] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_XCHACHA20_NONCEBYTES) {
[3095] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_XCHACHA20_NONCEBYTES long.');
[3096] Fix | Delete
}
[3097] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_XCHACHA20_KEYBYTES) {
[3098] Fix | Delete
throw new SodiumException('Argument 3 must be CRYPTO_STREAM_XCHACHA20_KEYBYTES long.');
[3099] Fix | Delete
}
[3100] Fix | Delete
[3101] Fix | Delete
if (self::useNewSodiumAPI() && !$dontFallback) {
[3102] Fix | Delete
return sodium_crypto_stream_xchacha20($len, $nonce, $key);
[3103] Fix | Delete
}
[3104] Fix | Delete
if (PHP_INT_SIZE === 4) {
[3105] Fix | Delete
return ParagonIE_Sodium_Core32_XChaCha20::stream($len, $nonce, $key);
[3106] Fix | Delete
}
[3107] Fix | Delete
return ParagonIE_Sodium_Core_XChaCha20::stream($len, $nonce, $key);
[3108] Fix | Delete
}
[3109] Fix | Delete
[3110] Fix | Delete
/**
[3111] Fix | Delete
* DANGER! UNAUTHENTICATED ENCRYPTION!
[3112] Fix | Delete
*
[3113] Fix | Delete
* Unless you are following expert advice, do not use this feature.
[3114] Fix | Delete
*
[3115] Fix | Delete
* Algorithm: XChaCha20
[3116] Fix | Delete
*
[3117] Fix | Delete
* This DOES NOT provide ciphertext integrity.
[3118] Fix | Delete
*
[3119] Fix | Delete
* @param string $message Plaintext message
[3120] Fix | Delete
* @param string $nonce Number to be used Once; must be 24 bytes
[3121] Fix | Delete
* @param string $key Encryption key
[3122] Fix | Delete
* @return string Encrypted text which is vulnerable to chosen-
[3123] Fix | Delete
* ciphertext attacks unless you implement some
[3124] Fix | Delete
* other mitigation to the ciphertext (i.e.
[3125] Fix | Delete
* Encrypt then MAC)
[3126] Fix | Delete
* @param bool $dontFallback
[3127] Fix | Delete
* @throws SodiumException
[3128] Fix | Delete
* @throws TypeError
[3129] Fix | Delete
* @psalm-suppress MixedArgument
[3130] Fix | Delete
*/
[3131] Fix | Delete
public static function crypto_stream_xchacha20_xor($message, $nonce, $key, $dontFallback = false)
[3132] Fix | Delete
{
[3133] Fix | Delete
/* Type checks: */
[3134] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1);
[3135] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
[3136] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3);
[3137] Fix | Delete
[3138] Fix | Delete
/* Input validation: */
[3139] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_XCHACHA20_NONCEBYTES) {
[3140] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_XCHACHA20_NONCEBYTES long.');
[3141] Fix | Delete
}
[3142] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_XCHACHA20_KEYBYTES) {
[3143] Fix | Delete
throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_XCHACHA20_KEYBYTES long.');
[3144] Fix | Delete
}
[3145] Fix | Delete
[3146] Fix | Delete
if (self::useNewSodiumAPI() && !$dontFallback) {
[3147] Fix | Delete
return sodium_crypto_stream_xchacha20_xor($message, $nonce, $key);
[3148] Fix | Delete
}
[3149] Fix | Delete
if (PHP_INT_SIZE === 4) {
[3150] Fix | Delete
return ParagonIE_Sodium_Core32_XChaCha20::streamXorIc($message, $nonce, $key);
[3151] Fix | Delete
}
[3152] Fix | Delete
return ParagonIE_Sodium_Core_XChaCha20::streamXorIc($message, $nonce, $key);
[3153] Fix | Delete
}
[3154] Fix | Delete
[3155] Fix | Delete
/**
[3156] Fix | Delete
* DANGER! UNAUTHENTICATED ENCRYPTION!
[3157] Fix | Delete
*
[3158] Fix | Delete
* Unless you are following expert advice, do not use this feature.
[3159] Fix | Delete
*
[3160] Fix | Delete
* Algorithm: XChaCha20
[3161] Fix | Delete
*
[3162] Fix | Delete
* This DOES NOT provide ciphertext integrity.
[3163] Fix | Delete
*
[3164] Fix | Delete
* @param string $message Plaintext message
[3165] Fix | Delete
* @param string $nonce Number to be used Once; must be 24 bytes
[3166] Fix | Delete
* @param int $counter
[3167] Fix | Delete
* @param string $key Encryption key
[3168] Fix | Delete
* @return string Encrypted text which is vulnerable to chosen-
[3169] Fix | Delete
* ciphertext attacks unless you implement some
[3170] Fix | Delete
* other mitigation to the ciphertext (i.e.
[3171] Fix | Delete
* Encrypt then MAC)
[3172] Fix | Delete
* @param bool $dontFallback
[3173] Fix | Delete
* @throws SodiumException
[3174] Fix | Delete
* @throws TypeError
[3175] Fix | Delete
* @psalm-suppress MixedArgument
[3176] Fix | Delete
*/
[3177] Fix | Delete
public static function crypto_stream_xchacha20_xor_ic($message, $nonce, $counter, $key, $dontFallback = false)
[3178] Fix | Delete
{
[3179] Fix | Delete
/* Type checks: */
[3180] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1);
[3181] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
[3182] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($counter, 'int', 3);
[3183] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 4);
[3184] Fix | Delete
[3185] Fix | Delete
/* Input validation: */
[3186] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_XCHACHA20_NONCEBYTES) {
[3187] Fix | Delete
throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_XCHACHA20_NONCEBYTES long.');
[3188] Fix | Delete
}
[3189] Fix | Delete
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_XCHACHA20_KEYBYTES) {
[3190] Fix | Delete
throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_XCHACHA20_KEYBYTES long.');
[3191] Fix | Delete
}
[3192] Fix | Delete
[3193] Fix | Delete
if (is_callable('sodium_crypto_stream_xchacha20_xor_ic') && !$dontFallback) {
[3194] Fix | Delete
return sodium_crypto_stream_xchacha20_xor_ic($message, $nonce, $counter, $key);
[3195] Fix | Delete
}
[3196] Fix | Delete
[3197] Fix | Delete
$ic = ParagonIE_Sodium_Core_Util::store64_le($counter);
[3198] Fix | Delete
if (PHP_INT_SIZE === 4) {
[3199] Fix | Delete
return ParagonIE_Sodium_Core32_XChaCha20::streamXorIc($message, $nonce, $key, $ic);
[3200] Fix | Delete
}
[3201] Fix | Delete
return ParagonIE_Sodium_Core_XChaCha20::streamXorIc($message, $nonce, $key, $ic);
[3202] Fix | Delete
}
[3203] Fix | Delete
[3204] Fix | Delete
/**
[3205] Fix | Delete
* Return a secure random key for use with crypto_stream_xchacha20
[3206] Fix | Delete
*
[3207] Fix | Delete
* @return string
[3208] Fix | Delete
* @throws Exception
[3209] Fix | Delete
* @throws Error
[3210] Fix | Delete
*/
[3211] Fix | Delete
public static function crypto_stream_xchacha20_keygen()
[3212] Fix | Delete
{
[3213] Fix | Delete
return random_bytes(self::CRYPTO_STREAM_XCHACHA20_KEYBYTES);
[3214] Fix | Delete
}
[3215] Fix | Delete
[3216] Fix | Delete
/**
[3217] Fix | Delete
* Cache-timing-safe implementation of hex2bin().
[3218] Fix | Delete
*
[3219] Fix | Delete
* @param string $string Hexadecimal string
[3220] Fix | Delete
* @param string $ignore List of characters to ignore; useful for whitespace
[3221] Fix | Delete
* @return string Raw binary string
[3222] Fix | Delete
* @throws SodiumException
[3223] Fix | Delete
* @throws TypeError
[3224] Fix | Delete
* @psalm-suppress TooFewArguments
[3225] Fix | Delete
* @psalm-suppress MixedArgument
[3226] Fix | Delete
*/
[3227] Fix | Delete
public static function hex2bin($string, $ignore = '')
[3228] Fix | Delete
{
[3229] Fix | Delete
/* Type checks: */
[3230] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($string, 'string', 1);
[3231] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($ignore, 'string', 2);
[3232] Fix | Delete
[3233] Fix | Delete
if (self::useNewSodiumAPI()) {
[3234] Fix | Delete
if (is_callable('sodium_hex2bin')) {
[3235] Fix | Delete
return (string) sodium_hex2bin($string, $ignore);
[3236] Fix | Delete
}
[3237] Fix | Delete
}
[3238] Fix | Delete
if (self::use_fallback('hex2bin')) {
[3239] Fix | Delete
return (string) call_user_func('\\Sodium\\hex2bin', $string, $ignore);
[3240] Fix | Delete
}
[3241] Fix | Delete
return ParagonIE_Sodium_Core_Util::hex2bin($string, $ignore);
[3242] Fix | Delete
}
[3243] Fix | Delete
[3244] Fix | Delete
/**
[3245] Fix | Delete
* Increase a string (little endian)
[3246] Fix | Delete
*
[3247] Fix | Delete
* @param string $var
[3248] Fix | Delete
*
[3249] Fix | Delete
* @return void
[3250] Fix | Delete
* @throws SodiumException
[3251] Fix | Delete
* @throws TypeError
[3252] Fix | Delete
* @psalm-suppress MixedArgument
[3253] Fix | Delete
*/
[3254] Fix | Delete
public static function increment(&$var)
[3255] Fix | Delete
{
[3256] Fix | Delete
/* Type checks: */
[3257] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($var, 'string', 1);
[3258] Fix | Delete
[3259] Fix | Delete
if (self::useNewSodiumAPI()) {
[3260] Fix | Delete
sodium_increment($var);
[3261] Fix | Delete
return;
[3262] Fix | Delete
}
[3263] Fix | Delete
if (self::use_fallback('increment')) {
[3264] Fix | Delete
$func = '\\Sodium\\increment';
[3265] Fix | Delete
$func($var);
[3266] Fix | Delete
return;
[3267] Fix | Delete
}
[3268] Fix | Delete
[3269] Fix | Delete
$len = ParagonIE_Sodium_Core_Util::strlen($var);
[3270] Fix | Delete
$c = 1;
[3271] Fix | Delete
$copy = '';
[3272] Fix | Delete
for ($i = 0; $i < $len; ++$i) {
[3273] Fix | Delete
$c += ParagonIE_Sodium_Core_Util::chrToInt(
[3274] Fix | Delete
ParagonIE_Sodium_Core_Util::substr($var, $i, 1)
[3275] Fix | Delete
);
[3276] Fix | Delete
$copy .= ParagonIE_Sodium_Core_Util::intToChr($c);
[3277] Fix | Delete
$c >>= 8;
[3278] Fix | Delete
}
[3279] Fix | Delete
$var = $copy;
[3280] Fix | Delete
}
[3281] Fix | Delete
[3282] Fix | Delete
/**
[3283] Fix | Delete
* @param string $str
[3284] Fix | Delete
* @return bool
[3285] Fix | Delete
*
[3286] Fix | Delete
* @throws SodiumException
[3287] Fix | Delete
*/
[3288] Fix | Delete
public static function is_zero($str)
[3289] Fix | Delete
{
[3290] Fix | Delete
$d = 0;
[3291] Fix | Delete
for ($i = 0; $i < 32; ++$i) {
[3292] Fix | Delete
$d |= ParagonIE_Sodium_Core_Util::chrToInt($str[$i]);
[3293] Fix | Delete
}
[3294] Fix | Delete
return ((($d - 1) >> 31) & 1) === 1;
[3295] Fix | Delete
}
[3296] Fix | Delete
[3297] Fix | Delete
/**
[3298] Fix | Delete
* The equivalent to the libsodium minor version we aim to be compatible
[3299] Fix | Delete
* with (sans pwhash and memzero).
[3300] Fix | Delete
*
[3301] Fix | Delete
* @return int
[3302] Fix | Delete
*/
[3303] Fix | Delete
public static function library_version_major()
[3304] Fix | Delete
{
[3305] Fix | Delete
if (self::useNewSodiumAPI() && defined('SODIUM_LIBRARY_MAJOR_VERSION')) {
[3306] Fix | Delete
return SODIUM_LIBRARY_MAJOR_VERSION;
[3307] Fix | Delete
}
[3308] Fix | Delete
if (self::use_fallback('library_version_major')) {
[3309] Fix | Delete
/** @psalm-suppress UndefinedFunction */
[3310] Fix | Delete
return (int) call_user_func('\\Sodium\\library_version_major');
[3311] Fix | Delete
}
[3312] Fix | Delete
return self::LIBRARY_VERSION_MAJOR;
[3313] Fix | Delete
}
[3314] Fix | Delete
[3315] Fix | Delete
/**
[3316] Fix | Delete
* The equivalent to the libsodium minor version we aim to be compatible
[3317] Fix | Delete
* with (sans pwhash and memzero).
[3318] Fix | Delete
*
[3319] Fix | Delete
* @return int
[3320] Fix | Delete
*/
[3321] Fix | Delete
public static function library_version_minor()
[3322] Fix | Delete
{
[3323] Fix | Delete
if (self::useNewSodiumAPI() && defined('SODIUM_LIBRARY_MINOR_VERSION')) {
[3324] Fix | Delete
return SODIUM_LIBRARY_MINOR_VERSION;
[3325] Fix | Delete
}
[3326] Fix | Delete
if (self::use_fallback('library_version_minor')) {
[3327] Fix | Delete
/** @psalm-suppress UndefinedFunction */
[3328] Fix | Delete
return (int) call_user_func('\\Sodium\\library_version_minor');
[3329] Fix | Delete
}
[3330] Fix | Delete
return self::LIBRARY_VERSION_MINOR;
[3331] Fix | Delete
}
[3332] Fix | Delete
[3333] Fix | Delete
/**
[3334] Fix | Delete
* Compare two strings.
[3335] Fix | Delete
*
[3336] Fix | Delete
* @param string $left
[3337] Fix | Delete
* @param string $right
[3338] Fix | Delete
* @return int
[3339] Fix | Delete
* @throws SodiumException
[3340] Fix | Delete
* @throws TypeError
[3341] Fix | Delete
* @psalm-suppress MixedArgument
[3342] Fix | Delete
*/
[3343] Fix | Delete
public static function memcmp($left, $right)
[3344] Fix | Delete
{
[3345] Fix | Delete
/* Type checks: */
[3346] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($left, 'string', 1);
[3347] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($right, 'string', 2);
[3348] Fix | Delete
[3349] Fix | Delete
if (self::useNewSodiumAPI()) {
[3350] Fix | Delete
return sodium_memcmp($left, $right);
[3351] Fix | Delete
}
[3352] Fix | Delete
if (self::use_fallback('memcmp')) {
[3353] Fix | Delete
return (int) call_user_func('\\Sodium\\memcmp', $left, $right);
[3354] Fix | Delete
}
[3355] Fix | Delete
/** @var string $left */
[3356] Fix | Delete
/** @var string $right */
[3357] Fix | Delete
return ParagonIE_Sodium_Core_Util::memcmp($left, $right);
[3358] Fix | Delete
}
[3359] Fix | Delete
[3360] Fix | Delete
/**
[3361] Fix | Delete
* It's actually not possible to zero memory buffers in PHP. You need the
[3362] Fix | Delete
* native library for that.
[3363] Fix | Delete
*
[3364] Fix | Delete
* @param string|null $var
[3365] Fix | Delete
* @param-out string|null $var
[3366] Fix | Delete
*
[3367] Fix | Delete
* @return void
[3368] Fix | Delete
* @throws SodiumException (Unless libsodium is installed)
[3369] Fix | Delete
* @throws TypeError
[3370] Fix | Delete
* @psalm-suppress TooFewArguments
[3371] Fix | Delete
*/
[3372] Fix | Delete
public static function memzero(&$var)
[3373] Fix | Delete
{
[3374] Fix | Delete
/* Type checks: */
[3375] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($var, 'string', 1);
[3376] Fix | Delete
[3377] Fix | Delete
if (self::useNewSodiumAPI()) {
[3378] Fix | Delete
/** @psalm-suppress MixedArgument */
[3379] Fix | Delete
sodium_memzero($var);
[3380] Fix | Delete
return;
[3381] Fix | Delete
}
[3382] Fix | Delete
if (self::use_fallback('memzero')) {
[3383] Fix | Delete
$func = '\\Sodium\\memzero';
[3384] Fix | Delete
$func($var);
[3385] Fix | Delete
if ($var === null) {
[3386] Fix | Delete
return;
[3387] Fix | Delete
}
[3388] Fix | Delete
}
[3389] Fix | Delete
// This is the best we can do.
[3390] Fix | Delete
throw new SodiumException(
[3391] Fix | Delete
'This is not implemented in sodium_compat, as it is not possible to securely wipe memory from PHP. ' .
[3392] Fix | Delete
'To fix this error, make sure libsodium is installed and the PHP extension is enabled.'
[3393] Fix | Delete
);
[3394] Fix | Delete
}
[3395] Fix | Delete
[3396] Fix | Delete
/**
[3397] Fix | Delete
* @param string $unpadded
[3398] Fix | Delete
* @param int $blockSize
[3399] Fix | Delete
* @param bool $dontFallback
[3400] Fix | Delete
* @return string
[3401] Fix | Delete
* @throws SodiumException
[3402] Fix | Delete
*/
[3403] Fix | Delete
public static function pad($unpadded, $blockSize, $dontFallback = false)
[3404] Fix | Delete
{
[3405] Fix | Delete
/* Type checks: */
[3406] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($unpadded, 'string', 1);
[3407] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($blockSize, 'int', 2);
[3408] Fix | Delete
[3409] Fix | Delete
$unpadded = (string) $unpadded;
[3410] Fix | Delete
$blockSize = (int) $blockSize;
[3411] Fix | Delete
[3412] Fix | Delete
if (self::useNewSodiumAPI() && !$dontFallback) {
[3413] Fix | Delete
return (string) sodium_pad($unpadded, $blockSize);
[3414] Fix | Delete
}
[3415] Fix | Delete
[3416] Fix | Delete
if ($blockSize <= 0) {
[3417] Fix | Delete
throw new SodiumException(
[3418] Fix | Delete
'block size cannot be less than 1'
[3419] Fix | Delete
);
[3420] Fix | Delete
}
[3421] Fix | Delete
$unpadded_len = ParagonIE_Sodium_Core_Util::strlen($unpadded);
[3422] Fix | Delete
$xpadlen = ($blockSize - 1);
[3423] Fix | Delete
if (($blockSize & ($blockSize - 1)) === 0) {
[3424] Fix | Delete
$xpadlen -= $unpadded_len & ($blockSize - 1);
[3425] Fix | Delete
} else {
[3426] Fix | Delete
$xpadlen -= $unpadded_len % $blockSize;
[3427] Fix | Delete
}
[3428] Fix | Delete
[3429] Fix | Delete
$xpadded_len = $unpadded_len + $xpadlen;
[3430] Fix | Delete
$padded = str_repeat("\0", $xpadded_len - 1);
[3431] Fix | Delete
if ($unpadded_len > 0) {
[3432] Fix | Delete
$st = 1;
[3433] Fix | Delete
$i = 0;
[3434] Fix | Delete
$k = $unpadded_len;
[3435] Fix | Delete
for ($j = 0; $j <= $xpadded_len; ++$j) {
[3436] Fix | Delete
$i = (int) $i;
[3437] Fix | Delete
$k = (int) $k;
[3438] Fix | Delete
$st = (int) $st;
[3439] Fix | Delete
if ($j >= $unpadded_len) {
[3440] Fix | Delete
$padded[$j] = "\0";
[3441] Fix | Delete
} else {
[3442] Fix | Delete
$padded[$j] = $unpadded[$j];
[3443] Fix | Delete
}
[3444] Fix | Delete
/** @var int $k */
[3445] Fix | Delete
$k -= $st;
[3446] Fix | Delete
$st = (int) (~(
[3447] Fix | Delete
(
[3448] Fix | Delete
(
[3449] Fix | Delete
($k >> 48)
[3450] Fix | Delete
|
[3451] Fix | Delete
($k >> 32)
[3452] Fix | Delete
|
[3453] Fix | Delete
($k >> 16)
[3454] Fix | Delete
|
[3455] Fix | Delete
$k
[3456] Fix | Delete
) - 1
[3457] Fix | Delete
) >> 16
[3458] Fix | Delete
)
[3459] Fix | Delete
) & 1;
[3460] Fix | Delete
$i += $st;
[3461] Fix | Delete
}
[3462] Fix | Delete
}
[3463] Fix | Delete
[3464] Fix | Delete
$mask = 0;
[3465] Fix | Delete
$tail = $xpadded_len;
[3466] Fix | Delete
for ($i = 0; $i < $blockSize; ++$i) {
[3467] Fix | Delete
# barrier_mask = (unsigned char)
[3468] Fix | Delete
# (((i ^ xpadlen) - 1U) >> ((sizeof(size_t) - 1U) * CHAR_BIT));
[3469] Fix | Delete
$barrier_mask = (($i ^ $xpadlen) -1) >> ((PHP_INT_SIZE << 3) - 1);
[3470] Fix | Delete
# tail[-i] = (tail[-i] & mask) | (0x80 & barrier_mask);
[3471] Fix | Delete
$padded[$tail - $i] = ParagonIE_Sodium_Core_Util::intToChr(
[3472] Fix | Delete
(ParagonIE_Sodium_Core_Util::chrToInt($padded[$tail - $i]) & $mask)
[3473] Fix | Delete
|
[3474] Fix | Delete
(0x80 & $barrier_mask)
[3475] Fix | Delete
);
[3476] Fix | Delete
# mask |= barrier_mask;
[3477] Fix | Delete
$mask |= $barrier_mask;
[3478] Fix | Delete
}
[3479] Fix | Delete
return $padded;
[3480] Fix | Delete
}
[3481] Fix | Delete
[3482] Fix | Delete
/**
[3483] Fix | Delete
* @param string $padded
[3484] Fix | Delete
* @param int $blockSize
[3485] Fix | Delete
* @param bool $dontFallback
[3486] Fix | Delete
* @return string
[3487] Fix | Delete
* @throws SodiumException
[3488] Fix | Delete
*/
[3489] Fix | Delete
public static function unpad($padded, $blockSize, $dontFallback = false)
[3490] Fix | Delete
{
[3491] Fix | Delete
/* Type checks: */
[3492] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($padded, 'string', 1);
[3493] Fix | Delete
ParagonIE_Sodium_Core_Util::declareScalarType($blockSize, 'int', 2);
[3494] Fix | Delete
[3495] Fix | Delete
$padded = (string) $padded;
[3496] Fix | Delete
$blockSize = (int) $blockSize;
[3497] Fix | Delete
[3498] Fix | Delete
if (self::useNewSodiumAPI() && !$dontFallback) {
[3499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function