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