| 1 | #cxx . . $ `<file>/mlspp/src/key_schedule.cpp`/include <mls/key_schedule.h>cxx . . $ `<file>/mlspp/include/mls/key_schedule.h`/ |
| 2 | |
| 3 | namespace mlsppcxx . . $ mlspp/ { |
| 4 | |
| 5 | /// |
| 6 | /// Key Derivation Functions |
| 7 | /// |
| 8 | |
| 9 | struct TreeContextcxx . . $ mlspp/TreeContext# |
| 10 | { |
| 11 | NodeIndexcxx . . $ mlspp/NodeIndex# nodecxx . . $ mlspp/TreeContext#node.; |
| 12 | uint32_tcxx . . $ uint32_t# generationcxx . . $ mlspp/TreeContext#generation. = 0; |
| 13 | |
| 14 | TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(node, generation) |
| 15 | }; |
| 16 | |
| 17 | /// |
| 18 | /// HashRatchet |
| 19 | /// |
| 20 | |
| 21 | HashRatchetcxx . . $ mlspp/HashRatchet#::HashRatchetcxx . . $ mlspp/HashRatchet#HashRatchet(69bc69b11a84d9c3).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, bytescxx . . $ mlspp/bytes_ns/bytes# base_secret_in) |
| 22 | : suitecxx . . $ mlspp/HashRatchet#suite.(suite_in) |
| 23 | , next_secretcxx . . $ mlspp/HashRatchet#next_secret.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(base_secret_in)) |
| 24 | , next_generationcxx . . $ mlspp/HashRatchet#next_generation.(0) |
| 25 | , key_sizecxx . . $ mlspp/HashRatchet#key_size.(suitecxx . . $ mlspp/HashRatchet#suite..hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..key_sizecxx . . $ mlspp/hpke/AEAD#key_size.) |
| 26 | , nonce_sizecxx . . $ mlspp/HashRatchet#nonce_size.(suitecxx . . $ mlspp/HashRatchet#suite..hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..nonce_sizecxx . . $ mlspp/hpke/AEAD#nonce_size.) |
| 27 | , secret_sizecxx . . $ mlspp/HashRatchet#secret_size.(suitecxx . . $ mlspp/HashRatchet#suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | stdcxx . . $ std/::tuplecxx . . $ std/tuple#<uint32_tcxx . . $ uint32_t#, KeyAndNoncecxx . . $ mlspp/KeyAndNonce#> |
| 32 | HashRatchetcxx . . $ mlspp/HashRatchet#::nextcxx . . $ mlspp/HashRatchet#next(e4908337947e37ad).() |
| 33 | { |
| 34 | auto generation = next_generationcxx . . $ mlspp/HashRatchet#next_generation.; |
| 35 | auto key = suitecxx . . $ mlspp/HashRatchet#suite..derive_tree_secretcxx . . $ mlspp/CipherSuite#derive_tree_secret(bad54adf3f284450).(next_secretcxx . . $ mlspp/HashRatchet#next_secret., "key"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., generation, key_sizecxx . . $ mlspp/HashRatchet#key_size.); |
| 36 | auto nonce = |
| 37 | suitecxx . . $ mlspp/HashRatchet#suite..derive_tree_secretcxx . . $ mlspp/CipherSuite#derive_tree_secret(bad54adf3f284450).(next_secretcxx . . $ mlspp/HashRatchet#next_secret., "nonce"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., generation, nonce_sizecxx . . $ mlspp/HashRatchet#nonce_size.); |
| 38 | auto secret = |
| 39 | suitecxx . . $ mlspp/HashRatchet#suite..derive_tree_secretcxx . . $ mlspp/CipherSuite#derive_tree_secret(bad54adf3f284450).(next_secretcxx . . $ mlspp/HashRatchet#next_secret., "secret"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., generation, secret_sizecxx . . $ mlspp/HashRatchet#secret_size.); |
| 40 | |
| 41 | next_generationcxx . . $ mlspp/HashRatchet#next_generation. += 1; |
| 42 | next_secretcxx . . $ mlspp/HashRatchet#next_secret. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(89adb9997e4a49c). secret; |
| 43 | |
| 44 | cachecxx . . $ mlspp/HashRatchet#cache.[cxx . . $ std/map#`operator[]`(bbd415b616967878).generation] =cxx . . $ mlspp/KeyAndNonce#`operator=`(70f844572061e3c7). { key, nonce }; |
| 45 | return {cxx . . $ std/tuple#tuple(533e79eb6234819d). generation, cachecxx . . $ mlspp/HashRatchet#cache..atcxx . . $ std/map#at(bbd415b616967878).(generation) }; |
| 46 | } |
| 47 | |
| 48 | // Note: This construction deliberately does not preserve the forward-secrecy |
| 49 | // invariant, in that keys/nonces are not deleted after they are used. |
| 50 | // Otherwise, it would not be possible for a node to send to itself. Keys can |
| 51 | // be deleted once they are not needed by calling HashRatchet::erase(). |
| 52 | KeyAndNoncecxx . . $ mlspp/KeyAndNonce# |
| 53 | HashRatchetcxx . . $ mlspp/HashRatchet#::getcxx . . $ mlspp/HashRatchet#get(6b3d961c32b85bc7).(uint32_tcxx . . $ uint32_t# generation) |
| 54 | { |
| 55 | if (cachecxx . . $ mlspp/HashRatchet#cache..countcxx . . $ std/map#count(ea780b5adf43227).(generation) > 0) { |
| 56 | auto out = cachecxx . . $ mlspp/HashRatchet#cache..atcxx . . $ std/map#at(bbd415b616967878).(generation); |
| 57 | return out; |
| 58 | } |
| 59 | |
| 60 | if (next_generationcxx . . $ mlspp/HashRatchet#next_generation. > generation) { |
| 61 | throw ProtocolErrorcxx . . $ mlspp/ProtocolError#("Request for expired key"); |
| 62 | } |
| 63 | |
| 64 | while (next_generationcxx . . $ mlspp/HashRatchet#next_generation. <= generation) { |
| 65 | nextcxx . . $ mlspp/HashRatchet#next(e4908337947e37ad).(); |
| 66 | } |
| 67 | |
| 68 | return cachecxx . . $ mlspp/HashRatchet#cache..atcxx . . $ std/map#at(bbd415b616967878).(generation); |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | HashRatchetcxx . . $ mlspp/HashRatchet#::erasecxx . . $ mlspp/HashRatchet#erase(cb2f890c2fdad230).(uint32_tcxx . . $ uint32_t# generation) |
| 73 | { |
| 74 | if (cachecxx . . $ mlspp/HashRatchet#cache..countcxx . . $ std/map#count(ea780b5adf43227).(generation) == 0) { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | cachecxx . . $ mlspp/HashRatchet#cache..erasecxx . . $ std/map#erase(a7de169f3ef4bfb3).(generation); |
| 79 | } |
| 80 | |
| 81 | /// |
| 82 | /// SecretTree |
| 83 | /// |
| 84 | |
| 85 | SecretTreecxx . . $ mlspp/SecretTree#::SecretTreecxx . . $ mlspp/SecretTree#SecretTree(b16addc4ae0f84c9).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, |
| 86 | LeafCountcxx . . $ mlspp/LeafCount# group_size_in, |
| 87 | bytescxx . . $ mlspp/bytes_ns/bytes# encryption_secret_in) |
| 88 | : suitecxx . . $ mlspp/SecretTree#suite.(suite_in) |
| 89 | , group_sizecxx . . $ mlspp/SecretTree#group_size.(LeafCountcxx . . $ mlspp/LeafCount#::fullcxx . . $ mlspp/LeafCount#full(1e5797729f614563).(group_size_in)) |
| 90 | , rootcxx . . $ mlspp/SecretTree#root.(NodeIndexcxx . . $ mlspp/NodeIndex#::rootcxx . . $ mlspp/NodeIndex#root(f0a39db46e675ba1).(group_sizecxx . . $ mlspp/SecretTree#group_size.)) |
| 91 | , secret_sizecxx . . $ mlspp/SecretTree#secret_size.(suite_in.secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()) |
| 92 | { |
| 93 | secretscxx . . $ mlspp/SecretTree#secrets..emplacecxx . . $ std/map#emplace(58eea87a368e5c96).(rootcxx . . $ mlspp/SecretTree#root., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(encryption_secret_in)); |
| 94 | } |
| 95 | |
| 96 | bytescxx . . $ mlspp/bytes_ns/bytes# |
| 97 | SecretTreecxx . . $ mlspp/SecretTree#::getcxx . . $ mlspp/SecretTree#get(a1b9d39d51a01b86).(LeafIndexcxx . . $ mlspp/LeafIndex# sender) |
| 98 | { |
| 99 | static const auto context_left = from_asciicxx . . $ mlspp/bytes_ns/from_ascii(fc01d114001b7256).("left"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 100 | static const auto context_right = from_asciicxx . . $ mlspp/bytes_ns/from_ascii(fc01d114001b7256).("right"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 101 | auto node = NodeIndexcxx . . $ mlspp/NodeIndex#NodeIndex(5a3d3cee3fdf86fc).(sender); |
| 102 | |
| 103 | // Find an ancestor that is populated |
| 104 | auto dirpath = node.dirpathcxx . . $ mlspp/NodeIndex#dirpath(41abe7a05f92e8bb).(group_sizecxx . . $ mlspp/SecretTree#group_size.); |
| 105 | dirpath.insertcxx . . $ std/vector#insert(e54735f7c99f2c9d).(dirpathcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..begincxx . . $ std/vector#begin(55a6de06420d4903).(), node); |
| 106 | dirpath.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(rootcxx . . $ mlspp/SecretTree#root.); |
| 107 | uint32_tcxx . . $ uint32_t# curr = 0; |
| 108 | for (; curr < dirpath.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++curr) { |
| 109 | auto i = dirpath.atcxx . . $ std/vector#at(428bb168810b9e52).(curr); |
| 110 | if (secretscxx . . $ mlspp/SecretTree#secrets..countcxx . . $ std/map#count(ea780b5adf43227).(i) > 0) { |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if (curr > dirpath.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) { |
| 116 | throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("No secret found to derive base key"); |
| 117 | } |
| 118 | |
| 119 | // Derive down |
| 120 | for (; curr > 0; --curr) { |
| 121 | auto curr_node = dirpath.atcxx . . $ std/vector#at(428bb168810b9e52).(curr); |
| 122 | auto left = curr_node.leftcxx . . $ mlspp/NodeIndex#left(d66767722381bbc7).(); |
| 123 | auto right = curr_node.rightcxx . . $ mlspp/NodeIndex#right(d66767722381bbc7).(); |
| 124 | |
| 125 | auto& secret = secretscxx . . $ mlspp/SecretTree#secrets..atcxx . . $ std/map#at(bbd415b616967878).(curr_node); |
| 126 | |
| 127 | const auto left_secret = |
| 128 | suitecxx . . $ mlspp/SecretTree#suite..expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(secret, "tree"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., context_left, secret_sizecxx . . $ mlspp/SecretTree#secret_size.); |
| 129 | const auto right_secret = |
| 130 | suitecxx . . $ mlspp/SecretTree#suite..expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(secret, "tree"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., context_right, secret_sizecxx . . $ mlspp/SecretTree#secret_size.); |
| 131 | |
| 132 | secretscxx . . $ mlspp/SecretTree#secrets..insert_or_assigncxx . . $ std/map#insert_or_assign(a356f559b7c7a273).(left, left_secret); |
| 133 | secretscxx . . $ mlspp/SecretTree#secrets..insert_or_assigncxx . . $ std/map#insert_or_assign(a356f559b7c7a273).(right, right_secret); |
| 134 | } |
| 135 | |
| 136 | // Copy the leaf |
| 137 | auto out = secretscxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)..atcxx . . $ std/map#at(bbd415b616967878).(node); |
| 138 | |
| 139 | // Zeroize along the direct path |
| 140 | for (auto i : dirpath) { |
| 141 | secretscxx . . $ mlspp/SecretTree#secrets..erasecxx . . $ std/map#erase(a7de169f3ef4bfb3).(i); |
| 142 | } |
| 143 | |
| 144 | return outcxx . . $ mlspp/bytes_ns/bytes#bytes(628b76f52f2a67f).; |
| 145 | } |
| 146 | |
| 147 | /// |
| 148 | /// ReuseGuard |
| 149 | /// |
| 150 | |
| 151 | static ReuseGuardcxx . . $ mlspp/ReuseGuard# |
| 152 | new_reuse_guardcxx . . $ mlspp/new_reuse_guard(ead6513d56dda5ea).() |
| 153 | { |
| 154 | auto random = random_bytescxx . . $ mlspp/random_bytes(b7161179e0ed6f95).(4); |
| 155 | auto guard = ReuseGuardcxx . . $ mlspp/ReuseGuard#(); |
| 156 | stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(random.begincxx . . $ mlspp/bytes_ns/bytes#begin(2f4f6d8a0f75beb2).(), random.endcxx . . $ mlspp/bytes_ns/bytes#end(2f4f6d8a0f75beb2).(), guard.begincxx . . $ std/array#begin(258ee1c9e0a18a5c).()); |
| 157 | return guard; |
| 158 | } |
| 159 | |
| 160 | static void |
| 161 | apply_reuse_guardcxx . . $ mlspp/apply_reuse_guard(f83932657fca80ea).(const ReuseGuardcxx . . $ mlspp/ReuseGuard#& guard, bytescxx . . $ mlspp/bytes_ns/bytes#& nonce) |
| 162 | { |
| 163 | for (size_t i = 0; i < guard.sizecxx . . $ std/array#size(c9b1e749b64d5edc).(); i++) { |
| 164 | nonce.atcxx . . $ mlspp/bytes_ns/bytes#at(b19923e35e3d04d7).(i) ^= guard.atcxx . . $ std/array#at(b741b238679282eb).(i); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /// |
| 169 | /// GroupKeySource |
| 170 | /// |
| 171 | |
| 172 | GroupKeySourcecxx . . $ mlspp/GroupKeySource#::GroupKeySourcecxx . . $ mlspp/GroupKeySource#GroupKeySource(b16addc4ae0f84c9).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, |
| 173 | LeafCountcxx . . $ mlspp/LeafCount# group_size, |
| 174 | bytescxx . . $ mlspp/bytes_ns/bytes# encryption_secret) |
| 175 | : suitecxx . . $ mlspp/GroupKeySource#suite.(suite_in) |
| 176 | , secret_treecxx . . $ mlspp/GroupKeySource#secret_tree.(suitecxx . . $ mlspp/GroupKeySource#suite., group_size, stdcxx . . $ mlspp/bytes_ns/bytes#bytes(628b76f52f2a67f).::movecxx . . $ std/move(e35c19a1ba7baa26).(encryption_secret)) |
| 177 | { |
| 178 | } |
| 179 | |
| 180 | HashRatchetcxx . . $ mlspp/HashRatchet#& |
| 181 | GroupKeySourcecxx . . $ mlspp/GroupKeySource#::chaincxx . . $ mlspp/GroupKeySource#chain(459e588c614e4c15).(ContentTypecxx . . $ mlspp/ContentType# type, LeafIndexcxx . . $ mlspp/LeafIndex# sender) |
| 182 | { |
| 183 | switch (type) { |
| 184 | case ContentTypecxx . . $ mlspp/ContentType#::proposalcxx . . $ mlspp/ContentType#proposal.: |
| 185 | case ContentTypecxx . . $ mlspp/ContentType#::commitcxx . . $ mlspp/ContentType#commit.: |
| 186 | return chaincxx . . $ mlspp/GroupKeySource#chain(78835417b4c098a5).(RatchetTypecxx . . $ mlspp/GroupKeySource#RatchetType#::handshakecxx . . $ mlspp/GroupKeySource#RatchetType#handshake., sender); |
| 187 | |
| 188 | case ContentTypecxx . . $ mlspp/ContentType#::applicationcxx . . $ mlspp/ContentType#application.: |
| 189 | return chaincxx . . $ mlspp/GroupKeySource#chain(78835417b4c098a5).(RatchetTypecxx . . $ mlspp/GroupKeySource#RatchetType#::applicationcxx . . $ mlspp/GroupKeySource#RatchetType#application., sender); |
| 190 | |
| 191 | default: |
| 192 | throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Invalid content type"); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | HashRatchetcxx . . $ mlspp/HashRatchet#& |
| 197 | GroupKeySourcecxx . . $ mlspp/GroupKeySource#::chaincxx . . $ mlspp/GroupKeySource#chain(78835417b4c098a5).(RatchetTypecxx . . $ mlspp/GroupKeySource#RatchetType# type, LeafIndexcxx . . $ mlspp/LeafIndex# sender) |
| 198 | { |
| 199 | auto key = Keycxx . . $ std/tuple#tuple(533e79eb6234819d).{ type, sender }; |
| 200 | if (chainscxx . . $ mlspp/GroupKeySource#chains..countcxx . . $ std/map#count(ea780b5adf43227).(key) > 0) { |
| 201 | return chainscxx . . $ mlspp/GroupKeySource#chains.[cxx . . $ std/map#`operator[]`(bbd415b616967878).key]; |
| 202 | } |
| 203 | |
| 204 | auto secret_size = suitecxx . . $ mlspp/GroupKeySource#suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).(); |
| 205 | auto leaf_secret = secret_treecxx . . $ mlspp/GroupKeySource#secret_tree..getcxx . . $ mlspp/SecretTree#get(a1b9d39d51a01b86).(sender); |
| 206 | |
| 207 | auto handshake_secret = |
| 208 | suitecxx . . $ mlspp/GroupKeySource#suite..expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(leaf_secret, "handshake"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, secret_size); |
| 209 | auto application_secret = |
| 210 | suitecxx . . $ mlspp/GroupKeySource#suite..expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(leaf_secret, "application"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, secret_size); |
| 211 | |
| 212 | chainscxx . . $ mlspp/GroupKeySource#chains..emplacecxx . . $ std/map#emplace(58eea87a368e5c96).(Keycxx . . $ std/tuple#tuple(533e79eb6234819d).{ RatchetTypecxx . . $ mlspp/GroupKeySource#RatchetType#::handshakecxx . . $ mlspp/GroupKeySource#RatchetType#handshake., sender }, |
| 213 | HashRatchetcxx . . $ mlspp/HashRatchet#HashRatchet(69bc69b11a84d9c3).{ suitecxx . . $ mlspp/GroupKeySource#suite., handshake_secretcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). }); |
| 214 | chainscxx . . $ mlspp/GroupKeySource#chains..emplacecxx . . $ std/map#emplace(58eea87a368e5c96).(Keycxx . . $ std/tuple#tuple(533e79eb6234819d).{ RatchetTypecxx . . $ mlspp/GroupKeySource#RatchetType#::applicationcxx . . $ mlspp/GroupKeySource#RatchetType#application., sender }, |
| 215 | HashRatchetcxx . . $ mlspp/HashRatchet#HashRatchet(69bc69b11a84d9c3).{ suitecxx . . $ mlspp/GroupKeySource#suite., application_secretcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). }); |
| 216 | |
| 217 | return chainscxx . . $ mlspp/GroupKeySource#chains.[cxx . . $ std/map#`operator[]`(bbd415b616967878).key]; |
| 218 | } |
| 219 | |
| 220 | stdcxx . . $ std/::tuplecxx . . $ std/tuple#<uint32_tcxx . . $ uint32_t#, ReuseGuardcxx . . $ mlspp/ReuseGuard#, KeyAndNoncecxx . . $ mlspp/KeyAndNonce#> |
| 221 | GroupKeySourcecxx . . $ mlspp/GroupKeySource#::nextcxx . . $ mlspp/GroupKeySource#next(93009b092b6559de).(ContentTypecxx . . $ mlspp/ContentType# type, LeafIndexcxx . . $ mlspp/LeafIndex# sender) |
| 222 | { |
| 223 | auto [generation, keys] = chaincxx . . $ mlspp/GroupKeySource#chain(459e588c614e4c15).(type, sender).nextcxx . . $ mlspp/HashRatchet#next(e4908337947e37ad).(); |
| 224 | |
| 225 | auto reuse_guard = new_reuse_guardcxx . . $ mlspp/new_reuse_guard(ead6513d56dda5ea).(); |
| 226 | apply_reuse_guardcxx . . $ mlspp/apply_reuse_guard(f83932657fca80ea).(reuse_guard, keys.noncecxx . . $ mlspp/KeyAndNonce#nonce.); |
| 227 | |
| 228 | return {cxx . . $ std/tuple#tuple(302f34f1d6e23d4f). generation, reuse_guard, keys }; |
| 229 | } |
| 230 | |
| 231 | KeyAndNoncecxx . . $ mlspp/KeyAndNonce# |
| 232 | GroupKeySourcecxx . . $ mlspp/GroupKeySource#::getcxx . . $ mlspp/GroupKeySource#get(b7daedcd7d3908ca).(ContentTypecxx . . $ mlspp/ContentType# type, |
| 233 | LeafIndexcxx . . $ mlspp/LeafIndex# sender, |
| 234 | uint32_tcxx . . $ uint32_t# generation, |
| 235 | ReuseGuardcxx . . $ mlspp/ReuseGuard# reuse_guard) |
| 236 | { |
| 237 | auto keys = chaincxx . . $ mlspp/GroupKeySource#chain(459e588c614e4c15).(type, sender).getcxx . . $ mlspp/HashRatchet#get(6b3d961c32b85bc7).(generation); |
| 238 | apply_reuse_guardcxx . . $ mlspp/apply_reuse_guard(f83932657fca80ea).(reuse_guard, keys.noncecxx . . $ mlspp/KeyAndNonce#nonce.); |
| 239 | return keys; |
| 240 | } |
| 241 | |
| 242 | void |
| 243 | GroupKeySourcecxx . . $ mlspp/GroupKeySource#::erasecxx . . $ mlspp/GroupKeySource#erase(efc0287f6c9543eb).(ContentTypecxx . . $ mlspp/ContentType# type, LeafIndexcxx . . $ mlspp/LeafIndex# sender, uint32_tcxx . . $ uint32_t# generation) |
| 244 | { |
| 245 | return chaincxx . . $ mlspp/GroupKeySource#chain(459e588c614e4c15).(type, sender).erasecxx . . $ mlspp/HashRatchet#erase(cb2f890c2fdad230).(generation); |
| 246 | } |
| 247 | |
| 248 | // struct { |
| 249 | // opaque group_id<0..255>; |
| 250 | // uint64 epoch; |
| 251 | // ContentType content_type; |
| 252 | // opaque authenticated_data<0..2^32-1>; |
| 253 | // } ContentAAD; |
| 254 | struct ContentAADcxx . . $ mlspp/ContentAAD# |
| 255 | { |
| 256 | const bytescxx . . $ mlspp/bytes_ns/bytes#& group_idcxx . . $ mlspp/ContentAAD#group_id.; |
| 257 | const epoch_tcxx . . $ mlspp/epoch_t# epochcxx . . $ mlspp/ContentAAD#epoch.; |
| 258 | const ContentTypecxx . . $ mlspp/ContentType# content_typecxx . . $ mlspp/ContentAAD#content_type.; |
| 259 | const bytescxx . . $ mlspp/bytes_ns/bytes#& authenticated_datacxx . . $ mlspp/ContentAAD#authenticated_data.; |
| 260 | |
| 261 | TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(group_id, epoch, content_type, authenticated_data) |
| 262 | }; |
| 263 | |
| 264 | /// |
| 265 | /// KeyScheduleEpoch |
| 266 | /// |
| 267 | |
| 268 | struct PSKLabelcxx . . $ mlspp/PSKLabel# |
| 269 | { |
| 270 | const PreSharedKeyIDcxx . . $ mlspp/PreSharedKeyID#& idcxx . . $ mlspp/PSKLabel#id.; |
| 271 | uint16_tcxx . . $ uint16_t# indexcxx . . $ mlspp/PSKLabel#index.; |
| 272 | uint16_tcxx . . $ uint16_t# countcxx . . $ mlspp/PSKLabel#count.; |
| 273 | |
| 274 | TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(id, index, count); |
| 275 | }; |
| 276 | |
| 277 | static bytescxx . . $ mlspp/bytes_ns/bytes# |
| 278 | make_joiner_secretcxx . . $ mlspp/make_joiner_secret(65c9fefbdfe65777).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, |
| 279 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context, |
| 280 | const bytescxx . . $ mlspp/bytes_ns/bytes#& init_secret, |
| 281 | const bytescxx . . $ mlspp/bytes_ns/bytes#& commit_secret) |
| 282 | { |
| 283 | auto pre_joiner_secret = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kdfcxx . . $ mlspp/hpke/HPKE#kdf..extractcxx . . $ mlspp/hpke/KDF#extract(802fe03ef4f7e693).(init_secret, commit_secret); |
| 284 | return suite.expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).( |
| 285 | pre_joiner_secret, "joiner"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., context, suite.secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()); |
| 286 | } |
| 287 | |
| 288 | static bytescxx . . $ mlspp/bytes_ns/bytes# |
| 289 | make_epoch_secretcxx . . $ mlspp/make_epoch_secret(65c9fefbdfe65777).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, |
| 290 | const bytescxx . . $ mlspp/bytes_ns/bytes#& joiner_secret, |
| 291 | const bytescxx . . $ mlspp/bytes_ns/bytes#& psk_secret, |
| 292 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context) |
| 293 | { |
| 294 | auto member_secret = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kdfcxx . . $ mlspp/hpke/HPKE#kdf..extractcxx . . $ mlspp/hpke/KDF#extract(802fe03ef4f7e693).(joiner_secret, psk_secret); |
| 295 | return suite.expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).( |
| 296 | member_secret, "epoch"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., context, suite.secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()); |
| 297 | } |
| 298 | |
| 299 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch# |
| 300 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::joinercxx . . $ mlspp/KeyScheduleEpoch#joiner(25b4bb31cd83193c).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, |
| 301 | const bytescxx . . $ mlspp/bytes_ns/bytes#& joiner_secret, |
| 302 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>& psks, |
| 303 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context) |
| 304 | { |
| 305 | return {cxx . . $ mlspp/KeyScheduleEpoch#KeyScheduleEpoch(9ca0faf22fb2ce09). suite_in, joiner_secret, make_psk_secretcxx . . $ mlspp/KeyScheduleEpoch#make_psk_secret(1d3bdec8dd887667).(suite_in, psks), context }; |
| 306 | } |
| 307 | |
| 308 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#KeyScheduleEpoch(9ca0faf22fb2ce09).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, |
| 309 | const bytescxx . . $ mlspp/bytes_ns/bytes#& joiner_secret, |
| 310 | const bytescxx . . $ mlspp/bytes_ns/bytes#& psk_secret, |
| 311 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context) |
| 312 | : suitecxx . . $ mlspp/KeyScheduleEpoch#suite.(suite_in) |
| 313 | , joiner_secretcxx . . $ mlspp/KeyScheduleEpoch#joiner_secret.(joiner_secret) |
| 314 | , epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret.( |
| 315 | make_epoch_secretcxx . . $ mlspp/make_epoch_secret(65c9fefbdfe65777).(suite_in, joiner_secret, psk_secret, context)) |
| 316 | , sender_data_secretcxx . . $ mlspp/KeyScheduleEpoch#sender_data_secret.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "sender data"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 317 | , encryption_secretcxx . . $ mlspp/KeyScheduleEpoch#encryption_secret.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "encryption"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 318 | , exporter_secretcxx . . $ mlspp/KeyScheduleEpoch#exporter_secret.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "exporter"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 319 | , epoch_authenticatorcxx . . $ mlspp/KeyScheduleEpoch#epoch_authenticator.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "authentication"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 320 | , external_secretcxx . . $ mlspp/KeyScheduleEpoch#external_secret.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "external"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 321 | , confirmation_keycxx . . $ mlspp/KeyScheduleEpoch#confirmation_key.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "confirm"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 322 | , membership_keycxx . . $ mlspp/KeyScheduleEpoch#membership_key.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "membership"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 323 | , resumption_pskcxx . . $ mlspp/KeyScheduleEpoch#resumption_psk.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "resumption"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 324 | , init_secretcxx . . $ mlspp/KeyScheduleEpoch#init_secret.(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret., "init"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 325 | , external_privcxx . . $ mlspp/KeyScheduleEpoch#external_priv.(HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#::derivecxx . . $ mlspp/HPKEPrivateKey#derive(d8fbf663c4028288).(suitecxx . . $ mlspp/KeyScheduleEpoch#suite., external_secretcxx . . $ mlspp/KeyScheduleEpoch#external_secret.)) |
| 326 | { |
| 327 | } |
| 328 | |
| 329 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#KeyScheduleEpoch(1ae84ca71f879861).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in) |
| 330 | : suitecxx . . $ mlspp/KeyScheduleEpoch#suite.(suite_in) |
| 331 | { |
| 332 | } |
| 333 | |
| 334 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#KeyScheduleEpoch(e9b6b1168c720405).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, |
| 335 | const bytescxx . . $ mlspp/bytes_ns/bytes#& init_secret, |
| 336 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context) |
| 337 | : KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#( |
| 338 | suite_in, |
| 339 | make_joiner_secretcxx . . $ mlspp/make_joiner_secret(65c9fefbdfe65777).(suite_in, context, init_secret, suite_in.zerocxx . . $ mlspp/CipherSuite#zero(d7392ba79aa35767).()), |
| 340 | {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d). /* no PSKs */ }, |
| 341 | context) |
| 342 | { |
| 343 | } |
| 344 | |
| 345 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#KeyScheduleEpoch(381fa99b4ceb7e56).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, |
| 346 | const bytescxx . . $ mlspp/bytes_ns/bytes#& init_secret, |
| 347 | const bytescxx . . $ mlspp/bytes_ns/bytes#& commit_secret, |
| 348 | const bytescxx . . $ mlspp/bytes_ns/bytes#& psk_secret, |
| 349 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context) |
| 350 | : KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#( |
| 351 | suite_in, |
| 352 | make_joiner_secretcxx . . $ mlspp/make_joiner_secret(65c9fefbdfe65777).(suite_in, context, init_secret, commit_secret), |
| 353 | psk_secret, |
| 354 | context) |
| 355 | { |
| 356 | } |
| 357 | |
| 358 | stdcxx . . $ std/::tuplecxx . . $ std/tuple#<bytescxx . . $ mlspp/bytes_ns/bytes#, bytescxx . . $ mlspp/bytes_ns/bytes#> |
| 359 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::external_initcxx . . $ mlspp/KeyScheduleEpoch#external_init(d332d7d6e9cedbfc).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, |
| 360 | const HPKEPublicKeycxx . . $ mlspp/HPKEPublicKey#& external_pub) |
| 361 | { |
| 362 | auto size = suite.secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).(); |
| 363 | return external_pub.do_exportcxx . . $ mlspp/HPKEPublicKey#do_export(10426ae6d3f47ac5).( |
| 364 | suite, {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, "MLS 1.0 external init secret"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., size); |
| 365 | } |
| 366 | |
| 367 | bytescxx . . $ mlspp/bytes_ns/bytes# |
| 368 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::receive_external_initcxx . . $ mlspp/KeyScheduleEpoch#receive_external_init(c5e1b85e16e94921).(const bytescxx . . $ mlspp/bytes_ns/bytes#& kem_output) const |
| 369 | { |
| 370 | auto size = suitecxx . . $ mlspp/KeyScheduleEpoch#suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).(); |
| 371 | return external_privcxx . . $ mlspp/KeyScheduleEpoch#external_priv..do_exportcxx . . $ mlspp/HPKEPrivateKey#do_export(7d96ce105d93ef47).( |
| 372 | suitecxx . . $ mlspp/KeyScheduleEpoch#suite., {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, kem_output, "MLS 1.0 external init secret"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., size); |
| 373 | } |
| 374 | |
| 375 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch# |
| 376 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::nextcxx . . $ mlspp/KeyScheduleEpoch#next(5d822d0102bcfbee).(const bytescxx . . $ mlspp/bytes_ns/bytes#& commit_secret, |
| 377 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>& psks, |
| 378 | const stdcxx . . $ std/::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>& force_init_secret, |
| 379 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context) const |
| 380 | { |
| 381 | return next_rawcxx . . $ mlspp/KeyScheduleEpoch#next_raw(4425c67f05643958).( |
| 382 | commit_secret, make_psk_secretcxx . . $ mlspp/KeyScheduleEpoch#make_psk_secret(1d3bdec8dd887667).(suitecxx . . $ mlspp/KeyScheduleEpoch#suite., psks), force_init_secret, context); |
| 383 | } |
| 384 | |
| 385 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch# |
| 386 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::next_rawcxx . . $ mlspp/KeyScheduleEpoch#next_raw(4425c67f05643958).(const bytescxx . . $ mlspp/bytes_ns/bytes#& commit_secret, |
| 387 | const bytescxx . . $ mlspp/bytes_ns/bytes#& psk_secret, |
| 388 | const stdcxx . . $ std/::optionalcxx . . $ std/optional#<bytescxx . . $ mlspp/bytes_ns/bytes#>& force_init_secret, |
| 389 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context) const |
| 390 | { |
| 391 | auto actual_init_secret = init_secretcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).; |
| 392 | if (force_init_secret) { |
| 393 | actual_init_secret =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(89adb9997e4a49c). opt::getcxx . . $ mlspp/tls/opt/get(3a846ed22d48625).(force_init_secret); |
| 394 | } |
| 395 | |
| 396 | return {cxx . . $ mlspp/KeyScheduleEpoch#KeyScheduleEpoch(381fa99b4ceb7e56). suitecxx . . $ mlspp/KeyScheduleEpoch#suite., actual_init_secret, commit_secret, psk_secret, context }; |
| 397 | } |
| 398 | |
| 399 | GroupKeySourcecxx . . $ mlspp/GroupKeySource# |
| 400 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::encryption_keyscxx . . $ mlspp/KeyScheduleEpoch#encryption_keys(578ffb7a4920202).(LeafCountcxx . . $ mlspp/LeafCount# size) const |
| 401 | { |
| 402 | return {cxx . . $ mlspp/GroupKeySource#GroupKeySource(b16addc4ae0f84c9). suitecxx . . $ mlspp/KeyScheduleEpoch#suite., size, encryption_secretcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). }; |
| 403 | } |
| 404 | |
| 405 | bytescxx . . $ mlspp/bytes_ns/bytes# |
| 406 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::confirmation_tagcxx . . $ mlspp/KeyScheduleEpoch#confirmation_tag(c5e1b85e16e94921).(const bytescxx . . $ mlspp/bytes_ns/bytes#& confirmed_transcript_hash) const |
| 407 | { |
| 408 | return suitecxx . . $ mlspp/KeyScheduleEpoch#suite..digestcxx . . $ mlspp/CipherSuite#digest(cdb80d7d9b9bc276).().hmaccxx . . $ mlspp/hpke/Digest#hmac(802fe03ef4f7e693).(confirmation_keycxx . . $ mlspp/KeyScheduleEpoch#confirmation_key., confirmed_transcript_hash); |
| 409 | } |
| 410 | |
| 411 | bytescxx . . $ mlspp/bytes_ns/bytes# |
| 412 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::do_exportcxx . . $ mlspp/KeyScheduleEpoch#do_export(7012e37337977242).(const stdcxx . . $ std/::stringcxx . . $ std/string#& label, |
| 413 | const bytescxx . . $ mlspp/bytes_ns/bytes#& context, |
| 414 | size_t size) const |
| 415 | { |
| 416 | auto secret = suitecxx . . $ mlspp/KeyScheduleEpoch#suite..derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(exporter_secretcxx . . $ mlspp/KeyScheduleEpoch#exporter_secret., label); |
| 417 | auto context_hash = suitecxx . . $ mlspp/KeyScheduleEpoch#suite..digestcxx . . $ mlspp/CipherSuite#digest(cdb80d7d9b9bc276).().hashcxx . . $ mlspp/hpke/Digest#hash(c5e1b85e16e94921).(context); |
| 418 | return suitecxx . . $ mlspp/KeyScheduleEpoch#suite..expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(secret, "exported"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., context_hash, size); |
| 419 | } |
| 420 | |
| 421 | PSKWithSecretcxx . . $ mlspp/PSKWithSecret# |
| 422 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::resumption_psk_w_secretcxx . . $ mlspp/KeyScheduleEpoch#resumption_psk_w_secret(1919b725acead621).(ResumptionPSKUsagecxx . . $ mlspp/ResumptionPSKUsage# usage, |
| 423 | const bytescxx . . $ mlspp/bytes_ns/bytes#& group_id, |
| 424 | epoch_tcxx . . $ mlspp/epoch_t# epoch) |
| 425 | { |
| 426 | auto nonce = random_bytescxx . . $ mlspp/random_bytes(b7161179e0ed6f95).(suitecxx . . $ mlspp/KeyScheduleEpoch#suite..secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()); |
| 427 | auto psk = ResumptionPSKcxx . . $ mlspp/ResumptionPSK#{ usage, group_id, epoch }; |
| 428 | return { { psk, nonce }, resumption_pskcxx . . $ mlspp/KeyScheduleEpoch#resumption_psk. }; |
| 429 | } |
| 430 | |
| 431 | bytescxx . . $ mlspp/bytes_ns/bytes# |
| 432 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::make_psk_secretcxx . . $ mlspp/KeyScheduleEpoch#make_psk_secret(1d3bdec8dd887667).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, |
| 433 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>& psks) |
| 434 | { |
| 435 | auto psk_secret = suite.zerocxx . . $ mlspp/CipherSuite#zero(d7392ba79aa35767).(); |
| 436 | auto count = uint16_tcxx . . $ uint16_t#(psks.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()); |
| 437 | auto index = uint16_tcxx . . $ uint16_t#(0); |
| 438 | for (const auto& psk : psks) { |
| 439 | auto psk_extracted = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kdfcxx . . $ mlspp/hpke/HPKE#kdf..extractcxx . . $ mlspp/hpke/KDF#extract(802fe03ef4f7e693).(suite.zerocxx . . $ mlspp/CipherSuite#zero(d7392ba79aa35767).(), psk.secretcxx . . $ mlspp/PSKWithSecret#secret.); |
| 440 | auto psk_label = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(PSKLabelcxx . . $ mlspp/PSKLabel#{ psk.idcxx . . $ mlspp/PSKWithSecret#id., index, count }); |
| 441 | auto psk_input = suite.expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).( |
| 442 | psk_extracted, "derived psk"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., psk_labelcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)., suite.secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).()); |
| 443 | psk_secret =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kdfcxx . . $ mlspp/hpke/HPKE#kdf..extractcxx . . $ mlspp/hpke/KDF#extract(802fe03ef4f7e693).(psk_input, psk_secret); |
| 444 | index += 1; |
| 445 | } |
| 446 | return psk_secretcxx . . $ mlspp/bytes_ns/bytes#bytes(628b76f52f2a67f).; |
| 447 | } |
| 448 | |
| 449 | bytescxx . . $ mlspp/bytes_ns/bytes# |
| 450 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::welcome_secretcxx . . $ mlspp/KeyScheduleEpoch#welcome_secret(e5f3c7282c3439d1).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, |
| 451 | const bytescxx . . $ mlspp/bytes_ns/bytes#& joiner_secret, |
| 452 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<PSKWithSecretcxx . . $ mlspp/PSKWithSecret#>& psks) |
| 453 | { |
| 454 | auto psk_secret = make_psk_secretcxx . . $ mlspp/KeyScheduleEpoch#make_psk_secret(1d3bdec8dd887667).(suite, psks); |
| 455 | return welcome_secret_rawcxx . . $ mlspp/KeyScheduleEpoch#welcome_secret_raw(e67fb899a8b6167f).(suite, joiner_secret, psk_secret); |
| 456 | } |
| 457 | |
| 458 | bytescxx . . $ mlspp/bytes_ns/bytes# |
| 459 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::welcome_secret_rawcxx . . $ mlspp/KeyScheduleEpoch#welcome_secret_raw(e67fb899a8b6167f).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, |
| 460 | const bytescxx . . $ mlspp/bytes_ns/bytes#& joiner_secret, |
| 461 | const bytescxx . . $ mlspp/bytes_ns/bytes#& psk_secret) |
| 462 | { |
| 463 | auto extract = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kdfcxx . . $ mlspp/hpke/HPKE#kdf..extractcxx . . $ mlspp/hpke/KDF#extract(802fe03ef4f7e693).(joiner_secret, psk_secret); |
| 464 | return suite.derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(extract, "welcome"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 465 | } |
| 466 | |
| 467 | KeyAndNoncecxx . . $ mlspp/KeyAndNonce# |
| 468 | KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#::sender_data_keyscxx . . $ mlspp/KeyScheduleEpoch#sender_data_keys(65fe22caf18b2b69).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, |
| 469 | const bytescxx . . $ mlspp/bytes_ns/bytes#& sender_data_secret, |
| 470 | const bytescxx . . $ mlspp/bytes_ns/bytes#& ciphertext) |
| 471 | { |
| 472 | auto sample_size = suite.secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).(); |
| 473 | auto sample = bytescxx . . $ mlspp/bytes_ns/bytes#(sample_size); |
| 474 | if (ciphertext.sizecxx . . $ mlspp/bytes_ns/bytes#size(fe4d2d262d4164a8).() <= sample_size) { |
| 475 | sample =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(89adb9997e4a49c). ciphertext; |
| 476 | } else { |
| 477 | sample =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). ciphertext.slicecxx . . $ mlspp/bytes_ns/bytes#slice(ef0b1008b63e00ff).(0, sample_size); |
| 478 | } |
| 479 | |
| 480 | auto key_size = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..key_sizecxx . . $ mlspp/hpke/AEAD#key_size.; |
| 481 | auto nonce_size = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().aeadcxx . . $ mlspp/hpke/HPKE#aead..nonce_sizecxx . . $ mlspp/hpke/AEAD#nonce_size.; |
| 482 | return { |
| 483 | suite.expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(sender_data_secret, "key"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., sample, key_size), |
| 484 | suite.expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(sender_data_secret, "nonce"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., sample, nonce_size), |
| 485 | }; |
| 486 | } |
| 487 | |
| 488 | bool |
| 489 | operatorcxx . . $ mlspp/`operator==`(9649cf35f662b0fb).==(const KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#& lhs, const KeyScheduleEpochcxx . . $ mlspp/KeyScheduleEpoch#& rhs) |
| 490 | { |
| 491 | auto epoch_secret = (lhs.epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.epoch_secretcxx . . $ mlspp/KeyScheduleEpoch#epoch_secret.); |
| 492 | auto sender_data_secret = (lhs.sender_data_secretcxx . . $ mlspp/KeyScheduleEpoch#sender_data_secret. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.sender_data_secretcxx . . $ mlspp/KeyScheduleEpoch#sender_data_secret.); |
| 493 | auto encryption_secret = (lhs.encryption_secretcxx . . $ mlspp/KeyScheduleEpoch#encryption_secret. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.encryption_secretcxx . . $ mlspp/KeyScheduleEpoch#encryption_secret.); |
| 494 | auto exporter_secret = (lhs.exporter_secretcxx . . $ mlspp/KeyScheduleEpoch#exporter_secret. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.exporter_secretcxx . . $ mlspp/KeyScheduleEpoch#exporter_secret.); |
| 495 | auto confirmation_key = (lhs.confirmation_keycxx . . $ mlspp/KeyScheduleEpoch#confirmation_key. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.confirmation_keycxx . . $ mlspp/KeyScheduleEpoch#confirmation_key.); |
| 496 | auto init_secret = (lhs.init_secretcxx . . $ mlspp/KeyScheduleEpoch#init_secret. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.init_secretcxx . . $ mlspp/KeyScheduleEpoch#init_secret.); |
| 497 | auto external_priv = (lhs.external_privcxx . . $ mlspp/KeyScheduleEpoch#external_priv. ==cxx . . $ mlspp/`operator==`(5401d31d8ac0aee4). rhs.external_privcxx . . $ mlspp/KeyScheduleEpoch#external_priv.); |
| 498 | |
| 499 | return epoch_secret && sender_data_secret && encryption_secret && |
| 500 | exporter_secret && confirmation_key && init_secret && external_priv; |
| 501 | } |
| 502 | |
| 503 | // struct { |
| 504 | // WireFormat wire_format; |
| 505 | // GroupContent content; // with content.content_type == commit |
| 506 | // opaque signature<V>; |
| 507 | // } ConfirmedTranscriptHashInput; |
| 508 | struct ConfirmedTranscriptHashInputcxx . . $ mlspp/ConfirmedTranscriptHashInput# |
| 509 | { |
| 510 | WireFormatcxx . . $ mlspp/WireFormat# wire_formatcxx . . $ mlspp/ConfirmedTranscriptHashInput#wire_format.; |
| 511 | const GroupContentcxx . . $ mlspp/GroupContent#& contentcxx . . $ mlspp/ConfirmedTranscriptHashInput#content.; |
| 512 | const bytescxx . . $ mlspp/bytes_ns/bytes#& signaturecxx . . $ mlspp/ConfirmedTranscriptHashInput#signature.; |
| 513 | |
| 514 | TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(wire_format, content, signature) |
| 515 | }; |
| 516 | |
| 517 | // struct { |
| 518 | // MAC confirmation_tag; |
| 519 | // } InterimTranscriptHashInput; |
| 520 | struct InterimTranscriptHashInputcxx . . $ mlspp/InterimTranscriptHashInput# |
| 521 | { |
| 522 | bytescxx . . $ mlspp/bytes_ns/bytes# confirmation_tagcxx . . $ mlspp/InterimTranscriptHashInput#confirmation_tag.; |
| 523 | |
| 524 | TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(confirmation_tag) |
| 525 | }; |
| 526 | |
| 527 | TranscriptHashcxx . . $ mlspp/TranscriptHash#::TranscriptHashcxx . . $ mlspp/TranscriptHash#TranscriptHash(1ae84ca71f879861).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in) |
| 528 | : suitecxx . . $ mlspp/TranscriptHash#suite.(suite_in) |
| 529 | { |
| 530 | } |
| 531 | |
| 532 | TranscriptHashcxx . . $ mlspp/TranscriptHash#::TranscriptHashcxx . . $ mlspp/TranscriptHash#TranscriptHash(7bb436d88e17613d).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, |
| 533 | bytescxx . . $ mlspp/bytes_ns/bytes# confirmed_in, |
| 534 | const bytescxx . . $ mlspp/bytes_ns/bytes#& confirmation_tag) |
| 535 | : suitecxx . . $ mlspp/TranscriptHash#suite.(suite_in) |
| 536 | , confirmedcxx . . $ mlspp/TranscriptHash#confirmed.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(confirmed_in)) |
| 537 | { |
| 538 | update_interimcxx . . $ mlspp/TranscriptHash#update_interim(68ca607eebb5be3e).(confirmation_tag); |
| 539 | } |
| 540 | |
| 541 | void |
| 542 | TranscriptHashcxx . . $ mlspp/TranscriptHash#::updatecxx . . $ mlspp/TranscriptHash#update(15c3fae94687094).(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) |
| 543 | { |
| 544 | update_confirmedcxx . . $ mlspp/TranscriptHash#update_confirmed(15c3fae94687094).(content_auth); |
| 545 | update_interimcxx . . $ mlspp/TranscriptHash#update_interim(15c3fae94687094).(content_auth); |
| 546 | } |
| 547 | |
| 548 | void |
| 549 | TranscriptHashcxx . . $ mlspp/TranscriptHash#::update_confirmedcxx . . $ mlspp/TranscriptHash#update_confirmed(15c3fae94687094).(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) |
| 550 | { |
| 551 | const auto transcript = |
| 552 | interimcxx . . $ mlspp/TranscriptHash#interim. +cxx . . $ mlspp/bytes_ns/bytes#operator+(c5e1b85e16e94921). content_auth.confirmed_transcript_hash_inputcxx . . $ mlspp/AuthenticatedContent#confirmed_transcript_hash_input(d7392ba79aa35767).(); |
| 553 | confirmedcxx . . $ mlspp/TranscriptHash#confirmed. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). suitecxx . . $ mlspp/TranscriptHash#suite..digestcxx . . $ mlspp/CipherSuite#digest(cdb80d7d9b9bc276).().hashcxx . . $ mlspp/hpke/Digest#hash(c5e1b85e16e94921).(transcript); |
| 554 | } |
| 555 | |
| 556 | void |
| 557 | TranscriptHashcxx . . $ mlspp/TranscriptHash#::update_interimcxx . . $ mlspp/TranscriptHash#update_interim(68ca607eebb5be3e).(const bytescxx . . $ mlspp/bytes_ns/bytes#& confirmation_tag) |
| 558 | { |
| 559 | const auto transcript = confirmedcxx . . $ mlspp/TranscriptHash#confirmed. +cxx . . $ mlspp/bytes_ns/bytes#operator+(c5e1b85e16e94921). tlscxx . . $ mlspp/bytes_ns/bytes#bytes(dd8c33c7e39dbe02).::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(confirmation_tag); |
| 560 | interimcxx . . $ mlspp/TranscriptHash#interim. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). suitecxx . . $ mlspp/TranscriptHash#suite..digestcxx . . $ mlspp/CipherSuite#digest(cdb80d7d9b9bc276).().hashcxx . . $ mlspp/hpke/Digest#hash(c5e1b85e16e94921).(transcript); |
| 561 | } |
| 562 | |
| 563 | void |
| 564 | TranscriptHashcxx . . $ mlspp/TranscriptHash#::update_interimcxx . . $ mlspp/TranscriptHash#update_interim(15c3fae94687094).(const AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#& content_auth) |
| 565 | { |
| 566 | const auto transcript = |
| 567 | confirmedcxx . . $ mlspp/TranscriptHash#confirmed. +cxx . . $ mlspp/bytes_ns/bytes#operator+(c5e1b85e16e94921). content_auth.interim_transcript_hash_inputcxx . . $ mlspp/AuthenticatedContent#interim_transcript_hash_input(d7392ba79aa35767).(); |
| 568 | interimcxx . . $ mlspp/TranscriptHash#interim. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). suitecxx . . $ mlspp/TranscriptHash#suite..digestcxx . . $ mlspp/CipherSuite#digest(cdb80d7d9b9bc276).().hashcxx . . $ mlspp/hpke/Digest#hash(c5e1b85e16e94921).(transcript); |
| 569 | } |
| 570 | |
| 571 | bool |
| 572 | operatorcxx . . $ mlspp/`operator==`(476a4c82fd602b31).==(const TranscriptHashcxx . . $ mlspp/TranscriptHash#& lhs, const TranscriptHashcxx . . $ mlspp/TranscriptHash#& rhs) |
| 573 | { |
| 574 | auto confirmed = (lhs.confirmedcxx . . $ mlspp/TranscriptHash#confirmed. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.confirmedcxx . . $ mlspp/TranscriptHash#confirmed.); |
| 575 | auto interim = (lhs.interimcxx . . $ mlspp/TranscriptHash#interim. ==cxx . . $ mlspp/bytes_ns/bytes#`operator==`(efd4f3c976ab92ce). rhs.interimcxx . . $ mlspp/TranscriptHash#interim.); |
| 576 | return confirmed && interim; |
| 577 | } |
| 578 | |
| 579 | } // namespace mlspp |