Debian Codegraph @

lib/3rdParty/composer/paragonie/sodium_compat/src/Core/XSalsa20.php

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