|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace MLS\Enums; |
| 6 | + |
| 7 | +/** |
| 8 | + * MLS Cipher Suites (RFC 9420 - Section 17.1, Tables 6 & 7) |
| 9 | + */ |
| 10 | +final class CipherSuite |
| 11 | +{ |
| 12 | + public const RESERVED = 0x0000; |
| 13 | + |
| 14 | + public const MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 = 0x0001; |
| 15 | + public const MLS_128_DHKEMP256_AES128GCM_SHA256_P256 = 0x0002; |
| 16 | + public const MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 = 0x0003; |
| 17 | + public const MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448 = 0x0004; |
| 18 | + public const MLS_256_DHKEMP521_AES256GCM_SHA512_P521 = 0x0005; |
| 19 | + public const MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 = 0x0006; |
| 20 | + public const MLS_256_DHKEMP384_AES256GCM_SHA384_P384 = 0x0007; |
| 21 | + |
| 22 | + // GREASE values |
| 23 | + public const GREASE_0A0A = 0x0A0A; |
| 24 | + public const GREASE_1A1A = 0x1A1A; |
| 25 | + public const GREASE_2A2A = 0x2A2A; |
| 26 | + public const GREASE_3A3A = 0x3A3A; |
| 27 | + public const GREASE_4A4A = 0x4A4A; |
| 28 | + public const GREASE_5A5A = 0x5A5A; |
| 29 | + public const GREASE_6A6A = 0x6A6A; |
| 30 | + public const GREASE_7A7A = 0x7A7A; |
| 31 | + public const GREASE_8A8A = 0x8A8A; |
| 32 | + public const GREASE_9A9A = 0x9A9A; |
| 33 | + public const GREASE_AAAA = 0xAAAA; |
| 34 | + public const GREASE_BABA = 0xBABA; |
| 35 | + public const GREASE_CACA = 0xCACA; |
| 36 | + public const GREASE_DADA = 0xDADA; |
| 37 | + public const GREASE_EAEA = 0xEAEA; |
| 38 | + |
| 39 | + public const PRIVATE_USE_START = 0xF000; |
| 40 | + public const PRIVATE_USE_END = 0xFFFF; |
| 41 | + |
| 42 | + protected const NAME_MAP = [ |
| 43 | + self::RESERVED => 'reserved', |
| 44 | + self::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 => 'MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519', |
| 45 | + self::MLS_128_DHKEMP256_AES128GCM_SHA256_P256 => 'MLS_128_DHKEMP256_AES128GCM_SHA256_P256', |
| 46 | + self::MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 => 'MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519', |
| 47 | + self::MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448 => 'MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448', |
| 48 | + self::MLS_256_DHKEMP521_AES256GCM_SHA512_P521 => 'MLS_256_DHKEMP521_AES256GCM_SHA512_P521', |
| 49 | + self::MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 => 'MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448', |
| 50 | + self::MLS_256_DHKEMP384_AES256GCM_SHA384_P384 => 'MLS_256_DHKEMP384_AES256GCM_SHA384_P384', |
| 51 | + self::GREASE_0A0A => 'grease_0a0a', |
| 52 | + self::GREASE_1A1A => 'grease_1a1a', |
| 53 | + self::GREASE_2A2A => 'grease_2a2a', |
| 54 | + self::GREASE_3A3A => 'grease_3a3a', |
| 55 | + self::GREASE_4A4A => 'grease_4a4a', |
| 56 | + self::GREASE_5A5A => 'grease_5a5a', |
| 57 | + self::GREASE_6A6A => 'grease_6a6a', |
| 58 | + self::GREASE_7A7A => 'grease_7a7a', |
| 59 | + self::GREASE_8A8A => 'grease_8a8a', |
| 60 | + self::GREASE_9A9A => 'grease_9a9a', |
| 61 | + self::GREASE_AAAA => 'grease_aaaa', |
| 62 | + self::GREASE_BABA => 'grease_baba', |
| 63 | + self::GREASE_CACA => 'grease_caca', |
| 64 | + self::GREASE_DADA => 'grease_dada', |
| 65 | + self::GREASE_EAEA => 'grease_eaea', |
| 66 | + ]; |
| 67 | + |
| 68 | + // Recommended flags per registry (true = recommended) |
| 69 | + protected const RECOMMENDED = [ |
| 70 | + self::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 => true, |
| 71 | + self::MLS_128_DHKEMP256_AES128GCM_SHA256_P256 => true, |
| 72 | + self::MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 => true, |
| 73 | + self::MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448 => true, |
| 74 | + self::MLS_256_DHKEMP521_AES256GCM_SHA512_P521 => true, |
| 75 | + self::MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 => true, |
| 76 | + self::MLS_256_DHKEMP384_AES256GCM_SHA384_P384 => true, |
| 77 | + self::GREASE_0A0A => true, |
| 78 | + self::GREASE_1A1A => true, |
| 79 | + self::GREASE_2A2A => true, |
| 80 | + self::GREASE_3A3A => true, |
| 81 | + self::GREASE_4A4A => true, |
| 82 | + self::GREASE_5A5A => true, |
| 83 | + self::GREASE_6A6A => true, |
| 84 | + self::GREASE_7A7A => true, |
| 85 | + self::GREASE_8A8A => true, |
| 86 | + self::GREASE_9A9A => true, |
| 87 | + self::GREASE_AAAA => true, |
| 88 | + self::GREASE_BABA => true, |
| 89 | + self::GREASE_CACA => true, |
| 90 | + self::GREASE_DADA => true, |
| 91 | + self::GREASE_EAEA => true, |
| 92 | + ]; |
| 93 | + |
| 94 | + // Component mapping per cipher suite (Table 7) |
| 95 | + protected const COMPONENTS = [ |
| 96 | + self::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 => [ |
| 97 | + 'kem' => 0x0020, |
| 98 | + 'kdf' => 0x0001, |
| 99 | + 'aead' => 0x0001, |
| 100 | + 'hash' => 'SHA256', |
| 101 | + 'signature' => 'ed25519', |
| 102 | + ], |
| 103 | + self::MLS_128_DHKEMP256_AES128GCM_SHA256_P256 => [ |
| 104 | + 'kem' => 0x0010, |
| 105 | + 'kdf' => 0x0001, |
| 106 | + 'aead' => 0x0001, |
| 107 | + 'hash' => 'SHA256', |
| 108 | + 'signature' => 'ecdsa_secp256r1_sha256', |
| 109 | + ], |
| 110 | + self::MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 => [ |
| 111 | + 'kem' => 0x0020, |
| 112 | + 'kdf' => 0x0001, |
| 113 | + 'aead' => 0x0003, |
| 114 | + 'hash' => 'SHA256', |
| 115 | + 'signature' => 'ed25519', |
| 116 | + ], |
| 117 | + self::MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448 => [ |
| 118 | + 'kem' => 0x0021, |
| 119 | + 'kdf' => 0x0003, |
| 120 | + 'aead' => 0x0002, |
| 121 | + 'hash' => 'SHA512', |
| 122 | + 'signature' => 'ed448', |
| 123 | + ], |
| 124 | + self::MLS_256_DHKEMP521_AES256GCM_SHA512_P521 => [ |
| 125 | + 'kem' => 0x0012, |
| 126 | + 'kdf' => 0x0003, |
| 127 | + 'aead' => 0x0002, |
| 128 | + 'hash' => 'SHA512', |
| 129 | + 'signature' => 'ecdsa_secp521r1_sha512', |
| 130 | + ], |
| 131 | + self::MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 => [ |
| 132 | + 'kem' => 0x0021, |
| 133 | + 'kdf' => 0x0003, |
| 134 | + 'aead' => 0x0003, |
| 135 | + 'hash' => 'SHA512', |
| 136 | + 'signature' => 'ed448', |
| 137 | + ], |
| 138 | + self::MLS_256_DHKEMP384_AES256GCM_SHA384_P384 => [ |
| 139 | + 'kem' => 0x0011, |
| 140 | + 'kdf' => 0x0002, |
| 141 | + 'aead' => 0x0002, |
| 142 | + 'hash' => 'SHA384', |
| 143 | + 'signature' => 'ecdsa_secp384r1_sha384', |
| 144 | + ], |
| 145 | + ]; |
| 146 | + |
| 147 | + private function __construct() |
| 148 | + { |
| 149 | + } |
| 150 | + |
| 151 | + public static function nameOf(int $value): ?string |
| 152 | + { |
| 153 | + if (isset(self::NAME_MAP[$value])) { |
| 154 | + return self::NAME_MAP[$value]; |
| 155 | + } |
| 156 | + |
| 157 | + if ($value >= self::PRIVATE_USE_START && $value <= self::PRIVATE_USE_END) { |
| 158 | + return 'private_use'; |
| 159 | + } |
| 160 | + |
| 161 | + return null; |
| 162 | + } |
| 163 | + |
| 164 | + public static function isRecommended(int $value): ?bool |
| 165 | + { |
| 166 | + return self::RECOMMENDED[$value] ?? null; |
| 167 | + } |
| 168 | + |
| 169 | + public static function isPrivateUse(int $value): bool |
| 170 | + { |
| 171 | + return $value >= self::PRIVATE_USE_START && $value <= self::PRIVATE_USE_END; |
| 172 | + } |
| 173 | + |
| 174 | + public static function componentsOf(int $value): ?array |
| 175 | + { |
| 176 | + return self::COMPONENTS[$value] ?? null; |
| 177 | + } |
| 178 | + |
| 179 | + public static function kemOf(int $value): ?int |
| 180 | + { |
| 181 | + return isset(self::COMPONENTS[$value]) ? self::COMPONENTS[$value]['kem'] : null; |
| 182 | + } |
| 183 | + |
| 184 | + public static function kdfOf(int $value): ?int |
| 185 | + { |
| 186 | + return isset(self::COMPONENTS[$value]) ? self::COMPONENTS[$value]['kdf'] : null; |
| 187 | + } |
| 188 | + |
| 189 | + public static function aeadOf(int $value): ?int |
| 190 | + { |
| 191 | + return isset(self::COMPONENTS[$value]) ? self::COMPONENTS[$value]['aead'] : null; |
| 192 | + } |
| 193 | + |
| 194 | + public static function hashOf(int $value): ?string |
| 195 | + { |
| 196 | + return isset(self::COMPONENTS[$value]) ? self::COMPONENTS[$value]['hash'] : null; |
| 197 | + } |
| 198 | + |
| 199 | + public static function signatureOf(int $value): ?string |
| 200 | + { |
| 201 | + return isset(self::COMPONENTS[$value]) ? self::COMPONENTS[$value]['signature'] : null; |
| 202 | + } |
| 203 | +} |
0 commit comments