Repository navigation
Description
Why
We vendor `libs/x25519` (c64-x25519) so that X25519 can be developed separately and c64-https picks up its improvements. In practice every shipped product still links the in-tree `src/crypto/{x25519,fe25519}.s`, and the two copies have drifted apart.
#242 shows what that costs. c64-x25519 found and fixed the `fe_reduce_wide` carry bug (a `cpx` clobbering the propagated carry) after its v0.1.0. The in-tree copy never got that fix. It shipped in all three products and failed about 2.6% of handshakes, until PR #244 patched the copy by hand. Every future sibling fix or speedup will miss us the same way until we link the sibling.
Current blocker (CLAUDE.md, Known issues; measured at pin v0.16.0)
`USE_X25519_SIBLING=1` links under neither backend:
- ip65: `X25519_RODATA` overflows `CRYPTO_OVERLAY` by 3,840 B. The real shortfall is 5,376 B, because ld65 warns only on the first segment to overflow a region.
- UCI: `X25519_BSS` overflows `CRYPTO_OVERLAY` by 1,536 B, a side effect of `CERT_BUF_BSS` moving there for wikipedia.
The duplicate `reu_mul_tables_init` symbol is already handled by `CONTRACT_DEFINES` deferral (`-D SHARED_REU_MUL_INIT -D SHARED_REU_MUL_FETCH`), so what remains is space.
Options to evaluate
-
UCI first. It is 1,536 B of BSS, not code. Try placing `X25519_BSS` in `CRYPTO_COLD_SHADOW` or `NET_BSS_TAIL`, or unioning it with a buffer whose lifetime is disjoint (X25519 runs before certificate processing, so `cert_buf` may qualify, as feat(cfg): ip65 refit — un-break BACKEND=ip65 via cert_buf/verify-scratch union #68 did for ip65's SCRATCH_UNION). Both shipped UCI products could switch before ip65 does.
-
ip65. 5,376 B is more than the whole ip65 pool has free. It needs one or more of:
- a smaller sibling variant, if c64-x25519 offers or could offer one (tables in REU, or computed rather than stored; ask upstream what a no-REU, low-footprint build costs);
- moving the tables into REU, which is not possible on the ip65-onchip product: stock C64, no REU;
- freeing space elsewhere.
If none of these works, ip65 stays on the in-tree copy for now, but under the drift guard below.
-
Drift guard until then. Run the sibling's KAT/differential vectors against the in-tree copy in our test suite, so an upstream fix that we lack shows up as a red test here rather than a field failure. Add the Intermittent UCI handshake stall after a good connect: tls_state=3, read_seq=0, ~707 B consumed, ring empty, net_last_error=$00 #242 vectors (the captured scalar and the `@prop3` case from PR fix(crypto): fe_reduce_wide dropped its final-fold carry past byte 2 — wrong X25519 key_share (#242) #244's `tools/test_x25519.py` groups) to c64-x25519's own suite too.
Done when
- Both UCI products link the sibling, and `tools/test_x25519.py`, the RFC 7748 vectors (including the iterated one) and the Intermittent UCI handshake stall after a good connect: tls_state=3, read_seq=0, ~707 B consumed, ring empty, net_last_error=$00 #242 vectors pass against it in VICE. Hardware handshakes pass on the exact PRG hashes.
- ip65 either links the sibling too, or carries the drift guard with a documented reason.
- `src/crypto/{x25519,fe25519}.s` is deleted, or reduced to the ip65 fallback only.
🤖 Generated with Claude Code
Activity
JC-000 commentedon Sep 24, 2026
More evidence for the switch: c64-x25519 already had both of the fixes that PR #244 had to hand-port.
fe_reduce_wideusesinx/dey/bnecascades there. Thefe25519_mul_a24byte-31 fold is commit2760bcc(2026-08-28, "audit A1, L32"), first tagged v0.12.0, and it is already inside our v0.16.0 pin. So we have been pinning a library with the fix while shipping the copy without it. The a24 bug is peer-triggerable: a crafted server key share faults every handshake. That makes this denial of service, not merely a random 2.6% failure rate.Link the libs/x25519 sibling on every profile; retire in-tree X25519 (#…
Merge pull request #251 from JC-000/feat/245-x25519-sibling