1<?php
2
3if (class_exists('ParagonIE_Sodium_Core32_XSalsa20', false)) {
4 return;
5}
6
7/**
8 * Class ParagonIE_Sodium_Core32_XSalsa20
9 */
10abstract class ParagonIE_Sodium_Core32_XSalsa20 extends ParagonIE_Sodium_Core32_HSalsa20
11{
12 /**
13 * Expand a key and nonce into an xsalsa20 keystream.
14 *
15 * @internal You should not use this directly from another application
16 *
17 * @param int $len
18 * @param string $nonce
19 * @param string $key
20 * @return string
21 * @throws SodiumException
22 * @throws TypeError
23 */
24 public static function xsalsa20($len, $nonce, $key)
25 {
26 $ret = self::salsa20(
27 $len,
28 self::substr($nonce, 16, 8),
29 self::hsalsa20($nonce, $key)
30 );
31 return $ret;
32 }
33
34 /**
35 * Encrypt a string with XSalsa20. Doesn't provide integrity.
36 *
37 * @internal You should not use this directly from another application
38 *
39 * @param string $message
40 * @param string $nonce
41 * @param string $key
42 * @return string
43 * @throws SodiumException
44 * @throws TypeError
45 */
46 public static function xsalsa20_xor($message, $nonce, $key)
47 {
48 return self::xorStrings(
49 $message,
50 self::xsalsa20(
51 self::strlen($message),
52 $nonce,
53 $key
54 )
55 );
56 }
57}
58