RFC 9605

Secure Frame (SFrame): Lightweight Authenticated Encryption for Real-Time Media

๐Ÿ“… published August 2024, from ietf

Part 1 of 11 ๐ŸŽ€

RFC 9605: Secure Frame (SFrame) ๐Ÿ’–

Internet Engineering Task Force (IETF) ๐ŸŒธ Request for Comments: 9605 โœจ Category: Standards Track (so it's an official Internet standard, bestie) ๐Ÿ‘‘ ISSN: 2070-1721 Date: August 2024 ๐Ÿ“… Obsoletes / Updates: The title block doesn't list anything it obsoletes or updates ๐Ÿซถ

Authors: E. Omara (Apple), J. Uberti (Fixie.ai), S. G. Murillo (CoSMo Software), R. Barnes, Ed. (Cisco), and Y. Fablet (Apple) ๐Ÿงš

Title: Secure Frame (SFrame): Lightweight Authenticated Encryption for Real-Time Media ๐Ÿฆ‹


Abstract ๐ŸŒˆ

okay so this doc describes SFrame, an end-to-end encryption and authentication mechanism for media frames in multiparty conference calls ๐Ÿ“ž. The vibe is that central media servers (Selective Forwarding Units, or SFUs) can read the media metadata they need to make forwarding decisions, but they still can't see the actual media ๐Ÿ™ˆ.

SFrame is not the same as the Secure Real-Time Protocol (SRTP) ๐Ÿ’…. It's independent of RTP, which means it works with non-RTP media transport too, and it can be applied to whole media frames so it's more bandwidth efficient ๐Ÿ”ฅ.


Status of This Memo โœจ

This is an Internet Standards Track document ๐Ÿ‘‘.

This document comes from the Internet Engineering Task Force (IETF) ๐ŸŒธ. It represents the consensus of the IETF community, got public review, and was approved for publication by the Internet Engineering Steering Group (IESG) ๐Ÿซถ. If you want more info on Internet Standards, check Section 2 of RFC 7841 ๐Ÿ’œ.

For the current status of this document, any errata, and how to give feedback on it, go to https://www.rfc-editor.org/info/rfc9605 ๐Ÿฆ‹.


Copyright (c) 2024 IETF Trust and the persons identified as the document authors. All rights reserved ๐Ÿ’–.

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) as they stand on the date of publication ๐Ÿ“œ. Please actually read these docs, bestie, because they spell out your rights and restrictions for this document ๐Ÿ™ˆ. Code Components pulled out of this document must include the Revised BSD License text described in Section 4.e of the Trust Legal Provisions, and they come with no warranty, as the Revised BSD License describes ๐Ÿ’….


Table of Contents ๐Ÿงš

1.  Introduction
2.  Terminology
3.  Goals
4.  SFrame
  4.1.  Application Context
  4.2.  SFrame Ciphertext
  4.3.  SFrame Header
  4.4.  Encryption Schema
    4.4.1.  Key Selection
    4.4.2.  Key Derivation
    4.4.3.  Encryption
    4.4.4.  Decryption
  4.5.  Cipher Suites
    4.5.1.  AES-CTR with SHA2
5.  Key Management
  5.1.  Sender Keys
  5.2.  MLS
6.  Media Considerations
  6.1.  Selective Forwarding Units
    6.1.1.  RTP Stream Reuse
    6.1.2.  Simulcast
    6.1.3.  Scalable Video Coding (SVC)
  6.2.  Video Key Frames
  6.3.  Partial Decoding
7.  Security Considerations
  7.1.  No Header Confidentiality
  7.2.  No Per-Sender Authentication
  7.3.  Key Management
  7.4.  Replay
  7.5.  Risks Due to Short Tags
8.  IANA Considerations
  8.1.  SFrame Cipher Suites
9.  Application Responsibilities
  9.1.  Header Value Uniqueness
  9.2.  Key Management Framework
  9.3.  Anti-Replay
  9.4.  Metadata
10. References
  10.1.  Normative References
  10.2.  Informative References
Appendix A.  Example API
Appendix B.  Overhead Analysis
  B.1.  Assumptions
  B.2.  Audio
  B.3.  Video
  B.4.  Conferences
  B.5.  SFrame over RTP
Appendix C.  Test Vectors
  C.1.  Header Encoding/Decoding
  C.2.  AEAD Encryption/Decryption Using AES-CTR and HMAC
  C.3.  SFrame Encryption/Decryption
Acknowledgements
Contributors
Authors' Addresses

1. Introduction โœจ

Modern multiparty video call systems use Selective Forwarding Unit (SFU) servers to route media streams to call endpoints efficiently ๐Ÿ“ž. The SFU picks where things go based on stuff like available bandwidth, desired video size, codec support, and other factors ๐Ÿง . An SFU typically doesn't need to access the conference's media content, so the media can be encrypted "end to end" and the SFU can't decrypt it ๐Ÿ”’.

Here's the catch, though ๐Ÿ’€. For the SFU to work properly, it usually needs to access RTP metadata and RTCP feedback messages. That's not possible if all RTP/RTCP traffic is end-to-end encrypted ๐Ÿ™ˆ.

So two layers of encryption and authentication are required ๐Ÿซถ:

  1. Hop-by-hop (HBH) encryption of media, metadata, and feedback messages between the endpoints and SFU ๐Ÿฆ‹
  2. End-to-end (E2E) encryption (E2EE) of media between the endpoints ๐Ÿ’œ

The Secure Real-Time Protocol (SRTP) is already super popular for HBH encryption [RFC3711] ๐ŸŒธ. The SRTP "double encryption" scheme is a way to do E2E encryption in SRTP [RFC8723]. Unfortunately, it's kinda inefficient and really complicated, and because it's so tangled up with RTP, it just doesn't work in several realistic SFU scenarios ๐Ÿ˜ญ.

So this document proposes a brand new E2EE protection scheme called SFrame ๐ŸŽ€. It's specifically designed for group conference calls with SFUs. SFrame is a general encryption framing that can protect media payloads, and it doesn't care what transport you're using ๐Ÿงš.


2. Terminology ๐Ÿ’…

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" are the BCP 14 words, and they mean what BCP 14 [RFC2119] [RFC8174] says they mean, but only when they show up in ALL CAPS like this ๐Ÿ“ฃ. Lowercase versions are just regular words ๐Ÿ™ˆ.

Quick acronym check ๐Ÿ“:

  • MAC: Message Authentication Code
  • E2EE: End-to-End Encryption
  • HBH: Hop-by-Hop

We use "Selective Forwarding Unit (SFU)" and "media stream" in a looser way than [RFC7656] does ๐Ÿฆ‹. An SFU is a selective switching function for media payloads. A media stream is a sequence of media payloads, whether those payloads ride over RTP or some other protocol โœจ.


3. Goals ๐ŸŽฏ

SFrame is meant to be a good E2EE protection scheme for conference call media in a wide range of scenarios. Its goals are:

  1. Provide a secure E2EE mechanism for audio and video in conference calls that can be used with arbitrary SFU servers ๐Ÿ”.
  2. Decouple media encryption from key management, so SFrame can be used with an arbitrary key management system ๐Ÿ—๏ธ.
  3. Minimize packet expansion, so conferencing can work in as many network conditions as possible ๐Ÿ“ถ.
  4. Decouple the media encryption framework from the underlying transport, so it can be used in non-RTP scenarios, e.g., WebTransport [WEBTRANSPORT] ๐ŸŒ.
  5. When used with RTP and its error-resilience mechanisms, i.e., RTX and Forward Error Correction (FEC), require no special handling for RTX and FEC packets ๐Ÿ›ก๏ธ.
  6. Minimize the changes needed in SFU servers ๐Ÿ–ฅ๏ธ.
  7. Minimize the changes needed in endpoints ๐Ÿ“ฑ.
  8. Work with the most popular audio and video codecs used in conferencing scenarios ๐ŸŽฌ.

4. SFrame ๐Ÿ’œ

This document defines an encryption mechanism that gives you effective E2EE ๐Ÿ”’. It's simple to implement, has no dependencies on RTP, and keeps the encryption bandwidth overhead low ๐Ÿ“‰. This section explains how the mechanism works, including how applications use SFrame to protect media and the actual mechanics of E2EE for protecting media ๐Ÿงš.

The text you pasted is the RFC body itself, not a shell or file task, so there's nothing to run here. Continuing the rewrite from Section 4.4, here's part 2 in the bestie voice. ๐ŸŽ€


4.1. Application Context โœจ

okay so SFrame is a general encryption framing that's basically built to be an E2EE layer sitting on top of a transport that already does HBH encryption, like SRTP or QUIC [RFC3711][MOQ-TRANSPORT]. the vibe is layered protection, bestie ๐Ÿงš

how much SFrame costs you depends on the scale you encrypt at. there are two common patterns: encrypting whole media frames (per frame) or encrypting the individual transport-level media payloads (per packet). the overhead and how hard it is to integrate both depend on which one you pick ๐Ÿ’…

here's a typical media sender stack: it grabs media from a source, encodes it into frames, splits those frames into media packets, and then sends the payloads inside SRTP packets. the receiver just does everything in reverse, putting frames back together from SRTP packets and then decoding. Figure 1 shows the two spots where SFrame can slot in, either around whole frames or around individual media packets ๐Ÿฆ‹

per frame is the more efficient option, but it can get messy to integrate in environments where depacketization depends on what's inside the media packets. per packet skips that headache, but you pay for it in higher bandwidth. there's some quantitative tea on these trade-offs in Appendix B ๐Ÿ“

also, SFrame is a general media encapsulation, so it works in other scenarios too. the main thing is that the sender and receivers of an SFrame-encrypted object have to agree on what that object means. SFrame does NOT handle that agreement for you, the application has to set it up ๐Ÿซถ

   +------------------------------------------------------+
   |                                                      |
   |  +--------+      +-------------+      +-----------+  |
.-.  |  |        |      |             |      |    HBH    |  |
|   | |  | Encode |----->|  Packetize  |----->|  Protect  |----------+
 '+'  |  |        |   ^  |             |  ^   |           |  |       |
 /|\  |  +--------+   |  +-------------+  |   +-----------+  |       |
/ + \ |               |                   |         ^        |       |
 / \  |            SFrame              SFrame       |        |       |
/   \ |            Protect             Protect      |        |       |
Alice |          (per frame)         (per packet)   |        |       |
      |               ^                   ^         |        |       |
      |               |                   |         |        |       |
      +---------------|-------------------|---------|--------+       |
                      |                   |         |                v
                      |                   |         |         +------+-+
                      |      E2E Key      |       HBH Key     | Media  |
                      +---- Management ---+      Management   | Server |
                      |                   |         |         +------+-+
                      |                   |         |                |
      +---------------|-------------------|---------|--------+       |
      |               |                   |         |        |       |
      |               V                   V         |        |       |
.-.  |            SFrame               SFrame      |        |       |
|   | |           Unprotect            Unprotect    |        |       |
 '+'  |          (per frame)          (per packet)  |        |       |
 /|\  |               |                    |        V        |       |
/ + \ |  +--------+   |  +-------------+   |  +-----------+  |       |
 / \  |  |        |   V  |             |   V  |    HBH    |  |       |
/   \ |  | Decode |<-----| Depacketize |<-----| Unprotect |<---------+
 Bob  |  |        |      |             |      |           |  |
      |  +--------+      +-------------+      +-----------+  |
      |                                                      |
      +------------------------------------------------------+

Figure 1: Two Options for Integrating SFrame in a Typical Media Stack

ngl this is the part where it gets real: like SRTP, SFrame does NOT define how the parties in the conference exchange their SFrame keys. keys might come over an existing E2E-secure channel (see Section 5.1), or get derived from an E2E-secure shared secret (see Section 5.2). the key management system MUST ensure that each key used for encrypting media is used by exactly one media sender, so nonces never get reused. ๐Ÿ’€๐Ÿ”ฅ

4.2. SFrame Ciphertext ๐ŸŒˆ

an SFrame ciphertext is an SFrame header followed by the output of an Authenticated Encryption with Associated Data (AEAD) encryption of the plaintext [RFC5116], with the header given as additional authenticated data (AAD). the header is a variable-length structure, and you can read all about it in Section 4.3 ๐Ÿ’œ the layout of the encrypted data and the authentication tag is decided by whichever AEAD algorithm you're using.

   +-+----+-+----+--------------------+--------------------+<-+
   |K|KLEN|C|CLEN|       Key ID       |      Counter       |  |
+->+-+----+-+----+--------------------+--------------------+  |
|  |                                                       |  |
|  |                                                       |  |
|  |                                                       |  |
|  |                                                       |  |
|  |                   Encrypted Data                      |  |
|  |                                                       |  |
|  |                                                       |  |
|  |                                                       |  |
|  |                                                       |  |
+->+-------------------------------------------------------+<-+
|  |                 Authentication Tag                    |  |
|  +-------------------------------------------------------+  |
|                                                             |
|                                                             |
+--- Encrypted Portion               Authenticated Portion ---+

Figure 2: Structure of an SFrame Ciphertext

when SFrame is applied per packet, each packet's payload is an SFrame ciphertext. when it's applied per frame, the SFrame ciphertext for one encrypted frame spans several packets: the header shows up in the first packet and the authentication tag shows up in the last one. reassembling that frame from the individual packets, dealing with packet loss and reordering as needed, is the application's job ๐ŸŽ€

4.3. SFrame Header ๐Ÿ’–

the SFrame header carries two values that the encryption parameters get derived from:

  • A Key ID (KID) that determines which encryption key should be used
  • A Counter (CTR) that is used to construct the nonce for the encryption

applications MUST make sure each (KID, CTR) combination is used for exactly one SFrame encryption operation. Section 9.1 walks through a typical way to get that guarantee ๐Ÿ”

   Config Byte
        |
 .-----' '-----.
|               |
 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+------------+------------+
|X|  K  |Y|  C  |   KID...   |   CTR...   |
+-+-+-+-+-+-+-+-+------------+------------+

                       Figure 3: SFrame Header

the SFrame header has the overall structure in Figure 3. the first byte is a "config byte" with these fields:

  • Extended KID Flag (X, 1 bit): tells you whether the K field holds the KID or the KID length.
  • KID or KID Length (K, 3 bits): if X is 0, this field holds the KID. if X is 1, it holds the length of the KID, minus one.
  • Extended CTR Flag (Y, 1 bit): tells you whether the C field holds the CTR or the CTR length.
  • CTR or CTR Length (C, 3 bits): this field holds the CTR if Y is 0, or the CTR length, minus one, if Y is 1.

the KID and CTR fields are compact unsigned integers in network (big-endian) byte order. if a value is in the range 0-7, it rides in the matching bits of the config byte (K or C), and the matching flag (X or Y) is set to zero. otherwise, the value MUST be encoded with the minimum number of bytes required and tacked on after the config byte, KID first and CTR second. the header field (K or C) is set to the number of bytes in the encoded value, minus one. so 000 means a length of 1, 001 means a length of 2, and so on. that means a 3-bit length field can cover value lengths 1-8 ๐Ÿ“โœจ

the SFrame header can take one of the four forms in Figure 4, depending on which X and Y flags are set.

KID < 8, CTR < 8:
+-+-----+-+-----+
|0| KID |0| CTR |
+-+-----+-+-----+

KID < 8, CTR >= 8:
+-+-----+-+-----+------------------------+
|0| KID |1|CLEN |  CTR... (length=CLEN)  |
+-+-----+-+-----+------------------------+

KID >= 8, CTR < 8:
+-+-----+-+-----+------------------------+
|1|KLEN |0| CTR |  KID... (length=KLEN)  |
+-+-----+-+-----+------------------------+

KID >= 8, CTR >= 8:
+-+-----+-+-----+------------------------+------------------------+
|1|KLEN |1|CLEN |  KID... (length=KLEN)  |  CTR... (length=CLEN)  |
+-+-----+-+-----+------------------------+------------------------+

                  Figure 4: Forms of Encoded SFrame Header

4.4. Encryption Schema ๐Ÿง

SFrame encryption uses an AEAD encryption algorithm and a hash function, both defined by the cipher suite in use (see Section 4.5). here are the bits of the AEAD and hash algorithm we'll keep referring to:

  • AEAD.Encrypt and AEAD.Decrypt: the encryption and decryption functions for the AEAD. we follow the convention of RFC 5116 [RFC5116] and treat the authentication tag as part of the ciphertext produced by AEAD.Encrypt (unlike SRTP [RFC3711], which keeps it as a separate field).
  • AEAD.Nk: the size in bytes of a key for the encryption algorithm
  • AEAD.Nn: the size in bytes of a nonce for the encryption algorithm
  • AEAD.Nt: the overhead in bytes of the encryption algorithm (usually the size of the "tag" added to the plaintext)
  • AEAD.Nka: for cipher suites using the compound AEAD described in Section 4.5.1, the size in bytes of a key for the underlying encryption algorithm
  • Hash.Nh: the size in bytes of the output of the hash function

4.4.1. Key Selection โœจ

Okay so every SFrame encryption or decryption op is premised on one secret base_key ๐Ÿ”‘, and each one is labeled with an integer KID value that gets signaled in the SFrame header. ๐ŸŽ€

The sender and receivers need to agree on which base_key goes with which KID ๐Ÿค. They also need to agree on whether a base_key is for encryption or decryption only. How you provision base_key values and their KID values is beyond the scope of this specification, bestie, but its security properties will bound the assurances SFrame gives you ๐Ÿ˜ญ. For example, if SFrame is used to provide E2E security against intermediary media nodes, then SFrame keys need to be negotiated in a way that does not make them accessible to those intermediaries ๐Ÿ™ˆ.

For each known KID value, the client stores the matching symmetric key base_key. For keys that can be used for encryption, the client also stores the next CTR value to be used when encrypting (initially 0) ๐Ÿ“.

When encrypting, the application specifies which KID to use, and the CTR value goes up after successful encryption. When decrypting, the base_key is selected from the available keys using the KID value in the SFrame header ๐Ÿงš.

A given base_key MUST NOT be used for encryption by multiple senders. Reuse would mean multiple encrypted frames get generated with the same (key, nonce) pair, and that harms the protections provided by many AEAD algorithms ๐Ÿ’€. Implementations MUST mark each base_key as usable for encryption or decryption, never both ๐Ÿ’….

Note that the set of available keys might change over the lifetime of a real-time session. In those cases, the client will need to manage key usage so it doesn't lose media, because a key being used to encrypt before all receivers can use it to decrypt is a recipe for drama ๐Ÿ˜ฉ. For example, an application may make decryption-only keys available immediately, but delay the use of keys for encryption until (a) all receivers have acknowledged receipt of the new key, or (b) a timeout expires โณ.

4.4.2. Key Derivation ๐Ÿงช

SFrame encryption and decryption use a key and salt derived from the base_key associated with a KID. Given a base_key value, the key and salt are derived using HMAC-based Key Derivation Function (HKDF) [RFC5869] as follows:

def derive_key_salt(KID, base_key):
  sframe_secret = HKDF-Extract("", base_key)

  sframe_key_label = "SFrame 1.0 Secret key " + KID + cipher_suite
  sframe_key =
    HKDF-Expand(sframe_secret, sframe_key_label, AEAD.Nk)

  sframe_salt_label = "SFrame 1.0 Secret salt " + KID + cipher_suite
  sframe_salt =
    HKDF-Expand(sframe_secret, sframe_salt_label, AEAD.Nn)

  return sframe_key, sframe_salt

In the derivation of sframe_secret:

  • The + operator represents concatenation of byte strings. ๐ŸŽ€
  • The KID value is encoded as an 8-byte big-endian integer, not the compressed form used in the SFrame header. ๐Ÿ’œ
  • The cipher_suite value is a 2-byte big-endian integer representing the cipher suite in use (see Section 8.1). ๐ŸŒธ

The hash function used for HKDF is determined by the cipher suite in use. ๐ŸŒˆ

4.4.3. Encryption ๐Ÿ”

SFrame encryption uses the AEAD encryption algorithm for the cipher suite in use. The key for the encryption is the sframe_key. The nonce is formed by first XORing the sframe_salt with the current CTR value, and then encoding the result as a big-endian integer of length AEAD.Nn ๐Ÿง.

The encryptor forms an SFrame header using the CTR and KID values provided. The encoded header is provided as AAD to the AEAD encryption operation, together with application-provided metadata about the encrypted media (see Section 9.4) ๐Ÿฆ‹.

def encrypt(CTR, KID, metadata, plaintext):
  sframe_key, sframe_salt = key_store[KID]

  # encode_big_endian(x, n) produces an n-byte string encoding the
  # integer x in big-endian byte order.
  ctr = encode_big_endian(CTR, AEAD.Nn)
  nonce = xor(sframe_salt, CTR)

  # encode_sframe_header produces a byte string encoding the
  # provided KID and CTR values into an SFrame header.
  header = encode_sframe_header(CTR, KID)
  aad = header + metadata

  ciphertext = AEAD.Encrypt(sframe_key, nonce, aad, plaintext)
  return header + ciphertext

For example, the metadata input to encryption lets frame metadata get authenticated when SFrame is applied per frame. After encoding the frame and before packetizing it, the necessary media metadata gets moved out of the encoded frame buffer to be sent in some channel visible to the SFU (e.g., an RTP header extension) ๐Ÿงšโ€โ™€๏ธ.

                                  +---------------+
                                  |               |
                                  |               |
                                  |   plaintext   |
                                  |               |
                                  |               |
                                  +-------+-------+
                                          |
        .- +-----+                        |
       |   |     +--+--> sframe_key ----->| Key
Header |   | KID |  |                     |
       |   |     |  +--> sframe_salt --+  |
    +--+   +-----+                     |  |
    |  |   |     +---------------------+->| Nonce
    |  |   | CTR |                        |
    |  |   |     |                        |
    |   '- +-----+                        |
    |                                     |
    |          +----------------+         |
    |          |    metadata    |         |
    |          +-------+--------+         |
    |                  |                  |
    +------------------+----------------->| AAD
    |                                     |
    |                                AEAD.Encrypt
    |                                     |
    |               SFrame Ciphertext     |
    |               +---------------+     |
    +-------------->| SFrame Header |     |
                    +---------------+     |
                    |               |     |
                    |               |<----+
                    |   ciphertext  |
                    |               |
                    |               |
                    +---------------+

Figure 5: Encrypting an SFrame Ciphertext

4.4.4. Decryption ๐Ÿ•ต๏ธโ€โ™€๏ธ

Before decrypting, a receiver needs to assemble a full SFrame ciphertext. When an SFrame ciphertext is fragmented into multiple parts for transport (e.g., a whole encrypted frame sent in multiple SRTP packets), the receiving client collects all the fragments of the ciphertext, using appropriate sequencing and start/end markers in the transport. Once all of the required fragments are available, the client reassembles them into the SFrame ciphertext and passes the ciphertext to SFrame for decryption ๐Ÿงฉ.

The KID field in the SFrame header is used to find the right key and salt for the encrypted frame, and the CTR field is used to construct the nonce. The SFrame decryption procedure is as follows ๐Ÿ”“:

def decrypt(metadata, sframe_ciphertext):
  KID, CTR, header, ciphertext = parse_ciphertext(sframe_ciphertext)

  sframe_key, sframe_salt = key_store[KID]

  ctr = encode_big_endian(CTR, AEAD.Nn)
  nonce = xor(sframe_salt, ctr)
  aad = header + metadata

  return AEAD.Decrypt(sframe_key, nonce, aad, ciphertext)

If a ciphertext fails to decrypt because there is no key available for the KID in the SFrame header, the client MAY buffer the ciphertext and retry decryption once a key with that KID is received ๐Ÿชฃ. If a ciphertext fails to decrypt for any other reason, the client MUST discard the ciphertext ๐Ÿ—‘๏ธ. Invalid ciphertexts SHOULD be discarded in a way that is indistinguishable (to an external observer) from having processed a valid ciphertext. In other words, the SFrame decrypt operation should take the same amount of time regardless of whether decryption succeeds or fails โฑ๏ธ.

๐Ÿšจ Timing matters here, bestie. Whether decryption succeeds or fails, the operation should take the same amount of time, so nobody on the outside can tell which one happened. ๐Ÿ™ˆ
                    SFrame Ciphertext
                    +---------------+
    +---------------| SFrame Header |
    |               +---------------+
    |               |               |
    |               |               |-----+
    |               |   ciphertext  |     |
    |               |               |     |
    |               |               |     |
    |               +---------------+     |
    |                                     |
    |   .- +-----+                        |
    |  |   |     +--+--> sframe_key ----->| Key
    |  |   | KID |  |                     |
    |  |   |     |  +--> sframe_salt --+  |
    +->+   +-----+                     |  |
    |  |   |     +---------------------+->| Nonce
    |  |   | CTR |                        |
    |  |   |     |                        |
    |   '- +-----+                        |
    |                                     |
    |          +----------------+         |
    |          |    metadata    |         |
    |          +-------+--------+         |
    |                  |                  |
    +------------------+----------------->| AAD
                                          |
                                     AEAD.Decrypt
                                          |
                                          V
                                  +---------------+
                                  |               |
                                  |               |
                                  |   plaintext   |
                                  |               |
                                  |               |
                                  +---------------+

Figure 6: Decrypting an SFrame Ciphertext

4.5. Cipher Suites โœจ

Okay so cipher suites, bestie ๐Ÿ’…. Each SFrame session uses a single cipher suite, and that suite bundles together two primitives:

  • a hash function for key derivation ๐Ÿ”‘
  • an AEAD encryption algorithm [RFC5116] for frame encryption, optionally with a truncated authentication tag ๐ŸŽ€

This document defines the following cipher suites, with the constants defined in Section 4.4:

      +============================+====+=====+====+====+====+
      | Name                       | Nh | Nka | Nk | Nn | Nt |
      +============================+====+=====+====+====+====+
      | AES_128_CTR_HMAC_SHA256_80 | 32 | 16  | 48 | 12 | 10 |
      +----------------------------+----+-----+----+----+----+
      | AES_128_CTR_HMAC_SHA256_64 | 32 | 16  | 48 | 12 | 8  |
      +----------------------------+----+-----+----+----+----+
      | AES_128_CTR_HMAC_SHA256_32 | 32 | 16  | 48 | 12 | 4  |
      +----------------------------+----+-----+----+----+----+
      | AES_128_GCM_SHA256_128     | 32 | n/a | 16 | 12 | 16 |
      +----------------------------+----+-----+----+----+----+
      | AES_256_GCM_SHA512_128     | 64 | n/a | 32 | 12 | 16 |
      +----------------------------+----+-----+----+----+----+

               Table 1: SFrame Cipher Suite Constants

The numeric identifiers for these suites live in the IANA registry created in Section 8.1 ๐Ÿฆ‹.

Here's a fun trick: the last number in each suite name tells you the authentication tag length. "_128" means a 128-bit tag, "_80" means 80-bit, "_64" means 64-bit, and "_32" means 32-bit ๐Ÿงš.

Also, a session with multiple media streams can configure different cipher suites for different streams. For example, to conserve bandwidth, a session might use a suite with 80-bit tags for video frames and a different suite with 32-bit tags for audio frames ๐ŸŽง๐Ÿ’œ.

4.5.1. AES-CTR with SHA2

Okay, this one is giving main character energy ๐Ÿ‘‘. To allow very short tag sizes, we define a synthetic AEAD function that uses the authenticated counter mode of AES together with HMAC for authentication. We use an encrypt-then-MAC approach, as in SRTP [RFC3711] ๐Ÿ”.

Before any encryption or decryption, the encryption and authentication subkeys get derived from the single AEAD key. The overall length of the AEAD key is Nka + Nh, where Nka is the key size for the AES block cipher in use and Nh is the output size of the hash function (as in Section 4.4). The encryption subkey is made of the first Nka bytes, and the authentication subkey is made of the remaining Nh bytes โœจ.

def derive_subkeys(sframe_key):
  # The encryption key comprises the first Nka bytes
  enc_key = sframe_key[..Nka]

  # The authentication key comprises Nh remaining bytes
  auth_key = sframe_key[Nka..]

  return enc_key, auth_key

The AEAD encryption and decryption functions are then composed of individual calls to the CTR encrypt function and HMAC. The resulting MAC value gets truncated to a number of bytes Nt, which is fixed by the cipher suite ๐Ÿฆ‹.

def truncate(tag, n):
  # Take the first `n` bytes of `tag`
  return tag[..n]

def compute_tag(auth_key, nonce, aad, ct):
  aad_len = encode_big_endian(len(aad), 8)
  ct_len = encode_big_endian(len(ct), 8)
  tag_len = encode_big_endian(Nt, 8)
  auth_data = aad_len + ct_len + tag_len + nonce + aad + ct
  tag = HMAC(auth_key, auth_data)
  return truncate(tag, Nt)

def AEAD.Encrypt(key, nonce, aad, pt):
  enc_key, auth_key = derive_subkeys(key)
  initial_counter = nonce + 0x00000000 # append four zero bytes
  ct = AES-CTR.Encrypt(enc_key, initial_counter, pt)
  tag = compute_tag(auth_key, nonce, aad, ct)
  return ct + tag

def AEAD.Decrypt(key, nonce, aad, ct):
  inner_ct, tag = split_ct(ct, tag_len)

  enc_key, auth_key = derive_subkeys(key)
  candidate_tag = compute_tag(auth_key, nonce, aad, inner_ct)
  if !constant_time_equal(tag, candidate_tag):
    raise Exception("Authentication Failure")

  initial_counter = nonce + 0x00000000 # append four zero bytes
  return AES-CTR.Decrypt(enc_key, initial_counter, inner_ct)

5. Key Management ๐Ÿ”

Okay, so SFrame has to be integrated with an E2E key management framework, and that framework is what exchanges and rotates the keys used for SFrame encryption ๐Ÿ—๏ธ. The key management framework provides these functions:

  • Provisioning KID / base_key mappings to participating clients
  • Updating the above data as clients join or leave

It's the application's job to provide the key management framework, as described in Section 9.2 ๐Ÿ’….

5.1. Sender Keys

If the participants in a call already have a preexisting E2E-secure channel, they can use it to distribute SFrame keys ๐Ÿ’Œ. Each client in a call generates a fresh base_key value that it will use to encrypt media. The client then uses the E2E-secure channel to send its encryption key to the other participants.

In this scheme, it's assumed that receivers have a signal outside of SFrame that says which client sent a given frame (for example, an RTP synchronization source (SSRC)). SFrame KID values are then used to tell apart versions of the sender's base_key ๐ŸŽ€.

KID values in this scheme have two parts: a "key generation" and a "ratchet step". Both are unsigned integers that begin at zero. The key generation goes up each time the sender distributes a new key to receivers. The ratchet step goes up each time the sender ratchets their key forward for forward secrecy ๐Ÿฆ‹:

base_key[i+1] = HKDF-Expand(
                  HKDF-Extract("", base_key[i]),
                  "SFrame 1.0 Ratchet", CipherSuite.Nh)

For compactness, we don't send the whole ratchet step. Instead, we send only its low-order R bits, where R is a value set by the application. Different senders may use different values of R, but each receiver of a given sender needs to know which value of R the sender is using, so they can recognize when they need to ratchet (vs. expecting a new key) ๐Ÿง . R effectively defines a reordering window, since no more than 2^R ratchet steps can be active at a given time. The key generation is sent in the remaining 64 - R bits of the KID ๐ŸŒธ.

KID = (key_generation << R) + (ratchet_step % (1 << R))

     64-R bits         R bits
 <---------------> <------------>
+-----------------+--------------+
| Key Generation  | Ratchet Step |
+-----------------+--------------+

        Figure 7: Structure of a KID in the Sender Keys Scheme

The sender signals a ratchet step update by sending with a KID value in which the ratchet step has been incremented. A receiver who gets a new KID from a sender computes the new key as above. The old key may be kept for some time to allow for out-of-order delivery, but should be deleted promptly ๐Ÿซถ.

If a new participant joins in the middle of a session, they will need to receive from each sender (a) the current sender key for that sender and (b) the current KID value for the sender ๐Ÿงš. Evicting a participant requires each sender to send a fresh sender key to all receivers ๐Ÿ’€.

It's the application's responsibility to decide when sender keys get updated ๐Ÿ“. A sender key may be updated by sending a new base_key (which updates the key generation) or by hashing the current base_key (which updates the ratchet step). Ratcheting the key forward is useful when adding new receivers to an SFrame-based interaction, since it ensures that the new receivers can't decrypt any media encrypted before they were added ๐Ÿ˜ญ. If a sender wants the opposite property when removing a receiver (ensuring that the receiver can't decrypt media after they're removed), then the sender will need to distribute a new sender key ๐Ÿ”ฅ.

5.2. MLS

The Messaging Layer Security (MLS) protocol provides group authenticated key exchange [MLS-ARCH] [MLS-PROTO] ๐ŸŒˆ. In principle, it could be used to instantiate the sender key scheme above, but it can also be used more efficiently directly โœจ.

MLS creates a linear sequence of keys, and each one is shared among the members of a group at a given point in time. When a member joins or leaves the group, a new key is produced that's known only to the augmented or reduced group. Each step in the lifetime of the group is known as an "epoch", and each member of the group is assigned an "index" that stays constant for the whole time they're in the group ๐ŸŽ€.

To generate keys and nonces for SFrame, we use the MLS exporter function to generate a base_key value for each MLS epoch. Each member of the group is assigned a set of KID values, so that each member has a unique sframe_key and sframe_salt to encrypt with. Senders may choose any KID value within their assigned set of KID values. For example, that lets a single sender send multiple, uncoordinated outbound media streams ๐Ÿ’–.

base_key = MLS-Exporter("SFrame 1.0 Base Key", "", AEAD.Nk)

For compactness, we don't send the whole epoch number. Instead, we send only its low-order E bits, where E is a value set by the application. E effectively defines a reordering window, since no more than 2^E epochs can be active at a given time. To handle rollover of the epoch counter, receivers MUST remove an old epoch when a new epoch with the same low-order E bits is introduced ๐Ÿšจ.

Let S be the number of bits required to encode a member index in the group, i.e., the smallest value such that group_size <= (1 << S). The sender index is encoded in the S bits above the epoch. The remaining 64 - S - E bits of the KID value are a context value chosen by the sender (context value 0 will produce the shortest encoded KID) ๐Ÿฆ‹.

KID = (context << (S + E)) + (sender_index << E) + (epoch % (1 << E))

  64-S-E bits   S bits   E bits
 <-----------> <------> <------>
+-------------+--------+-------+
| Context ID  | Index  | Epoch |
+-------------+--------+-------+

            Figure 8: Structure of a KID for an MLS Sender

Once an SFrame stack has been provisioned with the sframe_epoch_secret for an epoch, it can compute the required KID values on demand (along with the resulting SFrame keys and nonces derived from the base_key and KID) whenever it needs to encrypt or decrypt for a given member ๐Ÿง.

  ...
         |
         |
Epoch 14 +--+-- index=3 ---> KID = 0x3e
         |  |
         |  +-- index=7 ---> KID = 0x7e
         |  |
         |  +-- index=20 --> KID = 0x14e
         |
         |
Epoch 15 +--+-- index=3 ---> KID = 0x3f
         |  |
         |  +-- index=5 ---> KID = 0x5f
         |
         |
Epoch 16 +----- index=2 --+--> context = 2 --> KID = 0x820
         |                |
         |                +--> context = 3 --> KID = 0xc20
         |
         |
Epoch 17 +--+-- index=33 --> KID = 0x211
         |  |
         |  +-- index=51 --> KID = 0x331
         |
         |
  ...

    Figure 9: An Example Sequence of KIDs for an MLS-based SFrame
          Session (E=4; S=6, Allowing for 64 Group Members)

6. Media Considerations ๐ŸŽฌ

6.1. Selective Forwarding Units

SFUs (e.g., those described in Section 3.7 of [RFC7667]) receive the media streams from each participant and pick which ones should be forwarded to each of the other participants ๐Ÿ“บ. There are several approaches for stream selection, but in general, the SFU needs to access metadata associated with each frame and modify the RTP information of the incoming packets when they're transmitted to the receiving participants ๐Ÿงš.

This section describes how these normal SFU modes of operation interact with the E2EE provided by SFrame ๐Ÿ’œ.

6.1.1. RTP Stream Reuse โœจ

okay so the SFU can totally decide to only send a certain number of streams based on who's actually talking ๐ŸŽ™๏ธ. to skip the overhead of setting up brand-new transport streams every time, it might just reuse streams that already exist, or even pre-allocate a set number and pick in each moment whose media goes through each one ๐Ÿ”„.

that means the same transport-level stream (like an RTP stream identified by either an SSRC or a Media Identification (MID)) can carry media from different streams belonging to different participants ๐Ÿ‘€. but here's the magic ๐Ÿช„: every participant encrypts with their own key, so the receiver can verify who sent the media inside that RTP stream at any given moment. the receiver links the media to the sender named by the authenticated SFrame KID value, no matter how the SFU is sending stuff over to the client ๐Ÿ’….

ngl, there's one catch ๐Ÿ™ˆ. to stop a malicious participant (not the SFU) from impersonating someone, you'd need a mechanism based on digital signatures. SFrame does not protect against that kind of attack, so don't expect it to ๐Ÿšซ.

6.1.2. Simulcast ๐ŸŽž๏ธ

when you're doing simulcast, the same input image becomes N different encoded frames (one for each simulcast layer) ๐ŸŒˆ. each of those frames gets processed on its own by the frame encryptor, and each one is given a unique CTR value ๐Ÿ”.

6.1.3. Scalable Video Coding (SVC) ๐Ÿฆ‹

in both temporal and spatial scalability, the SFU can drop layers to match a certain bitrate, or to forward specific media sizes or frames per second ๐Ÿ“‰. so the SFU can selectively remove layers, the sender MUST encapsulate each layer in a different SFrame ciphertext ๐Ÿงฉ. that's the non-negotiable part, bestie ๐Ÿซถ.

6.2. Video Key Frames ๐Ÿ”‘

forward security and post-compromise security require that the E2EE keys (base keys) get updated any time a participant joins or leaves the call ๐Ÿ”„โœจ. this is giving "rotate on every entrance and exit" energy ๐Ÿ’ƒ.

the key exchange happens asynchronously, on a different path from the SFU signaling and media ๐Ÿ“ฌ. so it's possible that when a new participant joins and the SFU asks for a key frame, the sender ends up generating the E2EE frame with a key the receiver doesn't know yet, and the frame gets discarded ๐Ÿ˜ญ. when the sender updates its sending key to the new one, it sends that in a non-key frame. the receiver can decrypt it, but it can't decode it ๐Ÿ™ƒ.

the new receiver then re-requests a key frame, but thanks to sender and SFU policies, that new key frame could take a while to show up โณ.

if the sender sends a key frame after the new E2EE key is in use, the new participant sees video way faster ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ.

this doesn't happen for media streams without dependencies among frames, like audio streams ๐ŸŽง. in those, every frame can be decoded independently, so a frame never depends on another frame sitting on the other side of a key rotation. audio is literally unbothered ๐Ÿ’….

6.3. Partial Decoding ๐Ÿงฉ

some codecs support partial decoding, where individual packets can be decoded without waiting for the whole frame to arrive ๐Ÿ“ฆ. when SFrame is applied per frame, though, partial decoding isn't possible, because the decoder can't touch any data until the entire frame has arrived and been decrypted ๐Ÿ™…โ€โ™€๏ธ.


7. Security Considerations ๐Ÿ›ก๏ธ

okay bestie, this section is seriously important, so let's get into it ๐Ÿ‘€๐Ÿ’œ.

7.1. No Header Confidentiality ๐Ÿ™ˆ

SFrame gives integrity protection to the SFrame header (the KID and CTR values), but it does NOT give confidentiality protection ๐Ÿ˜ฌ. anyone who can see the SFrame header can learn things like which parties are sending SFrame payloads (from the KID values) and at what rates (from the CTR values) ๐Ÿ“Š. if SFrame is used for end-to-end security on top of hop-by-hop protections (like running over SRTP, as described in Appendix B.5), the hop-by-hop security mechanisms give confidentiality protection for the SFrame header between hops ๐Ÿ”’.

7.2. No Per-Sender Authentication ๐Ÿšจ

SFrame does not provide per-sender authentication of media data ๐Ÿ˜ฑ. any sender in a session can send media that gets associated with any other sender. the reason is that SFrame uses symmetric encryption to protect media data, so any receiver also has the keys needed to encrypt packets for the sender ๐Ÿ”‘๐Ÿ‘ฏ.

7.3. Key Management ๐Ÿ—๏ธ

the specifics of key management are beyond the scope of this document ๐Ÿ™ƒ. still, every client SHOULD change their keys when new clients join or leave the call, for forward secrecy and post-compromise security ๐Ÿ”„๐Ÿ’–.

7.4. Replay ๐Ÿ”

the handling of replay is out of scope for this document ๐Ÿ™…โ€โ™€๏ธ. however, senders MUST reject requests to encrypt multiple times with the same key and nonce, since several AEAD algorithms fail badly in those cases (see, e.g., Section 5.1.1 of [RFC5116]) ๐Ÿ’€. this one is a hard no, periodt ๐Ÿšซ.

7.5. Risks Due to Short Tags โš ๏ธ

the SFrame cipher suites based on AES-CTR allow for short authentication tags ๐Ÿท๏ธ. the catch is that short tags bring a higher risk that an attacker can make an SFrame receiver accept an SFrame ciphertext of the attacker's own choosing ๐Ÿ˜ฐ.

assuming the cipher suite's authentication properties are robust, the only attack an attacker can mount is trying to find an acceptable (ciphertext, tag) combination through brute force ๐ŸŽฒ. the expected success rate of that brute-force attack looks like this:

attacker_success_rate = attempts_per_second / 2^(8*Nt)

for example, a gigabit Ethernet connection can transmit roughly 2^20 packets per second ๐Ÿš€. if an attacker saturated that link with guesses against a 32-bit authentication tag (Nt=4), they'd succeed on average roughly once every 2^12 seconds, or about once an hour โฐ. yikes ๐Ÿ˜ญ.

in a typical SFrame usage in a real-time media application, there are a few ways to mitigate this risk ๐Ÿ› ๏ธ:

  • Receivers only accept SFrame ciphertexts over HBH-secure channels (e.g., SRTP security associations or QUIC connections). If that's the case, only an entity that is part of such a channel can mount the above attack ๐Ÿ”.
  • The expected packet rate for a media stream is very predictable (and typically far lower than the example above). On one hand, attacks at this rate succeed even less often than the high-rate attack described above ๐Ÿ“‰. On the other hand, the application can treat an elevated packet arrival rate as a signal of a brute-force attack ๐Ÿšจ. this latter approach is common in other settings, like mitigating brute-force attacks on passwords ๐Ÿ”‘.
  • Media applications typically don't give feedback to media senders about which media packets failed to decrypt ๐Ÿ™Š. when media-quality feedback mechanisms are used, decryption failures typically show up as packet losses, but only at an aggregate level ๐Ÿ“Š.
  • Anti-replay mechanisms (see Section 7.4) stop the attacker from reusing valid ciphertexts (either observed or guessed) ๐Ÿ›‘. a receiver applying anti-replay controls only accepts one valid plaintext per CTR value. since the CTR value is covered by SFrame authentication, the attacker has to do a fresh search for a valid tag for every forged ciphertext, even if the encrypted content stays the same ๐Ÿ”. so when the brute-force attack succeeds, it only lets the attacker send a single SFrame ciphertext ๐Ÿซ . that ciphertext can't be reused, because either it has the same CTR value and gets discarded as a replay, or it has a different CTR value and its tag is no longer valid ๐Ÿ’….

without these mitigations, an application that uses short tags is at heightened risk of forgery attacks ๐Ÿ˜ฑ. in many cases it's simpler to use full-size tags and tolerate slightly higher bandwidth usage, rather than add the extra defenses needed to use short tags safely ๐Ÿ’–.


8. IANA Considerations ๐Ÿ“‹

IANA has created a new registry called "SFrame Cipher Suites" (Section 8.1) under the "SFrame" group registry heading ๐ŸŽ€.

8.1. SFrame Cipher Suites ๐Ÿ”

the "SFrame Cipher Suites" registry lists identifiers for SFrame cipher suites as defined in Section 4.5 ๐Ÿ—‚๏ธ. the cipher suite field is two bytes wide, so the valid cipher suites are in the range 0x0000 to 0xFFFF ๐Ÿ”ข. except as noted below, assignments are made via the Specification Required policy [RFC8126] โœจ.

the registration template looks like this ๐Ÿ“:

  • Value: The numeric value of the cipher suite
  • Name: The name of the cipher suite
  • Recommended: Whether support for this cipher suite is recommended by the IETF. Valid values are "Y", "N", and "D" as described in Section 17.1 of [MLS-PROTO]. The default value of the "Recommended" column is "N". Setting the Recommended item to "Y" or "D", or changing an item whose current value is "Y" or "D", requires Standards Action [RFC8126] ๐Ÿ™Œ.
  • Reference: The document where this cipher suite is defined
  • Change Controller: Who is authorized to update the row in the registry

initial contents ๐ŸŒธ:

+========+============================+===+===========+============+
| Value  | Name                       | R | Reference | Change     |
|        |                            |   |           | Controller |
+========+============================+===+===========+============+
| 0x0000 | Reserved                   | - | RFC 9605  | IETF       |
+--------+----------------------------+---+-----------+------------+
| 0x0001 | AES_128_CTR_HMAC_SHA256_80 | Y | RFC 9605  | IETF       |
+--------+----------------------------+---+-----------+------------+
| 0x0002 | AES_128_CTR_HMAC_SHA256_64 | Y | RFC 9605  | IETF       |
+--------+----------------------------+---+-----------+------------+
| 0x0003 | AES_128_CTR_HMAC_SHA256_32 | Y | RFC 9605  | IETF       |
+--------+----------------------------+---+-----------+------------+
| 0x0004 | AES_128_GCM_SHA256_128     | Y | RFC 9605  | IETF       |
+--------+----------------------------+---+-----------+------------+
| 0x0005 | AES_256_GCM_SHA512_128     | Y | RFC 9605  | IETF       |
+--------+----------------------------+---+-----------+------------+
| 0xF000 | Reserved for Private Use   | - | RFC 9605  | IETF       |
| -      |                            |   |           |            |
| 0xFFFF |                            |   |           |            |
+--------+----------------------------+---+-----------+------------+

Table 2: SFrame Cipher Suites ๐ŸŽ€

9. Application Responsibilities ๐ŸŽ€

Okay bestie, so to use SFrame, your app has to decide what goes into the encryption and decryption operations and how the SFrame ciphertexts get from sender to receiver, including any fragmenting and reassembling along the way ๐Ÿ“ฆ. This section is the checklist of extra stuff the app has to handle so SFrame stays secure ๐Ÿ”๐Ÿ’–

Generally, the app is the one in charge of setting up SFrame ๐Ÿ‘‘. First it decides when SFrame gets applied at all. When it does get applied, the app picks the cipher suite. And if new SFrame versions show up later, the app is the one who figures out which version to use โœจ

This split is pretty similar to how other media settings like codecs usually work in media apps. They get set up in some signaling protocol, not inside the media itself ๐ŸŽฌ Apps might find it handy to extend the protocols they already use to negotiate other media settings, like Session Description Protocol (SDP) [RFC8866], so they can negotiate SFrame settings too ๐ŸŒธ


9.1. Header Value Uniqueness ๐Ÿ”‘

Applications MUST ensure that each (base_key, KID, CTR) combination is used for at most one SFrame encryption operation ๐Ÿšซ This is what keeps the (key, nonce) pairs used by the underlying AEAD algorithm from ever getting reused, which is literally the whole point ๐Ÿ˜ญ

The usual move is to give each sender a KID or a set of KIDs. Then each sender uses the CTR field as a monotonic counter, bumping it up for every plaintext they encrypt ๐Ÿ”ข It's simple, and it keeps CTR values as small as possible, so there's less overhead. Iconic โœจ

Now, if an SFrame context might get written to persistent storage, that context has to include the last-used CTR value ๐Ÿ’พ Later on, when the context gets used again, the app should use the stored CTR value to figure out the next CTR value for an encryption operation. Then it writes that next CTR value back to storage before actually using it for encryption. Storing it before usage (instead of after) is what makes sure a storage failure can't cause the same (base_key, KID, CTR) combo to get reused ๐Ÿ›ก๏ธ Main character energy for sure ๐Ÿ’…


9.2. Key Management Framework ๐Ÿ—๏ธ

The app is responsible for provisioning SFrame with a mapping of KID values to base_key values, plus the resulting keys and salts ๐Ÿ“‹ Even more important, the app decides which KID values get used for which purposes, like which senders get which ones ๐Ÿซถ An app's KID assignment strategy MUST be structured so that the non-reuse properties from Section 9.1 actually hold โœจ

The app also owns the rotation schedule for keys ๐Ÿ”„ For example, one app might have an ephemeral group for every call and keep rotating keys whenever endpoints join or leave the call. Another app could have a persistent group that gets reused across multiple calls and just derives ephemeral symmetric keys for each specific call ๐Ÿ’œ Both are valid vibes, just different ones ๐ŸŒˆ

It should be noted that KID values are not encrypted by SFrame, which means any application-layer intermediaries that handle an SFrame ciphertext can see them ๐Ÿ‘€ Ngl this is a big deal: if there's any application meaning packed into KID values, that meaning gets exposed to those intermediaries. For example, with the scheme in Section 5.1, the number of ratchet steps per sender is exposed. And with the scheme in Section 5.2, the number of epochs and the MLS sender ID of the SFrame sender are exposed ๐Ÿ™ˆ Keep your KIDs boring, bestie ๐Ÿซถ


9.3. Anti-Replay ๐Ÿ”

Handling anti-replay is the application's job ๐Ÿ™Œ Replays by network attackers are assumed to be stopped by network-layer stuff, like TLS or SRTP ๐Ÿ›ก๏ธ And as mentioned in Section 7.4, senders MUST reject requests to encrypt multiple times with the same key and nonce ๐Ÿšซ Absolutely no exceptions, periodt ๐Ÿ’€

Anti-replay on the receiver side isn't mandatory to implement ๐Ÿคทโ€โ™€๏ธ Receivers MAY apply time- or counter-based anti-replay mitigations if they want ๐Ÿฆ‹ For example, Section 3.3.2 of [RFC3711] specifies a counter-based anti-replay mitigation. That could be adapted for SFrame by using the CTR field as the counter ๐Ÿงš


9.4. Metadata ๐Ÿงพ

The metadata input to SFrame operations is an opaque byte string that the application specifies ๐Ÿซฅ So the app has to decide what info goes into the metadata and make sure it gets handed to the encryption and decryption functions at the right points ๐Ÿ“ A receiver MUST NOT use SFrame-authenticated metadata until after the SFrame decrypt function has authenticated it. The one exception is when the goal is just to prepare an SFrame ciphertext for SFrame decryption ๐Ÿ™…โ€โ™€๏ธ Basically, metadata can be used "upstream of SFrame" in a processing pipeline, but only to get ready for SFrame decryption ๐ŸŒธ

Here's an example. Say an app uses SFrame to encrypt audio frames that get sent over SRTP, and some app data rides along in the RTP header extension ๐ŸŽง Now say the app also puts that same app data in the SFrame metadata, so the SFU can read it but not change it ๐Ÿ‘€ A receiver can use the app data in the RTP header extension as part of the normal SRTP decryption process, since that's required to get the SFrame ciphertext out of the SRTP payload ๐Ÿ“ฆ But the receiver MUST NOT use the app data for any other purpose before SFrame decryption has authenticated it ๐Ÿšจ Do not skip the line, bestie ๐Ÿ˜ค


10. References ๐Ÿ“š

10.1. Normative References ๐Ÿ’…

[MLS-PROTO]
           Barnes, R., Beurdouche, B., Robert, R., Millican, J.,
           Omara, E., and K. Cohn-Gordon, "The Messaging Layer
           Security (MLS) Protocol", RFC 9420, DOI 10.17487/RFC9420,
           July 2023, <https://www.rfc-editor.org/info/rfc9420>.

[RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
           Requirement Levels", BCP 14, RFC 2119,
           DOI 10.17487/RFC2119, March 1997,
           <https://www.rfc-editor.org/info/rfc2119>.

[RFC5116]  McGrew, D., "An Interface and Algorithms for Authenticated
           Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008,
           <https://www.rfc-editor.org/info/rfc5116>.

[RFC5869]  Krawczyk, H. and P. Eronen, "HMAC-based Extract-and-Expand
           Key Derivation Function (HKDF)", RFC 5869,
           DOI 10.17487/RFC5869, May 2010,
           <https://www.rfc-editor.org/info/rfc5869>.

[RFC8126]  Cotton, M., Leiba, B., and T. Narten, "Guidelines for
           Writing an IANA Considerations Section in RFCs", BCP 26,
           RFC 8126, DOI 10.17487/RFC8126, June 2017,
           <https://www.rfc-editor.org/info/rfc8126>.

[RFC8174]  Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC
           2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174,
           May 2017, <https://www.rfc-editor.org/info/rfc8174>.

10.2. Informative References ๐Ÿฆ‹

[MLS-ARCH] Beurdouche, B., Rescorla, E., Omara, E., Inguva, S., and
           A. Duric, "The Messaging Layer Security (MLS)
           Architecture", Work in Progress, Internet-Draft, draft-
           ietf-mls-architecture-15, 3 August 2024,
           <https://datatracker.ietf.org/doc/html/draft-ietf-mls-
           architecture-15>.

[MOQ-TRANSPORT]
           Curley, L., Pugin, K., Nandakumar, S., Vasiliev, V., and
           I. Swett, Ed., "Media over QUIC Transport", Work in
           Progress, Internet-Draft, draft-ietf-moq-transport-05, 8
           July 2024, <https://datatracker.ietf.org/doc/html/draft-
           ietf-moq-transport-05>.

[RFC3711]  Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K.
           Norrman, "The Secure Real-time Transport Protocol (SRTP)",
           RFC 3711, DOI 10.17487/RFC3711, March 2004,
           <https://www.rfc-editor.org/info/rfc3711>.

[RFC6716]  Valin, JM., Vos, K., and T. Terriberry, "Definition of the
           Opus Audio Codec", RFC 6716, DOI 10.17487/RFC6716,
           September 2012, <https://www.rfc-editor.org/info/rfc6716>.

[RFC7656]  Lennox, J., Gross, K., Nandakumar, S., Salgueiro, G., and
           B. Burman, Ed., "A Taxonomy of Semantics and Mechanisms
           for Real-Time Transport Protocol (RTP) Sources", RFC 7656,
           DOI 10.17487/RFC7656, November 2015,
           <https://www.rfc-editor.org/info/rfc7656>.

[RFC7667]  Westerlund, M. and S. Wenger, "RTP Topologies", RFC 7667,
           DOI 10.17487/RFC7667, November 2015,
           <https://www.rfc-editor.org/info/rfc7667>.

[RFC8723]  Jennings, C., Jones, P., Barnes, R., and A.B. Roach,
           "Double Encryption Procedures for the Secure Real-Time
           Transport Protocol (SRTP)", RFC 8723,
           DOI 10.17487/RFC8723, April 2020,
           <https://www.rfc-editor.org/info/rfc8723>.

[RFC8866]  Begen, A., Kyzivat, P., Perkins, C., and M. Handley, "SDP:
           Session Description Protocol", RFC 8866,
           DOI 10.17487/RFC8866, January 2021,
           <https://www.rfc-editor.org/info/rfc8866>.

[RTP-PAYLOAD]
           Murillo, S. G., Fablet, Y., and A. Gouaillard, "Codec
           agnostic RTP payload format for video", Work in Progress,
           Internet-Draft, draft-gouaillard-avtcore-codec-agn-rtp-
           payload-01, 9 March 2021,
           <https://datatracker.ietf.org/doc/html/draft-gouaillard-
           avtcore-codec-agn-rtp-payload-01>.

[TestVectors]
           "SFrame Test Vectors", commit 025d568, September 2023,
           <https://github.com/sframe-wg/sframe/blob/025d568/test-
           vectors/test-vectors.json>.

[WEBTRANSPORT]
           Vasiliev, V., "The WebTransport Protocol Framework", Work
           in Progress, Internet-Draft, draft-ietf-webtrans-overview-
           08, 25 August 2024,
           <https://datatracker.ietf.org/api/v1/doc/document/draft-
           ietf-webtrans-overview/>.

Appendix A. Example API โœจ

This section is not normative. ๐Ÿซถ

okay so this section is a notional API, like a sketch of what an SFrame implementation might expose ๐Ÿ’… the big idea is the "SFrame context," and inside it KID values actually mean something. in the key management scheme from Section 5.1, every sender gets their own context ๐Ÿงš but in the scheme from Section 5.2, all the senders share one context. bestie, that difference is everything ๐Ÿ˜ญ

an SFrame context stores mappings from KID values to "key contexts," and the key context depends on whether the KID is for sending or receiving ๐ŸŽ€ (an SFrame key should never be used for both operations, so don't mix them up!!). a key context tracks the key and salt tied to the KID, plus the current CTR value. a sending key context also tracks the next CTR value it's going to use ๐Ÿฆ‹

here are the main moves you can make on an SFrame context:

  • Create an SFrame context: The context is initialized with a cipher suite and no KID mappings. ๐ŸŒธ
  • Add a key for sending: The key and salt are derived from the base key and used to initialize a send context, together with a zero CTR value. ๐Ÿ’–
  • Add a key for receiving: The key and salt are derived from the base key and used to initialize a send context. ๐Ÿ‘‘
  • Encrypt a plaintext: Encrypt a given plaintext using the key for a given KID, including the specified metadata. โœจ
  • Decrypt an SFrame ciphertext: Decrypt an SFrame ciphertext with the KID and CTR values specified in the SFrame header, and the provided metadata. ๐Ÿ”ฅ

Figure 10 shows an example of the kinds of structures and methods you could use to build an SFrame API in Rust. it's giving clean and simple ๐ŸŒˆ

type KeyId = u64;
type Counter = u64;
type CipherSuite = u16;

struct SendKeyContext {
  key: Vec<u8>,
  salt: Vec<u8>,
  next_counter: Counter,
}

struct RecvKeyContext {
  key: Vec<u8>,
  salt: Vec<u8>,
}

struct SFrameContext {
  cipher_suite: CipherSuite,
  send_keys: HashMap<KeyId, SendKeyContext>,
  recv_keys: HashMap<KeyId, RecvKeyContext>,
}

trait SFrameContextMethods {
  fn create(cipher_suite: CipherSuite) -> Self;
  fn add_send_key(&self, kid: KeyId, base_key: &[u8]);
  fn add_recv_key(&self, kid: KeyId, base_key: &[u8]);
  fn encrypt(&mut self, kid: KeyId, metadata: &[u8],
             plaintext: &[u8]) -> Vec<u8>;
  fn decrypt(&self, metadata: &[u8], ciphertext: &[u8]) -> Vec<u8>;
}

                   Figure 10: An Example SFrame API

Appendix B. Overhead Analysis

okay now the spicy math ๐Ÿ™ˆ any use of SFrame adds overhead, meaning extra bandwidth to send a given media stream. how much depends on a few things:

  • The number of senders involved in a conference (length of KID) ๐Ÿซถ
  • The duration of the conference (length of CTR) โณ
  • The cipher suite in use (length of authentication tag) ๐Ÿ”
  • Whether SFrame is used to encrypt packets, whole frames, or some other unit ๐Ÿ“ฆ

overall, you can estimate the overhead rate in kilobits per second like this:

OverheadKbps = (1 + |CTR| + |KID| + |TAG|) * 8 * CTPerSecond / 1024

the constant 1 is the fixed SFrame header ๐Ÿง. |CTR| and |KID| are the lengths of those fields, |TAG| is the cipher overhead, and CTPerSecond is how many SFrame ciphertexts get sent per second (like packets or frames per second). simple formula, big vibes โœจ

we're going to run overhead estimates for a bunch of common scenarios in the rest of this section ๐Ÿ’…

B.1. Assumptions

okay so in these calculations we make conservative assumptions about SFrame overhead ๐Ÿ›ก๏ธ the goal is that the numbers we compute here are likely to be an upper bound on what you'd see in practice. main character planning ๐Ÿ‘‘

        +==============+=======+============================+
        | Field        | Bytes | Explanation                |
        +==============+=======+============================+
        | Config byte  |     1 | Fixed                      |
        +--------------+-------+----------------------------+
        | Key ID (KID) |     2 | >255 senders; or MLS epoch |
        |              |       | (E=4) and >16 senders      |
        +--------------+-------+----------------------------+
        | Counter      |     3 | More than 24 hours of      |
        | (CTR)        |       | media in common cases      |
        +--------------+-------+----------------------------+
        | Cipher       |    16 | Full authentication tag    |
        | overhead     |       | (longest defined here)     |
        +--------------+-------+----------------------------+

                Table 3: Overhead Analysis Assumptions

so in total, each SFrame encryption adds 22 bytes of overhead ๐ŸŒธ we're gonna look at two scenarios: applying SFrame per frame and applying it per packet. in each one, we compute the SFrame overhead in absolute terms (kbps) and as a percentage of the base bandwidth ๐Ÿ“Š

B.2. Audio

in audio streams there's typically a one-to-one relationship between frames and packets ๐ŸŽต so the overhead is the same whether you use SFrame per packet or per frame. no difference, no drama ๐Ÿ’œ

Table 4 covers three scenarios based on the recommended configurations of the Opus codec [RFC6716] (where "fps" stands for "frames per second") ๐ŸŽง

 +==============+==============+=====+======+==========+==========+
 | Scenario     | Frame length | fps | Base | Overhead | Overhead |
 |              |              |     | kbps |   kbps   |    %     |
 +==============+==============+=====+======+==========+==========+
 | Narrow-band  |    120 ms    | 8.3 |  8   |   1.4    |  17.9%   |
 | speech       |              |     |      |          |          |
 +--------------+--------------+-----+------+----------+----------+
 | Full-band    |    20 ms     |  50 |  32  |   8.6    |  26.9%   |
 | speech       |              |     |      |          |          |
 +--------------+--------------+-----+------+----------+----------+
 | Full-band    |    10 ms     | 100 | 128  |   17.2   |  13.4%   |
 | stereo music |              |     |      |          |          |
 +--------------+--------------+-----+------+----------+----------+

            Table 4: SFrame Overhead for Audio Streams

B.3. Video

okay video frames can be bigger than an MTU, so they're commonly split across multiple packets ๐Ÿ“บ Tables 5 and 6 show the estimated overhead of encrypting a video stream. Table 5 is for SFrame applied per frame, and Table 6 is for SFrame applied per packet. the resolutions, frames per second, and bandwidths were picked to roughly reflect what modern video codecs can do, from very low to very high quality ๐ŸŒˆ

  +=============+=====+===========+===============+============+
  | Scenario    | fps | Base kbps | Overhead kbps | Overhead % |
  +=============+=====+===========+===============+============+
  | 426 x 240   | 7.5 |     45    |      1.3      |    2.9%    |
  +-------------+-----+-----------+---------------+------------+
  | 640 x 360   |  15 |    200    |      2.6      |    1.3%    |
  +-------------+-----+-----------+---------------+------------+
  | 640 x 360   |  30 |    400    |      5.2      |    1.3%    |
  +-------------+-----+-----------+---------------+------------+
  | 1280 x 720  |  30 |    1500   |      5.2      |    0.3%    |
  +-------------+-----+-----------+---------------+------------+
  | 1920 x 1080 |  60 |    7200   |      10.3     |    0.1%    |
  +-------------+-----+-----------+---------------+------------+

    Table 5: SFrame Overhead for a Video Stream Encrypted per
                              Frame
  +==========+=====+==============+======+==========+==========+
  | Scenario | fps | Packets per  | Base | Overhead | Overhead |
  |          |     | Second (pps) | kbps |   kbps   |    %     |
  +==========+=====+==============+======+==========+==========+
  | 426 x    | 7.5 |     7.5      |  45  |   1.3    |   2.9%   |
  | 240      |     |              |      |          |          |
  +----------+-----+--------------+------+----------+----------+
  | 640 x    |  15 |      30      | 200  |   5.2    |   2.6%   |
  | 360      |     |              |      |          |          |
  +----------+-----+--------------+------+----------+----------+
  | 640 x    |  30 |      60      | 400  |   10.3   |   2.6%   |
  | 360      |     |              |      |          |          |
  +----------+-----+--------------+------+----------+----------+
  | 1280 x   |  30 |     180      | 1500 |   30.9   |   2.1%   |
  | 720      |     |              |      |          |          |
  +----------+-----+--------------+------+----------+----------+
  | 1920 x   |  60 |     780      | 7200 |  134.1   |   1.9%   |
  | 1080     |     |              |      |          |          |
  +----------+-----+--------------+------+----------+----------+

    Table 6: SFrame Overhead for a Video Stream Encrypted per
                              Packet

the per-frame case is giving "the more quality you have, the less it hurts" ๐Ÿฅน the SFrame percentage overhead heads toward zero as video quality improves, since bandwidth is driven more by picture size than by frame rate. in the per-packet case, the SFrame percentage overhead approaches the ratio of SFrame overhead per packet to the MTU. here that's 22 bytes of SFrame overhead divided by an assumed 1200-byte MTU, which is about 1.8% ๐Ÿงฎ

B.4. Conferences

real conferences usually have several audio and video streams running at once ๐ŸŽ‰ the overhead of SFrame in a conference is the total of the overhead across all those individual streams. so yes, SFrame has a big percentage overhead on an audio stream, but if the conference also has a video stream, the audio overhead is probably negligible next to the conference's overall bandwidth ๐Ÿซง

for example, Table 7 shows the overhead estimates for a two-person conference where one person sends low-quality media and the other sends high-quality media. (we assume SFrame is applied per frame here.) the video streams dominate the bandwidth at the SFU, so the total bandwidth overhead is only around 1% ๐Ÿ’€โœจ

  +=====================+===========+===============+============+
  | Stream              | Base Kbps | Overhead Kbps | Overhead % |
  +=====================+===========+===============+============+
  | Participant 1 audio |     8     |      1.4      |   17.9%    |
  +---------------------+-----------+---------------+------------+
  | Participant 1 video |     45    |      1.3      |    2.9%    |
  +---------------------+-----------+---------------+------------+
  | Participant 2 audio |     32    |       9       |   26.9%    |
  +---------------------+-----------+---------------+------------+
  | Participant 2 video |    1500   |       5       |    0.3%    |
  +---------------------+-----------+---------------+------------+
  | Total at SFU        |    1585   |      16.5     |    1.0%    |
  +---------------------+-----------+---------------+------------+

        Table 7: SFrame Overhead for a Two-Person Conference

B.5. SFrame over RTP

okay so bestie, this part is where SFrame meets RTP ๐Ÿฆ‹ and it's giving "how do we make these two actually vibe together" energy ๐Ÿ’…

SFrame is a generic encapsulation format, but a lot of the apps that are likely to use it are built on RTP ๐ŸŽ€ This section talks about how you could integrate SFrame and RTP, and what challenges would need to be overcome ๐Ÿ’–

As we covered in Section 4.1, there are two natural patterns for plugging SFrame into an app: applying SFrame per frame or per packet โœจ For RTP-based apps, per packet means that the payload of each RTP packet is an SFrame ciphertext that starts with an SFrame header, as shown in Figure 11 ๐ŸŒธ Per frame means different RTP payloads look different: the first payload of a frame carries the SFrame headers, and the later payloads carry more chunks of the ciphertext, as shown in Figure 12 ๐Ÿงš

Receivers need to know which of these schemes the sender used for a given sequence of RTP packets, or they won't interpret the media payloads properly ๐Ÿ˜ญ SFrame does NOT give you a way to distribute this configuration info, though ๐Ÿ’€ For apps that use SDP to negotiate RTP media streams [RFC8866], an appropriate SDP extension could handle this job ๐Ÿซถ

Per-frame application also needs packetization and depacketization to be done in a generic way that doesn't depend on the media content of the packets ๐Ÿ™ˆ That's because what's being packetized is opaque ciphertext (except for the SFrame header) ๐Ÿ” For this generic packetization to work interoperably, one would have to be defined, for example as proposed in [RTP-PAYLOAD] ๐Ÿ‘‘

Here's the RTP packet layout with an SFrame-protected payload ๐Ÿฆ‹

   +---+-+-+-------+-+-----------+------------------------------+<-+
   |V=2|P|X|  CC   |M|     PT    |       sequence number        |  |
   +---+-+-+-------+-+-----------+------------------------------+  |
   |                          timestamp                         |  |
   +------------------------------------------------------------+  |
   |          synchronization source (SSRC) identifier          |  |
   +============================================================+  |
   |           contributing source (CSRC) identifiers           |  |
   |                              ....                          |  |
   +------------------------------------------------------------+  |
   |                  RTP extension(s) (OPTIONAL)               |  |
+->+-------------------+----------------------------------------+  |
|  |  SFrame header    |                                        |  |
|  +-------------------+                                        |  |
|  |                                                            |  |
|  |         SFrame encrypted and authenticated payload         |  |
|  |                                                            |  |
+->+------------------------------------------------------------+<-+
|  |                   SRTP authentication tag                  |  |
|  +------------------------------------------------------------+  |
|                                                                  |
+--- SRTP Encrypted Portion          SRTP Authenticated Portion ---+

            Figure 11: SRTP Packet with SFrame-Protected Payload

And here's the per-frame encryption flow for RTP ๐ŸŒˆ

      +----------------+  +---------------+
      | frame metadata |  |               |
      +-------+--------+  |               |
              |           |     frame     |
              |           |               |
              |           |               |
              |           +-------+-------+
              |                   |
              |                   |
              V                   V
   +--------------------------------------+
   |            SFrame Encrypt            |
   +--------------------------------------+
      |                           |
      |                           |
      |                           V
      |                   +-------+-------+
      |                   |               |
      |                   |               |
      |                   |   encrypted   |
      |                   |     frame     |
      |                   |               |
      |                   |               |
      |                   +-------+-------+
      |                           |
      |                  generic RTP packetize
      |                           |
      |    +----------------------+--------.....--------+
      |    |                      |                     |
      V    V                      V                     V
   +---------------+      +---------------+     +---------------+
   | SFrame header |      |               |     |               |
   +---------------+      |               |     |               |
   |               |      |  payload 2/N  | ... |  payload N/N  |
   |  payload 1/N  |      |               |     |               |
   |               |      |               |     |               |
   +---------------+      +---------------+     +---------------+

        Figure 12: Encryption Flow with per-Frame Encryption for RTP

Appendix C. Test Vectors ๐Ÿงช

okay this is the part where implementers get to check their homework, and I'm obsessed ๐Ÿ˜ญ This section gives you test vectors so you can verify that your SFrame encryption and decryption is actually correct ๐Ÿ’… Besides vectors for the whole encrypt/decrypt process, there are also vectors for header encoding/decoding, and for AEAD encryption/decryption using the AES-CTR construction defined in Section 4.5.1 โœจ

All values are either numeric or byte strings ๐Ÿ“ Numbers are written as hex with a 0x prefix, and byte strings are written in hex encoding ๐ŸŒธ

Line breaks and whitespace inside values are added so the text fits the RFC width requirements, so take them out before you use the values ๐Ÿ™ˆ The same vectors are also available in JSON at [TestVectors] ๐Ÿ’– In the JSON version, numbers are JSON numbers and byte strings are JSON strings holding the hex encoding ๐Ÿซถ

C.1. Header Encoding/Decoding

For each case, there are three things:

  • kid: A KID value
  • ctr: A CTR value
  • header: An encoded SFrame header

Your implementation should check that:

  • Encoding a header with the KID and CTR gives you the provided header value
  • Decoding the provided header value gives you the provided KID and CTR values

Here are the cases ๐ŸŽ€

   kid: 0x0000000000000000
   ctr: 0x0000000000000000
   header: 00

   kid: 0x0000000000000000
   ctr: 0x0000000000000001
   header: 01

   kid: 0x0000000000000000
   ctr: 0x00000000000000ff
   header: 08ff

   kid: 0x0000000000000000
   ctr: 0x0000000000000100
   header: 090100

   kid: 0x0000000000000000
   ctr: 0x000000000000ffff
   header: 09ffff

   kid: 0x0000000000000000
   ctr: 0x0000000000010000
   header: 0a010000

   kid: 0x0000000000000000
   ctr: 0x0000000000ffffff
   header: 0affffff

   kid: 0x0000000000000000
   ctr: 0x0000000001000000
   header: 0b01000000

   kid: 0x0000000000000000
   ctr: 0x00000000ffffffff
   header: 0bffffffff

   kid: 0x0000000000000000
   ctr: 0x0000000100000000
   header: 0c0100000000

   kid: 0x0000000000000000
   ctr: 0x000000ffffffffff
   header: 0cffffffffff

   kid: 0x0000000000000000
   ctr: 0x0000010000000000
   header: 0d010000000000

   kid: 0x0000000000000000
   ctr: 0x0000ffffffffffff
   header: 0dffffffffffff

   kid: 0x0000000000000000
   ctr: 0x0001000000000000
   header: 0e01000000000000

   kid: 0x0000000000000000
   ctr: 0x00ffffffffffffff
   header: 0effffffffffffff

   kid: 0x0000000000000000
   ctr: 0x0100000000000000
   header: 0f0100000000000000

   kid: 0x0000000000000000
   ctr: 0xffffffffffffffff
   header: 0fffffffffffffffff

   kid: 0x0000000000000001
   ctr: 0x0000000000000000
   header: 10

   kid: 0x0000000000000001
   ctr: 0x0000000000000001
   header: 11

   kid: 0x0000000000000001
   ctr: 0x00000000000000ff
   header: 18ff

   kid: 0x0000000000000001
   ctr: 0x0000000000000100
   header: 190100

   kid: 0x0000000000000001
   ctr: 0x000000000000ffff
   header: 19ffff

   kid: 0x0000000000000001
   ctr: 0x0000000000010000
   header: 1a010000

   kid: 0x0000000000000001
   ctr: 0x0000000000ffffff
   header: 1affffff

   kid: 0x0000000000000001
   ctr: 0x0000000001000000
   header: 1b01000000

   kid: 0x0000000000000001
   ctr: 0x00000000ffffffff
   header: 1bffffffff

   kid: 0x0000000000000001
   ctr: 0x0000000100000000
   header: 1c0100000000

   kid: 0x0000000000000001
   ctr: 0x000000ffffffffff
   header: 1cffffffffff

   kid: 0x0000000000000001
   ctr: 0x0000010000000000
   header: 1d010000000000

   kid: 0x0000000000000001
   ctr: 0x0000ffffffffffff
   header: 1dffffffffffff

   kid: 0x0000000000000001
   ctr: 0x0001000000000000
   header: 1e01000000000000

   kid: 0x0000000000000001
   ctr: 0x00ffffffffffffff
   header: 1effffffffffffff

   kid: 0x0000000000000001
   ctr: 0x0100000000000000
   header: 1f0100000000000000

   kid: 0x0000000000000001
   ctr: 0xffffffffffffffff
   header: 1fffffffffffffffff

   kid: 0x00000000000000ff
   ctr: 0x0000000000000000
   header: 80ff

   kid: 0x00000000000000ff
   ctr: 0x0000000000000001
   header: 81ff

   kid: 0x00000000000000ff
   ctr: 0x00000000000000ff
   header: 88ffff

   kid: 0x00000000000000ff
   ctr: 0x0000000000000100
   header: 89ff0100

   kid: 0x00000000000000ff
   ctr: 0x000000000000ffff
   header: 89ffffff

   kid: 0x00000000000000ff
   ctr: 0x0000000000010000
   header: 8aff010000

   kid: 0x00000000000000ff
   ctr: 0x0000000000ffffff
   header: 8affffffff

   kid: 0x00000000000000ff
   ctr: 0x0000000001000000
   header: 8bff01000000

   kid: 0x00000000000000ff
   ctr: 0x00000000ffffffff
   header: 8bffffffffff

   kid: 0x00000000000000ff
   ctr: 0x0000000100000000
   header: 8cff0100000000

   kid: 0x00000000000000ff
   ctr: 0x000000ffffffffff
   header: 8cffffffffffff

   kid: 0x00000000000000ff
   ctr: 0x0000010000000000
   header: 8dff010000000000

   kid: 0x00000000000000ff
   ctr: 0x0000ffffffffffff
   header: 8dffffffffffffff

   kid: 0x00000000000000ff
   ctr: 0x0001000000000000
   header: 8eff01000000000000

   kid: 0x00000000000000ff
   ctr: 0x00ffffffffffffff
   header: 8effffffffffffffff

   kid: 0x00000000000000ff
   ctr: 0x0100000000000000
   header: 8fff0100000000000000

   kid: 0x00000000000000ff
   ctr: 0xffffffffffffffff
   header: 8fffffffffffffffffff

   kid: 0x0000000000000100
   ctr: 0x0000000000000000
   header: 900100

   kid: 0x0000000000000100
   ctr: 0x0000000000000001
   header: 910100

   kid: 0x0000000000000100
   ctr: 0x00000000000000ff
   header: 980100ff

   kid: 0x0000000000000100
   ctr: 0x0000000000000100
   header: 9901000100

   kid: 0x0000000000000100
   ctr: 0x000000000000ffff
   header: 990100ffff

   kid: 0x0000000000000100
   ctr: 0x0000000000010000
   header: 9a0100010000

   kid: 0x0000000000000100
   ctr: 0x0000000000ffffff
   header: 9a0100ffffff

   kid: 0x0000000000000100
   ctr: 0x0000000001000000
   header: 9b010001000000

   kid: 0x0000000000000100
   ctr: 0x00000000ffffffff
   header: 9b0100ffffffff

   kid: 0x0000000000000100
   ctr: 0x0000000100000000
   header: 9c01000100000000

   kid: 0x0000000000000100
   ctr: 0x000000ffffffffff
   header: 9c0100ffffffffff

   kid: 0x0000000000000100
   ctr: 0x0000010000000000
   header: 9d0100010000000000

   kid: 0x0000000000000100
   ctr: 0x0000ffffffffffff
   header: 9d0100ffffffffffff

   kid: 0x0000000000000100
   ctr: 0x0001000000000000
   header: 9e010001000000000000

   kid: 0x0000000000000100
   ctr: 0x00ffffffffffffff
   header: 9e0100ffffffffffffff

   kid: 0x0000000000000100
   ctr: 0x0100000000000000
   header: 9f01000100000000000000

   kid: 0x0000000000000100
   ctr: 0xffffffffffffffff
   header: 9f0100ffffffffffffffff

Okay bestie, here are the rest of the header test vectors, straight from the source ๐ŸŽ€โœจ

kid: 0x0000000001000000
ctr: 0x0000000000000000
header: b001000000

kid: 0x0000000001000000
ctr: 0x0000000000000001
header: b101000000

kid: 0x0000000001000000
ctr: 0x00000000000000ff
header: b801000000ff

kid: 0x0000000001000000
ctr: 0x0000000000000100
header: b9010000000100

kid: 0x0000000001000000
ctr: 0x000000000000ffff
header: b901000000ffff

kid: 0x0000000001000000
ctr: 0x0000000000010000
header: ba01000000010000

kid: 0x0000000001000000
ctr: 0x0000000000ffffff
header: ba01000000ffffff

kid: 0x0000000001000000
ctr: 0x0000000001000000
header: bb0100000001000000

kid: 0x0000000001000000
ctr: 0x00000000ffffffff
header: bb01000000ffffffff

kid: 0x0000000001000000
ctr: 0x0000000100000000
header: bc010000000100000000

kid: 0x0000000001000000
ctr: 0x000000ffffffffff
header: bc01000000ffffffffff

kid: 0x0000000001000000
ctr: 0x0000010000000000
header: bd01000000010000000000

kid: 0x0000000001000000
ctr: 0x0000ffffffffffff
header: bd01000000ffffffffffff

kid: 0x0000000001000000
ctr: 0x0001000000000000
header: be0100000001000000000000

kid: 0x0000000001000000
ctr: 0x00ffffffffffffff
header: be01000000ffffffffffffff

kid: 0x0000000001000000
ctr: 0x0100000000000000
header: bf010000000100000000000000

kid: 0x0000000001000000
ctr: 0xffffffffffffffff
header: bf01000000ffffffffffffffff

kid: 0x00000000ffffffff
ctr: 0x0000000000000000
header: b0ffffffff

kid: 0x00000000ffffffff
ctr: 0x0000000000000001
header: b1ffffffff

kid: 0x00000000ffffffff
ctr: 0x00000000000000ff
header: b8ffffffffff

kid: 0x00000000ffffffff
ctr: 0x0000000000000100
header: b9ffffffff0100

kid: 0x00000000ffffffff
ctr: 0x000000000000ffff
header: b9ffffffffffff

kid: 0x00000000ffffffff
ctr: 0x0000000000010000
header: baffffffff010000

kid: 0x00000000ffffffff
ctr: 0x0000000000ffffff
header: baffffffffffffff

kid: 0x00000000ffffffff
ctr: 0x0000000001000000
header: bbffffffff01000000

kid: 0x00000000ffffffff
ctr: 0x00000000ffffffff
header: bbffffffffffffffff

kid: 0x00000000ffffffff
ctr: 0x0000000100000000
header: bcffffffff0100000000

kid: 0x00000000ffffffff
ctr: 0x000000ffffffffff
header: bcffffffffffffffffff

kid: 0x00000000ffffffff
ctr: 0x0000010000000000
header: bdffffffff010000000000

kid: 0x00000000ffffffff
ctr: 0x0000ffffffffffff
header: bdffffffffffffffffffff

kid: 0x00000000ffffffff
ctr: 0x0001000000000000
header: beffffffff01000000000000

kid: 0x00000000ffffffff
ctr: 0x00ffffffffffffff
header: beffffffffffffffffffffff

kid: 0x00000000ffffffff
ctr: 0x0100000000000000
header: bfffffffff0100000000000000

kid: 0x00000000ffffffff
ctr: 0xffffffffffffffff
header: bfffffffffffffffffffffffff

kid: 0x0000000100000000
ctr: 0x0000000000000000
header: c00100000000

kid: 0x0000000100000000
ctr: 0x0000000000000001
header: c10100000000

kid: 0x0000000100000000
ctr: 0x00000000000000ff
header: c80100000000ff

kid: 0x0000000100000000
ctr: 0x0000000000000100
header: c901000000000100

kid: 0x0000000100000000
ctr: 0x000000000000ffff
header: c90100000000ffff

kid: 0x0000000100000000
ctr: 0x0000000000010000
header: ca0100000000010000

kid: 0x0000000100000000
ctr: 0x0000000000ffffff
header: ca0100000000ffffff

kid: 0x0000000100000000
ctr: 0x0000000001000000
header: cb010000000001000000

kid: 0x0000000100000000
ctr: 0x00000000ffffffff
header: cb0100000000ffffffff

kid: 0x0000000100000000
ctr: 0x0000000100000000
header: cc01000000000100000000

kid: 0x0000000100000000
ctr: 0x000000ffffffffff
header: cc0100000000ffffffffff

kid: 0x0000000100000000
ctr: 0x0000010000000000
header: cd0100000000010000000000

kid: 0x0000000100000000
ctr: 0x0000ffffffffffff
header: cd0100000000ffffffffffff

kid: 0x0000000100000000
ctr: 0x0001000000000000
header: ce010000000001000000000000

kid: 0x0000000100000000
ctr: 0x00ffffffffffffff
header: ce0100000000ffffffffffffff

kid: 0x0000000100000000
ctr: 0x0100000000000000
header: cf01000000000100000000000000

kid: 0x0000000100000000
ctr: 0xffffffffffffffff
header: cf0100000000ffffffffffffffff

kid: 0x000000ffffffffff
ctr: 0x0000000000000000
header: c0ffffffffff

kid: 0x000000ffffffffff
ctr: 0x0000000000000001
header: c1ffffffffff

kid: 0x000000ffffffffff
ctr: 0x00000000000000ff
header: c8ffffffffffff

kid: 0x000000ffffffffff
ctr: 0x0000000000000100
header: c9ffffffffff0100

kid: 0x000000ffffffffff
ctr: 0x000000000000ffff
header: c9ffffffffffffff

kid: 0x000000ffffffffff
ctr: 0x0000000000010000
header: caffffffffff010000

kid: 0x000000ffffffffff
ctr: 0x0000000000ffffff
header: caffffffffffffffff

kid: 0x000000ffffffffff
ctr: 0x0000000001000000
header: cbffffffffff01000000

kid: 0x000000ffffffffff
ctr: 0x00000000ffffffff
header: cbffffffffffffffffff

kid: 0x000000ffffffffff
ctr: 0x0000000100000000
header: ccffffffffff0100000000

kid: 0x000000ffffffffff
ctr: 0x000000ffffffffff
header: ccffffffffffffffffffff

kid: 0x000000ffffffffff
ctr: 0x0000010000000000
header: cdffffffffff010000000000

kid: 0x000000ffffffffff
ctr: 0x0000ffffffffffff
header: cdffffffffffffffffffffff

kid: 0x000000ffffffffff
ctr: 0x0001000000000000
header: ceffffffffff01000000000000

kid: 0x000000ffffffffff
ctr: 0x00ffffffffffffff
header: ceffffffffffffffffffffffff

kid: 0x000000ffffffffff
ctr: 0x0100000000000000
header: cfffffffffff0100000000000000

kid: 0x000000ffffffffff
ctr: 0xffffffffffffffff
header: cfffffffffffffffffffffffffff

kid: 0x0000010000000000
ctr: 0x0000000000000000
header: d0010000000000

kid: 0x0000010000000000
ctr: 0x0000000000000001
header: d1010000000000

kid: 0x0000010000000000
ctr: 0x00000000000000ff
header: d8010000000000ff

kid: 0x0000010000000000
ctr: 0x0000000000000100
header: d90100000000000100

kid: 0x0000010000000000
ctr: 0x000000000000ffff
header: d9010000000000ffff

kid: 0x0000010000000000
ctr: 0x0000000000010000
header: da010000000000010000

kid: 0x0000010000000000
ctr: 0x0000000000ffffff
header: da010000000000ffffff

kid: 0x0000010000000000
ctr: 0x0000000001000000
header: db01000000000001000000

kid: 0x0000010000000000
ctr: 0x00000000ffffffff
header: db010000000000ffffffff

kid: 0x0000010000000000
ctr: 0x0000000100000000
header: dc0100000000000100000000

kid: 0x0000010000000000
ctr: 0x000000ffffffffff
header: dc010000000000ffffffffff

kid: 0x0000010000000000
ctr: 0x0000010000000000
header: dd010000000000010000000000

kid: 0x0000010000000000
ctr: 0x0000ffffffffffff
header: dd010000000000ffffffffffff

kid: 0x0000010000000000
ctr: 0x0001000000000000
header: de01000000000001000000000000

kid: 0x0000010000000000
ctr: 0x00ffffffffffffff
header: de010000000000ffffffffffffff

kid: 0x0000010000000000
ctr: 0x0100000000000000
header: df0100000000000100000000000000

kid: 0x0000010000000000
ctr: 0xffffffffffffffff
header: df010000000000ffffffffffffffff

kid: 0x0000ffffffffffff
ctr: 0x0000000000000000
header: d0ffffffffffff

kid: 0x0000ffffffffffff
ctr: 0x0000000000000001
header: d1ffffffffffff

kid: 0x0000ffffffffffff
ctr: 0x00000000000000ff
header: d8ffffffffffffff

kid: 0x0000ffffffffffff
ctr: 0x0000000000000100
header: d9ffffffffffff0100
   kid: 0x0000ffffffffffff
   ctr: 0x000000000000ffff
   header: d9ffffffffffffffff

   kid: 0x0000ffffffffffff
   ctr: 0x0000000000010000
   header: daffffffffffff010000

   kid: 0x0000ffffffffffff
   ctr: 0x0000000000ffffff
   header: daffffffffffffffffff

   kid: 0x0000ffffffffffff
   ctr: 0x0000000001000000
   header: dbffffffffffff01000000

   kid: 0x0000ffffffffffff
   ctr: 0x00000000ffffffff
   header: dbffffffffffffffffffff

   kid: 0x0000ffffffffffff
   ctr: 0x0000000100000000
   header: dcffffffffffff0100000000

   kid: 0x0000ffffffffffff
   ctr: 0x000000ffffffffff
   header: dcffffffffffffffffffffff

   kid: 0x0000ffffffffffff
   ctr: 0x0000010000000000
   header: ddffffffffffff010000000000

   kid: 0x0000ffffffffffff
   ctr: 0x0000ffffffffffff
   header: ddffffffffffffffffffffffff

   kid: 0x0000ffffffffffff
   ctr: 0x0001000000000000
   header: deffffffffffff01000000000000

   kid: 0x0000ffffffffffff
   ctr: 0x00ffffffffffffff
   header: deffffffffffffffffffffffffff

   kid: 0x0000ffffffffffff
   ctr: 0x0100000000000000
   header: dfffffffffffff0100000000000000

   kid: 0x0000ffffffffffff
   ctr: 0xffffffffffffffff
   header: dfffffffffffffffffffffffffffff

   kid: 0x0001000000000000
   ctr: 0x0000000000000000
   header: e001000000000000

   kid: 0x0001000000000000
   ctr: 0x0000000000000001
   header: e101000000000000

   kid: 0x0001000000000000
   ctr: 0x00000000000000ff
   header: e801000000000000ff

   kid: 0x0001000000000000
   ctr: 0x0000000000000100
   header: e9010000000000000100

   kid: 0x0001000000000000
   ctr: 0x000000000000ffff
   header: e901000000000000ffff

   kid: 0x0001000000000000
   ctr: 0x0000000000010000
   header: ea01000000000000010000

   kid: 0x0001000000000000
   ctr: 0x0000000000ffffff
   header: ea01000000000000ffffff

   kid: 0x0001000000000000
   ctr: 0x0000000001000000
   header: eb0100000000000001000000

   kid: 0x0001000000000000
   ctr: 0x00000000ffffffff
   header: eb01000000000000ffffffff

   kid: 0x0001000000000000
   ctr: 0x0000000100000000
   header: ec010000000000000100000000

   kid: 0x0001000000000000
   ctr: 0x000000ffffffffff
   header: ec01000000000000ffffffffff

   kid: 0x0001000000000000
   ctr: 0x0000010000000000
   header: ed01000000000000010000000000

   kid: 0x0001000000000000
   ctr: 0x0000ffffffffffff
   header: ed01000000000000ffffffffffff

   kid: 0x0001000000000000
   ctr: 0x0001000000000000
   header: ee0100000000000001000000000000

   kid: 0x0001000000000000
   ctr: 0x00ffffffffffffff
   header: ee01000000000000ffffffffffffff

   kid: 0x0001000000000000
   ctr: 0x0100000000000000
   header: ef010000000000000100000000000000

   kid: 0x0001000000000000
   ctr: 0xffffffffffffffff
   header: ef01000000000000ffffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0000000000000000
   header: e0ffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0000000000000001
   header: e1ffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x00000000000000ff
   header: e8ffffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0000000000000100
   header: e9ffffffffffffff0100

   kid: 0x00ffffffffffffff
   ctr: 0x000000000000ffff
   header: e9ffffffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0000000000010000
   header: eaffffffffffffff010000

   kid: 0x00ffffffffffffff
   ctr: 0x0000000000ffffff
   header: eaffffffffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0000000001000000
   header: ebffffffffffffff01000000

   kid: 0x00ffffffffffffff
   ctr: 0x00000000ffffffff
   header: ebffffffffffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0000000100000000
   header: ecffffffffffffff0100000000

   kid: 0x00ffffffffffffff
   ctr: 0x000000ffffffffff
   header: ecffffffffffffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0000010000000000
   header: edffffffffffffff010000000000

   kid: 0x00ffffffffffffff
   ctr: 0x0000ffffffffffff
   header: edffffffffffffffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0001000000000000
   header: eeffffffffffffff01000000000000

   kid: 0x00ffffffffffffff
   ctr: 0x00ffffffffffffff
   header: eeffffffffffffffffffffffffffff

   kid: 0x00ffffffffffffff
   ctr: 0x0100000000000000
   header: efffffffffffffff0100000000000000

   kid: 0x00ffffffffffffff
   ctr: 0xffffffffffffffff
   header: efffffffffffffffffffffffffffffff

   kid: 0x0100000000000000
   ctr: 0x0000000000000000
   header: f00100000000000000

   kid: 0x0100000000000000
   ctr: 0x0000000000000001
   header: f10100000000000000

   kid: 0x0100000000000000
   ctr: 0x00000000000000ff
   header: f80100000000000000ff

   kid: 0x0100000000000000
   ctr: 0x0000000000000100
   header: f901000000000000000100

   kid: 0x0100000000000000
   ctr: 0x000000000000ffff
   header: f90100000000000000ffff

   kid: 0x0100000000000000
   ctr: 0x0000000000010000
   header: fa0100000000000000010000

   kid: 0x0100000000000000
   ctr: 0x0000000000ffffff
   header: fa0100000000000000ffffff

   kid: 0x0100000000000000
   ctr: 0x0000000001000000
   header: fb010000000000000001000000

   kid: 0x0100000000000000
   ctr: 0x00000000ffffffff
   header: fb0100000000000000ffffffff

   kid: 0x0100000000000000
   ctr: 0x0000000100000000
   header: fc01000000000000000100000000

   kid: 0x0100000000000000
   ctr: 0x000000ffffffffff
   header: fc0100000000000000ffffffffff

   kid: 0x0100000000000000
   ctr: 0x0000010000000000
   header: fd0100000000000000010000000000

   kid: 0x0100000000000000
   ctr: 0x0000ffffffffffff
   header: fd0100000000000000ffffffffffff

   kid: 0x0100000000000000
   ctr: 0x0001000000000000
   header: fe010000000000000001000000000000

   kid: 0x0100000000000000
   ctr: 0x00ffffffffffffff
   header: fe0100000000000000ffffffffffffff

   kid: 0x0100000000000000
   ctr: 0x0100000000000000
   header: ff010000000000000001000000000000
           00

   kid: 0x0100000000000000
   ctr: 0xffffffffffffffff
   header: ff0100000000000000ffffffffffffff
           ff

   kid: 0xffffffffffffffff
   ctr: 0x0000000000000000
   header: f0ffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x0000000000000001
   header: f1ffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x00000000000000ff
   header: f8ffffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x0000000000000100
   header: f9ffffffffffffffff0100

   kid: 0xffffffffffffffff
   ctr: 0x000000000000ffff
   header: f9ffffffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x0000000000010000
   header: faffffffffffffffff010000

   kid: 0xffffffffffffffff
   ctr: 0x0000000000ffffff
   header: faffffffffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x0000000001000000
   header: fbffffffffffffffff01000000

   kid: 0xffffffffffffffff
   ctr: 0x00000000ffffffff
   header: fbffffffffffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x0000000100000000
   header: fcffffffffffffffff0100000000

   kid: 0xffffffffffffffff
   ctr: 0x000000ffffffffff
   header: fcffffffffffffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x0000010000000000
   header: fdffffffffffffffff010000000000

   kid: 0xffffffffffffffff
   ctr: 0x0000ffffffffffff
   header: fdffffffffffffffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x0001000000000000
   header: feffffffffffffffff01000000000000

   kid: 0xffffffffffffffff
   ctr: 0x00ffffffffffffff
   header: feffffffffffffffffffffffffffffff

   kid: 0xffffffffffffffff
   ctr: 0x0100000000000000
   header: ffffffffffffffffff01000000000000
           00

   kid: 0xffffffffffffffff
   ctr: 0xffffffffffffffff
   header: ffffffffffffffffffffffffffffffff
           ff

C.2. AEAD Encryption/Decryption Using AES-CTR and HMAC โœจ

okay bestie, now we get to the AEAD test vectors ๐ŸŽ€ so for each case we give you a bunch of little labelled values so you can check your work:

  • cipher_suite: the index of the cipher suite in use (see Section 8.1) ๐Ÿ’…
  • key: the key input to encryption/decryption ๐Ÿ”‘
  • enc_key: the encryption subkey produced by the derive_subkeys() algorithm ๐ŸŒธ
  • auth_key: the encryption subkey produced by the derive_subkeys() algorithm ๐Ÿฆ‹
  • nonce: the nonce input to encryption/decryption ๐Ÿงš
  • aad: the aad input to encryption/decryption ๐Ÿ’œ
  • pt: the plaintext ๐Ÿ“
  • ct: the ciphertext ๐Ÿ”ฅ

so an implementation should verify that the following are true, where AEAD.Encrypt and AEAD.Decrypt are as defined in Section 4.5.1, and this is the whole vibe check:

  • AEAD.Encrypt(key, nonce, aad, pt) == ct โœจ
  • AEAD.Decrypt(key, nonce, aad, ct) == pt โœจ

the other values in the test vector are just intermediate values that are there to help you debug when something goes sideways ๐Ÿ™ˆ

cipher_suite: 0x0001
key: 000102030405060708090a0b0c0d0e0f
     101112131415161718191a1b1c1d1e1f
     202122232425262728292a2b2c2d2e2f
enc_key: 000102030405060708090a0b0c0d0e0f
auth_key: 101112131415161718191a1b1c1d1e1f
          202122232425262728292a2b2c2d2e2f
nonce: 101112131415161718191a1b
aad: 4945544620534672616d65205747
pt: 64726166742d696574662d736672616d
    652d656e63
ct: 6339af04ada1d064688a442b8dc69d5b
    6bfa40f4bef0583e8081069cc60705

cipher_suite: 0x0002
key: 000102030405060708090a0b0c0d0e0f
     101112131415161718191a1b1c1d1e1f
     202122232425262728292a2b2c2d2e2f
enc_key: 000102030405060708090a0b0c0d0e0f
auth_key: 101112131415161718191a1b1c1d1e1f
          202122232425262728292a2b2c2d2e2f
nonce: 101112131415161718191a1b
aad: 4945544620534672616d65205747
pt: 64726166742d696574662d736672616d
    652d656e63
ct: 6339af04ada1d064688a442b8dc69d5b
    6bfa40f4be6e93b7da076927bb

cipher_suite: 0x0003
key: 000102030405060708090a0b0c0d0e0f
     101112131415161718191a1b1c1d1e1f
     202122232425262728292a2b2c2d2e2f
enc_key: 000102030405060708090a0b0c0d0e0f
auth_key: 101112131415161718191a1b1c1d1e1f
          202122232425262728292a2b2c2d2e2f
nonce: 101112131415161718191a1b
aad: 4945544620534672616d65205747
pt: 64726166742d696574662d736672616d
    652d656e63
ct: 6339af04ada1d064688a442b8dc69d5b
    6bfa40f4be09480509

C.3. SFrame Encryption/Decryption โœจ

okay so for each case, we give you a whole bundle of goodies ๐ŸŽ€:

  • cipher_suite: The index of the cipher suite in use (see Section 8.1)
  • kid: A KID value
  • ctr: A CTR value
  • base_key: The base_key input to the derive_key_salt algorithm
  • sframe_key_label: The label used to derive sframe_key in the derive_key_salt algorithm
  • sframe_salt_label: The label used to derive sframe_salt in the derive_key_salt algorithm
  • sframe_secret: The sframe_secret variable in the derive_key_salt algorithm
  • sframe_key: The sframe_key value produced by the derive_key_salt algorithm
  • sframe_salt: The sframe_salt value produced by the derive_key_salt algorithm
  • metadata: The metadata input to the SFrame encrypt algorithm
  • pt: The plaintext
  • ct: The SFrame ciphertext

An implementation should verify that the following are true, where encrypt and decrypt are as defined in Section 4.4, using an SFrame context initialized with base_key assigned to kid ๐Ÿซถ:

  • encrypt(ctr, kid, metadata, plaintext) == ct
  • decrypt(metadata, ct) == pt

The other values in the test vector are intermediate values provided to facilitate debugging of test failures. Think of them as the breadcrumbs ๐Ÿ“ that help you find where things went sideways ๐Ÿ˜ญ.

Vector one, with cipher_suite 0x0001 ๐Ÿ’œ:

cipher_suite: 0x0001
kid: 0x0000000000000123
ctr: 0x0000000000004567
base_key: 000102030405060708090a0b0c0d0e0f
sframe_key_label: 534672616d6520312e30205365637265
                  74206b65792000000000000001230001
sframe_salt_label: 534672616d6520312e30205365637265
                   742073616c7420000000000000012300
                   01
sframe_secret: d926952ca8b7ec4a95941d1ada3a5203
               ceff8cceee34f574d23909eb314c40c0
sframe_key: 3f7d9a7c83ae8e1c8a11ae695ab59314
            b367e359fadac7b9c46b2bc6f81f46e1
            6b96f0811868d59402b7e870102720b3
sframe_salt: 50b29329a04dc0f184ac3168
metadata: 4945544620534672616d65205747
nonce: 50b29329a04dc0f184ac740f
aad: 99012345674945544620534672616d65
     205747
pt: 64726166742d696574662d736672616d
    652d656e63
ct: 9901234567449408b6f490086165b9d6
    f62b24ae1a59a56486b4ae8ed036b889
    12e24f11

Vector two, with cipher_suite 0x0002 ๐ŸŒธ:

cipher_suite: 0x0002
kid: 0x0000000000000123
ctr: 0x0000000000004567
base_key: 000102030405060708090a0b0c0d0e0f
sframe_key_label: 534672616d6520312e30205365637265
                  74206b65792000000000000001230002
sframe_salt_label: 534672616d6520312e30205365637265
                   742073616c7420000000000000012300
                   02
sframe_secret: d926952ca8b7ec4a95941d1ada3a5203
               ceff8cceee34f574d23909eb314c40c0
sframe_key: e2ec5c797540310483b16bf6e7a570d2
            a27d192fe869c7ccd8584a8d9dab9154
            9fbe553f5113461ec6aa83bf3865553e
sframe_salt: e68ac8dd3d02fbcd368c5577
metadata: 4945544620534672616d65205747
nonce: e68ac8dd3d02fbcd368c1010
aad: 99012345674945544620534672616d65
     205747
pt: 64726166742d696574662d736672616d
    652d656e63
ct: 99012345673f31438db4d09434e43afa
    0f8a2f00867a2be085046a9f5cb4f101
    d607

Vector three, with cipher_suite 0x0003 ๐Ÿฆ‹:

cipher_suite: 0x0003
kid: 0x0000000000000123
ctr: 0x0000000000004567
base_key: 000102030405060708090a0b0c0d0e0f
sframe_key_label: 534672616d6520312e30205365637265
                  74206b65792000000000000001230003
sframe_salt_label: 534672616d6520312e30205365637265
                   742073616c7420000000000000012300
                   03
sframe_secret: d926952ca8b7ec4a95941d1ada3a5203
               ceff8cceee34f574d23909eb314c40c0
sframe_key: 2c5703089cbb8c583475e4fc461d97d1
            8809df79b6d550f78eb6d50ffa80d892
            11d57909934f46f5405e38cd583c69fe
sframe_salt: 38c16e4f5159700c00c7f350
metadata: 4945544620534672616d65205747
nonce: 38c16e4f5159700c00c7b637
aad: 99012345674945544620534672616d65
     205747
pt: 64726166742d696574662d736672616d
    652d656e63
ct: 990123456717fc8af28a5a695afcfc6c
    8df6358a17e26b2fcb3bae32e443

Vector four, with cipher_suite 0x0004 ๐Ÿงš:

cipher_suite: 0x0004
kid: 0x0000000000000123
ctr: 0x0000000000004567
base_key: 000102030405060708090a0b0c0d0e0f
sframe_key_label: 534672616d6520312e30205365637265
                  74206b65792000000000000001230004
sframe_salt_label: 534672616d6520312e30205365637265
                   742073616c7420000000000000012300
                   04
sframe_secret: d926952ca8b7ec4a95941d1ada3a5203
               ceff8cceee34f574d23909eb314c40c0
sframe_key: d34f547f4ca4f9a7447006fe7fcbf768
sframe_salt: 75234edefe07819026751816
metadata: 4945544620534672616d65205747
nonce: 75234edefe07819026755d71
aad: 99012345674945544620534672616d65
     205747
pt: 64726166742d696574662d736672616d
    652d656e63
ct: 9901234567b7412c2513a1b66dbb4884
    1bbaf17f598751176ad847681a69c6d0
    b091c07018ce4adb34eb

Vector five, with cipher_suite 0x0005 ๐Ÿ‘‘:

cipher_suite: 0x0005
kid: 0x0000000000000123
ctr: 0x0000000000004567
base_key: 000102030405060708090a0b0c0d0e0f
sframe_key_label: 534672616d6520312e30205365637265
                  74206b65792000000000000001230005
sframe_salt_label: 534672616d6520312e30205365637265
                   742073616c7420000000000000012300
                   05
sframe_secret: 0fc3ea6de6aac97a35f194cf9bed94d4
               b5230f1cb45a785c9fe5dce9c188938a
               b6ba005bc4c0a19181599e9d1bcf7b74
               aca48b60bf5e254e546d809313e083a3
sframe_key: d3e27b0d4a5ae9e55df01a70e6d4d28d
            969b246e2936f4b7a5d9b494da6b9633
sframe_salt: 84991c167b8cd23c93708ec7
metadata: 4945544620534672616d65205747
nonce: 84991c167b8cd23c9370cba0
aad: 99012345674945544620534672616d65
     205747
pt: 64726166742d696574662d736672616d
    652d656e63
ct: 990123456794f509d36e9beacb0e261d
    99c7d1e972f1fed787d4049f17ca2135
    3c1cc24d56ceabced279

Acknowledgements ๐Ÿซถ

The authors wish to specially thank Dr. Alex Gouaillard as one of the early contributors to the document. His passion and energy were key to the design and development of SFrame ๐ŸŒˆ๐Ÿ’–.

Contributors ๐Ÿ’…

Frรฉdรฉric Jacobs Apple Email: frederic.jacobs@apple.com

Marta Mularczyk Amazon Email: mulmarta@amazon.com

Suhas Nandakumar Cisco Email: snandaku@cisco.com

Tomas Rigaux Cisco Email: trigaux@cisco.com

Raphael Robert Phoenix R&D Email: ietf@raphaelrobert.com

Authors' Addresses ๐Ÿฆ‹

Emad Omara Apple Email: eomara@apple.com

Justin Uberti Fixie.ai Email: justin@fixie.ai

Sergio Garcia Murillo CoSMo Software Email: sergio.garcia.murillo@cosmosoftware.io

Richard Barnes (editor) Cisco Email: rlb@ipv.sx

Youenn Fablet Apple Email: youenn@apple.com

๐Ÿ“ฆ where this page comes from