Debian Codegraph @

mlspp/src/state.cpp

raw symbols SCIP
1 #cxx . . $ `<file>/mlspp/src/state.cpp`/include <mls/state.h>cxx . . $ `<file>/mlspp/include/mls/state.h`/
2 #include <set>
3
4 namespace mlsppcxx . . $ mlspp/ {
5
6 ///
7 /// Constructors
8 ///
9
10 Statecxx . . $ mlspp/State#::Statecxx . . $ mlspp/State#State(5c99977e15e97b35).(bytescxx . . $ mlspp/bytes_ns/bytes# group_id,
11 CipherSuitecxx . . $ mlspp/CipherSuite# suite,
12 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# enc_priv,
13 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
14 const LeafNodecxx . . $ mlspp/LeafNode#& leaf_node,
15 ExtensionListcxx . . $ mlspp/ExtensionList# extensions)
16 : _suitecxx . . $ mlspp/State#_suite.(suite)
17 , _group_idcxx . . $ mlspp/State#_group_id.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(group_id))
18 , _epochcxx . . $ mlspp/State#_epoch.(0)
19 , _treecxx . . $ mlspp/State#_tree.(suite)
20 , _transcript_hashcxx . . $ mlspp/State#_transcript_hash.(suite)
21 , _extensionscxx . . $ mlspp/State#_extensions.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(extensions))
22 , _indexcxx . . $ mlspp/State#_index.(0)
23 , _identity_privcxx . . $ mlspp/State#_identity_priv.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv))
24 {
25 // Verify that the client supports the proposed group extensions
26 if (!leaf_node.verify_extension_supportcxx . . $ mlspp/LeafNode#verify_extension_support(b1d6012e28b23e89).(_extensionscxx . . $ mlspp/State#_extensions.)) {
27 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Client doesn't support required extensions");
28 }
29
30 _indexcxx . . $ mlspp/State#_index. =cxx . . $ mlspp/LeafIndex#`operator=`(f64f93d71b0bc387). _treecxx . . $ mlspp/State#_tree..add_leafcxx . . $ mlspp/TreeKEMPublicKey#add_leaf(9995a7bfeddd280).(leaf_node);
31 _treecxx . . $ mlspp/State#_tree..set_hash_allcxx . . $ mlspp/TreeKEMPublicKey#set_hash_all(49f6e7a06ebc5aa8).();
32 _tree_privcxx . . $ mlspp/State#_tree_priv. =cxx . . $ mlspp/TreeKEMPrivateKey#`operator=`(7212344ec6a145a). TreeKEMPrivateKeycxx . . $ mlspp/TreeKEMPrivateKey#::solocxx . . $ mlspp/TreeKEMPrivateKey#solo(314639de3ba28cb).(suite, _indexcxx . . $ mlspp/State#_index., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(enc_priv));
33 if (!_tree_privcxx . . $ mlspp/State#_tree_priv..consistentcxx . . $ mlspp/TreeKEMPrivateKey#consistent(eaed869e1938a2dc).(_treecxx . . $ mlspp/State#_tree.)) {
34 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("LeafNode inconsistent with private key");
35 }
36
37 // XXX(RLB): Convert KeyScheduleEpoch to take GroupContext?
38 auto ctx = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(group_contextcxx . . $ mlspp/State#group_context(da187bf767f0d89d).());
39 _key_schedulecxx . . $ mlspp/State#_key_schedule. =cxx . . $ mlspp/KeyScheduleEpoch#`operator=`(8ef62e844b63fcc6).
40 KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#KeyScheduleEpoch(e9b6b1168c720405).(_suitecxx . . $ mlspp/State#_suite., random_bytescxx . . $ mlspp/random_bytes(b7161179e0ed6f95).(_suitecxx . . $ mlspp/State#_suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()), ctxcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
41 _keyscxx . . $ mlspp/State#_keys. =cxx . . $ mlspp/GroupKeySource#`operator=`(9bdcbd6beff8640f). _key_schedulecxx . . $ mlspp/State#_key_schedule..encryption_keyscxx . . $ mlspp/KeyScheduleEpoch#encryption_keys(578ffb7a4920202).(_treecxx . . $ mlspp/State#_tree..sizecxx . . $ mlspp/TreeKEMPublicKey#size.);
42
43 // Update the interim transcript hash with a virtual confirmation tag
44 _transcript_hashcxx . . $ mlspp/State#_transcript_hash..update_interimcxx . . $ mlspp/TranscriptHash#update_interim(68ca607eebb5be3e).(
45 _key_schedulecxx . . $ mlspp/State#_key_schedule..confirmation_tagcxx . . $ mlspp/KeyScheduleEpoch#confirmation_tag(c5e1b85e16e94921).(_transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.));
46 }
47
48 TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#
49 Statecxx . . $ mlspp/State#::import_treecxx . . $ mlspp/State#import_tree(485acda75e27d34f).(const bytescxx . . $ mlspp/bytes_ns/bytes#& tree_hash,
50 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#>& external,
51 const ExtensionListcxx . . $ mlspp/ExtensionList#& extensions)
52 {
53 auto tree = TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#TreeKEMPublicKey(1ae84ca71f879861).(_suitecxx . . $ mlspp/State#_suite.);
54 auto maybe_tree_extn = extensions.findcxx . . $ mlspp/ExtensionList#find(af95876f91a4b24c).<RatchetTreeExtensioncxx . . $ mlspp/RatchetTreeExtension#>();
55 if (external) {
56 tree =cxx . . $ mlspp/TreeKEMPublicKey#`operator=`(86f12d805300c086). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(external);
57 } else if (maybe_tree_extn) {
58 tree =cxx . . $ mlspp/TreeKEMPublicKey#`operator=`(86f12d805300c086). opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_tree_extn).treecxx . . $ mlspp/RatchetTreeExtension#tree.;
59 } else {
60 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("No tree available");
61 }
62
63 tree.suitecxx . . $ mlspp/TreeKEMPublicKey#suite. =cxx . . $ mlspp/CipherSuite#`operator=`(340e757a5e955ecc). _suitecxx . . $ mlspp/State#_suite.;
64
65 tree.set_hash_allcxx . . $ mlspp/TreeKEMPublicKey#set_hash_all(49f6e7a06ebc5aa8).();
66 if (tree.root_hashcxx . . $ mlspp/TreeKEMPublicKey#root_hash(d7392ba79aa35767).() !=cxx . . $ mlspp/bytes_ns/bytes#`operator!=`(efd4f3c976ab92ce). tree_hash) {
67 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Tree does not match GroupInfo");
68 }
69
70 return treecxx . . $ mlspp/TreeKEMPublicKey#TreeKEMPublicKey(f88decadefb06a69).;
71 }
72
73 bool
74 Statecxx . . $ mlspp/State#::validate_treecxx . . $ mlspp/State#validate_tree(50ce9a9e25b4a850).() const
75 {
76 // The functionality here is somewhat duplicative of State::valid(const
77 // LeafNode&). Simply calling that method, however, would result in this
78 // method having quadratic scaling, since each call to valid() does a linear
79 // scan through the tree to check uniqueness of keys and compatibility of
80 // credential support.
81
82 // Validate that the tree is parent-hash valid
83 if (!_treecxx . . $ mlspp/State#_tree..parent_hash_validcxx . . $ mlspp/TreeKEMPublicKey#parent_hash_valid(50ce9a9e25b4a850).()) {
84 return false;
85 }
86
87 // Validate the signatures on all leaves
88 const auto signature_valid =
89 _treecxx . . $ mlspp/State#_tree..all_leavescxx . . $ mlspp/TreeKEMPublicKey#all_leaves(8877ebe272b9620d).([&](auto i, const auto& leaf_node) {
90 auto binding = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<LeafNodecxx . . $ mlspp/LeafNode#::MemberBindingcxx . . $ mlspp/LeafNode#MemberBinding#>{};
91 switch (leaf_node.source()) {
92 case LeafNodeSourcecxx . . $ mlspp/LeafNodeSource#::commitcxx . . $ mlspp/LeafNodeSource#commit.:
93 case LeafNodeSourcecxx . . $ mlspp/LeafNodeSource#::updatecxx . . $ mlspp/LeafNodeSource#update.:
94 binding =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). LeafNodecxx . . $ mlspp/LeafNode#::MemberBindingcxx . . $ mlspp/LeafNode#MemberBinding#{ _group_idcxx . . $ mlspp/State#_group_id., i };
95 break;
96
97 default:
98 // Nothing to do
99 break;
100 }
101
102 return leaf_node.verify(_suitecxx . . $ mlspp/State#_suite., binding);
103 });
104 if (!signature_valid) {
105 return false;
106 }
107
108 // Collect cross-tree properties
109 auto n_leaves = size_t(0);
110 auto encryption_keys = stdcxx . . $ std/set#set(49f6e7a06ebc5aa8).::setcxx . . $ std/set#<bytescxx . . $ mlspp/bytes_ns/bytes#>{};
111 auto signature_keys = stdcxx . . $ std/set#set(49f6e7a06ebc5aa8).::setcxx . . $ std/set#<bytescxx . . $ mlspp/bytes_ns/bytes#>{};
112 auto credential_types = stdcxx . . $ std/set#set(49f6e7a06ebc5aa8).::setcxx . . $ std/set#<CredentialTypecxx . . $ mlspp/CredentialType#>{};
113 _treecxx . . $ mlspp/State#_tree..all_leavescxx . . $ mlspp/TreeKEMPublicKey#all_leaves(8877ebe272b9620d).([&](auto /* i */, const auto& leaf_node) {
114 n_leaves += 1;
115 encryption_keys.insertcxx . . $ std/set#insert(411a10a755068dfe).(leaf_node.encryption_key.data);
116 signature_keys.insertcxx . . $ std/set#insert(411a10a755068dfe).(leaf_node.signature_key.data);
117 credential_types.insertcxx . . $ std/set#insert(10916b2dbd511ba8).(leaf_node.credential.type());
118 return true;
119 });
120
121 // Verify uniqueness of keys
122 if (encryption_keys.sizecxx . . $ std/set#size(fa801f5ac5d26b4e).() != n_leaves) {
123 return false;
124 }
125
126 if (signature_keys.sizecxx . . $ std/set#size(fa801f5ac5d26b4e).() != n_leaves) {
127 return false;
128 }
129
130 // Verify that each leaf indicates support for all required parameters
131 return _treecxx . . $ mlspp/State#_tree..all_leavescxx . . $ mlspp/TreeKEMPublicKey#all_leaves(8877ebe272b9620d).([&](auto /* i */, const auto& leaf_node) {
132 const auto supports_group_extensions =
133 leaf_node.verify_extension_support(_extensionscxx . . $ mlspp/State#_extensions.);
134 const auto supports_own_extensions =
135 leaf_node.verify_extension_support(leaf_node.extensions);
136 const auto supports_group_credentials =
137 leaf_node.capabilities.credentials_supported(credential_types);
138 return supports_group_extensions && supports_own_extensions &&
139 supports_group_credentials;
140 });
141 }
142
143 Statecxx . . $ mlspp/State#::Statecxx . . $ mlspp/State#State(98680997732888de).(SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
144 const GroupInfocxx . . $ mlspp/GroupInfo#& group_info,
145 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#>& tree)
146 : _suitecxx . . $ mlspp/State#_suite.(group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..cipher_suitecxx . . $ mlspp/GroupContext#cipher_suite.)
147 , _group_idcxx . . $ mlspp/State#_group_id.(group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..group_idcxx . . $ mlspp/GroupContext#group_id.)
148 , _epochcxx . . $ mlspp/State#_epoch.(group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..epochcxx . . $ mlspp/GroupContext#epoch.)
149 , _treecxx . . $ mlspp/State#_tree.(import_treecxx . . $ mlspp/State#import_tree(485acda75e27d34f).(group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..tree_hashcxx . . $ mlspp/GroupContext#tree_hash.,
150 tree,
151 group_info.extensionscxx . . $ mlspp/GroupInfo#extensions.))
152 , _transcript_hashcxx . . $ mlspp/State#_transcript_hash.(_suitecxx . . $ mlspp/State#_suite.,
153 group_infocxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..group_contextcxx . . $ mlspp/GroupInfo#group_context..confirmed_transcript_hashcxx . . $ mlspp/GroupContext#confirmed_transcript_hash.,
154 group_info.confirmation_tagcxx . . $ mlspp/GroupInfo#confirmation_tag.)
155 , _extensionscxx . . $ mlspp/State#_extensions.(group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..extensionscxx . . $ mlspp/GroupContext#extensions.)
156 , _key_schedulecxx . . $ mlspp/State#_key_schedule.(_suitecxx . . $ mlspp/State#_suite.)
157 , _indexcxx . . $ mlspp/State#_index.(0)
158 , _identity_privcxx . . $ mlspp/State#_identity_priv.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv))
159 {
160 if (!validate_treecxx . . $ mlspp/State#validate_tree(50ce9a9e25b4a850).()) {
161 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid tree");
162 }
163
164 // The following are not set:
165 // _index
166 // _tree_priv
167 //
168 // This ctor should only be used within external_commit, in which case these
169 // fields are populated by the subsequent commit()
170 }
171
172 // Initialize a group from a Welcome
173 Statecxx . . $ mlspp/State#::Statecxx . . $ mlspp/State#State(b37a46165eb9ffa8).(const HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#& init_priv,
174 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# leaf_priv,
175 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
176 const KeyPackagecxx . . $ mlspp/KeyPackage#& key_package,
177 const Welcomecxx . . $ mlspp/Welcome#& welcome,
178 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#>& tree,
179 stdcxx . . $ std/::mapcxx . . $ std/map#<bytescxx . . $ mlspp/bytes_ns/bytes#, bytescxx . . $ mlspp/bytes_ns/bytes#> external_psks)
180 : Statecxx . . $ mlspp/State#State(e41efc7a5f03af4b).(init_priv,
181 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(leaf_priv),
182 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv),
183 key_package,
184 welcome,
185 tree,
186 stdcxx . . $ std/map#map(3d8f9cfb6064bed1).::movecxx . . $ std/move(e35c19a1ba7baa26).(external_psks),
187 {cxx . . $ std/map#map(49f6e7a06ebc5aa8).})
188 {
189 }
190
191 Statecxx . . $ mlspp/State#::Statecxx . . $ mlspp/State#State(e41efc7a5f03af4b).(const HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#& init_priv,
192 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# leaf_priv,
193 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
194 const KeyPackagecxx . . $ mlspp/KeyPackage#& key_package,
195 const Welcomecxx . . $ mlspp/Welcome#& welcome,
196 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#>& tree,
197 stdcxx . . $ std/::mapcxx . . $ std/map#<bytescxx . . $ mlspp/bytes_ns/bytes#, bytescxx . . $ mlspp/bytes_ns/bytes#> external_psks,
198 stdcxx . . $ std/::mapcxx . . $ std/map#<EpochRefcxx . . $ mlspp/State#EpochRef#, bytescxx . . $ mlspp/bytes_ns/bytes#> resumption_psks)
199 : _suitecxx . . $ mlspp/State#_suite.(welcome.cipher_suitecxx . . $ mlspp/Welcome#cipher_suite.)
200 , _epochcxx . . $ mlspp/State#_epoch.(0)
201 , _treecxx . . $ mlspp/State#_tree.(welcome.cipher_suitecxx . . $ mlspp/Welcome#cipher_suite.)
202 , _transcript_hashcxx . . $ mlspp/State#_transcript_hash.(welcome.cipher_suitecxx . . $ mlspp/Welcome#cipher_suite.)
203 , _identity_privcxx . . $ mlspp/State#_identity_priv.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv))
204 , _external_pskscxx . . $ mlspp/State#_external_psks.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(external_psks))
205 , _resumption_pskscxx . . $ mlspp/State#_resumption_psks.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(resumption_psks))
206 {
207 auto maybe_kpi = welcome.findcxx . . $ mlspp/Welcome#find(bb6a8adc8a3815ad).(key_package);
208 if (!maybe_kpi) {
209 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Welcome not intended for key package");
210 }
211 auto kpi = opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_kpi);
212
213 if (key_package.cipher_suitecxx . . $ mlspp/KeyPackage#cipher_suite. !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). welcome.cipher_suitecxx . . $ mlspp/Welcome#cipher_suite.) {
214 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Ciphersuite mismatch");
215 }
216
217 // Decrypt the GroupSecrets and look up required PSKs
218 auto secrets = welcome.decrypt_secretscxx . . $ mlspp/Welcome#decrypt_secrets(829c26bdce94c216).(kpi, init_priv);
219 auto psks = resolvecxx . . $ mlspp/State#resolve(93c5d9b7116d7785).(secrets.pskscxx . . $ mlspp/GroupSecrets#psks..pskscxx . . $ mlspp/PreSharedKeys#psks.);
220
221 // Decrypt the GroupInfo
222 auto group_info = welcome.decryptcxx . . $ mlspp/Welcome#decrypt(81448b52776f14d3).(secrets.joiner_secretcxx . . $ mlspp/GroupSecrets#joiner_secret., psks);
223 if (group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..cipher_suitecxx . . $ mlspp/GroupContext#cipher_suite. !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). _suitecxx . . $ mlspp/State#_suite.) {
224 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("GroupInfo and Welcome ciphersuites disagree");
225 }
226
227 // Import the tree from the argument or from the extension
228 _treecxx . . $ mlspp/State#_tree. =cxx . . $ mlspp/TreeKEMPublicKey#`operator=`(1436abb625ff747a). import_treecxx . . $ mlspp/State#import_tree(485acda75e27d34f).(
229 group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..tree_hashcxx . . $ mlspp/GroupContext#tree_hash., tree, group_info.extensionscxx . . $ mlspp/GroupInfo#extensions.);
230
231 // Verify the signature on the GroupInfo
232 if (!group_info.verifycxx . . $ mlspp/GroupInfo#verify(eaed869e1938a2dc).(_treecxx . . $ mlspp/State#_tree.)) {
233 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid GroupInfo");
234 }
235
236 // Ingest the GroupSecrets and GroupInfo
237 _epochcxx . . $ mlspp/State#_epoch. = group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..epochcxx . . $ mlspp/GroupContext#epoch.;
238 _group_idcxx . . $ mlspp/State#_group_id. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(89adb9997e4a49c). group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..group_idcxx . . $ mlspp/GroupContext#group_id.;
239
240 _transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(89adb9997e4a49c).
241 group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..confirmed_transcript_hashcxx . . $ mlspp/GroupContext#confirmed_transcript_hash.;
242 _transcript_hashcxx . . $ mlspp/State#_transcript_hash..update_interimcxx . . $ mlspp/TranscriptHash#update_interim(68ca607eebb5be3e).(group_info.confirmation_tagcxx . . $ mlspp/GroupInfo#confirmation_tag.);
243
244 _extensionscxx . . $ mlspp/State#_extensions. =cxx . . $ mlspp/ExtensionList#`operator=`(8fb3dd954f866f51). group_info.group_contextcxx . . $ mlspp/GroupInfo#group_context..extensionscxx . . $ mlspp/GroupContext#extensions.;
245
246 // Validate that the tree is in fact consistent with the group's parameters
247 if (!validate_treecxx . . $ mlspp/State#validate_tree(50ce9a9e25b4a850).()) {
248 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid tree");
249 }
250
251 // Construct TreeKEM private key from parts provided
252 auto maybe_index = _treecxx . . $ mlspp/State#_tree..findcxx . . $ mlspp/TreeKEMPublicKey#find(ce1aa2f7913b80cb).(key_package.leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node.);
253 if (!maybe_index) {
254 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("New joiner not in tree");
255 }
256
257 _indexcxx . . $ mlspp/State#_index. =cxx . . $ mlspp/LeafIndex#`operator=`(52b85dbf6b8ce299). opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_index);
258
259 auto ancestor = _indexcxx . . $ mlspp/State#_index..ancestorcxx . . $ mlspp/LeafIndex#ancestor(9a73b556cbb4fcfc).(group_info.signercxx . . $ mlspp/GroupInfo#signer.);
260 auto path_secret = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>{};
261 if (secrets.path_secretcxx . . $ mlspp/GroupSecrets#path_secret.) {
262 path_secret =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(secrets.path_secretcxx . . $ mlspp/GroupSecrets#path_secret.).secretcxx . . $ mlspp/GroupSecrets#PathSecret#secret.;
263 }
264
265 _tree_privcxx . . $ mlspp/State#_tree_priv. =cxx . . $ mlspp/TreeKEMPrivateKey#`operator=`(7212344ec6a145a). TreeKEMPrivateKeycxx . . $ mlspp/TreeKEMPrivateKey#::joinercxx . . $ mlspp/TreeKEMPrivateKey#joiner(3c3a8fd039c9c001).(
266 _treecxx . . $ mlspp/State#_tree., _indexcxx . . $ mlspp/State#_index., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(leaf_priv), ancestor, path_secret);
267
268 // Ratchet forward into the current epoch
269 auto group_ctx = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(group_contextcxx . . $ mlspp/State#group_context(da187bf767f0d89d).());
270 _key_schedulecxx . . $ mlspp/State#_key_schedule. =cxx . . $ mlspp/KeyScheduleEpoch#`operator=`(8ef62e844b63fcc6).
271 KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::joinercxx . . $ mlspp/KeyScheduleEpoch#joiner(25b4bb31cd83193c).(_suitecxx . . $ mlspp/State#_suite., secrets.joiner_secretcxx . . $ mlspp/GroupSecrets#joiner_secret., psks, group_ctxcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
272 _keyscxx . . $ mlspp/State#_keys. =cxx . . $ mlspp/GroupKeySource#`operator=`(9bdcbd6beff8640f). _key_schedulecxx . . $ mlspp/State#_key_schedule..encryption_keyscxx . . $ mlspp/KeyScheduleEpoch#encryption_keys(578ffb7a4920202).(_treecxx . . $ mlspp/State#_tree..sizecxx . . $ mlspp/TreeKEMPublicKey#size.);
273
274 // Verify the confirmation
275 const auto confirmation_tag =
276 _key_schedulecxx . . $ mlspp/State#_key_schedule..confirmation_tagcxx . . $ mlspp/KeyScheduleEpoch#confirmation_tag(c5e1b85e16e94921).(_transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.);
277 if (confirmation_tag !=cxx . . $ mlspp/bytes_ns/bytes#`operator!=`(efd4f3c976ab92ce). group_info.confirmation_tagcxx . . $ mlspp/GroupInfo#confirmation_tag.) {
278 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Confirmation failed to verify");
279 }
280 }
281
282 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<MLSMessagecxx . . $ mlspp/MLSMessage#, Statecxx . . $ mlspp/State#>
283 Statecxx . . $ mlspp/State#::external_joincxx . . $ mlspp/State#external_join(143e8da8d52ca271).(const bytescxx . . $ mlspp/bytes_ns/bytes#& leaf_secret,
284 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
285 const KeyPackagecxx . . $ mlspp/KeyPackage#& key_package,
286 const GroupInfocxx . . $ mlspp/GroupInfo#& group_info,
287 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#>& tree,
288 const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts,
289 stdcxx . . $ std/::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#> remove_prior,
290 const stdcxx . . $ std/::mapcxx . . $ std/map#<bytescxx . . $ mlspp/bytes_ns/bytes#, bytescxx . . $ mlspp/bytes_ns/bytes#>& psks)
291 {
292 // Create a preliminary state
293 auto initial_state = Statecxx . . $ mlspp/State#State(98680997732888de).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv), group_info, tree);
294
295 // Look up the external public key for the group
296 const auto maybe_external_pub =
297 group_info.extensionscxx . . $ mlspp/GroupInfo#extensions..findcxx . . $ mlspp/ExtensionList#find(af95876f91a4b24c).<ExternalPubExtensioncxx . . $ mlspp/ExternalPubExtension#>();
298 if (!maybe_external_pub) {
299 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("No external pub in GroupInfo");
300 }
301
302 const auto& external_pub = opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(maybe_external_pub).external_pubcxx . . $ mlspp/ExternalPubExtension#external_pub.;
303
304 // Insert an ExternalInit proposal
305 auto opts = CommitOptscxx . . $ mlspp/CommitOpts#{};
306 auto [enc, force_init_secret] =
307 KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::external_initcxx . . $ mlspp/KeyScheduleEpoch#external_init(d332d7d6e9cedbfc).(key_package.cipher_suitecxx . . $ mlspp/KeyPackage#cipher_suite., external_pub);
308 auto ext_init = Proposalcxx . . $ mlspp/Proposal#{ ExternalInitcxx . . $ mlspp/ExternalInit#{ enc } };
309 opts.extra_proposalscxx . . $ mlspp/CommitOpts#extra_proposals..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(ext_init);
310
311 // Evict a prior appearance if required
312 if (remove_prior) {
313 auto remove = initial_state.remove_proposalcxx . . $ mlspp/State#remove_proposal(edc3c171b293f4e4).(opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(remove_prior));
314 opts.extra_proposalscxx . . $ mlspp/CommitOpts#extra_proposals..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(remove);
315 }
316
317 // Inject PSKs
318 for (const auto& [id, secret] : psks) {
319 initial_state.add_external_pskcxx . . $ mlspp/State#add_external_psk(84c68846ffcb487b).(id, secret);
320 auto psk = initial_state.pre_shared_key_proposalcxx . . $ mlspp/State#pre_shared_key_proposal(e132d434992eff30).(id);
321 opts.extra_proposalscxx . . $ mlspp/CommitOpts#extra_proposals..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(psk);
322 }
323
324 // Use the preliminary state to create a commit and advance to a real state
325 auto params = ExternalCommitParamscxx . . $ mlspp/State#ExternalCommitParams#{ key_package, force_init_secret };
326 auto [commit_msg, welcome, state] =
327 initial_state.commitcxx . . $ mlspp/State#commit(c6dfec9d8a60f28e).(leaf_secret, optscxx . . $ std/optional#optional(e3f0d6382bd52f24)., msg_opts, paramscxx . . $ std/variant#variant(5ba8255a4607184).);
328 silence_unusedcxx . . $ mlspp/silence_unused(77d9f17553126ecb).(welcome);
329 return {cxx . . $ std/tuple#tuple(533e79eb6234819d). commit_msg, state };
330 }
331
332 MLSMessagecxx . . $ mlspp/MLSMessage#
333 Statecxx . . $ mlspp/State#::new_member_addcxx . . $ mlspp/State#new_member_add(edcdd2b1eae1b9c0).(const bytescxx . . $ mlspp/bytes_ns/bytes#& group_id,
334 epoch_tcxx . . $ mlspp/epoch_t# epoch,
335 const KeyPackagecxx . . $ mlspp/KeyPackage#& new_member,
336 const SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#& sig_priv)
337 {
338 const auto suite = new_member.cipher_suitecxx . . $ mlspp/KeyPackage#cipher_suite.;
339 auto proposal = Proposalcxx . . $ mlspp/Proposal#{ Addcxx . . $ mlspp/Add#{ new_member } };
340 auto content = GroupContentcxx . . $ mlspp/GroupContent#GroupContent(f5f370ed8cd561bf).{ group_idcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).,
341 epoch,
342 { NewMemberProposalSendercxx . . $ mlspp/NewMemberProposalSender#{} },
343 {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d). /* no authenticated data */ },
344 {cxx . . $ std/variant#variant(5ba8255a4607184). stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(proposal) } };
345 auto content_auth = AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::signcxx . . $ mlspp/AuthenticatedContent#sign(6554afcb5b84419).(
346 WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content), suite, sig_priv, {cxx . . $ std/optional#optional(ced63f7c635d850d).});
347
348 return PublicMessagecxx . . $ mlspp/MLSMessage#MLSMessage(efba1c00b0eccae9).::protectcxx . . $ mlspp/PublicMessage#protect(2291e3815af7a859).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth), suite, {cxx . . $ std/optional#optional(ced63f7c635d850d).}, {cxx . . $ std/optional#optional(ced63f7c635d850d).});
349 }
350
351 ///
352 /// Proposal and commit factories
353 ///
354 template<typename Inner>
355 MLSMessagecxx . . $ mlspp/MLSMessage#
356 Statecxx . . $ mlspp/State#::protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(Inner&& inner_content, const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
357 {
358 auto content_auth = signcxx . . $ mlspp/State#sign(ba0a57b5461d940d).({ MemberSendercxx . . $ mlspp/MemberSender#{ _indexcxx . . $ mlspp/State#_index. } },
359 stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Inner>(inner_content),
360 msg_opts.authenticated_datacxx . . $ mlspp/MessageOpts#authenticated_data.,
361 msg_opts.encryptcxx . . $ mlspp/MessageOpts#encrypt.);
362 return protectcxx . . $ mlspp/State#protect(ae39f86e951371d3).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth), msg_opts.padding_sizecxx . . $ mlspp/MessageOpts#padding_size.);
363 }
364
365 template<typename Inner>
366 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#
367 Statecxx . . $ mlspp/State#::signcxx . . $ mlspp/State#sign(ba0a57b5461d940d).(const Sendercxx . . $ mlspp/Sender#& sender,
368 Inner&& inner_content,
369 const bytescxx . . $ mlspp/bytes_ns/bytes#& authenticated_data,
370 bool encrypt) const
371 {
372 auto content = GroupContentcxx . . $ mlspp/GroupContent#{ _group_idcxx . . $ mlspp/State#_group_id.,
373 _epochcxx . . $ mlspp/State#_epoch.,
374 sender,
375 authenticated_data,
376 { stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<Inner>(inner_content) } };
377
378 auto wire_format = (encrypt) ? WireFormatcxx . . $ mlspp/WireFormat#::mls_private_messagecxx . . $ mlspp/WireFormat#mls_private_message.
379 : WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message.;
380
381 auto content_auth = AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::signcxx . . $ mlspp/AuthenticatedContent#sign(6554afcb5b84419).(
382 wire_format, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content), _suitecxx . . $ mlspp/State#_suite., _identity_privcxx . . $ mlspp/State#_identity_priv., group_contextcxx . . $ std/optional#optional(e3f0d6382bd52f24).());
383
384 return content_auth;
385 }
386
387 MLSMessagecxx . . $ mlspp/MLSMessage#
388 Statecxx . . $ mlspp/State#::protectcxx . . $ mlspp/State#protect(cc9bcfec8b65775d).(AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#&& content_auth, size_t padding_size)
389 {
390 switch (content_auth.wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format.) {
391 case WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message.:
392 return PublicMessagecxx . . $ mlspp/MLSMessage#MLSMessage(efba1c00b0eccae9).::protectcxx . . $ mlspp/PublicMessage#protect(2291e3815af7a859).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth),
393 _suitecxx . . $ mlspp/State#_suite.,
394 _key_schedulecxx . . $ std/optional#optional(e3f0d6382bd52f24)..membership_keycxx . . $ mlspp/KeyScheduleEpoch#membership_key.,
395 group_contextcxx . . $ std/optional#optional(e3f0d6382bd52f24).());
396
397 case WireFormatcxx . . $ mlspp/WireFormat#::mls_private_messagecxx . . $ mlspp/WireFormat#mls_private_message.:
398 return PrivateMessagecxx . . $ mlspp/MLSMessage#MLSMessage(305115f184887e4c).::protectcxx . . $ mlspp/PrivateMessage#protect(5256fdc14bb335a).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth),
399 _suitecxx . . $ mlspp/State#_suite.,
400 _keyscxx . . $ mlspp/State#_keys.,
401 _key_schedulecxx . . $ mlspp/State#_key_schedule..sender_data_secretcxx . . $ mlspp/KeyScheduleEpoch#sender_data_secret.,
402 padding_size);
403
404 default:
405 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Malformed AuthenticatedContent");
406 }
407 }
408
409 ValidatedContentcxx . . $ mlspp/ValidatedContent#
410 Statecxx . . $ mlspp/State#::unwrapcxx . . $ mlspp/State#unwrap(250da7eac3b4c99).(const MLSMessagecxx . . $ mlspp/MLSMessage#& msg)
411 {
412 if (msg.versioncxx . . $ mlspp/MLSMessage#version. != ProtocolVersioncxx . . $ mlspp/ProtocolVersion#::mls10cxx . . $ mlspp/ProtocolVersion#mls10.) {
413 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Unsupported version");
414 }
415
416 const auto unprotect = overloaded{
417 [&](const PublicMessagecxx . . $ mlspp/PublicMessage#& pt) -> ValidatedContentcxx . . $ mlspp/ValidatedContent# {
418 if (pt.get_group_idcxx . . $ mlspp/PublicMessage#get_group_id(d7392ba79aa35767).() !=cxx . . $ mlspp/bytes_ns/bytes#`operator!=`(efd4f3c976ab92ce). _group_idcxx . . $ mlspp/State#_group_id.) {
419 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("PublicMessage not for this group");
420 }
421
422 if (pt.get_epochcxx . . $ mlspp/PublicMessage#get_epoch(fe4d2d262d4164a8).() != _epochcxx . . $ mlspp/State#_epoch.) {
423 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("PublicMessage not for this epoch");
424 }
425
426 auto maybe_content_auth =
427 pt.unprotectcxx . . $ mlspp/PublicMessage#unprotect(fefd97f134b41226).(_suitecxx . . $ mlspp/State#_suite., _key_schedulecxx . . $ std/optional#optional(e3f0d6382bd52f24)..membership_keycxx . . $ mlspp/KeyScheduleEpoch#membership_key., group_contextcxx . . $ std/optional#optional(e3f0d6382bd52f24).());
428 if (!maybe_content_auth) {
429 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Membership tag failed to verify");
430 }
431 return opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_content_auth);
432 },
433
434 [&](const PrivateMessagecxx . . $ mlspp/PrivateMessage#& ct) -> ValidatedContentcxx . . $ mlspp/ValidatedContent# {
435 if (ct.get_group_idcxx . . $ mlspp/PrivateMessage#get_group_id(d7392ba79aa35767).() !=cxx . . $ mlspp/bytes_ns/bytes#`operator!=`(efd4f3c976ab92ce). _group_idcxx . . $ mlspp/State#_group_id.) {
436 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("PrivateMessage not for this group");
437 }
438
439 if (ct.get_epochcxx . . $ mlspp/PrivateMessage#get_epoch(fe4d2d262d4164a8).() != _epochcxx . . $ mlspp/State#_epoch.) {
440 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("PrivateMessage not for this epoch");
441 }
442
443 auto maybe_content_auth =
444 ct.unprotectcxx . . $ mlspp/PrivateMessage#unprotect(e57a24405060fb5).(_suitecxx . . $ mlspp/State#_suite., _keyscxx . . $ mlspp/State#_keys., _key_schedulecxx . . $ mlspp/State#_key_schedule..sender_data_secretcxx . . $ mlspp/KeyScheduleEpoch#sender_data_secret.);
445 if (!maybe_content_auth) {
446 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("PrivateMessage decryption failure");
447 }
448 return opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_content_auth);
449 },
450
451 [](const auto& /* unused */) -> ValidatedContentcxx . . $ mlspp/ValidatedContent# {
452 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid wire format");
453 },
454 };
455
456 auto val_content = var::visitcxx . . $ std/visit(9828ab07ec69b3d0).(unprotect, msg.messagecxx . . $ mlspp/MLSMessage#message.);
457 if (!verifycxx . . $ mlspp/State#verify(891fdc29165d76d0).(val_content.content_authcxx . . $ mlspp/ValidatedContent#content_auth.)) {
458 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Message signature failed to verify");
459 }
460
461 return val_content;
462 }
463
464 Proposalcxx . . $ mlspp/Proposal#
465 Statecxx . . $ mlspp/State#::add_proposalcxx . . $ mlspp/State#add_proposal(e4fd0120844a75d9).(const KeyPackagecxx . . $ mlspp/KeyPackage#& key_package) const
466 {
467 // Check that the key package is validly signed
468 if (!key_package.verifycxx . . $ mlspp/KeyPackage#verify(50ce9a9e25b4a850).()) {
469 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid signature on key package");
470 }
471
472 // Check that the group's basic properties are supported
473 auto now = seconds_since_epochcxx . . $ mlspp/seconds_since_epoch(f708dce9a8856c70).();
474 if (!key_package.leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node..verify_expirycxx . . $ mlspp/LeafNode#verify_expiry(2ff7c7de1baa6d0a).(now)) {
475 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Expired key package");
476 }
477
478 // Check that the group's extensions are supported
479 if (!key_package.leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node..verify_extension_supportcxx . . $ mlspp/LeafNode#verify_extension_support(b1d6012e28b23e89).(_extensionscxx . . $ mlspp/State#_extensions.)) {
480 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#(
481 "Key package does not support group's extensions");
482 }
483
484 return { Addcxx . . $ mlspp/Add#{ key_package } };
485 }
486
487 Proposalcxx . . $ mlspp/Proposal#
488 Statecxx . . $ mlspp/State#::update_proposalcxx . . $ mlspp/State#update_proposal(6da03f4c1f0a7f2f).(HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# leaf_priv, const LeafNodeOptionscxx . . $ mlspp/LeafNodeOptions#& opts)
489 {
490 if (_cached_updatecxx . . $ mlspp/State#_cached_update.) {
491 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Only one update may be generated per epoch");
492 }
493
494 auto leaf = optcxx . . $ mlspp/LeafNode#LeafNode(d63c1b60f6df9256).::getcxx . . $ mlspp/tls/opt/get(382ba35666c2b70b).(_treecxx . . $ mlspp/State#_tree..leaf_nodecxx . . $ mlspp/TreeKEMPublicKey#leaf_node(e2d641b4ea45e2f).(_indexcxx . . $ mlspp/State#_index.));
495
496 auto new_leaf = leaf.for_updatecxx . . $ mlspp/LeafNode#for_update(72414053c770abee).(
497 _suitecxx . . $ mlspp/State#_suite., _group_idcxx . . $ mlspp/State#_group_id., _indexcxx . . $ mlspp/State#_index., leaf_priv.public_keycxx . . $ mlspp/HPKEPrivateKey#public_key., opts, _identity_privcxx . . $ mlspp/State#_identity_priv.);
498
499 auto update = Updatecxx . . $ mlspp/Update#{ new_leaf };
500 _cached_updatecxx . . $ mlspp/State#_cached_update. =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). CachedUpdatecxx . . $ mlspp/State#CachedUpdate#{ stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(leaf_priv), update };
501 return { update };
502 }
503
504 Proposalcxx . . $ mlspp/Proposal#
505 Statecxx . . $ mlspp/State#::remove_proposalcxx . . $ mlspp/State#remove_proposal(c2ef5639e2e3f0d6).(RosterIndexcxx . . $ mlspp/RosterIndex# index) const
506 {
507 return remove_proposalcxx . . $ mlspp/State#remove_proposal(edc3c171b293f4e4).(leaf_for_roster_entrycxx . . $ mlspp/State#leaf_for_roster_entry(fb567b77ce7f3086).(index));
508 }
509
510 Proposalcxx . . $ mlspp/Proposal#
511 Statecxx . . $ mlspp/State#::remove_proposalcxx . . $ mlspp/State#remove_proposal(edc3c171b293f4e4).(LeafIndexcxx . . $ mlspp/LeafIndex# removed) const
512 {
513 if (!_treecxx . . $ mlspp/State#_tree..has_leafcxx . . $ mlspp/TreeKEMPublicKey#has_leaf(be225f04b72ff6f7).(removed)) {
514 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Remove on blank leaf");
515 }
516
517 return { Removecxx . . $ mlspp/Remove#{ removed } };
518 }
519
520 Proposalcxx . . $ mlspp/Proposal#
521 Statecxx . . $ mlspp/State#::group_context_extensions_proposalcxx . . $ mlspp/State#group_context_extensions_proposal(ce238ee285b81a55).(ExtensionListcxx . . $ mlspp/ExtensionList# exts) const
522 {
523 if (!extensions_supportedcxx . . $ mlspp/State#extensions_supported(b1d6012e28b23e89).(exts)) {
524 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Unsupported extensions");
525 }
526
527 return { GroupContextExtensionscxx . . $ mlspp/GroupContextExtensions#{ stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(exts) } };
528 }
529
530 Proposalcxx . . $ mlspp/Proposal#
531 Statecxx . . $ mlspp/State#::pre_shared_key_proposalcxx . . $ mlspp/State#pre_shared_key_proposal(e132d434992eff30).(const bytescxx . . $ mlspp/bytes_ns/bytes#& external_psk_id) const
532 {
533 if (_external_pskscxx . . $ mlspp/State#_external_psks..countcxx . . $ std/map#count(ea780b5adf43227).(external_psk_id) == 0) {
534 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Unknown PSK");
535 }
536
537 auto psk_id = PreSharedKeyIDcxx . . $ mlspp/PreSharedKeyID#{
538 { ExternalPSKcxx . . $ mlspp/ExternalPSK#{ external_psk_id } },
539 random_bytescxx . . $ mlspp/random_bytes(b7161179e0ed6f95).(_suitecxx . . $ mlspp/State#_suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()),
540 };
541 return { PreSharedKeycxx . . $ mlspp/PreSharedKey#{ psk_id } };
542 }
543
544 Proposalcxx . . $ mlspp/Proposal#
545 Statecxx . . $ mlspp/State#::pre_shared_key_proposalcxx . . $ mlspp/State#pre_shared_key_proposal(bde2bcef59e4f9b9).(const bytescxx . . $ mlspp/bytes_ns/bytes#& group_id, epoch_tcxx . . $ mlspp/epoch_t# epoch) const
546 {
547 if (epoch != _epochcxx . . $ mlspp/State#_epoch. && _resumption_pskscxx . . $ mlspp/State#_resumption_psks..countcxx . . $ std/map#count(ea780b5adf43227).({cxx . . $ std/tuple#tuple(533e79eb6234819d). group_id, epoch }) == 0) {
548 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Unknown PSK");
549 }
550
551 auto psk_id = PreSharedKeyIDcxx . . $ mlspp/PreSharedKeyID#{
552 { ResumptionPSKcxx . . $ mlspp/ResumptionPSK#{ ResumptionPSKUsagecxx . . $ mlspp/ResumptionPSKUsage#::applicationcxx . . $ mlspp/ResumptionPSKUsage#application., group_id, epoch } },
553 random_bytescxx . . $ mlspp/random_bytes(b7161179e0ed6f95).(_suitecxx . . $ mlspp/State#_suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()),
554 };
555 return { PreSharedKeycxx . . $ mlspp/PreSharedKey#{ psk_id } };
556 }
557
558 Proposalcxx . . $ mlspp/Proposal#
559 Statecxx . . $ mlspp/State#::reinit_proposalcxx . . $ mlspp/State#reinit_proposal(136e15f530ff81c1).(bytescxx . . $ mlspp/bytes_ns/bytes# group_id,
560 ProtocolVersioncxx . . $ mlspp/ProtocolVersion# version,
561 CipherSuitecxx . . $ mlspp/CipherSuite# cipher_suite,
562 ExtensionListcxx . . $ mlspp/ExtensionList# extensions)
563 {
564 return { ReInitcxx . . $ mlspp/ReInit#{
565 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(group_id), version, cipher_suite, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(extensions) } };
566 }
567
568 MLSMessagecxx . . $ mlspp/MLSMessage#
569 Statecxx . . $ mlspp/State#::addcxx . . $ mlspp/State#add(42c8642ea0f153d7).(const KeyPackagecxx . . $ mlspp/KeyPackage#& key_package, const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
570 {
571 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(add_proposalcxx . . $ mlspp/State#add_proposal(e4fd0120844a75d9).(key_package), msg_opts);
572 }
573
574 MLSMessagecxx . . $ mlspp/MLSMessage#
575 Statecxx . . $ mlspp/State#::updatecxx . . $ mlspp/State#update(be9350ea97adfaa1).(HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# leaf_priv,
576 const LeafNodeOptionscxx . . $ mlspp/LeafNodeOptions#& opts,
577 const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
578 {
579 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(update_proposalcxx . . $ mlspp/State#update_proposal(6da03f4c1f0a7f2f).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(leaf_priv), opts), msg_opts);
580 }
581
582 MLSMessagecxx . . $ mlspp/MLSMessage#
583 Statecxx . . $ mlspp/State#::removecxx . . $ mlspp/State#remove(2ba6878df04e464).(RosterIndexcxx . . $ mlspp/RosterIndex# index, const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
584 {
585 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(remove_proposalcxx . . $ mlspp/State#remove_proposal(c2ef5639e2e3f0d6).(index), msg_opts);
586 }
587
588 MLSMessagecxx . . $ mlspp/MLSMessage#
589 Statecxx . . $ mlspp/State#::removecxx . . $ mlspp/State#remove(eb7319eafc4af471).(LeafIndexcxx . . $ mlspp/LeafIndex# removed, const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
590 {
591 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(remove_proposalcxx . . $ mlspp/State#remove_proposal(edc3c171b293f4e4).(removed), msg_opts);
592 }
593
594 MLSMessagecxx . . $ mlspp/MLSMessage#
595 Statecxx . . $ mlspp/State#::group_context_extensionscxx . . $ mlspp/State#group_context_extensions(77d403aa03adcbdd).(ExtensionListcxx . . $ mlspp/ExtensionList# exts, const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
596 {
597 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(group_context_extensions_proposalcxx . . $ mlspp/State#group_context_extensions_proposal(ce238ee285b81a55).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(exts)),
598 msg_opts);
599 }
600
601 MLSMessagecxx . . $ mlspp/MLSMessage#
602 Statecxx . . $ mlspp/State#::pre_shared_keycxx . . $ mlspp/State#pre_shared_key(1fde39c3978cd5c1).(const bytescxx . . $ mlspp/bytes_ns/bytes#& external_psk_id, const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
603 {
604 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(pre_shared_key_proposalcxx . . $ mlspp/State#pre_shared_key_proposal(e132d434992eff30).(external_psk_id), msg_opts);
605 }
606
607 MLSMessagecxx . . $ mlspp/MLSMessage#
608 Statecxx . . $ mlspp/State#::pre_shared_keycxx . . $ mlspp/State#pre_shared_key(5a2841574fe3fe67).(const bytescxx . . $ mlspp/bytes_ns/bytes#& group_id,
609 epoch_tcxx . . $ mlspp/epoch_t# epoch,
610 const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
611 {
612 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(pre_shared_key_proposalcxx . . $ mlspp/State#pre_shared_key_proposal(bde2bcef59e4f9b9).(group_id, epoch), msg_opts);
613 }
614
615 MLSMessagecxx . . $ mlspp/MLSMessage#
616 Statecxx . . $ mlspp/State#::reinitcxx . . $ mlspp/State#reinit(797eea9a9c26af95).(bytescxx . . $ mlspp/bytes_ns/bytes# group_id,
617 ProtocolVersioncxx . . $ mlspp/ProtocolVersion# version,
618 CipherSuitecxx . . $ mlspp/CipherSuite# cipher_suite,
619 ExtensionListcxx . . $ mlspp/ExtensionList# extensions,
620 const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
621 {
622 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(
623 reinit_proposalcxx . . $ mlspp/State#reinit_proposal(136e15f530ff81c1).(
624 stdcxx . . $ mlspp/bytes_ns/bytes#bytes(628b76f52f2a67f).::movecxx . . $ std/move(e35c19a1ba7baa26).(group_id), version, cipher_suite, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(extensions)),
625 msg_opts);
626 }
627
628 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<MLSMessagecxx . . $ mlspp/MLSMessage#, Welcomecxx . . $ mlspp/Welcome#, Statecxx . . $ mlspp/State#>
629 Statecxx . . $ mlspp/State#::commitcxx . . $ mlspp/State#commit(79c4e4ce2bdb005c).(const bytescxx . . $ mlspp/bytes_ns/bytes#& leaf_secret,
630 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<CommitOptscxx . . $ mlspp/CommitOpts#>& opts,
631 const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
632 {
633 return commitcxx . . $ mlspp/State#commit(c6dfec9d8a60f28e).(leaf_secret, opts, msg_opts, NormalCommitParamscxx . . $ std/variant#variant(5ba8255a4607184).{});
634 }
635
636 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<MLSMessagecxx . . $ mlspp/MLSMessage#, Welcomecxx . . $ mlspp/Welcome#, Statecxx . . $ mlspp/State#>
637 Statecxx . . $ mlspp/State#::commitcxx . . $ mlspp/State#commit(c6dfec9d8a60f28e).(const bytescxx . . $ mlspp/bytes_ns/bytes#& leaf_secret,
638 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<CommitOptscxx . . $ mlspp/CommitOpts#>& opts,
639 const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts,
640 CommitParamscxx . . $ mlspp/State#CommitParams# params)
641 {
642 // Construct a commit from cached proposals
643 // TODO(rlb) ignore some proposals:
644 // * Update after Update
645 // * Update after Remove
646 // * Remove after Remove
647 Commitcxx . . $ mlspp/Commit# commit;
648 auto joiners = stdcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).::vectorcxx . . $ std/vector#<KeyPackagecxx . . $ mlspp/KeyPackage#>{};
649 for (const auto& cached : _pending_proposalscxx . . $ mlspp/State#_pending_proposals.) {
650 if (var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<Addcxx . . $ mlspp/Add#>(cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..contentcxx . . $ mlspp/Proposal#content.)) {
651 const auto& add = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Addcxx . . $ mlspp/Add#>(cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..contentcxx . . $ mlspp/Proposal#content.);
652 joiners.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(add.key_packagecxx . . $ mlspp/Add#key_package.);
653 }
654
655 commit.proposalscxx . . $ mlspp/Commit#proposals..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).({ cached.refcxx . . $ mlspp/State#CachedProposal#ref. });
656 }
657
658 // Add the extra proposals to those we had cached
659 if (opts) {
660 const auto& extra_proposals = opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(opts).extra_proposalscxx . . $ mlspp/CommitOpts#extra_proposals.;
661 for (const auto& proposal : extra_proposals) {
662 if (var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<Addcxx . . $ mlspp/Add#>(proposal.contentcxx . . $ mlspp/Proposal#content.)) {
663 const auto& add = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Addcxx . . $ mlspp/Add#>(proposal.contentcxx . . $ mlspp/Proposal#content.);
664 joiners.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(add.key_packagecxx . . $ mlspp/Add#key_package.);
665 }
666
667 commit.proposalscxx . . $ mlspp/Commit#proposals..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).({ proposal });
668 }
669 }
670
671 // If this is an external commit, insert an ExternalInit proposal
672 auto external_commit = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<ExternalCommitParamscxx . . $ mlspp/State#ExternalCommitParams#>{};
673 if (var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<ExternalCommitParamscxx . . $ mlspp/State#ExternalCommitParams#>(params)) {
674 external_commit =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). var::getcxx . . $ std/get(55ed64a6518b24d0).<ExternalCommitParamscxx . . $ mlspp/State#ExternalCommitParams#>(params);
675 }
676
677 auto force_init_secret = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>{};
678 if (external_commit) {
679 force_init_secret =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(external_commit).force_init_secretcxx . . $ mlspp/State#ExternalCommitParams#force_init_secret.;
680 }
681
682 // Apply proposals
683 Statecxx . . $ mlspp/State# next = successorcxx . . $ mlspp/State#successor(c5801eb416f519eb).();
684
685 const auto proposals = must_resolvecxx . . $ mlspp/State#must_resolve(5bc28b2fad777aa5).(commit.proposalscxx . . $ mlspp/Commit#proposals., _indexcxx . . $ std/optional#optional(e3f0d6382bd52f24).);
686 if (!validcxx . . $ mlspp/State#valid(5b837f842e0476dd).(proposals, _indexcxx . . $ mlspp/State#_index., params)) {
687 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid proposal list");
688 }
689
690 const auto [joiner_locations, psks] = next.applycxx . . $ mlspp/State#apply(8b7878ad0f8bc547).(proposals);
691
692 if (external_commit) {
693 const auto& leaf_node =
694 opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(external_commit).joiner_key_packagecxx . . $ mlspp/State#ExternalCommitParams#joiner_key_package..leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node.;
695 next._indexcxx . . $ mlspp/State#_index. =cxx . . $ mlspp/LeafIndex#`operator=`(f64f93d71b0bc387). next._treecxx . . $ mlspp/State#_tree..add_leafcxx . . $ mlspp/TreeKEMPublicKey#add_leaf(9995a7bfeddd280).(leaf_node);
696 }
697
698 // If this is an external commit, indicate it in the sender field
699 auto sender = Sendercxx . . $ mlspp/Sender#{ MemberSendercxx . . $ mlspp/MemberSender#{ _indexcxx . . $ mlspp/State#_index. } };
700 if (external_commit) {
701 sender =cxx . . $ mlspp/Sender#`operator=`(adddf02dc4c04b98). Sendercxx . . $ mlspp/Sender#{ NewMemberCommitSendercxx . . $ mlspp/NewMemberCommitSender#{} };
702 }
703
704 // KEM new entropy to the group and the new joiners
705 auto commit_secret = _suitecxx . . $ mlspp/State#_suite..zerocxx . . $ mlspp/CipherSuite#zero(d7392ba79aa35767).();
706 auto path_secrets =
707 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>>(joiner_locations.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).());
708 auto force_path = opts && opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(opts).force_pathcxx . . $ mlspp/CommitOpts#force_path.;
709 if (force_path || path_requiredcxx . . $ mlspp/State#path_required(10e28906c0b85113).(proposals)) {
710 auto leaf_node_opts = LeafNodeOptionscxx . . $ mlspp/LeafNodeOptions#{};
711 if (opts) {
712 leaf_node_opts =cxx . . $ mlspp/LeafNodeOptions#`operator=`(1ba71c221bae24bd). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(opts).leaf_node_optscxx . . $ mlspp/CommitOpts#leaf_node_opts.;
713 }
714
715 auto new_priv = next._treecxx . . $ mlspp/State#_tree..updatecxx . . $ mlspp/TreeKEMPublicKey#update(9c859f54cfdffec).(
716 next._indexcxx . . $ mlspp/State#_index., leaf_secret, next._group_idcxx . . $ mlspp/State#_group_id., _identity_privcxx . . $ mlspp/State#_identity_priv., leaf_node_opts);
717
718 auto ctx = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(GroupContextcxx . . $ mlspp/GroupContext#GroupContext(59c8082fdf1cbc0e).{
719 next._suitecxx . . $ mlspp/State#_suite.,
720 nextcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).._group_idcxx . . $ mlspp/State#_group_id.,
721 next._epochcxx . . $ mlspp/State#_epoch. + 1,
722 next._treecxx . . $ mlspp/State#_tree..root_hashcxx . . $ mlspp/TreeKEMPublicKey#root_hash(d7392ba79aa35767).(),
723 nextcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).._transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.,
724 next._extensionscxx . . $ mlspp/State#_extensions.,
725 });
726 auto path = next._treecxx . . $ mlspp/State#_tree..encapcxx . . $ mlspp/TreeKEMPublicKey#encap(b02cdda980f00156).(new_priv, ctxcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)., joiner_locations);
727
728 next._tree_privcxx . . $ mlspp/State#_tree_priv. =cxx . . $ mlspp/TreeKEMPrivateKey#`operator=`(734dfb79398e9b30). new_priv;
729 commit.pathcxx . . $ mlspp/Commit#path. =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). path;
730 commit_secret =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(89adb9997e4a49c). new_priv.update_secretcxx . . $ mlspp/TreeKEMPrivateKey#update_secret.;
731
732 for (size_t i = 0; i < joiner_locations.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) {
733 auto [overlap, shared_path_secret, ok] =
734 new_priv.shared_path_secretcxx . . $ mlspp/TreeKEMPrivateKey#shared_path_secret(f9c1aa84c71de2c3).(joiner_locations[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]);
735 silence_unusedcxx . . $ mlspp/silence_unused(77d9f17553126ecb).(overlap);
736 silence_unusedcxx . . $ mlspp/silence_unused(77d9f17553126ecb).(ok);
737
738 path_secrets[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). shared_path_secret;
739 }
740 }
741
742 // Create the Commit message and advance the transcripts / key schedule
743 auto commit_content_auth =
744 signcxx . . $ mlspp/State#sign(ba0a57b5461d940d).(sender, commit, msg_opts.authenticated_datacxx . . $ mlspp/MessageOpts#authenticated_data., msg_opts.encryptcxx . . $ mlspp/MessageOpts#encrypt.);
745
746 next._transcript_hashcxx . . $ mlspp/State#_transcript_hash..update_confirmedcxx . . $ mlspp/TranscriptHash#update_confirmed(15c3fae94687094).(commit_content_auth);
747 next._epochcxx . . $ mlspp/State#_epoch. += 1;
748 next.update_epoch_secretscxx . . $ mlspp/State#update_epoch_secrets(34e1f8f66a1cf646).(commit_secret, psks, force_init_secret);
749
750 const auto confirmation_tag =
751 next._key_schedulecxx . . $ mlspp/State#_key_schedule..confirmation_tagcxx . . $ mlspp/KeyScheduleEpoch#confirmation_tag(c5e1b85e16e94921).(next._transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.);
752 commit_content_auth.set_confirmation_tagcxx . . $ mlspp/AuthenticatedContent#set_confirmation_tag(68ca607eebb5be3e).(confirmation_tag);
753
754 next._transcript_hashcxx . . $ mlspp/State#_transcript_hash..update_interimcxx . . $ mlspp/TranscriptHash#update_interim(15c3fae94687094).(commit_content_auth);
755
756 auto commit_message =
757 protectcxx . . $ mlspp/State#protect(cc9bcfec8b65775d).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(commit_content_auth), msg_opts.padding_sizecxx . . $ mlspp/MessageOpts#padding_size.);
758
759 // Complete the GroupInfo and form the Welcome
760 auto group_info = GroupInfocxx . . $ mlspp/GroupInfo#GroupInfo(6eefa60eacb8ffcb).{
761 {cxx . . $ mlspp/GroupContext#GroupContext(59c8082fdf1cbc0e).
762 next._suitecxx . . $ mlspp/State#_suite.,
763 nextcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).._group_idcxx . . $ mlspp/State#_group_id.,
764 next._epochcxx . . $ mlspp/State#_epoch.,
765 next._treecxx . . $ mlspp/State#_tree..root_hashcxx . . $ mlspp/TreeKEMPublicKey#root_hash(d7392ba79aa35767).(),
766 nextcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).._transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.,
767 next._extensionscxx . . $ mlspp/State#_extensions.,
768 },
769 { /* No other extensions */ },
770 {cxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). confirmation_tag },
771 };
772 if (opts && opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(opts).inline_treecxx . . $ mlspp/CommitOpts#inline_tree.) {
773 group_info.extensionscxx . . $ mlspp/GroupInfo#extensions..addcxx . . $ mlspp/ExtensionList#add(77d9f17553126ecb).(RatchetTreeExtensioncxx . . $ mlspp/RatchetTreeExtension#{ next._treecxx . . $ mlspp/State#_tree. });
774 }
775 group_info.signcxx . . $ mlspp/GroupInfo#sign(f56bede4ff7e1bef).(next._treecxx . . $ mlspp/State#_tree., next._indexcxx . . $ mlspp/State#_index., next._identity_privcxx . . $ mlspp/State#_identity_priv.);
776
777 auto welcome =
778 Welcomecxx . . $ mlspp/Welcome#Welcome(eaff8aba63a9c6d).{ _suitecxx . . $ mlspp/State#_suite., next._key_schedulecxx . . $ mlspp/State#_key_schedule..joiner_secretcxx . . $ mlspp/KeyScheduleEpoch#joiner_secret., psks, group_info };
779 for (size_t i = 0; i < joiners.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) {
780 welcome.encryptcxx . . $ mlspp/Welcome#encrypt(36b3267e5243a5b9).(joiners[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i], path_secrets[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]);
781 }
782
783 return stdcxx . . $ std/::make_tuplecxx . . $ std/make_tuple(3964edbfd7e8599f).(commit_message, welcome, next);
784 }
785
786 ///
787 /// Message handlers
788 ///
789
790 GroupContextcxx . . $ mlspp/GroupContext#
791 Statecxx . . $ mlspp/State#::group_contextcxx . . $ mlspp/State#group_context(da187bf767f0d89d).() const
792 {
793 return GroupContextcxx . . $ mlspp/GroupContext#GroupContext(59c8082fdf1cbc0e).{
794 _suitecxx . . $ mlspp/State#_suite.,
795 _group_idcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).,
796 _epochcxx . . $ mlspp/State#_epoch.,
797 _treecxx . . $ mlspp/State#_tree..root_hashcxx . . $ mlspp/TreeKEMPublicKey#root_hash(d7392ba79aa35767).(),
798 _transcript_hashcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.,
799 _extensionscxx . . $ mlspp/State#_extensions.,
800 };
801 }
802
803 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#>
804 Statecxx . . $ mlspp/State#::handlecxx . . $ mlspp/State#handle(2758c2375a1dbd3).(const MLSMessagecxx . . $ mlspp/MLSMessage#& msg)
805 {
806 return handlecxx . . $ mlspp/State#handle(3d54451646908156).(unwrapcxx . . $ mlspp/State#unwrap(250da7eac3b4c99).(msg), stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt., stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.);
807 }
808
809 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#>
810 Statecxx . . $ mlspp/State#::handlecxx . . $ mlspp/State#handle(2377cf03b043af66).(const MLSMessagecxx . . $ mlspp/MLSMessage#& msg, stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#> cached_state)
811 {
812 return handlecxx . . $ mlspp/State#handle(3d54451646908156).(unwrapcxx . . $ mlspp/State#unwrap(250da7eac3b4c99).(msg), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(cached_state), stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.);
813 }
814
815 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#>
816 Statecxx . . $ mlspp/State#::handlecxx . . $ mlspp/State#handle(e951bd52be32ec5).(const ValidatedContentcxx . . $ mlspp/ValidatedContent#& content_auth)
817 {
818 return handlecxx . . $ mlspp/State#handle(3d54451646908156).(content_auth, stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt., stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.);
819 }
820
821 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#>
822 Statecxx . . $ mlspp/State#::handlecxx . . $ mlspp/State#handle(71cce857922e66be).(const ValidatedContentcxx . . $ mlspp/ValidatedContent#& content_auth,
823 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#> cached_state)
824 {
825 return handlecxx . . $ mlspp/State#handle(3d54451646908156).(content_auth, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(cached_state), stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.);
826 }
827
828 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#>
829 Statecxx . . $ mlspp/State#::handlecxx . . $ mlspp/State#handle(3843c3f51eb90619).(const MLSMessagecxx . . $ mlspp/MLSMessage#& msg,
830 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#> cached_state,
831 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<CommitParamscxx . . $ mlspp/State#CommitParams#>& expected_params)
832 {
833 return handlecxx . . $ mlspp/State#handle(3d54451646908156).(unwrapcxx . . $ mlspp/State#unwrap(250da7eac3b4c99).(msg), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(cached_state), expected_params);
834 }
835
836 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#>
837 Statecxx . . $ mlspp/State#::handlecxx . . $ mlspp/State#handle(3d54451646908156).(const ValidatedContentcxx . . $ mlspp/ValidatedContent#& val_content,
838 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#> cached_state,
839 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<CommitParamscxx . . $ mlspp/State#CommitParams#>& expected_params)
840 {
841 // Dispatch on content type
842 const auto& content_auth = val_content.authenticated_contentcxx . . $ mlspp/ValidatedContent#authenticated_content(780253df4e70ffcf).();
843 const auto& content = content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content.;
844 switch (content.content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).()) {
845 // Proposals get queued, do not result in a state transition
846 case ContentTypecxx . . $ mlspp/ContentType#::proposalcxx . . $ mlspp/ContentType#proposal.:
847 cache_proposalcxx . . $ mlspp/State#cache_proposal(4cb5f50ea8a1da54).(content_auth);
848 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
849
850 // Commits are handled in the remainder of this method
851 case ContentTypecxx . . $ mlspp/ContentType#::commitcxx . . $ mlspp/ContentType#commit.:
852 break;
853
854 // Any other content type in this method is an error
855 default:
856 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid content type");
857 }
858
859 switch (content.sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).()) {
860 case SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.:
861 case SenderTypecxx . . $ mlspp/SenderType#::new_member_commitcxx . . $ mlspp/SenderType#new_member_commit.:
862 break;
863
864 default:
865 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid commit sender type");
866 }
867
868 auto sender = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#>();
869 if (content.sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).() == SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.) {
870 sender =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<MemberSendercxx . . $ mlspp/MemberSender#>(content.sendercxx . . $ mlspp/GroupContent#sender..sendercxx . . $ mlspp/Sender#sender.).sendercxx . . $ mlspp/MemberSender#sender.;
871 }
872
873 if (sender ==cxx . . $ std/`operator==`(348876303c74c3ee). _indexcxx . . $ mlspp/State#_index.) {
874 if (cached_state) {
875 // Verify that the cached state is a plausible successor to this state
876 const auto& next = opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(cached_state);
877 if (next._group_idcxx . . $ mlspp/State#_group_id. !=cxx . . $ mlspp/bytes_ns/bytes#`operator!=`(efd4f3c976ab92ce). _group_idcxx . . $ mlspp/State#_group_id. || next._epochcxx . . $ mlspp/State#_epoch. != _epochcxx . . $ mlspp/State#_epoch. + 1 ||
878 next._indexcxx . . $ mlspp/State#_index. !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). _indexcxx . . $ mlspp/State#_index.) {
879 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid successor state");
880 }
881
882 return nextcxx . . $ std/optional#optional(e3f0d6382bd52f24).;
883 }
884
885 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Handle own commits with caching");
886 }
887
888 // Apply the commit
889 const auto& commit = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Commitcxx . . $ mlspp/Commit#>(content.contentcxx . . $ mlspp/GroupContent#content.);
890 const auto proposals = must_resolvecxx . . $ mlspp/State#must_resolve(5bc28b2fad777aa5).(commit.proposalscxx . . $ mlspp/Commit#proposals., sender);
891
892 const auto params = infer_commit_typecxx . . $ mlspp/State#infer_commit_type(1740ce9eaeaed3ae).(sender, proposals, expected_params);
893 auto external_commit = var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<ExternalCommitParamscxx . . $ mlspp/State#ExternalCommitParams#>(params);
894
895 // Check that a path is present when required
896 if (path_requiredcxx . . $ mlspp/State#path_required(10e28906c0b85113).(proposals) && !commit.pathcxx . . $ mlspp/Commit#path.) {
897 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Path required but not present");
898 }
899
900 // Apply the proposals
901 auto next = successorcxx . . $ mlspp/State#successor(c5801eb416f519eb).();
902 auto [joiner_locations, psks] = next.applycxx . . $ mlspp/State#apply(8b7878ad0f8bc547).(proposals);
903
904 // If this is an external commit, add the joiner to the tree and note the
905 // location where they were added. Also, compute the "externally forced"
906 // value that we will use for the init_secret (as opposed to the init_secret
907 // from the key schedule).
908 auto force_init_secret = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>{};
909 auto sender_location = LeafIndexcxx . . $ mlspp/LeafIndex#{ 0 };
910 if (!external_commit) {
911 sender_location =cxx . . $ mlspp/LeafIndex#`operator=`(52b85dbf6b8ce299). opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(sender);
912 } else {
913 // Find where the joiner will be added
914 sender_location =cxx . . $ mlspp/LeafIndex#`operator=`(f64f93d71b0bc387). next._treecxx . . $ mlspp/State#_tree..allocate_leafcxx . . $ mlspp/TreeKEMPublicKey#allocate_leaf(1c00ca8acb9206b2).();
915
916 // Extract the forced init secret
917 auto kem_output = commit.valid_externalcxx . . $ mlspp/Commit#valid_external(82a679487d1deb04).();
918 if (!kem_output) {
919 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid external commit");
920 }
921
922 force_init_secret =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed).
923 _key_schedulecxx . . $ mlspp/State#_key_schedule..receive_external_initcxx . . $ mlspp/KeyScheduleEpoch#receive_external_init(c5e1b85e16e94921).(opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(kem_output));
924 }
925
926 // Decapsulate and apply the UpdatePath, if provided
927 auto commit_secret = _suitecxx . . $ mlspp/State#_suite..zerocxx . . $ mlspp/CipherSuite#zero(d7392ba79aa35767).();
928 if (commit.pathcxx . . $ mlspp/Commit#path.) {
929 const auto& path = opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(commit.pathcxx . . $ mlspp/Commit#path.);
930
931 if (!validcxx . . $ mlspp/State#valid(7686b21a80015e7b).(path.leaf_nodecxx . . $ mlspp/UpdatePath#leaf_node., LeafNodeSourcecxx . . $ mlspp/LeafNodeSource#::commitcxx . . $ mlspp/LeafNodeSource#commit., sender_locationcxx . . $ std/optional#optional(e3f0d6382bd52f24).)) {
932 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Commit path has invalid leaf node");
933 }
934
935 if (!next._treecxx . . $ mlspp/State#_tree..parent_hash_validcxx . . $ mlspp/TreeKEMPublicKey#parent_hash_valid(de8db98f2089d9d5).(sender_location, path)) {
936 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Commit path has invalid parent hash");
937 }
938
939 next._treecxx . . $ mlspp/State#_tree..mergecxx . . $ mlspp/TreeKEMPublicKey#merge(5dcbaa0a66e57c87).(sender_location, path);
940
941 auto ctx = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(GroupContextcxx . . $ mlspp/GroupContext#GroupContext(59c8082fdf1cbc0e).{
942 next._suitecxx . . $ mlspp/State#_suite.,
943 nextcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).._group_idcxx . . $ mlspp/State#_group_id.,
944 next._epochcxx . . $ mlspp/State#_epoch. + 1,
945 next._treecxx . . $ mlspp/State#_tree..root_hashcxx . . $ mlspp/TreeKEMPublicKey#root_hash(d7392ba79aa35767).(),
946 nextcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).._transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.,
947 next._extensionscxx . . $ mlspp/State#_extensions.,
948 });
949 next._tree_privcxx . . $ mlspp/State#_tree_priv..decapcxx . . $ mlspp/TreeKEMPrivateKey#decap(ca2156724251758f).(
950 sender_location, next._treecxx . . $ mlspp/State#_tree., ctxcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)., path, joiner_locations);
951
952 commit_secret =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(89adb9997e4a49c). next._tree_privcxx . . $ mlspp/State#_tree_priv..update_secretcxx . . $ mlspp/TreeKEMPrivateKey#update_secret.;
953 }
954
955 // Update the transcripts and advance the key schedule
956 next._transcript_hashcxx . . $ mlspp/State#_transcript_hash..updatecxx . . $ mlspp/TranscriptHash#update(15c3fae94687094).(content_auth);
957 next._epochcxx . . $ mlspp/State#_epoch. += 1;
958 next.update_epoch_secretscxx . . $ mlspp/State#update_epoch_secrets(34e1f8f66a1cf646).(commit_secret, { psks }, force_init_secret);
959
960 // Verify the confirmation MAC
961 const auto confirmation_tag =
962 next._key_schedulecxx . . $ mlspp/State#_key_schedule..confirmation_tagcxx . . $ mlspp/KeyScheduleEpoch#confirmation_tag(c5e1b85e16e94921).(next._transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.);
963 if (!content_auth.check_confirmation_tagcxx . . $ mlspp/AuthenticatedContent#check_confirmation_tag(efd4f3c976ab92ce).(confirmation_tag)) {
964 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Confirmation failed to verify");
965 }
966
967 return nextcxx . . $ std/optional#optional(e3f0d6382bd52f24).;
968 }
969
970 ///
971 /// Subgroup branching
972 ///
973
974 // Parameters:
975 // * ctor inputs
976 // * leaf_secret
977 // * commit_opts
978 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<Statecxx . . $ mlspp/State#, Welcomecxx . . $ mlspp/Welcome#>
979 Statecxx . . $ mlspp/State#::create_branchcxx . . $ mlspp/State#create_branch(ab7084bb38813f17).(bytescxx . . $ mlspp/bytes_ns/bytes# group_id,
980 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# enc_priv,
981 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
982 const LeafNodecxx . . $ mlspp/LeafNode#& leaf_node,
983 ExtensionListcxx . . $ mlspp/ExtensionList# extensions,
984 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<KeyPackagecxx . . $ mlspp/KeyPackage#>& key_packages,
985 const bytescxx . . $ mlspp/bytes_ns/bytes#& leaf_secret,
986 const CommitOptscxx . . $ mlspp/CommitOpts#& commit_opts) const
987 {
988 // Create new empty group with the appropriate PSK
989 auto new_group =
990 Statecxx . . $ mlspp/State#State(5c99977e15e97b35).{ stdcxx . . $ mlspp/bytes_ns/bytes#bytes(628b76f52f2a67f).::movecxx . . $ std/move(e35c19a1ba7baa26).(group_id), _suitecxx . . $ mlspp/State#_suite., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(enc_priv),
991 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv), leaf_node, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(extensions) };
992
993 new_group.add_resumption_pskcxx . . $ mlspp/State#add_resumption_psk(1af26b66f871bc85).(_group_idcxx . . $ mlspp/State#_group_id., _epochcxx . . $ mlspp/State#_epoch., _key_schedulecxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..resumption_pskcxx . . $ mlspp/KeyScheduleEpoch#resumption_psk.);
994
995 // Create Add proposals
996 auto proposals = stdxcxx . . $ mlspp/stdx/::transformcxx . . $ mlspp/stdx/transform(895a059819fd6266).<Proposalcxx . . $ mlspp/Proposal#>(
997 key_packages, [&](const auto& kp) { return new_group.add_proposalcxx . . $ mlspp/State#add_proposal(e4fd0120844a75d9).(kp); });
998
999 // Create PSK proposal
1000 proposals.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).({ PreSharedKeycxx . . $ mlspp/PreSharedKey#{
1001 { ResumptionPSKcxx . . $ mlspp/ResumptionPSK#{ ResumptionPSKUsagecxx . . $ mlspp/ResumptionPSKUsage#::branchcxx . . $ mlspp/ResumptionPSKUsage#branch., _group_idcxx . . $ mlspp/State#_group_id., _epochcxx . . $ mlspp/State#_epoch. },
1002 random_bytescxx . . $ mlspp/random_bytes(b7161179e0ed6f95).(_suitecxx . . $ mlspp/State#_suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()) } } });
1003
1004 // Commit the Add and PSK proposals
1005 auto opts = CommitOptscxx . . $ mlspp/CommitOpts#{
1006 proposals,
1007 commit_opts.inline_treecxx . . $ mlspp/CommitOpts#inline_tree.,
1008 commit_opts.force_pathcxx . . $ mlspp/CommitOpts#force_path.,
1009 commit_opts.leaf_node_optscxx . . $ mlspp/CommitOpts#leaf_node_opts.,
1010 };
1011 auto [_commit, welcome, state] = new_group.commitcxx . . $ mlspp/State#commit(c6dfec9d8a60f28e).(
1012 leaf_secret, optscxx . . $ std/optional#optional(e3f0d6382bd52f24)., {}, RestartCommitParamscxx . . $ std/variant#variant(5ba8255a4607184).{ ResumptionPSKUsagecxx . . $ mlspp/ResumptionPSKUsage#::branchcxx . . $ mlspp/ResumptionPSKUsage#branch. });
1013 return {cxx . . $ std/tuple#tuple(533e79eb6234819d). state, welcome };
1014 }
1015
1016 Statecxx . . $ mlspp/State#
1017 Statecxx . . $ mlspp/State#::handle_branchcxx . . $ mlspp/State#handle_branch(4ba8b9a80237b0d5).(const HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#& init_priv,
1018 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# enc_priv,
1019 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
1020 const KeyPackagecxx . . $ mlspp/KeyPackage#& key_package,
1021 const Welcomecxx . . $ mlspp/Welcome#& welcome,
1022 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#>& tree) const
1023 {
1024 auto resumption_psks =
1025 stdcxx . . $ std/map#map(7786ef3e167e36fa).::mapcxx . . $ std/map#<EpochRefcxx . . $ mlspp/State#EpochRef#, bytescxx . . $ mlspp/bytes_ns/bytes#>{ { { _group_idcxx . . $ mlspp/State#_group_id., _epochcxx . . $ mlspp/State#_epoch. },
1026 _key_schedulecxx . . $ mlspp/State#_key_schedule..resumption_pskcxx . . $ mlspp/KeyScheduleEpoch#resumption_psk. } };
1027 auto branch_state = Statecxx . . $ mlspp/State#State(e41efc7a5f03af4b).{
1028 init_priv,
1029 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(enc_priv),
1030 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv),
1031 key_package,
1032 welcome,
1033 tree,
1034 {cxx . . $ std/map#map(49f6e7a06ebc5aa8).},
1035 resumption_pskscxx . . $ std/map#map(46e52724c94dff27).,
1036 };
1037
1038 if (branch_state._suitecxx . . $ mlspp/State#_suite. !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). _suitecxx . . $ mlspp/State#_suite.) {
1039 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Attempt to branch with a different ciphersuite");
1040 }
1041
1042 if (branch_state._epochcxx . . $ mlspp/State#_epoch. != 1) {
1043 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Branch not done at the beginning of the group");
1044 }
1045
1046 return branch_state;
1047 }
1048
1049 Statecxx . . $ mlspp/State#::Tombstonecxx . . $ mlspp/State#Tombstone#::Tombstonecxx . . $ mlspp/State#Tombstone#Tombstone(bd3e5c3ab7d6b604).(const Statecxx . . $ mlspp/State#& state_in, ReInitcxx . . $ mlspp/ReInit# reinit_in)
1050 : epoch_authenticatorcxx . . $ mlspp/State#Tombstone#epoch_authenticator.(state_in.epoch_authenticatorcxx . . $ mlspp/State#epoch_authenticator(d7392ba79aa35767).())
1051 , reinitcxx . . $ mlspp/State#Tombstone#reinit.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(reinit_in))
1052 , prior_group_idcxx . . $ mlspp/State#Tombstone#prior_group_id.(state_in._group_idcxx . . $ mlspp/State#_group_id.)
1053 , prior_epochcxx . . $ mlspp/State#Tombstone#prior_epoch.(state_in._epochcxx . . $ mlspp/State#_epoch.)
1054 , resumption_pskcxx . . $ mlspp/State#Tombstone#resumption_psk.(state_in._key_schedulecxx . . $ mlspp/State#_key_schedule..resumption_pskcxx . . $ mlspp/KeyScheduleEpoch#resumption_psk.)
1055 {
1056 }
1057
1058 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<Statecxx . . $ mlspp/State#, Welcomecxx . . $ mlspp/Welcome#>
1059 Statecxx . . $ mlspp/State#::Tombstonecxx . . $ mlspp/State#Tombstone#::create_welcomecxx . . $ mlspp/State#Tombstone#create_welcome(da9bd202aa9ebf49).(HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# enc_priv,
1060 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
1061 const LeafNodecxx . . $ mlspp/LeafNode#& leaf_node,
1062 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<KeyPackagecxx . . $ mlspp/KeyPackage#>& key_packages,
1063 const bytescxx . . $ mlspp/bytes_ns/bytes#& leaf_secret,
1064 const CommitOptscxx . . $ mlspp/CommitOpts#& commit_opts) const
1065 {
1066 // Create new empty group with the appropriate PSK
1067 auto new_group =
1068 Statecxx . . $ mlspp/State#State(5c99977e15e97b35).{ reinitcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..group_idcxx . . $ mlspp/ReInit#group_id., reinitcxx . . $ mlspp/State#Tombstone#reinit..cipher_suitecxx . . $ mlspp/ReInit#cipher_suite., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(enc_priv),
1069 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv), leaf_node, reinitcxx . . $ mlspp/State#Tombstone#reinit..extensionscxx . . $ mlspp/ReInit#extensions. };
1070
1071 new_group.add_resumption_pskcxx . . $ mlspp/State#add_resumption_psk(1af26b66f871bc85).(prior_group_idcxx . . $ mlspp/State#Tombstone#prior_group_id., prior_epochcxx . . $ mlspp/State#Tombstone#prior_epoch., resumption_pskcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).);
1072
1073 // Create Add proposals
1074 auto proposals = stdxcxx . . $ mlspp/stdx/::transformcxx . . $ mlspp/stdx/transform(895a059819fd6266).<Proposalcxx . . $ mlspp/Proposal#>(
1075 key_packages, [&](const auto& kp) { return new_group.add_proposalcxx . . $ mlspp/State#add_proposal(e4fd0120844a75d9).(kp); });
1076
1077 // Create PSK proposal
1078 proposals.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).({ PreSharedKeycxx . . $ mlspp/PreSharedKey#{
1079 { ResumptionPSKcxx . . $ mlspp/ResumptionPSK#{ ResumptionPSKUsagecxx . . $ mlspp/ResumptionPSKUsage#::reinitcxx . . $ mlspp/ResumptionPSKUsage#reinit., prior_group_idcxx . . $ mlspp/State#Tombstone#prior_group_id., prior_epochcxx . . $ mlspp/State#Tombstone#prior_epoch. },
1080 random_bytescxx . . $ mlspp/random_bytes(b7161179e0ed6f95).(reinitcxx . . $ mlspp/State#Tombstone#reinit..cipher_suitecxx . . $ mlspp/ReInit#cipher_suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()) } } });
1081
1082 // Commit the Add and PSK proposals
1083 auto opts = CommitOptscxx . . $ mlspp/CommitOpts#{
1084 proposals,
1085 commit_opts.inline_treecxx . . $ mlspp/CommitOpts#inline_tree.,
1086 commit_opts.force_pathcxx . . $ mlspp/CommitOpts#force_path.,
1087 commit_opts.leaf_node_optscxx . . $ mlspp/CommitOpts#leaf_node_opts.,
1088 };
1089 auto [_commit, welcome, state] = new_group.commitcxx . . $ mlspp/State#commit(c6dfec9d8a60f28e).(
1090 leaf_secret, optscxx . . $ std/optional#optional(e3f0d6382bd52f24)., {}, RestartCommitParamscxx . . $ std/variant#variant(5ba8255a4607184).{ ResumptionPSKUsagecxx . . $ mlspp/ResumptionPSKUsage#::reinitcxx . . $ mlspp/ResumptionPSKUsage#reinit. });
1091 return {cxx . . $ std/tuple#tuple(533e79eb6234819d). state, welcome };
1092 }
1093
1094 Statecxx . . $ mlspp/State#
1095 Statecxx . . $ mlspp/State#::Tombstonecxx . . $ mlspp/State#Tombstone#::handle_welcomecxx . . $ mlspp/State#Tombstone#handle_welcome(4ba8b9a80237b0d5).(
1096 const HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#& init_priv,
1097 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey# enc_priv,
1098 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey# sig_priv,
1099 const KeyPackagecxx . . $ mlspp/KeyPackage#& key_package,
1100 const Welcomecxx . . $ mlspp/Welcome#& welcome,
1101 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#>& tree) const
1102 {
1103 auto resumption_psks =
1104 stdcxx . . $ std/map#map(7786ef3e167e36fa).::mapcxx . . $ std/map#<EpochRefcxx . . $ mlspp/State#EpochRef#, bytescxx . . $ mlspp/bytes_ns/bytes#>{ { { prior_group_idcxx . . $ mlspp/State#Tombstone#prior_group_id., prior_epochcxx . . $ mlspp/State#Tombstone#prior_epoch. },
1105 resumption_pskcxx . . $ mlspp/State#Tombstone#resumption_psk. } };
1106 auto new_state = Statecxx . . $ mlspp/State#State(e41efc7a5f03af4b).{
1107 init_priv,
1108 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(enc_priv),
1109 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sig_priv),
1110 key_package,
1111 welcome,
1112 tree,
1113 {cxx . . $ std/map#map(49f6e7a06ebc5aa8).},
1114 resumption_pskscxx . . $ std/map#map(46e52724c94dff27).,
1115 };
1116
1117 if (new_state._suitecxx . . $ mlspp/State#_suite. !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). reinitcxx . . $ mlspp/State#Tombstone#reinit..cipher_suitecxx . . $ mlspp/ReInit#cipher_suite.) {
1118 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Attempt to reinit with the wrong ciphersuite");
1119 }
1120
1121 if (new_state._epochcxx . . $ mlspp/State#_epoch. != 1) {
1122 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("ReInit not done at the beginning of the group");
1123 }
1124
1125 return new_state;
1126 }
1127
1128 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<Statecxx . . $ mlspp/State#::Tombstonecxx . . $ mlspp/State#Tombstone#, MLSMessagecxx . . $ mlspp/MLSMessage#>
1129 Statecxx . . $ mlspp/State#::reinit_commitcxx . . $ mlspp/State#reinit_commit(208a70250eab2009).(const bytescxx . . $ mlspp/bytes_ns/bytes#& leaf_secret,
1130 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<CommitOptscxx . . $ mlspp/CommitOpts#>& opts,
1131 const MessageOptscxx . . $ mlspp/MessageOpts#& msg_opts)
1132 {
1133 // Ensure that either the proposal cache or the inline proposals have a ReInit
1134 // proposal, and no others.
1135 auto reinit_proposal = Proposalcxx . . $ mlspp/Proposal#{};
1136 if (_pending_proposalscxx . . $ mlspp/State#_pending_proposals..sizecxx . . $ std/__cxx11/list#size(c9b1e749b64d5edc).() == 1) {
1137 reinit_proposal =cxx . . $ mlspp/Proposal#`operator=`(a2c185f7a2cce022). _pending_proposalscxx . . $ mlspp/State#_pending_proposals..frontcxx . . $ std/__cxx11/list#front(d5f1ba0ed5a2655c).().proposalcxx . . $ mlspp/State#CachedProposal#proposal.;
1138 } else if (opts && opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(opts).extra_proposalscxx . . $ mlspp/CommitOpts#extra_proposals..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() == 1) {
1139 reinit_proposal =cxx . . $ mlspp/Proposal#`operator=`(a2c185f7a2cce022). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(opts).extra_proposalscxx . . $ mlspp/CommitOpts#extra_proposals..frontcxx . . $ std/vector#front(af0004c3ce7cab93).();
1140 } else {
1141 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Illegal proposals for reinitialization");
1142 }
1143
1144 auto reinit = var::getcxx . . $ std/get(55ed64a6518b24d0).<ReInitcxx . . $ mlspp/ReInit#>(reinit_proposal.contentcxx . . $ mlspp/Proposal#content.);
1145
1146 // Create the commit
1147 const auto [commit_msg, welcome, new_state] =
1148 commitcxx . . $ mlspp/State#commit(c6dfec9d8a60f28e).(leaf_secret, opts, msg_opts, ReInitCommitParamscxx . . $ std/variant#variant(5ba8255a4607184).{});
1149 silence_unusedcxx . . $ mlspp/silence_unused(77d9f17553126ecb).(welcome);
1150
1151 // Create the Tombstone from the terminal state
1152 return {cxx . . $ std/tuple#tuple(68f3cec925df479f). {cxx . . $ mlspp/State#Tombstone#Tombstone(bd3e5c3ab7d6b604). new_state, reinit }, commit_msg };
1153 }
1154
1155 Statecxx . . $ mlspp/State#::Tombstonecxx . . $ mlspp/State#Tombstone#
1156 Statecxx . . $ mlspp/State#::handle_reinit_commitcxx . . $ mlspp/State#handle_reinit_commit(a89b469b6df7f29d).(const MLSMessagecxx . . $ mlspp/MLSMessage#& commit_msg)
1157 {
1158 // Verify the signature and process the commit
1159 const auto val_content = unwrapcxx . . $ mlspp/State#unwrap(250da7eac3b4c99).(commit_msg);
1160 const auto& content_auth = val_content.authenticated_contentcxx . . $ mlspp/ValidatedContent#authenticated_content(780253df4e70ffcf).();
1161 if (!verifycxx . . $ mlspp/State#verify(891fdc29165d76d0).(content_auth)) {
1162 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Message signature failed to verify");
1163 }
1164
1165 auto new_state =
1166 opt::getcxx . . $ mlspp/tls/opt/get(382ba35666c2b70b).(handlecxx . . $ mlspp/State#handle(3d54451646908156).(content_authcxx . . $ mlspp/ValidatedContent#ValidatedContent(4cb5f50ea8a1da54)., stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt., ReInitCommitParamscxx . . $ std/optional#optional(e3f0d6382bd52f24).{}));
1167
1168 // Extract the ReInit and create the Tombstone
1169 const auto& commit = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Commitcxx . . $ mlspp/Commit#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..contentcxx . . $ mlspp/GroupContent#content.);
1170 const auto proposals = must_resolvecxx . . $ mlspp/State#must_resolve(5bc28b2fad777aa5).(commit.proposalscxx . . $ mlspp/Commit#proposals., stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.);
1171 if (!valid_reinitcxx . . $ mlspp/State#valid_reinit(10e28906c0b85113).(proposals)) {
1172 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid proposals for reinit");
1173 }
1174
1175 const auto& reinit_proposal = proposals.frontcxx . . $ std/vector#front(af0004c3ce7cab93).();
1176 const auto& reinit = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<ReInitcxx . . $ mlspp/ReInit#>(reinit_proposal.proposalcxx . . $ mlspp/State#CachedProposal#proposal..contentcxx . . $ mlspp/Proposal#content.);
1177 return Tombstonecxx . . $ mlspp/State#Tombstone#Tombstone(bd3e5c3ab7d6b604).{ new_state, reinit };
1178 }
1179
1180 ///
1181 /// Internals
1182 ///
1183
1184 LeafIndexcxx . . $ mlspp/LeafIndex#
1185 Statecxx . . $ mlspp/State#::applycxx . . $ mlspp/State#apply(817d13f772d2b94f).(const Addcxx . . $ mlspp/Add#& add)
1186 {
1187 return _treecxx . . $ mlspp/State#_tree..add_leafcxx . . $ mlspp/TreeKEMPublicKey#add_leaf(9995a7bfeddd280).(add.key_packagecxx . . $ mlspp/Add#key_package..leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node.);
1188 }
1189
1190 void
1191 Statecxx . . $ mlspp/State#::applycxx . . $ mlspp/State#apply(bbabe14ce4ba551a).(LeafIndexcxx . . $ mlspp/LeafIndex# target, const Updatecxx . . $ mlspp/Update#& update)
1192 {
1193 _treecxx . . $ mlspp/State#_tree..update_leafcxx . . $ mlspp/TreeKEMPublicKey#update_leaf(b4be21d46bd512a5).(target, update.leaf_nodecxx . . $ mlspp/Update#leaf_node.);
1194 }
1195
1196 void
1197 Statecxx . . $ mlspp/State#::applycxx . . $ mlspp/State#apply(9773a327894cdb3).(LeafIndexcxx . . $ mlspp/LeafIndex# target,
1198 const Updatecxx . . $ mlspp/Update#& update,
1199 const HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#& leaf_priv)
1200 {
1201 _treecxx . . $ mlspp/State#_tree..update_leafcxx . . $ mlspp/TreeKEMPublicKey#update_leaf(b4be21d46bd512a5).(target, update.leaf_nodecxx . . $ mlspp/Update#leaf_node.);
1202 _tree_privcxx . . $ mlspp/State#_tree_priv..set_leaf_privcxx . . $ mlspp/TreeKEMPrivateKey#set_leaf_priv(35c8eff745156dde).(leaf_priv);
1203 }
1204
1205 LeafIndexcxx . . $ mlspp/LeafIndex#
1206 Statecxx . . $ mlspp/State#::applycxx . . $ mlspp/State#apply(a2de76d9299b6d75).(const Removecxx . . $ mlspp/Remove#& remove)
1207 {
1208 if (!_treecxx . . $ mlspp/State#_tree..has_leafcxx . . $ mlspp/TreeKEMPublicKey#has_leaf(be225f04b72ff6f7).(remove.removedcxx . . $ mlspp/Remove#removed.)) {
1209 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Attempt to remove non-member");
1210 }
1211
1212 _treecxx . . $ mlspp/State#_tree..blank_pathcxx . . $ mlspp/TreeKEMPublicKey#blank_path(5a3d3cee3fdf86fc).(remove.removedcxx . . $ mlspp/Remove#removed.);
1213 return remove.removedcxx . . $ mlspp/Remove#removed.;
1214 }
1215
1216 void
1217 Statecxx . . $ mlspp/State#::applycxx . . $ mlspp/State#apply(53e06667aef065e3).(const GroupContextExtensionscxx . . $ mlspp/GroupContextExtensions#& gce)
1218 {
1219 // TODO(RLB): Update spec to clarify that you MUST verify that the new
1220 // extensions are compatible with all members.
1221 if (!extensions_supportedcxx . . $ mlspp/State#extensions_supported(b1d6012e28b23e89).(gce.group_context_extensionscxx . . $ mlspp/GroupContextExtensions#group_context_extensions.)) {
1222 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Unsupported extensions in GroupContextExtensions");
1223 }
1224
1225 _extensionscxx . . $ mlspp/State#_extensions. =cxx . . $ mlspp/ExtensionList#`operator=`(8fb3dd954f866f51). gce.group_context_extensionscxx . . $ mlspp/GroupContextExtensions#group_context_extensions.;
1226 }
1227
1228 bool
1229 Statecxx . . $ mlspp/State#::extensions_supportedcxx . . $ mlspp/State#extensions_supported(b1d6012e28b23e89).(const ExtensionListcxx . . $ mlspp/ExtensionList#& exts) const
1230 {
1231 return _treecxx . . $ mlspp/State#_tree..all_leavescxx . . $ mlspp/TreeKEMPublicKey#all_leaves(8877ebe272b9620d).([&](auto /* i */, const auto& leaf_node) {
1232 return leaf_node.verify_extension_support(exts);
1233 });
1234 }
1235
1236 void
1237 Statecxx . . $ mlspp/State#::cache_proposalcxx . . $ mlspp/State#cache_proposal(4cb5f50ea8a1da54).(AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent# content_auth)
1238 {
1239 auto ref = _suitecxx . . $ mlspp/State#_suite..refcxx . . $ mlspp/CipherSuite#ref(b507ead0e101b284).(content_auth);
1240 if (stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(_pending_proposalscxx . . $ mlspp/State#_pending_proposals.,
1241 [&](const auto& cached) { return cached.ref ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ref; })) {
1242 return;
1243 }
1244
1245 auto sender_location = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#>();
1246 if (content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).() == SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.) {
1247 const auto& sender = content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..sendercxx . . $ mlspp/GroupContent#sender..sendercxx . . $ mlspp/Sender#sender.;
1248 sender_location =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<MemberSendercxx . . $ mlspp/MemberSender#>(sender).sendercxx . . $ mlspp/MemberSender#sender.;
1249 }
1250
1251 const auto& proposal = var::getcxx . . $ std/get(55ed64a6518b24d0).<Proposalcxx . . $ mlspp/Proposal#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..contentcxx . . $ mlspp/GroupContent#content.);
1252
1253 if (content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).() == SenderTypecxx . . $ mlspp/SenderType#::externalcxx . . $ mlspp/SenderType#external. &&
1254 !valid_external_proposal_typecxx . . $ mlspp/State#valid_external_proposal_type(3c978dac0e5ee2ad).(proposal.proposal_typecxx . . $ mlspp/Proposal#proposal_type(72085aa11f4b6e09).())) {
1255 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid external proposal");
1256 }
1257
1258 if (!validcxx . . $ mlspp/State#valid(1cfcf2061f410bee).(sender_location, proposal)) {
1259 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid proposal");
1260 }
1261
1262 _pending_proposalscxx . . $ mlspp/State#_pending_proposals..push_backcxx . . $ std/__cxx11/list#push_back(fe7a8a4d1eddb70).({
1263 _suitecxx . . $ mlspp/State#_suite..refcxx . . $ mlspp/CipherSuite#ref(b507ead0e101b284).(content_auth),
1264 proposal,
1265 sender_location,
1266 });
1267 }
1268
1269 stdcxx . . $ std/::optionalcxx . . $ std/optional#<Statecxx . . $ mlspp/State#::CachedProposalcxx . . $ mlspp/State#CachedProposal#>
1270 Statecxx . . $ mlspp/State#::resolvecxx . . $ mlspp/State#resolve(8b4a89bcc9579b5f).(const ProposalOrRefcxx . . $ mlspp/ProposalOrRef#& id,
1271 stdcxx . . $ std/::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#> sender_index) const
1272 {
1273 if (var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<Proposalcxx . . $ mlspp/Proposal#>(id.contentcxx . . $ mlspp/ProposalOrRef#content.)) {
1274 return CachedProposalcxx . . $ std/optional#optional(e3f0d6382bd52f24).{
1275 {},
1276 var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Proposalcxx . . $ mlspp/Proposal#>(id.contentcxx . . $ mlspp/ProposalOrRef#content.),
1277 sender_index,
1278 };
1279 }
1280
1281 const auto& ref = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<ProposalRefcxx . . $ mlspp/ProposalRef#>(id.contentcxx . . $ mlspp/ProposalOrRef#content.);
1282 for (const auto& cached : _pending_proposalscxx . . $ mlspp/State#_pending_proposals.) {
1283 if (cached.refcxx . . $ mlspp/State#CachedProposal#ref. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). ref) {
1284 return cachedcxx . . $ std/optional#optional(e3f0d6382bd52f24).;
1285 }
1286 }
1287
1288 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
1289 }
1290
1291 stdcxx . . $ std/::vectorcxx . . $ std/vector#<Statecxx . . $ mlspp/State#::CachedProposalcxx . . $ mlspp/State#CachedProposal#>
1292 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1293 Statecxx . . $ mlspp/State#::must_resolvecxx . . $ mlspp/State#must_resolve(5bc28b2fad777aa5).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<ProposalOrRefcxx . . $ mlspp/ProposalOrRef#>& ids,
1294 stdcxx . . $ std/::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#> sender_index) const
1295 {
1296 auto must_resolve = [&](const auto& id) {
1297 return opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(resolvecxx . . $ mlspp/State#resolve(8b4a89bcc9579b5f).(id, sender_index));
1298 };
1299 return stdxcxx . . $ mlspp/stdx/::transformcxx . . $ mlspp/stdx/transform(895a059819fd6266).<CachedProposalcxx . . $ mlspp/State#CachedProposal#>(ids, must_resolve);
1300 }
1301
1302 stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>
1303 Statecxx . . $ mlspp/State#::resolvecxx . . $ mlspp/State#resolve(93c5d9b7116d7785).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PreSharedKeyIDcxx . . $ mlspp/PreSharedKeyID#>& psks) const
1304 {
1305 return stdxcxx . . $ mlspp/stdx/::transformcxx . . $ mlspp/stdx/transform(895a059819fd6266).<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>(psks, [&](const auto& psk_id) {
1306 auto get_secret = overloaded{
1307 [&](const ExternalPSKcxx . . $ mlspp/ExternalPSK#& ext_psk) {
1308 if (_external_pskscxx . . $ mlspp/State#_external_psks..countcxx . . $ std/map#count(ea780b5adf43227).(ext_psk.psk_idcxx . . $ mlspp/ExternalPSK#psk_id.) == 0) {
1309 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Unknown external PSK");
1310 }
1311
1312 return _external_pskscxx . . $ mlspp/State#_external_psks..atcxx . . $ std/map#at(9bc8fa515171eae).(ext_psk.psk_idcxx . . $ mlspp/ExternalPSK#psk_id.);
1313 },
1314
1315 [&](const ResumptionPSKcxx . . $ mlspp/ResumptionPSK#& res_psk) {
1316 if (res_psk.psk_epochcxx . . $ mlspp/ResumptionPSK#psk_epoch. == _epochcxx . . $ mlspp/State#_epoch.) {
1317 return _key_schedulecxx . . $ mlspp/State#_key_schedule..resumption_pskcxx . . $ mlspp/KeyScheduleEpoch#resumption_psk.;
1318 }
1319
1320 auto key = stdcxx . . $ std/::make_tuplecxx . . $ std/make_tuple(3964edbfd7e8599f).(res_psk.psk_group_idcxx . . $ mlspp/ResumptionPSK#psk_group_id., res_psk.psk_epochcxx . . $ mlspp/ResumptionPSK#psk_epoch.);
1321 if (_resumption_pskscxx . . $ mlspp/State#_resumption_psks..countcxx . . $ std/map#count(ea780b5adf43227).(key) == 0) {
1322 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Unknown Resumption PSK");
1323 }
1324
1325 return _resumption_pskscxx . . $ mlspp/State#_resumption_psks..atcxx . . $ std/map#at(9bc8fa515171eae).(key);
1326 },
1327 };
1328
1329 auto secret = var::visitcxx . . $ std/visit(9828ab07ec69b3d0).(get_secret, psk_id.content);
1330 return PSKWithSecretcxx . . $ mlspp/PSKWithSecret#{ psk_id, secret };
1331 });
1332 }
1333
1334 stdcxx . . $ std/::vectorcxx . . $ std/vector#<LeafIndexcxx . . $ mlspp/LeafIndex#>
1335 Statecxx . . $ mlspp/State#::applycxx . . $ mlspp/State#apply(96903485d10560d).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals,
1336 Proposalcxx . . $ mlspp/Proposal#::Typecxx . . $ mlspp/Proposal#Type# required_type)
1337 {
1338 auto locations = stdcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).::vectorcxx . . $ std/vector#<LeafIndexcxx . . $ mlspp/LeafIndex#>{};
1339 for (const auto& cached : proposals) {
1340 auto proposal_type = cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..proposal_typecxx . . $ mlspp/Proposal#proposal_type(72085aa11f4b6e09).();
1341 if (proposal_type != required_type) {
1342 continue;
1343 }
1344
1345 switch (proposal_type) {
1346 case ProposalTypecxx . . $ mlspp/ProposalType#::addcxx . . $ mlspp/ProposalType#add.: {
1347 locations.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(applycxx . . $ mlspp/State#apply(817d13f772d2b94f).(var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Addcxx . . $ mlspp/Add#>(cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..contentcxx . . $ mlspp/Proposal#content.)));
1348 break;
1349 }
1350
1351 case ProposalTypecxx . . $ mlspp/ProposalType#::updatecxx . . $ mlspp/ProposalType#update.: {
1352 const auto& update = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Updatecxx . . $ mlspp/Update#>(cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..contentcxx . . $ mlspp/Proposal#content.);
1353
1354 if (!cached.sendercxx . . $ mlspp/State#CachedProposal#sender.) {
1355 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Update without target leaf");
1356 }
1357
1358 auto target = opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(cached.sendercxx . . $ mlspp/State#CachedProposal#sender.);
1359 if (target !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). _indexcxx . . $ mlspp/State#_index.) {
1360 applycxx . . $ mlspp/State#apply(bbabe14ce4ba551a).(target, update);
1361 break;
1362 }
1363
1364 if (!_cached_updatecxx . . $ mlspp/State#_cached_update.) {
1365 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Self-update with no cached secret");
1366 }
1367
1368 const auto& cached_update = opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(_cached_updatecxx . . $ mlspp/State#_cached_update.);
1369 if (update !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). cached_update.proposalcxx . . $ mlspp/State#CachedUpdate#proposal.) {
1370 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Self-update does not match cached data");
1371 }
1372
1373 applycxx . . $ mlspp/State#apply(9773a327894cdb3).(target, update, cached_update.update_privcxx . . $ mlspp/State#CachedUpdate#update_priv.);
1374 locations.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(target);
1375 break;
1376 }
1377
1378 case ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove.: {
1379 const auto& remove = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Removecxx . . $ mlspp/Remove#>(cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..contentcxx . . $ mlspp/Proposal#content.);
1380 locations.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(applycxx . . $ mlspp/State#apply(a2de76d9299b6d75).(remove));
1381 break;
1382 }
1383
1384 case ProposalTypecxx . . $ mlspp/ProposalType#::group_context_extensionscxx . . $ mlspp/ProposalType#group_context_extensions.: {
1385 const auto& gce =
1386 var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<GroupContextExtensionscxx . . $ mlspp/GroupContextExtensions#>(cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..contentcxx . . $ mlspp/Proposal#content.);
1387 applycxx . . $ mlspp/State#apply(53e06667aef065e3).(gce);
1388 break;
1389 }
1390
1391 default:
1392 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Unsupported proposal type");
1393 }
1394 }
1395
1396 // The cached update needs to be reset after applying proposals, so that it is
1397 // in a clean state for the next epoch.
1398 _cached_updatecxx . . $ mlspp/State#_cached_update..resetcxx . . $ std/optional#reset(ced63f7c635d850d).();
1399
1400 return locationscxx . . $ std/vector#vector(6f559d22b039ccdb).;
1401 }
1402
1403 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<LeafIndexcxx . . $ mlspp/LeafIndex#>, stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>>
1404 Statecxx . . $ mlspp/State#::applycxx . . $ mlspp/State#apply(8b7878ad0f8bc547).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals)
1405 {
1406 applycxx . . $ mlspp/State#apply(96903485d10560d).(proposals, ProposalTypecxx . . $ mlspp/ProposalType#::updatecxx . . $ mlspp/ProposalType#update.);
1407 applycxx . . $ mlspp/State#apply(96903485d10560d).(proposals, ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove.);
1408 auto joiner_locations = applycxx . . $ mlspp/State#apply(96903485d10560d).(proposals, ProposalTypecxx . . $ mlspp/ProposalType#::addcxx . . $ mlspp/ProposalType#add.);
1409 applycxx . . $ mlspp/State#apply(96903485d10560d).(proposals, ProposalTypecxx . . $ mlspp/ProposalType#::group_context_extensionscxx . . $ mlspp/ProposalType#group_context_extensions.);
1410
1411 // Extract the PSK proposals and look up the secrets
1412 // TODO(RLB): Factor this out, and also factor the above methods into
1413 // apply_update, apply_remove, etc.
1414 auto psk_ids = stdcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).::vectorcxx . . $ std/vector#<PreSharedKeyIDcxx . . $ mlspp/PreSharedKeyID#>{};
1415 for (const auto& cached : proposals) {
1416 if (cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..proposal_typecxx . . $ mlspp/Proposal#proposal_type(72085aa11f4b6e09).() != ProposalTypecxx . . $ mlspp/ProposalType#::pskcxx . . $ mlspp/ProposalType#psk.) {
1417 continue;
1418 }
1419
1420 const auto& proposal = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<PreSharedKeycxx . . $ mlspp/PreSharedKey#>(cached.proposalcxx . . $ mlspp/State#CachedProposal#proposal..contentcxx . . $ mlspp/Proposal#content.);
1421 psk_ids.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(proposal.pskcxx . . $ mlspp/PreSharedKey#psk.);
1422 }
1423 auto psks = resolvecxx . . $ mlspp/State#resolve(93c5d9b7116d7785).(psk_ids);
1424
1425 _treecxx . . $ mlspp/State#_tree..truncatecxx . . $ mlspp/TreeKEMPublicKey#truncate(49f6e7a06ebc5aa8).();
1426 _tree_privcxx . . $ mlspp/State#_tree_priv..truncatecxx . . $ mlspp/TreeKEMPrivateKey#truncate(a733f6ba51500b8c).(_treecxx . . $ mlspp/State#_tree..sizecxx . . $ mlspp/TreeKEMPublicKey#size.);
1427 _treecxx . . $ mlspp/State#_tree..set_hash_allcxx . . $ mlspp/TreeKEMPublicKey#set_hash_all(49f6e7a06ebc5aa8).();
1428 return {cxx . . $ std/tuple#tuple(533e79eb6234819d). joiner_locations, psks };
1429 }
1430
1431 ///
1432 /// Message protection
1433 ///
1434
1435 MLSMessagecxx . . $ mlspp/MLSMessage#
1436 Statecxx . . $ mlspp/State#::protectcxx . . $ mlspp/State#protect(ae39f86e951371d3).(const bytescxx . . $ mlspp/bytes_ns/bytes#& authenticated_data,
1437 const bytescxx . . $ mlspp/bytes_ns/bytes#& pt,
1438 size_t padding_size)
1439 {
1440 auto msg_opts = MessageOptscxx . . $ mlspp/MessageOpts#{ true, authenticated_data, padding_size };
1441 return protect_fullcxx . . $ mlspp/State#protect_full(1f2559e3f896eeae).(ApplicationDatacxx . . $ mlspp/ApplicationData#{ pt }, msg_opts);
1442 }
1443
1444 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<bytescxx . . $ mlspp/bytes_ns/bytes#, bytescxx . . $ mlspp/bytes_ns/bytes#>
1445 Statecxx . . $ mlspp/State#::unprotectcxx . . $ mlspp/State#unprotect(2711fe3526d2deb9).(const MLSMessagecxx . . $ mlspp/MLSMessage#& ct)
1446 {
1447 const auto val_content = unwrapcxx . . $ mlspp/State#unwrap(250da7eac3b4c99).(ct);
1448 const auto& content_auth = val_content.authenticated_contentcxx . . $ mlspp/ValidatedContent#authenticated_content(780253df4e70ffcf).();
1449
1450 if (!verifycxx . . $ mlspp/State#verify(891fdc29165d76d0).(content_auth)) {
1451 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Message signature failed to verify");
1452 }
1453
1454 if (content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).() != ContentTypecxx . . $ mlspp/ContentType#::applicationcxx . . $ mlspp/ContentType#application.) {
1455 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Unprotect of handshake message");
1456 }
1457
1458 if (content_auth.wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format. != WireFormatcxx . . $ mlspp/WireFormat#::mls_private_messagecxx . . $ mlspp/WireFormat#mls_private_message.) {
1459 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Application data not sent as PrivateMessage");
1460 }
1461
1462 return {cxx . . $ std/tuple#tuple(68f3cec925df479f).
1463 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..authenticated_datacxx . . $ mlspp/GroupContent#authenticated_data.,
1464 var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<ApplicationDatacxx . . $ mlspp/ApplicationData#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..contentcxx . . $ mlspp/GroupContent#content.).datacxx . . $ mlspp/ApplicationData#data.,
1465 };
1466 }
1467
1468 ///
1469 /// Properties of a proposal list
1470 ///
1471
1472 bool
1473 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(7686b21a80015e7b).(const LeafNodecxx . . $ mlspp/LeafNode#& leaf_node,
1474 LeafNodeSourcecxx . . $ mlspp/LeafNodeSource# required_source,
1475 stdcxx . . $ std/::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#> index) const
1476 {
1477 // Verify that the credential in the LeafNode is valid as described in Section
1478 // 5.3.1.
1479 // XXX(RLB) N/A, no credential validation in the library right now
1480
1481 // Verify the leaf_node_source field:
1482 const auto correct_source = (leaf_node.sourcecxx . . $ mlspp/LeafNode#source(55e6e70ced2b7f9f).() == required_source);
1483
1484 // Verify that the signature on the LeafNode is valid using signature_key.
1485 auto binding = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<LeafNodecxx . . $ mlspp/LeafNode#::MemberBindingcxx . . $ mlspp/LeafNode#MemberBinding#>{};
1486 switch (required_source) {
1487 case LeafNodeSourcecxx . . $ mlspp/LeafNodeSource#::commitcxx . . $ mlspp/LeafNodeSource#commit.:
1488 case LeafNodeSourcecxx . . $ mlspp/LeafNodeSource#::updatecxx . . $ mlspp/LeafNodeSource#update.:
1489 binding =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). LeafNodecxx . . $ mlspp/LeafNode#::MemberBindingcxx . . $ mlspp/LeafNode#MemberBinding#{ _group_idcxx . . $ mlspp/State#_group_id., opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(index) };
1490 break;
1491
1492 default:
1493 // Nothing to do
1494 break;
1495 }
1496
1497 const auto signature_valid = leaf_node.verifycxx . . $ mlspp/LeafNode#verify(d1779568e26cb1db).(_suitecxx . . $ mlspp/State#_suite., binding);
1498
1499 // Verify that the LeafNode is compatible with the group's parameters. If the
1500 // GroupContext has a required_capabilities extension, then the required
1501 // extensions, proposals, and credential types MUST be listed in the
1502 // LeafNode's capabilities field.
1503 const auto supports_group_extensions =
1504 leaf_node.verify_extension_supportcxx . . $ mlspp/LeafNode#verify_extension_support(b1d6012e28b23e89).(_extensionscxx . . $ mlspp/State#_extensions.);
1505
1506 // TODO(RLB) Verify the lifetime field
1507
1508 // Verify that the credential type is supported by all members of the group,
1509 // as specified by the capabilities field of each member's LeafNode, and that
1510 // the capabilities field of this LeafNode indicates support for all the
1511 // credential types currently in use by other members.
1512 //
1513 // Verify that the following fields are unique among the members of the group:
1514 // signature_key
1515 // encryption_key
1516 //
1517 // Note: Uniqueness of signature and encryption keys is assured by the
1518 // tree operations (add/update), so we do not need to verify those here.
1519 const auto mutual_credential_support =
1520 _treecxx . . $ mlspp/State#_tree..all_leavescxx . . $ mlspp/TreeKEMPublicKey#all_leaves(8877ebe272b9620d).([&](auto /* i */, const auto& leaf) {
1521 return leaf.capabilities.credential_supported(leaf_node.credentialcxx . . $ mlspp/LeafNode#credential.) &&
1522 leaf_node.capabilitiescxx . . $ mlspp/LeafNode#capabilities..credential_supportedcxx . . $ mlspp/Capabilities#credential_supported(cc412b879dbc0a1e).(leaf.credential);
1523 });
1524
1525 // Verify that the extensions in the LeafNode are supported by checking that
1526 // the ID for each extension in the extensions field is listed in the
1527 // capabilities.extensions field of the LeafNode.
1528 auto supports_own_extensions =
1529 leaf_node.verify_extension_supportcxx . . $ mlspp/LeafNode#verify_extension_support(b1d6012e28b23e89).(leaf_node.extensionscxx . . $ mlspp/LeafNode#extensions.);
1530
1531 return (signature_valid && supports_group_extensions && correct_source &&
1532 mutual_credential_support && supports_own_extensions);
1533 }
1534
1535 bool
1536 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(631cf8aff067838e).(const KeyPackagecxx . . $ mlspp/KeyPackage#& key_package) const
1537 {
1538 // Verify that the ciphersuite and protocol version of the KeyPackage match
1539 // those in the GroupContext.
1540 const auto correct_ciphersuite = (key_package.cipher_suitecxx . . $ mlspp/KeyPackage#cipher_suite. ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). _suitecxx . . $ mlspp/State#_suite.);
1541
1542 // Verify that the signature on the KeyPackage is valid using the public key
1543 // in leaf_node.credential.
1544 const auto valid_signature = key_package.verifycxx . . $ mlspp/KeyPackage#verify(50ce9a9e25b4a850).();
1545
1546 // Verify that the leaf_node of the KeyPackage is valid for a KeyPackage
1547 // according to Section 7.3.
1548 const auto leaf_node_valid =
1549 validcxx . . $ mlspp/State#valid(7686b21a80015e7b).(key_package.leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node., LeafNodeSourcecxx . . $ mlspp/LeafNodeSource#::key_packagecxx . . $ mlspp/LeafNodeSource#key_package., stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.);
1550
1551 // Verify that the value of leaf_node.encryption_key is different from the
1552 // value of the init_key field.
1553 const auto distinct_keys =
1554 (key_package.init_keycxx . . $ mlspp/KeyPackage#init_key. !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). key_package.leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node..encryption_keycxx . . $ mlspp/LeafNode#encryption_key.);
1555
1556 return (correct_ciphersuite && valid_signature && leaf_node_valid &&
1557 distinct_keys);
1558 }
1559
1560 bool
1561 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(93270e26fed03509).(const Addcxx . . $ mlspp/Add#& add) const
1562 {
1563 return validcxx . . $ mlspp/State#valid(631cf8aff067838e).(add.key_packagecxx . . $ mlspp/Add#key_package.);
1564 }
1565
1566 bool
1567 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(f8526462f5e1c3fa).(LeafIndexcxx . . $ mlspp/LeafIndex# sender, const Updatecxx . . $ mlspp/Update#& update) const
1568 {
1569 const auto maybe_leaf = _treecxx . . $ mlspp/State#_tree..leaf_nodecxx . . $ mlspp/TreeKEMPublicKey#leaf_node(e2d641b4ea45e2f).(sender);
1570 if (!maybe_leaf) {
1571 return false;
1572 }
1573
1574 return validcxx . . $ mlspp/State#valid(7686b21a80015e7b).(update.leaf_nodecxx . . $ mlspp/Update#leaf_node., LeafNodeSourcecxx . . $ mlspp/LeafNodeSource#::updatecxx . . $ mlspp/LeafNodeSource#update., sendercxx . . $ std/optional#optional(e3f0d6382bd52f24).);
1575 }
1576
1577 bool
1578 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(d182833d0433cb04).(const Removecxx . . $ mlspp/Remove#& remove) const
1579 {
1580 // We mark self-removes invalid here even though a resync Commit will
1581 // sometimes cause them. This is OK because this method is only called from
1582 // the normal proposal list validation method, not the external commit one.
1583 auto in_tree = remove.removedcxx . . $ mlspp/Remove#removed. <cxx . . $ mlspp/LeafIndex#`operator<`(6a6f1ee87d9a491e). _treecxx . . $ mlspp/State#_tree..sizecxx . . $ mlspp/TreeKEMPublicKey#size. && _treecxx . . $ mlspp/State#_tree..has_leafcxx . . $ mlspp/TreeKEMPublicKey#has_leaf(be225f04b72ff6f7).(remove.removedcxx . . $ mlspp/Remove#removed.);
1584 auto not_me = remove.removedcxx . . $ mlspp/Remove#removed. !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). _indexcxx . . $ mlspp/State#_index.;
1585 return in_tree && not_me;
1586 }
1587
1588 bool
1589 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(16425a0d68d68158).(const PreSharedKeycxx . . $ mlspp/PreSharedKey#& psk) const
1590 {
1591 // External PSKs are allowed if we have the corresponding secret
1592 if (var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<ExternalPSKcxx . . $ mlspp/ExternalPSK#>(psk.pskcxx . . $ mlspp/PreSharedKey#psk..contentcxx . . $ mlspp/PreSharedKeyID#content.)) {
1593 const auto& ext_psk = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<ExternalPSKcxx . . $ mlspp/ExternalPSK#>(psk.pskcxx . . $ mlspp/PreSharedKey#psk..contentcxx . . $ mlspp/PreSharedKeyID#content.);
1594 return _external_pskscxx . . $ mlspp/State#_external_psks..countcxx . . $ std/map#count(ea780b5adf43227).(ext_psk.psk_idcxx . . $ mlspp/ExternalPSK#psk_id.) > 0;
1595 }
1596
1597 // Resumption PSKs are allowed only with usage 'application', and only if we
1598 // have the corresponding secret.
1599 if (var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<ResumptionPSKcxx . . $ mlspp/ResumptionPSK#>(psk.pskcxx . . $ mlspp/PreSharedKey#psk..contentcxx . . $ mlspp/PreSharedKeyID#content.)) {
1600 const auto& res_psk = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<ResumptionPSKcxx . . $ mlspp/ResumptionPSK#>(psk.pskcxx . . $ mlspp/PreSharedKey#psk..contentcxx . . $ mlspp/PreSharedKeyID#content.);
1601 if (res_psk.usagecxx . . $ mlspp/ResumptionPSK#usage. != ResumptionPSKUsagecxx . . $ mlspp/ResumptionPSKUsage#::applicationcxx . . $ mlspp/ResumptionPSKUsage#application.) {
1602 return false;
1603 }
1604
1605 const auto key = stdcxx . . $ std/::make_tuplecxx . . $ std/make_tuple(3964edbfd7e8599f).(res_psk.psk_group_idcxx . . $ mlspp/ResumptionPSK#psk_group_id., res_psk.psk_epochcxx . . $ mlspp/ResumptionPSK#psk_epoch.);
1606 return res_psk.psk_epochcxx . . $ mlspp/ResumptionPSK#psk_epoch. == _epochcxx . . $ mlspp/State#_epoch. || _resumption_pskscxx . . $ mlspp/State#_resumption_psks..countcxx . . $ std/map#count(ea780b5adf43227).(key) > 0;
1607 }
1608
1609 return false;
1610 }
1611
1612 bool
1613 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(78776dccf133dbdb).(const ReInitcxx . . $ mlspp/ReInit#& reinit)
1614 {
1615 // Check that the version and CipherSuite are ones we support
1616 auto supported_version = (reinit.versioncxx . . $ mlspp/ReInit#version. == ProtocolVersioncxx . . $ mlspp/ProtocolVersion#::mls10cxx . . $ mlspp/ProtocolVersion#mls10.);
1617 auto supported_suite =
1618 stdxcxx . . $ mlspp/stdx/::containscxx . . $ mlspp/stdx/contains(acb94948942028a1).(all_supported_suitescxx . . $ mlspp/all_supported_suites., reinit.cipher_suitecxx . . $ mlspp/ReInit#cipher_suite..cipher_suitecxx . . $ mlspp/CipherSuite#cipher_suite(49aa5d40b84760c0).());
1619
1620 return supported_version && supported_suite;
1621 }
1622
1623 bool
1624 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(6117d87957a79960).(const ExternalInitcxx . . $ mlspp/ExternalInit#& external_init) const
1625 {
1626 return external_init.kem_outputcxx . . $ mlspp/ExternalInit#kem_output..sizecxx . . $ mlspp/bytes_ns/bytes#size(fe4d2d262d4164a8).() == _suitecxx . . $ mlspp/State#_suite..hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..enc_sizecxx . . $ mlspp/hpke/KEM#enc_size.;
1627 }
1628
1629 bool
1630 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(c638b1b939771a6f).(const GroupContextExtensionscxx . . $ mlspp/GroupContextExtensions#& gce) const
1631 {
1632 return extensions_supportedcxx . . $ mlspp/State#extensions_supported(b1d6012e28b23e89).(gce.group_context_extensionscxx . . $ mlspp/GroupContextExtensions#group_context_extensions.);
1633 }
1634
1635 bool
1636 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(1cfcf2061f410bee).(stdcxx . . $ std/::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#> sender, const Proposalcxx . . $ mlspp/Proposal#& proposal) const
1637 {
1638 const auto specifically_valid = overloaded{
1639 [&](const Updatecxx . . $ mlspp/Update#& update) { return validcxx . . $ mlspp/State#valid(f8526462f5e1c3fa).(opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(sender), update); },
1640 [&](const auto& proposal) { return validcxx . . $ mlspp/State#valid(16425a0d68d68158).(proposal); },
1641 };
1642 return var::visitcxx . . $ std/visit(9828ab07ec69b3d0).(specifically_valid, proposal.contentcxx . . $ mlspp/Proposal#content.);
1643 }
1644
1645 bool
1646 Statecxx . . $ mlspp/State#::validcxx . . $ mlspp/State#valid(5b837f842e0476dd).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals,
1647 LeafIndexcxx . . $ mlspp/LeafIndex# commit_sender,
1648 const CommitParamscxx . . $ mlspp/State#CommitParams#& params) const
1649 {
1650 auto specifically = overloaded{
1651 [&](const NormalCommitParamscxx . . $ mlspp/State#NormalCommitParams#& /* unused */) {
1652 return valid_normalcxx . . $ mlspp/State#valid_normal(a3e4f4503fe1bf58).(proposals, commit_sender);
1653 },
1654 [&](const ExternalCommitParamscxx . . $ mlspp/State#ExternalCommitParams#& /* unused */) {
1655 return valid_externalcxx . . $ mlspp/State#valid_external(2e14fbd53494efe4).(proposals);
1656 },
1657 [&](const RestartCommitParamscxx . . $ mlspp/State#RestartCommitParams#& params) {
1658 return valid_restartcxx . . $ mlspp/State#valid_restart(459c8a53464c5055).(proposals, params.allowed_usagecxx . . $ mlspp/State#RestartCommitParams#allowed_usage.);
1659 },
1660 [&](const ReInitCommitParamscxx . . $ mlspp/State#ReInitCommitParams#& /* unused */) {
1661 return valid_reinitcxx . . $ mlspp/State#valid_reinit(10e28906c0b85113).(proposals);
1662 },
1663 };
1664
1665 return var::visitcxx . . $ std/visit(9828ab07ec69b3d0).(specifically, params);
1666 }
1667
1668 bool
1669 // NB(RLB): clang-tidy thinks this can be static, but it can't.
1670 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1671 Statecxx . . $ mlspp/State#::valid_normalcxx . . $ mlspp/State#valid_normal(a3e4f4503fe1bf58).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals,
1672 LeafIndexcxx . . $ mlspp/LeafIndex# commit_sender) const
1673 {
1674 // It contains an individual proposal that is invalid as specified in Section
1675 // 12.1.
1676 const auto has_invalid_proposal =
1677 stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1678 return !validcxx . . $ mlspp/State#valid(16425a0d68d68158).(cached.sender, cached.proposal);
1679 });
1680
1681 // It contains an Update proposal generated by the committer.
1682 const auto has_self_update = stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1683 return cached.proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::updatecxx . . $ mlspp/ProposalType#update. &&
1684 cached.sender ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). commit_sender;
1685 });
1686
1687 // It contains a Remove proposal that removes the committer.
1688 const auto has_self_remove = stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1689 return cached.proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove. &&
1690 var::getcxx . . $ std/get(5aabc72a970aa7ce).<Removecxx . . $ mlspp/Remove#>(cached.proposal.content).removed ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). commit_sender;
1691 });
1692
1693 // It contains multiple Update and/or Remove proposals that apply to the same
1694 // leaf. If the committer has received multiple such proposals they SHOULD
1695 // prefer any Remove received, or the most recent Update if there are no
1696 // Removes.
1697 auto updated_or_removed = stdcxx . . $ std/set#set(49f6e7a06ebc5aa8).::setcxx . . $ std/set#<LeafIndexcxx . . $ mlspp/LeafIndex#>{};
1698 const auto has_dup_update_remove =
1699 stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1700 auto index = LeafIndexcxx . . $ mlspp/LeafIndex#{ 0 };
1701 switch (cached.proposal.proposal_type()) {
1702 case ProposalTypecxx . . $ mlspp/ProposalType#::updatecxx . . $ mlspp/ProposalType#update.:
1703 index = opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(cached.sender);
1704 break;
1705
1706 case ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove.:
1707 index = var::getcxx . . $ std/get(5aabc72a970aa7ce).<Removecxx . . $ mlspp/Remove#>(cached.proposal.content).removed;
1708 break;
1709
1710 default:
1711 return false;
1712 }
1713
1714 if (stdxcxx . . $ mlspp/stdx/::containscxx . . $ mlspp/stdx/contains(acb94948942028a1).(updated_or_removed, index)) {
1715 return true;
1716 }
1717
1718 updated_or_removed.insertcxx . . $ std/set#insert(411a10a755068dfe).(index);
1719 return false;
1720 });
1721
1722 // It contains multiple Add proposals that contain KeyPackages that represent
1723 // the same client according to the application (for example, identical
1724 // signature keys).
1725 auto signature_keys = stdcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).::vectorcxx . . $ std/vector#<SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#>{};
1726 const auto has_dup_signature_key =
1727 stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1728 if (cached.proposal.proposal_type() !=cxx . . $ mlspp/`operator!=`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::addcxx . . $ mlspp/ProposalType#add.) {
1729 return false;
1730 }
1731
1732 auto key_package = var::getcxx . . $ std/get(5aabc72a970aa7ce).<Addcxx . . $ mlspp/Add#>(cached.proposal.content).key_package;
1733 auto signature_key = key_package.leaf_node.signature_key;
1734 if (stdxcxx . . $ mlspp/stdx/::containscxx . . $ mlspp/stdx/contains(acb94948942028a1).(signature_keys, signature_key)) {
1735 return true;
1736 }
1737
1738 signature_keys.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(signature_key);
1739 return false;
1740 });
1741
1742 // It contains an Add proposal with a KeyPackage that represents a client
1743 // already in the group according to the application, unless there is a Remove
1744 // proposal in the list removing the matching client from the group.
1745 // TODO(RLB)
1746
1747 // It contains multiple PreSharedKey proposals that reference the same
1748 // PreSharedKeyID.
1749 auto psk_ids = stdcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).::vectorcxx . . $ std/vector#<PreSharedKeyIDcxx . . $ mlspp/PreSharedKeyID#>{};
1750 const auto has_dup_psk_id = stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1751 if (cached.proposal.proposal_type() !=cxx . . $ mlspp/`operator!=`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::pskcxx . . $ mlspp/ProposalType#psk.) {
1752 return false;
1753 }
1754
1755 auto psk_id = var::getcxx . . $ std/get(5aabc72a970aa7ce).<PreSharedKeycxx . . $ mlspp/PreSharedKey#>(cached.proposal.content).psk;
1756 if (stdxcxx . . $ mlspp/stdx/::containscxx . . $ mlspp/stdx/contains(acb94948942028a1).(psk_ids, psk_id)) {
1757 return true;
1758 }
1759
1760 psk_ids.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(psk_id);
1761 return false;
1762 });
1763
1764 // It contains multiple GroupContextExtensions proposals.
1765 const auto gce_count = stdxcxx . . $ mlspp/stdx/::count_ifcxx . . $ mlspp/stdx/count_if(91f28ad055782622).(proposals, [](const auto& cached) {
1766 return cached.proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558).
1767 ProposalTypecxx . . $ mlspp/ProposalType#::group_context_extensionscxx . . $ mlspp/ProposalType#group_context_extensions.;
1768 });
1769 const auto has_multiple_gce = (gce_count > 1);
1770
1771 // It contains a ReInit proposal together with any other proposal. If the
1772 // committer has received other proposals during the epoch, they SHOULD prefer
1773 // them over the ReInit proposal, allowing the ReInit to be resent and applied
1774 // in a subsequent epoch.
1775 const auto has_reinit = stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [](const auto& cached) {
1776 return cached.proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::reinitcxx . . $ mlspp/ProposalType#reinit.;
1777 });
1778
1779 // It contains an ExternalInit proposal.
1780 const auto has_external_init =
1781 stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [](const auto& cached) {
1782 return cached.proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::external_initcxx . . $ mlspp/ProposalType#external_init.;
1783 });
1784
1785 // It contains a proposal with a non-default proposal type that is not
1786 // supported by some members of the group that will process the Commit (i.e.,
1787 // members being added or removed by the Commit do not need to support the
1788 // proposal type).
1789 // XXX(RLB): N/A, no non-default proposal types
1790
1791 // After processing the commit the ratchet tree is invalid, in particular, if
1792 // it contains any leaf node that is invalid according to Section 7.3.
1793 //
1794 // NB(RLB): Leaf nodes are already checked in the individual proposal check at
1795 // the top. So the focus here is key uniqueness. We check this by checking
1796 // uniqueness of encryption keys across the Adds and Updates in this list of
1797 // proposals. The keys have already been checked to be distinct from any keys
1798 // already in the tree.
1799 auto enc_keys = stdcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).::vectorcxx . . $ std/vector#<HPKEPublicKeycxx . . $ mlspp/HPKEPublicKey#>{};
1800 const auto has_dup_enc_key = stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1801 const auto get_enc_key =
1802 overloaded{ [](const Addcxx . . $ mlspp/Add#& add) -> stdcxx . . $ std/::optionalcxx . . $ std/optional#<HPKEPublicKeycxx . . $ mlspp/HPKEPublicKey#> {
1803 return addcxx . . $ std/optional#optional(e3f0d6382bd52f24)..key_packagecxx . . $ mlspp/Add#key_package..leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node..encryption_keycxx . . $ mlspp/LeafNode#encryption_key.;
1804 },
1805 [](const Updatecxx . . $ mlspp/Update#& update) -> stdcxx . . $ std/::optionalcxx . . $ std/optional#<HPKEPublicKeycxx . . $ mlspp/HPKEPublicKey#> {
1806 return updatecxx . . $ std/optional#optional(e3f0d6382bd52f24)..leaf_nodecxx . . $ mlspp/Update#leaf_node..encryption_keycxx . . $ mlspp/LeafNode#encryption_key.;
1807 },
1808
1809 [](const auto& /* default */)
1810 -> stdcxx . . $ std/::optionalcxx . . $ std/optional#<HPKEPublicKeycxx . . $ mlspp/HPKEPublicKey#> { return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.; } };
1811 auto maybe_enc_key = var::visitcxx . . $ std/visit(9828ab07ec69b3d0).(get_enc_key, cached.proposal.content);
1812 if (!maybe_enc_key) {
1813 return false;
1814 }
1815
1816 const auto& enc_key = opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_enc_key);
1817 if (stdxcxx . . $ mlspp/stdx/::containscxx . . $ mlspp/stdx/contains(acb94948942028a1).(enc_keys, enc_key)) {
1818 return true;
1819 }
1820
1821 enc_keys.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(enc_key);
1822 return false;
1823 });
1824
1825 return !(has_invalid_proposal || has_self_update || has_self_remove ||
1826 has_dup_update_remove || has_dup_signature_key || has_dup_psk_id ||
1827 has_multiple_gce || has_reinit || has_external_init ||
1828 has_dup_enc_key);
1829 }
1830
1831 bool
1832 Statecxx . . $ mlspp/State#::valid_reinitcxx . . $ mlspp/State#valid_reinit(10e28906c0b85113).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals)
1833 {
1834 // Check that the list contains a ReInit proposal
1835 const auto has_reinit = stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [](const auto& cached) {
1836 return cached.proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::reinitcxx . . $ mlspp/ProposalType#reinit.;
1837 });
1838
1839 // Check whether the list contains any disallowed proposals
1840 const auto has_disallowed = stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [](const auto& cached) {
1841 return cached.proposal.proposal_type() !=cxx . . $ mlspp/`operator!=`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::reinitcxx . . $ mlspp/ProposalType#reinit.;
1842 });
1843
1844 return has_reinit && !has_disallowed;
1845 }
1846
1847 bool
1848 Statecxx . . $ mlspp/State#::valid_restartcxx . . $ mlspp/State#valid_restart(459c8a53464c5055).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals,
1849 ResumptionPSKUsagecxx . . $ mlspp/ResumptionPSKUsage# allowed_usage)
1850 {
1851 // Check that the list has exactly one resumption PSK proposal with the
1852 // allowed usage and any other PSKs are external
1853 auto found_allowed = false;
1854 const auto acceptable_psks = stdxcxx . . $ mlspp/stdx/::all_ofcxx . . $ mlspp/stdx/all_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1855 if (cached.proposal.proposal_type() !=cxx . . $ mlspp/`operator!=`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::pskcxx . . $ mlspp/ProposalType#psk.) {
1856 return true;
1857 }
1858
1859 const auto& psk = var::getcxx . . $ std/get(5aabc72a970aa7ce).<PreSharedKeycxx . . $ mlspp/PreSharedKey#>(cached.proposal.content);
1860 if (var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<ExternalPSKcxx . . $ mlspp/ExternalPSK#>(psk.psk.content)) {
1861 return true;
1862 }
1863
1864 const auto& res_psk = var::getcxx . . $ std/get(5aabc72a970aa7ce).<ResumptionPSKcxx . . $ mlspp/ResumptionPSK#>(psk.psk.content);
1865 const auto allowed = res_psk.usage ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). allowed_usage;
1866 if (found_allowed && allowed) {
1867 return false;
1868 }
1869
1870 found_allowed = found_allowed || allowed;
1871 return true;
1872 });
1873
1874 return acceptable_psks && found_allowed;
1875 }
1876
1877 bool
1878 Statecxx . . $ mlspp/State#::valid_external_proposal_typecxx . . $ mlspp/State#valid_external_proposal_type(3c978dac0e5ee2ad).(const Proposalcxx . . $ mlspp/Proposal#::Typecxx . . $ mlspp/Proposal#Type# proposal_type)
1879 {
1880 switch (proposal_type) {
1881 case ProposalTypecxx . . $ mlspp/ProposalType#::addcxx . . $ mlspp/ProposalType#add.:
1882 case ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove.:
1883 case ProposalTypecxx . . $ mlspp/ProposalType#::pskcxx . . $ mlspp/ProposalType#psk.:
1884 case ProposalTypecxx . . $ mlspp/ProposalType#::reinitcxx . . $ mlspp/ProposalType#reinit.:
1885 case ProposalTypecxx . . $ mlspp/ProposalType#::group_context_extensionscxx . . $ mlspp/ProposalType#group_context_extensions.:
1886 return true;
1887
1888 default:
1889 return false;
1890 }
1891 }
1892
1893 bool
1894 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1895 Statecxx . . $ mlspp/State#::valid_externalcxx . . $ mlspp/State#valid_external(2e14fbd53494efe4).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals) const
1896 {
1897 // Exactly one ExternalInit
1898 auto ext_init_count = stdxcxx . . $ mlspp/stdx/::count_ifcxx . . $ mlspp/stdx/count_if(91f28ad055782622).(proposals, [](const auto& cached) {
1899 return cached.proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::external_initcxx . . $ mlspp/ProposalType#external_init.;
1900 });
1901 auto one_ext_init = (ext_init_count == 1);
1902
1903 // At most one Remove proposal, with which the joiner removes an old version
1904 // of themselves. If a Remove proposal is present, then the LeafNode in the
1905 // path field of the external commit MUST meet the same criteria as would the
1906 // LeafNode in an Update for the removed leaf (see Section 12.1.2). In
1907 // particular, the credential in the LeafNode MUST present a set of
1908 // identifiers that is acceptable to the application for the removed
1909 // participant.
1910 // TODO(RLB) Verify that Remove is properly formed
1911 auto remove_count = stdxcxx . . $ mlspp/stdx/::count_ifcxx . . $ mlspp/stdx/count_if(91f28ad055782622).(proposals, [](const auto& cached) {
1912 return cached.proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove.;
1913 });
1914 auto no_dup_remove = (remove_count <= 1);
1915
1916 // Zero or more PreSharedKey proposals.
1917 // No other proposals.
1918 auto no_disallowed = stdxcxx . . $ mlspp/stdx/::all_ofcxx . . $ mlspp/stdx/all_of(acb94948942028a1).(proposals, [&](const auto& cached) {
1919 switch (cached.proposal.proposal_type()) {
1920 case ProposalTypecxx . . $ mlspp/ProposalType#::external_initcxx . . $ mlspp/ProposalType#external_init.:
1921 case ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove.:
1922 return true;
1923
1924 case ProposalTypecxx . . $ mlspp/ProposalType#::pskcxx . . $ mlspp/ProposalType#psk.:
1925 return validcxx . . $ mlspp/State#valid(16425a0d68d68158).(var::getcxx . . $ std/get(5aabc72a970aa7ce).<PreSharedKeycxx . . $ mlspp/PreSharedKey#>(cached.proposal.content));
1926
1927 default:
1928 return false;
1929 }
1930 });
1931
1932 return one_ext_init && no_dup_remove && no_disallowed;
1933 }
1934
1935 Statecxx . . $ mlspp/State#::CommitParamscxx . . $ mlspp/State#CommitParams#
1936 Statecxx . . $ mlspp/State#::infer_commit_typecxx . . $ mlspp/State#infer_commit_type(1740ce9eaeaed3ae).(
1937 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#>& sender,
1938 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals,
1939 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<CommitParamscxx . . $ mlspp/State#CommitParams#>& expected_params) const
1940 {
1941 // If an expected type was provided, validate against it
1942 if (expected_params) {
1943 const auto& expected = opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(expected_params);
1944
1945 auto specifically = overloaded{
1946 [&](const NormalCommitParamscxx . . $ mlspp/State#NormalCommitParams#& /* unused */) {
1947 return sender && valid_normalcxx . . $ mlspp/State#valid_normal(a3e4f4503fe1bf58).(proposals, opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(sender));
1948 },
1949 [&](const ExternalCommitParamscxx . . $ mlspp/State#ExternalCommitParams#& /* unused */) {
1950 return !sender && valid_externalcxx . . $ mlspp/State#valid_external(2e14fbd53494efe4).(proposals);
1951 },
1952 [&](const RestartCommitParamscxx . . $ mlspp/State#RestartCommitParams#& params) {
1953 return sender && valid_restartcxx . . $ mlspp/State#valid_restart(459c8a53464c5055).(proposals, params.allowed_usagecxx . . $ mlspp/State#RestartCommitParams#allowed_usage.);
1954 },
1955 [&](const ReInitCommitParamscxx . . $ mlspp/State#ReInitCommitParams#& /* unused */) {
1956 return sender && valid_reinitcxx . . $ mlspp/State#valid_reinit(10e28906c0b85113).(proposals);
1957 },
1958 };
1959
1960 if (!var::visitcxx . . $ std/visit(9828ab07ec69b3d0).(specifically, expected)) {
1961 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid proposal list");
1962 }
1963
1964 return expectedcxx . . $ std/variant#variant(4258f37888306be3).;
1965 }
1966
1967 // Otherwise, check to see if this is a valid external or normal commit
1968 if (!sender && valid_externalcxx . . $ mlspp/State#valid_external(2e14fbd53494efe4).(proposals)) {
1969 return ExternalCommitParamscxx . . $ std/variant#variant(5ba8255a4607184).{};
1970 }
1971
1972 if (sender && valid_normalcxx . . $ mlspp/State#valid_normal(a3e4f4503fe1bf58).(proposals, opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(sender))) {
1973 return NormalCommitParamscxx . . $ std/variant#variant(5ba8255a4607184).{};
1974 }
1975
1976 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid proposal list");
1977 }
1978
1979 bool
1980 Statecxx . . $ mlspp/State#::path_requiredcxx . . $ mlspp/State#path_required(10e28906c0b85113).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CachedProposalcxx . . $ mlspp/State#CachedProposal#>& proposals)
1981 {
1982 static const auto path_required_types = stdcxx . . $ std/set#set(6a59bae0ff1db065).::setcxx . . $ std/set#<Proposalcxx . . $ mlspp/Proposal#::Typecxx . . $ mlspp/Proposal#Type#>{
1983 ProposalTypecxx . . $ mlspp/ProposalType#::updatecxx . . $ mlspp/ProposalType#update.,
1984 ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove.,
1985 ProposalTypecxx . . $ mlspp/ProposalType#::external_initcxx . . $ mlspp/ProposalType#external_init.,
1986 ProposalTypecxx . . $ mlspp/ProposalType#::group_context_extensionscxx . . $ mlspp/ProposalType#group_context_extensions.,
1987 };
1988
1989 if (proposals.emptycxx . . $ std/vector#empty(3482b152b9333168).()) {
1990 return true;
1991 }
1992
1993 return stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(proposals, [](const auto& cp) {
1994 return path_required_types.countcxx . . $ std/set#count(a9c5b6ffd713dfa6).(cp.proposal.proposal_type()) !=cxx . . $ mlspp/`operator!=`(bd3c88d6bafb6558). 0;
1995 });
1996 }
1997
1998 ///
1999 /// Inner logic and convenience functions
2000 ///
2001
2002 bool
2003 operatorcxx . . $ mlspp/`operator==`(f7ea92d64b4f5a4f).==(const Statecxx . . $ mlspp/State#& lhs, const Statecxx . . $ mlspp/State#& rhs)
2004 {
2005 auto suite = (lhs._suitecxx . . $ mlspp/State#_suite. ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). rhs._suitecxx . . $ mlspp/State#_suite.);
2006 auto group_id = (lhs._group_idcxx . . $ mlspp/State#_group_id. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs._group_idcxx . . $ mlspp/State#_group_id.);
2007 auto epoch = (lhs._epochcxx . . $ mlspp/State#_epoch. == rhs._epochcxx . . $ mlspp/State#_epoch.);
2008 auto tree = (lhs._treecxx . . $ mlspp/State#_tree. ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). rhs._treecxx . . $ mlspp/State#_tree.);
2009 auto transcript_hash = (lhs._transcript_hashcxx . . $ mlspp/State#_transcript_hash. ==cxx . . $ mlspp/`operator==`(476a4c82fd602b31). rhs._transcript_hashcxx . . $ mlspp/State#_transcript_hash.);
2010 auto key_schedule = (lhs._key_schedulecxx . . $ mlspp/State#_key_schedule. ==cxx . . $ mlspp/`operator==`(9649cf35f662b0fb). rhs._key_schedulecxx . . $ mlspp/State#_key_schedule.);
2011 auto extensions = (lhs._extensionscxx . . $ mlspp/State#_extensions. ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). rhs._extensionscxx . . $ mlspp/State#_extensions.);
2012
2013 return suite && group_id && epoch && tree && transcript_hash &&
2014 key_schedule && extensions;
2015 }
2016
2017 bool
2018 operatorcxx . . $ mlspp/`operator!=`(f7ea92d64b4f5a4f).!=(const Statecxx . . $ mlspp/State#& lhs, const Statecxx . . $ mlspp/State#& rhs)
2019 {
2020 return !(lhs ==cxx . . $ mlspp/`operator==`(f7ea92d64b4f5a4f). rhs);
2021 }
2022
2023 void
2024 Statecxx . . $ mlspp/State#::update_epoch_secretscxx . . $ mlspp/State#update_epoch_secrets(34e1f8f66a1cf646).(const bytescxx . . $ mlspp/bytes_ns/bytes#& commit_secret,
2025 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>& psks,
2026 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>& force_init_secret)
2027 {
2028 auto ctx = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(GroupContextcxx . . $ mlspp/GroupContext#GroupContext(59c8082fdf1cbc0e).{
2029 _suitecxx . . $ mlspp/State#_suite.,
2030 _group_idcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).,
2031 _epochcxx . . $ mlspp/State#_epoch.,
2032 _treecxx . . $ mlspp/State#_tree..root_hashcxx . . $ mlspp/TreeKEMPublicKey#root_hash(d7392ba79aa35767).(),
2033 _transcript_hashcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.,
2034 _extensionscxx . . $ mlspp/State#_extensions.,
2035 });
2036 _key_schedulecxx . . $ mlspp/State#_key_schedule. =cxx . . $ mlspp/KeyScheduleEpoch#`operator=`(8ef62e844b63fcc6).
2037 _key_schedulecxx . . $ mlspp/State#_key_schedule..nextcxx . . $ mlspp/KeyScheduleEpoch#next(5d822d0102bcfbee).(commit_secret, psks, force_init_secret, ctxcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
2038 _keyscxx . . $ mlspp/State#_keys. =cxx . . $ mlspp/GroupKeySource#`operator=`(9bdcbd6beff8640f). _key_schedulecxx . . $ mlspp/State#_key_schedule..encryption_keyscxx . . $ mlspp/KeyScheduleEpoch#encryption_keys(578ffb7a4920202).(_treecxx . . $ mlspp/State#_tree..sizecxx . . $ mlspp/TreeKEMPublicKey#size.);
2039 }
2040
2041 ///
2042 /// Message encryption and decryption
2043 ///
2044 bool
2045 Statecxx . . $ mlspp/State#::verify_internalcxx . . $ mlspp/State#verify_internal(891fdc29165d76d0).(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) const
2046 {
2047 const auto& sender =
2048 var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<MemberSendercxx . . $ mlspp/MemberSender#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..sendercxx . . $ mlspp/GroupContent#sender..sendercxx . . $ mlspp/Sender#sender.).sendercxx . . $ mlspp/MemberSender#sender.;
2049 auto maybe_leaf = _treecxx . . $ mlspp/State#_tree..leaf_nodecxx . . $ mlspp/TreeKEMPublicKey#leaf_node(e2d641b4ea45e2f).(sender);
2050 if (!maybe_leaf) {
2051 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Signature from blank node");
2052 }
2053
2054 const auto& pub = opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_leaf).signature_keycxx . . $ mlspp/LeafNode#signature_key.;
2055 return content_auth.verifycxx . . $ mlspp/AuthenticatedContent#verify(3653f40ee3caab0a).(_suitecxx . . $ mlspp/State#_suite., pub, group_contextcxx . . $ std/optional#optional(e3f0d6382bd52f24).());
2056 }
2057
2058 bool
2059 Statecxx . . $ mlspp/State#::verify_externalcxx . . $ mlspp/State#verify_external(891fdc29165d76d0).(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) const
2060 {
2061 const auto& ext_sender =
2062 var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<ExternalSenderIndexcxx . . $ mlspp/ExternalSenderIndex#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..sendercxx . . $ mlspp/GroupContent#sender..sendercxx . . $ mlspp/Sender#sender.);
2063 const auto senders_ext = _extensionscxx . . $ mlspp/State#_extensions..findcxx . . $ mlspp/ExtensionList#find(af95876f91a4b24c).<ExternalSendersExtensioncxx . . $ mlspp/ExternalSendersExtension#>();
2064 const auto& senders = opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(senders_ext).senderscxx . . $ mlspp/ExternalSendersExtension#senders.;
2065 const auto& pub = senders.atcxx . . $ std/vector#at(b61e45a10b63f40a).(ext_sender.sender_indexcxx . . $ mlspp/ExternalSenderIndex#sender_index.).signature_keycxx . . $ mlspp/ExternalSender#signature_key.;
2066 return content_auth.verifycxx . . $ mlspp/AuthenticatedContent#verify(3653f40ee3caab0a).(_suitecxx . . $ mlspp/State#_suite., pub, group_contextcxx . . $ std/optional#optional(e3f0d6382bd52f24).());
2067 }
2068
2069 bool
2070 Statecxx . . $ mlspp/State#::verify_new_member_proposalcxx . . $ mlspp/State#verify_new_member_proposal(891fdc29165d76d0).(
2071 const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) const
2072 {
2073 const auto& proposal = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Proposalcxx . . $ mlspp/Proposal#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..contentcxx . . $ mlspp/GroupContent#content.);
2074 const auto& add = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Addcxx . . $ mlspp/Add#>(proposal.contentcxx . . $ mlspp/Proposal#content.);
2075 const auto& pub = add.key_packagecxx . . $ mlspp/Add#key_package..leaf_nodecxx . . $ mlspp/KeyPackage#leaf_node..signature_keycxx . . $ mlspp/LeafNode#signature_key.;
2076 return content_auth.verifycxx . . $ mlspp/AuthenticatedContent#verify(3653f40ee3caab0a).(_suitecxx . . $ mlspp/State#_suite., pub, group_contextcxx . . $ std/optional#optional(e3f0d6382bd52f24).());
2077 }
2078
2079 bool
2080 Statecxx . . $ mlspp/State#::verify_new_member_commitcxx . . $ mlspp/State#verify_new_member_commit(891fdc29165d76d0).(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) const
2081 {
2082 const auto& commit = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Commitcxx . . $ mlspp/Commit#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..contentcxx . . $ mlspp/GroupContent#content.);
2083 const auto& path = opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(commit.pathcxx . . $ mlspp/Commit#path.);
2084 const auto& pub = path.leaf_nodecxx . . $ mlspp/UpdatePath#leaf_node..signature_keycxx . . $ mlspp/LeafNode#signature_key.;
2085 return content_auth.verifycxx . . $ mlspp/AuthenticatedContent#verify(3653f40ee3caab0a).(_suitecxx . . $ mlspp/State#_suite., pub, group_contextcxx . . $ std/optional#optional(e3f0d6382bd52f24).());
2086 }
2087
2088 bool
2089 Statecxx . . $ mlspp/State#::verifycxx . . $ mlspp/State#verify(891fdc29165d76d0).(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) const
2090 {
2091 switch (content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).()) {
2092 case SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.:
2093 return verify_internalcxx . . $ mlspp/State#verify_internal(891fdc29165d76d0).(content_auth);
2094
2095 case SenderTypecxx . . $ mlspp/SenderType#::externalcxx . . $ mlspp/SenderType#external.:
2096 return verify_externalcxx . . $ mlspp/State#verify_external(891fdc29165d76d0).(content_auth);
2097
2098 case SenderTypecxx . . $ mlspp/SenderType#::new_member_proposalcxx . . $ mlspp/SenderType#new_member_proposal.:
2099 return verify_new_member_proposalcxx . . $ mlspp/State#verify_new_member_proposal(891fdc29165d76d0).(content_auth);
2100
2101 case SenderTypecxx . . $ mlspp/SenderType#::new_member_commitcxx . . $ mlspp/SenderType#new_member_commit.:
2102 return verify_new_member_commitcxx . . $ mlspp/State#verify_new_member_commit(891fdc29165d76d0).(content_auth);
2103
2104 default:
2105 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Invalid sender type");
2106 }
2107 }
2108
2109 void
2110 Statecxx . . $ mlspp/State#::add_resumption_pskcxx . . $ mlspp/State#add_resumption_psk(1af26b66f871bc85).(const bytescxx . . $ mlspp/bytes_ns/bytes#& group_id, epoch_tcxx . . $ mlspp/epoch_t# epoch, bytescxx . . $ mlspp/bytes_ns/bytes# secret)
2111 {
2112 _resumption_pskscxx . . $ mlspp/State#_resumption_psks..insert_or_assigncxx . . $ std/map#insert_or_assign(e23b589f5fc14fc4).({cxx . . $ std/tuple#tuple(533e79eb6234819d). group_id, epoch }, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(secret));
2113 }
2114
2115 void
2116 Statecxx . . $ mlspp/State#::remove_resumption_pskcxx . . $ mlspp/State#remove_resumption_psk(3383564e9931e9d2).(const bytescxx . . $ mlspp/bytes_ns/bytes#& group_id, epoch_tcxx . . $ mlspp/epoch_t# epoch)
2117 {
2118 _resumption_pskscxx . . $ mlspp/State#_resumption_psks..erasecxx . . $ std/map#erase(a7de169f3ef4bfb3).({cxx . . $ std/tuple#tuple(533e79eb6234819d). group_id, epoch });
2119 }
2120
2121 void
2122 Statecxx . . $ mlspp/State#::add_external_pskcxx . . $ mlspp/State#add_external_psk(84c68846ffcb487b).(const bytescxx . . $ mlspp/bytes_ns/bytes#& id, const bytescxx . . $ mlspp/bytes_ns/bytes#& secret)
2123 {
2124 _external_pskscxx . . $ mlspp/State#_external_psks..insert_or_assigncxx . . $ std/map#insert_or_assign(a356f559b7c7a273).(id, secret);
2125 }
2126
2127 void
2128 Statecxx . . $ mlspp/State#::remove_external_pskcxx . . $ mlspp/State#remove_external_psk(68ca607eebb5be3e).(const bytescxx . . $ mlspp/bytes_ns/bytes#& id)
2129 {
2130 _external_pskscxx . . $ mlspp/State#_external_psks..erasecxx . . $ std/map#erase(a7de169f3ef4bfb3).(id);
2131 }
2132
2133 bytescxx . . $ mlspp/bytes_ns/bytes#
2134 Statecxx . . $ mlspp/State#::do_exportcxx . . $ mlspp/State#do_export(7012e37337977242).(const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
2135 const bytescxx . . $ mlspp/bytes_ns/bytes#& context,
2136 size_t size) const
2137 {
2138 return _key_schedulecxx . . $ mlspp/State#_key_schedule..do_exportcxx . . $ mlspp/KeyScheduleEpoch#do_export(7012e37337977242).(label, context, size);
2139 }
2140
2141 GroupInfocxx . . $ mlspp/GroupInfo#
2142 Statecxx . . $ mlspp/State#::group_infocxx . . $ mlspp/State#group_info(c29763f177bca0e).(bool inline_tree) const
2143 {
2144 auto group_info = GroupInfocxx . . $ mlspp/GroupInfo#GroupInfo(6eefa60eacb8ffcb).{
2145 {cxx . . $ mlspp/GroupContext#GroupContext(59c8082fdf1cbc0e).
2146 _suitecxx . . $ mlspp/State#_suite.,
2147 _group_idcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).,
2148 _epochcxx . . $ mlspp/State#_epoch.,
2149 _treecxx . . $ mlspp/State#_tree..root_hashcxx . . $ mlspp/TreeKEMPublicKey#root_hash(d7392ba79aa35767).(),
2150 _transcript_hashcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.,
2151 _extensionscxx . . $ mlspp/State#_extensions.,
2152 },
2153 { /* No other extensions */ },
2154 _key_schedulecxx . . $ mlspp/State#_key_schedule..confirmation_tagcxx . . $ mlspp/KeyScheduleEpoch#confirmation_tag(c5e1b85e16e94921).(_transcript_hashcxx . . $ mlspp/State#_transcript_hash..confirmedcxx . . $ mlspp/TranscriptHash#confirmed.),
2155 };
2156
2157 group_info.extensionscxx . . $ mlspp/GroupInfo#extensions..addcxx . . $ mlspp/ExtensionList#add(77d9f17553126ecb).(
2158 ExternalPubExtensioncxx . . $ mlspp/ExternalPubExtension#{ _key_schedulecxx . . $ mlspp/State#_key_schedule..external_privcxx . . $ mlspp/KeyScheduleEpoch#external_priv..public_keycxx . . $ mlspp/HPKEPrivateKey#public_key. });
2159
2160 if (inline_tree) {
2161 group_info.extensionscxx . . $ mlspp/GroupInfo#extensions..addcxx . . $ mlspp/ExtensionList#add(77d9f17553126ecb).(RatchetTreeExtensioncxx . . $ mlspp/RatchetTreeExtension#{ _treecxx . . $ mlspp/State#_tree. });
2162 }
2163
2164 group_info.signcxx . . $ mlspp/GroupInfo#sign(f56bede4ff7e1bef).(_treecxx . . $ mlspp/State#_tree., _indexcxx . . $ mlspp/State#_index., _identity_privcxx . . $ mlspp/State#_identity_priv.);
2165 return group_info;
2166 }
2167
2168 stdcxx . . $ std/::vectorcxx . . $ std/vector#<LeafNodecxx . . $ mlspp/LeafNode#>
2169 Statecxx . . $ mlspp/State#::rostercxx . . $ mlspp/State#roster(e6c5b5c0a1adb3b2).() const
2170 {
2171 auto leaves = stdcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).::vectorcxx . . $ std/vector#<LeafNodecxx . . $ mlspp/LeafNode#>{};
2172 leaves.reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(_treecxx . . $ mlspp/State#_tree..sizecxx . . $ mlspp/TreeKEMPublicKey#size..valcxx . . $ mlspp/UInt32#val.);
2173
2174 _treecxx . . $ mlspp/State#_tree..all_leavescxx . . $ mlspp/TreeKEMPublicKey#all_leaves(8877ebe272b9620d).([&](auto /* i */, auto leaf) {
2175 leaves.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(leaf);
2176 return true;
2177 });
2178
2179 return leavescxx . . $ std/vector#vector(6f559d22b039ccdb).;
2180 }
2181
2182 bytescxx . . $ mlspp/bytes_ns/bytes#
2183 Statecxx . . $ mlspp/State#::epoch_authenticatorcxx . . $ mlspp/State#epoch_authenticator(d7392ba79aa35767).() const
2184 {
2185 return _key_schedulecxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..epoch_authenticatorcxx . . $ mlspp/KeyScheduleEpoch#epoch_authenticator.;
2186 }
2187
2188 LeafIndexcxx . . $ mlspp/LeafIndex#
2189 Statecxx . . $ mlspp/State#::leaf_for_roster_entrycxx . . $ mlspp/State#leaf_for_roster_entry(fb567b77ce7f3086).(RosterIndexcxx . . $ mlspp/RosterIndex# index) const
2190 {
2191 auto visited = RosterIndexcxx . . $ mlspp/RosterIndex#{ 0 };
2192 auto found = stdcxx . . $ std/optional#optional(ced63f7c635d850d).::optionalcxx . . $ std/optional#<LeafIndexcxx . . $ mlspp/LeafIndex#>{};
2193 _treecxx . . $ mlspp/State#_tree..all_leavescxx . . $ mlspp/TreeKEMPublicKey#all_leaves(8877ebe272b9620d).([&](auto i, const auto& /* leaf_node */) {
2194 if (visited ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). index) {
2195 found = i;
2196 return false;
2197 }
2198
2199 visited.valcxx . . $ mlspp/UInt32#val. += 1;
2200 return true;
2201 });
2202
2203 return opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(found);
2204 }
2205
2206 Statecxx . . $ mlspp/State#
2207 Statecxx . . $ mlspp/State#::successorcxx . . $ mlspp/State#successor(c5801eb416f519eb).() const
2208 {
2209 // Copy everything, then clear things that shouldn't be copied
2210 auto next = *this;
2211 next._pending_proposalscxx . . $ mlspp/State#_pending_proposals..clearcxx . . $ std/__cxx11/list#clear(ced63f7c635d850d).();
2212
2213 // Copy forward a resumption PSK
2214 next.add_resumption_pskcxx . . $ mlspp/State#add_resumption_psk(1af26b66f871bc85).(_group_idcxx . . $ mlspp/State#_group_id., _epochcxx . . $ mlspp/State#_epoch., _key_schedulecxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..resumption_pskcxx . . $ mlspp/KeyScheduleEpoch#resumption_psk.);
2215
2216 return next;
2217 }
2218
2219 } // namespace mlspp