You are here

public static function ParagonIE_Sodium_Core32_Salsa20::salsa20_xor_ic in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core32/Salsa20.php \ParagonIE_Sodium_Core32_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_Core32_Salsa20::salsa20_xor_ic()
ParagonIE_Sodium_Crypto32::secretbox in vendor/paragonie/sodium_compat/src/Crypto32.php
XSalsa20-Poly1305 authenticated symmetric-key encryption.
ParagonIE_Sodium_Crypto32::secretbox_open in vendor/paragonie/sodium_compat/src/Crypto32.php
Decrypt a ciphertext generated via secretbox().
ParagonIE_Sodium_File::secretbox_decrypt_core32 in vendor/paragonie/sodium_compat/src/File.php
Decrypt a file (32-bit)
ParagonIE_Sodium_File::secretbox_encrypt_core32 in vendor/paragonie/sodium_compat/src/File.php
Encrypt a file (32-bit)

File

vendor/paragonie/sodium_compat/src/Core32/Salsa20.php, line 238

Class

ParagonIE_Sodium_Core32_Salsa20
Class ParagonIE_Sodium_Core32_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_Core32_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;
}