public static function salsa20($len,
$nonce,
$key) { if (self::
strlen($key) !== 32
) { throw new RangeException('Key must be 32 bytes long'
);
} $kcopy = '' .
$key;
$in = self::
substr($nonce, 0, 8
) .
str_repeat("\0", 8
);
$c = '';
while ($len >= 64
) { $c .= self::
core_salsa20($in,
$kcopy, null
);
$u = 1;
// Internal counter.
for ($i = 8;
$i < 16; ++
$i) { $u += self::
chrToInt($in[$i]);
$in[$i] = self::
intToChr($u & 0xff
);
$u >>= 8;
} $len -= 64;
} if ($len > 0
) { $c .= self::
substr(