| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
if (class_exists('ParagonIE_Sodium_Core_Poly1305', false)) { |
| 5 |
return; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
abstract class ParagonIE_Sodium_Core_Poly1305 extends ParagonIE_Sodium_Core_Util |
| 12 |
{ |
| 13 |
const BLOCK_SIZE = 16; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public static function onetimeauth( |
| 25 |
string $m, |
| 26 |
#[SensitiveParameter] |
| 27 |
string $key |
| 28 |
): string { |
| 29 |
if (self::strlen($key) < 32) { |
| 30 |
throw new InvalidArgumentException( |
| 31 |
'Key must be 32 bytes long.' |
| 32 |
); |
| 33 |
} |
| 34 |
$state = new ParagonIE_Sodium_Core_Poly1305_State( |
| 35 |
self::substr($key, 0, 32) |
| 36 |
); |
| 37 |
return $state |
| 38 |
->update($m) |
| 39 |
->finish(); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static function onetimeauth_verify( |
| 53 |
string $mac, |
| 54 |
string $m, |
| 55 |
#[SensitiveParameter] |
| 56 |
string $key |
| 57 |
): bool { |
| 58 |
if (self::strlen($key) !== 32) { |
| 59 |
throw new InvalidArgumentException( |
| 60 |
'Key must be 32 bytes long.' |
| 61 |
); |
| 62 |
} |
| 63 |
$state = new ParagonIE_Sodium_Core_Poly1305_State( |
| 64 |
self::substr($key, 0, 32) |
| 65 |
); |
| 66 |
$calc = $state |
| 67 |
->update($m) |
| 68 |
->finish(); |
| 69 |
return self::verify_16($calc, $mac); |
| 70 |
} |
| 71 |
} |