# DCP Zero-Knowledge Envelope — Open Specification

**Version:** `dcp-zk-v1` (cipher suite `intl-v1`) · **Status:** stable · **Suites:** `intl-v1` (active), `dstu-v1` (planned) · **Updated:** 2026-08

This document fully specifies the DCP zero-knowledge encryption envelope so that
any third party can implement a compatible encryptor/decryptor and independently
verify the published test vectors. Nothing here is secret — the security rests on
the keys, which never leave the client.

All primitives are standard and audited: AES-256-GCM, ChaCha20-Poly1305,
HKDF-SHA256, HMAC-SHA256, Argon2id, ECDH P-256. Reference implementation:
`@humanscode/dcp-zk-sdk` (built on `@noble/ciphers` + `@noble/hashes`).

---

## 1. Overview

Plaintext is encrypted in **9 sequential AEAD layers** with **algorithmic
diversity**: layers alternate AES-256-GCM and ChaCha20-Poly1305, so breaking a
single primitive does not compromise the envelope. Each layer uses an
independent key (HKDF), fresh salt and nonce, and layer-bound AAD. The whole
envelope is then signed with HMAC-SHA256, verified **first** on decrypt
(fail-fast, no oracle).

The **content key** is either:
- derived from a user passphrase via **Argon2id** (self-custody), or
- a random per-item key **wrapped to an ECDH public key** (E2E sharing, envelope
  `dcp-e2e-v1`, see §6).

The server stores only the envelope. It has no passphrase and no private key, so
it cannot decrypt — even under full compromise.

---

## 1a. Cipher suites (crypto-agility)

The set of primitives is named by a **cipher suite** carried in the optional envelope
field `suite`. This makes the format crypto-agile: the same envelope structure can host
different primitive families, selected and versioned explicitly, without breaking stored data.

| Suite | Status | AEAD layers | Hash / MAC | Key wrap | Intended use |
|-------|--------|-------------|-----------|----------|--------------|
| `intl-v1` | active | AES-256-GCM ⇄ ChaCha20-Poly1305 | SHA-256 / HMAC-SHA256 | ECDH P-256 | EU / commercial (ISO 27001, SOC 2) |
| `dcp-cascade-v1` | active | AES-256-GCM · ChaCha20-Poly1305 · AES-256-GCM-SIV · AES-256-OCB3 · AES-256-CCM (9 шарів, каскад) | SHA-256 / HMAC-SHA256 | ECDH P-256 | server-side at-rest — 5 різних AEAD, interlocked-ключі |
| `dstu-v1` | planned | Kalyna (ДСТУ 7624:2014) | Kupyna (ДСТУ 7564:2014) | ДСТУ 4145-2002 | UA state data (КСЗІ) — served by a certified crypto module |

**This specification defines suite `intl-v1`.** The "9 layers" are therefore a
*suite-defined, versioned* construction (algorithmic diversity + independent per-layer
keys), not an arbitrary number.

**Backward compatibility:** the `suite` field is OPTIONAL. An envelope without it MUST be
treated as `suite = "intl-v1"`, so every previously produced envelope stays valid. The
server per-tenant envelope (`dcp-v2`) sets `suite` explicitly; it is covered by the HMAC
like any other field.

`dstu-v1` (Ukrainian national crypto) requires a certified ДСТУ module and is
server-side only — state-data crypto must run in a certified module, not browser JS. Until
that module is wired, requests for `dstu-v1` are refused cleanly (no partial crypto).

---

## 1b. DCP Interlocked Cascade (`dcp-cascade-v1`)

A server-side suite for at-rest data. Nine layers cascade **five genuinely distinct, standard AEADs**
(AES-256-GCM, ChaCha20-Poly1305, AES-256-GCM-SIV, AES-256-OCB3, AES-256-CCM — two cipher families,
four MAC constructions, misuse-resistant variants), each layer encrypting the previous layer's output.
No new or exotic primitives; all are standard and well-analyzed.

**Interlocked key schedule** — the distinctive part. The per-layer key is chained so that each layer's
*algorithm identifier* and salt are folded into every subsequent key:
```
K_0 = tenant master
K_i = HKDF-SHA256(ikm = K_{i-1}, salt = S_i, info = "dcp-cascade|i=" + i + "|alg=" + alg_i)
```
Changing or breaking any layer alters every downstream key. Decryption forward-derives the whole chain
from the stored layer metadata (alg, salt), then peels outermost → innermost. Integrity is a whole-envelope
HMAC-SHA256 plus per-layer AEAD tags with layer-bound AAD (`|layer=i|alg=alg_i`).

**Honest positioning (for audit):** this is a transparent, documented *composition* of standard primitives
— not a new algorithm and not a strength multiplier (one correct AEAD layer is already beyond brute force).
Its value is **algorithmic diversity + defense-in-depth** (no dependence on a single primitive or
implementation) and a distinctive, verifiable construction. Envelope: `version:"dcp-v2"`, `suite:"dcp-cascade-v1"`. **Known-answer tests + open reference:** `test-vectors-cascade.json` (published test key) and a standalone
Python reference/verifier `dcp-cascade-reference.py` let any third party reproduce and check the construction
(`python dcp-cascade-reference.py verify test-vectors-cascade.json`).

---

## 2. Constants

| Name | Value |
|------|-------|
| `ROUNDS` | `9` |
| Layer algorithms | `["AES-256-GCM", "ChaCha20-Poly1305"]`; layer *i* (0-based) uses `LAYER_ALGS[i % 2]` |
| KDF (per layer) | HKDF-SHA256, output 32 bytes |
| Salt (per layer) | 16 random bytes |
| Nonce (per layer) | 12 random bytes |
| MAC | HMAC-SHA256 over canonical envelope |
| Passphrase KDF | Argon2id, output 32 bytes |

---

## 3. Key schedule

Let `M` be the 32-byte content master key.

- **Layer key** for layer index `i` (1-based) with layer salt `S_i`:
  `K_i = HKDF-SHA256(ikm = M, salt = S_i, info = "dcp-zk-layer-" + i, len = 32)`
- **MAC key:** `K_mac = HKDF-SHA256(ikm = M, salt = <none>, info = "dcp-zk-hmac", len = 32)`

`info` strings are ASCII, no null terminator. HKDF `salt = <none>` means the
all-zero salt block per RFC 5869.

---

## 4. Encryption

Input: plaintext bytes `P`, master key `M`, optional AAD object `A` (default `{}`).

1. `aad = canonical(A)` (see §7).
2. `current = P`.
3. For `i = 0 … 8`:
   - `S = random(16)`, `N = random(12)`, `alg = LAYER_ALGS[i % 2]`.
   - `K = HKDF-SHA256(M, S, "dcp-zk-layer-" + (i+1), 32)`.
   - `layer_aad = aad || "|layer=" + (i+1)` (ASCII bytes concatenated).
   - `current = AEAD_Encrypt(alg, K, N, layer_aad, current)` (ciphertext includes the 16-byte tag).
   - Append `{ layer: i+1, alg, salt: b64(S), nonce: b64(N) }` to `layers`.
4. Build the envelope object (§5) without `hmac`.
5. `hmac = HMAC-SHA256(K_mac, canonical(envelope_without_hmac))`; set `envelope.hmac = b64(hmac)`.

---

## 5. Envelope format (`dcp-zk-v1`)

```json
{
  "version": "dcp-zk-v1",
  "alg": "AES-256-GCM+ChaCha20-Poly1305",
  "rounds": 9,
  "kdf": { "algo": "argon2id", "t": 2, "m": 19456, "p": 1, "dkLen": 32, "salt": "<b64>" },
  "ciphertext": "<b64 of final layer output>",
  "layers": [ { "layer": 1, "alg": "AES-256-GCM", "salt": "<b64>", "nonce": "<b64>" }, … 9 ],
  "aad": "<b64 of canonical AAD>",
  "created_at": "<ISO-8601>",
  "hmac": "<b64 HMAC-SHA256>"
}
```

`kdf` is `null` for the raw-master-key path. All binary fields are standard
base64. `layers` MUST have exactly 9 entries in ascending order. An implementation MAY
include an optional `"suite": "intl-v1"` field (see §1a); its absence means `intl-v1`.

---

## 6. Passphrase & E2E key custody

**Passphrase (`kdf` present):**
`M = Argon2id(password, salt = b64d(kdf.salt), t = kdf.t, m = kdf.m, p = kdf.p, dkLen = 32)`.
The salt is public; the password never leaves the client.

**E2E sharing (`dcp-e2e-v1`):** the content key `M` is random per item and wrapped
to a recipient with ephemeral-static **ECDH P-256** → AES-256-GCM:
`wrapped = ephPub(65) || iv(12) || AES-GCM(sharedKey, b64(M))`, base64-encoded.
`sharedKey = ECDH(ephemeralPriv, recipientPub)`. The envelope carries `wrapped`
for the owner; a share additionally stores `wrapped_key` for each recipient. Only
the holder of the matching ECDH private key can unwrap `M`.

---

## 7. Canonicalization

`canonical(x)` is deterministic JSON: object keys sorted lexicographically, no
insignificant whitespace, UTF-8 bytes. Applied to the AAD object and to the
envelope (excluding `hmac`) for the MAC. Encryptor and decryptor MUST agree
byte-for-byte.

---

## 8. Decryption

1. Reject if `version != "dcp-zk-v1"`, `rounds != 9`, or `layers.length != 9`.
2. Recompute `K_mac`; verify `hmac` with constant-time compare. **Abort on mismatch before touching ciphertext.**
3. For `i = 9 … 1`: derive `K_i`, `layer_aad`, and `current = AEAD_Decrypt(alg, K_i, N_i, layer_aad, current)`.
4. Output `current`.

Any failure returns a single uniform error — no padding/tag/version oracle.

---

## 9. Security properties

- **Zero-knowledge:** server holds no key material; envelope reveals only length and metadata.
- **Algorithmic diversity:** a break in AES-GCM *or* ChaCha20-Poly1305 alone leaves 5 (resp. 4) intact layers.
- **Integrity:** HMAC-SHA256 over the whole envelope + per-layer AEAD tags; tamper is detected fail-fast.
- **Nonce safety:** each layer has an independent random key, so 96-bit random nonces carry no reuse risk across messages.
- **KDF hardness:** Argon2id memory-hard derivation resists offline guessing.
- **Crypto-agility:** the primitive set is a named, versioned suite (`suite` field); a
  certified ДСТУ suite (`dstu-v1`) can be added for state data without changing the format.

---

## 10. Test vectors & verification

Public known-answer tests: `test-vectors.json`. For each vector, decrypting
`envelope` with the given secret MUST yield `expected_plaintext`; flipping any
ciphertext byte MUST fail. An in-browser verifier that runs these against the
reference SDK is published at `/solutions/verify/`.

© 2026 DCP Protocol · Humanscode (humanscode.site)
