| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
if (class_exists('ParagonIE_Sodium_Core_XSalsa20', false)) { |
| 5 |
return; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
abstract class ParagonIE_Sodium_Core_XSalsa20 extends ParagonIE_Sodium_Core_HSalsa20 |
| 12 |
{ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 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 |
} |