Debian Codegraph @

mlspp/src/messages.cpp

raw symbols SCIP
1 #cxx . . $ `<file>/mlspp/src/messages.cpp`/include <mls/key_schedule.h>cxx . . $ `<file>/mlspp/include/mls/key_schedule.h`/
2 #include <mls/messages.h>cxx . . $ `<file>/mlspp/include/mls/messages.h`/
3 #include <mls/state.h>cxx . . $ `<file>/mlspp/include/mls/state.h`/
4 #include <mls/treekem.h>cxx . . $ `<file>/mlspp/include/mls/treekem.h`/
5
6 #include "grease.h"cxx . . $ `<file>/mlspp/src/grease.h`/
7
8 namespace mlsppcxx . . $ mlspp/ {
9
10 // Extensions
11
12 const Extensioncxx . . $ mlspp/Extension#::Typecxx . . $ mlspp/Extension#Type# ExternalPubExtensioncxx . . $ mlspp/ExternalPubExtension#::typecxx . . $ mlspp/ExternalPubExtension#type. = ExtensionTypecxx . . $ mlspp/ExtensionType#::external_pubcxx . . $ mlspp/ExtensionType#external_pub.;
13 const Extensioncxx . . $ mlspp/Extension#::Typecxx . . $ mlspp/Extension#Type# RatchetTreeExtensioncxx . . $ mlspp/RatchetTreeExtension#::typecxx . . $ mlspp/RatchetTreeExtension#type. = ExtensionTypecxx . . $ mlspp/ExtensionType#::ratchet_treecxx . . $ mlspp/ExtensionType#ratchet_tree.;
14 const Extensioncxx . . $ mlspp/Extension#::Typecxx . . $ mlspp/Extension#Type# ExternalSendersExtensioncxx . . $ mlspp/ExternalSendersExtension#::typecxx . . $ mlspp/ExternalSendersExtension#type. =
15 ExtensionTypecxx . . $ mlspp/ExtensionType#::external_senderscxx . . $ mlspp/ExtensionType#external_senders.;
16 const Extensioncxx . . $ mlspp/Extension#::Typecxx . . $ mlspp/Extension#Type# SFrameParameterscxx . . $ mlspp/SFrameParameters#::typecxx . . $ mlspp/SFrameParameters#type. = ExtensionTypecxx . . $ mlspp/ExtensionType#::sframe_parameterscxx . . $ mlspp/ExtensionType#sframe_parameters.;
17 const Extensioncxx . . $ mlspp/Extension#::Typecxx . . $ mlspp/Extension#Type# SFrameCapabilitiescxx . . $ mlspp/SFrameCapabilities#::typecxx . . $ mlspp/SFrameCapabilities#type. =
18 ExtensionTypecxx . . $ mlspp/ExtensionType#::sframe_parameterscxx . . $ mlspp/ExtensionType#sframe_parameters.;
19
20 bool
21 SFrameCapabilitiescxx . . $ mlspp/SFrameCapabilities#::compatiblecxx . . $ mlspp/SFrameCapabilities#compatible(eecd3f1a07cc47fb).(const SFrameParameterscxx . . $ mlspp/SFrameParameters#& params) const
22 {
23 return stdxcxx . . $ mlspp/stdx/::containscxx . . $ mlspp/stdx/contains(acb94948942028a1).(cipher_suitescxx . . $ mlspp/SFrameCapabilities#cipher_suites., params.cipher_suitecxx . . $ mlspp/SFrameParameters#cipher_suite.);
24 }
25
26 // GroupContext
27
28 GroupContextcxx . . $ mlspp/GroupContext#::GroupContextcxx . . $ mlspp/GroupContext#GroupContext(59c8082fdf1cbc0e).(CipherSuitecxx . . $ mlspp/CipherSuite# cipher_suite_in,
29 bytescxx . . $ mlspp/bytes_ns/bytes# group_id_in,
30 epoch_tcxx . . $ mlspp/epoch_t# epoch_in,
31 bytescxx . . $ mlspp/bytes_ns/bytes# tree_hash_in,
32 bytescxx . . $ mlspp/bytes_ns/bytes# confirmed_transcript_hash_in,
33 ExtensionListcxx . . $ mlspp/ExtensionList# extensions_in)
34 : cipher_suitecxx . . $ mlspp/GroupContext#cipher_suite.(cipher_suite_in)
35 , group_idcxx . . $ mlspp/GroupContext#group_id.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(group_id_in))
36 , epochcxx . . $ mlspp/GroupContext#epoch.(epoch_in)
37 , tree_hashcxx . . $ mlspp/GroupContext#tree_hash.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(tree_hash_in))
38 , confirmed_transcript_hashcxx . . $ mlspp/GroupContext#confirmed_transcript_hash.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(confirmed_transcript_hash_in))
39 , extensionscxx . . $ mlspp/GroupContext#extensions.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(extensions_in))
40 {
41 }
42
43 // GroupInfo
44
45 GroupInfocxx . . $ mlspp/GroupInfo#::GroupInfocxx . . $ mlspp/GroupInfo#GroupInfo(6eefa60eacb8ffcb).(GroupContextcxx . . $ mlspp/GroupContext# group_context_in,
46 ExtensionListcxx . . $ mlspp/ExtensionList# extensions_in,
47 bytescxx . . $ mlspp/bytes_ns/bytes# confirmation_tag_in)
48 : group_contextcxx . . $ mlspp/GroupInfo#group_context.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(group_context_in))
49 , extensionscxx . . $ mlspp/GroupInfo#extensions.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(extensions_in))
50 , confirmation_tagcxx . . $ mlspp/GroupInfo#confirmation_tag.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(confirmation_tag_in))
51 , signercxx . . $ mlspp/GroupInfo#signer.(0)
52 {
53 greasecxx . . $ mlspp/grease(848010cd98b83bb3).(extensionscxx . . $ mlspp/GroupInfo#extensions.);
54 }
55
56 struct GroupInfoTBScxx . . $ mlspp/GroupInfoTBS#
57 {
58 GroupContextcxx . . $ mlspp/GroupContext# group_contextcxx . . $ mlspp/GroupInfoTBS#group_context.;
59 ExtensionListcxx . . $ mlspp/ExtensionList# extensionscxx . . $ mlspp/GroupInfoTBS#extensions.;
60 bytescxx . . $ mlspp/bytes_ns/bytes# confirmation_tagcxx . . $ mlspp/GroupInfoTBS#confirmation_tag.;
61 LeafIndexcxx . . $ mlspp/LeafIndex# signercxx . . $ mlspp/GroupInfoTBS#signer.;
62
63 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(group_context, extensions, confirmation_tag, signer)
64 };
65
66 bytescxx . . $ mlspp/bytes_ns/bytes#
67 GroupInfocxx . . $ mlspp/GroupInfo#::to_be_signedcxx . . $ mlspp/GroupInfo#to_be_signed(d7392ba79aa35767).() const
68 {
69 return tlscxx . . $ mlspp/bytes_ns/bytes#bytes(dd8c33c7e39dbe02).::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(
70 GroupInfoTBScxx . . $ mlspp/GroupInfoTBS#{ group_contextcxx . . $ mlspp/GroupInfo#group_context., extensionscxx . . $ mlspp/GroupInfo#extensions., confirmation_tagcxx . . $ mlspp/GroupInfo#confirmation_tag., signercxx . . $ mlspp/GroupInfo#signer. });
71 }
72
73 void
74 GroupInfocxx . . $ mlspp/GroupInfo#::signcxx . . $ mlspp/GroupInfo#sign(f56bede4ff7e1bef).(const TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#& tree,
75 LeafIndexcxx . . $ mlspp/LeafIndex# signer_index,
76 const SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#& priv)
77 {
78 auto maybe_leaf = tree.leaf_nodecxx . . $ mlspp/TreeKEMPublicKey#leaf_node(e2d641b4ea45e2f).(signer_index);
79 if (!maybe_leaf) {
80 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Cannot sign from a blank leaf");
81 }
82
83 if (priv.public_keycxx . . $ mlspp/SignaturePrivateKey#public_key. !=cxx . . $ mlspp/`operator!=`(5401d31d8ac0aee4). opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_leaf).signature_keycxx . . $ mlspp/LeafNode#signature_key.) {
84 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Bad key for index");
85 }
86
87 signercxx . . $ mlspp/GroupInfo#signer. =cxx . . $ mlspp/LeafIndex#`operator=`(52b85dbf6b8ce299). signer_index;
88 signaturecxx . . $ mlspp/GroupInfo#signature. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). priv.signcxx . . $ mlspp/SignaturePrivateKey#sign(9a20592b3b42a8ed).(tree.suitecxx . . $ mlspp/TreeKEMPublicKey#suite., sign_labelcxx . . $ mlspp/sign_label/::group_infocxx . . $ mlspp/sign_label/group_info., to_be_signedcxx . . $ mlspp/GroupInfo#to_be_signed(d7392ba79aa35767).());
89 }
90
91 bool
92 GroupInfocxx . . $ mlspp/GroupInfo#::verifycxx . . $ mlspp/GroupInfo#verify(eaed869e1938a2dc).(const TreeKEMPublicKeycxx . . $ mlspp/TreeKEMPublicKey#& tree) const
93 {
94 auto maybe_leaf = tree.leaf_nodecxx . . $ mlspp/TreeKEMPublicKey#leaf_node(e2d641b4ea45e2f).(signercxx . . $ mlspp/GroupInfo#signer.);
95 if (!maybe_leaf) {
96 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Signer not found");
97 }
98
99 const auto& leaf = opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(maybe_leaf);
100 return verifycxx . . $ mlspp/GroupInfo#verify(9a76ab9c2cdc40ef).(leaf.signature_keycxx . . $ mlspp/LeafNode#signature_key.);
101 }
102
103 void
104 GroupInfocxx . . $ mlspp/GroupInfo#::signcxx . . $ mlspp/GroupInfo#sign(a62c296173377137).(LeafIndexcxx . . $ mlspp/LeafIndex# signer_index, const SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#& priv)
105 {
106 signercxx . . $ mlspp/GroupInfo#signer. =cxx . . $ mlspp/LeafIndex#`operator=`(52b85dbf6b8ce299). signer_index;
107 signaturecxx . . $ mlspp/GroupInfo#signature. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). priv.signcxx . . $ mlspp/SignaturePrivateKey#sign(9a20592b3b42a8ed).(
108 group_contextcxx . . $ mlspp/GroupInfo#group_context..cipher_suitecxx . . $ mlspp/GroupContext#cipher_suite., sign_labelcxx . . $ mlspp/sign_label/::group_infocxx . . $ mlspp/sign_label/group_info., to_be_signedcxx . . $ mlspp/GroupInfo#to_be_signed(d7392ba79aa35767).());
109 }
110
111 bool
112 GroupInfocxx . . $ mlspp/GroupInfo#::verifycxx . . $ mlspp/GroupInfo#verify(9a76ab9c2cdc40ef).(const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& pub) const
113 {
114 return pub.verifycxx . . $ mlspp/SignaturePublicKey#verify(e28f084f4f4fb6fe).(group_contextcxx . . $ mlspp/GroupInfo#group_context..cipher_suitecxx . . $ mlspp/GroupContext#cipher_suite.,
115 sign_labelcxx . . $ mlspp/sign_label/::group_infocxx . . $ mlspp/sign_label/group_info.,
116 to_be_signedcxx . . $ mlspp/GroupInfo#to_be_signed(d7392ba79aa35767).(),
117 signaturecxx . . $ mlspp/GroupInfo#signature.);
118 }
119
120 // Welcome
121
122 Welcomecxx . . $ mlspp/Welcome#::Welcomecxx . . $ mlspp/Welcome#Welcome(49f6e7a06ebc5aa8).()
123 : cipher_suitecxx . . $ mlspp/Welcome#cipher_suite.(CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#::unknowncxx . . $ mlspp/CipherSuite#ID#unknown.)
124 {
125 }
126
127 Welcomecxx . . $ mlspp/Welcome#::Welcomecxx . . $ mlspp/Welcome#Welcome(eaff8aba63a9c6d).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
128 const bytescxx . . $ mlspp/bytes_ns/bytes#& joiner_secret,
129 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>& psks,
130 const GroupInfocxx . . $ mlspp/GroupInfo#& group_info)
131 : cipher_suitecxx . . $ mlspp/Welcome#cipher_suite.(suite)
132 , _joiner_secretcxx . . $ mlspp/Welcome#_joiner_secret.(joiner_secret)
133 {
134 // Cache the list of PSK IDs
135 for (const auto& psk : psks) {
136 _pskscxx . . $ mlspp/Welcome#_psks..pskscxx . . $ mlspp/PreSharedKeys#psks..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(psk.idcxx . . $ mlspp/PSKWithSecret#id.);
137 }
138
139 // Pre-encrypt the GroupInfo
140 auto [key, nonce] = group_info_key_noncecxx . . $ mlspp/Welcome#group_info_key_nonce(6ac639ad95aa0e0f).(suite, joiner_secret, psks);
141 auto group_info_data = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(group_info);
142 encrypted_group_infocxx . . $ mlspp/Welcome#encrypted_group_info. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed).
143 cipher_suitecxx . . $ mlspp/Welcome#cipher_suite..hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..sealcxx . . $ mlspp/hpke/AEAD#seal(a2160eb270d8417e).(key, nonce, {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, group_info_datacxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
144 }
145
146 stdcxx . . $ std/::optionalcxx . . $ std/optional#<int>
147 Welcomecxx . . $ mlspp/Welcome#::findcxx . . $ mlspp/Welcome#find(bb6a8adc8a3815ad).(const KeyPackagecxx . . $ mlspp/KeyPackage#& kp) const
148 {
149 auto ref = kp.refcxx . . $ mlspp/KeyPackage#ref(d7392ba79aa35767).();
150 for (size_t i = 0; i < secretscxx . . $ mlspp/Welcome#secrets..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) {
151 if (ref ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). secretscxx . . $ mlspp/Welcome#secrets.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i].new_membercxx . . $ mlspp/EncryptedGroupSecrets#new_member.) {
152 return static_castcxx . . $ std/optional#optional(e3f0d6382bd52f24).<int>(i);
153 }
154 }
155 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
156 }
157
158 void
159 Welcomecxx . . $ mlspp/Welcome#::encryptcxx . . $ mlspp/Welcome#encrypt(36b3267e5243a5b9).(const KeyPackagecxx . . $ mlspp/KeyPackage#& kp, const stdcxx . . $ std/::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>& path_secret)
160 {
161 auto gs = GroupSecretscxx . . $ mlspp/GroupSecrets#{ _joiner_secretcxx . . $ mlspp/Welcome#_joiner_secret., stdcxx . . $ std/::nulloptcxx . . $ std/nullopt., _pskscxx . . $ mlspp/Welcome#_psks. };
162 if (path_secret) {
163 gs.path_secretcxx . . $ mlspp/GroupSecrets#path_secret. =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). GroupSecretscxx . . $ mlspp/GroupSecrets#::PathSecretcxx . . $ mlspp/GroupSecrets#PathSecret#{ opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(path_secret) };
164 }
165
166 auto gs_data = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(gs);
167 auto enc_gs = kp.init_keycxx . . $ mlspp/KeyPackage#init_key..encryptcxx . . $ mlspp/HPKEPublicKey#encrypt(4062c3a081c08efa).(
168 kp.cipher_suitecxx . . $ mlspp/KeyPackage#cipher_suite., encrypt_labelcxx . . $ mlspp/encrypt_label/::welcomecxx . . $ mlspp/encrypt_label/welcome., encrypted_group_infocxx . . $ mlspp/Welcome#encrypted_group_info., gs_datacxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
169 secretscxx . . $ mlspp/Welcome#secrets..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).({ kp.refcxx . . $ mlspp/KeyPackage#ref(d7392ba79aa35767).(), enc_gs });
170 }
171
172 GroupSecretscxx . . $ mlspp/GroupSecrets#
173 Welcomecxx . . $ mlspp/Welcome#::decrypt_secretscxx . . $ mlspp/Welcome#decrypt_secrets(829c26bdce94c216).(int kp_index, const HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#& init_priv) const
174 {
175 auto secrets_data =
176 init_priv.decryptcxx . . $ mlspp/HPKEPrivateKey#decrypt(e80468221b998043).(cipher_suitecxx . . $ mlspp/Welcome#cipher_suite.,
177 encrypt_labelcxx . . $ mlspp/encrypt_label/::welcomecxx . . $ mlspp/encrypt_label/welcome.,
178 encrypted_group_infocxx . . $ mlspp/Welcome#encrypted_group_info.,
179 secretscxx . . $ mlspp/Welcome#secrets..atcxx . . $ std/vector#at(b61e45a10b63f40a).(kp_index).encrypted_group_secretscxx . . $ mlspp/EncryptedGroupSecrets#encrypted_group_secrets.);
180 return tlscxx . . $ mlspp/tls/::getcxx . . $ mlspp/tls/get(fdfeec44f419faae).<GroupSecretscxx . . $ mlspp/GroupSecrets#>(secrets_data);
181 }
182
183 GroupInfocxx . . $ mlspp/GroupInfo#
184 Welcomecxx . . $ mlspp/Welcome#::decryptcxx . . $ mlspp/Welcome#decrypt(81448b52776f14d3).(const bytescxx . . $ mlspp/bytes_ns/bytes#& joiner_secret,
185 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>& psks) const
186 {
187 auto [key, nonce] = group_info_key_noncecxx . . $ mlspp/Welcome#group_info_key_nonce(6ac639ad95aa0e0f).(cipher_suitecxx . . $ mlspp/Welcome#cipher_suite., joiner_secret, psks);
188 auto group_info_data =
189 cipher_suitecxx . . $ mlspp/Welcome#cipher_suite..hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..opencxx . . $ mlspp/hpke/AEAD#open(f7542dab5ac51900).(key, nonce, {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, encrypted_group_infocxx . . $ mlspp/Welcome#encrypted_group_info.);
190 if (!group_info_data) {
191 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Welcome decryption failed");
192 }
193
194 return tlscxx . . $ mlspp/tls/::getcxx . . $ mlspp/tls/get(fdfeec44f419faae).<GroupInfocxx . . $ mlspp/GroupInfo#>(opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(group_info_data));
195 }
196
197 KeyAndNoncecxx . . $ mlspp/KeyAndNonce#
198 Welcomecxx . . $ mlspp/Welcome#::group_info_key_noncecxx . . $ mlspp/Welcome#group_info_key_nonce(6ac639ad95aa0e0f).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
199 const bytescxx . . $ mlspp/bytes_ns/bytes#& joiner_secret,
200 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>& psks)
201 {
202 auto welcome_secret =
203 KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::welcome_secretcxx . . $ mlspp/KeyScheduleEpoch#welcome_secret(e5f3c7282c3439d1).(suite, joiner_secret, psks);
204
205 // XXX(RLB): These used to be done with ExpandWithLabel. Should we do that
206 // instead, for better domain separation? (In particular, including "mls10")
207 // That is what we do for the sender data key/nonce.
208 auto key =
209 suite.expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(welcome_secret, "key"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, suite.key_sizecxx . . $ mlspp/CipherSuite#key_size(fe4d2d262d4164a8).());
210 auto nonce =
211 suite.expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(welcome_secret, "nonce"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, suite.nonce_sizecxx . . $ mlspp/CipherSuite#nonce_size(fe4d2d262d4164a8).());
212 return { stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(key), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(nonce) };
213 }
214
215 // Commit
216 stdcxx . . $ std/::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>
217 Commitcxx . . $ mlspp/Commit#::valid_externalcxx . . $ mlspp/Commit#valid_external(82a679487d1deb04).() const
218 {
219 // External Commits MUST contain a path field (and is therefore a "full"
220 // Commit). The joiner is added at the leftmost free leaf node (just as if
221 // they were added with an Add proposal), and the path is calculated relative
222 // to that leaf node.
223 //
224 // The Commit MUST NOT include any proposals by reference, since an external
225 // joiner cannot determine the validity of proposals sent within the group
226 const auto all_by_value = stdxcxx . . $ mlspp/stdx/::all_ofcxx . . $ mlspp/stdx/all_of(acb94948942028a1).(proposalscxx . . $ mlspp/Commit#proposals., [](const auto& p) {
227 return var::holds_alternativecxx . . $ std/holds_alternative(4d382a1a2d74a3ce).<Proposalcxx . . $ mlspp/Proposal#>(p.content);
228 });
229 if (!pathcxx . . $ mlspp/Commit#path. || !all_by_value) {
230 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
231 }
232
233 const auto ext_init_ptr = stdxcxx . . $ mlspp/stdx/::find_ifcxx . . $ mlspp/stdx/find_if(91f28ad055782622).(proposalscxx . . $ mlspp/Commit#proposals., [](const auto& p) {
234 const auto proposal = var::getcxx . . $ std/get(5aabc72a970aa7ce).<Proposalcxx . . $ mlspp/Proposal#>(p.content);
235 return proposal.proposal_type() ==cxx . . $ mlspp/`operator==`(bd3c88d6bafb6558). ProposalTypecxx . . $ mlspp/ProposalType#::external_initcxx . . $ mlspp/ProposalType#external_init.;
236 });
237 if (ext_init_ptr ==cxx . . $ __gnu_cxx/`operator==`(3cd84a314b671a91). proposalscxx . . $ mlspp/Commit#proposals..endcxx . . $ std/vector#end(d1e1699016b9d7e6).()) {
238 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
239 }
240
241 const auto& ext_init_proposal = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<Proposalcxx . . $ mlspp/Proposal#>(ext_init_ptr->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).contentcxx . . $ mlspp/ProposalOrRef#content.);
242 const auto& ext_init = var::getcxx . . $ std/get(ca5bafa5a3bcea9d).<ExternalInitcxx . . $ mlspp/ExternalInit#>(ext_init_proposal.contentcxx . . $ mlspp/Proposal#content.);
243 return ext_initcxx . . $ std/optional#optional(e3f0d6382bd52f24)..kem_outputcxx . . $ mlspp/ExternalInit#kem_output.;
244 }
245
246 // PublicMessage
247 Proposalcxx . . $ mlspp/Proposal#::Typecxx . . $ mlspp/Proposal#Type#
248 Proposalcxx . . $ mlspp/Proposal#::proposal_typecxx . . $ mlspp/Proposal#proposal_type(72085aa11f4b6e09).() const
249 {
250 return tlscxx . . $ mlspp/tls/::variantcxx . . $ mlspp/tls/variant#<ProposalType>::typecxx . . $ mlspp/tls/variant#type(3f716087ed284cc1).(contentcxx . . $ mlspp/Proposal#content.).valcxx . . $ mlspp/ProposalType#val.;
251 }
252
253 SenderTypecxx . . $ mlspp/SenderType#
254 Sendercxx . . $ mlspp/Sender#::sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).() const
255 {
256 return tlscxx . . $ mlspp/tls/::variantcxx . . $ mlspp/tls/variant#<SenderType>::typecxx . . $ mlspp/tls/variant#type(75812b123985b71e).(sendercxx . . $ mlspp/Sender#sender.);
257 }
258
259 tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#&
260 operatorcxx . . $ mlspp/`operator<<`(ec46f4e5e266d437).<<(tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#& str, const GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData#& obj)
261 {
262 switch (obj.content_typecxx . . $ mlspp/GroupContentAuthData#content_type.) {
263 case ContentTypecxx . . $ mlspp/ContentType#::proposalcxx . . $ mlspp/ContentType#proposal.:
264 case ContentTypecxx . . $ mlspp/ContentType#::applicationcxx . . $ mlspp/ContentType#application.:
265 return str <<cxx . . $ mlspp/tls/`operator<<`(412b32e9a88efffb). obj.signaturecxx . . $ mlspp/GroupContentAuthData#signature.;
266
267 case ContentTypecxx . . $ mlspp/ContentType#::commitcxx . . $ mlspp/ContentType#commit.:
268 return str <<cxx . . $ mlspp/tls/`operator<<`(412b32e9a88efffb). obj.signaturecxx . . $ mlspp/GroupContentAuthData#signature. <<cxx . . $ mlspp/tls/`operator<<`(412b32e9a88efffb). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(obj.confirmation_tagcxx . . $ mlspp/GroupContentAuthData#confirmation_tag.);
269
270 default:
271 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid content type");
272 }
273 }
274
275 tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#&
276 operatorcxx . . $ mlspp/`operator>>`(63c45ef99cb77536).>>(tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#& str, GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData#& obj)
277 {
278 switch (obj.content_typecxx . . $ mlspp/GroupContentAuthData#content_type.) {
279 case ContentTypecxx . . $ mlspp/ContentType#::proposalcxx . . $ mlspp/ContentType#proposal.:
280 case ContentTypecxx . . $ mlspp/ContentType#::applicationcxx . . $ mlspp/ContentType#application.:
281 return str >>cxx . . $ mlspp/tls/`operator>>`(b2c72a419bbd3d19). obj.signaturecxx . . $ mlspp/GroupContentAuthData#signature.;
282
283 case ContentTypecxx . . $ mlspp/ContentType#::commitcxx . . $ mlspp/ContentType#commit.:
284 obj.confirmation_tagcxx . . $ mlspp/GroupContentAuthData#confirmation_tag..emplacecxx . . $ std/optional#emplace(8cc437dbb5d7266f).();
285 return str >>cxx . . $ mlspp/tls/`operator>>`(b2c72a419bbd3d19). obj.signaturecxx . . $ mlspp/GroupContentAuthData#signature. >>cxx . . $ mlspp/tls/`operator>>`(b2c72a419bbd3d19). opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(obj.confirmation_tagcxx . . $ mlspp/GroupContentAuthData#confirmation_tag.);
286
287 default:
288 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid content type");
289 }
290 }
291
292 bool
293 operatorcxx . . $ mlspp/`operator==`(5664086339a95c04).==(const GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData#& lhs, const GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData#& rhs)
294 {
295 return lhs.content_typecxx . . $ mlspp/GroupContentAuthData#content_type. == rhs.content_typecxx . . $ mlspp/GroupContentAuthData#content_type. &&
296 lhs.signaturecxx . . $ mlspp/GroupContentAuthData#signature. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.signaturecxx . . $ mlspp/GroupContentAuthData#signature. &&
297 lhs.confirmation_tagcxx . . $ mlspp/GroupContentAuthData#confirmation_tag. ==cxx . . $ std/`operator==`(b01326bb8e6dcef). rhs.confirmation_tagcxx . . $ mlspp/GroupContentAuthData#confirmation_tag.;
298 }
299
300 GroupContentcxx . . $ mlspp/GroupContent#::GroupContentcxx . . $ mlspp/GroupContent#GroupContent(f5f370ed8cd561bf).(bytescxx . . $ mlspp/bytes_ns/bytes# group_id_in,
301 epoch_tcxx . . $ mlspp/epoch_t# epoch_in,
302 Sendercxx . . $ mlspp/Sender# sender_in,
303 bytescxx . . $ mlspp/bytes_ns/bytes# authenticated_data_in,
304 RawContentcxx . . $ mlspp/GroupContent#RawContent# content_in)
305 : group_idcxx . . $ mlspp/GroupContent#group_id.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(group_id_in))
306 , epochcxx . . $ mlspp/GroupContent#epoch.(epoch_in)
307 , sendercxx . . $ mlspp/GroupContent#sender.(sender_in)
308 , authenticated_datacxx . . $ mlspp/GroupContent#authenticated_data.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(authenticated_data_in))
309 , contentcxx . . $ mlspp/GroupContent#content.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_in))
310 {
311 }
312
313 GroupContentcxx . . $ mlspp/GroupContent#::GroupContentcxx . . $ mlspp/GroupContent#GroupContent(b1128e9291071743).(bytescxx . . $ mlspp/bytes_ns/bytes# group_id_in,
314 epoch_tcxx . . $ mlspp/epoch_t# epoch_in,
315 Sendercxx . . $ mlspp/Sender# sender_in,
316 bytescxx . . $ mlspp/bytes_ns/bytes# authenticated_data_in,
317 ContentTypecxx . . $ mlspp/ContentType# content_type)
318 : group_idcxx . . $ mlspp/GroupContent#group_id.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(group_id_in))
319 , epochcxx . . $ mlspp/GroupContent#epoch.(epoch_in)
320 , sendercxx . . $ mlspp/GroupContent#sender.(sender_in)
321 , authenticated_datacxx . . $ mlspp/GroupContent#authenticated_data.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(authenticated_data_in))
322 {
323 switch (content_type) {
324 case ContentTypecxx . . $ mlspp/ContentType#::commitcxx . . $ mlspp/ContentType#commit.:
325 contentcxx . . $ mlspp/GroupContent#content..emplacecxx . . $ std/variant#emplace(ca64f3c84650be36).<Commitcxx . . $ mlspp/Commit#>();
326 break;
327
328 case ContentTypecxx . . $ mlspp/ContentType#::proposalcxx . . $ mlspp/ContentType#proposal.:
329 contentcxx . . $ mlspp/GroupContent#content..emplacecxx . . $ std/variant#emplace(ca64f3c84650be36).<Proposalcxx . . $ mlspp/Proposal#>();
330 break;
331
332 case ContentTypecxx . . $ mlspp/ContentType#::applicationcxx . . $ mlspp/ContentType#application.:
333 contentcxx . . $ mlspp/GroupContent#content..emplacecxx . . $ std/variant#emplace(ca64f3c84650be36).<ApplicationDatacxx . . $ mlspp/ApplicationData#>();
334 break;
335
336 default:
337 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid content type");
338 }
339 }
340
341 ContentTypecxx . . $ mlspp/ContentType#
342 GroupContentcxx . . $ mlspp/GroupContent#::content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).() const
343 {
344 return tlscxx . . $ mlspp/tls/::variantcxx . . $ mlspp/tls/variant#<ContentType>::typecxx . . $ mlspp/tls/variant#type(9a0591017c72b1d3).(contentcxx . . $ mlspp/GroupContent#content.);
345 }
346
347 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#
348 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::signcxx . . $ mlspp/AuthenticatedContent#sign(6554afcb5b84419).(WireFormatcxx . . $ mlspp/WireFormat# wire_format,
349 GroupContentcxx . . $ mlspp/GroupContent# content,
350 CipherSuitecxx . . $ mlspp/CipherSuite# suite,
351 const SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#& sig_priv,
352 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<GroupContextcxx . . $ mlspp/GroupContext#>& context)
353 {
354 if (wire_format == WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message. &&
355 content.content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).() == ContentTypecxx . . $ mlspp/ContentType#::applicationcxx . . $ mlspp/ContentType#application.) {
356 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#(
357 "Application data cannot be sent as PublicMessage");
358 }
359
360 auto content_auth = AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#AuthenticatedContent(6fb0b5b8685f6795).{ wire_format, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content) };
361 auto tbs = content_auth.to_be_signedcxx . . $ mlspp/AuthenticatedContent#to_be_signed(7354dd4995a43625).(context);
362 content_auth.authcxx . . $ mlspp/AuthenticatedContent#auth..signaturecxx . . $ mlspp/GroupContentAuthData#signature. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed).
363 sig_priv.signcxx . . $ mlspp/SignaturePrivateKey#sign(9a20592b3b42a8ed).(suite, sign_labelcxx . . $ mlspp/sign_label/::mls_contentcxx . . $ mlspp/sign_label/mls_content., tbs);
364 return content_auth;
365 }
366
367 bool
368 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::verifycxx . . $ mlspp/AuthenticatedContent#verify(3653f40ee3caab0a).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
369 const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& sig_pub,
370 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<GroupContextcxx . . $ mlspp/GroupContext#>& context) const
371 {
372 if (wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format. == WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message. &&
373 contentcxx . . $ mlspp/AuthenticatedContent#content..content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).() == ContentTypecxx . . $ mlspp/ContentType#::applicationcxx . . $ mlspp/ContentType#application.) {
374 return false;
375 }
376
377 auto tbs = to_be_signedcxx . . $ mlspp/AuthenticatedContent#to_be_signed(7354dd4995a43625).(context);
378 return sig_pub.verifycxx . . $ mlspp/SignaturePublicKey#verify(e28f084f4f4fb6fe).(suite, sign_labelcxx . . $ mlspp/sign_label/::mls_contentcxx . . $ mlspp/sign_label/mls_content., tbs, authcxx . . $ mlspp/AuthenticatedContent#auth..signaturecxx . . $ mlspp/GroupContentAuthData#signature.);
379 }
380
381 struct ConfirmedTranscriptHashInputcxx . . $ mlspp/ConfirmedTranscriptHashInput#
382 {
383 WireFormatcxx . . $ mlspp/WireFormat# wire_formatcxx . . $ mlspp/ConfirmedTranscriptHashInput#wire_format.;
384 const GroupContentcxx . . $ mlspp/GroupContent#& contentcxx . . $ mlspp/ConfirmedTranscriptHashInput#content.;
385 const bytescxx . . $ mlspp/bytes_ns/bytes#& signaturecxx . . $ mlspp/ConfirmedTranscriptHashInput#signature.;
386
387 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(wire_format, content, signature);
388 };
389
390 struct InterimTranscriptHashInputcxx . . $ mlspp/InterimTranscriptHashInput#
391 {
392 const bytescxx . . $ mlspp/bytes_ns/bytes#& confirmation_tagcxx . . $ mlspp/InterimTranscriptHashInput#confirmation_tag.;
393
394 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(confirmation_tag);
395 };
396
397 bytescxx . . $ mlspp/bytes_ns/bytes#
398 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::confirmed_transcript_hash_inputcxx . . $ mlspp/AuthenticatedContent#confirmed_transcript_hash_input(d7392ba79aa35767).() const
399 {
400 return tlscxx . . $ mlspp/bytes_ns/bytes#bytes(dd8c33c7e39dbe02).::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(ConfirmedTranscriptHashInputcxx . . $ mlspp/ConfirmedTranscriptHashInput#{
401 wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format.,
402 contentcxx . . $ mlspp/AuthenticatedContent#content.,
403 authcxx . . $ mlspp/AuthenticatedContent#auth..signaturecxx . . $ mlspp/GroupContentAuthData#signature.,
404 });
405 }
406
407 bytescxx . . $ mlspp/bytes_ns/bytes#
408 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::interim_transcript_hash_inputcxx . . $ mlspp/AuthenticatedContent#interim_transcript_hash_input(d7392ba79aa35767).() const
409 {
410 return tlscxx . . $ mlspp/bytes_ns/bytes#bytes(dd8c33c7e39dbe02).::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(
411 InterimTranscriptHashInputcxx . . $ mlspp/InterimTranscriptHashInput#{ opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(authcxx . . $ mlspp/AuthenticatedContent#auth..confirmation_tagcxx . . $ mlspp/GroupContentAuthData#confirmation_tag.) });
412 }
413
414 void
415 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::set_confirmation_tagcxx . . $ mlspp/AuthenticatedContent#set_confirmation_tag(68ca607eebb5be3e).(const bytescxx . . $ mlspp/bytes_ns/bytes#& confirmation_tag)
416 {
417 authcxx . . $ mlspp/AuthenticatedContent#auth..confirmation_tagcxx . . $ mlspp/GroupContentAuthData#confirmation_tag. =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed). confirmation_tag;
418 }
419
420 bool
421 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::check_confirmation_tagcxx . . $ mlspp/AuthenticatedContent#check_confirmation_tag(efd4f3c976ab92ce).(
422 const bytescxx . . $ mlspp/bytes_ns/bytes#& confirmation_tag) const
423 {
424 return confirmation_tag ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(authcxx . . $ mlspp/AuthenticatedContent#auth..confirmation_tagcxx . . $ mlspp/GroupContentAuthData#confirmation_tag.);
425 }
426
427 tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#&
428 operatorcxx . . $ mlspp/`operator<<`(3de15628e07b82e2).<<(tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#& str, const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& obj)
429 {
430 return str <<cxx . . $ mlspp/tls/`operator<<`(6fe629d8779e7a9e). obj.wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format. <<cxx . . $ mlspp/tls/`operator<<`(4e4cd7c57e422a98). obj.contentcxx . . $ mlspp/AuthenticatedContent#content. <<cxx . . $ mlspp/`operator<<`(ec46f4e5e266d437). obj.authcxx . . $ mlspp/AuthenticatedContent#auth.;
431 }
432
433 tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#&
434 operatorcxx . . $ mlspp/`operator>>`(b28fa0a93aad6ead).>>(tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#& str, AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& obj)
435 {
436 str >>cxx . . $ mlspp/tls/`operator>>`(705db4ae2ef34f8a). obj.wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format. >>cxx . . $ mlspp/tls/`operator>>`(466797c0969b3236). obj.contentcxx . . $ mlspp/AuthenticatedContent#content.;
437
438 obj.authcxx . . $ mlspp/AuthenticatedContent#auth..content_typecxx . . $ mlspp/GroupContentAuthData#content_type. = obj.contentcxx . . $ mlspp/AuthenticatedContent#content..content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).();
439 return str >>cxx . . $ mlspp/`operator>>`(63c45ef99cb77536). obj.authcxx . . $ mlspp/AuthenticatedContent#auth.;
440 }
441
442 bool
443 operatorcxx . . $ mlspp/`operator==`(1d9eaf42c0eadcee).==(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& lhs, const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& rhs)
444 {
445 return lhs.wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format. == rhs.wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format. && lhs.contentcxx . . $ mlspp/AuthenticatedContent#content. ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). rhs.contentcxx . . $ mlspp/AuthenticatedContent#content. &&
446 lhs.authcxx . . $ mlspp/AuthenticatedContent#auth. ==cxx . . $ mlspp/`operator==`(5664086339a95c04). rhs.authcxx . . $ mlspp/AuthenticatedContent#auth.;
447 }
448
449 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#AuthenticatedContent(6fb0b5b8685f6795).(WireFormatcxx . . $ mlspp/WireFormat# wire_format_in,
450 GroupContentcxx . . $ mlspp/GroupContent# content_in)
451 : wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format.(wire_format_in)
452 , contentcxx . . $ mlspp/AuthenticatedContent#content.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_in))
453 {
454 authcxx . . $ mlspp/AuthenticatedContent#auth..content_typecxx . . $ mlspp/GroupContentAuthData#content_type. = contentcxx . . $ mlspp/AuthenticatedContent#content..content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).();
455 }
456
457 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#AuthenticatedContent(8d87d391e6c7cdab).(WireFormatcxx . . $ mlspp/WireFormat# wire_format_in,
458 GroupContentcxx . . $ mlspp/GroupContent# content_in,
459 GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData# auth_in)
460 : wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format.(wire_format_in)
461 , contentcxx . . $ mlspp/AuthenticatedContent#content.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_in))
462 , authcxx . . $ mlspp/AuthenticatedContent#auth.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(auth_in))
463 {
464 }
465
466 const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#&
467 ValidatedContentcxx . . $ mlspp/ValidatedContent#::authenticated_contentcxx . . $ mlspp/ValidatedContent#authenticated_content(780253df4e70ffcf).() const
468 {
469 return content_authcxx . . $ mlspp/ValidatedContent#content_auth.;
470 }
471
472 ValidatedContentcxx . . $ mlspp/ValidatedContent#::ValidatedContentcxx . . $ mlspp/ValidatedContent#ValidatedContent(4cb5f50ea8a1da54).(AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent# content_auth_in)
473 : content_authcxx . . $ mlspp/ValidatedContent#content_auth.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth_in))
474 {
475 }
476
477 bool
478 operatorcxx . . $ mlspp/`operator==`(b819a072b6308eef).==(const ValidatedContentcxx . . $ mlspp/ValidatedContent#& lhs, const ValidatedContentcxx . . $ mlspp/ValidatedContent#& rhs)
479 {
480 return lhs.content_authcxx . . $ mlspp/ValidatedContent#content_auth. ==cxx . . $ mlspp/`operator==`(1d9eaf42c0eadcee). rhs.content_authcxx . . $ mlspp/ValidatedContent#content_auth.;
481 }
482
483 struct GroupContentTBScxx . . $ mlspp/GroupContentTBS#
484 {
485 WireFormatcxx . . $ mlspp/WireFormat# wire_formatcxx . . $ mlspp/GroupContentTBS#wire_format. = WireFormatcxx . . $ mlspp/WireFormat#::reservedcxx . . $ mlspp/WireFormat#reserved.;
486 const GroupContentcxx . . $ mlspp/GroupContent#& contentcxx . . $ mlspp/GroupContentTBS#content.;
487 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<GroupContextcxx . . $ mlspp/GroupContext#>& contextcxx . . $ mlspp/GroupContentTBS#context.;
488 };
489
490 static tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#&
491 operatorcxx . . $ mlspp/`operator<<`(ebe2e0317fff708d).<<(tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#& str, const GroupContentTBScxx . . $ mlspp/GroupContentTBS#& obj)
492 {
493 str <<cxx . . $ mlspp/tls/`operator<<`(6fe629d8779e7a9e). ProtocolVersioncxx . . $ mlspp/ProtocolVersion#::mls10cxx . . $ mlspp/ProtocolVersion#mls10. <<cxx . . $ mlspp/tls/`operator<<`(6fe629d8779e7a9e). obj.wire_formatcxx . . $ mlspp/GroupContentTBS#wire_format. <<cxx . . $ mlspp/tls/`operator<<`(4e4cd7c57e422a98). obj.contentcxx . . $ mlspp/GroupContentTBS#content.;
494
495 switch (obj.contentcxx . . $ mlspp/GroupContentTBS#content..sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).()) {
496 case SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.:
497 case SenderTypecxx . . $ mlspp/SenderType#::new_member_commitcxx . . $ mlspp/SenderType#new_member_commit.:
498 str <<cxx . . $ mlspp/tls/`operator<<`(412b32e9a88efffb). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(obj.contextcxx . . $ mlspp/GroupContentTBS#context.);
499 break;
500
501 case SenderTypecxx . . $ mlspp/SenderType#::externalcxx . . $ mlspp/SenderType#external.:
502 case SenderTypecxx . . $ mlspp/SenderType#::new_member_proposalcxx . . $ mlspp/SenderType#new_member_proposal.:
503 break;
504
505 default:
506 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid sender type");
507 }
508
509 return str;
510 }
511
512 bytescxx . . $ mlspp/bytes_ns/bytes#
513 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::to_be_signedcxx . . $ mlspp/AuthenticatedContent#to_be_signed(7354dd4995a43625).(
514 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<GroupContextcxx . . $ mlspp/GroupContext#>& context) const
515 {
516 return tlscxx . . $ mlspp/bytes_ns/bytes#bytes(dd8c33c7e39dbe02).::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(GroupContentTBScxx . . $ mlspp/GroupContentTBS#{
517 wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format.,
518 contentcxx . . $ mlspp/AuthenticatedContent#content.,
519 context,
520 });
521 }
522
523 PublicMessagecxx . . $ mlspp/PublicMessage#
524 PublicMessagecxx . . $ mlspp/PublicMessage#::protectcxx . . $ mlspp/PublicMessage#protect(2291e3815af7a859).(AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent# content_auth,
525 CipherSuitecxx . . $ mlspp/CipherSuite# suite,
526 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>& membership_key,
527 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<GroupContextcxx . . $ mlspp/GroupContext#>& context)
528 {
529 auto pt = PublicMessagecxx . . $ mlspp/PublicMessage#PublicMessage(4cb5f50ea8a1da54).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth));
530
531 // Add the membership_mac if required
532 switch (pt.contentcxx . . $ mlspp/PublicMessage#content..sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).()) {
533 case SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.:
534 pt.membership_tagcxx . . $ mlspp/PublicMessage#membership_tag. =cxx . . $ std/optional#`operator=`(4ce4dd0ee161fed).
535 pt.membership_maccxx . . $ mlspp/PublicMessage#membership_mac(27872dd8c9f4b71a).(suite, opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(membership_key), context);
536 break;
537
538 default:
539 break;
540 }
541
542 return pt;
543 }
544
545 stdcxx . . $ std/::optionalcxx . . $ std/optional#<ValidatedContentcxx . . $ mlspp/ValidatedContent#>
546 PublicMessagecxx . . $ mlspp/PublicMessage#::unprotectcxx . . $ mlspp/PublicMessage#unprotect(fefd97f134b41226).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
547 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>& membership_key,
548 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<GroupContextcxx . . $ mlspp/GroupContext#>& context) const
549 {
550 // Verify the membership_tag if the message was sent within the group
551 switch (contentcxx . . $ mlspp/PublicMessage#content..sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).()) {
552 case SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.: {
553 auto candidate = membership_maccxx . . $ mlspp/PublicMessage#membership_mac(27872dd8c9f4b71a).(suite, opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(membership_key), context);
554 if (candidate !=cxx . . $ mlspp/bytes_ns/bytes#`operator!=`(efd4f3c976ab92ce). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(membership_tagcxx . . $ mlspp/PublicMessage#membership_tag.)) {
555 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
556 }
557 break;
558 }
559
560 default:
561 break;
562 }
563
564 return {cxx . . $ std/optional#optional(e3f0d6382bd52f24). {cxx . . $ mlspp/ValidatedContent#ValidatedContent(4cb5f50ea8a1da54). AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#AuthenticatedContent(8d87d391e6c7cdab).{
565 WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message.,
566 contentcxx . . $ mlspp/PublicMessage#content.,
567 authcxx . . $ mlspp/PublicMessage#auth.,
568 } } };
569 }
570
571 bool
572 PublicMessagecxx . . $ mlspp/PublicMessage#::containscxx . . $ mlspp/PublicMessage#contains(891fdc29165d76d0).(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) const
573 {
574 return contentcxx . . $ mlspp/PublicMessage#content. ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content. && authcxx . . $ mlspp/PublicMessage#auth. ==cxx . . $ mlspp/`operator==`(5664086339a95c04). content_auth.authcxx . . $ mlspp/AuthenticatedContent#auth.;
575 }
576
577 AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#
578 PublicMessagecxx . . $ mlspp/PublicMessage#::authenticated_contentcxx . . $ mlspp/PublicMessage#authenticated_content(a7864a14feee5fc2).() const
579 {
580 auto auth_content = AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#AuthenticatedContent(49f6e7a06ebc5aa8).{};
581 auth_content.wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format. = WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message.;
582 auth_content.contentcxx . . $ mlspp/AuthenticatedContent#content. =cxx . . $ mlspp/GroupContent#`operator=`(b29a34be6850ec95). contentcxx . . $ mlspp/PublicMessage#content.;
583 auth_content.authcxx . . $ mlspp/AuthenticatedContent#auth. =cxx . . $ mlspp/GroupContentAuthData#`operator=`(df16bfbd439dd78b). authcxx . . $ mlspp/PublicMessage#auth.;
584 return auth_content;
585 }
586
587 PublicMessagecxx . . $ mlspp/PublicMessage#::PublicMessagecxx . . $ mlspp/PublicMessage#PublicMessage(4cb5f50ea8a1da54).(AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent# content_auth)
588 : contentcxx . . $ mlspp/PublicMessage#content.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content.))
589 , authcxx . . $ mlspp/PublicMessage#auth.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth.authcxx . . $ mlspp/AuthenticatedContent#auth.))
590 {
591 if (content_auth.wire_formatcxx . . $ mlspp/AuthenticatedContent#wire_format. != WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message.) {
592 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Wire format mismatch (not mls_plaintext)");
593 }
594 }
595
596 struct GroupContentTBMcxx . . $ mlspp/GroupContentTBM#
597 {
598 GroupContentTBScxx . . $ mlspp/GroupContentTBS# content_tbscxx . . $ mlspp/GroupContentTBM#content_tbs.;
599 GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData# authcxx . . $ mlspp/GroupContentTBM#auth.;
600
601 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(content_tbs, auth);
602 };
603
604 bytescxx . . $ mlspp/bytes_ns/bytes#
605 PublicMessagecxx . . $ mlspp/PublicMessage#::membership_maccxx . . $ mlspp/PublicMessage#membership_mac(27872dd8c9f4b71a).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
606 const bytescxx . . $ mlspp/bytes_ns/bytes#& membership_key,
607 const stdcxx . . $ std/::optionalcxx . . $ std/optional#<GroupContextcxx . . $ mlspp/GroupContext#>& context) const
608 {
609 auto tbm = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(GroupContentTBMcxx . . $ mlspp/GroupContentTBM#{
610 { WireFormatcxx . . $ mlspp/WireFormat#::mls_public_messagecxx . . $ mlspp/WireFormat#mls_public_message., contentcxx . . $ mlspp/PublicMessage#content., context },
611 authcxx . . $ mlspp/PublicMessage#auth.,
612 });
613
614 return suite.digestcxx . . $ mlspp/CipherSuite#digest(cdb80d7d9b9bc276).().hmaccxx . . $ mlspp/hpke/Digest#hmac(802fe03ef4f7e693).(membership_key, tbmcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
615 }
616
617 tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#&
618 operatorcxx . . $ mlspp/`operator<<`(5abed274187f5cbe).<<(tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#& str, const PublicMessagecxx . . $ mlspp/PublicMessage#& obj)
619 {
620 switch (obj.contentcxx . . $ mlspp/PublicMessage#content..sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).()) {
621 case SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.:
622 return str <<cxx . . $ mlspp/tls/`operator<<`(4e4cd7c57e422a98). obj.contentcxx . . $ mlspp/PublicMessage#content. <<cxx . . $ mlspp/`operator<<`(ec46f4e5e266d437). obj.authcxx . . $ mlspp/PublicMessage#auth. <<cxx . . $ mlspp/tls/`operator<<`(412b32e9a88efffb). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(obj.membership_tagcxx . . $ mlspp/PublicMessage#membership_tag.);
623
624 case SenderTypecxx . . $ mlspp/SenderType#::externalcxx . . $ mlspp/SenderType#external.:
625 case SenderTypecxx . . $ mlspp/SenderType#::new_member_proposalcxx . . $ mlspp/SenderType#new_member_proposal.:
626 case SenderTypecxx . . $ mlspp/SenderType#::new_member_commitcxx . . $ mlspp/SenderType#new_member_commit.:
627 return str <<cxx . . $ mlspp/tls/`operator<<`(4e4cd7c57e422a98). obj.contentcxx . . $ mlspp/PublicMessage#content. <<cxx . . $ mlspp/`operator<<`(ec46f4e5e266d437). obj.authcxx . . $ mlspp/PublicMessage#auth.;
628
629 default:
630 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid sender type");
631 }
632 }
633
634 tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#&
635 operatorcxx . . $ mlspp/`operator>>`(14ee52d4faa317cc).>>(tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#& str, PublicMessagecxx . . $ mlspp/PublicMessage#& obj)
636 {
637 str >>cxx . . $ mlspp/tls/`operator>>`(466797c0969b3236). obj.contentcxx . . $ mlspp/PublicMessage#content.;
638
639 obj.authcxx . . $ mlspp/PublicMessage#auth..content_typecxx . . $ mlspp/GroupContentAuthData#content_type. = obj.contentcxx . . $ mlspp/PublicMessage#content..content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).();
640 str >>cxx . . $ mlspp/`operator>>`(63c45ef99cb77536). obj.authcxx . . $ mlspp/PublicMessage#auth.;
641
642 if (obj.contentcxx . . $ mlspp/PublicMessage#content..sendercxx . . $ mlspp/GroupContent#sender..sender_typecxx . . $ mlspp/Sender#sender_type(2a41707803b4ee62).() == SenderTypecxx . . $ mlspp/SenderType#::membercxx . . $ mlspp/SenderType#member.) {
643 obj.membership_tagcxx . . $ mlspp/PublicMessage#membership_tag..emplacecxx . . $ std/optional#emplace(8cc437dbb5d7266f).();
644 str >>cxx . . $ mlspp/tls/`operator>>`(b2c72a419bbd3d19). opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(obj.membership_tagcxx . . $ mlspp/PublicMessage#membership_tag.);
645 }
646
647 return str;
648 }
649
650 bool
651 operatorcxx . . $ mlspp/`operator==`(a11265f2657dfb81).==(const PublicMessagecxx . . $ mlspp/PublicMessage#& lhs, const PublicMessagecxx . . $ mlspp/PublicMessage#& rhs)
652 {
653 return lhs.contentcxx . . $ mlspp/PublicMessage#content. ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). rhs.contentcxx . . $ mlspp/PublicMessage#content. && lhs.authcxx . . $ mlspp/PublicMessage#auth. ==cxx . . $ mlspp/`operator==`(5664086339a95c04). rhs.authcxx . . $ mlspp/PublicMessage#auth. &&
654 lhs.membership_tagcxx . . $ mlspp/PublicMessage#membership_tag. ==cxx . . $ std/`operator==`(b01326bb8e6dcef). rhs.membership_tagcxx . . $ mlspp/PublicMessage#membership_tag.;
655 }
656
657 bool
658 operatorcxx . . $ mlspp/`operator!=`(a11265f2657dfb81).!=(const PublicMessagecxx . . $ mlspp/PublicMessage#& lhs, const PublicMessagecxx . . $ mlspp/PublicMessage#& rhs)
659 {
660 return !(lhs ==cxx . . $ mlspp/`operator==`(a11265f2657dfb81). rhs);
661 }
662
663 static bytescxx . . $ mlspp/bytes_ns/bytes#
664 marshal_ciphertext_contentcxx . . $ mlspp/marshal_ciphertext_content(cbf8eb14480c5219).(const GroupContentcxx . . $ mlspp/GroupContent#& content,
665 const GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData#& auth,
666 size_t padding_size)
667 {
668 auto w = tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#{};
669 var::visitcxx . . $ std/visit(9828ab07ec69b3d0).([&w](const auto& val) { w <<cxx . . $ mlspp/`operator<<`(5abed274187f5cbe). val; }, content.contentcxx . . $ mlspp/GroupContent#content.);
670 w <<cxx . . $ mlspp/`operator<<`(ec46f4e5e266d437). auth;
671 w.write_rawcxx . . $ mlspp/tls/ostream#write_raw(981a1a29c6e5fab4).(bytescxx . . $ mlspp/bytes_ns/bytes#bytes(913f486ae89fd8a8).(padding_size, 0));
672 return wcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)..bytescxx . . $ mlspp/tls/ostream#bytes(30469b417f2e3d73).();
673 }
674
675 static void
676 unmarshal_ciphertext_contentcxx . . $ mlspp/unmarshal_ciphertext_content(b53d88b03eebeded).(const bytescxx . . $ mlspp/bytes_ns/bytes#& content_pt,
677 GroupContentcxx . . $ mlspp/GroupContent#& content,
678 GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData#& auth)
679 {
680 auto r = tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#(content_pt);
681
682 var::visitcxx . . $ std/visit(9828ab07ec69b3d0).([&r](auto& val) { r >>cxx . . $ mlspp/`operator>>`(14ee52d4faa317cc). val; }, content.contentcxx . . $ mlspp/GroupContent#content.);
683 r >>cxx . . $ mlspp/`operator>>`(63c45ef99cb77536). auth;
684
685 const auto padding = r.bytescxx . . $ mlspp/tls/istream#bytes(695134cc693f8bd0).();
686 const auto nonzero = [](const auto& x) { return x !=cxx . . $ mlspp/`operator!=`(a11265f2657dfb81). 0; };
687 if (stdxcxx . . $ mlspp/stdx/::any_ofcxx . . $ mlspp/stdx/any_of(acb94948942028a1).(padding, nonzero)) {
688 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Malformed AuthenticatedContentTBE padding");
689 }
690 }
691
692 struct ContentAADcxx . . $ mlspp/ContentAAD#
693 {
694 const bytescxx . . $ mlspp/bytes_ns/bytes#& group_idcxx . . $ mlspp/ContentAAD#group_id.;
695 const epoch_tcxx . . $ mlspp/epoch_t# epochcxx . . $ mlspp/ContentAAD#epoch.;
696 const ContentTypecxx . . $ mlspp/ContentType# content_typecxx . . $ mlspp/ContentAAD#content_type.;
697 const bytescxx . . $ mlspp/bytes_ns/bytes#& authenticated_datacxx . . $ mlspp/ContentAAD#authenticated_data.;
698
699 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(group_id, epoch, content_type, authenticated_data)
700 };
701
702 struct SenderDatacxx . . $ mlspp/SenderData#
703 {
704 LeafIndexcxx . . $ mlspp/LeafIndex# sendercxx . . $ mlspp/SenderData#sender.{ 0 };
705 uint32_tcxx . . $ uint32_t# generationcxx . . $ mlspp/SenderData#generation.{ 0 };
706 ReuseGuardcxx . . $ mlspp/ReuseGuard# reuse_guardcxx . . $ mlspp/SenderData#reuse_guard.{ 0, 0, 0, 0 };
707
708 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(sender, generation, reuse_guard)
709 };
710
711 struct SenderDataAADcxx . . $ mlspp/SenderDataAAD#
712 {
713 const bytescxx . . $ mlspp/bytes_ns/bytes#& group_idcxx . . $ mlspp/SenderDataAAD#group_id.;
714 const epoch_tcxx . . $ mlspp/epoch_t# epochcxx . . $ mlspp/SenderDataAAD#epoch.;
715 const ContentTypecxx . . $ mlspp/ContentType# content_typecxx . . $ mlspp/SenderDataAAD#content_type.;
716
717 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(group_id, epoch, content_type)
718 };
719
720 PrivateMessagecxx . . $ mlspp/PrivateMessage#
721 PrivateMessagecxx . . $ mlspp/PrivateMessage#::protectcxx . . $ mlspp/PrivateMessage#protect(5256fdc14bb335a).(AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent# content_auth,
722 CipherSuitecxx . . $ mlspp/CipherSuite# suite,
723 GroupKeySourcecxx . . $ mlspp/GroupKeySource#& keys,
724 const bytescxx . . $ mlspp/bytes_ns/bytes#& sender_data_secret,
725 size_t padding_size)
726 {
727 // Pull keys from the secret tree
728 auto index =
729 var::getcxx . . $ std/get(55ed64a6518b24d0).<MemberSendercxx . . $ mlspp/MemberSender#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..sendercxx . . $ mlspp/GroupContent#sender..sendercxx . . $ mlspp/Sender#sender.).sendercxx . . $ mlspp/MemberSender#sender.;
730 auto content_type = content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).();
731 auto [generation, reuse_guard, content_keys] = keys.nextcxx . . $ mlspp/GroupKeySource#next(93009b092b6559de).(content_type, index);
732
733 // Encrypt the content
734 auto content_pt = marshal_ciphertext_contentcxx . . $ mlspp/marshal_ciphertext_content(cbf8eb14480c5219).(
735 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content., content_auth.authcxx . . $ mlspp/AuthenticatedContent#auth., padding_size);
736 auto content_aad = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(ContentAADcxx . . $ mlspp/ContentAAD#{
737 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..group_idcxx . . $ mlspp/GroupContent#group_id.,
738 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..epochcxx . . $ mlspp/GroupContent#epoch.,
739 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).(),
740 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..authenticated_datacxx . . $ mlspp/GroupContent#authenticated_data.,
741 });
742
743 auto content_ct = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..sealcxx . . $ mlspp/hpke/AEAD#seal(a2160eb270d8417e).(
744 content_keys.keycxx . . $ mlspp/KeyAndNonce#key., content_keys.noncecxx . . $ mlspp/KeyAndNonce#nonce., content_aadcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)., content_pt);
745
746 // Encrypt the sender data
747 auto sender_index =
748 var::getcxx . . $ std/get(55ed64a6518b24d0).<MemberSendercxx . . $ mlspp/MemberSender#>(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..sendercxx . . $ mlspp/GroupContent#sender..sendercxx . . $ mlspp/Sender#sender.).sendercxx . . $ mlspp/MemberSender#sender.;
749 auto sender_data_pt = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(SenderDatacxx . . $ mlspp/SenderData#{
750 sender_index,
751 generation,
752 reuse_guard,
753 });
754 auto sender_data_aad = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(SenderDataAADcxx . . $ mlspp/SenderDataAAD#{
755 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..group_idcxx . . $ mlspp/GroupContent#group_id.,
756 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..epochcxx . . $ mlspp/GroupContent#epoch.,
757 content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content..content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).(),
758 });
759
760 auto sender_data_keys =
761 KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::sender_data_keyscxx . . $ mlspp/KeyScheduleEpoch#sender_data_keys(65fe22caf18b2b69).(suite, sender_data_secret, content_ct);
762
763 auto sender_data_ct = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..sealcxx . . $ mlspp/hpke/AEAD#seal(a2160eb270d8417e).(sender_data_keys.keycxx . . $ mlspp/KeyAndNonce#key.,
764 sender_data_keys.noncecxx . . $ mlspp/KeyAndNonce#nonce.,
765 sender_data_aadcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).,
766 sender_data_ptcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
767
768 return PrivateMessagecxx . . $ mlspp/PrivateMessage#PrivateMessage(22a646458d5d0229).{
769 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content_auth.contentcxx . . $ mlspp/AuthenticatedContent#content.),
770 stdcxx . . $ mlspp/bytes_ns/bytes#bytes(628b76f52f2a67f).::movecxx . . $ std/move(e35c19a1ba7baa26).(sender_data_ct),
771 stdcxx . . $ mlspp/bytes_ns/bytes#bytes(628b76f52f2a67f).::movecxx . . $ std/move(e35c19a1ba7baa26).(content_ct),
772 };
773 }
774
775 stdcxx . . $ std/::optionalcxx . . $ std/optional#<ValidatedContentcxx . . $ mlspp/ValidatedContent#>
776 PrivateMessagecxx . . $ mlspp/PrivateMessage#::unprotectcxx . . $ mlspp/PrivateMessage#unprotect(e57a24405060fb5).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
777 GroupKeySourcecxx . . $ mlspp/GroupKeySource#& keys,
778 const bytescxx . . $ mlspp/bytes_ns/bytes#& sender_data_secret) const
779 {
780 // Decrypt and parse the sender data
781 auto sender_data_keys =
782 KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::sender_data_keyscxx . . $ mlspp/KeyScheduleEpoch#sender_data_keys(65fe22caf18b2b69).(suite, sender_data_secret, ciphertextcxx . . $ mlspp/PrivateMessage#ciphertext.);
783 auto sender_data_aad = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(SenderDataAADcxx . . $ mlspp/SenderDataAAD#{
784 group_idcxx . . $ mlspp/PrivateMessage#group_id.,
785 epochcxx . . $ mlspp/PrivateMessage#epoch.,
786 content_typecxx . . $ mlspp/PrivateMessage#content_type.,
787 });
788
789 auto sender_data_pt = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..opencxx . . $ mlspp/hpke/AEAD#open(f7542dab5ac51900).(sender_data_keys.keycxx . . $ mlspp/KeyAndNonce#key.,
790 sender_data_keys.noncecxx . . $ mlspp/KeyAndNonce#nonce.,
791 sender_data_aadcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).,
792 encrypted_sender_datacxx . . $ mlspp/PrivateMessage#encrypted_sender_data.);
793 if (!sender_data_pt) {
794 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
795 }
796
797 auto sender_data = tlscxx . . $ mlspp/tls/::getcxx . . $ mlspp/tls/get(fdfeec44f419faae).<SenderDatacxx . . $ mlspp/SenderData#>(opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(sender_data_pt));
798 if (!keys.has_leafcxx . . $ mlspp/GroupKeySource#has_leaf(5c30a2d8336e88c0).(sender_data.sendercxx . . $ mlspp/SenderData#sender.)) {
799 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
800 }
801
802 // Decrypt the content
803 auto content_keys = keys.getcxx . . $ mlspp/GroupKeySource#get(b7daedcd7d3908ca).(content_typecxx . . $ mlspp/PrivateMessage#content_type.,
804 sender_data.sendercxx . . $ mlspp/SenderData#sender.,
805 sender_data.generationcxx . . $ mlspp/SenderData#generation.,
806 sender_data.reuse_guardcxx . . $ mlspp/SenderData#reuse_guard.);
807 keys.erasecxx . . $ mlspp/GroupKeySource#erase(efc0287f6c9543eb).(content_typecxx . . $ mlspp/PrivateMessage#content_type., sender_data.sendercxx . . $ mlspp/SenderData#sender., sender_data.generationcxx . . $ mlspp/SenderData#generation.);
808
809 auto content_aad = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(ContentAADcxx . . $ mlspp/ContentAAD#{
810 group_idcxx . . $ mlspp/PrivateMessage#group_id.,
811 epochcxx . . $ mlspp/PrivateMessage#epoch.,
812 content_typecxx . . $ mlspp/PrivateMessage#content_type.,
813 authenticated_datacxx . . $ mlspp/PrivateMessage#authenticated_data.,
814 });
815
816 auto content_pt = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..opencxx . . $ mlspp/hpke/AEAD#open(f7542dab5ac51900).(
817 content_keys.keycxx . . $ mlspp/KeyAndNonce#key., content_keys.noncecxx . . $ mlspp/KeyAndNonce#nonce., content_aadcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)., ciphertextcxx . . $ mlspp/PrivateMessage#ciphertext.);
818 if (!content_pt) {
819 return stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.;
820 }
821
822 // Parse the content
823 auto content = GroupContentcxx . . $ mlspp/GroupContent#GroupContent(b1128e9291071743).{ group_idcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).,
824 epochcxx . . $ mlspp/PrivateMessage#epoch.,
825 { MemberSendercxx . . $ mlspp/MemberSender#{ sender_data.sendercxx . . $ mlspp/SenderData#sender. } },
826 authenticated_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).,
827 content_typecxx . . $ mlspp/PrivateMessage#content_type. };
828 auto auth = GroupContentAuthDatacxx . . $ mlspp/GroupContentAuthData#{ content_typecxx . . $ mlspp/PrivateMessage#content_type., {}, {} };
829
830 unmarshal_ciphertext_contentcxx . . $ mlspp/unmarshal_ciphertext_content(b53d88b03eebeded).(opt::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(content_pt), content, auth);
831
832 return {cxx . . $ std/optional#optional(e3f0d6382bd52f24). {cxx . . $ mlspp/ValidatedContent#ValidatedContent(4cb5f50ea8a1da54). AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#AuthenticatedContent(8d87d391e6c7cdab).{
833 WireFormatcxx . . $ mlspp/WireFormat#::mls_private_messagecxx . . $ mlspp/WireFormat#mls_private_message.,
834 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content),
835 stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(auth),
836 } } };
837 }
838
839 PrivateMessagecxx . . $ mlspp/PrivateMessage#::PrivateMessagecxx . . $ mlspp/PrivateMessage#PrivateMessage(22a646458d5d0229).(GroupContentcxx . . $ mlspp/GroupContent# content,
840 bytescxx . . $ mlspp/bytes_ns/bytes# encrypted_sender_data_in,
841 bytescxx . . $ mlspp/bytes_ns/bytes# ciphertext_in)
842 : group_idcxx . . $ mlspp/PrivateMessage#group_id.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content.group_idcxx . . $ mlspp/GroupContent#group_id.))
843 , epochcxx . . $ mlspp/PrivateMessage#epoch.(content.epochcxx . . $ mlspp/GroupContent#epoch.)
844 , content_typecxx . . $ mlspp/PrivateMessage#content_type.(content.content_typecxx . . $ mlspp/GroupContent#content_type(911b27f74c945772).())
845 , authenticated_datacxx . . $ mlspp/PrivateMessage#authenticated_data.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(content.authenticated_datacxx . . $ mlspp/GroupContent#authenticated_data.))
846 , encrypted_sender_datacxx . . $ mlspp/PrivateMessage#encrypted_sender_data.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(encrypted_sender_data_in))
847 , ciphertextcxx . . $ mlspp/PrivateMessage#ciphertext.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(ciphertext_in))
848 {
849 }
850
851 bytescxx . . $ mlspp/bytes_ns/bytes#
852 MLSMessagecxx . . $ mlspp/MLSMessage#::group_idcxx . . $ mlspp/MLSMessage#group_id(d7392ba79aa35767).() const
853 {
854 return var::visitcxx . . $ std/visit(9828ab07ec69b3d0).(
855 overloaded{
856 [](const PublicMessagecxx . . $ mlspp/PublicMessage#& pt) -> bytescxx . . $ mlspp/bytes_ns/bytes# { return pt.get_group_idcxx . . $ mlspp/PublicMessage#get_group_id(d7392ba79aa35767).(); },
857 [](const PrivateMessagecxx . . $ mlspp/PrivateMessage#& ct) -> bytescxx . . $ mlspp/bytes_ns/bytes# { return ct.get_group_idcxx . . $ mlspp/PrivateMessage#get_group_id(d7392ba79aa35767).(); },
858 [](const GroupInfocxx . . $ mlspp/GroupInfo#& gi) -> bytescxx . . $ mlspp/bytes_ns/bytes# { return gicxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..group_contextcxx . . $ mlspp/GroupInfo#group_context..group_idcxx . . $ mlspp/GroupContext#group_id.; },
859 [](const auto& /* unused */) -> bytescxx . . $ mlspp/bytes_ns/bytes# {
860 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("MLSMessage has no group_id");
861 },
862 },
863 messagecxx . . $ mlspp/MLSMessage#message.);
864 }
865
866 epoch_tcxx . . $ mlspp/epoch_t#
867 MLSMessagecxx . . $ mlspp/MLSMessage#::epochcxx . . $ mlspp/MLSMessage#epoch(fe4d2d262d4164a8).() const
868 {
869 return var::visitcxx . . $ std/visit(9828ab07ec69b3d0).(
870 overloaded{
871 [](const PublicMessagecxx . . $ mlspp/PublicMessage#& pt) -> epoch_tcxx . . $ mlspp/epoch_t# { return pt.get_epochcxx . . $ mlspp/PublicMessage#get_epoch(fe4d2d262d4164a8).(); },
872 [](const PrivateMessagecxx . . $ mlspp/PrivateMessage#& pt) -> epoch_tcxx . . $ mlspp/epoch_t# { return pt.get_epochcxx . . $ mlspp/PrivateMessage#get_epoch(fe4d2d262d4164a8).(); },
873 [](const auto& /* unused */) -> epoch_tcxx . . $ mlspp/epoch_t# {
874 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("MLSMessage has no epoch");
875 },
876 },
877 messagecxx . . $ mlspp/MLSMessage#message.);
878 }
879
880 WireFormatcxx . . $ mlspp/WireFormat#
881 MLSMessagecxx . . $ mlspp/MLSMessage#::wire_formatcxx . . $ mlspp/MLSMessage#wire_format(6821ab1531194d4c).() const
882 {
883 return tlscxx . . $ mlspp/tls/::variantcxx . . $ mlspp/tls/variant#<WireFormat>::typecxx . . $ mlspp/tls/variant#type(b7fd53df2f44de88).(messagecxx . . $ mlspp/MLSMessage#message.);
884 }
885
886 MLSMessagecxx . . $ mlspp/MLSMessage#::MLSMessagecxx . . $ mlspp/MLSMessage#MLSMessage(efba1c00b0eccae9).(PublicMessagecxx . . $ mlspp/PublicMessage# public_message)
887 : messagecxx . . $ mlspp/MLSMessage#message.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(public_message))
888 {
889 }
890
891 MLSMessagecxx . . $ mlspp/MLSMessage#::MLSMessagecxx . . $ mlspp/MLSMessage#MLSMessage(305115f184887e4c).(PrivateMessagecxx . . $ mlspp/PrivateMessage# private_message)
892 : messagecxx . . $ mlspp/MLSMessage#message.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(private_message))
893 {
894 }
895
896 MLSMessagecxx . . $ mlspp/MLSMessage#::MLSMessagecxx . . $ mlspp/MLSMessage#MLSMessage(aeaf1eb64702ea21).(Welcomecxx . . $ mlspp/Welcome# welcome)
897 : messagecxx . . $ mlspp/MLSMessage#message.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(welcome))
898 {
899 }
900
901 MLSMessagecxx . . $ mlspp/MLSMessage#::MLSMessagecxx . . $ mlspp/MLSMessage#MLSMessage(56b4a303122a185a).(GroupInfocxx . . $ mlspp/GroupInfo# group_info)
902 : messagecxx . . $ mlspp/MLSMessage#message.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(group_info))
903 {
904 }
905
906 MLSMessagecxx . . $ mlspp/MLSMessage#::MLSMessagecxx . . $ mlspp/MLSMessage#MLSMessage(559025088f3cfff9).(KeyPackagecxx . . $ mlspp/KeyPackage# key_package)
907 : messagecxx . . $ mlspp/MLSMessage#message.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(key_package))
908 {
909 }
910
911 MLSMessagecxx . . $ mlspp/MLSMessage#
912 external_proposalcxx . . $ mlspp/external_proposal(fa83ef3fa85544c0).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
913 const bytescxx . . $ mlspp/bytes_ns/bytes#& group_id,
914 epoch_tcxx . . $ mlspp/epoch_t# epoch,
915 const Proposalcxx . . $ mlspp/Proposal#& proposal,
916 uint32_tcxx . . $ uint32_t# signer_index,
917 const SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#& sig_priv)
918 {
919 switch (proposal.proposal_typecxx . . $ mlspp/Proposal#proposal_type(72085aa11f4b6e09).()) {
920 // These proposal types are OK
921 case ProposalTypecxx . . $ mlspp/ProposalType#::addcxx . . $ mlspp/ProposalType#add.:
922 case ProposalTypecxx . . $ mlspp/ProposalType#::removecxx . . $ mlspp/ProposalType#remove.:
923 case ProposalTypecxx . . $ mlspp/ProposalType#::pskcxx . . $ mlspp/ProposalType#psk.:
924 case ProposalTypecxx . . $ mlspp/ProposalType#::reinitcxx . . $ mlspp/ProposalType#reinit.:
925 case ProposalTypecxx . . $ mlspp/ProposalType#::group_context_extensionscxx . . $ mlspp/ProposalType#group_context_extensions.:
926 break;
927
928 // These proposal types are forbidden
929 case ProposalTypecxx . . $ mlspp/ProposalType#::invalidcxx . . $ mlspp/ProposalType#invalid.:
930 case ProposalTypecxx . . $ mlspp/ProposalType#::updatecxx . . $ mlspp/ProposalType#update.:
931 case ProposalTypecxx . . $ mlspp/ProposalType#::external_initcxx . . $ mlspp/ProposalType#external_init.:
932 default:
933 throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("External proposal has invalid type");
934 }
935
936 auto content = GroupContentcxx . . $ mlspp/GroupContent#GroupContent(f5f370ed8cd561bf).{ group_idcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).,
937 epoch,
938 { ExternalSenderIndexcxx . . $ mlspp/ExternalSenderIndex#{ signer_index } },
939 {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d). /* no authenticated data */ },
940 {cxx . . $ std/variant#variant(5ba8255a4607184). proposal } };
941 auto content_auth = AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#::signcxx . . $ mlspp/AuthenticatedContent#sign(6554afcb5b84419).(
942 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).});
943
944 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).});
945 }
946
947 } // namespace mlspp