draft-schanzen-cake.xml (65438B)
1 <?xml version='1.0' encoding='utf-8'?> 2 <!DOCTYPE rfc [ 3 <!ENTITY RFC1034 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.1034.xml"> 4 <!ENTITY RFC1035 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.1035.xml"> 5 <!ENTITY RFC1928 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.1928.xml"> 6 <!ENTITY RFC2119 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"> 7 <!--<!ENTITY RFC2693 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2693.xml">--> 8 <!ENTITY RFC2782 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2782.xml"> 9 <!ENTITY RFC3629 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3629.xml"> 10 <!ENTITY RFC3686 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3686.xml"> 11 <!ENTITY RFC3826 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3826.xml"> 12 <!ENTITY RFC4033 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4033.xml"> 13 <!ENTITY RFC5237 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5237.xml"> 14 <!--<!ENTITY RFC3912 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3912.xml">--> 15 <!ENTITY RFC5869 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5869.xml"> 16 <!ENTITY RFC5890 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5890.xml"> 17 <!ENTITY RFC5895 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5895.xml"> 18 <!ENTITY RFC6066 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6066.xml"> 19 <!ENTITY RFC6761 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6761.xml"> 20 <!ENTITY RFC6895 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6895.xml"> 21 <!ENTITY RFC6979 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6979.xml"> 22 <!ENTITY RFC7363 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7363.xml"> 23 <!ENTITY RFC8806 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8806.xml"> 24 <!ENTITY RFC7748 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7748.xml"> 25 <!ENTITY RFC8126 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8126.xml"> 26 <!ENTITY RFC8174 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8174.xml"> 27 <!ENTITY RFC8244 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8244.xml"> 28 <!ENTITY RFC8324 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8324.xml"> 29 <!ENTITY RFC8439 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8439.xml"> 30 <!ENTITY RFC8446 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8446.xml"> 31 <!ENTITY RFC8499 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8499.xml"> 32 <!ENTITY RFC9106 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9106.xml"> 33 <!ENTITY RFC9147 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9147.xml"> 34 <!ENTITY RFC9180 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9180.xml"> 35 <!ENTITY RFC8032 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8032.xml"> 36 <!ENTITY RFC9001 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9001.xml"> 37 <!ENTITY RFC2104 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2104.xml"> 38 <!ENTITY RFC6234 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6234.xml"> 39 <!ENTITY I-D.ietf-dnsop-alt-tld PUBLIC '' "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-dnsop-alt-tld.xml"> 40 ]> 41 <?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?> 42 <?rfc strict="yes" ?> 43 <?rfc toc="yes" ?> 44 <?rfc symrefs="yes"?> 45 <?rfc sortrefs="yes" ?> 46 <?rfc compact="yes" ?> 47 <?rfc subcompact="no" ?> 48 <rfc xmlns:xi="http://www.w3.org/2001/XInclude" 49 category="info" 50 docName="draft-schanzen-cake-00" 51 ipr="trust200902" 52 obsoletes="" updates="" 53 submissionType="independent" 54 xml:lang="en" 55 version="3"> 56 <!-- xml2rfc v2v3 conversion 2.26.0 --> 57 <front> 58 <title abbrev="CORE Authenticated Key Exchange (CAKE)"> 59 CORE Authenticated Key Exchange (CAKE) 60 </title> 61 <seriesInfo name="Internet-Draft" value="draft-schanzen-cake-00"/> 62 <author fullname="Martin Schanzenbach" initials="M." surname="Schanzenbach"> 63 <organization>Fraunhofer AISEC</organization> 64 <address> 65 <postal> 66 <street>Lichtenbergstrasse 11</street> 67 <city>Garching</city> 68 <code>85748</code> 69 <country>DE</country> 70 </postal> 71 <email>martin.schanzenbach@aisec.fraunhofer.de</email> 72 </address> 73 </author> 74 <author fullname="ch3" initials="" surname="ch3"> 75 <organization>GNUnet e.V.</organization> 76 <address> 77 <postal> 78 <street></street> 79 <city>Lenggries</city> 80 <code></code> 81 <country>DE</country> 82 </postal> 83 <email>ch3@mailbox.org</email> 84 </address> 85 </author> 86 <!-- Meta-data Declarations --> 87 <area>General</area> 88 <workgroup>Independent Stream</workgroup> 89 <keyword>transport protocols</keyword> 90 <abstract> 91 <t> 92 This document contains the GNUnet CORE AKE (CAKE): a signed 93 ephemeral key exchange -- regular DTLS 1.3 with raw Ed25519 public 94 keys -- using the key schedule of TLS 1.3 and the handshake state 95 machine of DTLS 1.3. 96 </t> 97 <t> 98 This document defines the normative wire format of the protocol, 99 cryptographic routines and security 100 considerations for use by implementers. 101 </t> 102 <t> 103 This specification was developed outside the IETF and does not have 104 IETF consensus. It is published here to inform readers about the 105 function of GNUnet CORE, guide future implementations, and ensure 106 interoperability among implementations. 107 </t> 108 </abstract> 109 </front> 110 <middle> 111 <section anchor="introduction" numbered="true" toc="default"> 112 <name>Introduction</name> 113 <t> 114 This specification was developed outside the IETF and does not have 115 IETF consensus. It is published here to guide implementers of the 116 GNUnet CORE service and to ensure interoperability among 117 implementations. 118 </t> 119 <section numbered="true" toc="default"> 120 <name>Requirements Notation</name> 121 <t> 122 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 123 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 124 "OPTIONAL" in this document are to be interpreted as described in 125 BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only 126 when, they appear in all capitals, as shown here. 127 </t> 128 </section> 129 </section> 130 <section anchor="terminology"> 131 <name>Conventions and Terminology</name> 132 <t> 133 While some of the terminology is explicitly re-defined here, the reader is expected 134 to be familiar with TLS 1.3 (<xref target="RFC8446"/>), DTLS 1.3 (<xref target="RFC9147"/>) and 135 Ed25519 (<xref target="RFC8032"/>). 136 </t> 137 <dl> 138 <dt>initiator:</dt><dd>See client in <xref target="RFC9147"/> Section 2.</dd> 139 <dt>responder:</dt><dd>See server in <xref target="RFC9147"/> Section 2.</dd> 140 <dt>epoch:</dt><dd>See <xref target="RFC9147"/> Section 2.</dd> 141 <dt>ES:</dt> <dd>Early Secret</dd> 142 <dt>HS:</dt> <dd>Handshake Secret</dd> 143 <dt>IHTS:</dt> <dd>Initiator Handshake Traffic Secret</dd> 144 <dt>RHTS:</dt> <dd>Responder Handshake Traffic Secret</dd> 145 <dt>MS:</dt> <dd>Master Secret</dd> 146 <dt>IATS<sub>N</sub>:</dt> <dd>Initiator Application Traffic Secret of epoch N</dd> 147 <dt>RATS<sub>N</sub>:</dt> <dd>Responder Application Traffic Secret of epoch N</dd> 148 <dt>DHE:</dt> <dd>The ephemeral X25519 shared secret of the handshake, see 149 <xref target="ecdh"/>. Computed once, from the two peers' 150 ephemeral keys.</dd> 151 <dt>H(D):</dt> <dd>SHA-256 <xref target="RFC6234"/> over D. Hash.length is 32.</dd> 152 <dt>HKDF-Extract(Salt, IKM), HKDF-Expand(PRK, Info, L):</dt> 153 <dd>The functions of <xref target="RFC5869"/>, instantiated with 154 SHA-256.</dd> 155 <dt>HMAC(K, D):</dt> <dd>HMAC <xref target="RFC2104"/> with SHA-256 over D.</dd> 156 <dt>HKDF-Expand-Label, Derive-Secret:</dt> 157 <dd>As in <xref target="RFC8446" section="7.1"/>, with the label 158 prefix of <xref target="crypto_label"/>.</dd> 159 <dt>Sign(sk, D), Verify(pk, sig, D):</dt> 160 <dd>Ed25519 signature and verification of D, see 161 <xref target="ed25519"/>. A signature is 64 bytes.</dd> 162 <dt>T(M):</dt> <dd>The transcript up to and including M, see 163 <xref target="transcript"/>. Transcript-Hash(M) is H(T(M)).</dd> 164 <dt>'{}K'</dt> <dd>indicates encryption with the handshake 165 traffic secret K, see <xref target="traffic_keys"/>.</dd> 166 <dt>'[]K'</dt> <dd>indicates a record protected with the 167 application traffic secret K, see <xref target="encrypted_message"/>.</dd> 168 </dl> 169 </section> 170 <section anchor="rationale" numbered="true" toc="default"> 171 <name>Design Rationale</name> 172 <t> 173 CAKE is a signed ephemeral key exchange -- regular DTLS 1.3 with raw 174 Ed25519 public keys -- carried by the handshake state machine of 175 DTLS 1.3 (<xref target="RFC9147" section="5"/>). Both peers know 176 each other's long-term public key in advance (the peer identity and 177 the <tt>HELLO</tt>), so neither carries a certificate: each signs 178 its ephemeral key with its long-term Ed25519 identity key, the 179 analogue of the CertificateVerify of TLS 1.3 180 (<xref target="RFC8446" section="4.4.3"/>). There is no KEM and 181 no 0-RTT. 182 </t> 183 <t> 184 CAKE takes from TLS 1.3 and DTLS 1.3: 185 </t> 186 <ul> 187 <li>The key schedule of <xref target="RFC8446" section="7.1"/>, 188 including HKDF-Expand-Label and Derive-Secret, with a single 189 (EC)DHE shared secret (DHE) as the input to the Handshake Secret 190 and zero (no PSK) as the inputs to the Early Secret and to the 191 Master Secret.</li> 192 <li>The transcript hash over the plaintext of the handshake 193 messages (<xref target="RFC8446" section="4.4.1"/>), see 194 <xref target="transcript"/>.</li> 195 <li>The traffic key calculation, the per-record nonce and the key 196 update (Sections 7.3, 5.3 and 7.2 of <xref target="RFC8446"/>).</li> 197 <li>The flights, timers and retransmissions of 198 <xref target="RFC9147" section="5.8"/>, including the ACK of the 199 initiator's final flight, and the handling of a new handshake on an 200 existing association of <xref target="RFC9147" section="5.11"/>.</li> 201 <li>Sequence number encryption (<xref target="RFC9147" section="4.2.3"/>) 202 and anti-replay (<xref target="RFC9147" section="4.5.1"/>).</li> 203 </ul> 204 <t> 205 CAKE has no use for most of the rest of (D)TLS and leaves it out: 206 version and cipher suite negotiation and the legacy fields that come 207 with them, extensions, HelloRetryRequest and cookies, PSK 208 resumption, 0-RTT and 0.5-RTT application data, alerts, connection 209 IDs, content types and padding. Fragmentation is provided by the 210 transport underlay of GNUnet. In addition, CAKE simplifies the 211 following: 212 </t> 213 <ul> 214 <li>The handshake consists of three messages, one per flight 215 (InitiatorHello, ResponderHello, InitiatorDone), each of which 216 packs what would be several TLS handshake messages.</li> 217 <li>Each handshake traffic secret protects one or two fields with 218 fixed sequence numbers, so the handshake needs no epochs and no 219 record headers. Epoch 0 of CAKE is the first application traffic 220 secret (epoch 3 in DTLS 1.3).</li> 221 <li>Records carry their 64-bit epoch and sequence number in full, so 222 neither needs to be reconstructed, and a peer can move to its next 223 epoch at any time without a KeyUpdate message. A Heartbeat 224 (<xref target="heartbeat_msg"/>) can ask the other peer to do so.</li> 225 <li>There is a single set of algorithms (<xref target="primitives"/>).</li> 226 </ul> 227 </section> 228 <section anchor="protocol_flow" numbered="true" toc="default"> 229 <name>Protocol Flow</name> 230 <t> 231 We assume that the peers have semi-static (as opposed to ephemeral) key pairs. Let (pk<sub>A</sub>,sk<sub>A</sub>) be the key pair of peer PID<sub>A</sub> and (pk<sub>B</sub>,sk<sub>B</sub>) the key pair of peer PID<sub>B</sub>. 232 </t> 233 <t> 234 For any secure handshake protocol, we have to determine an initiator and a responder in the protocol. 235 The peer whose identity has the smaller hash is the initiator I, the other one the responder R: 236 </t> 237 <sourcecode> 238 <![CDATA[ 239 if (H(pk_A) < H(pk_B)) 240 { 241 pk_I = pk_A 242 pk_R = pk_B 243 } 244 else 245 { 246 pk_I = pk_B 247 pk_R = pk_A 248 } 249 ]]> 250 </sourcecode> 251 <t> 252 Here pk<sub>A</sub> and pk<sub>B</sub> are the 32-byte Ed25519 253 public keys that are the peer identities, and the hashes are 254 compared as byte strings, that is, as unsigned big-endian 255 integers. 256 The responder never initiates a handshake; a peer that receives an 257 InitiatorHello from a peer that should be the responder discards 258 it. (See <xref target="open"/> for a fallback for designated 259 initiators that never initiate.) 260 We assume that the initiator knows pk<sub>R</sub> (pre-distributed through <tt>HELLO</tt>, for example). 261 </t> 262 <t> 263 Below is a swimlane of the protocol messages. 264 On the left and right side of the swimlanes the secrets known to the Initiator and Responder are 265 shown respectively. 266 If a private key of a key pair is known it is implied that the public key is also known. 267 Messages in braces are encrypted with a handshake traffic secret, 268 messages in brackets are records protected with an application 269 traffic secret. 270 </t> 271 <figure anchor="figure_swimlane" title="Overview over the Handshake Protocol Flow."> 272 <artwork name="" type="" align="left" alt=""><![CDATA[ 273 Initiator Responder 274 sk_I | | sk_R 275 pk_R | | 276 sk_e | | 277 | InitiatorHello: | 278 | r_I | 279 | pk_e | 280 | H(pk_R) | 281 +---------------------------------------------->| 282 | | pk_e (peer) 283 | | DHE 284 | ResponderHello: | 285 | r_R | 286 | pk_e | 287 | sig_R | 288 | {pc_R,svcinfo_R}RHTS | 289 | {finished_R}RHTS | 290 |<----------------------------------------------+ 291 DHE | | 292 | InitiatorDone: | 293 | sig_I | 294 | {finished_I}IHTS | 295 +---------------------------------------------->| 296 | | 297 | [ACK]RATS | 298 |<----------------------------------------------+ 299 | | 300 | [Application Payload] | 301 |<--------------------------------------------->| 302 | | 303 v v 304 ]]></artwork> 305 </figure> 306 <t> 307 As in DTLS 1.3, every flight but the last is implicitly 308 acknowledged by the next one: the InitiatorHello by the 309 ResponderHello, and the ResponderHello by the InitiatorDone. 310 The InitiatorDone, the initiator's final flight, is acknowledged 311 by the responder with an ACK record 312 (<xref target="RFC9147" section="5.8.1"/>). 313 pc<sub>X</sub> are 16 bit fields that indicate the peer class (FIXME peer class section). 314 r<sub>I</sub> and r<sub>R</sub> are 64-bit random nonces of the 315 initiator and of the responder. 316 </t> 317 <t> 318 The initiator creates the InitiatorHello message: 319 </t> 320 <ol> 321 <li>(sk<sub>e</sub>,pk<sub>e</sub>) <- GenerateKeyPair(). Ephemeral X25519 key pair.</li> 322 <li>r<sub>I</sub> <- RandomUInt64(). Initiator nonce.</li> 323 <li>H(pk<sub>R</sub>). The responder identity is known from the peer identity and the <tt>HELLO</tt>.</li> 324 </ol> 325 <t> 326 The InitiatorHello is sent in plaintext: with a signed ephemeral key 327 exchange there is no static secret to protect it with, and its 328 fields are not secret. R processes the InitiatorHello as follows: 329 </t> 330 <ol> 331 <li>Verify that the message type is CORE_INITIATOR_HELLO. See Message Header.</li> 332 <li>Verify that H(pk<sub>R</sub>) matches R's pk<sub>R</sub>.</li> 333 <li>(sk<sub>e</sub>,pk<sub>e</sub>) <- GenerateKeyPair(). R's ephemeral X25519 key pair.</li> 334 <li>DHE <- ECDH(sk<sub>e</sub>, pk<sub>e</sub>). Ephemeral shared secret, see <xref target="ecdh"/>.</li> 335 <li>Derive ES, HS, IHTS and RHTS (<xref target="key_schedule"/>).</li> 336 </ol> 337 <t> 338 Note that IATS<sub>0</sub> cannot be derived (yet) at this point. 339 R now generates its ResponderHello message: 340 </t> 341 <ol> 342 <li>r<sub>R</sub> <- RandomUInt64(). Responder nonce.</li> 343 <li>sig<sub>R</sub> <- Sign(sk<sub>R</sub>, context<sub>R</sub> || Transcript-Hash(T(pk<sub>e</sub>))). See <xref target="ed25519"/>.</li> 344 <li>Encrypt pc<sub>R</sub> and svcinfo<sub>R</sub> with RHTS (sequence number 0).</li> 345 <li>Create finished<sub>R</sub> as per <xref target="finished_field"/> 346 and encrypt it with RHTS (sequence number 1).</li> 347 <li>Derive RATS<sub>0</sub>.</li> 348 </ol> 349 <t> 350 I processes the ResponderHello: 351 </t> 352 <ol> 353 <li>Verify that the message type is CORE_RESPONDER_HELLO. See Message Header.</li> 354 <li>DHE <- ECDH(sk<sub>e</sub>, pk<sub>e</sub>). Ephemeral shared secret, see <xref target="ecdh"/>.</li> 355 <li>Derive HS, IHTS and RHTS and decrypt pc<sub>R</sub>, svcinfo<sub>R</sub> and finished<sub>R</sub>.</li> 356 <li>Verify sig<sub>R</sub> against pk<sub>R</sub> (the responder identity, as known from the transport) over Transcript-Hash(T(pk<sub>e</sub>)). See <xref target="ed25519"/>.</li> 357 <li>Verify finished<sub>R</sub> (<xref target="finished_field"/>).</li> 358 <li>Derive RATS<sub>0</sub>, create finished<sub>I</sub>, sign 359 sig<sub>I</sub> <- Sign(sk<sub>I</sub>, context<sub>I</sub> || Transcript-Hash(T(finished<sub>R</sub>))) and send 360 the InitiatorDone: finished<sub>I</sub> encrypted with IHTS 361 (sequence number 0).</li> 362 <li>Derive IATS<sub>0</sub>. I may now send records protected with IATS<sub>0</sub>.</li> 363 </ol> 364 <t> 365 R processes the InitiatorDone: it verifies sig<sub>I</sub> against 366 pk<sub>I</sub> (the initiator identity, as known from the transport) 367 over Transcript-Hash(T(finished<sub>R</sub>)), decrypts and verifies 368 finished<sub>I</sub>, derives IATS<sub>0</sub> and answers with an 369 ACK record protected with RATS<sub>0</sub>. At this point R has a 370 secure channel with I. I has one once it has received a 371 record that deprotects under RATS<sub>0</sub> (or a later 372 RATS<sub>N</sub>), normally that ACK. 373 </t> 374 <t> 375 The following rules are not optional. Each of them protects an 376 existing association against an attacker that can inject 377 messages: 378 </t> 379 <ul> 380 <li>A handshake message that fails any of the checks above, or 381 does not decrypt, MUST be discarded without changing any state; 382 in particular it MUST NOT stop the retransmission of the 383 receiver's own last flight.</li> 384 <li>R MUST NOT consider I authenticated, MUST NOT deliver any data 385 received from I, and MUST NOT protect any record with 386 RATS<sub>0</sub> before it has verified finished<sub>I</sub>. 387 (Hence the first record under RATS<sub>0</sub> confirms the 388 handshake to I.)</li> 389 <li>If R already has an association with I, it MUST continue to 390 use that association's traffic secrets for sending and receiving 391 until finished<sub>I</sub> of the new handshake has verified, 392 and MUST keep the association if the new handshake does not 393 complete (<xref target="RFC9147" section="5.11"/>).</li> 394 </ul> 395 <t> 396 Note that for the handshake we do not use epochs or sequence numbers on the wire. 397 The reason for this is simple: DTLS uses epoch 0 for plaintext messages, 398 and the InitiatorHello is plaintext (there is no ETS, and no 0-RTT). 399 Epoch 1 is reserved for payload encrypted with a key derived from *HTS. 400 But we only have a single message that contains a payload encrypted with a key 401 derived from RHTS: ResponderHello. 402 We also only have a single message that contains a payload encrypted with a key 403 derived from IHTS: InitiatorDone. 404 Consequently, we do not need any signalling of epochs until we encrypt data using 405 *ATS secrets, and the sequence numbers of the handshake fields are 406 fixed (RHTS: 0 and 1; IHTS: 0). 407 Records are wrapped inside an EncryptedMessage 408 (<xref target="encrypted_message"/>) and carry their epoch and 409 sequence number. In every epoch, the sequence numbers of a peer 410 start at 0. 411 </t> 412 </section> 413 <section anchor="key_schedule" numbered="true" toc="default"> 414 <name>Key Schedule</name> 415 <t> 416 The key schedule is that of <xref target="RFC8446" section="7.1"/>, 417 with a single ephemeral X25519 shared secret (DHE) as the only 418 non-zero input, as in TLS 1.3 without a PSK. As there, HKDF-Extract 419 is drawn as taking the Salt argument from the top and the IKM 420 argument from the left, its output is shown to the right, and "0" 421 is a string of Hash.length zero bytes: 422 </t> 423 <figure anchor="figure_key_schedule" title="The Key Schedule."> 424 <artwork name="" type="" align="left" alt=""><![CDATA[ 425 0 426 | 427 v 428 0 -> HKDF-Extract = Early Secret (ES) 429 | 430 v 431 Derive-Secret(., "derived", "") 432 | 433 v 434 DHE -> HKDF-Extract = Handshake Secret (HS) 435 | 436 +-----> Derive-Secret(., "i hs traffic", 437 | InitiatorHello...pk_e_R) 438 | = IHTS 439 | 440 +-----> Derive-Secret(., "r hs traffic", 441 | InitiatorHello...pk_e_R) 442 | = RHTS 443 v 444 Derive-Secret(., "derived", "") 445 | 446 v 447 0 -> HKDF-Extract = Master Secret (MS) 448 | 449 +-----> Derive-Secret(., "r ap traffic", 450 | InitiatorHello...ResponderHello) 451 | = RATS_0 452 | 453 +-----> Derive-Secret(., "i ap traffic", 454 InitiatorHello...InitiatorDone) 455 = IATS_0 456 ]]></artwork> 457 </figure> 458 <t> 459 As in <xref target="RFC8446"/>, Derive-Secret(Secret, Label, Messages) 460 is HKDF-Expand-Label(Secret, Label, Transcript-Hash(Messages), 461 Hash.length), and the context of "derived" is the hash of the 462 empty string. The transcripts are those of <xref target="transcript"/>: 463 "InitiatorHello...pk<sub>e</sub><sub>R</sub>" is T(pk<sub>e</sub><sub>R</sub>) 464 (both ephemeral keys declared), 465 "InitiatorHello...ResponderHello" is T(finished<sub>R</sub>), and 466 "InitiatorHello...InitiatorDone" is T(finished<sub>I</sub>). 467 </t> 468 <t> 469 The Early Secret and the Master Secret take zero IKM, since CAKE has 470 no PSK and no second KEM. The only secret input to the key schedule 471 is DHE, which provides forward secrecy; sk<sub>e</sub> MUST be fresh 472 for every handshake. The long-term identity keys do not enter the 473 key schedule: they authenticate the ephemeral keys through 474 sig<sub>R</sub> and sig<sub>I</sub> (<xref target="ed25519"/>), 475 and the Finished fields provide key confirmation. As in TLS 1.3, 476 each application traffic secret is derived from the transcript up to 477 its sender's Finished. 478 </t> 479 <section anchor="transcript" numbered="true" toc="default"> 480 <name>Transcript</name> 481 <t> 482 As in TLS 1.3 (<xref target="RFC8446" section="4.4.1"/>), the 483 transcript is made of the plaintext of the handshake messages, not 484 of the bytes on the wire. It is the concatenation of the 485 InitiatorHello, ResponderHello and InitiatorDone of the handshake, 486 each starting with its message header, with every encrypted field 487 in plaintext and without the AEAD tags. Everything else is as 488 sent, including the message headers, whose Size counts the tags. 489 T(X) is the transcript up to and including the field X: 490 </t> 491 <ul> 492 <li>T(pk<sub>e</sub><sub>R</sub>) is the InitiatorHello followed 493 by the ResponderHello up to and including the responder's 494 ephemeral key pk<sub>e</sub>. (The InitiatorHello is plaintext; 495 this is the point at which both ephemeral keys are on the 496 transcript.) Transcript-Hash of this is what sig<sub>R</sub> 497 signs and what *HTS are derived from.</li> 498 <li>T(sig<sub>R</sub>) is that plus the responder's signature 499 sig<sub>R</sub>.</li> 500 <li>T(svcinfo<sub>R</sub>) additionally includes pc<sub>R</sub> 501 and svcinfo<sub>R</sub>. Transcript-Hash of this is what 502 finished<sub>R</sub> covers.</li> 503 <li>T(finished<sub>R</sub>) is the InitiatorHello followed by 504 the ResponderHello (its full plaintext). Transcript-Hash of 505 this is what sig<sub>I</sub> signs.</li> 506 <li>T(sig<sub>I</sub>) is that plus the InitiatorDone up to and 507 including sig<sub>I</sub>. Transcript-Hash of this is what 508 finished<sub>I</sub> covers.</li> 509 <li>T(finished<sub>I</sub>) is the InitiatorHello followed by 510 the ResponderHello and the InitiatorDone (its full plaintext).</li> 511 </ul> 512 <t> 513 The peers thus confirm what they said, independently of how it was 514 protected on the wire, which is what the analysis of TLS 1.3 515 assumes. The Size fields delimit the messages and with them 516 the services infos, so the transcript needs no further framing. 517 Retransmissions are byte-identical copies and are not part of the 518 transcript. 519 </t> 520 </section> 521 <section anchor="traffic_keys" numbered="true" toc="default"> 522 <name>Traffic Keys and Key Updates</name> 523 <t> 524 When a traffic secret TS (IHTS, RHTS, IATS<sub>N</sub> or 525 RATS<sub>N</sub>) is used to encrypt data, the key and IV are 526 derived as in <xref target="RFC8446" section="7.3"/>: 527 </t> 528 <figure anchor="figure_traffic_key_derivation" title="Traffic Key Generation."> 529 <artwork name="" type="" align="left" alt=""><![CDATA[ 530 key = HKDF-Expand-Label(TS, "key", "", 32) 531 iv = HKDF-Expand-Label(TS, "iv", "", 24) 532 ]]></artwork> 533 </figure> 534 <t> 535 The per-record nonce is generated from the IV and the sequence 536 number as in <xref target="RFC8446" section="5.3"/>: the 537 64-bit sequence number in network byte order, left-padded with 538 zeros to 24 bytes, is XORed with the IV. 539 The AEAD is XChaCha20-Poly1305 (<xref target="primitives"/>), 540 with empty associated data. 541 Nothing is ever encrypted twice with the same key and nonce: 542 retransmitted handshake messages are byte-identical copies, not 543 re-encryptions. 544 </t> 545 <t> 546 After the handshake, both initiator and responder may 547 update their application traffic secrets and generate new keys, 548 as in <xref target="RFC8446" section="7.2"/>: 549 </t> 550 <figure anchor="figure_traffic_key_derivation_next" title="Traffic Secret Update."> 551 <artwork name="" type="" align="left" alt=""><![CDATA[ 552 [I,R]ATS_N+1 = HKDF-Expand-Label([I,R]ATS_N, "traffic upd", "", 553 Hash.length) 554 ]]></artwork> 555 </figure> 556 <t> 557 The index N is the epoch of <xref target="encrypted_message"/>. 558 A peer moves to its next epoch on its own accord (the GNUnet 559 implementation does so every 12 hours, and before its sequence 560 numbers are exhausted), or when asked to with a Heartbeat 561 (<xref target="heartbeat_msg"/>). The receiver learns about it 562 from the epoch of the records. Unlike in DTLS 1.3, there is no 563 KeyUpdate message to acknowledge, and the sender does not wait 564 before it uses its new keys: the full epoch is part of every 565 record, so the receiver can always tell which keys a record was 566 protected with. 567 Implementations <bcp14>SHOULD</bcp14> delete old traffic secrets and their derived keys. 568 </t> 569 </section> 570 </section> 571 <section anchor="cake_hs_proto" numbered="true" toc="default"> 572 <name>The CAKE Handshake Protocol</name> 573 <t> 574 This section is named and structured to mimic <xref target="RFC9147" section="5"/>. 575 </t> 576 <section anchor="timeout_retransmission" numbered="true" toc="default"> 577 <name>Timeout and Retransmission</name> 578 <t> 579 CAKE reuses the logic for timeout and retransmission from <xref target="RFC9147" section="5.8"/>. 580 It differs in that large flight sizes are not of concern for CAKE, 581 since each flight is a single message. The initiator retransmits 582 its InitiatorHello until it receives a ResponderHello that 583 verifies, and its InitiatorDone until it receives a record that 584 deprotects under the new RATS. The responder retransmits its 585 ResponderHello until it receives an InitiatorDone that verifies. 586 A peer that receives a retransmission of the flight it has 587 already answered retransmits its answer: the responder its 588 ResponderHello for a copy of the InitiatorHello it is answering, 589 the initiator its InitiatorDone for a copy of the ResponderHello 590 it has accepted, and the responder its ACK for an InitiatorDone 591 once the handshake is complete 592 (<xref target="RFC9147" section="5.8.1"/>). 593 </t> 594 <t> 595 The GNUnet implementation uses an initial timer of 1 second, 596 doubles it with each retransmission up to 60 seconds 597 (<xref target="RFC9147" section="5.8.2"/>), and gives up 598 on a flight after 5 retransmissions, starting over with a new 599 handshake. A responder that gives up on a handshake started over 600 an existing association keeps that association. 601 </t> 602 </section> 603 <section anchor="crypto_label" numbered="true" toc="default"> 604 <name>Cryptographic Label Prefix</name> 605 <t> 606 <xref target="RFC8446" section="7.1"/> specifies that HKDF-Expand-Label uses a label prefix of "tls13 ". 607 For CAKE, that label <bcp14>SHALL</bcp14> be "cake10". 608 This ensures key separation between CAKE, DTLS 1.3 and TLS 1.3. 609 As with the "dtls13" of <xref target="RFC9147" section="5.9"/>, 610 there is no trailing space; this keeps the overall label size 611 inside of one hash iteration. For clarity: 612 </t> 613 <figure anchor="figure_expand_label" title="HKDF-Expand-Label."> 614 <artwork name="" type="" align="left" alt=""><![CDATA[ 615 HKDF-Expand-Label(Secret, Label, Context, Length) = 616 HKDF-Expand(Secret, HkdfLabel, Length) 617 618 struct { 619 uint16 length = Length; 620 opaque label<7..255> = "cake10" + Label; 621 opaque context<0..255> = Context; 622 } HkdfLabel; 623 ]]></artwork> 624 </figure> 625 <t> 626 The labels CAKE uses are "derived", 627 "i hs traffic", "r hs traffic", "r ap traffic", "i ap traffic", 628 "r finished", "i finished", "key", "iv", "sn" and "traffic upd". 629 </t> 630 </section> 631 <section anchor="svcinfo" numbered="true" toc="default"> 632 <name>Services Info Field</name> 633 <t> 634 The svcinfo field is a string consisting of key-value pairs separated by 635 a separator indicating supported services and their versions. 636 E.g. "dht:1.1;cadet:0.4". 637 It extends to the end of the encrypted field it is in, and has 638 no terminator. It may be empty. 639 </t> 640 </section> 641 <section anchor="finished_field" numbered="true" toc="default"> 642 <name>Finished Field</name> 643 <t> 644 As in TLS 1.3 (<xref target="RFC8446" section="4.4.4"/>), the 645 finished keys are derived from the handshake traffic secrets, not 646 from MS. The signatures sig<sub>R</sub> and sig<sub>I</sub> 647 (<xref target="ed25519"/>) authenticate the peers; the Finished 648 fields provide key confirmation over the transcript: 649 </t> 650 <ol> 651 <li>fk<sub>R</sub> <- HKDF-Expand-Label(RHTS, "r finished", "", Hash.length)</li> 652 <li>finished<sub>R</sub> <- HMAC(fk<sub>R</sub>, Transcript-Hash(svcinfo<sub>R</sub>))</li> 653 </ol> 654 <ol> 655 <li>fk<sub>I</sub> <- HKDF-Expand-Label(IHTS, "i finished", "", Hash.length)</li> 656 <li>finished<sub>I</sub> <- HMAC(fk<sub>I</sub>, Transcript-Hash(sig<sub>I</sub>))</li> 657 </ol> 658 <t> 659 Both are Hash.length (32) bytes long. Receivers 660 <bcp14>SHOULD</bcp14> compare them in constant time. 661 </t> 662 </section> 663 <section anchor="primitives" numbered="true" toc="default"> 664 <name>Algorithms</name> 665 <t> 666 CAKE has no algorithm negotiation. It uses: 667 </t> 668 <ul> 669 <li>Hash: SHA-256, for the transcript hash, H(pk), HKDF and HMAC. 670 Hash.length is 32.</li> 671 <li>AEAD: XChaCha20-Poly1305 <xref target="XCHACHA"/>, with a 672 32-byte key, a 24-byte nonce and a 16-byte tag, and empty 673 associated data. It is ChaCha20-Poly1305 674 (<xref target="RFC8439"/>), which TLS 1.3 uses, with an extended 675 nonce; CAKE does not need the longer nonce, since its nonces are 676 counters (see <xref target="open"/>).</li> 677 <li>Sequence number encryption: ChaCha20 <xref target="RFC8439"/> 678 (<xref target="encrypted_message"/>).</li> 679 <li>ECDH: see <xref target="ecdh"/>.</li> 680 <li>Signature: see <xref target="ed25519"/>.</li> 681 </ul> 682 <section anchor="ecdh" numbered="true" toc="default"> 683 <name>ECDH</name> 684 <t> 685 DHE is the shared secret of X25519 (<xref target="RFC7748"/>) 686 computed from the two peers' ephemeral keys. Each peer 687 generates a fresh X25519 key pair (sk<sub>e</sub>, pk<sub>e</sub>) 688 for every handshake; pk<sub>e</sub> is 32 bytes. DHE is the 689 single secret input to the key schedule 690 (<xref target="key_schedule"/>) and provides forward secrecy 691 once sk<sub>e</sub> is erased. Implementations MUST reject the 692 all-zero shared secret. 693 </t> 694 </section> 695 <section anchor="ed25519" numbered="true" toc="default"> 696 <name>Ed25519 Signatures</name> 697 <t> 698 sig<sub>R</sub> and sig<sub>I</sub> are Ed25519 signatures 699 (<xref target="RFC8032"/>) made with the peers' long-term 700 identity keys (the Ed25519 public keys that are the peer 701 identities), the analogue of the CertificateVerify of TLS 1.3 702 (<xref target="RFC8446" section="4.4.3"/>). They are 64 bytes. 703 The signed content is, as in TLS 1.3, 64 zero bytes followed by a 704 context string and a single 0x00 byte, followed by the 705 transcript hash: 706 </t> 707 <ul> 708 <li>sig<sub>R</sub> = Sign(sk<sub>R</sub>, 0x00*64 || 709 "CAKE responder signed ephemeral" || 0x00 || 710 Transcript-Hash(T(pk<sub>e</sub>)))</li> 711 <li>sig<sub>I</sub> = Sign(sk<sub>I</sub>, 0x00*64 || 712 "CAKE initiator signed ephemeral" || 0x00 || 713 Transcript-Hash(T(finished<sub>R</sub>)))</li> 714 </ul> 715 <t> 716 The context strings differ so that a signature over one 717 transcript point cannot be reused for the other, and so that 718 CAKE signatures are disjoint from any other use of the identity 719 key (e.g. HELLO signatures). The signature is verified against 720 the peer identity as known from the transport: the responder 721 verifies sig<sub>R</sub> against pk<sub>R</sub>, and the 722 initiator verifies sig<sub>I</sub> against pk<sub>I</sub>, the 723 identity of the peer the ResponderHello resp. InitiatorHello was 724 received from. 725 </t> 726 </section> 727 </section> 728 <section anchor="cake_hs_msg_fmt" numbered="true" toc="default"> 729 <name>CAKE Message Format</name> 730 <t> 731 Any sent message starts with a <tt>MessageHeader</tt>: 732 </t> 733 <figure anchor="figure_msghdr" title="The Wire Format of the Message Header."> 734 <artwork name="" type="" align="left" alt=""><![CDATA[ 735 0 8 16 24 32 736 +-----+-----+-----+-----+ 737 | Size | Type | 738 +-----+-----+-----+-----+ 739 ]]></artwork> 740 </figure> 741 <dl> 742 <dt>Size:</dt> <dd>The size of the message including the Size and Type fields, 16 bits in network byte order.</dd> 743 <dt>Type:</dt> <dd>The message type, 16 bits in network byte order.</dd> 744 </dl> 745 <t> 746 All multi-byte integers are in network byte order, and all 747 structures are packed (there is no padding other than the 748 explicit "Reserved" fields). 749 The possible types of messages are: 750 </t> 751 <ul> 752 <li>InitiatorHello (80, CORE_INITIATOR_HELLO)</li> 753 <li>ResponderHello (81, CORE_RESPONDER_HELLO)</li> 754 <li>InitiatorDone (82, CORE_INITIATOR_DONE)</li> 755 <li>EncryptedMessage (83, CORE_ENCRYPTED_MESSAGE)</li> 756 </ul> 757 <t> 758 The payload of an EncryptedMessage is a sequence of messages that 759 also always start with a MessageHeader. It is either a single 760 Heartbeat (84, CORE_HEARTBEAT), a single ACK (85, CORE_ACK), or 761 application data: one or more messages of other types. 762 </t> 763 </section> 764 <section anchor="initiator_hello" numbered="true" toc="default"> 765 <name>InitiatorHello Message</name> 766 <figure anchor="figure_inithello" title="The Wire Format of the InitiatorHello."> 767 <artwork name="" type="" align="left" alt=""><![CDATA[ 768 0 8 16 24 32 40 48 56 769 +-----+-----+-----+-----+-----+-----+-----+-----+ 770 | Size | Type (80) | Reserved | 771 +-----+-----+-----+-----+-----+-----+-----+-----+ 772 | r_I | 773 +-----+-----+-----+-----+-----+-----+-----+-----+ 774 | pk_e (256 bit) | 775 / / 776 +-----+-----+-----+-----+-----+-----+-----+-----+ 777 | H(pk_R) (256 bit) | 778 / / 779 +-----+-----+-----+-----+-----+-----+-----+-----+ 780 ]]></artwork> 781 </figure> 782 <t> 783 The Reserved field <bcp14>MUST</bcp14> be zero when sent and is 784 ignored on receipt (it is covered by the transcript); it keeps 785 r<sub>I</sub> aligned. The InitiatorHello is sent in plaintext: 786 there is no ETS and no encrypted payload. It is exactly 787 80 bytes long, and receivers <bcp14>MUST</bcp14> discard other sizes. 788 </t> 789 </section> 790 <section anchor="responder_hello" numbered="true" toc="default"> 791 <name>ResponderHello Message</name> 792 <figure anchor="figure_recvhello" title="The Wire Format of the ResponderHello."> 793 <artwork name="" type="" align="left" alt=""><![CDATA[ 794 0 8 16 24 32 40 48 56 795 +-----+-----+-----+-----+-----+-----+-----+-----+ 796 | Size | Type (81) | Reserved | 797 +-----+-----+-----+-----+-----+-----+-----+-----+ 798 | r_R | 799 +-----+-----+-----+-----+-----+-----+-----+-----+ 800 | pk_e (256 bit) | 801 / / 802 +-----+-----+-----+-----+-----+-----+-----+-----+ 803 | sig_R (512 bit) | 804 / / 805 / / 806 / / 807 / / 808 / / 809 / / 810 / / 811 +-----+-----+-----+-----+-----+-----+-----+-----+ 812 | pc_R (enc)| svcinfo_R (encrypted) / 813 +-----+-----+ / 814 / / 815 +-----+-----+-----+-----+-----+-----+-----+-----+ 816 | Tag (128 bit) | 817 | | 818 +-----+-----+-----+-----+-----+-----+-----+-----+ 819 | finished_R (256 bit, enc) | 820 / / 821 +-----+-----+-----+-----+-----+-----+-----+-----+ 822 | Tag (128 bit) | 823 | | 824 +-----+-----+-----+-----+-----+-----+-----+-----+ 825 ]]></artwork> 826 </figure> 827 <t> 828 The Reserved field is as in the InitiatorHello. 829 sig<sub>R</sub> is the responder's Ed25519 signature over 830 Transcript-Hash(T(pk<sub>e</sub>)); it is sent in plaintext 831 (<xref target="ed25519"/>). 832 pc<sub>R</sub> and svcinfo<sub>R</sub> are encrypted 833 with RHTS, sequence number 0. 834 finished<sub>R</sub> is encrypted individually, with RHTS and 835 sequence number 1, because its transcript ends before it. 836 The receiver finds finished<sub>R</sub> at the end of the message: 837 svcinfo<sub>R</sub> extends up to 48 bytes (finished<sub>R</sub> 838 and its tag) before the end. The message is at least 178 bytes 839 long. 840 </t> 841 </section> 842 <section anchor="handshake_finished" numbered="true" toc="default"> 843 <name>InitiatorDone Message</name> 844 <figure anchor="figure_initdone" title="The Wire Format of the InitiatorDone."> 845 <artwork name="" type="" align="left" alt=""><![CDATA[ 846 0 8 16 24 32 40 48 56 847 +-----+-----+-----+-----+-----+-----+-----+-----+ 848 | Size | Type (82) | Reserved | 849 +-----+-----+-----+-----+-----+-----+-----+-----+ 850 | sig_I (512 bit) | 851 / / 852 / / 853 / / 854 / / 855 / / 856 / / 857 / / 858 +-----+-----+-----+-----+-----+-----+-----+-----+ 859 | finished_I (256 bit, enc) | 860 / / 861 +-----+-----+-----+-----+-----+-----+-----+-----+ 862 | Tag (128 bit) | 863 | | 864 +-----+-----+-----+-----+-----+-----+-----+-----+ 865 ]]></artwork> 866 </figure> 867 <t> 868 The InitiatorDone carries sig<sub>I</sub>, the initiator's Ed25519 869 signature over Transcript-Hash(T(finished<sub>R</sub>)), in 870 plaintext (<xref target="ed25519"/>), followed by 871 finished<sub>I</sub> encrypted with IHTS (sequence number 0). It 872 is exactly 120 bytes long, and receivers <bcp14>MUST</bcp14> 873 discard other sizes. 874 </t> 875 </section> 876 <section anchor="encrypted_message" numbered="true" toc="default"> 877 <name>EncryptedMessage</name> 878 <t> 879 The EncryptedMessage follows a message header with type <tt>CORE_ENCRYPTED_MESSAGE</tt>: 880 </t> 881 <figure anchor="figure_encryptedmsg" title="The Wire Format of the EncryptedMessage header."> 882 <artwork name="" type="" align="left" alt=""><![CDATA[ 883 0 8 16 24 32 40 48 56 884 +-----+-----+-----+-----+-----+-----+-----+-----+ 885 | Epoch | 886 +-----+-----+-----+-----+-----+-----+-----+-----+ 887 | Sequence Number (encrypted) | 888 +-----+-----+-----+-----+-----+-----+-----+-----+ 889 | Tag | 890 | | 891 +-----+-----+-----+-----+-----+-----+-----+-----+ 892 ]]></artwork> 893 </figure> 894 <t> 895 The Tag is followed by the payload, encrypted with the key and 896 nonce of <xref target="traffic_keys"/> for the sender's traffic 897 secret of the epoch ([I,R]ATS<sub>Epoch</sub>) and the sequence 898 number. The length of the payload is given by the Size field of 899 the MessageHeader preceding the EncryptedMessage header. 900 </t> 901 <t> 902 The Epoch is sent in plaintext. Neither it nor the Sequence Number 903 is associated data; both are authenticated implicitly, since the 904 epoch selects the key and the sequence number determines the 905 nonce: a record whose epoch or sequence number was tampered with 906 fails to deprotect. 907 </t> 908 <t> 909 The epoch starts at 0 after the handshake with the first *ATS secret. 910 Any peer may at any time update to a new epoch 911 (<xref target="traffic_keys"/>). 912 Peers may keep a history of secrets for respective epochs at their own discretion in 913 order to handle out-of-order message deliveries. 914 Unlike DTLS 1.3, CAKE does not truncate the epoch and no reconstruction is 915 necessary. 916 A peer may consider the epoch too old or too far in the future and reject decryption. 917 For this purpose, a peer may manage a sliding window of epochs that can be used 918 by the other peer. (The GNUnet implementation keeps the secrets of 919 the 10 most recent epochs of its peer, and does not ratchet forward 920 more than 20 epochs at a time.) 921 A peer <bcp14>MUST NOT</bcp14> let its epoch or its sequence 922 numbers wrap; it starts a new handshake instead. 923 </t> 924 <t> 925 Receivers <bcp14>MUST</bcp14> keep an anti-replay window per epoch 926 as in <xref target="RFC9147" section="4.5.1"/>. Since the epoch is 927 not authenticated before the record deprotects, receivers 928 <bcp14>MUST NOT</bcp14> change any state -- the anti-replay 929 windows, the traffic secrets they keep, the newest epoch seen -- 930 on account of a record before it has deprotected successfully. 931 (Otherwise a single forged record claiming a later epoch could 932 reset the anti-replay windows of epochs still in use, after which 933 their records could be replayed.) 934 Records that do not deprotect are silently discarded. 935 </t> 936 <t> 937 The sequence number is encrypted as defined in <xref target="RFC9147" section="4.2.3"/> 938 for ChaCha20-based AEAD schemes, with the Tag as the sample: 939 </t> 940 <figure anchor="figure_sn_xor" title="Sequence Number Encryption."> 941 <artwork name="" type="" align="left" alt=""><![CDATA[ 942 sn_key = HKDF-Expand-Label([I,R]ATS_N, "sn", "", 32) 943 mask = ChaCha20(sn_key, Tag[0..3], Tag[4..15]) 944 sn_enc = mask[0..7] XOR sn 945 ]]></artwork> 946 </figure> 947 <t> 948 Where [I,R]ATS<sub>N</sub> is the sender's traffic secret of epoch 949 N, sn is the 64-bit sequence number in network byte order, and 950 ChaCha20 is the block function of <xref target="RFC8439" section="2.3"/> 951 with Tag[0..3] as the block counter and Tag[4..15] as the nonce. 952 As in <xref target="RFC9001" section="5.4.4"/>, the block counter 953 is Tag[0..3] read as a little-endian integer. 954 In DTLS 1.3 the sample is the first 16 bytes of the ciphertext; 955 in CAKE the Tag comes first, so the sample is always the Tag, 956 and there are always enough bytes to sample. 957 </t> 958 </section> 959 <section anchor="heartbeat_msg" numbered="true" toc="default"> 960 <name>Heartbeat</name> 961 <t> 962 The HEARTBEAT message is a simple MessageHeader inside an EncryptedMessage with type <tt>CORE_HEARTBEAT</tt> followed by a 32-bit UpdateRequested flags field in network byte order. 963 This means that for every received EncryptedMessage 964 the peer <bcp14>MUST</bcp14> check if this is a Heartbeat. 965 If the flag 0x00000001 is set in the UpdateRequested field, the receiver 966 of the Heartbeat <bcp14>SHOULD</bcp14> move to its next epoch 967 before it answers; this is the request_update of the KeyUpdate of 968 <xref target="RFC8446" section="4.6.3"/>. 969 All other flags are reserved: they <bcp14>MUST</bcp14> be zero 970 when sent and <bcp14>MUST</bcp14> be ignored on receipt. 971 Any bytes following the UpdateRequested field are updated services info 972 svcinfo (<xref target="svcinfo"/>). 973 Services info updates are optional; receivers that do not process 974 them <bcp14>MUST</bcp14> ignore them. 975 <!-- TODO: Incremental or full ServicesInfo --> 976 </t> 977 <t> 978 Every Heartbeat <bcp14>MUST</bcp14> be answered with an ACK. A 979 peer that has not received any record for some time sends a 980 Heartbeat to probe the association (the GNUnet implementation 981 does so after 30 seconds, and considers the association dead 982 after three Heartbeats in a row went unanswered). 983 </t> 984 <figure anchor="figure_keyupdate_msg" title="The Wire Format of the Heartbeat."> 985 <artwork name="" type="" align="left" alt=""><![CDATA[ 986 0 8 16 24 32 987 +-----+-----+-----+-----+ 988 | UpdateRequested | 989 +-----+-----+-----+-----+ 990 | svcinfo / 991 / / 992 ]]></artwork> 993 </figure> 994 </section> 995 <section anchor="ack_msg" numbered="true" toc="default"> 996 <name>ACK</name> 997 <t> 998 The ACK message is a simple MessageHeader inside an EncryptedMessage with 999 type <tt>CORE_ACK</tt>. 1000 This means that for every received EncryptedMessage 1001 the peer <bcp14>MUST</bcp14> check if this is an ACK message after decryption. 1002 The ACK of DTLS 1.3 lists the records it acknowledges; CAKE's ACK 1003 is empty, since it only ever answers one thing: the InitiatorDone 1004 (its first ACK under RATS<sub>0</sub>) or a Heartbeat. 1005 The peer may use the ACK in order to ensure liveness of connected 1006 peers in combination with Heartbeats. 1007 </t> 1008 </section> 1009 </section> 1010 <section anchor="open" numbered="true" toc="default"> 1011 <name>Open Issues</name> 1012 <t> 1013 The Ed25519 peer identity key is now used only for signatures 1014 (HELLOs and sig<sub>R</sub>/sig<sub>I</sub>), not for key 1015 encapsulation, so the signing-oracle concern of the earlier KEM-based 1016 design no longer applies. Separating the HELLO signing key from the 1017 peer identity key remains a possible future hardening. 1018 </t> 1019 <t> 1020 XChaCha20-Poly1305 is specified in <xref target="XCHACHA"/>, which 1021 expired as an Internet-Draft; it may be worth defining it here based 1022 on HChaCha20, or to use ChaCha20-Poly1305 <xref target="RFC8439"/> 1023 as TLS 1.3 does. The objection to ChaCha20-Poly1305 -- that its 1024 nonce is too short to be chosen at random -- does not apply to 1025 CAKE, whose nonces are derived from sequence numbers. 1026 We could also use XSalsa20 which is better specified (and available). We use it already for GNS (EDKEY encryption). 1027 </t> 1028 <t> 1029 The Initiator/Responder selection logic may require a timed fallback: The designated Initiator may never initiate (NAT, already has sufficient connections, learns about responder later than responder about initiator etc.). 1030 1031 This may result in edge cases where the Initiator initiates a handshake and the Responder also initiates a handshake at the same time switching roles. 1032 1033 In such cases we may simply do both key exchanges. If both succeed, we drop the key exchange that was not initiated by the designated initiator on both peers. Otherwise we use the successful key exchange and the roles are swapped. 1034 </t> 1035 </section> 1036 <section anchor="security" numbered="true" toc="default"> 1037 <name>Security and Privacy Considerations</name> 1038 <section numbered="true" toc="default"> 1039 <name>Authentication and Key Confirmation</name> 1040 <t> 1041 Both peers are authenticated explicitly through Ed25519 signatures: 1042 only the holder of sk<sub>R</sub> can produce sig<sub>R</sub>, and 1043 only the holder of sk<sub>I</sub> can produce sig<sub>I</sub>. 1044 Each signature covers the transcript up to the signer's ephemeral 1045 key (sig<sub>R</sub>) or up to the peer's Finished 1046 (sig<sub>I</sub>), binding the ephemeral keys and the whole 1047 preceding exchange to the signing identity. finished<sub>R</sub> 1048 and finished<sub>I</sub>, keyed from *HTS, provide key confirmation 1049 over the transcript. Because authentication rests on signatures 1050 made with the peer's own key, compromise of a peer's own key does 1051 not let an attacker impersonate others to it (no key compromise 1052 impersonation). 1053 </t> 1054 <t> 1055 Nothing in the InitiatorHello is authenticated, and the 1056 InitiatorDone only once sig<sub>I</sub> and finished<sub>I</sub> 1057 have verified. Anybody able to inject messages can produce an 1058 InitiatorHello that claims to come from any initiator; the 1059 responder learns the initiator identity from the transport, and 1060 verifies sig<sub>I</sub> against it. This is why the rules of 1061 <xref target="protocol_flow"/> forbid a handshake that has not 1062 completed to affect an existing association: it must not switch 1063 the association's sending keys before then, and must not tear the 1064 association down when the new handshake times out. Likewise, 1065 handshake messages that do not verify must not change any state: 1066 an implementation that, say, stops retransmitting its flight 1067 upon receiving anything that merely looks like the answer can be 1068 stalled indefinitely by a single forged message. 1069 </t> 1070 </section> 1071 <section numbered="true" toc="default"> 1072 <name>Forward Secrecy and Privacy</name> 1073 <t> 1074 Forward secrecy comes from the ephemeral X25519 key exchange 1075 (DHE) alone. sk<sub>e</sub> <bcp14>MUST</bcp14> be 1076 fresh for every handshake and erased afterwards, as must all 1077 handshake secrets. An attacker that later obtains the long-term 1078 keys of both peers can then not decrypt recorded traffic. 1079 </t> 1080 <t> 1081 The InitiatorHello is sent in plaintext: with no static secret to 1082 protect it, its fields (r<sub>I</sub>, pk<sub>e</sub>, 1083 H(pk<sub>R</sub>)) are visible to passive observers. None of them 1084 is secret (the peer identities are in any case known to the 1085 underlying transport), and the exchange is not complete until 1086 sig<sub>R</sub> and sig<sub>I</sub> have verified. There is no 1087 0-RTT and no early data. 1088 </t> 1089 <t> 1090 The key exchange uses X25519 only. An attacker that records 1091 traffic today and obtains a cryptographically relevant quantum 1092 computer later can decrypt it. 1093 </t> 1094 </section> 1095 <section numbered="true" toc="default"> 1096 <name>Replay and Denial of Service</name> 1097 <t> 1098 The InitiatorHello is not protected against replay. A replayed 1099 InitiatorHello costs the responder one ephemeral key generation, one 1100 ECDH and one signature, and makes it send a ResponderHello, which is 1101 larger than the InitiatorHello (it adds sig<sub>R</sub>); the 1102 handshake cannot complete without sk<sub>I</sub>. 1103 Responders <bcp14>SHOULD</bcp14> recognize retransmissions of the 1104 InitiatorHello they are answering (e.g. by its hash) and answer 1105 them with a retransmission of their ResponderHello instead of 1106 starting over. CAKE has no cookie exchange (the 1107 HelloRetryRequest of DTLS 1.3): protection against InitiatorHellos 1108 from spoofed addresses is left to the GNUnet transport layer. 1109 </t> 1110 <t> 1111 Records are protected against replay by the per-epoch anti-replay 1112 windows (<xref target="encrypted_message"/>), which must only ever 1113 be updated by records that deprotected. 1114 </t> 1115 </section> 1116 <section numbered="true" toc="default"> 1117 <name>Key Usage</name> 1118 <t> 1119 The Ed25519 peer identity key is used for signatures: of HELLOs 1120 and of the ephemeral keys (sig<sub>R</sub>, sig<sub>I</sub>). It 1121 is not used for key encapsulation. The context strings of 1122 <xref target="ed25519"/> keep these uses disjoint. 1123 </t> 1124 <t> 1125 Each handshake traffic secret protects at most two fields, with 1126 distinct sequence numbers. Application traffic secrets are 1127 replaced before their sequence numbers wrap; the regular change of 1128 epochs also bounds the number of forgery attempts against any one 1129 key (cf. <xref target="RFC9147" section="4.5.3"/>). 1130 </t> 1131 </section> 1132 </section> 1133 <!-- gana --> 1134 <section anchor="gana"> 1135 <name>GANA Considerations</name> 1136 <t> 1137 The message types of <xref target="cake_hs_msg_fmt"/> are GNUnet 1138 message types, allocated in GANA's GNUnet message type registry. 1139 </t> 1140 </section> 1141 <section> 1142 <name>Implementation and Deployment Status</name> 1143 <t> 1144 CAKE is implemented in the CORE service of GNUnet 1145 (<tt>src/service/core/</tt>). This version of the specification 1146 replaces the earlier KEMTLS-based design (three DHKEM shared 1147 secrets, ss<sub>R</sub>, ss<sub>e</sub>, ss<sub>I</sub>, and a 0-RTT 1148 InitiatorHello encrypted with ETS) with a signed ephemeral key 1149 exchange: a single X25519 ECDH (DHE) and Ed25519 signatures 1150 (sig<sub>R</sub>, sig<sub>I</sub>), with no 0-RTT. The handshake is 1151 not compatible with the earlier design. 1152 </t> 1153 <t> 1154 The GNUnet implementation has been migrated to this specification. 1155 The wire format, the key schedule, and the handshake flight logic 1156 (signature generation and verification, ECDH, the retransmission and 1157 rekey behaviour) now follow this document. GNUnet 0.25 implements 1158 an earlier, KEMTLS-based version, which is not compatible: it used 1159 three DHKEM shared secrets (ss<sub>R</sub>, ss<sub>e</sub>, 1160 ss<sub>I</sub>), a 0-RTT InitiatorHello encrypted with ETS, 1161 "cake10" || Label || Context instead of the HkdfLabel structure, 1162 SHA-512 for the transcript hash, H(pk) and the Finished HMAC, a 1163 transcript of the messages as sent (ciphertexts and tags included) 1164 instead of their plaintext, and an InitiatorDone that also carried 1165 an ACK. (The ACK in the InitiatorDone has been dropped; the 1166 responder's ACK under RATS<sub>0</sub> now confirms the handshake, 1167 as in the rest of this specification.) 1168 </t> 1169 <t> 1170 The implementation uses SHA-512 (not SHA-256) for the transcript 1171 hash and H(pk), and feeds the X25519 shared secret through 1172 <tt>GNUNET_CRYPTO_ecc_ecdh</tt> (which hashes it with SHA-512) 1173 rather than as the raw 32-byte secret of <xref target="ecdh"/>; 1174 these are to be aligned with the specification. Open tasks 1175 include: 1176 </t> 1177 <ol> 1178 <li>Requesting key updates</li> 1179 <li>Services info transmission (currently empty/unused)</li> 1180 <li>Integrate and test PILS PID changes (potentially requires in-band signalling of new PIDs in CORE, not really that much related to CAKE)</li> 1181 <li>Align the transcript hash and H(pk) with SHA-256, and DHE with the raw X25519 shared secret</li> 1182 <li>Regenerate test vectors for the signed ephemeral key exchange</li> 1183 </ol> 1184 </section> 1185 <!-- <section> 1186 <name>Acknowledgements</name> 1187 <t> 1188 FIXME 1189 </t> 1190 </section>--> 1191 </middle> 1192 <back> 1193 <references> 1194 <name>Normative References</name> 1195 &RFC2104; 1196 &RFC2119; 1197 &RFC5869; 1198 &RFC6234; 1199 &RFC7748; 1200 &RFC8174; 1201 &RFC8439; 1202 &RFC8446; 1203 &RFC9147; 1204 &RFC8032; 1205 1206 <reference anchor="XCHACHA" target="https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03"> 1207 <front> 1208 <title>XChaCha: eXtended-nonce ChaCha and AEAD_XChaCha20_Poly1305</title> 1209 <author initials="S." surname="Arciszewski" fullname="Scott Arciszewski"> 1210 <organization>Paragon Initiative Enterprises</organization> 1211 </author> 1212 <date year="2020" month="January"/> 1213 </front> 1214 <seriesInfo name="Internet-Draft" value="draft-irtf-cfrg-xchacha-03"/> 1215 </reference> 1216 </references> 1217 <references> 1218 <name>Informative References</name> 1219 &RFC9001; 1220 </references> 1221 <section anchor="test_vectors" numbered="true" toc="default"> 1222 <name>Test Vectors</name> 1223 <t> 1224 The test vectors of the earlier KEM-based version of CAKE do not 1225 apply to the signed ephemeral key exchange defined here (the key 1226 schedule, the handshake messages and the transcript all changed). 1227 Vectors for this version -- one complete handshake followed by a 1228 few records -- will be generated from an independent implementation 1229 and added here once the implementation of this specification is 1230 complete (its test <tt>test_cake</tt>). 1231 </t> 1232 </section> 1233 </back> 1234 </rfc>