|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace MLS\Enums; |
| 6 | + |
| 7 | +/** |
| 8 | + * Epoch-derived secrets (RFC 9420 - Table 4) |
| 9 | + */ |
| 10 | +final class EpochSecrets |
| 11 | +{ |
| 12 | + public const SENDER_DATA = 'sender data'; |
| 13 | + public const ENCRYPTION = 'encryption'; |
| 14 | + public const EXPORTER = 'exporter'; |
| 15 | + public const EXTERNAL = 'external'; |
| 16 | + public const CONFIRM = 'confirm'; |
| 17 | + public const MEMBERSHIP = 'membership'; |
| 18 | + public const RESUMPTION = 'resumption'; |
| 19 | + public const AUTHENTICATION = 'authentication'; |
| 20 | + |
| 21 | + protected const SECRET_NAME = [ |
| 22 | + self::SENDER_DATA => 'sender_data', |
| 23 | + self::ENCRYPTION => 'encryption_secret', |
| 24 | + self::EXPORTER => 'exporter_secret', |
| 25 | + self::EXTERNAL => 'external_secret', |
| 26 | + self::CONFIRM => 'confirmation_key', |
| 27 | + self::MEMBERSHIP => 'membership_key', |
| 28 | + self::RESUMPTION => 'resumption_psk', |
| 29 | + self::AUTHENTICATION => 'epoch_authenticator', |
| 30 | + ]; |
| 31 | + |
| 32 | + protected const PURPOSE = [ |
| 33 | + self::SENDER_DATA => 'Deriving keys to encrypt sender data', |
| 34 | + self::ENCRYPTION => 'Deriving message encryption keys (via the secret tree)', |
| 35 | + self::EXPORTER => 'Deriving exported secrets', |
| 36 | + self::EXTERNAL => 'Deriving the external init key', |
| 37 | + self::CONFIRM => 'Computing the confirmation MAC for an epoch', |
| 38 | + self::MEMBERSHIP => 'Computing the membership MAC for a PublicMessage', |
| 39 | + self::RESUMPTION => 'Proving membership in this epoch (via a PSK injected later)', |
| 40 | + self::AUTHENTICATION => 'Confirming that two clients have the same view of the group', |
| 41 | + ]; |
| 42 | + |
| 43 | + public function __construct() |
| 44 | + { |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Return all labels as defined in Table 4. |
| 49 | + * |
| 50 | + * @return string[] |
| 51 | + */ |
| 52 | + public static function labels(): array |
| 53 | + { |
| 54 | + return array_keys(self::SECRET_NAME); |
| 55 | + } |
| 56 | + |
| 57 | + public static function secretNameOf(string $label): ?string |
| 58 | + { |
| 59 | + return self::SECRET_NAME[$label] ?? null; |
| 60 | + } |
| 61 | + |
| 62 | + public static function purposeOf(string $label): ?string |
| 63 | + { |
| 64 | + return self::PURPOSE[$label] ?? null; |
| 65 | + } |
| 66 | +} |
0 commit comments