Debian Codegraph @

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

raw symbols SCIP
1 <?php
2 declare(strict_types=1);
3
4 if (class_exists('ParagonIE_Sodium_Core_Poly1305', false)) {
5 return;
6 }
7
8 /**
9 * Class ParagonIE_Sodium_Core_Poly1305
10 */
11 abstract class ParagonIE_Sodium_Core_Poly1305 extends ParagonIE_Sodium_Core_Util
12 {
13 const BLOCK_SIZE = 16;
14
15 /**
16 * @internal You should not use this directly from another application
17 *
18 * @param string $m
19 * @param string $key
20 * @return string
21 * @throws SodiumException
22 * @throws TypeError
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 * @internal You should not use this directly from another application
44 *
45 * @param string $mac
46 * @param string $m
47 * @param string $key
48 * @return bool
49 * @throws SodiumException
50 * @throws TypeError
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 }