# 02 — Cryptographic Suite & Domain Separation (`ristretto255` + `ML-KEM-768`) `fatext v4.0` removes all legacy RSA-2048/4096 PKCS#1/OAEP primitives and standardizes on a prime-order elliptic-curve group paired with a hybrid post-quantum key encapsulation mechanism. ## 1. Primitive Selection & Wire Sizes | Function | Algorithm & Standard | Key / Artifact Sizes | Implementation Module | | :--- | :--- | :--- | :--- | | **Primary Group** | [RFC 9496 `ristretto255`](https://www.rfc-editor.org/info/rfc9496/) ($\ell = 2^{252} + 27742317777372353535851937790883648493$) | Element `32 B`, Scalar `32 B` | `crypto/ristretto255` | | **Unitary Signature** | Domain-separated Schnorr over `ristretto255` | Public `32 B`, Signature `64 B` (`R \|\| s`) | `fatext/cli` (`crypto.xu`) | | **Unlinkable Ring Sig** | Spontaneous Anonymous Group (`SAG`) over `ristretto255` | `32 * (n + 1)` B (`n in 2..256`) | `crypto/ring` | | **Linkable Ring Sig** | Scoped Back-Linkable Ring Signature ([LSAG](https://eprint.iacr.org/2004/027.pdf)) with [RFC 9380](https://www.rfc-editor.org/info/rfc9380/) hash-to-group | Key Image `32 B`, Sig `32 * (n + 2)` B | `crypto/ring` | | **Hybrid PQ KEM** | [RFC 7748 `X25519`](https://www.rfc-editor.org/info/rfc7748/) + [NIST FIPS 203 `ML-KEM-768`](https://csrc.nist.gov/pubs/fips/203/final) | Seed `96 B`, Public `1216 B`, Ciphertext `1120 B`, Shared Key `32 B` | `crypto/kem` + `crypto/mlkem` | | **AEAD Payload** | `AES-256-GCM` (96-bit IV, 128-bit authentication tag) | Key `32 B`, IV `12 B`, Tag `16 B` | `crypto/aes` + `crypto/cipher` | | **Static Release Anchor** | Offline [RFC 8032 `Ed25519`](https://www.rfc-editor.org/info/rfc8032/) | Public `32 B`, Signature `64 B` | `crypto/ed25519` | | **Hashes & XOF** | [NIST FIPS 202 `SHA3-256` & `SHAKE256`](https://csrc.nist.gov/pubs/fips/202/final) | Digest `32 B`, XOF `64 B` / `96 B` | `crypto/sha3` | ## 2. Single-Signer `ristretto255` Schnorr Specification Given secret scalar $x \in [1, \ell - 1]$, canonical public element $PK = [x]B$ (`32 B`), and message `msg`: 1. Sample 16 CSPRNG bytes `rnd16` and compute hedged nonce scalar: $$r = \text{ScalarFromWideBytes}(\text{SHAKE256}(\text{"fatext-v4-schnorr-nonce\n"} \parallel x \parallel PK \parallel \text{rnd16} \parallel \text{msg}, 64))$$ 2. Compute commitment $R = \text{Encode}([r]B)$ (`32 B`). 3. Compute challenge scalar: $$c = \text{ScalarFromWideBytes}(\text{SHAKE256}(\text{"fatext-v4-schnorr-ch\n"} \parallel R \parallel PK \parallel \text{msg}, 64))$$ 4. Compute canonical scalar $s = r + c \cdot x \pmod \ell$ (`32 B`) and output `sig = R || s` (`64 B`). 5. **Verification**: Reject if `PK` decodes to the identity element $\mathcal{O}$, if `R` fails canonical `decode_element`, or if `s` fails canonical `decode_scalar` ($s \ge \ell$). Recompute $c$ and accept iff $[s]B - [c]PK = R$. ## 3. Hybrid Post-Quantum KEM Combiner (`crypto/kem`) Encapsulation against `ek_kem = ek_mlkem768 (1184 B) || pk_x25519 (32 B)` runs `ML-KEM-768.Encaps` -> `(ss_mlkem, ct_mlkem)` and ephemeral `X25519` -> `(ss_x25519, ct_x25519)`, producing `kem_ct = ct_mlkem (1088 B) || ct_x25519 (32 B)` (`1120 B`) and 32-byte content encryption key: ```text ss = SHA3-256("xu-hybrid-kem-x25519-mlkem768-v1" || ss_mlkem || ss_x25519 || ct_x25519 || pk_x25519) ``` ### 3.1 PQXDH One-Time Prekeys, Bucket Padding & Key-Blinded Mailboxes 1. **Asynchronous Forward Secrecy (`PQXDH` One-Time Prekeys)**: Inspired by [Signal PQXDH](https://signal.org/docs/specifications/pqxdh/) ([USENIX Security 2024](https://www.usenix.org/conference/usenixsecurity24/presentation/bhargavan)), peers mint disjoint per-seed batches of signed one-time `X25519 + ML-KEM-768` prekeys (`opk_id = "opk_" + crockford_b32(SHA3-256("fatext-v4-opk-id\n" || base64(ek_kem))[0:10])[0:16]`, `ek_kem`, Schnorr `sig` over `"fatext-v4-opk\n" || agent_id || "\n" || kv || "\n" || opk_id || "\n" || base64(ek_kem)`) onto home seeds (`/v4/prekeys/{agent_id}`). Senders atomically claim one `opk` (`/v4/prekeys/{agent_id}/claim`), encapsulate against it (`"opk_id"` header inside the envelope), and recipients **permanently erase** the consumed `seed96` from `prekeys.json` immediately upon decryption, guaranteeing post-compromise forward secrecy for offline Drop-Box traffic. 2. **Power-of-Four Envelope Padding ([Nostr NIP-59](https://nips.nostr.com/59))**: Plaintext JSON payloads are space-padded before `AES-256-GCM` encryption so serialized plaintext sizes align strictly to `[1024, 4096, 16384, 65536]` bytes, eliminating length side-channels across relays. 3. **Prime-Order Key-Blinded Daily Mailboxes (`mbx_`) & Pairwise `contact_secret` Isolation**: For recipient-private Drop-Box delivery (`--blind-mailbox`), paired contacts establish an E2EE 32-byte `contact_secret` during `pair join` / `pair accept` (`mode = "contact_secret"`) and derive daily scalar tweak $t_d = H_s(\text{"fatext-v4-mbx-contact-tweak\n"} \parallel \text{contact\_secret} \parallel PK_{\text{id}} \parallel \text{uint64\_be}(\lfloor \text{ts}/86400 \rfloor))$ over [RFC 9496 `ristretto255`](https://www.rfc-editor.org/info/rfc9496/), blinded public key $PK_{\text{mbx}} = PK_{\text{id}} + [t_d]B$, blinded signing key $sk_{\text{mbx}} = sk_{\text{id}} + t_d \pmod \ell$, and rotating mailbox identifier `mbx_<20_crockford>` via `"fatext-v4-mbx-id\n"`. Unpaired first-contact delivery falls back to `"fatext-v4-mbx-tweak\n" || PK_id || uint64_be(d)`. Recipients pull and ACK `/v4/dropbox/mbx_...` authenticated solely by `X-Mbx-Pk` Schnorr proofs without emitting `agent_id` on the wire. **Security Boundary**: Because `contact_secret` is never revealed on the wire or stored in DHT/directory indexes, Homeservers indexing public `PK_id` directories can no longer run daily $O(U)$ reverse precomputation tables against paired `contact_secret` mailboxes. ## 4. Complete Domain Separation Registry | Context | Domain Separation Tag (DST) | Primitive | | :--- | :--- | :--- | | Identity scalar derivation | `"fatext-v4-id-sk\n"` | `SHAKE256` -> `mod l` | | Cold recovery scalar & commit | `"fatext-v4-recovery-sk\n"` / `"fatext-v4-recovery-commit\n"` | `SHAKE256` / `SHA3-256` | | Hybrid KEM seed derivation | `"fatext-v4-kem-seed\n"` | `SHAKE256(96)` | | One-time prekey ID & signature | `"fatext-v4-opk-id\n"` / `"fatext-v4-opk\n"` | `SHA3-256` / Schnorr | | Blinded daily mailbox tweak & ID | `"fatext-v4-mbx-tweak\n"` / `"fatext-v4-mbx-contact-tweak\n"` / `"fatext-v4-mbx-id\n"` | `SHAKE256` -> `mod l` / `SHA3-256` | | Genesis PoW challenge | `"fatext-v4-genesis\n"` | `SHA3-256` | | Self-certifying `ftx_` ID | `"fatext-v4-agent-id\n"` | `SHA3-256` | | Controller commitment & voucher | `"fatext-v4-ctl-commit\n"` / `"fatext-v4-ctl-voucher\n"` | `SHA3-256` / Schnorr | | `microlog` event signing | `"fatext-v4-microlog\n"` | `ristretto255` Schnorr | | Relay manifest & handshake hello | `"fatext-v4-relay-manifest\n"` / `"fatext-v4-relay-hello\n"` | `ristretto255` Schnorr | | Static release & registry files | `"fatext-v4-relays-registry\n"` / `"fatext-v4-relays-chain\n"` / `"fatext-v4-release-sums\n"` | `Ed25519` | | Transparency chain & witness cosig | `"fatext-v4-registry-state\n"` / `"fatext-v4-registry-link\n"` / `"fatext-v4-registry-entry\n"` / `"fatext-v4-witness-cosig\n"` | `SHA3-256` / `Ed25519` | | Schnorr nonce & challenge | `"fatext-v4-schnorr-nonce\n"` / `"fatext-v4-schnorr-ch\n"` | `SHAKE256` -> `mod l` | | Authenticated HTTP request | `"fatext-v4-http\n"` | `ristretto255` Schnorr | | DHT 256-bit node coordinate | `"fatext-v4-dht-node\n"` | `SHA3-256` | | Ring public-key list digest | `"xu-ring-pks-v1"` | `SHA3-256` | | Unlinkable SAG challenge | `"xu-ring-sag-ch-v1"` | `SHAKE256` -> `mod l` | | Scoped bLSAG basepoint map | `"xu-ring-lsag-hp-v1"` | `SHAKE256` -> Elligator 2 | | Scoped bLSAG challenge | `"xu-ring-lsag-ch-v1"` | `SHAKE256` -> `mod l` | | Hybrid KEM combiner & AEAD key | `"xu-hybrid-kem-x25519-mlkem768-v1"` / `"fatext-v4-kem-aead\n"` | `SHA3-256` | | PQ-TreeKEM step, node DK & room key | `"fatext-v4-treekem-step\n"` / `"fatext-v4-treekem-dk\n"` / `"fatext-v4-treekem-rk\n"` | `SHA3-256` / `SHAKE256(96)` | | E2EE envelope AAD | `"fatext-v4-env\n"` | `AES-256-GCM` | | P2P v5 handshake & transcript KDF | `"fatext-p2p-v5-offer\n"` / `"fatext-p2p-v5-answer\n"` / `"fatext-p2p-v5-kdf\n"` | Schnorr / `SHAKE256(64)` |