lsd0012

LSD0012: CORE Authenticated Key Exchange (CAKE)
Log | Files | Refs

commit 311bece1c5dbbf9bfd0b08358657bf7c18cfae7c
parent aab8797dd74a397a26aa206aca8826ec9f954c2d
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Thu, 26 Nov 2026 19:04:36 +0100

Move to signed-ephemeral KX

Diffstat:
Mdraft-schanzen-cake.xml | 1127+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Mstyle.css | 4++++
2 files changed, 789 insertions(+), 342 deletions(-)

diff --git a/draft-schanzen-cake.xml b/draft-schanzen-cake.xml @@ -32,6 +32,10 @@ <!ENTITY RFC9106 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9106.xml"> <!ENTITY RFC9147 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9147.xml"> <!ENTITY RFC9180 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9180.xml"> +<!ENTITY RFC8032 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8032.xml"> +<!ENTITY RFC9001 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.9001.xml"> +<!ENTITY RFC2104 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2104.xml"> +<!ENTITY RFC6234 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6234.xml"> <!ENTITY I-D.ietf-dnsop-alt-tld PUBLIC '' "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-dnsop-alt-tld.xml"> ]> <?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?> @@ -85,7 +89,10 @@ <keyword>transport protocols</keyword> <abstract> <t> - This document contains the GNUnet CORE AKE (CAKE). + This document contains the GNUnet CORE AKE (CAKE): a signed + ephemeral key exchange -- regular DTLS 1.3 with raw Ed25519 public + keys -- using the key schedule of TLS 1.3 and the handshake state + machine of DTLS 1.3. </t> <t> This document defines the normative wire format of the protocol, @@ -95,9 +102,8 @@ <t> This specification was developed outside the IETF and does not have IETF consensus. It is published here to inform readers about the - function of GNUnet communicators, guide future implementations, and ensure - interoperability including with the pre-existing - GNUnet implementation. + function of GNUnet CORE, guide future implementations, and ensure + interoperability among implementations. </t> </abstract> </front> @@ -106,8 +112,9 @@ <name>Introduction</name> <t> This specification was developed outside the IETF and does not have - IETF consensus. It is published here to guide implementers of GNS - and to ensure interoperability among implementations. + IETF consensus. It is published here to guide implementers of the + GNUnet CORE service and to ensure interoperability among + implementations. </t> <section numbered="true" toc="default"> <name>Requirements Notation</name> @@ -124,51 +131,112 @@ <name>Conventions and Terminology</name> <t> While some of the terminology is explicitly re-defined here, the reader is expected - to be familiar with TLS 1.3 (<xref target="RFC8446"/>), DTLS 1.3 (<xref target="RFC9147"/>) and HPKE - (<xref target="RFC9180"/>). + to be familiar with TLS 1.3 (<xref target="RFC8446"/>), DTLS 1.3 (<xref target="RFC9147"/>) and + Ed25519 (<xref target="RFC8032"/>). </t> <dl> - <dt>inititator:</dt><dd>See client in <xref target="RFC9147"/> Section 2.</dd> + <dt>initiator:</dt><dd>See client in <xref target="RFC9147"/> Section 2.</dd> <dt>responder:</dt><dd>See server in <xref target="RFC9147"/> Section 2.</dd> <dt>epoch:</dt><dd>See <xref target="RFC9147"/> Section 2.</dd> - <dt>IATS:</dt> - <dd>Initiator Application Traffic Secret Key</dd> - <dt>RATS:</dt> <dd>Responder Application Traffic Secret Key</dd> - <dt>ES:</dt> <dd>Early Secret Key</dd> - <dt>ETS:</dt> <dd>Early Traffic Secret Key</dd> - <dt>HS:</dt> <dd>Handshake Secret Key</dd> - <dt>MS:</dt> <dd>Main Secret Key</dd> - <dt>ES:</dt> <dd>Early Secret Key</dd> - <dt>IHTS:</dt> <dd>Initiator Handshake Secret Key</dd> - <dt>RHTS:</dt> <dd>Responder Handshake Secret Key</dd> - <dt>H(D):</dt> <dd>A 512-bit hash over D. The hash function is TBD (Blake2b or SHA-512).</dd> - <dt>T(M):</dt> <dd>means the transcript as a concatenation of received/sent messages starting from and including the InitiatorHello pk_e until and including M. Note that the transcript refers to everything that is seen on the wire, including potentially encrypted messages or fields and metadata.</dd> - <dt>'{}K'</dt> <dd>indicates encryption with a handshake traffic key K and a modified <xref target="RFC8439"/>, the XChaCha20-Poly1305 Authenticated Encryption with Associated Data (AEAD) construction.</dd> - <dt>'[]K'</dt> <dd>indicates encryption with an application traffic key K using the XChaCha20-Poly1305 Authenticated Encryption with Associated Data (AEAD) construction.</dd> - </dl> + <dt>ES:</dt> <dd>Early Secret</dd> + <dt>HS:</dt> <dd>Handshake Secret</dd> + <dt>IHTS:</dt> <dd>Initiator Handshake Traffic Secret</dd> + <dt>RHTS:</dt> <dd>Responder Handshake Traffic Secret</dd> + <dt>MS:</dt> <dd>Master Secret</dd> + <dt>IATS<sub>N</sub>:</dt> <dd>Initiator Application Traffic Secret of epoch N</dd> + <dt>RATS<sub>N</sub>:</dt> <dd>Responder Application Traffic Secret of epoch N</dd> + <dt>DHE:</dt> <dd>The ephemeral X25519 shared secret of the handshake, see + <xref target="ecdh"/>. Computed once, from the two peers' + ephemeral keys.</dd> + <dt>H(D):</dt> <dd>SHA-256 <xref target="RFC6234"/> over D. Hash.length is 32.</dd> + <dt>HKDF-Extract(Salt, IKM), HKDF-Expand(PRK, Info, L):</dt> + <dd>The functions of <xref target="RFC5869"/>, instantiated with + SHA-256.</dd> + <dt>HMAC(K, D):</dt> <dd>HMAC <xref target="RFC2104"/> with SHA-256 over D.</dd> + <dt>HKDF-Expand-Label, Derive-Secret:</dt> + <dd>As in <xref target="RFC8446" section="7.1"/>, with the label + prefix of <xref target="crypto_label"/>.</dd> + <dt>Sign(sk, D), Verify(pk, sig, D):</dt> + <dd>Ed25519 signature and verification of D, see + <xref target="ed25519"/>. A signature is 64 bytes.</dd> + <dt>T(M):</dt> <dd>The transcript up to and including M, see + <xref target="transcript"/>. Transcript-Hash(M) is H(T(M)).</dd> + <dt>'{}K'</dt> <dd>indicates encryption with the handshake + traffic secret K, see <xref target="traffic_keys"/>.</dd> + <dt>'[]K'</dt> <dd>indicates a record protected with the + application traffic secret K, see <xref target="encrypted_message"/>.</dd> + </dl> </section> <section anchor="rationale" numbered="true" toc="default"> <name>Design Rationale</name> <t> - The design rationale for CAKE is similar to DTLS 1.3 (cf. <xref target="RFC9147" section="3"/>). - Except that CAKE does not consider Fragmentation as this is expected to be provided by the - transport underlay layer of GNUnet. + CAKE is a signed ephemeral key exchange -- regular DTLS 1.3 with raw + Ed25519 public keys -- carried by the handshake state machine of + DTLS 1.3 (<xref target="RFC9147" section="5"/>). Both peers know + each other's long-term public key in advance (the peer identity and + the <tt>HELLO</tt>), so neither carries a certificate: each signs + its ephemeral key with its long-term Ed25519 identity key, the + analogue of the CertificateVerify of TLS 1.3 + (<xref target="RFC8446" section="4.4.3"/>). There is no KEM and + no 0-RTT. + </t> + <t> + CAKE takes from TLS 1.3 and DTLS 1.3: </t> + <ul> + <li>The key schedule of <xref target="RFC8446" section="7.1"/>, + including HKDF-Expand-Label and Derive-Secret, with a single + (EC)DHE shared secret (DHE) as the input to the Handshake Secret + and zero (no PSK) as the inputs to the Early Secret and to the + Master Secret.</li> + <li>The transcript hash over the plaintext of the handshake + messages (<xref target="RFC8446" section="4.4.1"/>), see + <xref target="transcript"/>.</li> + <li>The traffic key calculation, the per-record nonce and the key + update (Sections 7.3, 5.3 and 7.2 of <xref target="RFC8446"/>).</li> + <li>The flights, timers and retransmissions of + <xref target="RFC9147" section="5.8"/>, including the ACK of the + initiator's final flight, and the handling of a new handshake on an + existing association of <xref target="RFC9147" section="5.11"/>.</li> + <li>Sequence number encryption (<xref target="RFC9147" section="4.2.3"/>) + and anti-replay (<xref target="RFC9147" section="4.5.1"/>).</li> + </ul> + <t> + CAKE has no use for most of the rest of (D)TLS and leaves it out: + version and cipher suite negotiation and the legacy fields that come + with them, extensions, HelloRetryRequest and cookies, PSK + resumption, 0-RTT and 0.5-RTT application data, alerts, connection + IDs, content types and padding. Fragmentation is provided by the + transport underlay of GNUnet. In addition, CAKE simplifies the + following: + </t> + <ul> + <li>The handshake consists of three messages, one per flight + (InitiatorHello, ResponderHello, InitiatorDone), each of which + packs what would be several TLS handshake messages.</li> + <li>Each handshake traffic secret protects one or two fields with + fixed sequence numbers, so the handshake needs no epochs and no + record headers. Epoch 0 of CAKE is the first application traffic + secret (epoch 3 in DTLS 1.3).</li> + <li>Records carry their 64-bit epoch and sequence number in full, so + neither needs to be reconstructed, and a peer can move to its next + epoch at any time without a KeyUpdate message. A Heartbeat + (<xref target="heartbeat_msg"/>) can ask the other peer to do so.</li> + <li>There is a single set of algorithms (<xref target="primitives"/>).</li> + </ul> </section> <section anchor="protocol_flow" numbered="true" toc="default"> <name>Protocol Flow</name> <t> - This protocol is heavily inspired by <xref target="KEMTLS"/>. - </t> - <t> 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>. </t> <t> - For any secure handshake protocol, we have to dermine an initiator and a responder in the protocol. We use <tt>GNUNET_CRYPTO_hash_cmp</tt> to determine which peer is the responder R and which peer the initiator I: + For any secure handshake protocol, we have to determine an initiator and a responder in the protocol. + The peer whose identity has the smaller hash is the initiator I, the other one the responder R: </t> <sourcecode> <![CDATA[ -if (GNUNET_CRYPTO_hash_cmp (pk_A, pk_B)) +if (H(pk_A) < H(pk_B)) { pk_I = pk_A pk_R = pk_B @@ -181,7 +249,14 @@ else ]]> </sourcecode> <t> - It is possible that the designated initiator does not initiate the handshake. After a pre-determined timeout, the respective other peer may initiate. + Here pk<sub>A</sub> and pk<sub>B</sub> are the 32-byte Ed25519 + public keys that are the peer identities, and the hashes are + compared as byte strings, that is, as unsigned big-endian + integers. + The responder never initiates a handshake; a peer that receives an + InitiatorHello from a peer that should be the responder discards + it. (See <xref target="open"/> for a fallback for designated + initiators that never initiate.) We assume that the initiator knows pk<sub>R</sub> (pre-distributed through <tt>HELLO</tt>, for example). </t> <t> @@ -189,56 +264,39 @@ else On the left and right side of the swimlanes the secrets known to the Initiator and Responder are shown respectively. If a private key of a key pair is known it is implied that the public key is also known. - Messages in brackets are optional. - Messages in braces are encrypted. + Messages in braces are encrypted with a handshake traffic secret, + messages in brackets are records protected with an application + traffic secret. </t> <figure anchor="figure_swimlane" title="Overview over the Handshake Protocol Flow."> <artwork name="" type="" align="left" alt=""><![CDATA[ Initiator Responder sk_I | | sk_R -sk_e | | -r_I | | pk_R | | -c_R | | -ss_e | | -ss_R | | - | | +sk_e | | | InitiatorHello: | | r_I | | pk_e | - | c_R | | H(pk_R) | - | {pk_I,pc_I,svcinfo_I}ETS | +---------------------------------------------->| - | | r_R - | | r_I - | | pk_I - | | c_R - | | c_I - | | c_e - | | ss_R - | | ss_I - | | ss_e + | | pk_e (peer) + | | DHE | ResponderHello: | | r_R | - | c_e | - | {c_I,pc_R,svcinfo_R}RHTS | + | pk_e | + | sig_R | + | {pc_R,svcinfo_R}RHTS | | {finished_R}RHTS | -r_R | | -c_I | | -c_e | | -ss_I | | -ss_e | | + |<----------------------------------------------+ +DHE | | | InitiatorDone: | + | sig_I | | {finished_I}IHTS | - | [ACK]IATS | +---------------------------------------------->| | | - | | | [ACK]RATS | |<----------------------------------------------+ | | - | | | [Application Payload] | |<--------------------------------------------->| | | @@ -246,179 +304,269 @@ ss_e | | ]]></artwork> </figure> <t> - Notice how we do not need any acknowledgement messages until after finished<sub>R</sub> (after 1 RTT). - We use the ACKs in the handshake as explicit key confirmations. - The InitiatorHello message is a single flight that is implicitly ack'ed with ResponderHello. - ResponderHello is a single flight that is implicitly ack'ed with finished<sub>I</sub>. - The reason why this works is because CAKE groups the messages in row 3 of Table 1 in <xref target="RFC9147" section="5.7"/> into a single message (ResponderHello). - Hence the only message that is sent without any expected response (and consequently requiring an explicit ACK) is finished<sub>I</sub> (and Heartbeats). + As in DTLS 1.3, every flight but the last is implicitly + acknowledged by the next one: the InitiatorHello by the + ResponderHello, and the ResponderHello by the InitiatorDone. + The InitiatorDone, the initiator's final flight, is acknowledged + by the responder with an ACK record + (<xref target="RFC9147" section="5.8.1"/>). pc<sub>X</sub> are 16 bit fields that indicate the peer class (FIXME peer class section). - N<sub>I</sub> is a nonce generated by the initiator. - N<sub>R</sub> is a nonce generated by the responder. + r<sub>I</sub> and r<sub>R</sub> are 64-bit random nonces of the + initiator and of the responder. </t> <t> - The Initiator creates the InitiatorHello message which includes the encrypted tuple (pk<sub>I</sub>,svcinfo_I). - The fields are encrypted using a key derived from the ETS according to <xref target="figure_swimlane"/> - and <xref target="figure_key_schedule"/>. - The so-called Responder KEM Challenge c<sub>R</sub> and the nonce r<sub>I</sub> are computed as: + The initiator creates the InitiatorHello message: </t> <ol> - <li>(ss<sub>R</sub>,c<sub>R</sub>) &lt;- Encaps(pk<sub>R</sub>). Reciver KEM Challenge.</li> + <li>(sk<sub>e</sub>,pk<sub>e</sub>) &lt;- GenerateKeyPair(). Ephemeral X25519 key pair.</li> <li>r<sub>I</sub> &lt;- RandomUInt64(). Initiator nonce.</li> - <li>Encrypt pk<sub>I</sub> and svcinfo<sub>I</sub> using ETS (seq=0).</li> + <li>H(pk<sub>R</sub>). The responder identity is known from the peer identity and the <tt>HELLO</tt>.</li> </ol> <t> - R processes the InitiatorHello as follows: + The InitiatorHello is sent in plaintext: with a signed ephemeral key + exchange there is no static secret to protect it with, and its + fields are not secret. R processes the InitiatorHello as follows: </t> <ol> <li>Verify that the message type is CORE_INITIATOR_HELLO. See Message Header.</li> - <li>Verify that H(pk_R) matches R's pk_R.</li> - <li>(ss<sub>R</sub>,c<sub>R</sub>) &lt;- Decaps(sk<sub>R</sub>, c<sub>R</sub>). Response to Responder KEM Challenge.</li> - <li>(ss<sub>e</sub>,c<sub>e</sub>) &lt;- Encaps(pk<sub>e</sub>). Ephemeral shared secret.</li> - <li>Generate ETS from <xref target="key_schedule"/> and decrypt pk<sub>I</sub>. pk<sub>I</sub> and svcinfo_I may be processed now.</li> - <li>(ss<sub>I</sub>,c<sub>I</sub>) &lt;- Encaps(pk<sub>I</sub>). Initiator KEM Challenge.</li> - <li>Generate RHTS and RATS from <xref target="key_schedule"/>.</li> + <li>Verify that H(pk<sub>R</sub>) matches R's pk<sub>R</sub>.</li> + <li>(sk<sub>e</sub>,pk<sub>e</sub>) &lt;- GenerateKeyPair(). R's ephemeral X25519 key pair.</li> + <li>DHE &lt;- ECDH(sk<sub>e</sub>, pk<sub>e</sub>). Ephemeral shared secret, see <xref target="ecdh"/>.</li> + <li>Derive ES, HS, IHTS and RHTS (<xref target="key_schedule"/>).</li> </ol> <t> - The ETS, the Handshake and Master Secrets are generated according to <xref target="figure_key_schedule"/>. - Note that IATS cannot be derived (yet) at this point. - R may now generate its ResponderHello message: + Note that IATS<sub>0</sub> cannot be derived (yet) at this point. + R now generates its ResponderHello message: </t> <ol> <li>r<sub>R</sub> &lt;- RandomUInt64(). Responder nonce.</li> - <li>Encrypt svcinfo_R and c<sub>I</sub> (Initiator KEM Challenge) using RHTS (seq=0).</li> - <li>Create finished<sub>R</sub> as per <xref target="cake_hs_proto"/>.</li> - <li>Encrypt finished<sub>R</sub> with RHTS (seq=1).</li> - <li>Optionally, R may now already send application data encrypted with RATS.</li> + <li>sig<sub>R</sub> &lt;- Sign(sk<sub>R</sub>, context<sub>R</sub> || Transcript-Hash(T(pk<sub>e</sub>))). See <xref target="ed25519"/>.</li> + <li>Encrypt pc<sub>R</sub> and svcinfo<sub>R</sub> with RHTS (sequence number 0).</li> + <li>Create finished<sub>R</sub> as per <xref target="finished_field"/> + and encrypt it with RHTS (sequence number 1).</li> + <li>Derive RATS<sub>0</sub>.</li> </ol> <t> - I processes the message received by R: + I processes the ResponderHello: </t> <ol> - <li>Verify that the message type is CORE_Responder_HELLO. See Message Header</li> - <li>ss<sub>e</sub> &lt;- Decaps(sk<sub>e</sub>,c<sub>e</sub>). Ephemeral shared secret.</li> - <li>Generate IHTS and RHTS from <xref target="key_schedule"/> and decrypt svcinfo_R, c<sub>I</sub> and finished<sub>R</sub>.</li> - <li>ss<sub>I</sub> &lt;- Decaps(sk<sub>I</sub>,c<sub>I</sub>). Response to KEM Challenge</li> - <li>Create finished<sub>R</sub> as per <xref target="cake_hs_proto"/> and check against decrypted payload.</li> - <li>Create finished<sub>I</sub> as per <xref target="cake_hs_proto"/>.</li> - <li>Send finished<sub>I</sub> message encrypted with the key derived from IHTS (seq=0) to R</li> + <li>Verify that the message type is CORE_RESPONDER_HELLO. See Message Header.</li> + <li>DHE &lt;- ECDH(sk<sub>e</sub>, pk<sub>e</sub>). Ephemeral shared secret, see <xref target="ecdh"/>.</li> + <li>Derive HS, IHTS and RHTS and decrypt pc<sub>R</sub>, svcinfo<sub>R</sub> and finished<sub>R</sub>.</li> + <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> + <li>Verify finished<sub>R</sub> (<xref target="finished_field"/>).</li> + <li>Derive RATS<sub>0</sub>, create finished<sub>I</sub>, sign + sig<sub>I</sub> &lt;- Sign(sk<sub>I</sub>, context<sub>I</sub> || Transcript-Hash(T(finished<sub>R</sub>))) and send + the InitiatorDone: finished<sub>I</sub> encrypted with IHTS + (sequence number 0).</li> + <li>Derive IATS<sub>0</sub>. I may now send records protected with IATS<sub>0</sub>.</li> </ol> <t> - At this point we have a secure channel. + R processes the InitiatorDone: it verifies sig<sub>I</sub> against + pk<sub>I</sub> (the initiator identity, as known from the transport) + over Transcript-Hash(T(finished<sub>R</sub>)), decrypts and verifies + finished<sub>I</sub>, derives IATS<sub>0</sub> and answers with an + ACK record protected with RATS<sub>0</sub>. At this point R has a + secure channel with I. I has one once it has received a + record that deprotects under RATS<sub>0</sub> (or a later + RATS<sub>N</sub>), normally that ACK. </t> <t> - Note that for the handshake we do not use epochs or sequence numbers. - The reason for this is simple: DTLS uses epoch 0 for plaintext messages. - Epoch 1 is reserved for payload encrypted with a key derived from ETS. - However, we only have a single message that contains such a payload: InitiatorHello. - Epoch 2 is reserved for payload encrypted with a key derived from *HTS. + The following rules are not optional. Each of them protects an + existing association against an attacker that can inject + messages: + </t> + <ul> + <li>A handshake message that fails any of the checks above, or + does not decrypt, MUST be discarded without changing any state; + in particular it MUST NOT stop the retransmission of the + receiver's own last flight.</li> + <li>R MUST NOT consider I authenticated, MUST NOT deliver any data + received from I, and MUST NOT protect any record with + RATS<sub>0</sub> before it has verified finished<sub>I</sub>. + (Hence the first record under RATS<sub>0</sub> confirms the + handshake to I.)</li> + <li>If R already has an association with I, it MUST continue to + use that association's traffic secrets for sending and receiving + until finished<sub>I</sub> of the new handshake has verified, + and MUST keep the association if the new handshake does not + complete (<xref target="RFC9147" section="5.11"/>).</li> + </ul> + <t> + Note that for the handshake we do not use epochs or sequence numbers on the wire. + The reason for this is simple: DTLS uses epoch 0 for plaintext messages, + and the InitiatorHello is plaintext (there is no ETS, and no 0-RTT). + Epoch 1 is reserved for payload encrypted with a key derived from *HTS. But we only have a single message that contains a payload encrypted with a key derived from RHTS: ResponderHello. We also only have a single message that contains a payload encrypted with a key - derived from IHTS: finished<sub>I</sub>. - Consequently, we do not need any signalling of Epochs until we encrypt data using - *ATS secrets. - The optional application data that may already be sent by the responder after its first - handshake message or by the initiator after its second handshake message, are - already wrapped inside an EncryptedMessage and have both Epoch and sequence numbers set. + derived from IHTS: InitiatorDone. + Consequently, we do not need any signalling of epochs until we encrypt data using + *ATS secrets, and the sequence numbers of the handshake fields are + fixed (RHTS: 0 and 1; IHTS: 0). + Records are wrapped inside an EncryptedMessage + (<xref target="encrypted_message"/>) and carry their epoch and + sequence number. In every epoch, the sequence numbers of a peer + start at 0. </t> </section> <section anchor="key_schedule" numbered="true" toc="default"> <name>Key Schedule</name> <t> - The key schedule is very similar to <xref target="RFC8446"/> Section 7.1: - </t> - <figure anchor="figure_key_schedule" title="The Key Schedule."> - <artwork name="" type="" align="left" alt=""><![CDATA[ -HKDF-Extract(ss_R,0) = Early Secret (ES) - | - +-----> HKDF-Expand-Label(., - | "early data", - | H(T(H(pk_R)))) - | = Early Transport Secret (ETS) - | - v -HKDF-Expand-Label(., - | "derived", - | "") = derived Early Secret (dES) - | - v -HKDF-Extract(ss_e,.) = Handshake Secret (HS) - | - +-----> HKDF-Expand-Label(., - | "i hs traffic", - | H(T(r_R))) - | = IHTS - | - +-----> HKDF-Expand-Label(., - | "r hs traffic", - | H(T(r_R))) - | = RHTS - v -HKDF-Expand-Label(., - | "derived", - | "") = derived Handshake Secret (dHS) - | - v -HKDF-Extract(ss_I,.) = Master Secret (MS) - | - +-----> HKDF-Expand-Label(., - | "i ap traffic", - | H(T({finished_I}))) - | = IATS_0 - | - +-----> HKDF-Expand-Label(., - "r ap traffic", - H(T({finished_R}))) - = RATS_0 - ]]></artwork> + The key schedule is that of <xref target="RFC8446" section="7.1"/>, + with a single ephemeral X25519 shared secret (DHE) as the only + non-zero input, as in TLS 1.3 without a PSK. As there, HKDF-Extract + is drawn as taking the Salt argument from the top and the IKM + argument from the left, its output is shown to the right, and "0" + is a string of Hash.length zero bytes: + </t> + <figure anchor="figure_key_schedule" title="The Key Schedule."> + <artwork name="" type="" align="left" alt=""><![CDATA[ + 0 + | + v + 0 -> HKDF-Extract = Early Secret (ES) + | + v + Derive-Secret(., "derived", "") + | + v + DHE -> HKDF-Extract = Handshake Secret (HS) + | + +-----> Derive-Secret(., "i hs traffic", + | InitiatorHello...pk_e_R) + | = IHTS + | + +-----> Derive-Secret(., "r hs traffic", + | InitiatorHello...pk_e_R) + | = RHTS + v + Derive-Secret(., "derived", "") + | + v + 0 -> HKDF-Extract = Master Secret (MS) + | + +-----> Derive-Secret(., "r ap traffic", + | InitiatorHello...ResponderHello) + | = RATS_0 + | + +-----> Derive-Secret(., "i ap traffic", + InitiatorHello...InitiatorDone) + = IATS_0 + ]]></artwork> </figure> <t> - "." shows the argument position of the input variable from the incoming arrow. + As in <xref target="RFC8446"/>, Derive-Secret(Secret, Label, Messages) + is HKDF-Expand-Label(Secret, Label, Transcript-Hash(Messages), + Hash.length), and the context of "derived" is the hash of the + empty string. The transcripts are those of <xref target="transcript"/>: + "InitiatorHello...pk<sub>e</sub><sub>R</sub>" is T(pk<sub>e</sub><sub>R</sub>) + (both ephemeral keys declared), + "InitiatorHello...ResponderHello" is T(finished<sub>R</sub>), and + "InitiatorHello...InitiatorDone" is T(finished<sub>I</sub>). </t> + <t> + The Early Secret and the Master Secret take zero IKM, since CAKE has + no PSK and no second KEM. The only secret input to the key schedule + is DHE, which provides forward secrecy; sk<sub>e</sub> MUST be fresh + for every handshake. The long-term identity keys do not enter the + key schedule: they authenticate the ephemeral keys through + sig<sub>R</sub> and sig<sub>I</sub> (<xref target="ed25519"/>), + and the Finished fields provide key confirmation. As in TLS 1.3, + each application traffic secret is derived from the transcript up to + its sender's Finished. + </t> + <section anchor="transcript" numbered="true" toc="default"> + <name>Transcript</name> + <t> + As in TLS 1.3 (<xref target="RFC8446" section="4.4.1"/>), the + transcript is made of the plaintext of the handshake messages, not + of the bytes on the wire. It is the concatenation of the + InitiatorHello, ResponderHello and InitiatorDone of the handshake, + each starting with its message header, with every encrypted field + in plaintext and without the AEAD tags. Everything else is as + sent, including the message headers, whose Size counts the tags. + T(X) is the transcript up to and including the field X: + </t> + <ul> + <li>T(pk<sub>e</sub><sub>R</sub>) is the InitiatorHello followed + by the ResponderHello up to and including the responder's + ephemeral key pk<sub>e</sub>. (The InitiatorHello is plaintext; + this is the point at which both ephemeral keys are on the + transcript.) Transcript-Hash of this is what sig<sub>R</sub> + signs and what *HTS are derived from.</li> + <li>T(sig<sub>R</sub>) is that plus the responder's signature + sig<sub>R</sub>.</li> + <li>T(svcinfo<sub>R</sub>) additionally includes pc<sub>R</sub> + and svcinfo<sub>R</sub>. Transcript-Hash of this is what + finished<sub>R</sub> covers.</li> + <li>T(finished<sub>R</sub>) is the InitiatorHello followed by + the ResponderHello (its full plaintext). Transcript-Hash of + this is what sig<sub>I</sub> signs.</li> + <li>T(sig<sub>I</sub>) is that plus the InitiatorDone up to and + including sig<sub>I</sub>. Transcript-Hash of this is what + finished<sub>I</sub> covers.</li> + <li>T(finished<sub>I</sub>) is the InitiatorHello followed by + the ResponderHello and the InitiatorDone (its full plaintext).</li> + </ul> + <t> + The peers thus confirm what they said, independently of how it was + protected on the wire, which is what the analysis of TLS 1.3 + assumes. The Size fields delimit the messages and with them + the services infos, so the transcript needs no further framing. + Retransmissions are byte-identical copies and are not part of the + transcript. + </t> + </section> + <section anchor="traffic_keys" numbered="true" toc="default"> + <name>Traffic Keys and Key Updates</name> <t> - In general the transcript hashes are part of the HKDF-Expand calls. - The transcript hash is defined as the hash over the message parts sent (or to be sent) and received on the wire - up until that point. - </t> - <t> - Notice that from the very beginning ss<sub>R</sub> is required for the key schedule. - This means that R must be able to solve the Responder KEM Challenge c<sub>R</sub>. - Similarly, the master secret (MS) requires knowledge of ss<sub>I</sub>. - This means that I must be able to solve the Initiator KEM Challenge c<sub>I</sub>. - The KEM Challenges provide the underlying public key authentication mechanism. - </t> - <t> - When a traffic secret ([I,R][A,H]TS or ETS) is used to encrypt data, the respective - encryption key and starting nonce is generated as follows: + When a traffic secret TS (IHTS, RHTS, IATS<sub>N</sub> or + RATS<sub>N</sub>) is used to encrypt data, the key and IV are + derived as in <xref target="RFC8446" section="7.3"/>: </t> <figure anchor="figure_traffic_key_derivation" title="Traffic Key Generation."> <artwork name="" type="" align="left" alt=""><![CDATA[ -key = HKDF-Expand-Label [I,R][A,H]TS, "key", 32) -nonce = HKDF-Expand-Label ([I,R][A,H]TS, "iv", 24) +key = HKDF-Expand-Label(TS, "key", "", 32) +iv = HKDF-Expand-Label(TS, "iv", "", 24) ]]></artwork> </figure> <t> - Notice that the per-message nonce is generated from the nonce above - as defined in <xref target="RFC8446" section="5.3"/> from the sequence number. + The per-record nonce is generated from the IV and the sequence + number as in <xref target="RFC8446" section="5.3"/>: the + 64-bit sequence number in network byte order, left-padded with + zeros to 24 bytes, is XORed with the IV. + The AEAD is XChaCha20-Poly1305 (<xref target="primitives"/>), + with empty associated data. + Nothing is ever encrypted twice with the same key and nonce: + retransmitted handshake messages are byte-identical copies, not + re-encryptions. </t> <t> - After a successful initial handshake, both initiator and responder may - update the application traffic secrets ([A,I]ATS) and generate new keys. - Let [I,R]ATS<sub>0</sub> be the initial secrets with index 0. - The next secret is derived as: + After the handshake, both initiator and responder may + update their application traffic secrets and generate new keys, + as in <xref target="RFC8446" section="7.2"/>: </t> <figure anchor="figure_traffic_key_derivation_next" title="Traffic Secret Update."> <artwork name="" type="" align="left" alt=""><![CDATA[ -[I,R]ATS_N+1 = HKDF-Expand-Label ([I,R]ATS_N, - "traffic_upd", - secret_len) +[I,R]ATS_N+1 = HKDF-Expand-Label([I,R]ATS_N, "traffic upd", "", + Hash.length) ]]></artwork> </figure> <t> - When a peer wants to update keys, it sends a key update message <xref target="heartbeat_msg"/>. + The index N is the epoch of <xref target="encrypted_message"/>. + A peer moves to its next epoch on its own accord (the GNUnet + implementation does so every 12 hours, and before its sequence + numbers are exhausted), or when asked to with a Heartbeat + (<xref target="heartbeat_msg"/>). The receiver learns about it + from the epoch of the records. Unlike in DTLS 1.3, there is no + KeyUpdate message to acknowledge, and the sender does not wait + before it uses its new keys: the full epoch is part of every + record, so the receiver can always tell which keys a record was + protected with. Implementations <bcp14>SHOULD</bcp14> delete old traffic secrets and their derived keys. </t> + </section> </section> <section anchor="cake_hs_proto" numbered="true" toc="default"> <name>The CAKE Handshake Protocol</name> @@ -429,8 +577,27 @@ nonce = HKDF-Expand-Label ([I,R][A,H]TS, "iv", 24) <name>Timeout and Retransmission</name> <t> CAKE reuses the logic for timeout and retransmission from <xref target="RFC9147" section="5.8"/>. - It differs in that large flight sizes are not of concern for CAKE. - Similarly, the only Post-Handshake message relevant for CAKE is the KeyUpdate message. + It differs in that large flight sizes are not of concern for CAKE, + since each flight is a single message. The initiator retransmits + its InitiatorHello until it receives a ResponderHello that + verifies, and its InitiatorDone until it receives a record that + deprotects under the new RATS. The responder retransmits its + ResponderHello until it receives an InitiatorDone that verifies. + A peer that receives a retransmission of the flight it has + already answered retransmits its answer: the responder its + ResponderHello for a copy of the InitiatorHello it is answering, + the initiator its InitiatorDone for a copy of the ResponderHello + it has accepted, and the responder its ACK for an InitiatorDone + once the handshake is complete + (<xref target="RFC9147" section="5.8.1"/>). + </t> + <t> + The GNUnet implementation uses an initial timer of 1 second, + doubles it with each retransmission up to 60 seconds + (<xref target="RFC9147" section="5.8.2"/>), and gives up + on a flight after 5 retransmissions, starting over with a new + handshake. A responder that gives up on a handshake started over + an existing association keeps that association. </t> </section> <section anchor="crypto_label" numbered="true" toc="default"> @@ -439,6 +606,26 @@ nonce = HKDF-Expand-Label ([I,R][A,H]TS, "iv", 24) <xref target="RFC8446" section="7.1"/> specifies that HKDF-Expand-Label uses a label prefix of "tls13 ". For CAKE, that label <bcp14>SHALL</bcp14> be "cake10". This ensures key separation between CAKE, DTLS 1.3 and TLS 1.3. + As with the "dtls13" of <xref target="RFC9147" section="5.9"/>, + there is no trailing space; this keeps the overall label size + inside of one hash iteration. For clarity: + </t> + <figure anchor="figure_expand_label" title="HKDF-Expand-Label."> + <artwork name="" type="" align="left" alt=""><![CDATA[ +HKDF-Expand-Label(Secret, Label, Context, Length) = + HKDF-Expand(Secret, HkdfLabel, Length) + +struct { + uint16 length = Length; + opaque label<7..255> = "cake10" + Label; + opaque context<0..255> = Context; +} HkdfLabel; + ]]></artwork> + </figure> + <t> + The labels CAKE uses are "derived", + "i hs traffic", "r hs traffic", "r ap traffic", "i ap traffic", + "r finished", "i finished", "key", "iv", "sn" and "traffic upd". </t> </section> <section anchor="svcinfo" numbered="true" toc="default"> @@ -447,24 +634,97 @@ nonce = HKDF-Expand-Label ([I,R][A,H]TS, "iv", 24) The svcinfo field is a string consisting of key-value pairs separated by a separator indicating supported services and their versions. E.g. "dht:1.1;cadet:0.4". - The field is zero terminated. + It extends to the end of the encrypted field it is in, and has + no terminator. It may be empty. </t> </section> <section anchor="finished_field" numbered="true" toc="default"> <name>Finished Field</name> <t> - The HandshakeFinished field contains either finished<sub>I</sub> - or finished<sub>R</sub> value: + As in TLS 1.3 (<xref target="RFC8446" section="4.4.4"/>), the + finished keys are derived from the handshake traffic secrets, not + from MS. The signatures sig<sub>R</sub> and sig<sub>I</sub> + (<xref target="ed25519"/>) authenticate the peers; the Finished + fields provide key confirmation over the transcript: </t> <ol> - <li>fk<sub>I</sub> &lt;- HKDF-Expand-Label(MS, "i finished", NULL)</li> - <li>finished<sub>I</sub> &lt;- HMAC(fk<sub>I</sub>, H(T({finished<sub>R</sub>})))</li> + <li>fk<sub>R</sub> &lt;- HKDF-Expand-Label(RHTS, "r finished", "", Hash.length)</li> + <li>finished<sub>R</sub> &lt;- HMAC(fk<sub>R</sub>, Transcript-Hash(svcinfo<sub>R</sub>))</li> </ol> <ol> - <li>fk<sub>R</sub> &lt;- HKDF-Expand-Label(MS, "r finished", NULL)</li> - <li>finished<sub>R</sub> &lt;- HMAC(fk<sub>R</sub>, H(T({svcinfo_R,c_I}))</li> + <li>fk<sub>I</sub> &lt;- HKDF-Expand-Label(IHTS, "i finished", "", Hash.length)</li> + <li>finished<sub>I</sub> &lt;- HMAC(fk<sub>I</sub>, Transcript-Hash(sig<sub>I</sub>))</li> </ol> + <t> + Both are Hash.length (32) bytes long. Receivers + <bcp14>SHOULD</bcp14> compare them in constant time. + </t> + </section> + <section anchor="primitives" numbered="true" toc="default"> + <name>Algorithms</name> + <t> + CAKE has no algorithm negotiation. It uses: + </t> + <ul> + <li>Hash: SHA-256, for the transcript hash, H(pk), HKDF and HMAC. + Hash.length is 32.</li> + <li>AEAD: XChaCha20-Poly1305 <xref target="XCHACHA"/>, with a + 32-byte key, a 24-byte nonce and a 16-byte tag, and empty + associated data. It is ChaCha20-Poly1305 + (<xref target="RFC8439"/>), which TLS 1.3 uses, with an extended + nonce; CAKE does not need the longer nonce, since its nonces are + counters (see <xref target="open"/>).</li> + <li>Sequence number encryption: ChaCha20 <xref target="RFC8439"/> + (<xref target="encrypted_message"/>).</li> + <li>ECDH: see <xref target="ecdh"/>.</li> + <li>Signature: see <xref target="ed25519"/>.</li> + </ul> + <section anchor="ecdh" numbered="true" toc="default"> + <name>ECDH</name> + <t> + DHE is the shared secret of X25519 (<xref target="RFC7748"/>) + computed from the two peers' ephemeral keys. Each peer + generates a fresh X25519 key pair (sk<sub>e</sub>, pk<sub>e</sub>) + for every handshake; pk<sub>e</sub> is 32 bytes. DHE is the + single secret input to the key schedule + (<xref target="key_schedule"/>) and provides forward secrecy + once sk<sub>e</sub> is erased. Implementations MUST reject the + all-zero shared secret. + </t> + </section> + <section anchor="ed25519" numbered="true" toc="default"> + <name>Ed25519 Signatures</name> + <t> + sig<sub>R</sub> and sig<sub>I</sub> are Ed25519 signatures + (<xref target="RFC8032"/>) made with the peers' long-term + identity keys (the Ed25519 public keys that are the peer + identities), the analogue of the CertificateVerify of TLS 1.3 + (<xref target="RFC8446" section="4.4.3"/>). They are 64 bytes. + The signed content is, as in TLS 1.3, 64 zero bytes followed by a + context string and a single 0x00 byte, followed by the + transcript hash: + </t> + <ul> + <li>sig<sub>R</sub> = Sign(sk<sub>R</sub>, 0x00*64 || + "CAKE responder signed ephemeral" || 0x00 || + Transcript-Hash(T(pk<sub>e</sub>)))</li> + <li>sig<sub>I</sub> = Sign(sk<sub>I</sub>, 0x00*64 || + "CAKE initiator signed ephemeral" || 0x00 || + Transcript-Hash(T(finished<sub>R</sub>)))</li> + </ul> + <t> + The context strings differ so that a signature over one + transcript point cannot be reused for the other, and so that + CAKE signatures are disjoint from any other use of the identity + key (e.g. HELLO signatures). The signature is verified against + the peer identity as known from the transport: the responder + verifies sig<sub>R</sub> against pk<sub>R</sub>, and the + initiator verifies sig<sub>I</sub> against pk<sub>I</sub>, the + identity of the peer the ResponderHello resp. InitiatorHello was + received from. + </t> </section> + </section> <section anchor="cake_hs_msg_fmt" numbered="true" toc="default"> <name>CAKE Message Format</name> <t> @@ -472,106 +732,145 @@ nonce = HKDF-Expand-Label ([I,R][A,H]TS, "iv", 24) </t> <figure anchor="figure_msghdr" title="The Wire Format of the Message Header."> <artwork name="" type="" align="left" alt=""><![CDATA[ - 0 8 16 24 32 40 48 56 - +-----+-----+-----+-----+-----+-----+-----+-----+ - | Size | Type (0xXX) | - +-----+-----+-----+-----+-----+-----+-----+-----+ + 0 8 16 24 32 + +-----+-----+-----+-----+ + | Size | Type | + +-----+-----+-----+-----+ ]]></artwork> </figure> <dl> - <dt>size:</dt> <dd>The size of the message including the Size and Type fields.</dd> - <dt>type:</dt> <dd>The message type.</dd> + <dt>Size:</dt> <dd>The size of the message including the Size and Type fields, 16 bits in network byte order.</dd> + <dt>Type:</dt> <dd>The message type, 16 bits in network byte order.</dd> </dl> <t> + All multi-byte integers are in network byte order, and all + structures are packed (there is no padding other than the + explicit "Reserved" fields). The possible types of messages are: </t> <ul> - <li>InitiatorHello</li> - <li>ResponderHello</li> - <li>InitiatorDone</li> - <li>EncryptedMessage</li> + <li>InitiatorHello (80, CORE_INITIATOR_HELLO)</li> + <li>ResponderHello (81, CORE_RESPONDER_HELLO)</li> + <li>InitiatorDone (82, CORE_INITIATOR_DONE)</li> + <li>EncryptedMessage (83, CORE_ENCRYPTED_MESSAGE)</li> </ul> <t> - An encrypted message also always starts with a MessageHeader - and the allowed types are: + The payload of an EncryptedMessage is a sequence of messages that + also always start with a MessageHeader. It is either a single + Heartbeat (84, CORE_HEARTBEAT), a single ACK (85, CORE_ACK), or + application data: one or more messages of other types. </t> - <ul> - <li>Hearbeat</li> - <li>Ack</li> - <li>ApplicationData</li> - </ul> </section> <section anchor="initiator_hello" numbered="true" toc="default"> <name>InitiatorHello Message</name> - <t> - The InitiatorHello: - </t> <figure anchor="figure_inithello" title="The Wire Format of the InitiatorHello."> <artwork name="" type="" align="left" alt=""><![CDATA[ 0 8 16 24 32 40 48 56 +-----+-----+-----+-----+-----+-----+-----+-----+ - | r_I | + | Size | Type (80) | Reserved | +-----+-----+-----+-----+-----+-----+-----+-----+ - | pk_e | - | | - | | + | r_I | +-----+-----+-----+-----+-----+-----+-----+-----+ - | c_R | - | | - | | - | | + | pk_e (256 bit) | + / / +-----+-----+-----+-----+-----+-----+-----+-----+ - | H(pk_R) (512 bit) | + | H(pk_R) (256 bit) | / / - | | +-----+-----+-----+-----+-----+-----+-----+-----+ - / {pk_I,pc_I,svcinfo_I} / ]]></artwork> </figure> <t> - The initiator kem challenge c<sub>R</sub> is generated according to <xref target="figure_key_schedule"/> using: - </t> - <ol> - <li>(ss<sub>R</sub>,c<sub>R</sub>) &lt;- Encaps(pk<sub>R</sub>)</li> - </ol> - <t> - The pk<sub>I</sub> and <tt>ServiceInfo</tt> are encrypted using XChaCha20-Poly1305 <xref target="RFC8439"/> - with key and IV derived from the ETS. - <!-- FIXME: Discuss IV. We may be able to use data from HKDF-Expand for that --> + The Reserved field <bcp14>MUST</bcp14> be zero when sent and is + ignored on receipt (it is covered by the transcript); it keeps + r<sub>I</sub> aligned. The InitiatorHello is sent in plaintext: + there is no ETS and no encrypted payload. It is exactly + 80 bytes long, and receivers <bcp14>MUST</bcp14> discard other sizes. </t> </section> <section anchor="responder_hello" numbered="true" toc="default"> <name>ResponderHello Message</name> - <t> - The ResponderHello: - </t> <figure anchor="figure_recvhello" title="The Wire Format of the ResponderHello."> <artwork name="" type="" align="left" alt=""><![CDATA[ 0 8 16 24 32 40 48 56 +-----+-----+-----+-----+-----+-----+-----+-----+ + | Size | Type (81) | Reserved | + +-----+-----+-----+-----+-----+-----+-----+-----+ | r_R | +-----+-----+-----+-----+-----+-----+-----+-----+ - | c_e | - | | + | pk_e (256 bit) | + / / + +-----+-----+-----+-----+-----+-----+-----+-----+ + | sig_R (512 bit) | + / / + / / + / / + / / + / / + / / + / / + +-----+-----+-----+-----+-----+-----+-----+-----+ + | pc_R (enc)| svcinfo_R (encrypted) / + +-----+-----+ / + / / + +-----+-----+-----+-----+-----+-----+-----+-----+ + | Tag (128 bit) | | | + +-----+-----+-----+-----+-----+-----+-----+-----+ + | finished_R (256 bit, enc) | + / / + +-----+-----+-----+-----+-----+-----+-----+-----+ + | Tag (128 bit) | | | +-----+-----+-----+-----+-----+-----+-----+-----+ - / {c_I,pc_I,svcinfo_R}{finished_R} / ]]></artwork> </figure> <t> - The protected fields after the nonce are encrypted using a key derived from AHTS. - The finished<sub>R</sub> is encrypted individually. - This is because the transcript of the ResponderHello to generate the - finished<sub>R</sub> must end before it. + The Reserved field is as in the InitiatorHello. + sig<sub>R</sub> is the responder's Ed25519 signature over + Transcript-Hash(T(pk<sub>e</sub>)); it is sent in plaintext + (<xref target="ed25519"/>). + pc<sub>R</sub> and svcinfo<sub>R</sub> are encrypted + with RHTS, sequence number 0. + finished<sub>R</sub> is encrypted individually, with RHTS and + sequence number 1, because its transcript ends before it. + The receiver finds finished<sub>R</sub> at the end of the message: + svcinfo<sub>R</sub> extends up to 48 bytes (finished<sub>R</sub> + and its tag) before the end. The message is at least 178 bytes + long. </t> </section> <section anchor="handshake_finished" numbered="true" toc="default"> <name>InitiatorDone Message</name> + <figure anchor="figure_initdone" title="The Wire Format of the InitiatorDone."> + <artwork name="" type="" align="left" alt=""><![CDATA[ + 0 8 16 24 32 40 48 56 + +-----+-----+-----+-----+-----+-----+-----+-----+ + | Size | Type (82) | Reserved | + +-----+-----+-----+-----+-----+-----+-----+-----+ + | sig_I (512 bit) | + / / + / / + / / + / / + / / + / / + / / + +-----+-----+-----+-----+-----+-----+-----+-----+ + | finished_I (256 bit, enc) | + / / + +-----+-----+-----+-----+-----+-----+-----+-----+ + | Tag (128 bit) | + | | + +-----+-----+-----+-----+-----+-----+-----+-----+ + ]]></artwork> + </figure> <t> - The InitiatorDone message contains the finished<sub>I</sub> field - encrypted with a key derived from the IHTS. - The message type <bcp14>MUST</bcp14> be CORE_INITIATOR_DONE. + The InitiatorDone carries sig<sub>I</sub>, the initiator's Ed25519 + signature over Transcript-Hash(T(finished<sub>R</sub>)), in + plaintext (<xref target="ed25519"/>), followed by + finished<sub>I</sub> encrypted with IHTS (sequence number 0). It + is exactly 120 bytes long, and receivers <bcp14>MUST</bcp14> + discard other sizes. </t> </section> <section anchor="encrypted_message" numbered="true" toc="default"> @@ -585,7 +884,7 @@ nonce = HKDF-Expand-Label ([I,R][A,H]TS, "iv", 24) +-----+-----+-----+-----+-----+-----+-----+-----+ | Epoch | +-----+-----+-----+-----+-----+-----+-----+-----+ -| Sequence Number | +| Sequence Number (encrypted) | +-----+-----+-----+-----+-----+-----+-----+-----+ | Tag | | | @@ -593,74 +892,96 @@ nonce = HKDF-Expand-Label ([I,R][A,H]TS, "iv", 24) ]]></artwork> </figure> <t> + The Tag is followed by the payload, encrypted with the key and + nonce of <xref target="traffic_keys"/> for the sender's traffic + secret of the epoch ([I,R]ATS<sub>Epoch</sub>) and the sequence + number. The length of the payload is given by the Size field of + the MessageHeader preceding the EncryptedMessage header. + </t> + <t> + The Epoch is sent in plaintext. Neither it nor the Sequence Number + is associated data; both are authenticated implicitly, since the + epoch selects the key and the sequence number determines the + nonce: a record whose epoch or sequence number was tampered with + fails to deprotect. + </t> + <t> The epoch starts at 0 after the handshake with the first *ATS secret. - Any peer may at any time update to a new epoch. + Any peer may at any time update to a new epoch + (<xref target="traffic_keys"/>). Peers may keep a history of secrets for respective epochs at their own discretion in order to handle out-of-order message deliveries. - Unlike DTLS1.3 in CAKE does not truncate the epoch and no reconstruction is - necessary, hence the epoch may be bumped by peers at their own discretion without - explicit key update mechanisms. - A peer may consider the epoch too old or too far in the future and reject description. + Unlike DTLS 1.3, CAKE does not truncate the epoch and no reconstruction is + necessary. + A peer may consider the epoch too old or too far in the future and reject decryption. For this purpose, a peer may manage a sliding window of epochs that can be used - by the other peer. + by the other peer. (The GNUnet implementation keeps the secrets of + the 10 most recent epochs of its peer, and does not ratchet forward + more than 20 epochs at a time.) + A peer <bcp14>MUST NOT</bcp14> let its epoch or its sequence + numbers wrap; it starts a new handshake instead. </t> <t> - The sequence number is encrypted as defined in <xref target="RFC9147" section="4.2.3"/> - for ChaCha20-based AEAD schemes. - For clarity, the XOR-based encryption using the 64 byte output of ChaCha20 is as follows: - The Tag is divided into a 32-bit counter and 96-bit nonce for use with ChaCha20. - The key is derived from the *ats as follows: + Receivers <bcp14>MUST</bcp14> keep an anti-replay window per epoch + as in <xref target="RFC9147" section="4.5.1"/>. Since the epoch is + not authenticated before the record deprotects, receivers + <bcp14>MUST NOT</bcp14> change any state -- the anti-replay + windows, the traffic secrets they keep, the newest epoch seen -- + on account of a record before it has deprotected successfully. + (Otherwise a single forged record claiming a later epoch could + reset the anti-replay windows of epochs still in use, after which + their records could be replayed.) + Records that do not deprotect are silently discarded. </t> - <figure anchor="figure_sn_key_derivation" title="Traffic Key Generation."> - <artwork name="" type="" align="left" alt=""><![CDATA[ -sn_secret = HKDF-Expand-Label [I,R]ATS_N, "sn", 32) - ]]></artwork> - </figure> <t> - Where [I,R]ATS_N is the respective ATS secret of epoch N. - The leading 8 bytes of the 64 byte output of ChaCha20 are then - XORed with the sequence number in network byte order: + The sequence number is encrypted as defined in <xref target="RFC9147" section="4.2.3"/> + for ChaCha20-based AEAD schemes, with the Tag as the sample: </t> - <figure anchor="figure_sn_xor" title="Traffic Key Generation."> + <figure anchor="figure_sn_xor" title="Sequence Number Encryption."> <artwork name="" type="" align="left" alt=""><![CDATA[ -sn_key = HKDF-Expand-Label(Secret, "sn", "", 8) -mask = ChaCha20(sn_key, Ciphertext[0..3], Ciphertext[4..15]) -sn_enc = mask[0..8] XOR sn_nbo +sn_key = HKDF-Expand-Label([I,R]ATS_N, "sn", "", 32) +mask = ChaCha20(sn_key, Tag[0..3], Tag[4..15]) +sn_enc = mask[0..7] XOR sn ]]></artwork> </figure> <t> - Notice how this requires a ciphertext of at least 16 bytes. - But our ciphertexts are always at least 16 bytes due to the Poly1305 - atuthentication tag. In fact, since the authentication tag is considered - part of the ciphertext, and is prepended in front of the encrypted plaintext, - the mask is always computed on the authentication tag only. - </t> - <t> - The Tag is followed by encrypted application data. - The length of the data is included in the size field of the MessageHeader - preceeding the EncryptedMessage header. - </t> - <t> - The per-message nonce is not transmitted and instead generated as defined in <xref target="RFC8446" section="5.3"/>. - <!-- FIXME the records/encryptions apply to all messages(?)--> + Where [I,R]ATS<sub>N</sub> is the sender's traffic secret of epoch + N, sn is the 64-bit sequence number in network byte order, and + ChaCha20 is the block function of <xref target="RFC8439" section="2.3"/> + with Tag[0..3] as the block counter and Tag[4..15] as the nonce. + As in <xref target="RFC9001" section="5.4.4"/>, the block counter + is Tag[0..3] read as a little-endian integer. + In DTLS 1.3 the sample is the first 16 bytes of the ciphertext; + in CAKE the Tag comes first, so the sample is always the Tag, + and there are always enough bytes to sample. </t> </section> <section anchor="heartbeat_msg" numbered="true" toc="default"> <name>Heartbeat</name> <t> - The HEARTBEAT message is a simple MessageHeader inside an EncryptedMessage with type <tt>CORE_HEARTBEAT</tt> followed by an UpdateRequested indicator. + 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. This means that for every received EncryptedMessage the peer <bcp14>MUST</bcp14> check if this is a Heartbeat. - A Heartbeat message may implicitlyindicate that the sender has switched its - traffic secrets according to the key schedule in <xref target="key_schedule"/>. - If any bit in the UpdateRequested field is set, this means that the responder - of the Heartbeat <bcp14>SHOULD</bcp14> increment its epoch. + If the flag 0x00000001 is set in the UpdateRequested field, the receiver + of the Heartbeat <bcp14>SHOULD</bcp14> move to its next epoch + before it answers; this is the request_update of the KeyUpdate of + <xref target="RFC8446" section="4.6.3"/>. + All other flags are reserved: they <bcp14>MUST</bcp14> be zero + when sent and <bcp14>MUST</bcp14> be ignored on receipt. Any bytes following the UpdateRequested field are updated services info svcinfo (<xref target="svcinfo"/>). - Services info updates are optional. + Services info updates are optional; receivers that do not process + them <bcp14>MUST</bcp14> ignore them. <!-- TODO: Incremental or full ServicesInfo --> </t> - <figure anchor="figure_keyupdate_msg" title="The Wire Format of the EncryptedMessage header."> + <t> + Every Heartbeat <bcp14>MUST</bcp14> be answered with an ACK. A + peer that has not received any record for some time sends a + Heartbeat to probe the association (the GNUnet implementation + does so after 30 seconds, and considers the association dead + after three Heartbeats in a row went unanswered). + </t> + <figure anchor="figure_keyupdate_msg" title="The Wire Format of the Heartbeat."> <artwork name="" type="" align="left" alt=""><![CDATA[ 0 8 16 24 32 +-----+-----+-----+-----+ @@ -678,41 +999,34 @@ sn_enc = mask[0..8] XOR sn_nbo type <tt>CORE_ACK</tt>. This means that for every received EncryptedMessage the peer <bcp14>MUST</bcp14> check if this is an ACK message after decryption. - The peer may use the ACK in order to ensure liveliness of connected peers in - combination with Heartbeats. + The ACK of DTLS 1.3 lists the records it acknowledges; CAKE's ACK + is empty, since it only ever answers one thing: the InitiatorDone + (its first ACK under RATS<sub>0</sub>) or a Heartbeat. + The peer may use the ACK in order to ensure liveness of connected + peers in combination with Heartbeats. </t> </section> </section> <section anchor="open" numbered="true" toc="default"> <name>Open Issues</name> <t> - We must discuss EdDSA vs X25519 KEM usage. Maybe see Communicator draft for this. - Basically, since we also use the EdDSA peer ID key for signing (HELLOs), we offer - any attacker a signing oracle against our X25519 public keys. - This should be safe, but it is not clean. - To solve this, we would have to separate HELLO signing keys and PID KX keys. - This issue did not arise before, because we used signed semi-statix DH keys. + The Ed25519 peer identity key is now used only for signatures + (HELLOs and sig<sub>R</sub>/sig<sub>I</sub>), not for key + encapsulation, so the signing-oracle concern of the earlier KEM-based + design no longer applies. Separating the HELLO signing key from the + peer identity key remains a possible future hardening. </t> <t> - The IETF ChaCha20 version is basically only recommended for use when a specification - or compatibility specifically requires it. - With ChaCha20, we would have to increment the nonce as it cannot be chosen securely at random - (not long enough). - We could actually still use it, and then have to stick to a suitable rekey schedule. - XChaCha20 is the generally recommended cipher for any use case and we use it. - The only downside seems to be that XChaCha20 is practically not specified anywhere - (although it can be trivially defined in this document based on HChaCha) and only really implemented in libsodium. - We could also use XSalsa20 which is better specified (and availiable). We use it already for GNS (EDKEY encryption). + XChaCha20-Poly1305 is specified in <xref target="XCHACHA"/>, which + expired as an Internet-Draft; it may be worth defining it here based + on HChaCha20, or to use ChaCha20-Poly1305 <xref target="RFC8439"/> + as TLS 1.3 does. The objection to ChaCha20-Poly1305 -- that its + nonce is too short to be chosen at random -- does not apply to + CAKE, whose nonces are derived from sequence numbers. + We could also use XSalsa20 which is better specified (and available). We use it already for GNS (EDKEY encryption). </t> <t> - We must define which KEM is to be used. - We may want to use our HPKE Elligator KEM <xref target="LSD0011"/>. - Using Elligator on this level may not be useful unless we also get rid of the plaintext message headers since - those definitely do not look random. - Ergo, the use of elligator probably makes more sense on the communicator level. - </t> - <t> - The Initiator/Responder selection logic may require a timed fallback: The designates Initiator may never initiate (NAT, already has sufficient connections, learns about responder later than responder about initiator etc.). + 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.). 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. @@ -721,28 +1035,151 @@ sn_enc = mask[0..8] XOR sn_nbo </section> <section anchor="security" numbered="true" toc="default"> <name>Security and Privacy Considerations</name> - <t> - TODO - </t> + <section numbered="true" toc="default"> + <name>Authentication and Key Confirmation</name> + <t> + Both peers are authenticated explicitly through Ed25519 signatures: + only the holder of sk<sub>R</sub> can produce sig<sub>R</sub>, and + only the holder of sk<sub>I</sub> can produce sig<sub>I</sub>. + Each signature covers the transcript up to the signer's ephemeral + key (sig<sub>R</sub>) or up to the peer's Finished + (sig<sub>I</sub>), binding the ephemeral keys and the whole + preceding exchange to the signing identity. finished<sub>R</sub> + and finished<sub>I</sub>, keyed from *HTS, provide key confirmation + over the transcript. Because authentication rests on signatures + made with the peer's own key, compromise of a peer's own key does + not let an attacker impersonate others to it (no key compromise + impersonation). + </t> + <t> + Nothing in the InitiatorHello is authenticated, and the + InitiatorDone only once sig<sub>I</sub> and finished<sub>I</sub> + have verified. Anybody able to inject messages can produce an + InitiatorHello that claims to come from any initiator; the + responder learns the initiator identity from the transport, and + verifies sig<sub>I</sub> against it. This is why the rules of + <xref target="protocol_flow"/> forbid a handshake that has not + completed to affect an existing association: it must not switch + the association's sending keys before then, and must not tear the + association down when the new handshake times out. Likewise, + handshake messages that do not verify must not change any state: + an implementation that, say, stops retransmitting its flight + upon receiving anything that merely looks like the answer can be + stalled indefinitely by a single forged message. + </t> + </section> + <section numbered="true" toc="default"> + <name>Forward Secrecy and Privacy</name> + <t> + Forward secrecy comes from the ephemeral X25519 key exchange + (DHE) alone. sk<sub>e</sub> <bcp14>MUST</bcp14> be + fresh for every handshake and erased afterwards, as must all + handshake secrets. An attacker that later obtains the long-term + keys of both peers can then not decrypt recorded traffic. + </t> + <t> + The InitiatorHello is sent in plaintext: with no static secret to + protect it, its fields (r<sub>I</sub>, pk<sub>e</sub>, + H(pk<sub>R</sub>)) are visible to passive observers. None of them + is secret (the peer identities are in any case known to the + underlying transport), and the exchange is not complete until + sig<sub>R</sub> and sig<sub>I</sub> have verified. There is no + 0-RTT and no early data. + </t> + <t> + The key exchange uses X25519 only. An attacker that records + traffic today and obtains a cryptographically relevant quantum + computer later can decrypt it. + </t> + </section> + <section numbered="true" toc="default"> + <name>Replay and Denial of Service</name> + <t> + The InitiatorHello is not protected against replay. A replayed + InitiatorHello costs the responder one ephemeral key generation, one + ECDH and one signature, and makes it send a ResponderHello, which is + larger than the InitiatorHello (it adds sig<sub>R</sub>); the + handshake cannot complete without sk<sub>I</sub>. + Responders <bcp14>SHOULD</bcp14> recognize retransmissions of the + InitiatorHello they are answering (e.g. by its hash) and answer + them with a retransmission of their ResponderHello instead of + starting over. CAKE has no cookie exchange (the + HelloRetryRequest of DTLS 1.3): protection against InitiatorHellos + from spoofed addresses is left to the GNUnet transport layer. + </t> + <t> + Records are protected against replay by the per-epoch anti-replay + windows (<xref target="encrypted_message"/>), which must only ever + be updated by records that deprotected. + </t> + </section> + <section numbered="true" toc="default"> + <name>Key Usage</name> + <t> + The Ed25519 peer identity key is used for signatures: of HELLOs + and of the ephemeral keys (sig<sub>R</sub>, sig<sub>I</sub>). It + is not used for key encapsulation. The context strings of + <xref target="ed25519"/> keep these uses disjoint. + </t> + <t> + Each handshake traffic secret protects at most two fields, with + distinct sequence numbers. Application traffic secrets are + replaced before their sequence numbers wrap; the regular change of + epochs also bounds the number of forgery attempts against any one + key (cf. <xref target="RFC9147" section="4.5.3"/>). + </t> + </section> </section> <!-- gana --> - <section> + <section anchor="gana"> <name>GANA Considerations</name> <t> - - + The message types of <xref target="cake_hs_msg_fmt"/> are GNUnet + message types, allocated in GANA's GNUnet message type registry. </t> </section> <section> <name>Implementation and Deployment Status</name> <t> - The CAKE handshake is currently implemented in a branch. - Open tasks include: + CAKE is implemented in the CORE service of GNUnet + (<tt>src/service/core/</tt>). This version of the specification + replaces the earlier KEMTLS-based design (three DHKEM shared + secrets, ss<sub>R</sub>, ss<sub>e</sub>, ss<sub>I</sub>, and a 0-RTT + InitiatorHello encrypted with ETS) with a signed ephemeral key + exchange: a single X25519 ECDH (DHE) and Ed25519 signatures + (sig<sub>R</sub>, sig<sub>I</sub>), with no 0-RTT. The handshake is + not compatible with the earlier design. + </t> + <t> + The GNUnet implementation has been migrated to this specification. + The wire format, the key schedule, and the handshake flight logic + (signature generation and verification, ECDH, the retransmission and + rekey behaviour) now follow this document. GNUnet 0.25 implements + an earlier, KEMTLS-based version, which is not compatible: it used + three DHKEM shared secrets (ss<sub>R</sub>, ss<sub>e</sub>, + ss<sub>I</sub>), a 0-RTT InitiatorHello encrypted with ETS, + "cake10" || Label || Context instead of the HkdfLabel structure, + SHA-512 for the transcript hash, H(pk) and the Finished HMAC, a + transcript of the messages as sent (ciphertexts and tags included) + instead of their plaintext, and an InitiatorDone that also carried + an ACK. (The ACK in the InitiatorDone has been dropped; the + responder's ACK under RATS<sub>0</sub> now confirms the handshake, + as in the rest of this specification.) + </t> + <t> + The implementation uses SHA-512 (not SHA-256) for the transcript + hash and H(pk), and feeds the X25519 shared secret through + <tt>GNUNET_CRYPTO_ecc_ecdh</tt> (which hashes it with SHA-512) + rather than as the raw 32-byte secret of <xref target="ecdh"/>; + these are to be aligned with the specification. Open tasks + include: </t> <ol> <li>Requesting key updates</li> - <li>Use KDF/Hash Function, SHA2 vs Blake2b</li> <li>Services info transmission (currently empty/unused)</li> <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> + <li>Align the transcript hash and H(pk) with SHA-256, and DHE with the raw X25519 shared secret</li> + <li>Regenerate test vectors for the signed ephemeral key exchange</li> </ol> </section> <!-- <section> @@ -755,37 +1192,43 @@ sn_enc = mask[0..8] XOR sn_nbo <back> <references> <name>Normative References</name> + &RFC2104; &RFC2119; + &RFC5869; + &RFC6234; + &RFC7748; &RFC8174; &RFC8439; &RFC8446; &RFC9147; - &RFC9180; + &RFC8032; - <reference anchor="LSD0011" target="https://lsd.gnunet.org/lsd0011"> + <reference anchor="XCHACHA" target="https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03"> <front> - <title>The HPKE Elligator KEM</title> - <author initials="M." surname="Schanzenbach" fullname="Martin Schanzenbach"> - <organization>Fraunhofer AISEC</organization> - </author> - <author initials="P." surname="Fardzadeh" fullname="Pedram Fardzadeh"> - <organization>Technische Universität München</organization> + <title>XChaCha: eXtended-nonce ChaCha and AEAD_XChaCha20_Poly1305</title> + <author initials="S." surname="Arciszewski" fullname="Scott Arciszewski"> + <organization>Paragon Initiative Enterprises</organization> </author> - <date year="2024"/> + <date year="2020" month="January"/> </front> + <seriesInfo name="Internet-Draft" value="draft-irtf-cfrg-xchacha-03"/> </reference> </references> <references> <name>Informative References</name> - <reference anchor="KEMTLS" target="https://thomwiggers.nl/publication/thesis/"> - <front> - <title>Post-Quantum TLS</title> - <author initials="T." surname="Wiggers" fullname="Thom Wiggers"> - <organization>Radboud University</organization> - </author> - <date year="2024"/> - </front> - </reference> -</references> + &RFC9001; + </references> + <section anchor="test_vectors" numbered="true" toc="default"> + <name>Test Vectors</name> + <t> + The test vectors of the earlier KEM-based version of CAKE do not + apply to the signed ephemeral key exchange defined here (the key + schedule, the handshake messages and the transcript all changed). + Vectors for this version -- one complete handshake followed by a + few records -- will be generated from an independent implementation + and added here once the implementation of this specification is + complete (its test <tt>test_cake</tt>). + </t> + </section> </back> </rfc> diff --git a/style.css b/style.css @@ -1147,3 +1147,7 @@ li > p:last-of-type { .label-expires,.expires { display: none; } + +h2.name-status-of-this-memo { + display: none; +}