public static function ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic in Automatic Updates 7
Same name and namespace in other branches
- 8 vendor/paragonie/sodium_compat/src/Core/Salsa20.php \ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic()
@internal You should not use this directly from another application
Parameters
string $m:
string $n:
int $ic:
string $k:
Return value
string
Throws
SodiumException
TypeError
4 calls to ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic()
- ParagonIE_Sodium_Crypto::secretbox in vendor/
paragonie/ sodium_compat/ src/ Crypto.php - XSalsa20-Poly1305 authenticated symmetric-key encryption.
- ParagonIE_Sodium_Crypto::secretbox_open in vendor/
paragonie/ sodium_compat/ src/ Crypto.php - Decrypt a ciphertext generated via secretbox().
- ParagonIE_Sodium_File::secretbox_decrypt in vendor/
paragonie/ sodium_compat/ src/ File.php - Decrypt a file
- ParagonIE_Sodium_File::secretbox_encrypt in vendor/
paragonie/ sodium_compat/ src/ File.php - Encrypt a file
File
- vendor/
paragonie/ sodium_compat/ src/ Core/ Salsa20.php, line 186
Class
- ParagonIE_Sodium_Core_Salsa20
- Class ParagonIE_Sodium_Core_Salsa20
Code
public static function salsa20_xor_ic($m, $n, $ic, $k) {
$mlen = self::strlen($m);
if ($mlen < 1) {
return '';
}
$kcopy = self::substr($k, 0, 32);
$in = self::substr($n, 0, 8);
// Initialize the counter
$in .= ParagonIE_Sodium_Core_Util::store64_le($ic);
$c = '';
while ($mlen >= 64) {
$block = self::core_salsa20($in, $kcopy, null);
$c .= self::xorStrings(self::substr($m, 0, 64), self::substr($block, 0, 64));
$u = 1;
for ($i = 8; $i < 16; ++$i) {
$u += self::chrToInt($in[$i]);
$in[$i] = self::intToChr($u & 0xff);
$u >>= 8;
}
$mlen -= 64;
$m = self::substr($m, 64);
}
if ($mlen) {
$block = self::core_salsa20($in, $kcopy, null);
$c .= self::xorStrings(self::substr($m, 0, $mlen), self::substr($block, 0, $mlen));
}
try {
ParagonIE_Sodium_Compat::memzero($block);
ParagonIE_Sodium_Compat::memzero($kcopy);
} catch (SodiumException $ex) {
$block = null;
$kcopy = null;
}
return $c;
}