From eb8ddd63e31950e1a85896da01f2fc46203288de Mon Sep 17 00:00:00 2001 From: Satya Date: Mon, 5 Oct 2026 19:55:26 +0800 Subject: [PATCH 01/14] docs(adr): ADR-0054 encrypted DKG share delivery with HPKE (proposed) Resolves ADR-0053 Q1 with an optional ZeroJ transport: dealers HPKE-encrypt each SHARE (RFC 9180 Base, DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305) to per-attempt recipient keys announced in a transport round 0, and post the envelopes on the DKG board. New-DKG, its transcript and admission are unchanged. The replacement of ideal channels by IND-CCA2 encryption is stated as an explicit assumption with an external-review gate. Design only; seven open questions. Co-Authored-By: Claude Opus 5.5 --- docs/adr/0054-hpke-dkg-share-delivery.md | 462 +++++++++++++++++++++++ 1 file changed, 462 insertions(+) create mode 100644 docs/adr/0054-hpke-dkg-share-delivery.md diff --git a/docs/adr/0054-hpke-dkg-share-delivery.md b/docs/adr/0054-hpke-dkg-share-delivery.md new file mode 100644 index 00000000..52d2cf3a --- /dev/null +++ b/docs/adr/0054-hpke-dkg-share-delivery.md @@ -0,0 +1,462 @@ +# ADR-0054: Encrypted DKG share delivery with HPKE (`dkg-share-delivery-hpke-v1`) + +## Status +Proposed — 2026-10-05. +- Design only. This ADR adds no implementation, test or build file. Accepting it would be design + acceptance only; it would certify no implementation, test or security property. +- It answers ADR-0053's Q1 ("how are the private channels realized?") with an **optional** + ZeroJ-provided transport. Application-provided channels (ADR-0053 D3) stay supported. +- It also bears on ADR-0053's Q7 (late shares under partial synchrony); see D7 and Q6. +- Tracked as #77. Stacked on PR #76, which implements ADR-0052 and ADR-0053. + +This ADR changes no maturity claim. ADR-0039's assurance classes apply: every secret-bearing +host operation here is **compatibility/offline** class. + +## Date +2026-10-05 + +## Revision history +- **r1** (2026-10-05): initial proposal. + +## Risk classification +- **R3:** D1 (the ciphersuite and mode), D2 (the composition that replaces [GJKR07]'s ideal + private channels) and D5 (recipient key lifecycle). These decide whether a share stays secret. +- **R2:** D3 (the envelope and its binding), D4 (key announcement), D6 (failure handling and the + interface to `DkgParticipant`), D7 (relation to ADR-0053's delivery precondition) and D8 + (encodings and canonicality). + +## Context + +[GJKR07] §2.1 assumes that the trustees "are connected by a complete network of private (i.e., +untappable and authenticated) point-to-point channels", in addition to "a dedicated broadcast +channel". ADR-0053 implements New-DKG over Jubjub and leaves both to the application (D3), with Q1 +escalated. PR #76's `DkgParticipant` takes private deliveries through +`receivePrivate(authenticatedSender, message)`, so the transport is pluggable. + +Leaving the private channels to every application has costs: +- Each application must build and review its own confidential, authenticated channel. That is + exactly the kind of security-critical code ZeroJ exists to provide once, reviewed. +- Point-to-point channels such as TLS between trustees need trustees to be online together and + reachable, and leave no evidence of delivery. +- ADR-0053's implementation review found that **timely private delivery is a secrecy + precondition** (spec §5.2, Q7). A `SHARE` that misses its round draws a complaint. The + dealer's answer then publishes the pair, and with the `t` shares the faulty participants hold, + that determines the dealer's polynomial. If that happens for every honest dealer, the joint key + is exposed with no abort. + +Cardano gives a natural alternative. The trustees already need a broadcast board with agreement +and round closure (ADR-0053 D3, D4a), for example transactions. If each dealer **encrypts each +share to its recipient's key and posts the ciphertext on that board**, then: +- delivery is provable: everyone sees whether, and when, an encrypted share was posted; +- trustees need not be online together or reach each other; +- a share is delivered exactly when the board delivers the dealer's post, which the broadcast + model already requires to be timely and agreed. + +The scheme must be a pinned standard used exactly as specified. HPKE (RFC 9180) is the standard +construction for encrypting one message to a public key, and Java 25 provides every building +block (D1). + +The [GJKR07] Appendix, "Committing Encryption on a Broadcast Channel", shows that encrypting +shares on the broadcast channel **does not fix the bias attack on JF-DKG** (Fig. 1). The attack +works because a JF-DKG dealer's contribution is still undecided when complaints are filed. It +does not say that encryption is unsafe for New-DKG. New-DKG's two-phase structure, with Pedersen +commitments fixed before `QUAL` is decided and extraction only afterwards, is what prevents bias, +and this ADR leaves New-DKG unchanged. + +## Threat model and trust assumptions + +This extends ADR-0053's threat model, which still applies in full. + +- **Adversary:** static and rushing, corrupting up to `t < n/2` trustees ([GJKR07] §2.1), as in + ADR-0053. Adaptive corruption stays out of scope (ADR-0053 D8). +- **The board is public and permanent.** Every ciphertext posted on it can be stored forever by + anyone ("harvest now, decrypt later"). +- **Broadcast with agreement and round closure** is still provided by the application + (ADR-0053 D3). Board posts are authenticated under the roster keys (ADR-0053 D4a). +- **Untrusted:** every announced encryption key, every envelope, and the plaintext inside it, + until it passes ADR-0053's `SHARE` checks. +- **Secret:** + - each trustee's HPKE private key `skR` for the attempt; + - every share pair `(s_ij, s'_ij)` before the dealer publishes it in an answer; + - each dealer's encapsulation randomness. +- **HPKE's guarantees and limits (RFC 9180):** + - §9.1 and §9.1.2: Base mode targets message secrecy against chosen-ciphertext attacks. + [CS01] shows that a hybrid scheme of essentially this form is IND-CCA2 secure when its KEM + and AEAD are. The RFC notes that the extra KDF calls in HPKE need their own analysis + ([HPKEAnalysis]). + - §9.1 and §9.7.4: **no forward secrecy with respect to recipient compromise.** "In the Base + and Auth modes, the secrecy properties are only expected to hold if the recipient private + key skR is not compromised at any point in time." + - §9.7.5: with bad encapsulation randomness, Base mode can lose confidentiality completely. + - §9.1.3: the analyses are classical; X25519 is not post-quantum. +- **Consequence of recipient-key compromise.** A leaked `skR_j` exposes every share ever sent to + trustee `j` under that key. Leaked keys of `t + 1` or more trustees expose the joint key, and + with it every ballot ever encrypted to it. D5 limits the window to one attempt. +- **Post-quantum.** A quantum adversary could decrypt the envelopes. It could equally compute + discrete logarithms on Jubjub and decrypt the `elgamal-jubjub-v1` ballots directly, so X25519 + adds no weaker link than the one the election already has. A post-quantum design is out of + scope (see Related findings). + +## Pinned normative references + +- **[RFC9180]** R. Barnes, K. Bhargavan, B. Lipp, C. Wood, *Hybrid Public Key Encryption*, + RFC 9180, February 2022. The text was fetched from rfc-editor.org on 2026-10-05. + - §4.1: DHKEM. + - §5.1.1: `SetupBaseS`/`SetupBaseR`. + - §5.2: encryption and decryption. + - §6.1: single-shot `SealBase`/`OpenBase`. + - §7.1: KEM `0x0020` DHKEM(X25519, HKDF-SHA256). §7.2: KDF `0x0001` HKDF-SHA256. + §7.3: AEAD `0x0003` ChaCha20Poly1305 (and `0x0001` AES-128-GCM, the Q3 alternative). + - §7.1.4: "recipients MUST check whether the Diffie-Hellman shared secret is the all-zero value + and abort if so." + - §8.1: applications that use only the single-shot APIs "should use the Setup info parameter". + - §9.1, §9.1.1, §9.1.2, §9.1.3, §9.2.3 (encapsulation randomness "MUST NOT be reused"), + §9.7.3 (no replay protection), §9.7.4, §9.7.5. + - Appendix A.2: test vectors for DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305. + A.2.1 covers Base mode. +- **[RFC7748]** Langley, Hamburg, Turner, *Elliptic Curves for Security*, RFC 7748, January 2016. + Fetched 2026-10-05. + - §5: X25519 implementations "MUST mask the most significant bit in the final byte" and "MUST + accept non-canonical values and process them as if they had been reduced modulo the field + prime". + - §6.1: the optional all-zero check. +- **[RFC8439]** ChaCha20 and Poly1305 for IETF protocols, §2.8 (AEAD). Fetched 2026-10-05. +- **[RFC5869]** HKDF. Fetched 2026-10-05. +- **[GJKR07]** as pinned by ADR-0053: §2.1 (the channel and adversary model) and the Appendix + ("Committing Encryption on a Broadcast Channel", an attack on JF-DKG's bias). +- **[CS01], [HPKEAnalysis]**: cited through RFC 9180 §9.1.2; not fetched (**unverified** + directly). +- **ZeroJ:** + - ADR-0053 (D3, D4a, D6, D8; Q1, Q7); + - `docs/specs/elgamal-jubjub-threshold-v1.md` (§4 messages, §5 delivery windows, §5.2, §8); + - ADR-0039 (assurance classes). + +## Notation + +- `n`, `t`, trustee identifiers `1 … n`, `session`: as in `elgamal-jubjub-threshold-v1`. +- `SHARE_ij`: the canonical 100-byte `SHARE` message of spec §4 from dealer `i` to recipient `j` + (header and `I2OSP32(s_ij) ‖ I2OSP32(s'_ij)`). +- `(skR_j, pkR_j)`: trustee `j`'s X25519 key pair for one attempt. +- `SealBase`/`OpenBase`: RFC 9180 §6.1. + +## Decision + +### D1 — Ciphersuite and mode (R3) + +ZeroJ uses **HPKE Base mode, single-shot** (RFC 9180 §5.1.1, §6.1) with one fixed ciphersuite: +- KEM `0x0020`, DHKEM(X25519, HKDF-SHA256); +- KDF `0x0001`, HKDF-SHA256; +- AEAD `0x0003`, ChaCha20Poly1305 (lean; Q3). + +No other mode, suite or negotiation is accepted. A fixed suite leaves nothing to downgrade +(RFC 9180 §9.7.2). + +**Base, not Auth.** Sender authentication comes from the board: every post is authenticated under +the dealer's roster key (ADR-0053 D4a). HPKE's Auth mode would add a second sender key, and its +DHKEM variant is subject to key-compromise impersonation (§9.1.1). + +**The implementation is assembled from the RFC on JDK primitives.** Java 25 has no HPKE `Cipher`. +A probe on GraalVM JDK 25.0.2 (2026-10-05) found: +- `KeyAgreement` X25519 from SunEC; +- `javax.crypto.KDF` HKDF-SHA256 from SunJCE; +- `Cipher` ChaCha20-Poly1305 and AES/GCM from SunJCE. + +SunEC refuses small-order inputs with `InvalidKeyException: Point has small order`. That +includes `u = 0`, `u = 1` and their non-canonical forms `p` and `p + 1`, which covers §7.1.4's +all-zero check. The ZeroJ code also checks the shared secret explicitly, so the rule does not +depend on the provider. ZeroJ's main code uses no third-party cryptography library. + +### D2 — Replacing ideal channels by encryption (R3; security argument stated, not proven) + +The [GJKR07] proof assumes ideal private channels. Here, each private channel is replaced by HPKE +encryption of `SHARE_ij` to `pkR_j`, posted on the board. The assumption this rests on is stated +explicitly: + +> **Assumption A1 (to be reviewed externally).** Against a static adversary, New-DKG with ideal +> private channels can be replaced by New-DKG whose private messages are encrypted under an +> IND-CCA2-secure public-key encryption scheme to per-attempt honest recipient keys. Secrecy then +> holds computationally, under the security of that scheme plus [GJKR07]'s discrete-log +> assumption. + +The intuition, which is **not** a proof: +- A simulator for the ideal-channel proof knows every share between an honest and a corrupted + party, and can replace each honest-to-honest ciphertext by an encryption of a fixed dummy + plaintext. +- IND-CCA2 covers the adversary's ability to post envelopes to honest recipients and watch + whether they complain, which amounts to a one-bit decryption oracle (D6). +- Non-committing encryption would be needed only against adaptive corruption, which is out of + scope. + +ZeroJ does not supply a proof of A1. It is an explicit **external-review gate**, and the spec +must state it. + +Robustness and the complaint flow are unchanged. A dealer still answers a complaint by publishing +the pair in the clear ([GJKR07] Fig. 2, Step 1(c)), so no party ever needs to prove what a +ciphertext decrypts to (Q5). + +### D3 — The envelope and its binding (R2) + +Dealer `i` sends `SHARE_ij` by posting an **envelope** on the board in round 1: + +``` +envelope = header ‖ enc (32 bytes) ‖ ct (116 bytes) +header = PROFILE_TAG ‖ session (32 bytes) ‖ u8(sender i) ‖ u8(recipient j) +info = INFO_TAG ‖ session ‖ u8(i) ‖ u8(j) +(enc, ct) = SealBase(pkR_j, info, aad = empty, pt = SHARE_ij) +``` + +The illustration is not normative; the spec (M0) fixes the tags, lengths and order. Its +properties are fixed here: +- **Everything is bound in `info`**, as RFC 9180 §8.1 recommends for single-shot use: the + profile, the session, the sender and the recipient. HPKE also binds `enc` and `pkR_j` through + its key schedule. `aad` is empty. +- **The plaintext is the full canonical `SHARE_ij`**, header included. After decryption, + ADR-0053's existing `SHARE` checks apply unchanged: the session, round, sender, subject and + scalar ranges. +- **Fixed length.** 100-byte plaintext and 116-byte ciphertext, so length reveals nothing + (RFC 9180 §9.7.6). +- **Not a DKG message.** The header starts with a tag that is not a session prefix, so + `DkgMessage.decode` refuses envelopes and `DkgTranscript.deliveredRound` drops them as junk. + The DKG transcript, digest and admission (ADR-0053 D4a) are unchanged. +- **Replay** is refused by the binding: an envelope opens only for its own session, sender and + recipient. RFC 9180 provides no replay protection itself (§9.7.3). Byte-identical repeats count + once. Two different envelopes from one dealer to one recipient deliver two `SHARE`s, which + ADR-0053's conflict rules already handle. + +### D4 — Key announcement (R2) + +Before round 1, a transport round 0 publishes the attempt's encryption keys: +- Each trustee `j` posts `ANNOUNCE_j = header ‖ pkR_j`, authenticated under its roster key, like + every board post. +- Trustee `j`'s key is the **unique** well-formed, authenticated announcement from `j` delivered + in round 0, under the per-window delivery rule of spec §5. +- Two different announcements from `j` are a conflict, and `j` then has **no key**. So does a + trustee that posts no announcement. +- A dealer posts no envelope to a recipient without a key. That recipient complains or stays + silent, and either way only a faulty trustee's own shares can become public. +- Round 1 opens when round 0 closes. The DKG's round numbering and rules (spec §5) are unchanged. + +No proof of possession is required for these keys. Copying another trustee's public key only +makes the copier's own shares unreadable to itself. HPKE binds `pkR` in its key schedule, so the +victim cannot be made to accept the copier's shares as its own. The copier's complaints then +publish only its own shares. Rogue-key attacks matter for key aggregation, which this +construction does not use. + +Alternative (Q2): put the encryption keys in the trusted configuration instead. + +### D5 — Recipient key lifecycle (R3) + +- **Per attempt.** Each trustee generates a fresh X25519 key pair for every `(session, j)`, from + a `SecureRandom`. The API binds a key pair to the session it was generated for, and refuses to + seal or open under another session. +- **Separation.** The encryption key is never the roster authentication key, nor derived from + it. +- **Deletion.** The private key is needed only until round 1 closes and the envelopes are opened. + The API provides a best-effort destroy, after which opening is refused. Java cannot guarantee + erasure of key material, so this is an offline-class property, not a guarantee. +- **Encapsulation randomness** is fresh per envelope from a `SecureRandom` and never reused + (RFC 9180 §9.2.3, §9.7.5). +- **Harvest now, decrypt later.** Per-attempt keys deleted after round 1 bound the exposure to + the DKG window. Long-lived encryption keys would expose every past attempt to one later + compromise. + +### D6 — Failure handling and the `DkgParticipant` interface (R2) + +Every failure to obtain a valid `SHARE_ij` is treated **as absence**, and leads to the same +public consequence as today: a Fig. 2 complaint in round 2. The failures are: +- no envelope; +- a malformed envelope or header; +- a non-canonical or invalid `enc`; +- an all-zero shared secret; +- AEAD failure; +- a plaintext that fails ADR-0053's `SHARE` checks. + +The recipient publishes no other signal, and the library exposes no error detail to other +parties. Locally, the reason may be logged for diagnosis. + +The interface is a thin layer over the existing participant: +- **Open:** the recipient decrypts and calls `DkgParticipant.receivePrivate(i, SHARE_ij)`. +- **Seal:** the dealer takes the `SHARE` messages from `DkgParticipant.start()` and seals each + one into an envelope. + +`DkgParticipant`, `DkgRules`, `DkgTranscript` and `ThresholdKeyContext.admit` are unchanged. + +### D7 — Relation to ADR-0053's delivery precondition (R2; Q6) + +With this transport, a `SHARE` is delivered when the board delivers its envelope in round 1, by +the same mechanism and deadline as the dealer's `COMMITMENTS`. The board assumption of +ADR-0053 D3 (agreement, closure, partial synchrony) already makes that timely for every honest +dealer. An honest recipient that reads the board and holds its key then never complains about an +honest dealer. So the §5.2 precondition, "timely private delivery", **reduces to the broadcast +assumption the protocol already needs**. + +This is an argument, not a theorem, and it is flagged for review. It does not cover an honest +recipient that loses its key during the run, which is a local fault like losing its share. +ADR-0053's Q7 note stays in force for application-provided channels. + +### D8 — Encodings and canonicality (R2; Q4) + +- Announcements and envelopes have exact lengths. +- Every X25519 public value on the board (`pkR_j`, `enc`) must be the **canonical** 32-byte + little-endian encoding: bit 255 clear and `u < 2^255 − 19`. A non-canonical value makes the + announcement or envelope malformed, so the key or share is absent. +- The X25519 function itself stays RFC 7748 conformant. This is a message-format rule, applied + before any X25519 call. It keeps one accepted encoding per message, as AGENTS.md requires. + Because RFC 7748 §5 says implementations "MUST accept non-canonical values", Q4 asks the + maintainer to confirm that a protocol message format may refuse them. + +### D9 — Out of scope + +- Post-quantum or hybrid KEMs. +- Adaptive security and non-committing encryption. +- Publicly verifiable secret sharing, which proves share validity in zero knowledge and would + remove the complaint round. +- HPKE PSK, Auth and AuthPSK modes; the export interface. +- Key storage between attempts. +- Delivery for anything other than DKG `SHARE`s. + +### Alternatives considered + +| Alternative | Why not chosen | +|---|---| +| Application-provided channels only (ADR-0053 status quo) | Kept as an option, but every application must build and review its own. Point-to-point channels give no evidence of delivery, and they leave the §5.2 precondition on the application. | +| TLS or Noise between trustees | Needs simultaneous online presence and reachability. Delivery is not provable on the board, and it is application infrastructure rather than a library primitive. | +| ECIES or ElGamal-based encryption on Jubjub | No standardized ciphersuite exists; ZeroJ would be defining new cryptography. | +| HPKE Auth mode | Redundant with board authentication, and DHKEM Auth is subject to key-compromise impersonation (RFC 9180 §9.1.1). | +| Committing encryption with recipient proofs of decryption | Not needed: Fig. 2's public answers resolve disputes. The [GJKR07] Appendix shows it does not help JF-DKG, and proofs about decryption would be new constructions. | +| PVSS with zero-knowledge share proofs | Would remove complaints and answers, but is a research-level protocol change with new proofs and circuits. Possible future work. | +| Amending `elgamal-jubjub-threshold-v1` to carry envelopes as DKG messages | Changes a format under review in PR #76 and puts transport into the DKG transcript. Kept as Q1's alternative. | + +## Security invariants + +- **I1 (D1, D2, D5) Confidentiality.** `SHARE_ij` is recoverable only with `skR_j` of that + attempt, under HPKE Base IND-CCA2 and Assumption A1. Tested only for functional behaviour + (wrong-key failure); the security claim is an assumption. +- **I2 (D3) Binding.** An envelope opens only under the profile, session, sender `i` and recipient + `j` it was sealed for. Changing any of them, `enc`, `ct` or the recipient key makes it fail. +- **I3 (D3, D6) DKG unchanged.** A decrypted plaintext enters only through + `receivePrivate(i, ·)` and must pass every ADR-0053 `SHARE` check. No transport message is ever + accepted by `DkgMessage.decode`. The transcript digest and admission are identical to an + application-channel run with the same shares. +- **I4 (D6) Uniform failure.** Every envelope failure is equivalent to absence: no exception, + return value or public message distinguishes the failure kinds. +- **I5 (D4) Announcement rule.** A trustee's key is its unique authenticated round-0 + announcement. A conflict or absence gives no key, and dealers send no envelope to it. +- **I6 (D8) Canonical encodings.** Exact lengths, and canonical X25519 values, are enforced + before cryptographic use. All-zero shared secrets are refused independently of the provider. +- **I7 (D5) Key lifecycle.** Keys are fresh per session, refused for any other session, never the + roster key, and destroyable. Opening after destroy is refused. +- **I8 (D5) Randomness.** Encapsulation uses fresh `SecureRandom` output per envelope. Determinism + exists only in a test seam for RFC known-answer tests. +- **I9 (D1) Single suite.** Only `(0x0020, 0x0001, 0x0003)` in Base mode is produced or accepted. +- **I10 (D1) Provider.** Main code uses JDK primitives only, with identical results on the JVM and + in a GraalVM native image. + +## Consequences + +- Applications get confidential share delivery without building channels, and delivery becomes + evidence on the board. +- The DKG gains a transport round 0 and per-attempt key generation; round 1 waits for round 0 to + close. +- Each trustee posts one announcement and `n − 1` envelopes of about 182 bytes plus the profile + tag each (34-byte header, 32-byte `enc`, 116-byte `ct` in D3's illustrative layout; the spec + fixes the length). That is `n(n − 1)` envelopes per attempt, + 4,032 at `n = 64`. Board cost scales quadratically, as the `SHARE` count already does. +- Secrecy now rests computationally on HPKE and Assumption A1, not on ideal channels. +- Recipient key compromise during the window exposes that recipient's shares (no forward secrecy, + RFC 9180 §9.7.4). + +## Compatibility + +- **No change** to `elgamal-jubjub-v1`, `elgamal-jubjub-threshold-v1`, their encodings, + transcripts or admission, under the Q1 lean. Under that lean, PR #76's release gate ("don't + ship the threshold profile until ADR-0054 settles its wire format") can be lifted; Q7 asks the + maintainer to confirm. +- A new profile, `dkg-share-delivery-hpke-v1`, and a new public API in + `org.zeroj.circuit.lib.jubjub`. +- Application-provided channels remain valid. + +## Implementation milestones + +| ID | Scope | Entry gate | Exit criteria | +|---|---|---|---| +| M0 | Normative spec `docs/specs/dkg-share-delivery-hpke-v1.md`: tags, announcement and envelope formats, `info`, the suite, canonicality, absence rules, key lifecycle, Assumption A1, test vectors. An independent Python reference written from the spec and RFC 9180 on pyca `cryptography` primitives (X25519, HKDF, ChaCha20Poly1305) with no Java read; it reproduces RFC 9180 A.2.1 and emits replayable vectors | ADR accepted | Spec reviewed. The reference passes A.2.1 and its own vectors. | +| M1 | Package-private HPKE (Base, single-shot, the D1 suite) on JDK primitives, with a deterministic-ephemeral test seam | M0 | Every RFC 9180 A.2.1 Base encryption matches. Differential against BouncyCastle 1.83's HPKE on random inputs. Negatives: small-order and all-zero inputs, non-canonical `enc`, tampered `enc`/`ct`, wrong `info`/key. A GraalVM native-image probe produces identical results (I10). | +| M2 | Delivery layer: key generation per session, round-0 announcement, seal/open, wiring to `DkgParticipant` | M1, and ADR-0053 M2 (merged with PR #76) | ADR-0053's honest and adversarial DKG suites rerun with encrypted delivery and identical transcripts (I3). Negatives for I2, I4–I7: wrong session, sender or recipient; cross-attempt replay; conflicting or missing announcements; copied keys; opening after destroy. The §5.2 late-share scenario does not arise under board closure (D7). The Python reference replays. | +| M3 | Docs: support matrix and guide; ADR-0053 Q1/Q7 notes pointing here | M2 | Docs reviewed. | + +## Verification and test-vector strategy + +- **Published vectors:** RFC 9180 Appendix A.2.1 (Base mode), all encryptions. +- **Independent implementations:** + - BouncyCastle 1.83's `org.bouncycastle.crypto.hpke.HPKE`, already a test dependency; + - a Python reference from the RFC text on pyca `cryptography` 46, which has X25519, HKDF and + ChaCha20Poly1305 but no HPKE, so it is written independently. Its reproduction of A.2.1 is + checked before Java exists. +- **Adversarial and negative cases:** every invariant's failure mode, run through the real + `DkgParticipant` state machine. +- **Expected values never come from the code under test.** + +## Production / audit gates + +- External review of Assumption A1 and D7, together with ADR-0053's DKG review. +- External review of key storage, deletion and `SecureRandom` use on the deployment platform. +- Native-image verification on each released platform. +- Not production-ready until those gates pass; experimental, like ADR-0053. + +## Risks + +- **The composition argument is wrong or incomplete.** Mitigation: it is stated as an + assumption, with an external-review gate. +- **Recipient key compromise** while a key exists exposes that trustee's shares. Mitigation: + per-attempt keys and deletion (D5). +- **Assembly errors in HPKE.** Mitigation: RFC known-answer tests, a BouncyCastle differential + and an independent Python reference. +- **Provider differences** between the JVM and native image. Mitigation: I10, tested in M1. +- **Metadata:** the board reveals who sent envelopes to whom and when (RFC 9180 §9.9). This + matches the public DKG structure and reveals no share. + +## Open questions (points needing a maintainer decision) + +1. **Q1 (D3, Compatibility): layering.** + - Options: + - (a) a separate transport profile; envelopes and announcements are board posts outside the + DKG transcript, and `elgamal-jubjub-threshold-v1` is unchanged; + - (b) amend the threshold profile with envelope and announcement message kinds in its + transcript. + - Lean: (a). The DKG stays untouched and #76's release gate can lift. Admission does not need + envelopes, because outputs do not depend on them. +2. **Q2 (D4): where encryption keys come from.** + - Options: + - (a) per-attempt keys announced in a round 0 under the roster keys; + - (b) keys in the trusted configuration, such as an election manifest. + - Lean: (a). Fresh keys per attempt bound harvest-now-decrypt-later exposure. (b) saves a + round, but tends toward long-lived keys. +3. **Q3 (D1): the AEAD.** + - Options: (a) ChaCha20Poly1305 (`0x0003`); (b) AES-128-GCM (`0x0001`). + - Lean: (a). Its software implementation uses no table-based S-box, so it does not depend on + AES hardware support for timing behaviour. Both have RFC 9180 test vectors (A.2 and A.1). + This is not a constant-time claim. +4. **Q4 (D8): canonical X25519 encodings versus RFC 7748 §5.** + - Options: + - (a) refuse non-canonical values at the message layer, before X25519; + - (b) accept them, as the X25519 function must, and canonicalize. + - Lean: (a). The RFC's MUST governs the X25519 function, and ZeroJ's message formats require + one accepted encoding. Escalated because it narrows inputs that RFC 7748 says + implementations accept. +5. **Q5 (D2): complaint evidence.** + - Options: + - (a) keep [GJKR07] Fig. 2's public answers only; + - (b) add recipient proofs of what an envelope decrypts to. + - Lean: (a). It is sufficient for disputes, and (b) would be new cryptography. +6. **Q6 (D7): ADR-0053's Q7.** Should ADR-0053 record Q7 as resolved, for deployments using this + transport, once ADR-0054 is accepted? Lean: yes, as a note in ADR-0053, keeping the + precondition for application-provided channels. +7. **Q7 (Compatibility): PR #76's release gate.** If Q1's lean is adopted, lift it. Lean: yes. + +## Related findings (out of scope) + +- A post-quantum or hybrid KEM (outside RFC 9180's registry) would matter only alongside a + post-quantum replacement for Jubjub ElGamal itself. +- PVSS-style DKGs with zero-knowledge share proofs could remove complaint rounds. That would be a + separate ADR. From 9a2f7abfbd46bcb2b72ba41c135c6ce35a754434 Mon Sep 17 00:00:00 2001 From: Satya Date: Mon, 5 Oct 2026 20:41:05 +0800 Subject: [PATCH 02/14] =?UTF-8?q?docs(adr):=20ADR-0054=20r2=20=E2=80=94=20?= =?UTF-8?q?address=20review=20round=201=20(F1=E2=80=93F2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit F1: new D6a processing barrier (final window retrieved and fully processed before sealing or closing round 1), D7 rewritten as the delivery contract P1-P3, new D7a (a dealer's COMMITMENTS only after its envelopes are final, or atomically) and transport abort T1 (own announcement missing); I11-I13; timing tests; Q6 rescoped; new Q8. F2: exposure accounting replaces the 't + 1 leaked keys' claim: leaked recipient keys vs full trustee state vs public disclosures, per-dealer evaluation-index counting with no self-envelope; I14; exposure vectors. Also: explicit 32-byte-to-key decoding in D8/M1 (review note). Co-Authored-By: Claude Opus 5.5 --- docs/adr/0054-hpke-dkg-share-delivery.md | 221 +++++++++++++++++++---- 1 file changed, 187 insertions(+), 34 deletions(-) diff --git a/docs/adr/0054-hpke-dkg-share-delivery.md b/docs/adr/0054-hpke-dkg-share-delivery.md index 52d2cf3a..9b7a10f3 100644 --- a/docs/adr/0054-hpke-dkg-share-delivery.md +++ b/docs/adr/0054-hpke-dkg-share-delivery.md @@ -16,14 +16,27 @@ host operation here is **compatibility/offline** class. 2026-10-05 ## Revision history -- **r1** (2026-10-05): initial proposal. +- **r1** (`eb8ddd6`, 2026-10-05): initial proposal. +- **r2** (2026-10-05; responds to the review of `eb8ddd6`): + - F1 → new D6a (a processing barrier: a window is final, retrieved and fully processed before + a participant seals or closes round 1); D7 rewritten as an explicit contract P1–P3; new D7a + (a dealer's `COMMITMENTS` only after its envelopes are final, or atomically); new transport + abort T1 in D4 (own announcement missing); a timing bullet in the threat model; new I11–I13; + M0/M2 tests for late-processed envelopes, delayed announcements and envelopes excluded by the + cutoff; Q6 rescoped; new Q8. + - F2 → the threat model's key-compromise bullet is replaced by exposure accounting that + separates leaked recipient keys, full trustee state and public disclosures, with per-dealer + evaluation-index counting (no dealer sends itself an envelope). New I14; M0/M2 exposure tests; + D5 and Risks updated. + - Review note on key import → D8 and M1: the 32-byte-to-key adapter decodes explicitly and does + not rely on provider masking. ## Risk classification - **R3:** D1 (the ciphersuite and mode), D2 (the composition that replaces [GJKR07]'s ideal private channels) and D5 (recipient key lifecycle). These decide whether a share stays secret. -- **R2:** D3 (the envelope and its binding), D4 (key announcement), D6 (failure handling and the - interface to `DkgParticipant`), D7 (relation to ADR-0053's delivery precondition) and D8 - (encodings and canonicality). +- **R2:** D3 (the envelope and its binding), D4 (key announcement and abort T1), D6 (failure + handling and the interface to `DkgParticipant`), D6a (the processing barrier), D7 and D7a + (the delivery contract and the dealer's posting order) and D8 (encodings and canonicality). ## Context @@ -49,8 +62,9 @@ and round closure (ADR-0053 D3, D4a), for example transactions. If each dealer * share to its recipient's key and posts the ciphertext on that board**, then: - delivery is provable: everyone sees whether, and when, an encrypted share was posted; - trustees need not be online together or reach each other; -- a share is delivered exactly when the board delivers the dealer's post, which the broadcast - model already requires to be timely and agreed. +- the board decides which shares were delivered. With a processing barrier, a commitments-last + posting order and an abort for a missing own announcement (D6a, D7, D7a, D4), secrecy no longer + depends on private-delivery timing. The scheme must be a pinned standard used exactly as specified. HPKE (RFC 9180) is the standard construction for encrypting one message to a public key, and Java 25 provides every building @@ -89,9 +103,44 @@ This extends ADR-0053's threat model, which still applies in full. key skR is not compromised at any point in time." - §9.7.5: with bad encapsulation randomness, Base mode can lose confidentiality completely. - §9.1.3: the analyses are classical; X25519 is not post-quantum. -- **Consequence of recipient-key compromise.** A leaked `skR_j` exposes every share ever sent to - trustee `j` under that key. Leaked keys of `t + 1` or more trustees expose the joint key, and - with it every ballot ever encrypted to it. D5 limits the window to one attempt. +- **Timing and processing (r2, F1).** Secrecy also needs bounded publication, finality, + retrieval and local processing of the round-0 and round-1 board posts before each participant + advances: the contract P1–P3 of D7, with the barrier of D6a. Closure evidence (ADR-0053 D4a) + proves which posts a window contains. It does not prove that a participant processed them before + it closed its round. +- **Exposure accounting (r2, F2).** Three kinds of compromise must be kept apart: + - **(a) a leaked HPKE private key `skR_j`.** It reveals what was sent to `j` in envelopes: the + pairs `(s_ij, s'_ij)` for dealers `i ≠ j`. A dealer keeps its own evaluation `f_j(j)` and + never sends itself an envelope (threshold spec §3; `DkgParticipant.start()`), so `skR_j` + alone does not reveal `j`'s final share `x_j`; + - **(b) a trustee's complete state:** its polynomials, received shares and `x_j`. That is a + corruption, counted in `t`; + - **(c) public disclosures:** complaint answers (round 3), and the pairs published to + reconstruct marked dealers (rounds 5–6). + + **Counting rule.** Dealer `i`'s contribution `z_i` is exposed when the distinct evaluation + indices known for `f_i` reach `t + 1`. The known indices are: + - the leaked recipient keys other than `i`; + - the corrupted trustees; + - the public answers for `i`; + - all of them, if `i` itself is corrupted. + + The joint key `x = Σ z_i` is exposed when every `z_i`, `i ∈ QUAL`, is exposed. For example + (`n = 3`, `t = 1`, no corruption), leaking `skR_1` and `skR_2` exposes `z_3` but not `z_1` or + `z_2`, since only `f_1(2)` and `f_2(1)` are in envelopes. + + An enumeration over `(n, t) ∈ {(3, 1), (5, 2), (7, 3)}` (2026-10-05) gives, **in this counting + model** (not a security proof): + - **Recipient keys alone:** `t + 1` leaked keys never expose `x`, because each leaked trustee's + own dealing has only `t` known points. `t + 2` always do. + - **With the static adversary's `t` corrupted trustees:** one leaked honest key does not expose + `x`; two always do. + - **Public answers add points and lower these numbers:** `t` corrupted trustees, one leaked key + and one answer against that trustee's dealing exposed `x` at `n = 5`, `t = 2`. + + This is **not** a stronger guarantee. Deployments must assume that a few leaked recipient keys, + together with corruptions and disclosures, can expose the key and every ballot encrypted to it. + D5 limits the window to one attempt. - **Post-quantum.** A quantum adversary could decrypt the envelopes. It could equally compute discrete logarithms on Jubjub and decrypt the `elgamal-jubjub-v1` ballots directly, so X25519 adds no weaker link than the one the election already has. A post-quantum design is out of @@ -232,9 +281,19 @@ Before round 1, a transport round 0 publishes the attempt's encryption keys: in round 0, under the per-window delivery rule of spec §5. - Two different announcements from `j` are a conflict, and `j` then has **no key**. So does a trustee that posts no announcement. -- A dealer posts no envelope to a recipient without a key. That recipient complains or stays - silent, and either way only a faulty trustee's own shares can become public. -- Round 1 opens when round 0 closes. The DKG's round numbering and rules (spec §5) are unchanged. +- A dealer posts no envelope to a recipient without a key. +- **Transport abort T1 (r2).** A trustee whose own announcement is absent from the final round-0 + set, or conflicts there, aborts the attempt before round 1. It stays silent: it neither deals + nor complains. + + Without T1, an honest trustee whose announcement missed the cutoff would complain against + every dealer. The answers would then publish its shares, which is the §5.2 exposure in another + form. T1 mirrors A9, under which a participant's own broadcasts are delivered to itself. + + A recipient without a key that does complain is therefore faulty. The answers give it only the + shares a corrupted trustee holds in [GJKR07]'s model anyway. +- Round 1's window opens on schedule after round 0's. A dealer seals only after processing the + final round-0 set (D6a). The DKG's round numbering and rules (spec §5) are unchanged. No proof of possession is required for these keys. Copying another trustee's public key only makes the copier's own shares unreadable to itself. HPKE binds `pkR` in its key schedule, so the @@ -258,7 +317,8 @@ Alternative (Q2): put the encryption keys in the trusted configuration instead. (RFC 9180 §9.2.3, §9.7.5). - **Harvest now, decrypt later.** Per-attempt keys deleted after round 1 bound the exposure to the DKG window. Long-lived encryption keys would expose every past attempt to one later - compromise. + compromise. How many leaked keys suffice depends on corruptions and disclosures; the threat + model's exposure accounting gives the count. ### D6 — Failure handling and the `DkgParticipant` interface (R2) @@ -281,18 +341,71 @@ The interface is a thin layer over the existing participant: `DkgParticipant`, `DkgRules`, `DkgTranscript` and `ThresholdKeyContext.admit` are unchanged. -### D7 — Relation to ADR-0053's delivery precondition (R2; Q6) - -With this transport, a `SHARE` is delivered when the board delivers its envelope in round 1, by -the same mechanism and deadline as the dealer's `COMMITMENTS`. The board assumption of -ADR-0053 D3 (agreement, closure, partial synchrony) already makes that timely for every honest -dealer. An honest recipient that reads the board and holds its key then never complains about an -honest dealer. So the §5.2 precondition, "timely private delivery", **reduces to the broadcast -assumption the protocol already needs**. +### D6a — Processing barrier (R2; r2, responds to F1) + +A participant advances past round 0 or round 1 only when all three hold: +1. **The window is final.** Its cutoff has passed, and the set of posts up to the cutoff is final + and complete, on the same closure evidence admission uses (ADR-0053 D4a). +2. **Every post is retrieved.** It has every post in that window. +3. **Every post is processed.** + - Round 0: the announcements are applied to the key directory (D4, including T1). + - Round 1: every envelope is opened and validated, and each accepted plaintext is submitted + through `receivePrivate` (D6). + +Only then does it seal its envelopes (after round 0) or call `DkgParticipant.closeRound()` (for +round 1). + +- **The cutoff decides delivery, not processing time.** Slow processing delays the participant, + a liveness cost. It never turns a delivered share into an absent one. +- **Never close round 1 on a timer while envelopes in the final window are unprocessed.** That is + the failure the review demonstrated with the unchanged state machine (`n = 3`, `t = 1`). + Envelopes `1→2` and `2→1` were processed after round 1 closed. That drew two complaints and two + public answers, and corrupted participant 3 recovered `x` from its own shares plus the answers. +- **The API enforces the order.** The delivery layer takes a final window's posts and returns + only after every accepted plaintext has been submitted. It offers no close after partial + processing. + +### D7 — Relation to ADR-0053's delivery precondition (R2; Q6; rewritten in r2 for F1) + +With this transport, a `SHARE` is delivered when the final round-1 set contains its envelope and +the recipient has processed it. The §5.2 argument needs an explicit **delivery contract**: +- **(P1) Bounded publication.** An honest trustee's round-0 announcement and round-1 posts are + included on the board before their window's cutoff. This is [GJKR07] §2.1's "received by their + recipients within some specified time bound", applied to board inclusion. Its budget must + include processing the previous window, sealing and posting. +- **(P2) Agreement and finality.** Every honest participant obtains the same final set of posts + for each window (ADR-0053 D3, D4a). +- **(P3) The processing barrier** of D6a. + +Under P1–P3, an honest recipient holds its key, so T1 never fires for it. It receives every honest +dealer's envelope in the final round-1 set, and processes it before closing round 1. So it never +complains about an honest dealer, and no honest dealer's answer publishes a share. The §5.2 +precondition then **reduces to P1–P3**. + +Closure evidence alone is not enough. It proves what a window contains (part of P2). It proves +neither that honest posts made the cutoff (P1) nor that they were processed in time (P3). + +#### D7a — A dealer's `COMMITMENTS` only after its envelopes (R2; r2; Q8) + +An honest dealer posts its round-1 `COMMITMENTS` **only after all its envelopes are final on the +board within the round-1 window**. Posting them all atomically in one post, for example one +transaction, satisfies the same rule. Recipients need no new check: this constrains honest +dealers only. A dealer whose `COMMITMENTS` arrives without a recipient's envelope is faulty, and +the recipient's complaint makes it publish a point on its own polynomial. + +With T1 and D7a, **secrecy no longer depends on P1**: +- An honest dealer whose envelopes miss the cutoff never posts `COMMITMENTS`. R1 disqualifies it, + and it is never asked to answer. +- An honest trustee whose announcement misses round 0 aborts (T1) and never complains. + +P1 then matters only for liveness, through ADR-0053's A1 bound on `|QUAL|`. Without D7a, an +envelope that misses the cutoff while its `COMMITMENTS` makes it reproduces the §5.2 exposure for +that dealer. Hence Q8. This is an argument, not a theorem, and it is flagged for review. It does not cover an honest recipient that loses its key during the run, which is a local fault like losing its share. -ADR-0053's Q7 note stays in force for application-provided channels. +ADR-0053's Q7 note stays in force for application-provided channels, and for deployments that do +not meet P2, P3, T1 and D7a. ### D8 — Encodings and canonicality (R2; Q4) @@ -304,6 +417,11 @@ ADR-0053's Q7 note stays in force for application-provided channels. before any X25519 call. It keeps one accepted encoding per message, as AGENTS.md requires. Because RFC 7748 §5 says implementations "MUST accept non-canonical values", Q4 asks the maintainer to confirm that a protocol message format may refuse them. +- **Explicit decoding (r2, from the review).** The adapter from 32 bytes to a provider key + implements RFC 7748 §5's decoding itself: little-endian, then the Q4 policy (refuse, under the + lean) for bit 255 and for `u ≥ 2^255 − 19`. It does not rely on a provider API to decide. The + review observed that SunEC's encoded-key import masks bit 255, while building an + `XECPublicKeySpec` from the unmasked integer did not give the same result. ### D9 — Out of scope @@ -349,8 +467,20 @@ ADR-0053's Q7 note stays in force for application-provided channels. - **I8 (D5) Randomness.** Encapsulation uses fresh `SecureRandom` output per envelope. Determinism exists only in a test seam for RFC known-answer tests. - **I9 (D1) Single suite.** Only `(0x0020, 0x0001, 0x0003)` in Base mode is produced or accepted. -- **I10 (D1) Provider.** Main code uses JDK primitives only, with identical results on the JVM and - in a GraalVM native image. +- **I10 (D1, D8) Provider.** Main code uses JDK primitives only, with identical results on the JVM + and in a GraalVM native image. The byte-to-key adapter decodes explicitly (D8). +- **I11 (D6a) Processing barrier.** A participant seals only after the final round-0 window is + processed, and closes round 1 only after every envelope in the final round-1 window is processed + and submitted. An envelope inside the cutoff but opened late draws no complaint. +- **I12 (D4) Abort T1.** A trustee whose own announcement is absent or conflicting in the final + round-0 set aborts before round 1 and never deals or complains. +- **I13 (D7a) Commitments last.** An honest dealer's `COMMITMENTS` is released for posting only + after all its envelopes are final in the round-1 window, or together with them atomically. + Envelopes excluded by the cutoff therefore leave the dealer disqualified, with no answer + published. +- **I14 (threat model, F2) No self-envelope.** A dealer never seals an envelope to itself, so a + leaked recipient key reveals only the pairs `(s_ij, s'_ij)`, `i ≠ j`. Exposure follows the + counting rule of the threat model. ## Consequences @@ -362,7 +492,10 @@ ADR-0053's Q7 note stays in force for application-provided channels. tag each (34-byte header, 32-byte `enc`, 116-byte `ct` in D3's illustrative layout; the spec fixes the length). That is `n(n − 1)` envelopes per attempt, 4,032 at `n = 64`. Board cost scales quadratically, as the `SHARE` count already does. -- Secrecy now rests computationally on HPKE and Assumption A1, not on ideal channels. +- Round 1 includes one finality wait: envelopes first, then `COMMITMENTS` (D7a), unless both are + posted atomically. +- Secrecy now rests computationally on HPKE and Assumption A1, not on ideal channels, and + operationally on the contract of D7. - Recipient key compromise during the window exposes that recipient's shares (no forward secrecy, RFC 9180 §9.7.4). @@ -380,9 +513,9 @@ ADR-0053's Q7 note stays in force for application-provided channels. | ID | Scope | Entry gate | Exit criteria | |---|---|---|---| -| M0 | Normative spec `docs/specs/dkg-share-delivery-hpke-v1.md`: tags, announcement and envelope formats, `info`, the suite, canonicality, absence rules, key lifecycle, Assumption A1, test vectors. An independent Python reference written from the spec and RFC 9180 on pyca `cryptography` primitives (X25519, HKDF, ChaCha20Poly1305) with no Java read; it reproduces RFC 9180 A.2.1 and emits replayable vectors | ADR accepted | Spec reviewed. The reference passes A.2.1 and its own vectors. | -| M1 | Package-private HPKE (Base, single-shot, the D1 suite) on JDK primitives, with a deterministic-ephemeral test seam | M0 | Every RFC 9180 A.2.1 Base encryption matches. Differential against BouncyCastle 1.83's HPKE on random inputs. Negatives: small-order and all-zero inputs, non-canonical `enc`, tampered `enc`/`ct`, wrong `info`/key. A GraalVM native-image probe produces identical results (I10). | -| M2 | Delivery layer: key generation per session, round-0 announcement, seal/open, wiring to `DkgParticipant` | M1, and ADR-0053 M2 (merged with PR #76) | ADR-0053's honest and adversarial DKG suites rerun with encrypted delivery and identical transcripts (I3). Negatives for I2, I4–I7: wrong session, sender or recipient; cross-attempt replay; conflicting or missing announcements; copied keys; opening after destroy. The §5.2 late-share scenario does not arise under board closure (D7). The Python reference replays. | +| M0 | Normative spec `docs/specs/dkg-share-delivery-hpke-v1.md`: tags, announcement and envelope formats, `info`, the suite, canonicality and explicit decoding, absence rules, abort T1, the processing barrier, the delivery contract P1–P3 and the posting order of D7a, key lifecycle, exposure accounting, Assumption A1, test vectors. An independent Python reference written from the spec and RFC 9180 on pyca `cryptography` primitives (X25519, HKDF, ChaCha20Poly1305) with no Java read. It reproduces RFC 9180 A.2.1, models the barrier and the exposure counting rule, and emits replayable vectors | ADR accepted | Spec reviewed. The reference passes A.2.1 and its own vectors. | +| M1 | Package-private HPKE (Base, single-shot, the D1 suite) on JDK primitives, with a deterministic-ephemeral test seam and the explicit byte-to-key adapter (D8) | M0 | Every RFC 9180 A.2.1 Base encryption matches. Differential against BouncyCastle 1.83's HPKE on random inputs. Negatives: small-order and all-zero inputs; non-canonical `enc`, both bit 255 set and `u ≥ p`; tampered `enc`/`ct`; wrong `info`/key. A GraalVM native-image probe produces identical results (I10). | +| M2 | Delivery layer: key generation per session, round-0 announcement and T1, the processing barrier, seal/open with the D7a posting order, wiring to `DkgParticipant` | M1, and ADR-0053 M2 (merged with PR #76) | ADR-0053's honest and adversarial DKG suites rerun with encrypted delivery and identical transcripts (I3). Negatives for I2, I4–I7: wrong session, sender or recipient; cross-attempt replay; conflicting or missing announcements; copied keys; opening after destroy. **Timing (I11–I13):** envelopes posted before the cutoff but opened later draw no complaint; delayed announcements are processed before sealing; an own announcement missing triggers T1 with no complaint; envelopes excluded by the cutoff leave the dealer's `COMMITMENTS` unposted and the dealer disqualified, with no answer. The review's late-processing scenario (`n = 3`, `t = 1`) is reproduced as a negative control without the barrier and refused with it. **Exposure (I14):** no envelope is addressed to its sender; leaked-key exposure matches the counting rule. The Python reference replays. | | M3 | Docs: support matrix and guide; ADR-0053 Q1/Q7 notes pointing here | M2 | Docs reviewed. | ## Verification and test-vector strategy @@ -395,11 +528,17 @@ ADR-0053's Q7 note stays in force for application-provided channels. checked before Java exists. - **Adversarial and negative cases:** every invariant's failure mode, run through the real `DkgParticipant` state machine. +- **Timing harness:** a board model with window cutoffs, finality and delayed processing. It + drives the barrier (I11), T1 (I12) and the posting order (I13). It includes the review's + late-processing counterexample as a negative control. +- **Exposure accounting:** vectors that leak chosen recipient keys, with and without corruptions + and public answers. Reconstruction must succeed exactly when the counting rule says it does. - **Expected values never come from the code under test.** ## Production / audit gates -- External review of Assumption A1 and D7, together with ADR-0053's DKG review. +- External review of Assumption A1, D7 and D7a (the contract P1–P3, T1 and the posting order), + together with ADR-0053's DKG review. - External review of key storage, deletion and `SecureRandom` use on the deployment platform. - Native-image verification on each released platform. - Not production-ready until those gates pass; experimental, like ADR-0053. @@ -408,8 +547,13 @@ ADR-0053's Q7 note stays in force for application-provided channels. - **The composition argument is wrong or incomplete.** Mitigation: it is stated as an assumption, with an external-review gate. -- **Recipient key compromise** while a key exists exposes that trustee's shares. Mitigation: - per-attempt keys and deletion (D5). +- **Recipient key compromise** while a key exists exposes that trustee's received shares; with + corruptions and public answers, a few leaked keys can expose the joint key (threat model). + Mitigation: per-attempt keys and deletion (D5). +- **An application closes rounds on a timer**, before processing finishes. Mitigation: the API's + order (D6a), documentation, and the negative control in M2. +- **Board finality is slow** relative to the window, so honest dealers miss the cutoff under D7a. + This costs liveness (A1 aborts), not secrecy. Mitigation: size the windows for finality. - **Assembly errors in HPKE.** Mitigation: RFC known-answer tests, a BouncyCastle differential and an independent Python reference. - **Provider differences** between the JVM and native image. Mitigation: I10, tested in M1. @@ -449,10 +593,19 @@ ADR-0053's Q7 note stays in force for application-provided channels. - (a) keep [GJKR07] Fig. 2's public answers only; - (b) add recipient proofs of what an envelope decrypts to. - Lean: (a). It is sufficient for disputes, and (b) would be new cryptography. -6. **Q6 (D7): ADR-0053's Q7.** Should ADR-0053 record Q7 as resolved, for deployments using this - transport, once ADR-0054 is accepted? Lean: yes, as a note in ADR-0053, keeping the - precondition for application-provided channels. +6. **Q6 (D7): ADR-0053's Q7.** Should ADR-0053 record Q7 as resolved once ADR-0054 is accepted? + Lean: yes, but **only for deployments that use this transport and meet P2, P3, T1 and D7a**. + ADR-0053 keeps the precondition, and the documented limitation, for application-provided + channels and for deployments without that contract. 7. **Q7 (Compatibility): PR #76's release gate.** If Q1's lean is adopted, lift it. Lean: yes. +8. **Q8 (D7a): must a dealer's `COMMITMENTS` follow its final envelopes?** + - Options: + - (a) a MUST of the profile, either commitments after the envelopes are final, or one atomic + post; + - (b) optional, with the §5.2 exposure documented for dealers whose envelopes miss the + cutoff. + - Lean: (a). It removes secrecy's dependence on publication timing, at the cost of one + finality wait in round 1. Recipients need no new check. ## Related findings (out of scope) From cc637626f24e48bb93d0098bc0d5b5d244df8009 Mon Sep 17 00:00:00 2001 From: Satya Date: Mon, 5 Oct 2026 20:48:40 +0800 Subject: [PATCH 03/14] =?UTF-8?q?docs(adr):=20ADR-0054=20r3=20=E2=80=94=20?= =?UTF-8?q?address=20review=20round=202=20(F3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit F3: scope the disclosure guarantee. Corrupted trustees may still complain and dealers answer before their own-qualification check, so the guarantee is that every answer by an honest qualified dealer is at a corrupted index (new I15), not that no answer is published. D7, D7a and I13 corrected; a dealer without COMMITMENTS is excluded from QUAL and draws no honest complaint. M2 and the timing harness gain both adversarial-complaint traces. Fig. 2 unchanged. Co-Authored-By: Claude Opus 5.5 --- docs/adr/0054-hpke-dkg-share-delivery.md | 57 +++++++++++++++++++----- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/docs/adr/0054-hpke-dkg-share-delivery.md b/docs/adr/0054-hpke-dkg-share-delivery.md index 9b7a10f3..f18350d5 100644 --- a/docs/adr/0054-hpke-dkg-share-delivery.md +++ b/docs/adr/0054-hpke-dkg-share-delivery.md @@ -17,7 +17,7 @@ host operation here is **compatibility/offline** class. ## Revision history - **r1** (`eb8ddd6`, 2026-10-05): initial proposal. -- **r2** (2026-10-05; responds to the review of `eb8ddd6`): +- **r2** (`9a2f7ab`, 2026-10-05; responds to the review of `eb8ddd6`): - F1 → new D6a (a processing barrier: a window is final, retrieved and fully processed before a participant seals or closes round 1); D7 rewritten as an explicit contract P1–P3; new D7a (a dealer's `COMMITMENTS` only after its envelopes are final, or atomically); new transport @@ -30,6 +30,13 @@ host operation here is **compatibility/offline** class. D5 and Risks updated. - Review note on key import → D8 and M1: the 32-byte-to-key adapter decodes explicitly and does not rely on provider masking. +- **r3** (2026-10-05; responds to the review of `9a2f7ab`): F3 → the disclosure guarantee is + scoped. D7 now says what answers can still reveal: corrupted trustees may complain, and dealers + answer before their own-qualification check, at corrupted indices only. D7a and I13 no longer + claim "no answer"; a dealer without `COMMITMENTS` is excluded from `QUAL` and draws no honest + complaint. New I15 (answer scope). M2 and the timing harness include both adversarial-complaint + traces. The threat model's public-answer example is scoped to honest indices. No change to + Fig. 2's rules. ## Risk classification - **R3:** D1 (the ciphersuite and mode), D2 (the composition that replaces [GJKR07]'s ideal @@ -136,7 +143,9 @@ This extends ADR-0053's threat model, which still applies in full. - **With the static adversary's `t` corrupted trustees:** one leaked honest key does not expose `x`; two always do. - **Public answers add points and lower these numbers:** `t` corrupted trustees, one leaked key - and one answer against that trustee's dealing exposed `x` at `n = 5`, `t = 2`. + and one answer at an honest index against that trustee's dealing exposed `x` at `n = 5`, + `t = 2`. Under the delivery contract, an honest qualified dealer never answers at an honest + index (D7, I15). This is **not** a stronger guarantee. Deployments must assume that a few leaked recipient keys, together with corruptions and disclosures, can expose the key and every ballot encrypted to it. @@ -378,9 +387,24 @@ the recipient has processed it. The §5.2 argument needs an explicit **delivery - **(P3) The processing barrier** of D6a. Under P1–P3, an honest recipient holds its key, so T1 never fires for it. It receives every honest -dealer's envelope in the final round-1 set, and processes it before closing round 1. So it never -complains about an honest dealer, and no honest dealer's answer publishes a share. The §5.2 -precondition then **reduces to P1–P3**. +dealer's envelope in the final round-1 set, and processes it before closing round 1. It never +complains about a dealer whose `COMMITMENTS` is absent: `closeDeal` skips such a dealer, which +R1 disqualifies regardless. So an honest active recipient never makes a false absence complaint +about an honest qualified dealer. + +**What answers can still reveal (r3, F3).** Fig. 2 is unchanged, so corrupted trustees may still +complain about any dealer. A dealer answers every delivered complaint in round 3 (`closeComplaints`) +before it checks its own qualification (`closeAnswers`). Such an answer publishes the pair at the +**complainer's** index. That is a corrupted index, already inside the corruption budget of the +threat model's counting rule, so it adds no new evaluation index. + +The guarantee is therefore scoped: +- for every honest dealer in `QUAL`, every answer it publishes is addressed to a corrupted + complainer (I15); +- so the known indices of its polynomial stay within the corrupted set. + +It is **not** that honest dealers publish no answers. The §5.2 precondition, in this scoped form, +then **reduces to P1–P3**. Closure evidence alone is not enough. It proves what a window contains (part of P2). It proves neither that honest posts made the cutoff (P1) nor that they were processed in time (P3). @@ -395,7 +419,10 @@ the recipient's complaint makes it publish a point on its own polynomial. With T1 and D7a, **secrecy no longer depends on P1**: - An honest dealer whose envelopes miss the cutoff never posts `COMMITMENTS`. R1 disqualifies it, - and it is never asked to answer. + so its contribution is not part of the joint key. Honest participants do not complain about it, + because `closeDeal` skips a dealer without `COMMITMENTS`. Corrupted trustees still may: under the + unchanged Fig. 2 rule it answers them in round 3, and only then aborts with A2 (`closeAnswers`). + Those answers concern a polynomial excluded from `QUAL`, at corrupted indices. - An honest trustee whose announcement misses round 0 aborts (T1) and never complains. P1 then matters only for liveness, through ADR-0053's A1 bound on `|QUAL|`. Without D7a, an @@ -476,11 +503,16 @@ not meet P2, P3, T1 and D7a. round-0 set aborts before round 1 and never deals or complains. - **I13 (D7a) Commitments last.** An honest dealer's `COMMITMENTS` is released for posting only after all its envelopes are final in the round-1 window, or together with them atomically. - Envelopes excluded by the cutoff therefore leave the dealer disqualified, with no answer - published. + Envelopes excluded by the cutoff therefore leave the dealer disqualified, with its contribution + outside the joint key and no complaint from any honest participant. It may still answer + complaints from corrupted trustees before its A2 abort (r3, F3). - **I14 (threat model, F2) No self-envelope.** A dealer never seals an envelope to itself, so a leaked recipient key reveals only the pairs `(s_ij, s'_ij)`, `i ≠ j`. Exposure follows the counting rule of the threat model. +- **I15 (D7; r3, F3) Answer scope.** Under P1–P3, T1 and D7a, every answer that an honest dealer + in `QUAL` publishes is addressed to a corrupted complainer. Answers therefore add no evaluation + index beyond the corruption budget. Honest active recipients make no false absence complaint + about an honest qualified dealer. Fig. 2's complaint and answer rules are unchanged. ## Consequences @@ -515,7 +547,7 @@ not meet P2, P3, T1 and D7a. |---|---|---|---| | M0 | Normative spec `docs/specs/dkg-share-delivery-hpke-v1.md`: tags, announcement and envelope formats, `info`, the suite, canonicality and explicit decoding, absence rules, abort T1, the processing barrier, the delivery contract P1–P3 and the posting order of D7a, key lifecycle, exposure accounting, Assumption A1, test vectors. An independent Python reference written from the spec and RFC 9180 on pyca `cryptography` primitives (X25519, HKDF, ChaCha20Poly1305) with no Java read. It reproduces RFC 9180 A.2.1, models the barrier and the exposure counting rule, and emits replayable vectors | ADR accepted | Spec reviewed. The reference passes A.2.1 and its own vectors. | | M1 | Package-private HPKE (Base, single-shot, the D1 suite) on JDK primitives, with a deterministic-ephemeral test seam and the explicit byte-to-key adapter (D8) | M0 | Every RFC 9180 A.2.1 Base encryption matches. Differential against BouncyCastle 1.83's HPKE on random inputs. Negatives: small-order and all-zero inputs; non-canonical `enc`, both bit 255 set and `u ≥ p`; tampered `enc`/`ct`; wrong `info`/key. A GraalVM native-image probe produces identical results (I10). | -| M2 | Delivery layer: key generation per session, round-0 announcement and T1, the processing barrier, seal/open with the D7a posting order, wiring to `DkgParticipant` | M1, and ADR-0053 M2 (merged with PR #76) | ADR-0053's honest and adversarial DKG suites rerun with encrypted delivery and identical transcripts (I3). Negatives for I2, I4–I7: wrong session, sender or recipient; cross-attempt replay; conflicting or missing announcements; copied keys; opening after destroy. **Timing (I11–I13):** envelopes posted before the cutoff but opened later draw no complaint; delayed announcements are processed before sealing; an own announcement missing triggers T1 with no complaint; envelopes excluded by the cutoff leave the dealer's `COMMITMENTS` unposted and the dealer disqualified, with no answer. The review's late-processing scenario (`n = 3`, `t = 1`) is reproduced as a negative control without the barrier and refused with it. **Exposure (I14):** no envelope is addressed to its sender; leaked-key exposure matches the counting rule. The Python reference replays. | +| M2 | Delivery layer: key generation per session, round-0 announcement and T1, the processing barrier, seal/open with the D7a posting order, wiring to `DkgParticipant` | M1, and ADR-0053 M2 (merged with PR #76) | ADR-0053's honest and adversarial DKG suites rerun with encrypted delivery and identical transcripts (I3). Negatives for I2, I4–I7: wrong session, sender or recipient; cross-attempt replay; conflicting or missing announcements; copied keys; opening after destroy. **Timing (I11–I13):** envelopes posted before the cutoff but opened later draw no complaint; delayed announcements are processed before sealing; an own announcement missing triggers T1 with no complaint; envelopes excluded by the cutoff leave the dealer's `COMMITMENTS` unposted and the dealer disqualified, with no complaint from any honest participant. The review's late-processing scenario (`n = 3`, `t = 1`) is reproduced as a negative control without the barrier and refused with it. **Adversarial complaints (I15):** (i) with timely delivery, a corrupted trustee's complaint against an honest dealer draws one answer at the corrupted index, `QUAL` is unchanged, and the exposure count is unchanged; (ii) under D7a, a corrupted trustee's complaint against an honest dealer whose `COMMITMENTS` was withheld draws an answer at the corrupted index, after which the dealer aborts with A2 and is excluded from `QUAL`. **Exposure (I14):** no envelope is addressed to its sender; leaked-key exposure matches the counting rule. The Python reference replays. | | M3 | Docs: support matrix and guide; ADR-0053 Q1/Q7 notes pointing here | M2 | Docs reviewed. | ## Verification and test-vector strategy @@ -529,8 +561,11 @@ not meet P2, P3, T1 and D7a. - **Adversarial and negative cases:** every invariant's failure mode, run through the real `DkgParticipant` state machine. - **Timing harness:** a board model with window cutoffs, finality and delayed processing. It - drives the barrier (I11), T1 (I12) and the posting order (I13). It includes the review's - late-processing counterexample as a negative control. + drives the barrier (I11), T1 (I12), the posting order (I13) and the answer scope (I15). It + includes: + - the review's late-processing counterexample, as a negative control; + - both adversarial-complaint traces of review round 2. Every answer by an honest qualified + dealer must be at a corrupted index. - **Exposure accounting:** vectors that leak chosen recipient keys, with and without corruptions and public answers. Reconstruction must succeed exactly when the counting rule says it does. - **Expected values never come from the code under test.** From afe4d8dbad8f1b936a1fb5121afaaa91244d80a0 Mon Sep 17 00:00:00 2001 From: Satya Date: Fri, 9 Oct 2026 11:38:05 +0800 Subject: [PATCH 04/14] =?UTF-8?q?docs(adr):=20ADR-0054=20status=20Accepted?= =?UTF-8?q?=20(design);=20Q1=E2=80=93Q8=20leans=20adopted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Approved at r3 (cc63762). The maintainer adopted every recorded lean on 2026-10-09. No design text changes; adds the implementation-status table. Co-Authored-By: Claude Opus 5.5 --- docs/adr/0054-hpke-dkg-share-delivery.md | 33 +++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/docs/adr/0054-hpke-dkg-share-delivery.md b/docs/adr/0054-hpke-dkg-share-delivery.md index f18350d5..8ef13800 100644 --- a/docs/adr/0054-hpke-dkg-share-delivery.md +++ b/docs/adr/0054-hpke-dkg-share-delivery.md @@ -1,19 +1,24 @@ # ADR-0054: Encrypted DKG share delivery with HPKE (`dkg-share-delivery-hpke-v1`) ## Status -Proposed — 2026-10-05. -- Design only. This ADR adds no implementation, test or build file. Accepting it would be design - acceptance only; it would certify no implementation, test or security property. +Accepted (design) — 2026-10-09. +- The reviewer approved r3 at `cc63762` with no outstanding findings, and the maintainer + accepted the design. +- Acceptance is design acceptance only. It certifies no implementation, test or security + property. +- Q1–Q8 were decided by the maintainer on 2026-10-09: each recorded lean is adopted (see "Open + questions"). - It answers ADR-0053's Q1 ("how are the private channels realized?") with an **optional** ZeroJ-provided transport. Application-provided channels (ADR-0053 D3) stay supported. -- It also bears on ADR-0053's Q7 (late shares under partial synchrony); see D7 and Q6. -- Tracked as #77. Stacked on PR #76, which implements ADR-0052 and ADR-0053. +- It bears on ADR-0053's Q7 (late shares under partial synchrony); see D7 and Q6. +- Tracked as #77. Implementation of M0–M3 is in progress on PR #80, one reviewed step at a time. + The "Implementation status" section at the end tracks it. This ADR changes no maturity claim. ADR-0039's assurance classes apply: every secret-bearing host operation here is **compatibility/offline** class. ## Date -2026-10-05 +2026-10-05 (proposed); 2026-10-09 (accepted) ## Revision history - **r1** (`eb8ddd6`, 2026-10-05): initial proposal. @@ -37,6 +42,10 @@ host operation here is **compatibility/offline** class. complaint. New I15 (answer scope). M2 and the timing harness include both adversarial-complaint traces. The threat model's public-answer example is scoped to honest indices. No change to Fig. 2's rules. +- **Accepted** (2026-10-09): approved at r3 (`cc63762`); status flipped without changing the + design text. +- **Decisions recorded** (2026-10-09): the maintainer adopted the leans of Q1–Q8. No design text + changes. ## Risk classification - **R3:** D1 (the ciphersuite and mode), D2 (the composition that replaces [GJKR07]'s ideal @@ -597,6 +606,9 @@ not meet P2, P3, T1 and D7a. ## Open questions (points needing a maintainer decision) +**Decided 2026-10-09 (maintainer): the lean of every question below is adopted.** The +questions stay as written for the record. + 1. **Q1 (D3, Compatibility): layering.** - Options: - (a) a separate transport profile; envelopes and announcements are board posts outside the @@ -648,3 +660,12 @@ not meet P2, P3, T1 and D7a. post-quantum replacement for Jubjub ElGamal itself. - PVSS-style DKGs with zero-knowledge share proofs could remove complaint rounds. That would be a separate ADR. + +## Implementation status + +| Milestone | State | Notes | +|---|---|---| +| M0 | Not started | | +| M1 | Not started | | +| M2 | Not started | | +| M3 | Not started | | From 5f1c25b122822c78f07fcde39bf2c840691fba69 Mon Sep 17 00:00:00 2001 From: Satya Date: Fri, 9 Oct 2026 12:35:52 +0800 Subject: [PATCH 05/14] =?UTF-8?q?feat(dkg):=20ADR-0054=20M0=20=E2=80=94=20?= =?UTF-8?q?normative=20dkg-share-delivery-hpke-v1=20spec,=20independent=20?= =?UTF-8?q?reference=20and=20standard=20vectors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Normative spec: one HPKE suite (RFC 9180 Base, single-shot; DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305), canonical X25519 encodings and small-order probe, round-0 announcements and directory with abort T1, envelope format with all binding in info, failure as absence, processing barrier, commitments-after-envelopes order, key lifecycle, exposure counting rule, Assumption A1, and pinned test vectors. Independent Python reference written from the spec and RFC 9180 (no Java read): 294 checks, 110 replayable vectors. Vendored standard vectors pinned by commit and SHA-256: RFC 9180 A.2.1 (CFRG test-vectors.json) and Wycheproof X25519, ChaCha20-Poly1305 and HKDF-SHA256. Co-Authored-By: Claude Opus 5.5 --- docs/specs/dkg-share-delivery-hpke-v1.md | 387 ++ .../dkg-share-delivery-reference/README.md | 542 ++ .../dkg_share_delivery_hpke_v1_reference.py | 2068 ++++++ .../reference-output.txt | 2374 +++++++ .../test/resources/standard-vectors/README.md | 23 + ...e-x25519-sha256-chacha20poly1305-base.json | 1583 +++++ .../wycheproof-chacha20_poly1305_test.json | 4721 +++++++++++++ .../wycheproof-hkdf_sha256_test.json | 1220 ++++ .../wycheproof-x25519_test.json | 6056 +++++++++++++++++ 9 files changed, 18974 insertions(+) create mode 100644 docs/specs/dkg-share-delivery-hpke-v1.md create mode 100644 zeroj-circuit-lib/src/test/resources/dkg-share-delivery-reference/README.md create mode 100644 zeroj-circuit-lib/src/test/resources/dkg-share-delivery-reference/dkg_share_delivery_hpke_v1_reference.py create mode 100644 zeroj-circuit-lib/src/test/resources/dkg-share-delivery-reference/reference-output.txt create mode 100644 zeroj-circuit-lib/src/test/resources/standard-vectors/README.md create mode 100644 zeroj-circuit-lib/src/test/resources/standard-vectors/hpke-x25519-sha256-chacha20poly1305-base.json create mode 100644 zeroj-circuit-lib/src/test/resources/standard-vectors/wycheproof-chacha20_poly1305_test.json create mode 100644 zeroj-circuit-lib/src/test/resources/standard-vectors/wycheproof-hkdf_sha256_test.json create mode 100644 zeroj-circuit-lib/src/test/resources/standard-vectors/wycheproof-x25519_test.json diff --git a/docs/specs/dkg-share-delivery-hpke-v1.md b/docs/specs/dkg-share-delivery-hpke-v1.md new file mode 100644 index 00000000..a3b82d99 --- /dev/null +++ b/docs/specs/dkg-share-delivery-hpke-v1.md @@ -0,0 +1,387 @@ +# ZeroJ DKG Share Delivery with HPKE v1 — Normative Specification + +**Profile identifier:** `dkg-share-delivery-hpke-v1` +**Status:** Normative. Required by ADR-0054 (milestone M0). +**Date:** 2026-10-09 + +This document pins every value, message, rule and encoding that a second implementation needs to +deliver the private `SHARE` messages of [`elgamal-jubjub-threshold-v1`](elgamal-jubjub-threshold-v1.md) +over the same public board as the rest of the key generation. Each `SHARE` is encrypted with +HPKE [RFC 9180] to a per-attempt recipient key announced in a transport round 0 (ADR-0054 D1–D8). +Anything not written here is not part of the profile. Any change needs a new identifier (`-v2`). + +This is a **transport profile**. It changes nothing in `elgamal-jubjub-threshold-v1`: not its +messages, rules, transcript, digest, admission or outputs (ADR-0054 Q1). A run that uses this +transport produces exactly the transcript a run with ideal private channels would produce, given +the same shares. + +Conventions: +- `u8` is one unsigned byte. `‖` is concatenation. +- `I2OSP(x, k)` writes `x` as `k` big-endian bytes, as in RFC 9180 §3. +- `p = 2^255 − 19`. X25519 values are 32-byte strings, little-endian, as in [RFC 7748] §5. +- `session`, `n`, `t`, the identifiers `1 … n`, the roster keys `key_j`, `SHARE`, + `COMMITMENTS` and the rounds are those of `elgamal-jubjub-threshold-v1` (§1–§5). +- `ASCII(s)` is the byte string of the ASCII characters of `s`, without a terminator. + +--- + +## 1. Suite and mode + +| Item | Value | Reference | +|---|---|---| +| Mode | `mode_base = 0x00`, single-shot | RFC 9180 §5.1.1, §6.1 | +| KEM | `0x0020` DHKEM(X25519, HKDF-SHA256): `Nsecret = 32`, `Nenc = 32`, `Npk = 32`, `Nsk = 32` | §4.1, §7.1 | +| KDF | `0x0001` HKDF-SHA256: `Nh = 32` | §7.2, [RFC 5869] | +| AEAD | `0x0003` ChaCha20Poly1305: `Nk = 32`, `Nn = 12`, `Nt = 16` | §7.3, [RFC 8439] §2.8 | + +This one suite and this one mode are the only ones produced or accepted. There is no +negotiation. `SealBase` and `OpenBase` are RFC 9180 §6.1 exactly, with the key schedule of §5.1, +`psk = ""` and `psk_id = ""`. A single-shot context uses sequence number 0 only. The export +interface (§5.3) is not used. + +**Validation (RFC 9180 §7.1.4).** Every Diffie–Hellman output is checked. If `DH(sk, pk)` is the +all-zero string, the operation fails. This is required of both the sender (`Encap`) and the +recipient (`Decap`), whatever the underlying X25519 implementation does. + +--- + +## 2. X25519 encodings + +### 2.1 Canonical public values + +A 32-byte string `b` is a **canonical X25519 public value** if: +1. bit 255 of `b` (the most significant bit of `b[31]`) is 0; and +2. the little-endian integer `u` that `b` encodes satisfies `u < p`. + +Every X25519 public value carried in a message of this profile, the announced key `pkR` (§3) and +the encapsulation `enc` (§4), must be canonical. A non-canonical value makes its message +**malformed**. This is checked on the bytes before any X25519 computation (ADR-0054 D8, Q4). + +The X25519 function itself is unchanged. [RFC 7748] §5 requires implementations of the function +to "accept non-canonical values". This profile only refuses such values earlier, at the message +format, so that each message has one accepted encoding. + +### 2.2 Small-order announced keys + +An announced key `pkR` must also have **non-zero DH output** with a fixed probe scalar: + +``` +PROBE = 0x09 ‖ 0^31 (a 32-byte X25519 private scalar, clamped as in RFC 7748 §5) +X25519(PROBE, pkR) ≠ 0^32 +``` + +Clamping makes every X25519 scalar `k` a multiple of 8, with `k = 8k'` and +`2^251 ≤ k' < 2^252`. So `k'` is never a multiple of either large prime factor: +- the curve's subgroup order `q = 2^252 + 27742317777372353535851937790883648493`; +- the twist's `q' = 2^253 − 55484635554744707071703875581767296995`. + +Hence `X25519(k, u) = 0^32` exactly when the point with u-coordinate `u` has order dividing 8 +(curve, cofactor 8) or 4 (twist, cofactor 4), whatever the scalar. That is, `u` is of small +order. One fixed scalar decides it for all. A small-order key would make every dealer's `Encap` fail (§1). Refusing it in the +announcement gives every participant the same directory (§3.2). + +### 2.3 Private keys + +A recipient private key `skR` is 32 bytes from a cryptographically secure generator: RFC 9180 +§4's `GenerateKeyPair`, which for X25519 is 32 random bytes used as the scalar. It is clamped by +X25519 itself. `DeriveKeyPair` (§7.1.3) is used only to reproduce the RFC's test vectors. +`pkR = X25519(skR, 9)`, which is `SerializePublicKey`. The same applies to the ephemeral key `skE`: fresh for every envelope, and +never reused (RFC 9180 §9.2.3). + +--- + +## 3. Round 0 — key announcements + +### 3.1 Message + +Before round 1 of the key generation, each participant `j` posts one announcement for the +attempt: + +``` +ANNOUNCE_j = TAG_A ‖ session (32) ‖ u8(j) ‖ pkR_j (32) +TAG_A = ASCII("zeroj.dkg-share-delivery-hpke.v1.announce") (41 bytes) +``` + +Its length is exactly 106 bytes. `pkR_j` is a fresh key for this session (§7). + +An announcement is **well-formed** for a configuration only if all of the following hold: +- its length is exactly 106 bytes and it starts with `TAG_A`; +- `session` equals the configuration's session; +- `1 ≤ j ≤ n`; +- `pkR_j` is canonical (§2.1) and passes the small-order probe (§2.2). + +It is **delivered** only if it is also authenticated as sent by participant `j` under `key_j`, +by the application's authenticator (`elgamal-jubjub-threshold-v1` §8), and it is in the final +round-0 window (§5). + +### 3.2 The key directory + +For each `j`, consider the delivered announcements from `j`. Byte-identical copies count once. +- Exactly one distinct announcement: `j`'s key is its `pkR_j`. +- None, or two or more distinct ones (a **conflict**): `j` has **no key**. + +The directory is a deterministic function of the final round-0 window, so every honest +participant computes the same one. + +### 3.3 Abort T1 — own key missing + +A participant `j` whose directory gives **no key for `j` itself**, or a key other than its own +(the public key of the private key `j` holds), aborts the attempt before round 1 (ADR-0054 D4). It does not deal, complain, +answer, confirm or post anything further for the attempt. +- This covers an announcement that is missing, malformed, unauthenticated or in conflict. +- A different key can be there only if someone authenticated as `j` posted it. That cannot + happen to an honest participant. + +T1 ensures that an honest participant never complains about missing shares because its own key +went missing. Such complaints would make every dealer publish that participant's shares. + +--- + +## 4. Round 1 — envelopes + +### 4.1 Sealing + +For each recipient `j ≠ i` that has a key in the directory, dealer `i` seals its `SHARE_ij`, the +canonical 100-byte `SHARE` message of `elgamal-jubjub-threshold-v1` §4 (header included): + +``` +info = TAG_I ‖ session (32) ‖ u8(i) ‖ u8(j) +TAG_I = ASCII("zeroj.dkg-share-delivery-hpke.v1.info") (37 bytes) +(enc, ct) = SealBase(pkR_j, info, aad = "", pt = SHARE_ij) (RFC 9180 §6.1) +ENVELOPE_ij = TAG_E ‖ session (32) ‖ u8(i) ‖ u8(j) ‖ enc (32) ‖ ct (116) +TAG_E = ASCII("zeroj.dkg-share-delivery-hpke.v1.envelope") (41 bytes) +``` + +- `ENVELOPE_ij` is exactly 223 bytes, and `ct` is exactly `100 + 16 = 116` bytes. +- `info` is 71 bytes. All binding is in `info`, as RFC 9180 §8.1 recommends for single-shot + use, and `aad` is the empty string. +- A dealer seals **no envelope to itself**: it keeps `(s_ii, s'_ii)`. +- It seals none to a recipient without a key. + +None of the three tags is a prefix of any other, or of any `elgamal-jubjub-threshold-v1` +message. Those all begin with a 32-byte session, which a fixed ASCII tag matches only with +negligible probability, so the threshold profile's decoding refuses every message of this +profile. + +### 4.2 Opening + +Recipient `j` processes every envelope in the final round-1 window (§5) whose header names `j` +as recipient. An envelope is **accepted** only if every step succeeds: +1. its length is exactly 223 bytes and it starts with `TAG_E`; +2. `session` equals the configuration's session, `1 ≤ i ≤ n`, the header recipient is `j`, and + `i ≠ j`; +3. it is authenticated as sent by participant `i` under `key_i`; +4. `enc` is canonical (§2.1); +5. `pt = OpenBase(enc, skR_j, info_ij, aad = "", ct)` succeeds, including the all-zero DH check + (§1) and AEAD verification; +6. `pt` is a well-formed `SHARE` of this session, with sender `i` and subject `j` + (`elgamal-jubjub-threshold-v1` §4). The recipient then submits it as a private delivery from + `i`. + +Byte-identical envelopes count once. Envelopes are de-duplicated only **after** authentication +(step 3), so an unauthenticated copy can never shadow the genuine post. +- Two accepted envelopes from `i` to `j` whose plaintexts are byte-identical deliver one `SHARE`. +- Two whose plaintexts differ deliver two different `SHARE`s, which the threshold profile treats + as a conflict (§5, R2: a complaint). + +**Failure is absence.** If any step fails, that envelope delivers nothing. The participant +publishes nothing about the failure and no other message. The only public consequence of a +missing or invalid share is the threshold profile's usual round-2 `COMPLAINT` (ADR-0054 D6, I4). + +--- + +## 5. Windows, the processing barrier and posting order + +A **window** is the board's set of posts for one round of this profile or of the threshold +profile, delivered under the per-window rule of `elgamal-jubjub-threshold-v1` §5. That set +contains the posts made while the round was open, before its cutoff, and final. An early or late +post belongs to no window. + +With this profile, **round 0 precedes round 1**: +- Round 1's window opens when round 0's window closes. This refines the threshold profile's + "for round 1, once the session started". +- A threshold-profile message posted during round 0 is early and belongs to no window. +- Rounds 2–7 are unchanged. + +**Atomic posting** (§5.2) is a property of the board: all of a set of posts are included in one +window, or none are. For example, they share one ledger transaction. This profile defines no +wire format for it. Each contained message is authenticated and processed exactly as if posted +alone. + +### 5.1 Processing barrier (ADR-0054 D6a) + +A participant advances only after the window is final, retrieved and fully processed: +- **After round 0:** it builds the directory (§3.2), applies T1 (§3.3) and only then seals + (§4.1). +- **After round 1:** it delivers its round-1 broadcasts to the threshold participant, opens and + processes **every** envelope addressed to it (§4.2), and only then closes round 1 of the + threshold profile. + +A participant must never close round 1 while an envelope in the final window is unprocessed. The +window's cutoff decides what was delivered; how long processing takes does not. + +### 5.2 Posting order (ADR-0054 D7a) + +Dealer `i` posts its round-1 `COMMITMENTS` **only after all its envelopes are final on the board +within the round-1 window**. Alternatively, it posts the envelopes and `COMMITMENTS` atomically, +in one post that the board includes entirely or not at all. + +If its envelopes cannot be made final before the cutoff, the dealer posts no `COMMITMENTS`. R1 +then disqualifies it, and it is never asked to answer an honest complaint. Recipients perform no +check of this rule. + +### 5.3 Delivery contract (ADR-0054 D7) + +The secrecy argument of ADR-0054 assumes: +- **(P1) bounded publication:** an honest participant's posts are included before their window's + cutoff; +- **(P2) agreement and finality:** every honest participant obtains the same final window; +- **(P3) the barrier of §5.1.** + +With T1 (§3.3) and the posting order (§5.2), secrecy does not depend on P1. P1 then affects only +liveness. + +--- + +## 6. What the board reveals + +This section is informative: it records consequences, not rules. + +- The board reveals who sent envelopes to whom and when, but no share (RFC 9180 §9.9). +- **No self-envelope.** A leaked `skR_j` reveals only the pairs `(s_ij, s'_ij)` with `i ≠ j`, + never `j`'s own evaluation or final share. +- **Exposure counting rule (ADR-0054 threat model).** Dealer `i`'s contribution is exposed when + the distinct evaluation indices known for `f_i` reach `t + 1`. The known indices are: + - leaked recipient keys `j ≠ i` for which an authentic envelope from `i` is on the board. This + includes one posted outside its window: it delivered nothing, but it is public and permanent; + - corrupted participants; + - public answers for `i`; + - the pairs published in rounds 5–6 for `i` (extraction complaints and reconstruction); a + dealer reconstructed in round 6 is entirely public; + - all of them, if `i` is corrupted. + + The joint key is exposed when every qualified dealer's contribution is exposed. +- **Answers.** Corrupted participants may still complain about any dealer. A dealer that has not + aborted answers every delivered complaint; a participant that aborted with T1 answers nothing + (§3.3). Under §5, every answer by an honest qualified dealer goes to a corrupted complainer's + index (ADR-0054 I15). + +--- + +## 7. Key lifecycle + +- **Per attempt.** A recipient key pair is generated for exactly one `(session, j)` and is used + only for that session. +- **Separation.** It is never the roster key `key_j` and is not derived from it. +- **Destroy.** The private key is needed only until round 1 is processed (§5.1), and should then + be destroyed. Implementations can only make this best-effort; it is offline class (ADR-0039). +- **Fresh randomness.** Every envelope uses a fresh ephemeral key from a cryptographically + secure generator. + +--- + +## 8. Assumption A1 + +The [GJKR07] proof assumes ideal private channels. This profile relies on the following +assumption, which ADR-0054 states and does not prove (an external-review gate): + +> Against a static adversary, New-DKG with ideal private channels can be replaced by New-DKG +> whose private messages are encrypted under an IND-CCA2-secure public-key encryption scheme +> to per-attempt honest recipient keys. Secrecy then holds computationally, under the security +> of that scheme plus [GJKR07]'s discrete-log assumption. + +RFC 9180 §9.1 and §9.1.2 describe HPKE Base mode's chosen-ciphertext security goal, and its +analysis. + +--- + +## 9. Test vectors + +### 9.1 Test keys + +Test keys are deterministic. Test X25519 private keys are + +``` +sk(tag) = SHA-256( ASCII("zeroj.dkg-share-delivery-hpke.v1.test.") ‖ ASCII(tag) ) +``` + +used as 32-byte scalars, clamped by X25519. Production keys must come from a secure generator. + +Tag scheme of the profile vectors (§9.3): +- `.recipient.` is participant `j`'s recipient key; +- `.ephemeral..` is the ephemeral key of envelope `i → j`; +- `envelope.ephemeral.` is the ephemeral key of a single envelope case. + +The prefix is the fixture name (`honest-2of3`, `honest-3of5`, `honest-4of7`), `timing.`, +`directory…`, `envelope…` or `announce`. The reference's README lists every tag. No tag is used +twice. + +### 9.2 Required external vectors + +- RFC 9180 Appendix A.2.1: every Base-mode encryption, sequence numbers 0–256 as listed in the + CFRG `test-vectors.json` at commit `b1f7cb0cdeab6906c61b3d6574e8bdfdbe1cd3fb`. +- [RFC 7748] §5.2 and §6.1, and Wycheproof `x25519_test.json`. +- [RFC 8439] §2.8.2, and Wycheproof `chacha20_poly1305_test.json`. +- [RFC 5869] A.1–A.3, and Wycheproof `hkdf_sha256_test.json`. + +The Wycheproof files are taken at commit `12fd3aaf33eb5fa1f52e026912ee00c054f9d984` of +`C2SP/wycheproof`. + +### 9.3 Profile vectors + +They are produced by the independent reference in +`zeroj-circuit-lib/src/test/resources/dkg-share-delivery-reference/`. Pinned values: + +Configuration `honest-2of3`: `t = 1`, `n = 3`, `ctx = "zeroj.test.honest"`, attempt 1, the +standard roster. Recipient 2's key is `sk("envelope.recipient.2")`. Dealer 1's share to +participant 2 is sealed with `skE = sk("envelope.ephemeral.good")`. + +| Item | Value | +|---|---| +| `pkR` (recipient 2) | `504988081ce259944f19570f5e350690a094ec9d519d9c41e20c355c4939d96a` | +| `info` (1 → 2) | `7a65726f6a2e646b672d73686172652d64656c69766572792d68706b652e76312e696e666f` ‖ session ‖ `01` ‖ `02` (71 bytes) | +| `enc` | `b9886d82301676564de05a8ace89f381e6421f55d634db0194093db4bc733d12` | +| `shared_secret` | `0af8f73bda0aa3472c9dfc33df93d80647bdd1612bfd2316d83c3c46022bd8e7` | +| `key` | `a50c772753344ab621250e97d7be47778df5114d1703a701e0ab16c1703e3e6f` | +| `base_nonce` | `a13c0a5653e198c69e43a28b` | +| `ct` (116 bytes) | `d898640e561c28fa2f1256ff43dbb3f03b61fe44f15577bcf715434119db5be2faf267425d83e29475d62b7a3f82fdd98994c385fb537b1d595b67021e048fa21bb4e467e4432ed55d8282edbe3c735ae7e28b54322539f3df54d7d31ce761da2028a60045b07987e39b92e44acd84f34431cbf7` | + +Full encrypted runs, with recipient keys `.recipient.` and ephemerals +`.ephemeral..`, give exactly the threshold profile's §11 outputs. Encrypted delivery +leaves the key generation unchanged: + +| Run | Transcript digest | `y` | +|---|---|---| +| `honest-2of3` | `2af7f7eae154833d51861bae276448b396eae5479a074a833a31a9fb9aa46023` | `14acdc488055720e853cbb6b613d2c7f52aee2fa8e7f37b410b1fa9093082658` | +| `honest-3of5` | `edd7aa9f589992e9801d76987611d293ff921e046da81c3790121d767ffdcf71` | `89eeef65017eb8f1a18e38a5b9fc0efb971386181e0db4649c60941cd5a6c425` | +| `honest-4of7` | `9b6a52fe5b0fb06feb875b82cb37871e64bc235b01de384ba54a06f96c24431b` | `ba8011aef2b5f23231919caf1c3c901626e7c970436e98386d46b01713616a63` | + +The reference's `reference-output.txt` holds every vector: 110 replayable cases (announce, +envelope, directory, timing, run and exposure), each documented in its README. + +--- + +## 10. References + +- **[RFC 9180]** R. Barnes, K. Bhargavan, B. Lipp, C. Wood, *Hybrid Public Key Encryption*, + February 2022: + - §3: notation; + - §4: labeled HKDF; + - §4.1: DHKEM; + - §5.1: key schedule; + - §5.1.1: Base mode; + - §5.2: encryption and sequence numbers; + - §6.1: single-shot; + - §7.1–§7.3: identifiers; + - §7.1.3: DeriveKeyPair; + - §7.1.4: validation; + - §8.1: `info`; + - §9: security considerations; + - Appendix A.2: test vectors. +- **[RFC 7748]** *Elliptic Curves for Security*, January 2016: §5 (X25519, decoding), §5.2 and + §6.1 (test vectors). +- **[RFC 8439]** *ChaCha20 and Poly1305 for IETF Protocols*, June 2018: §2.8 (AEAD). +- **[RFC 5869]** *HMAC-based Extract-and-Expand Key Derivation Function (HKDF)*, May 2010, + including Appendix A. +- **[GJKR07]** Gennaro, Jarecki, Krawczyk, Rabin, J. Cryptology 20:51–83 (2007), §2.1 and Fig. 2. +- **ZeroJ:** ADR-0053, ADR-0054, [`elgamal-jubjub-threshold-v1`](elgamal-jubjub-threshold-v1.md). diff --git a/zeroj-circuit-lib/src/test/resources/dkg-share-delivery-reference/README.md b/zeroj-circuit-lib/src/test/resources/dkg-share-delivery-reference/README.md new file mode 100644 index 00000000..7004ea1b --- /dev/null +++ b/zeroj-circuit-lib/src/test/resources/dkg-share-delivery-reference/README.md @@ -0,0 +1,542 @@ +# DKG share delivery with HPKE v1: independent reference + +This is an independent reproduction of the `dkg-share-delivery-hpke-v1` transport profile +(ADR-0054, milestone M0). It covers HPKE Base mode from RFC 9180, the announcements, the key +directory, abort T1, the envelopes, the processing barrier, the D7a posting order and the +exposure counting rule. It was written from the spec, the RFC texts and the existing Python +reference of the threshold DKG. Its output is evidence for checking ZeroJ's Java implementation. +It is not a security proof. The composition argument (Assumption A1) stays an external-review +gate. + +## Files + +- `dkg_share_delivery_hpke_v1_reference.py`: Python 3. It uses pyca `cryptography` 46.0.5 for + four things only: X25519, HMAC-SHA256, ChaCha20Poly1305, and HKDF (HKDF only as a + differential). Everything else uses the standard library. It contains: + - **HPKE, from the RFC 9180 text:** + - LabeledExtract and LabeledExpand (§4); + - DHKEM(X25519, HKDF-SHA256): Encap, Decap, ExtractAndExpand and `kem_context` (§4.1); + - DeriveKeyPair (§7.1.3); + - KeySchedule, with VerifyPSKInputs (§5.1); + - a context with a sequence number, ComputeNonce, the overflow error and Export (§5.2, §5.3); + - SealBase and OpenBase (§6.1); + - the all-zero DH check (§7.1.4), for both sender and recipient. + + HKDF Extract and Expand are written from RFC 5869 on pyca's HMAC. A pure-Python X25519 + ladder, transcribed from RFC 7748 §5, is used as a differential. It also evaluates + small-order inputs, which pyca refuses. + - **The profile:** + - canonicality and the small-order probe (§2); + - announcements, the directory and T1, including its key-mismatch clause (§3); + - `info`, sealing, and the 6-step opening rule, with de-duplication only after + authentication (§4); + - a board with windows, cutoffs, processing lags, the barrier and D7a (§5); + - the counting rule (§6); + - session-bound, destroyable recipient keys (§7); + - the test keys `sk(tag)` (§9.1). + - **DKG mechanics:** imported from + `../elgamal-threshold-reference/elgamal_jubjub_threshold_v1_reference.py`, not + reimplemented. That covers `Config`/session, the §11 dealings, `SHARE`/`COMMITMENTS` + encodings, `parse`, `simulate` (rounds 1–7, `QUAL`, complaints, answers, aborts), + `delivered_round` and the transcript digest. Decrypted `SHARE`s enter `simulate` only + through its private channel (`Script.private_raw`). No transport message enters a DKG + round. +- `reference-output.txt`: the output, one `key=value` per line, sorted by key, with no header. + +## Running + +``` +cd zeroj-circuit-lib/src/test/resources/dkg-share-delivery-reference +python3 dkg_share_delivery_hpke_v1_reference.py +``` + +The run takes about 10 s. It prints the output and rewrites `reference-output.txt`. +- **Exit status:** 0 if every check passes. Otherwise 1, with the failing keys on stderr; a crash + also gives 1. +- **Determinism:** the output depends only on the code and the vendored inputs. It contains no + Python version and no timing. Two runs, and runs with `PYTHONHASHSEED` set to 0, 1 and 12345, + gave byte-identical files (SHA-256 at the end of this README). + +## Independence + +Read: +- `docs/specs/dkg-share-delivery-hpke-v1.md`, `docs/adr/0054-hpke-dkg-share-delivery.md` and + `docs/specs/elgamal-jubjub-threshold-v1.md`. During the work, an informative paragraph about + this profile was added to §5.2 of that spec; it changes no rule; +- the RFC texts: RFC 9180, RFC 7748, RFC 8439 and RFC 5869; +- the vendored vectors in `../standard-vectors/` and their README; +- the threshold reference's README and Python source. + +The spec was read again at its second revision (resolving S1–S7), with the same rules. + +Not read: any Java source (`*/src/main/java`, `*/src/test/java`) and any other ZeroJ code. A +`git diff --stat` printed some Java file names, but no Java content was opened. + +Every expected value of the primitives comes from published vectors: the RFC texts, the CFRG +A.2.1 JSON and Wycheproof. The profile vectors are this reference's own outputs. Where the code +could have got one of them wrong, a hand-written intent check states the outcome the case was +built to show (see "Checks"). + +## Results + +This README describes the run against the **second revision** of the spec, which resolves +findings S1–S7 of the first run (see "Spec findings"). + +All 294 checks pass. There are 110 replayable vectors, and each replays from its own keys. + +| Area | Result | +|---|---| +| RFC 9180 A.2.1 | `DeriveKeyPair(ikmE)` and `DeriveKeyPair(ikmR)` give `skEm`/`pkEm` and `skRm`/`pkRm`. `enc`, `shared_secret` (Encap and Decap), `key_schedule_context`, `secret`, `key`, `base_nonce` and `exporter_secret` all match. **All 257 encryptions (sequence numbers 0–256) match**, sealed and opened through one sender context and one receiver context, with each nonce checked against `base_nonce XOR seq`. All 3 exported values match on both sides. Single-shot SealBase/OpenBase matches. Wrong `info`, wrong `aad`, wrong key and an out-of-sequence ciphertext are refused, and sequence overflow raises. | +| RFC 7748 | §5.2: both vectors and the 1-iteration and 1,000-iteration results match, through pyca and through the ladder. The 1,000,000-iteration result is not run, for cost. §6.1: Alice's and Bob's public keys and `K` match. | +| Wycheproof X25519 (518 tests) | All 518 pass. See "Handling of acceptable cases" below. | +| RFC 8439 §2.8.2, Wycheproof ChaCha20-Poly1305 (325 tests) | The KAT seals and opens, and a modified tag is refused. Wycheproof: 256 valid tests seal to `ct‖tag` and open. 69 invalid tests fail to open: 60 have a modified tag, and 9 have a wrong nonce size. | +| RFC 5869 A.1–A.3, Wycheproof HKDF-SHA256 (86 tests) | PRK and OKM match. 83 valid tests match, both in this reference's HKDF and in pyca's. 3 invalid tests (`SizeTooLarge`) are refused by both. | +| §2.2 claim | Verified independently (see "Small-order points"). | + +### Handling of "acceptable" Wycheproof X25519 cases + +The file has 264 `valid` tests, 254 `acceptable` tests and no `invalid` ones. + +| Category | Count | Handling | +|---|---|---| +| `valid` | 264 | pyca, the ladder and the HPKE `DH` all give `shared`. Every public value is canonical. | +| `acceptable`, non-zero `shared` (twist, non-canonical or edge-case public values) | 223 | **Computed.** pyca and the ladder both give `shared`, as RFC 7748 §5 requires the X25519 function to accept these values. At the profile layer, the 13 with a non-canonical public value would be refused before any X25519 call (§2.1). The other 210, including twist points, are canonical and pass the probe. | +| `acceptable`, all-zero `shared` (`ZeroSharedSecret`) | 31 | **Refused.** The ladder gives `0^32`, pyca raises, and the HPKE `DH` raises `ValidationError` (RFC 9180 §7.1.4). At the profile layer, all 31 public values fail canonicality or the probe. | + +pyca raises exactly on the all-zero output. That was checked against the ladder on every +Wycheproof input and every small-order point. + +### Small-order points (§2.2) + +There are exactly 5 canonical small-order u-coordinates: `0`, `1`, the two order-8 values, and +`p − 1`. They were found two independent ways: +- **From Wycheproof:** reduce every public value with an all-zero shared secret (mask bit 255, + then reduce mod `p`). +- **Algebraically:** the order-2 points (`x = 0`, and the roots of `x² + Ax + 1`, which have none + in `F_p`). Then repeated x-only halving, solving `x(2P) = c` through `w = x + 1/x`. + +The two sets are equal (`check.small_order.algebraic_equals_wycheproof_set`). There are no +order-16 points. + +The spec's claim was then checked in both directions: +- `X25519(k, u) = 0^32` for `PROBE` and for five other test scalars, on every small-order `u`; +- `X25519(PROBE, u) ≠ 0` for every other public value in the file. + +The reason, in brief: a clamped `k` is `8m` with `2^251 ≤ m < 2^252`, which is below both the +curve's prime order `l` and the twist's `l'`. So `[k]P = O` exactly when the order of `P` +divides 8. + +## Output keys + +| Key | Content | +|---|---| +| `profile`, `profile.*` | The suite, `TAG_A`, `TAG_I` and `TAG_E` with their lengths, `PROBE`, and the §9.1 prefix. | +| `session.` | The threshold-profile sessions used: `honest-2of3`, `honest-3of5` and `honest-4of7` (`ctx = "zeroj.test.honest"`, attempt 1, threshold §11 roster). `*-attempt2` is the same configuration at attempt 2. | +| `small_order.*` | The Wycheproof-derived and algebraic sets, in hex of the big-endian integer. | +| `check.*` | Checks, each `true` or `false`. | +| `info.*` | Informative values, which are not checks. Among them: the Wycheproof counts per category (`info.wycheproof.*.count.*`), the failed test ids (empty), `info.rfc9180.a21.encryptions.*`, the per-trace values `info.timing.*`, `info.case_count.*`, `info.check_count` and `info.failed_checks`. | +| `case...*` | Replayable vectors (below). | +| `result` | `pass` or `fail`. | + +Value conventions: +- byte strings are bare lowercase hex; +- lists of ids are comma-separated and may be empty; +- `i->j` pairs are comma-separated, sorted, and mean (sender, subject): + - a complaint `j->i` is "participant `j` complains about dealer `i`"; + - an answer `i->j` is "dealer `i` answers complainer `j`". + +## Test keys + +All keys are `sk(tag)` of spec §9.1: `SHA-256("zeroj.dkg-share-delivery-hpke.v1.test." ‖ tag)`. +The tag scheme below is normative since the second revision (§9.1). +The 32 bytes are used directly as an X25519 scalar, which X25519 clamps; they are **not** passed +through DeriveKeyPair. Then `pk = X25519(sk, 9)`. Production keys must come from a secure +generator (§2.3). + +| Tag | Use | +|---|---| +| `.recipient.` | Participant `j`'s recipient key. The prefix is the fixture (`honest-2of3`, …), `timing.`, `directory`, `directory.conflicts`, `envelope`, `envelope.attempt2` or `announce`. | +| `.ephemeral..` | The ephemeral key of envelope `i → j` in a board scenario. | +| `envelope.ephemeral.` | The ephemeral key of a sealed `envelope` case. The good case uses `envelope.ephemeral.good`. | +| `directory.recipient.3.second`, `directory.forged.2`, `directory.other_session.1`, `directory.recipient.1.late`, `directory.conflicts.recipient..second`, `directory..substitute.2` | Extra announced keys in the directory cases. | +| `small-order.scalar.` | The extra scalars used for the §2.2 claim. | + +Every ephemeral tag is used once, and every test key is distinct +(`check.lifecycle.ephemeral_tags_never_reused`, `check.lifecycle.all_test_keys_distinct`). + +## Replayable vectors + +Counts: `announce` 21, `envelope` 42, `directory` 4, `run` 3, `timing` 16, `exposure` 24, so +110 in all. `config` is always `t,n,ctx-hex,attempt`, and the roster is the threshold §11 standard +one (`key_j` = 32 bytes, each equal to `j`). + +### `case.announce..*` (§3.1 well-formedness) + +| Key | Content | +|---|---| +| `config` | The configuration the announcement is checked against (`honest-2of3`). | +| `bytes` | The announcement. | +| `expect` | `accept` or `reject`. | +| `reason` | Informative: `length_or_tag`, `session`, `index`, `non_canonical`, `small_order` or `none`. The spec sets no precedence among reasons. | +| `u` | `small_order_` only: the small-order `u`. | + +Cases: +- accepted: `well_formed_j1`, `well_formed_j_n`, `canonical_u_p_minus_2` (the largest canonical + value that is not small-order) and `canonical_base_point_u_9`; +- rejected: + - `wrong_tag_first_byte`, `tag_of_envelope`, `length_105`, `length_107`; + - `other_session` (attempt 2), `j_zero`, `j_n_plus_1`; + - `non_canonical_bit255_set`, `non_canonical_u_p`, `non_canonical_u_p_plus_1`, + `non_canonical_u_p_plus_9`, `non_canonical_u_2_255_minus_1`; + - `small_order_1` … `small_order_5`, all five canonical small-order points. + +Authentication and windows are not part of well-formedness. The directory vectors cover them. + +### `case.envelope..*` (§4.2 acceptance) + +| Key | Content | +|---|---| +| `config` | Mostly `honest-2of3`. The cross-attempt cases use attempt 2. | +| `recipient` | `j`, the participant that opens the envelope. | +| `recipient_key_tag` | `j`'s key, `sk(tag)`, bound to `(config session, j)`. | +| `auth`, `bytes` | One envelope and the participant its post is authenticated as (`none`: unauthenticated). Multi-envelope cases use `auth.` and `bytes.`. | +| `expect` | Envelopes are processed in the listed order. `share:` (one `SHARE` delivered), `absent`, or `shares:,` (two different `SHARE`s, which the threshold profile treats as a conflict, so `j` complains). | +| `step` | Informative: the first §4.2 step that fails (1–6), or `none` (for several envelopes: `none` if any is accepted). | +| `good` only: `info`, `enc`, `ct`, `plaintext`, `pkR`, `ephemeral_tag`, `shared_secret`, `key`, `base_nonce`, `key_schedule_context` | Intermediate values, for debugging. | + +The cases are listed below. Dealer 1 seals to recipient 2 unless the name says otherwise. The +step that fails is in parentheses. +- Delivered: + - `good`; + - `duplicate_byte_identical`: one share; + - `duplicate_unauthentic_copy_first`: a byte-identical copy authenticated as 3 is listed before + the genuine envelope. Each is authenticated on its own (step 3) before de-duplication, so the + copy fails and the genuine one delivers the share. + `check.envelope.duplicate_unauthentic_copy_first.dedup_before_auth_would_lose_share` shows + that de-duplicating first would lose it; + - `reencrypted_same_share`: two different envelopes of the same `SHARE` give one share (§4.2); + - `canonical_enc_u_9_control`: `enc = 9`, so the DH output is `pkR`, which is public. It is + accepted: a dealer can always reveal its own share. +- Two shares: `two_different_shares_conflict`. +- Absent: + - (1) `truncated_222`, `extended_224`, `wrong_tag_first_byte`, `tag_of_announce`, + `plaintext_99_bytes`; + - (2) `wrong_session_header`, `sender_zero`, `sender_n_plus_1`, `self_envelope_i_equals_j`, + `wrong_recipient_header_seen_by_2`, `cross_attempt_replay` (an attempt-1 envelope seen in + attempt 2); + - (3) `wrong_sender_header_auth_mismatch`, `unauthenticated`; + - (4) `non_canonical_enc_bit255_set`, `non_canonical_enc_u_p_plus_9`, + `non_canonical_small_order_enc_u_p`, `non_canonical_small_order_enc_u_p_plus_1`; + - (5) `reposted_by_other_sender` (header and authentication say 3), `wrong_recipient_key`, + `wrong_recipient_header_opened_by_3`, `tampered_enc_byte0`, `tampered_ct_byte0`, + `tampered_tag_last_byte`, `small_order_enc_1` … `_5`, `cross_attempt_replay_header_rewritten` + and `cross_attempt_replay_header_rewritten_key_reused` (the attempt-1 key reused, against + §7); + - (6) `plaintext_answer_message`, `plaintext_random_100_bytes`, `plaintext_share_wrong_sender`, + `plaintext_share_wrong_subject`, `plaintext_share_other_session`, + `plaintext_share_scalar_not_below_l`. + +The adversarial `enc` cases are built so that only the check named refuses them: +- the non-canonical ones encrypt under the `kem_context` of the non-canonical bytes; +- `u = p + 9` uses the DH output `X25519(skR, 9) = pkR`; +- the small-order ones encrypt under a DH output of `0^32`. + +`check.envelope.*.opens_without_step4` and +`check.envelope.small_order_enc.all_open_without_zero_check` show that OpenBase would deliver +the share if step 4, or the all-zero check, were skipped. + +### Board vectors: `case.directory.*`, `case.timing.*` + +The board model: +- Times are integers. Round 0 is the window `[0, cut0)`, and round 1 is `[cut0, cut1)` (`cut0 = + 10`, `cut1 = 20`). A post's time is its inclusion and finality time. A post outside its round's + window belongs to no window; in particular round 1 opens when round 0 closes (§5). +- In each window, every post is first authenticated on its own (announcements §3.1, envelopes + §4.2 step 3, `COMMITMENTS` threshold §4–§5), and only then are byte-identical copies counted + once. With `dedup_before_auth=true` (negative control only), posts are de-duplicated by bytes + first, keeping the earliest, which is the defect the spec forbids. +- Participant `j` finishes processing post `p` at `p.time + lag(j, p)`. The default lag is 0. +- With `barrier=true` (§5.1), each participant uses every post of the final window. With + `barrier=false` (negative control), it closes at the cutoff and uses only the posts it + finished processing before then. +- Rounds 2–7 are run by the threshold reference's `simulate`, with timely broadcast. Each + participant's private deliveries are the `SHARE`s accepted by §4.2 from the envelopes it + processed. +- T1 (§3.3) fires when the participant's directory has no key for it, or a key other than the + one it holds (`recipient_key_tag.`). A T1 participant posts nothing after round 0: no + complaint and no answer. Participants in `t1_ignored_by` are corrupted and deviate: they do + not apply T1. +- `extra_complaint` entries are additional round-2 `COMPLAINT`s posted by corrupted + participants. + +| Key | Content | +|---|---| +| `config`, `cut0`, `cut1` | The configuration and the window cutoffs. | +| `barrier`, `d7a`, `t1_rule` | `true` or `false`; `false` marks a negative control. `d7a` affects only how the board was generated: the posts are given, and replay does not need it. | +| `corrupted` | The adversary's set, for the coalition analysis and for I15. | +| `t1_ignored_by` | Deviating participants that do not apply T1. | +| `dedup_before_auth` | `true` only in the two front-running negative controls. | +| `withhold_extraction` | Dealers whose round-4 `EXTRACTION` is not delivered. | +| `recipient_key_tag.` | Each participant's recipient key. | +| `post.` | `time,author,label,hex`. `author` is the authenticated sender. `label` names the post (`announce.[.]`, `envelope..`, `commitments.[.early]`; a front-running copy is `