@weave_protocol/yoxallismus 0.1.0-beta.0 → 0.2.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,37 +43,69 @@ The design principle: **novel architecture, standardized primitives.** The primi
43
43
 
44
44
  - **Not a replacement for liboqs, PQClean, or BoringSSL.** Those libraries are the primitive layer. This library composes them for agent use cases.
45
45
  - **Not audited.** Signal, Cloudflare, Google, and every serious PQ-crypto deployment has been externally audited. This library has not.
46
- - **Not production-ready.** v0.1.0-beta.0 explicitly.
46
+ - **Not production-ready.** 0.2.0-beta.0 explicitly.
47
47
 
48
48
  ## Installation
49
49
 
50
50
  ```bash
51
- npm install @weave_protocol/yoxallismus
51
+ npm install @weave_protocol/yoxallismus@beta
52
52
  ```
53
53
 
54
+ The `@beta` tag is required: `latest` intentionally points at a stub until the library is audited.
55
+
54
56
  To silence the runtime beta banner:
55
57
 
56
58
  ```bash
57
59
  export YOXALL_SILENCE_BETA_WARNING=1
58
60
  ```
59
61
 
62
+ ## 🔒 Wire format `yoxall/2` is locked
63
+
64
+ As of **0.2.0-beta.0**, everything 0.2 writes stays readable by every release through **1.0**. The format is specified byte by byte in [WIRE_FORMAT.md](WIRE_FORMAT.md), and known-answer test vectors in CI fail the build if any byte changes. Later releases may only *add* optional fields; anything else becomes `yoxall/3`. Data written by v0.1 stays readable too.
65
+
60
66
  ## Quick start (programmatic)
61
67
 
68
+ **One-shot encryption to a public key (sealed box):**
69
+
62
70
  ```typescript
63
- import { PQCipher } from '@weave_protocol/yoxallismus';
71
+ import { generateHybridKeypair, publicKeyOf, seal, open, serializeSealed, deserializeSealed } from '@weave_protocol/yoxallismus';
64
72
 
65
- // Alice generates a keypair, shares her public key
66
- const alice = PQCipher.generateKeypair();
67
- const alicePub = PQCipher.publicKeyOf(alice);
73
+ const alice = generateHybridKeypair();
68
74
 
69
- // Bob encrypts a message to Alice
70
- const bundle = PQCipher.encryptTo(alicePub, new TextEncoder().encode('secret'));
75
+ // Anyone with Alice's public key can seal a message to her
76
+ const msg = seal(publicKeyOf(alice), new TextEncoder().encode('secret'), {
77
+ aad: new TextEncoder().encode('inbox:alice'), // context binding, checked on open
78
+ mode: 'cascade', // optional: AES-256-GCM inside ChaCha20-Poly1305
79
+ });
80
+ const wire = serializeSealed(msg); // yoxall/2 JSON envelope
71
81
 
72
- // Alice decrypts
73
- const message = PQCipher.decryptFrom(alice, bundle.ciphertext, bundle.payload);
74
- console.log(new TextDecoder().decode(message)); // "secret"
82
+ // Alice opens it, supplying the context she expects
83
+ const pt = open(alice, deserializeSealed(wire), { aad: new TextEncoder().encode('inbox:alice') });
75
84
  ```
76
85
 
86
+ **A conversation with post-compromise security (Double Ratchet):**
87
+
88
+ ```typescript
89
+ import { initiateSession, acceptSession, drEncrypt, drDecrypt } from '@weave_protocol/yoxallismus';
90
+
91
+ const bob = generateHybridKeypair();
92
+
93
+ // Alice starts a session from Bob's public key and sends first
94
+ const alice = initiateSession(publicKeyOf(bob));
95
+ const m1 = drEncrypt(alice, new TextEncoder().encode('hi bob'));
96
+
97
+ // Bob creates his session from that first message: no other setup needed
98
+ const { session: bobSession, plaintext } = acceptSession(bob, m1);
99
+
100
+ // From here, either side sends; keys ratchet forward every message
101
+ const reply = drEncrypt(bobSession, new TextEncoder().encode('hi alice'));
102
+ drDecrypt(alice, reply);
103
+ ```
104
+
105
+ Persist sessions with `serializeSession()` / `deserializeSession()`. Those envelopes contain secret keys, so store them encrypted.
106
+
107
+ `PQCipher` (the v0.1 API) still works and still reads v0.1 data; use `seal()` / `open()` for new code.
108
+
77
109
  ## Quick start (CLI)
78
110
 
79
111
  ```bash
@@ -99,19 +131,21 @@ weave-yoxall audit-self
99
131
  weave-yoxall benchmark
100
132
  ```
101
133
 
102
- ## What's inside (v0.1.0-beta.0)
134
+ ## What's inside (v0.2.0-beta.0)
103
135
 
104
136
  | Component | Primitive | Size / Cost |
105
137
  |---|---|---|
106
138
  | Classical KEM | X25519 (Node crypto) | 32B pub / 32B priv |
107
139
  | Post-quantum KEM | ML-KEM-768 via `@noble/post-quantum` (NIST FIPS 203) | 1184B pub / 2400B priv |
108
- | Hybrid combination | HKDF-SHA-256 over concatenated shared secrets | 32B output |
140
+ | Hybrid combination | **v2:** X-Wing-style HKDF over both secrets + X25519 ephemeral and recipient keys | 32B output |
109
141
  | AEAD | AES-256-GCM (Node crypto) | 12B nonce, 16B tag |
110
- | KDF | HKDF-SHA-256 (Node crypto) | 32B default |
111
- | Ratchet | Symmetric ratchet (chain-key advance via HKDF) | Forward secrecy within session |
112
- | Wire format | JSON envelopes with `_type` + `_version` discriminator | Base64url values |
142
+ | Cascade AEAD *(new)* | AES-256-GCM inside ChaCha20-Poly1305, independent keys | +44B |
143
+ | Sealed boxes *(new)* | Hybrid KEM → HKDF → AEAD or cascade | 1120B KEM ciphertext |
144
+ | Double Ratchet *(new)* | Signal Double Ratchet over X25519, seeded by the hybrid KEM | Forward secrecy + post-compromise security |
145
+ | Wire format | `yoxall/2` JSON envelopes, **locked through 1.0** | Base64url values |
146
+ | v1 detection *(new)* | Recognizes Hord `YoxallismusCipher` payloads (unrecoverable; YOXALL-2026-003) | — |
113
147
 
114
- ## Performance (v0.1.0-beta.0)
148
+ ## Performance (measured on v0.1.0-beta.0; v0.2 adds no cost to these paths)
115
149
 
116
150
  Measured on Node.js 22, x86_64, single-threaded, warm cache:
117
151
 
@@ -133,15 +167,16 @@ weave-yoxall test
133
167
  ```
134
168
 
135
169
  This runs assertions on:
136
- - AEAD encrypt/decrypt roundtrip
137
- - Ciphertext bit-flip rejection
138
- - AAD binding
170
+ - AEAD encrypt/decrypt roundtrip, bit-flip rejection, AAD binding
139
171
  - PQ-hybrid keypair sizes match NIST FIPS 203
140
172
  - Encapsulate/decapsulate produce matching shared secrets
141
173
  - Wrong recipient cannot decrypt
142
- - Ratchet forward-motion and message counter
174
+ - Sealed boxes in both modes, including wrong-AAD rejection
175
+ - Double Ratchet: session start from the handshake alone, and **a stolen session copy that stops decrypting after one DH round trip** (post-compromise security)
143
176
  - Serialization roundtrip preserves bytes
144
177
 
178
+ The full suite (`npm test`, 26 tests) also covers the `yoxall/2` known-answer vectors, out-of-order delivery across ratchet steps, replay and forgery rejection that leaves the session untouched, the skipped-message limit, and v1 payload detection.
179
+
145
180
  To verify known-attack vectors are rejected:
146
181
 
147
182
  ```bash
@@ -151,15 +186,13 @@ weave-yoxall audit-self
151
186
  ## Known limitations
152
187
 
153
188
  - **No formal external audit** performed
154
- - **No threshold encryption** (multi-agent m-of-n) yet — planned v0.2+
155
- - **No DH double-ratchet** — v0.1 only has symmetric ratcheting; no post-compromise recovery. Planned v0.2.
156
- - **No zero-knowledge proofs** yet — planned v0.3+
157
- - **No verifiable delay functions** yet — planned v0.3+
158
- - **No FHE integration** yet — planned v0.4+
159
- - **No Yoxallismus v1 backward-compat shim** yet — planned v0.2
160
- - **No cascade cipher** (classical ⊕ PQ) mode — planned v0.2
161
- - **No quantum-RNG integration** — planned v0.3+
162
- - **Wire format not stabilized** — may change between v0.1 and v0.2 (migration tooling will accompany the break)
189
+ - **Ratchet steps are classical.** Sessions *start* post-quantum (hybrid KEM), but ongoing Double Ratchet DH steps use X25519, as in Signal's original design. A PQ ratchet is planned after v0.3.
190
+ - **No sender authentication**: sealed boxes and sessions are sender-anonymous. Authenticate peers at a higher layer.
191
+ - **Yoxallismus v1 (Hord) payloads can't be decrypted** by any implementation; v0.2 detects them and explains why (YOXALL-2026-003).
192
+ - **No threshold encryption** (multi-agent m-of-n) yet, planned v0.3
193
+ - **No zero-knowledge proofs or verifiable delay functions** yet, planned v0.3+
194
+ - **No FHE integration** yet, planned v0.4+
195
+ - **No quantum-RNG integration**, planned v0.3+
163
196
 
164
197
  See `weave-yoxall status` for the machine-readable version of this list.
165
198
 
@@ -174,10 +207,13 @@ Full threat model in [THREAT_MODEL.md](THREAT_MODEL.md).
174
207
  - Chosen-ciphertext attacks on the KEM (via ML-KEM's IND-CCA2 security + X25519 ephemeral keys)
175
208
  - Post-quantum harvest-now-decrypt-later on ciphertexts (via hybrid KEM PQ half)
176
209
  - Forward secrecy of past messages within a session (via ratcheting)
210
+ - Post-compromise recovery: a stolen session stops working after one DH round trip (Double Ratchet)
211
+ - Out-of-order and lost messages within a session
177
212
 
178
- **What v0.1 does NOT defend against:**
179
- - Post-compromise recovery (need DH ratcheting; planned v0.2)
180
- - Multi-agent state isolation (need threshold encryption; planned v0.2+)
213
+ **What v0.2 does NOT defend against:**
214
+ - Quantum attacks on the ongoing ratchet: only the session start is post-quantum
215
+ - Sender impersonation: messages are sender-anonymous
216
+ - Multi-agent state isolation (need threshold encryption; planned v0.3)
181
217
  - Side-channel attacks (timing, cache, power)
182
218
  - Compromised RNG
183
219
  - Malicious dependency updates
@@ -2,7 +2,7 @@
2
2
 
3
3
  _This document is the public record of all security advisories issued for this library._
4
4
 
5
- _As of v0.1.0-beta.0: no advisories have been issued yet._
5
+ _Three advisories have been issued, all found during v0.2 development and fixed or documented in 0.2.0-beta.0._
6
6
 
7
7
  ---
8
8
 
@@ -34,7 +34,50 @@ Each entry follows this structure:
34
34
 
35
35
  ## Advisories
36
36
 
37
- _(none yet)_
37
+ ### YOXALL-2026-001: v0.1 symmetric ratchet has no interoperable session start
38
+
39
+ - **Severity:** Low (availability / misuse; no confidentiality break)
40
+ - **Affects:** @weave_protocol/yoxallismus 0.1.0-beta.0
41
+ - **Fixed in:** 0.2.0-beta.0 (replaced by the Double Ratchet)
42
+ - **Reporter:** found internally during v0.2 development
43
+
44
+ **Description:** `initRatchet(sharedSecret)` salts the chain key with a random `sessionId` generated locally, and nothing transmits it. Two parties calling it with the same shared secret derive different chain keys and cannot exchange messages. The v0.1 self-test only passed by copying the sender's `sessionId` and `chainKey` into the receiver.
45
+
46
+ **Impact:** The v0.1 ratchet couldn't be used between two real parties without an ad-hoc, unspecified state transfer. A transfer like that, done carelessly, could expose chain keys.
47
+
48
+ **Fix:** v0.2 adds `initiateSession()` / `acceptSession()` (Double Ratchet), where the session is derived from the hybrid KEM handshake carried in the first messages. `initRatchet` remains only for compatibility and is deprecated.
49
+
50
+ **Mitigation for users on older versions:** Use `initiateSession` / `acceptSession`.
51
+
52
+ ### YOXALL-2026-002: v0.1 KEM combiner doesn't bind the X25519 public keys
53
+
54
+ - **Severity:** Low (defense in depth; no known practical attack)
55
+ - **Affects:** @weave_protocol/yoxallismus 0.1.0-beta.0
56
+ - **Fixed in:** 0.2.0-beta.0 (combiner v2)
57
+ - **Reporter:** found internally during v0.2 development
58
+
59
+ **Description:** The v0.1 combiner hashed the two shared secrets with the recipient public keys as salt, but not the X25519 **ephemeral** public key. Modern hybrid combiners such as X-Wing hash it, because a raw X25519 shared secret alone isn't IND-CCA.
60
+
61
+ **Impact:** The ML-KEM-768 half is IND-CCA on its own, so the combined secret stays secure while ML-KEM holds. The weakness only matters in the scenario hybrids are meant to hedge, where ML-KEM is broken and X25519 is relied on alone.
62
+
63
+ **Fix:** Combiner v2 hashes `ss_mlkem ‖ ss_x25519 ‖ eph_pub ‖ recipient_pub` under a new label (see WIRE_FORMAT.md). It's the default for all new data; the v0.1 combiner is used only to read v0.1 data.
64
+
65
+ **Mitigation for users on older versions:** Re-encrypt long-lived v0.1 data with `seal()`.
66
+
67
+ ### YOXALL-2026-003: Yoxallismus v1 (Hord `YoxallismusCipher`) output cannot be decrypted
68
+
69
+ - **Severity:** High for data written with it (unrecoverable); not a confidentiality leak
70
+ - **Affects:** `YoxallismusCipher` in @weave_protocol/hord (all versions to date)
71
+ - **Fixed in:** not fixable for existing payloads. @weave_protocol/hord 0.1.8 deprecates `YoxallismusCipher` (`unlock()` now throws instead of returning wrong bytes), and @weave_protocol/yoxallismus 0.2.0-beta.0 detects v1 payloads
72
+ - **Reporter:** found internally while building the planned v1 decoder
73
+
74
+ **Description:** `lock()` derives its XOR mask from `HMAC(deadboltKey, seed)`, where `seed = SHA-256(tumblerKey ‖ SHA-256(plaintext))`. The header stores only the first 1-12 seed bytes, and stores them after they've been advanced during encryption. `unlock()` rebuilds the mask from the header bytes instead, so Hord's own `unlock()` never round-trips (we verified this for every configuration tested). No decoder holding the key can recover the remaining seed bytes, which depend on the unknown plaintext, short of brute force.
75
+
76
+ **Impact:** Anything stored only as a v1 payload is lost. Hord's vault does **not** use this cipher internally, so the exposure is limited to callers who used `YoxallismusCipher` directly. v1 was also never an AEAD: it's deterministic, unauthenticated, and built from permutation plus XOR.
77
+
78
+ **Fix:** The planned read-only v1 decoder is impossible. Instead, `inspectV1()` / `readV1()` recognize v1 payloads and raise `V1PayloadUnrecoverableError`, and `weave-yoxall decrypt` explains the situation.
79
+
80
+ **Mitigation:** Stop using `YoxallismusCipher` for anything that must be recovered. Re-encrypt from the original data with `seal()`.
38
81
 
39
82
  ---
40
83
 
package/SKILL.md CHANGED
@@ -42,8 +42,10 @@ Lower-level primitives also exported:
42
42
  ### Critical caveats
43
43
 
44
44
  - **NOT AUDITED.** Do not use for regulated, medical, financial, or legal data.
45
- - Wire format may break between v0.1 and v0.2.
46
- - No post-compromise recovery yet (planned v0.2 via DH double-ratchet).
45
+ - Wire format `yoxall/2` is locked through 1.0 (see `WIRE_FORMAT.md`); use `seal()`/`open()` and `initiateSession()`/`acceptSession()` for new code.
46
+ - Double Ratchet sessions heal after compromise, but only the session start is post-quantum; ongoing ratchet steps are classical X25519.
47
+ - Messages are sender-anonymous: authenticate peers at a higher layer.
48
+ - Yoxallismus v1 (Hord `YoxallismusCipher`) payloads cannot be decrypted (YOXALL-2026-003).
47
49
  - No threshold encryption yet (planned v0.3).
48
50
  - Silence the runtime beta banner with `YOXALL_SILENCE_BETA_WARNING=1`.
49
51
 
package/THREAT_MODEL.md CHANGED
@@ -1,4 +1,4 @@
1
- # Threat Model — @weave_protocol/yoxallismus v0.1.0-beta.0
1
+ # Threat Model — @weave_protocol/yoxallismus v0.2.0-beta.0
2
2
 
3
3
  **Status:** EXPERIMENTAL. NOT AUDITED. Beta software.
4
4
 
@@ -55,32 +55,48 @@ We assume the following adversary capabilities:
55
55
  **Behavior:** A wrong recipient trying to decapsulate produces a *different* shared secret; subsequent AEAD decryption fails with authentication error
56
56
 
57
57
  ### C7. Forward secrecy within a session
58
- **Primitive:** Symmetric ratcheting via HKDF chain advance
59
- **Guarantee:** Compromising the chain key at message N does not reveal messages 1..N-1
60
- **Limitation:** Does NOT provide post-compromise recovery (see § Not defended)
58
+ **Primitive:** Double Ratchet symmetric chains (HMAC-SHA-256); message keys deleted after use
59
+ **Guarantee:** Compromising session state at message N does not reveal earlier messages
61
60
 
62
61
  ### C8. Chosen-ciphertext security (IND-CCA2)
63
62
  **Primitive:** ML-KEM-768 provides IND-CCA2 by construction; X25519 is used with ephemeral keys per encapsulation
64
63
  **Behavior:** An attacker cannot use the recipient as a decryption oracle to extract information about other ciphertexts
65
64
 
65
+ ### C9. Post-compromise security (new in v0.2)
66
+ **Primitive:** Double Ratchet DH ratchet (fresh X25519 keys every round trip)
67
+ **Guarantee:** An attacker who copies a party's full session state can read traffic only until both parties have sent again. After that round trip the session derives keys from DH secrets the attacker never saw. The test suite demonstrates this with a stolen session copy.
68
+ **Limitation:** Healing requires the attacker to be passive during the round trip. An active attacker holding the state can impersonate the party instead.
69
+
70
+ ### C10. Out-of-order and lost messages (new in v0.2)
71
+ **Primitive:** Skipped-message key retention (at most 1000 per chain step, 2000 in total)
72
+ **Guarantee:** Messages can arrive in any order and some can be lost; the session stays in sync. A lost first message doesn't strand the session, because the handshake is repeated until the first reply.
73
+
74
+ ### C11. Robust decryption (new in v0.2)
75
+ **Behavior:** Forged, replayed, or out-of-window ratchet messages throw and leave the session unchanged, because decryption runs on a copy that is committed only after authentication succeeds.
76
+
77
+ ### C12. Single-primitive break of the symmetric cipher (optional, new in v0.2)
78
+ **Primitive:** Cascade mode, with AES-256-GCM inside ChaCha20-Poly1305 under independent HKDF-derived keys
79
+ **Guarantee:** Confidentiality holds if either AES-256 or ChaCha20 holds.
80
+
81
+
66
82
  ---
67
83
 
68
- ## What v0.1 does NOT defend against
84
+ ## What v0.2 does NOT defend against
69
85
 
70
- ### N1. Post-compromise recovery
71
- **Missing:** DH double-ratchet (Signal Protocol style)
72
- **Impact:** If a chain key is compromised at message N, all *future* messages in that session become readable to the attacker until the session is torn down and re-established
73
- **Planned:** v0.2
86
+ ### N1. Post-quantum post-compromise security
87
+ **Missing:** A PQ KEM inside the ratchet (as in Signal's SPQR / triple ratchet)
88
+ **Impact:** The session start is hybrid post-quantum, but ongoing DH ratchet steps are classical X25519. A future quantum attacker who recorded the traffic and later breaks X25519 can follow the ratchet *after* the first DH step. Messages protected only by the initial KEM chain remain PQ-safe.
89
+ **Planned:** after v0.3
74
90
 
75
91
  ### N2. Multi-agent m-of-n threshold decryption
76
92
  **Missing:** Threshold encryption primitive
77
93
  **Impact:** Any single compromised agent that holds a private key can decrypt state that was intended to require multi-party approval
78
94
  **Planned:** v0.3
79
95
 
80
- ### N3. Out-of-order message delivery
81
- **Missing:** Skipped-message key retention
82
- **Impact:** Messages must be decrypted in order. Skipping a message breaks the chain for all subsequent messages
83
- **Planned:** v0.2
96
+ ### N3. Sender authentication
97
+ **Missing:** Identity keys or signatures
98
+ **Impact:** Sealed boxes and ratchet sessions are **sender-anonymous**: the recipient learns that someone who knew its public key sent the message, not who. Authenticate peers at a higher layer (for example Domere handoff tokens).
99
+ **Planned:** v0.3
84
100
 
85
101
  ### N4. Side-channel attacks
86
102
  **Missing:** Constant-time guarantees, memory-cleared secret handling, side-channel resistant primitives
@@ -159,6 +175,7 @@ Documented so we don't pretend we've thought of everything:
159
175
 
160
176
  ## Version history
161
177
 
178
+ - **v0.2.0-beta.0**: Double Ratchet (post-compromise security, out-of-order delivery), hybrid KEM combiner v2, sealed boxes, cascade AEAD, and the locked `yoxall/2` wire format (WIRE_FORMAT.md). Advisories YOXALL-2026-001, -002 and -003 published.
162
179
  - **v0.1.0-beta.0** — Initial public beta. PQ-hybrid KEM, AEAD, symmetric ratcheting. Aggressive experimental labeling. Threat model established.
163
180
 
164
181
  ---
package/WIRE_FORMAT.md ADDED
@@ -0,0 +1,102 @@
1
+ # Wire Format `yoxall/2`: Locked
2
+
3
+ > **Stability promise.** Everything in this document is frozen from `@weave_protocol/yoxallismus@0.2.0-beta.0` through `1.0`. Data written by 0.2 will be readable by every later release up to and including 1.0. Changes in that window may only **add** optional envelope fields (readers ignore unknown fields) or add new envelope types. Anything else ships as `yoxall/3`.
4
+ >
5
+ > The known-answer vectors in [`test/vectors/yoxall-2.json`](test/vectors/yoxall-2.json) are part of this lock: CI fails if any byte of them changes.
6
+
7
+ ## Conventions
8
+
9
+ - Envelopes are JSON objects with `_type` and `_version: "yoxall/2"`.
10
+ - Binary fields are **base64url without padding**.
11
+ - Integers are JSON numbers in `0 … 2³²−1`.
12
+ - `HKDF` = HKDF-SHA-256 (RFC 5869). `HMAC` = HMAC-SHA-256. `‖` = concatenation. `Z32` = 32 zero bytes.
13
+ - Every label below is an ASCII string used verbatim as HKDF `info`.
14
+
15
+ ## Keys (unchanged since v0.1)
16
+
17
+ | Object | Layout |
18
+ |---|---|
19
+ | Hybrid public key | X25519 public (32 B) + ML-KEM-768 public (1184 B) |
20
+ | Hybrid private key | X25519 private (32 B) + ML-KEM-768 private (2400 B) |
21
+ | KEM ciphertext | X25519 ephemeral public (32 B) + ML-KEM-768 ciphertext (1088 B) |
22
+
23
+ Key envelopes `yoxall-pubkey` / `yoxall-keypair` keep their v0.1 shape and are accepted under either version string.
24
+
25
+ ## Hybrid KEM combiner v2
26
+
27
+ ```
28
+ ss = HKDF(ikm = ss_mlkem ‖ ss_x25519 ‖ eph_x25519_pub ‖ recipient_x25519_pub,
29
+ salt = Z32,
30
+ info = "weave-yoxall/2 kem-combine",
31
+ L = 32)
32
+ ```
33
+
34
+ Same shape as X-Wing: hashing the X25519 ephemeral and recipient public keys makes the combined secret IND-CCA even if only the X25519 half is relied on. The v0.1 combiner (`"weave-yoxall v0.1 pq-hybrid-combine"`) is kept **only** for reading v0.1 data (see YOXALL-2026-002).
35
+
36
+ ## Sealed box: `yoxall-sealed`
37
+
38
+ ```
39
+ ss = KEM-v2 encapsulate(recipient)
40
+ key = HKDF(ss, salt = Z32, info = "weave-yoxall/2 seal " ‖ mode, L = 32)
41
+ ```
42
+
43
+ | `mode` | Body |
44
+ |---|---|
45
+ | `aes-256-gcm` | `nonce` = random 12 B; `ct` = AES-256-GCM(key, nonce, pt, aad) ‖ tag (16 B) |
46
+ | `cascade` | see Cascade below; `nonce` = outer ChaCha20 nonce |
47
+
48
+ ```json
49
+ { "_type": "yoxall-sealed", "_version": "yoxall/2", "mode": "aes-256-gcm",
50
+ "x25519eph": "<32 B>", "mlkem": "<1088 B>", "nonce": "<12 B>", "ct": "<…>" }
51
+ ```
52
+
53
+ The AAD is **never** stored in the envelope; the recipient supplies the expected value to `open()`.
54
+
55
+ ## Cascade AEAD
56
+
57
+ ```
58
+ k_aes = HKDF(key, Z32, "weave-yoxall/2 cascade aes-256-gcm", 32)
59
+ k_chacha = HKDF(key, Z32, "weave-yoxall/2 cascade chacha20-poly1305", 32)
60
+ inner = n1 ‖ AES-256-GCM(k_aes, n1, pt, aad) ‖ tag1
61
+ ct = ChaCha20-Poly1305(k_chacha, n2, inner, aad) ‖ tag2
62
+ ```
63
+
64
+ `n1`, `n2` are independent random 12-byte nonces; `n2` is the envelope `nonce`. Overhead is 44 bytes plus the outer nonce.
65
+
66
+ ## Double Ratchet
67
+
68
+ Follows the [Signal Double Ratchet specification](https://signal.org/docs/specifications/doubleratchet/).
69
+
70
+ ```
71
+ session start (rk, ck0) = HKDF(ss_kem_v2, Z32, "weave-yoxall/2 dr-init", 64)
72
+ session AD ad = SHA-256("weave-yoxall/2 dr-ad" ‖ kem_ct.x25519eph ‖ kem_ct.mlkem
73
+ ‖ responder.x25519_pub ‖ responder.mlkem_pub)
74
+ KDF_RK(rk, dh) (rk', ck) = HKDF(ikm = dh, salt = rk, "weave-yoxall/2 dr-rk", 64)
75
+ KDF_CK(ck) ck' = HMAC(ck, 0x02); mk = HMAC(ck, 0x01)
76
+ message key key ‖ nonce = HKDF(mk, Z32, "weave-yoxall/2 dr-msg", 44) (32 B + 12 B)
77
+ header bytes dh (32 B) ‖ pn (uint32 BE) ‖ n (uint32 BE) (40 B)
78
+ ciphertext AES-256-GCM(key, nonce, pt, aad = ad ‖ header ‖ caller_aad) ‖ tag
79
+ ```
80
+
81
+ - The **initiator** sends first with chain `ck0` and a fresh X25519 ratchet key. Its messages carry the KEM ciphertext as `handshake` until the first reply arrives.
82
+ - The **responder** sets `ckr = ck0`, `dhr` = the initiator's header key, generates its ratchet key, and derives its first sending chain with `KDF_RK(rk, DH(own, dhr))`.
83
+ - Skipped message keys are kept (at most 1000 per chain step, 2000 in total).
84
+
85
+ ```json
86
+ { "_type": "yoxall-dr-msg", "_version": "yoxall/2",
87
+ "dh": "<32 B>", "pn": 0, "n": 3,
88
+ "handshake": { "x25519eph": "<32 B>", "mlkem": "<1088 B>" },
89
+ "ct": "<…>" }
90
+ ```
91
+
92
+ ### Session state: `yoxall-dr-session` (secret)
93
+
94
+ Fields: `role` (`initiator` | `responder`), `ad`, `rk`, `dhsPub`, `dhsPriv`, `dhr`, `cks`, `ckr` (32 B or `null`), `ns`, `nr`, `pn`, `skipped` (array of `["<dh b64url>:<n>", "<mk>"]`, oldest first), `pendingHandshake` (KEM ciphertext object or `null`). **Contains secret key material: store it encrypted and never log it.**
95
+
96
+ ## Legacy formats
97
+
98
+ | Format | Status |
99
+ |---|---|
100
+ | `yoxall/0.1.0-beta.0` envelopes (`yoxall-kem-ct`, `yoxall-payload`, `yoxall-encrypted-file`) | **Readable**, through `PQCipher` and `weave-yoxall decrypt`. Written only by the deprecated v0.1 APIs. |
101
+ | v0.1 symmetric ratchet | Deprecated: no interoperable session start (YOXALL-2026-001). |
102
+ | Yoxallismus v1 (`YXLS` header, Hord `YoxallismusCipher`) | **Detected, not decryptable** by any implementation (YOXALL-2026-003). |
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Cascade AEAD: AES-256-GCM inside ChaCha20-Poly1305.
3
+ *
4
+ * Two independent ciphers, two independent keys (derived from one 32-byte
5
+ * key with HKDF under distinct labels), two independent random nonces:
6
+ *
7
+ * inner = AES-256-GCM(k_aes, n1, plaintext, aad) ‖ tag1
8
+ * outer = ChaCha20-Poly1305(k_chacha, n2, n1 ‖ inner, aad) ‖ tag2
9
+ *
10
+ * Confidentiality holds if EITHER cipher holds; forgery requires breaking
11
+ * the outer AEAD and then the inner one. This is a defense-in-depth hedge
12
+ * against a break in one primitive, not a performance feature: it costs
13
+ * two passes and 44 extra bytes.
14
+ *
15
+ * Why not XOR the two keystreams? XOR composition drops both ciphers'
16
+ * authentication and makes key/nonce misuse in either one fatal for the
17
+ * whole construction. Layering keeps every AEAD guarantee of both.
18
+ */
19
+ export interface CascadePayload {
20
+ /** ChaCha20-Poly1305 nonce (outer layer). The AES nonce is inside the ciphertext. */
21
+ nonce: Uint8Array;
22
+ /** n1 ‖ AES-GCM ciphertext ‖ tag1, encrypted by ChaCha20-Poly1305 ‖ tag2 */
23
+ ciphertext: Uint8Array;
24
+ }
25
+ export declare function cascadeEncrypt(key: Uint8Array, plaintext: Uint8Array, aad?: Uint8Array): CascadePayload;
26
+ /** Fixed-nonce variant for known-answer test vectors only. Never reuse nonces in real use. */
27
+ export declare function cascadeEncryptWith(key: Uint8Array, plaintext: Uint8Array, aad: Uint8Array | undefined, n1: Uint8Array, n2: Uint8Array): CascadePayload;
28
+ export declare function cascadeDecrypt(key: Uint8Array, payload: CascadePayload, aad?: Uint8Array): Uint8Array;
29
+ /** Bytes added by cascade mode on top of the plaintext (n1 + 2 tags; outer nonce stored separately). */
30
+ export declare const CASCADE_OVERHEAD: number;
31
+ //# sourceMappingURL=cascade.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cascade.d.ts","sourceRoot":"","sources":["../src/cascade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAUH,MAAM,WAAW,cAAc;IAC7B,qFAAqF;IACrF,KAAK,EAAE,UAAU,CAAC;IAClB,4EAA4E;IAC5E,UAAU,EAAE,UAAU,CAAC;CACxB;AA2BD,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,cAAc,CAEvG;AAED,8FAA8F;AAC9F,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,GAAG,cAAc,CAKtJ;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,UAAU,CAMrG;AAED,wGAAwG;AACxG,eAAO,MAAM,gBAAgB,QAAkB,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Cascade AEAD: AES-256-GCM inside ChaCha20-Poly1305.
3
+ *
4
+ * Two independent ciphers, two independent keys (derived from one 32-byte
5
+ * key with HKDF under distinct labels), two independent random nonces:
6
+ *
7
+ * inner = AES-256-GCM(k_aes, n1, plaintext, aad) ‖ tag1
8
+ * outer = ChaCha20-Poly1305(k_chacha, n2, n1 ‖ inner, aad) ‖ tag2
9
+ *
10
+ * Confidentiality holds if EITHER cipher holds; forgery requires breaking
11
+ * the outer AEAD and then the inner one. This is a defense-in-depth hedge
12
+ * against a break in one primitive, not a performance feature: it costs
13
+ * two passes and 44 extra bytes.
14
+ *
15
+ * Why not XOR the two keystreams? XOR composition drops both ciphers'
16
+ * authentication and makes key/nonce misuse in either one fatal for the
17
+ * whole construction. Layering keeps every AEAD guarantee of both.
18
+ */
19
+ import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
20
+ import { hkdf } from './kdf.js';
21
+ const NONCE = 12;
22
+ const TAG = 16;
23
+ const K_AES = 'weave-yoxall/2 cascade aes-256-gcm';
24
+ const K_CHACHA = 'weave-yoxall/2 cascade chacha20-poly1305';
25
+ function keys(key) {
26
+ if (key.length !== 32)
27
+ throw new Error(`cascade: key must be 32 bytes, got ${key.length}`);
28
+ const salt = new Uint8Array(32);
29
+ return { aes: Buffer.from(hkdf(key, salt, K_AES, 32)), chacha: Buffer.from(hkdf(key, salt, K_CHACHA, 32)) };
30
+ }
31
+ function seal(algo, key, nonce, pt, aad) {
32
+ const c = createCipheriv(algo, key, nonce, { authTagLength: TAG });
33
+ if (aad && aad.length)
34
+ c.setAAD(Buffer.from(aad), { plaintextLength: pt.length });
35
+ return Buffer.concat([c.update(Buffer.from(pt)), c.final(), c.getAuthTag()]);
36
+ }
37
+ function unseal(algo, key, nonce, ct, aad) {
38
+ if (ct.length < TAG)
39
+ throw new Error('cascade: authentication failed');
40
+ const body = Buffer.from(ct.subarray(0, ct.length - TAG));
41
+ const d = createDecipheriv(algo, key, nonce, { authTagLength: TAG });
42
+ if (aad && aad.length)
43
+ d.setAAD(Buffer.from(aad), { plaintextLength: body.length });
44
+ d.setAuthTag(Buffer.from(ct.subarray(ct.length - TAG)));
45
+ try {
46
+ return Buffer.concat([d.update(body), d.final()]);
47
+ }
48
+ catch {
49
+ throw new Error('cascade: authentication failed (tampered, wrong key, or wrong AAD)');
50
+ }
51
+ }
52
+ export function cascadeEncrypt(key, plaintext, aad) {
53
+ return cascadeEncryptWith(key, plaintext, aad, randomBytes(NONCE), randomBytes(NONCE));
54
+ }
55
+ /** Fixed-nonce variant for known-answer test vectors only. Never reuse nonces in real use. */
56
+ export function cascadeEncryptWith(key, plaintext, aad, n1, n2) {
57
+ if (n1.length !== NONCE || n2.length !== NONCE)
58
+ throw new Error(`cascade: nonces must be ${NONCE} bytes`);
59
+ const k = keys(key);
60
+ const inner = Buffer.concat([Buffer.from(n1), seal('aes-256-gcm', k.aes, Buffer.from(n1), plaintext, aad)]);
61
+ return { nonce: new Uint8Array(n2), ciphertext: new Uint8Array(seal('chacha20-poly1305', k.chacha, Buffer.from(n2), inner, aad)) };
62
+ }
63
+ export function cascadeDecrypt(key, payload, aad) {
64
+ if (payload.nonce.length !== NONCE)
65
+ throw new Error(`cascade: nonce must be ${NONCE} bytes`);
66
+ const k = keys(key);
67
+ const inner = unseal('chacha20-poly1305', k.chacha, Buffer.from(payload.nonce), payload.ciphertext, aad);
68
+ if (inner.length < NONCE + TAG)
69
+ throw new Error('cascade: authentication failed');
70
+ return new Uint8Array(unseal('aes-256-gcm', k.aes, inner.subarray(0, NONCE), inner.subarray(NONCE), aad));
71
+ }
72
+ /** Bytes added by cascade mode on top of the plaintext (n1 + 2 tags; outer nonce stored separately). */
73
+ export const CASCADE_OVERHEAD = NONCE + 2 * TAG;
74
+ //# sourceMappingURL=cascade.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cascade.js","sourceRoot":"","sources":["../src/cascade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,MAAM,KAAK,GAAG,EAAE,CAAC;AACjB,MAAM,GAAG,GAAG,EAAE,CAAC;AACf,MAAM,KAAK,GAAG,oCAAoC,CAAC;AACnD,MAAM,QAAQ,GAAG,0CAA0C,CAAC;AAS5D,SAAS,IAAI,CAAC,GAAe;IAC3B,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3F,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAChC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,C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AAmB,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;AACrI,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAe,EAAE,OAAuB,EAAE,GAAgB;IACvF,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,QAAQ,CAAC,CAAC;IAC7F,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACpB,MAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACzG,IAAI,KAAK,CAAC,MAAM,GAAG,KAAK,GAAG,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAClF,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAC5G,CAAC;AAED,wGAAwG;AACxG,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,GAAG,CAAC,GAAG,GAAG,CAAC"}
package/dist/cli.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * weave-yoxall — CLI for @weave_protocol/yoxallismus v0.1.0-beta.0.
3
+ * weave-yoxall — CLI for @weave_protocol/yoxallismus.
4
4
  *
5
5
  * Subcommands:
6
6
  * status Print library status, primitives, known limitations