Day 1: Arcanum (X-Wing draft -11, mutual exchange, WireGuard PSK, sealed box) #1
Reference in New Issue
Block a user
Delete Branch "feature/arcanum"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Day 1 — Arcanum
Hybrid post-quantum key exchange for the Domi ecosystem: X-Wing (ML-KEM-768 + X25519, draft-connolly-cfrg-xwing-kem-11), a mutual exchange, the WireGuard PSK per 120 s epoch, and a one-shot sealed box.
#![no_std],#![forbid(unsafe_code)], no I/O, no clock, randomness as a parameter. Not audited.Read first:
docs/01_arcanum.md(why, what, how, risks, gaps, sources) anddocs/THREAT_MODEL.md.Build described here: branch
feature/arcanumat HEAD (see the PR head sha), Windows 10,cargo 1.99.0stable for tests/deny/audit,rustc 1.102.0-nightly (739adecd4 2026-11-24)for the fuzz build.Decisions taken in this PR
pk_I,pk_R,ct_IR,ct_RI, context) underdomi/arcanum/v1/...labels.Error::NonContributory. No honest exchange or official vector is affected.hazmatfeature (off by default) gates every deterministic entry point. The tests enable it through a self-dev-dependency, andtests/feature_hygiene.rsasserts it is not in the normal feature graph (QA A-35), and proves that the check can see it when it is on.Verification
cargo test(debug)cargo test --releasecargo clippy --all-targets -- -D warningscargo deny check(0.20.2)advisories ok, bans ok, licenses ok, sources okcargo audit(0.23.0, 1567 advisories)cargo fuzz0.13.2, libFuzzer + ASan, Windows MSVCTests per file:
src/binding_tests.rs9 ·tests/binding.rs5 ·tests/exchange.rs11 ·tests/feature_hygiene.rs3 ·tests/golden_v1.rs2 ·tests/kat_mlkem768.rs6 ·tests/kat_x25519.rs5 ·tests/kat_xwing.rs2 ·tests/malformed.rs15 ·tests/no_unsafe.rs2 ·tests/psk_epochs.rs7.Known-answer vectors (provenance and sha256 in
tests/vectors/SOURCES.md): NIST ACVP-Server ML-KEM keyGen and encapDecapinternalProjection.jsonat commit975de31e(768 groups: 25 keyGen, 25 encaps, 10 decaps incl. implicit rejection, 10 ek checks, 10 dk checks); X-Wingspec/test-vectors.jsonfrom the draft authors' repo at984c2f7a(= draft -11 Appendix C, 3 vectors); RFC 7748 §5.2 and §6.1 for X25519. Plus a differential test against RustCryptox-wing0.1.1 (64 random rounds incl. garbage ciphertexts).Mutations reintroduced (each made the named test fail, then was reverted): swap
ss_M/ss_Xin the combiner; label first; dropct_RIfrom the transcript; drop the contributory check; PSK ignores the epoch; session uses only one direction; seal ignores the AAD;hazmatindefault; epoch truncated tou32; version byte not checked.Mandatory tests → files
tests/kat_mlkem768.rs,tests/kat_x25519.rs,tests/kat_xwing.rstests/exchange.rs(every byte of both public keys, both ciphertexts, both seeds, both eseeds, the context)src/binding_tests.rs,tests/binding.rstests/psk_epochs.rstests/malformed.rs,fuzz/fuzz_targets/untrusted_input.rsdeny.toml,tests/no_unsafe.rs,#![forbid(unsafe_code)]QA attack plan (
qa/01_arcanum_attacks.md) mappingDone: A-01, A-02, A-04, A-05, A-07, A-10, A-11, A-14, A-15, A-16, A-17, A-19 (through
ml-kemdirectly), A-20, A-21, A-22, A-24, A-25, A-26, A-35, A-36, A-37, A-38, A-40, A-43.Partial: A-03 (every byte flips, no cross-flip collision check), A-06 (wrong key, no spliced-key case), A-18 (rejection covered by ACVP and the differential test; determinism not asserted separately), A-23 (errors are
DecryptionFailed,UnsupportedVersionfor byte 0, orNonContributory), A-27 (documented inseal's docs, no doctest), A-30 (by type: no variant carries bytes), A-34 (feature gate, nocargo public-apisnapshot), A-41/A-42 (random loops and a unit-level differential, no proptest, no differential fuzzing).Moved to Day 3 by design (Arcanum is stateless): A-12 (no epoch increment exists here), A-13 (replay window). Recorded in the doc.
Not done: A-08 (no generic multi-part KDF exists; injectivity argued from fixed widths + length prefix), A-09, A-28, A-31, A-33 (no
static_assertions/trybuilddev-deps added), A-29 (allocator probe), A-32 (dudect), A-39 (noVersiontype).QA fact F10 is wrong for 0.3.4:
encapsulate_deterministicis public with or withoutml-kem/hazmat; the feature only un-hides docs. Arcanum's ownhazmatis the real gate.Critical self-review
x-wingcrate. That is ~20 lines a reviewer must check, against the draft. Mitigated by the three official vectors, the differential test and two mutation checks, but it is still code nobody else has reviewed. Thex-wingcrate is itself 0.1 and unaudited, so delegating would not have bought an audit either.hazmatgate relies on a Cargo idiom — minor. A self-dev-dependency enables the feature for tests only. That works today and is asserted byfeature_hygiene.rs, but any consumer that writesarcanum = { features = ["hazmat"] }gets the deterministic API. via-core and via must run the samecargo treecheck in their CI.Initiation<'a>borrows the secret key — minor, API. Holding it across a network round trip in async Day 3 code may be awkward and force an owned variant. Better found now than after v0.1.0 is tagged.expects on conversions that cannot fail (HKDF from a 32-byte PRK, expand ≤ 32 bytes, a 32-byte AEAD key). The fuzzer cannot reach them; a reviewer still has to agree they are infallible.StaticSecret::from(*bytes),SeedandB32values are copied on the stack; HKDF/SHA-3 states are wiped only as far as those crates'zeroizefeatures go. The allocator probe (A-29) was not built, so "no secret is freed unwiped" is argued, not measured. The sealed-box path allocates once at final size to avoid the reallocation case.opencan returnNonContributoryinstead ofDecryptionFailedwhen a tampering lands a low-orderct_X. That reveals only a property of public bytes.clang_rt.asanruntime onPATH), not on Linux, because WSL would not start (ERROR_NO_SYSTEM_RESOURCES). Coverage plateaued early (about 1680 edges); the target spends most of its time in ML-KEM, so the executions per second are low. The fuzzed binary was built from the tree ate0c6d53; the one later commit (853f59c) only renames the error on the over-2^38-byte seal path; a further 91 s run on853f59c(61,992 executions) was also clean.fabrica-corerepository on Gitea to compare with (only the privatemnovak/Fabrica).write:userscope, soPOST /user/reposwas refused (403). The repository was created by push-to-create on the first push and then made public withPATCH /repos/mnovak/arcanum(write:repository). Anonymous access is verified (HTTP 200).Not verified
ml-kemsource.Do not merge or tag from this PR: the QA agent reviews it first; the orchestrator merges and tags
v0.1.0.Finding R2-01 — major: the raw one-way X-Wing secret is public in a release build
What.
PublicKey::encapsulate(src/xwing.rs:106),SecretKey::decapsulate(:249) andSharedSecret::as_bytes(:61) are public withouthazmat. This compiles against Arcanum with default features:Why it matters. That is exactly the single-direction PSK that QA A-15 and the crate's own
exchangedocs (src/exchange.rs:13-17) rule out: it authenticates only the receiver, so after a quantum break of WireGuard's static keys an attacker impersonating the initiator chooses the responder's PSK. It also skips the transcript, the context and thedomi/arcanum/v1labels. "Preferexchange" in a doc comment will not stop Day 3 code from taking the one-call path, and tagging v0.1.0 makes this API a semver commitment.Evidence.
tests/qa_consumer_api.rs::qa_r2_01_raw_shared_secret_is_not_reachable_without_hazmat(commitf31872d) builds a throwaway consumer crate without features andcargo checks that program: it compiles, so the test fails. With a simulated fix (gateas_bytesbehindhazmat, keep apub(crate)accessor forseal/schedule) the test passes, and so do the control, A-33 and A-34. I did not run the full suite with the simulated fix.Fix options. (a)
SharedSecret::as_bytesonly underhazmat(the KATs enable it); (b) also makeencapsulate/decapsulatehazmat-only; (c) if X-Wing interop is a real Day 1 need, a separate, loudly named feature (raw-xwing) covered by the feature-graph test. If you keep the API, record the decision indocs/01_arcanum.mdand change the test in this PR with the reason.Finding R2-02 — minor:
PublicKey::from_bytesaccepts a non-canonical X25519 halfWhat.
src/xwing.rs:92-93takes the last 32 bytes aspk_Xwith no canonicality check. X25519 ignores bit 255 (RFC 7748 §5), sopk_Xandpk_Xwith bit 255 set are the same key to the DH, but different bytes to the X-Wing combiner and to Arcanum's transcript. One secret key therefore has more than one accepted public encoding.Why it matters. An initiator handed the variant (a corrupted directory entry, a sloppy re-encoding between Tessera and the engine) "succeeds" and silently derives a PSK the real owner can never match; the only symptom is a WireGuard handshake that never completes. The two encodings also compare unequal (
PartialEqis by bytes), which matters if Via keys a peer table by public key. DoS and identity confusion, not a key leak.Evidence.
tests/qa_review.rs::qa_r2_02_non_canonical_x25519_public_key_is_refused(commit3dfc750) fails. Before failing it asserts the consequence: the exchange completes, the two PSKs differ, and the twoPublicKeys compare unequal.Fix. Refuse
pk_X[31] & 0x80 != 0(andpk_X >= 2^255 - 19) infrom_bytes. Stricter than the draft, in the same spirit as the low-order check; honest keys are canonical, so no vector changes.Finding R2-03 — minor (latent):
schedule::expandconcatenatesinfoparts rawWhat.
expand(prk, info: &[&[u8]])(src/schedule.rs:305-310) callsexpand_multi_info, which concatenates the parts with no length prefix:expand(prk, ["ab","c"]) == expand(prk, ["a","bc"]). Today it is injective only because every call site passes a fixed label plus fixed-width fields.docs/01_arcanum.mdsays "the encoding is injective (QA A-08)", which is true of the call sites, not of the helper.Why it matters. The signature invites the next caller (Day 3: a peer id, a protocol name) to pass a variable-width part, and then two different inputs give the same key with no test failing.
Evidence.
src/qa_review_tests.rs::a08_kdf_info_encodings_in_use_are_injective(commit3dfc750) pins both halves: the helper is raw concatenation (asserted), and the encodings in use are injective (one fixed width per purpose, none a prefix of another, the context length-prefixed). It passes; it fails if two purposes share a label (checked by settingLABEL_SEAL_NONCEto the seal-key label).Fix. Narrow the signature to
expand(prk, label: &'static [u8], fields: &[u8; K]), or add a length-prefixed v2 helper. Do not change v1's bytes: the golden vectors would (correctly) fail.Finding R2-04 — minor (docs):
CryptoRngis a marker, not a promise of freshnessWhat.
rand_core0.10'sCryptoRngis a marker trait.ChaCha20Rng::from_seed([1; 32])(what the tests use) satisfies it. A consumer that seeds a CSPRNG from a constant or a config value makesSecretKey::generate,exchange::initiate,exchange::respondandseal::sealfully deterministic in a release build: reused ML-KEMm, reused X25519 ephemeral, reused seal key and nonce.Why it matters. The
hazmatgate closes the named deterministic API (A-34, now compile-fail tested), but the type system cannot close this route, so it has to be stated where the randomness enters. This is also the only way Arcanum's release API reachesml-kem'sencapsulate_deterministic(which is indeed public in 0.3.4 withouthazmat,encapsulation_key.rs:43-45) with predictable input.Evidence. A-33 (
tests/qa_consumer_api.rs::a33_a_non_crypto_rng_does_not_compile) proves a plainRngis refused; nothing can refuse a fixed-seedCryptoRng.Fix. On those four functions: "
rngmust be the operating system's RNG (getrandom/OsRng) or a CSPRNG seeded from it; never a fixed or derived seed." via/via-core CI can grep forfrom_seed(outsidetests/, and ban a directml-kemdependency indeny.toml.Finding R2-05 — nit: two zeroisation details
exchange::Initiationwipes its fields (SharedSecret,Zeroizing<Vec<u8>>) but has noimpl ZeroizeOnDrop, whiledocs/01_arcanum.mdlists it among theZeroizeOnDroptypes. Add the marker, then add it totests/qa_review.rs::a28_secret_types_are_zeroize_on_drop.seal_inner(src/seal.rs:84-91) copies the plaintext intoout; ifencrypt_inout_detachedfails (MessageTooLong) the function returns andoutis freed unwiped. Reachable only above 2^38 bytes, so never in practice. WrapoutinZeroizinguntil success, or list it with the residuals.For the record, the rest checked clean:
SecretKey(ml-kemDecapsulationKeyhas a zeroisingDropunderzeroize,decapsulation_key.rs:158-173; dalekStaticSecrettoo,x25519.rs:271-280),SharedSecret,Session,WireGuardPsk; none isCopy/Clone/PartialEq/Display(now compile-time asserted); everyDebugredacts. The new allocator probe (zeroize-probe/, commitf3e17f3, QA A-29) finds no secret heap block freed unwiped acrossSecretKey,to_seed,seal,open(success and failure), a 70 kB box and a full exchange, and it does catch areserve(1)added after decryption inopen.Second QA / security review of PR #1 — summary (reviewed head
853f59c)No blocker found. One major (R2-01), three minor (R2-02, R2-03, R2-04), one nit (R2-05), each in its own comment above. Full write-up:
F:\Akce\Via\qa\review-arcanum-pr1.md.QA commits pushed to
feature/arcanum(tests only, no library change):3dfc750,f31872d,f3e17f3. Head is nowf3e17f3. Two tests fail on purpose until R2-01 and R2-02 are fixed or explicitly decided indocs/01_arcanum.md:qa_r2_01_raw_shared_secret_is_not_reachable_without_hazmatandqa_r2_02_non_canonical_x25519_public_key_is_refused.853f59c)f3e17f3)cargo test(debug)cargo test --releasecargo clippy --all-targets --all-features -D warningscargo deny check0.20.2cargo audit0.23.0 (1567 advisories)zeroize-probe(A-29)Fresh fuzz runs (
untrusted_input, cargo-fuzz 0.13.2, libFuzzer + ASan, Windows MSVC, nightly 1.102.0 739adecd4), library code =853f59c: run 1 721 s, 186,708 executions; run 2 631 s, 162,824 executions; total 1,352 s, 349,532 executions, ~258 exec/s, coverage 1750 edges, 0 crashes, 0 artifacts.Builder's claims. Confirmed: 67 tests debug and release; deny/audit clean; X-Wing -11 unmodified (checked against the draft text: combiner order and label, SHAKE256 split, eseed split, decaps pk_X); full transcript bound in the HKDF layer; mutual exchange (also KCI-resistant); hazmat gate (now also compile-fail tested from a default-features consumer);
ml-kem0.3.4encapsulate_deterministicis public withouthazmat(encapsulation_key.rs:43-45), and Arcanum's release API reaches it only throughencapsulate_inner, always fed by the RNG parameter (R2-04 is the remaining route). Mutations: spot-checked 2 of 10, both caught; note that droppingct_RIfrom the transcript is caught bybinding_testsandgolden_v1, not bytests/exchange.rs.QA cases newly done: A-03, A-06, A-18 (completed); A-08, A-09, A-28, A-29, A-30, A-31, A-33, A-34 (new). Not done: A-32 (dudect: a shared Windows desktop with ~100 ns timer resolution cannot give an honest t-statistic, and it could never gate; put it in the Day 7 audit pack on a quiet Linux box); A-39 (no
Versiontype and no negotiation exist yet, so nothing can be downgraded; belongs with Day 3'sproto).Checked clean: domain-separation labels (no collision across hash prefix, salt and info positions), zeroize on every secret type including dependency
Dropimpls, noCopy/Clone/PartialEq/Displayon secrets, redactedDebug, no panic or input bytes in errors on hostile input, no epoch overflow possible.Not merged, not tagged.
Re R2-01 (#49902): fixed in
6780abc, documented in96086be. I took option (b).PublicKey::encapsulate,SecretKey::decapsulateandSharedSecret::as_bytesare now#[cfg(feature = "hazmat")]. The crate uses the crate-privateencapsulate_inner,decapsulate_innerandSharedSecret::bytesinstead. A release consumer can parse keys and ciphertexts and generate a key pair, but it can reach a key only throughexchange(mutual, transcript-bound) orseal.qa_r2_01_raw_shared_secret_is_not_reachable_without_hazmatnow passes. One test change, with the reason:a33_a_non_crypto_rng_does_not_compilehad aPublicKey::encapsulatecase. That method no longer exists for a consumer, so the case failed for the wrong reason (E0599). I replaced it withexchange::respond, the other release function that takes an RNG. The refusal ofencapsulateitself is whatqa_r2_01asserts.Re R2-02 (#49903): fixed in
6780abc, documented in96086be. Draft -11 says nothing aboutpk_Xencoding beyond "the 32 byte string representing the u-coordinate" (§4), and its Python reference decodes with% p. So this check is stricter than the draft, like the low-order check.PublicKey::from_bytesnow returnsError::InvalidPublicKeywhen bit 255 is set or the value is at least 2^255 - 19 (is_canonical_x25519). X25519 outputs are always canonical, sokat_xwing::draft_11_vectorsand the differential test still pass unchanged.qa_r2_02_non_canonical_x25519_public_key_is_refusedpasses. Builder tests:binding::low_order_x25519_public_key_is_refusednow expects the 9 non-canonical low-order encodings (7 with bit 255 set, plus p and p+1) to be refused at parse and the 5 canonical ones at use. A newbinding::the_canonical_boundary_is_exactly_pchecks the boundary: p-1 accepted, p refused, and a value below p whose first byte is 0xff accepted.ct_Xis deliberately not checked this way: its raw bytes are bound by the combiner (A-04), so an alias only gives a different secret.Re R2-03 (#49904): fixed in
6780abc. The signature is nowexpand<N, K>(prk, label: &'static [u8], field: &[u8; K]), with exactly one label and one fixed-width field. Itsinfois injective by construction: the labels are prefix-free (A-07), so an equalinfoimplies an equal label and therefore an equal field. The old["ab","c"]vs["a","bc"]call can no longer be written. The bytes did not change: it is stilllabel || field, andgolden_v1passes without regenerating anything. Test change, with the reason: your A-08 part (1) asserted the raw-concatenation collision, which the new signature cannot express. It now pins the helper toHKDF-Expand(prk, label || field)computed independently withhkdf, for the PSK and seal-key cases. Parts (2) and A-09 are unchanged apart from the call syntax.Re R2-04 (#49905): fixed in
6780abc, documented in96086be.SecretKey::generate,exchange::initiate,exchange::respondandseal::sealeach say thatrngmust be the OS RNG (getrandom/OsRng) or a CSPRNG seeded from it once per process, never a fixed, derived or configured seed. They also say thatCryptoRngis only a marker.docs/01_arcanum.mdnow has rules for consumers. via-core and via run the samecargo tree -e features,normalcheck. They take no directml-kem,x25519-dalekorx-wingdependency, banned indeny.toml, because ml-kem 0.3.4'sencapsulate_deterministicis public regardless of its feature. They also grep forfrom_seed(outsidetests/.Re R2-05 (#49906): fixed in
6780abc. (1)impl ZeroizeOnDrop for Initiation<'_>is in place, anda28_secret_types_are_zeroize_on_dropnow also assertsInitiation. (2)seal_innerkeeps its output buffer inZeroizinguntil the plaintext in it has been encrypted, and then moves the buffer out withmem::take(no copy). TheMessageTooLongearly return now wipes the plaintext copy.zeroize-probestill passes (1/1).Builder: R2-01 to R2-05 addressed. Head
96086be(fixes in6780abc, docs in96086be; replies on #49902-#49906).96086becargo test(debug)cargo test --releasezeroize-probe(--test-threads=1)cargo clippy --all-targets --all-features -D warnings,--no-default-features, probe cratecargo fmt --checkcargo deny check(0.20.2)advisories ok, bans ok, licenses ok, sources okcargo audit(0.23.0)cargo fuzz, libFuzzer + ASan, Windows MSVC, built from96086beThe golden v1 vectors did not change: the narrowed
expandkeeps the v1 encoding byte for byte.I changed two of QA's tests, giving the reason in the replies: the A-33
encapsulatecase becameexchange::respond, and A-08 part (1) now pins the newexpandsignature to the v1 encoding. I added one builder test,binding::the_canonical_boundary_is_exactly_p, and updatedbinding::low_order_x25519_public_key_is_refusedfor R2-02.Not merged, not tagged.
Merged and released by the owner session.
mainis now2fae9ad(merge --no-ffoffeature/arcanumat9f8d116, which is96086beplusHANDOVER.md), andv0.1.0is an annotated tag on it.git rev-parse HEAD origin/mainprinted the same hash.Re-run on a fresh clone at
96086be: 82 passed, 0 failed, 0 ignored in debug and release; clippy, fmt, deny and audit clean; zeroize probe 1 passed; fuzzuntrusted_input631 s, 172,694 executions, 0 crashes (ASan).Mutation checks: R2-02 (skip the canonical check) fails its test. R2-01 (
encapsulateandas_bytespublic again) fails its test. Ungatingas_bytesalone does not, correctly, because nothing in the release API produces aSharedSecret. The test only reaches the secret throughencapsulate, notdecapsulate, which is a minor gap.Gitea's manual-merge detection is off for this repository, so this PR is closed by hand. The tag is not signed: whether releases go through Artifex is still open with Mark. Not audited.
Pull request closed