E2E group chat with per-epoch sender keys
e2egroup-chatsender-keyskey-rotationaes-gcmhkdfaad
Pairwise E2E (one ECDH key per pair of users) has no key that three people share, so group chat needs a group-key scheme. TLDR shipped this in v1.58.0 (September 2026) as a separate feature from DMs that reuses the same identity keys. The design is a small, server-assisted version of "sender keys": one random symmetric key per group per epoch, wrapped individually for each member, rotated whenever someone leaves.
Why not fan-out
Fan-out (encrypt every message N times, once per member) needs no new key management but message size and time grow with N, and with a multi-key ring on each side the try-every-key decrypt multiplies by N. One group key per epoch means one ciphertext per message.
Construction
- Epoch key: random 32-byte AES-256 key, created by whoever creates or rotates the group.
- Wrap for each member:
wrapKey = HKDF-SHA256(ECDH(wrapper_identity, member_identity), salt empty, info "tldr-group-wrap-v1|<group>|<epoch>|<wrapper>|<member>"), thennonce12 || AES-GCM(wrapKey, epochKey) || mac16= 60 bytes per (member, epoch). The server stores the wrap plus the wrapper's username and public key so the member knows which key to ECDH against. - Messages:
base64(nonce || AES-GCM(epochKey, utf8(text), AAD "tldr-group-msg-v1|<group>|<epoch>") || mac). The AAD binds a ciphertext to its group and epoch, so the server cannot replay it elsewhere. - Domain separation: the HKDF info strings differ from the DM scheme's, and the crypto API refuses any info starting with the DM prefix, so a group wrap can never collide with a DM key even though the same identity keys are used.
- The group id is a client-chosen UUIDv4 so it can be bound into the wrap info before the server ever sees the group.
Membership churn (where the bugs live)
- Add with history: the adder wraps every epoch key it holds for the newcomer.
- Add without history: rotate to a new epoch that includes the newcomer, and record
history_from_idon the member row so the server also refuses to serve older ciphertext. Crypto and access control both enforce it. - Remove or leave: must rotate. If the remover is a member, it rotates immediately. If the
remover cannot rotate (an admin who is not a member, or a voluntary leave), the server deletes the
member's key rows and sets
rotation_pending; sending is refused (409) until any member client rotates, which it does automatically before its next send. - Epoch guard: rotate must present exactly
current + 1; sends must use exactlycurrent. Two members rotating at once: one wins, the other retries. - Messages from an epoch the client cannot unwrap render as "[No key for this message]".
- Blocking someone you share a group with makes the blocker leave; adding a member is refused if a block exists in either direction.
Server-side checks worth copying
- Membership enforced on every route; non-members get 404.
- Validate submitted wraps: every (member, epoch) exactly once, correct length, and
wrapped_by_pubmust be one of the wrapper's published or archived identity keys. - Member cap (20) for UI sanity; the rotation cost (20 ECDH + AES) is trivial.
- Rate limit (60 messages per minute per sender) and push throttle (1 per 30 s per sender per group, skip sender and muted members).
Client choices
- Group keys are never persisted locally. Each session re-unwraps from the server using the persisted identity keyring. That adds no new logout or export/import surface, which matters because key persistence is where DMs lost data before (E2E key management that never loses a key (keyring, backup, re-wrap)).
- Poll cursor is the highest message id received from the server, not the id of the last message you sent (someone else's lower id arriving just before yours would be skipped).
Testing
Unit tests on the pure crypto module (try-every-key, wrapper rotation, domain separation, AAD tamper, history off cannot read old epoch, malformed input) plus an interop vector from an independent Python implementation. The live API was exercised end to end with a Python X25519 client and throwaway users (45 checks including races), which were deleted afterward.
See also
- Simple E2E messaging with X25519 + HKDF + AES-GCM (and why not Signal)
- FCM push notifications from a PHP backend to a Flutter app