From d1b3e4ad26d6d07370cf2989650a70639cf2b981 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Sun, 6 Sep 2026 21:33:37 -0500 Subject: [PATCH 01/14] chore(deps): bump libs/nistcurves v0.11.2 -> v0.14.0, and place the growth v0.13.0 carries the fail-closed fix for the defect we reported upstream (c64-nist-curves#148): the Lim-Lee comb accepted an unusable anchor-table slot and ecdsa_verify returned VALID on the collapsed u1*G = O case. c64-https-uci-comb.prg is a shipped product on that path (LIB_NISTCURVES_REU_BANKS_USED = $0004, measured). Keep the scope exact. The guard catches a COLLAPSED anchor table, not a CORRUPT one. An attacker who can write REU bank 2 plants a valid point instead, reaches a forged R with Z != 0 throughout, and no post-condition on the result would see it. This is not a defence against that attacker. v0.12.0 adds the SPEC 8.2 REU DMA settle across thirteen sites, and that is where the bytes went: LIB_NISTCURVES_MUL_CODE 123 -> 162 (+39, nistcurves_reu_dma_wait) LIB_NISTCURVES_P256_CODE 8304 -> 8362 (+58 onchip; +82 REU; +100 comb) ABI 2 -> 4 (v0.13.0 gave ec_scalar_mul a carry return; v0.14.0 fixed reu_fetch_mul_row to take the row index in A per 8.2). Neither hop reaches our call surface: we never jsr ec_scalar_mul into the library (src/crypto/ecdsa_verify.s defines its own shim) and we never call the fetch. src/crypto/ecdsa_verify.s needs no change -- it asserts MAJOR = 0 and MINOR >= 9, both still true. PLACEMENT. Measured, literal ld65, against the five configurations: uci-onchip 'LIB_NISTCURVES_P256_RODATA' overflows 'CRYPTO_HOT' by 22 bytes uci REU default same segment, same region, by 59 bytes uci-comb links (CRYPTO_HOT 93 free) ip65 REU default links (CRYPTO_RESIDENT 29 free) The fix routes LIB_NISTCURVES_P256_RODATA -- 192 B of curve/mod constants -- from CRYPTO_HOT to CRYPTO_OVERLAY in cfg/c64-https-uci.cfg. One line, one cfg, no source change, and cfg/c64-https-uci-onchip.cfg has routed the same segment the same way since the comb profile existed, so the shipped comb image is untouched. CRYPTO_OVERLAY is plain resident RAM at $4200-$5FFF under UCI with ~2 KB free in both affected profiles, it is where LIB_NISTCURVES_MUL_CODE already lives, and rodata there is subject to nothing the cold-shadow zero-fill does. Post-fix CRYPTO_HOT margins: 170 B uci-onchip, 133 B uci REU default. Rejected: moving LIB_NISTCURVES_MUL_CODE instead (it is not the segment that overflows under UCI, and it already lives in CRYPTO_OVERLAY there); and enlarging CRYPTO_HOT, which cannot grow past $A000 without landing under boot's zbss zero-fill. ip65-onchip is NOT fixed by this commit and still fails to link ('LIB_NISTCURVES_MUL_CODE' overflows 'CRYPTO_RESIDENT' by 57 bytes). It needs a decision outside a pin bump -- see the PR body. Suites, both matching their pre-bump baseline: tools/test_ecdsa_kat_oracle.py 6/6 (3 valid accepted, 3 invalid rejected) tools/test_x25519.py 73/73 Co-Authored-By: Claude Opus 5 (1M context) --- cfg/c64-https-uci.cfg | 27 +++++++++++++++++-- libs/nistcurves | 2 +- src/lib_contract_asserts.s | 53 ++++++++++++++++++++++++++++++-------- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/cfg/c64-https-uci.cfg b/cfg/c64-https-uci.cfg index 6ad9107f..7c8d962c 100644 --- a/cfg/c64-https-uci.cfg +++ b/cfg/c64-https-uci.cfg @@ -61,7 +61,9 @@ # Under EMBED_P256_OVERLAY=1: routed via # OVERLAY_BLOB_P256 to the live overlay # slot at boot. -# LIB_NISTCURVES_P256_RODATA - curve256, mod256 constants. CRYPTO_HOT. +# LIB_NISTCURVES_P256_RODATA - curve256, mod256 constants. CRYPTO_OVERLAY +# from the v0.14.0 pin (was CRYPTO_HOT) — +# see the routing line near the bottom. # LIB_NISTCURVES_P256_BSS - data_p256 working buffers. NET_BSS_TAIL # (NOT CRYPTO_HOT — see the routing line # near the bottom of this file and the @@ -399,7 +401,28 @@ SEGMENTS { # from this same archive), not by re-routing the segments at # link time. LIB_NISTCURVES_P256_CODE: load = CRYPTO_HOT, type = ro, optional = yes; - LIB_NISTCURVES_P256_RODATA: load = CRYPTO_HOT, type = ro, optional = yes; + # CRYPTO_OVERLAY, not CRYPTO_HOT, from the libs/nistcurves v0.14.0 pin. + # v0.12.0's SPEC 8.2 REU DMA settle added 58 B to LIB_NISTCURVES_P256_CODE + # (thirteen `jsr nistcurves_reu_dma_wait` sites) against 36 B of free + # CRYPTO_HOT, so the link failed here: + # + # ld65: Warning: cfg/c64-https-uci.cfg(NNN): Segment + # 'LIB_NISTCURVES_P256_RODATA' overflows memory area + # 'CRYPTO_HOT' by 22 bytes + # + # (NNN is CRYPTO_HOT's own MEMORY line, not this one — ld65 names the + # region's declaration. Do not paste a line number here; the comment + # you are reading moves it.) + # + # — 22 B under USE_NISTCURVES_ONCHIP=1 and 59 B under the default REU + # profile, which shares this cfg. Moving the 192 B of curve/mod + # constants into CRYPTO_OVERLAY (~2 KB free in both profiles) buys back + # far more than the deficit and costs the hot region nothing at runtime: + # CRYPTO_OVERLAY is plain resident RAM at $4200-$5FFF under UCI, it is + # where LIB_NISTCURVES_MUL_CODE already lives, and cfg/c64-https-uci-onchip.cfg + # has routed this same segment there since the comb profile existed. + # It is rodata, so nothing about the cold-shadow zero-fill applies. + LIB_NISTCURVES_P256_RODATA: load = CRYPTO_OVERLAY, type = ro, optional = yes; # P-256 BSS is 1,312 B (fp256/mod256/points256 scratch + ecdsa256 # input/output staging + data_p256 working buffers). Stays in # NET_BSS_TAIL under the W1 hot/cold split — CRYPTO_COLD_SHADOW diff --git a/libs/nistcurves b/libs/nistcurves index 58f4cf53..c05ead66 160000 --- a/libs/nistcurves +++ b/libs/nistcurves @@ -1 +1 @@ -Subproject commit 58f4cf53b28eb35c4872c93b9b6d799d031ff892 +Subproject commit c05ead664e4611544696a683a16c57396a777913 diff --git a/src/lib_contract_asserts.s b/src/lib_contract_asserts.s index 5874b9a9..d77da2ae 100644 --- a/src/lib_contract_asserts.s +++ b/src/lib_contract_asserts.s @@ -162,12 +162,30 @@ APP_OWNED = LIB_SHARED_PRIMITIVES_SQTAB | LIB_SHARED_PRIMITIVES_REU_MUL | LIB_SH ; on MINOR bumps, so MAJOR carries no signal. ; ; nistcurves shipped 0 from v0.3.0 through v0.8.0, bumped to 1 at v0.9.0 -; (17 exported symbols REMOVED, c64-nist-curves #90/#91), and to 2 at -; v0.10.0 (the lib-contract phase-3 namespace wave, c64-nist-curves #103). +; (17 exported symbols REMOVED, c64-nist-curves #90/#91), to 2 at v0.10.0 +; (the lib-contract phase-3 namespace wave, c64-nist-curves #103), to 3 at +; v0.13.0 (`ec_scalar_mul` gained a carry return, part of the #148 +; fail-closed fix) and to 4 at v0.14.0 (#153: `reu_fetch_mul_row` takes the +; row index in A, which §8.2 had documented all along — what changed is +; upstream's conformance to it, which is why upstream ruled it MINOR). ; If a submodule bump makes this assert fire, that is the gate working: ; re-check the integration against the new export surface, then update the ; expected value on the next line — do not delete the assert. ; +; THE 2 -> 4 RE-CHECK (v0.11.2 -> v0.14.0). NEITHER hop reaches c64-https's +; call surface, and both were checked rather than assumed: +; +; ec_scalar_mul's carry return — we never `jsr ec_scalar_mul` into the +; library. src/crypto/ecdsa_verify.s defines its own shim (compiled out +; under comb; dead code under the two non-comb builds, whose ECDSA_NO_COMB +; archives do not import it), and v0.13.0's new carry check sits inside +; the library's own `.ifndef ECDSA_NO_COMB`. +; +; reu_fetch_mul_row's A-on-entry convention — c64-https never calls it. +; `git grep 'jsr reu_fetch_mul_row'` over the v0.14.0 sources finds one +; site, src/fp384.asm:697, which the archive build never assembles. +; src/boot.s owns the c64-https copy under SPEC §8.2 deferral. +; ; THE v0.9.1 -> v0.10.1 RE-CHECK, so the next person can audit the audit ; rather than re-run it blind. Method: `git diff v0.9.1 v0.10.1 -- src/` ; filtered to `.export`/`.exportzp` lines, cross-checked against every @@ -187,20 +205,33 @@ APP_OWNED = LIB_SHARED_PRIMITIVES_SQTAB | LIB_SHARED_PRIMITIVES_REU_MUL | LIB_SH ; Everything else in the wave is ADDITIVE at the default gate: the §6.5 ; rename window (#107) adds canonical `nistcurves_zp_*` / ; `nistcurves_mul_*` names while KEEPING the bare forms as same-address -; aliases, export-gated behind -D LIB_NO_BARE_EXPORTS=1. c64-https links -; ungated, so `mul_dma_lo` / `mul_dma_hi` / `mul_cached_a` / -; `mul_src2_buf` — which src/data.s provides and boot.s imports — are -; untouched. The functional surface c64-https actually consumes is the -; same four symbols as at v0.9.1: ec_base_x, ec_gx256, ec_scalar_mul_var, -; ecdsa_verify_256, all still exported. +; aliases, export-gated behind -D LIB_NO_BARE_EXPORTS=1. That sentence +; used to end "c64-https links ungated, so mul_dma_lo / mul_dma_hi / +; mul_cached_a / mul_src2_buf are untouched" — WE DO NOT LINK UNGATED, +; and have not since the wrapper started passing the flag (the very next +; paragraph depends on it). src/data.s owns those four buffers precisely +; BECAUSE the archive's copies are suppressed. The functional surface +; c64-https actually consumes is the same four symbols as at v0.9.1: +; ec_base_x, ec_gx256, ec_scalar_mul_var, ecdsa_verify_256, all still +; exported. ; ; One INPUT-side break is real and was migrated: `-D zp_ptr2=$3d` in ; tools/integration/build_nistcurves_p256.sh now hard-errors, because ; the bare alias assignment is no longer `.ifndef`-guarded. The override ; is spelled `-D nistcurves_zp_ptr2=$3d` from this pin; the wrapper's ; od65 post-check was retargeted to the canonical name so it cannot go -; vacuous. See that script's ZP_OVERRIDES block. -; PREFIXED FORM, from the v0.11.2 pin. The wrapper builds the archive with +; vacuous. (The ZP_OVERRIDES array this used to cite is gone — the +; overrides ride CONTRACT_ZP_DEFINES now; read the check_zp_slot calls.) +; +; The SECOND leg of that post-check — "no member re-exports the bare +; zp_ptr2" — DID go vacuous at v0.14.0, which is the cautionary tale. +; #154 moved the bare aliases out of zp_config*.o into their own archived +; TU (zp_aliases*.o) for §6.1 member isolation, so the member the guard +; read could no longer carry the alias whether or not the suppression +; flag took effect, and it passed by reading the wrong object. It now +; scans every member of the archive, which cannot be re-homed out from +; under it. +; PREFIXED FORM, from the v0.11.2 pin onward. The wrapper builds the archive with ; `-D LIB_NO_BARE_EXPORTS=1` (SPEC §6.5) — which is what lets src/data.s ; keep its own adopter-private mul_dma_* buffers without colliding — so the ; bare `LIB_ABI_VERSION` is no longer exported and importing it fails as an @@ -208,7 +239,7 @@ APP_OWNED = LIB_SHARED_PRIMITIVES_SQTAB | LIB_SHARED_PRIMITIVES_REU_MUL | LIB_SH ; anticipated; it arrived via the bare-export gate rather than via a second ; contract library entering the link. .import LIB_NISTCURVES_ABI_VERSION -.assert LIB_NISTCURVES_ABI_VERSION = 2, lderror, "libs/nistcurves: exported-surface generation changed (LIB_NISTCURVES_ABI_VERSION != 2) — re-check the integration, then bump the expected value in src/lib_contract_asserts.s" +.assert LIB_NISTCURVES_ABI_VERSION = 4, lderror, "libs/nistcurves: exported-surface generation changed (LIB_NISTCURVES_ABI_VERSION != 4) — re-check the integration, then bump the expected value in src/lib_contract_asserts.s" ; ===================================================================== From ace14522e1ca653e5d57b818976a3cd7400d7061 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Sun, 6 Sep 2026 21:33:57 -0500 Subject: [PATCH 02/14] fix(integration): the bare-export guard went vacuous at v0.14.0 -- rescope it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tools/integration/build_nistcurves_p256.sh proves LIB_NO_BARE_EXPORTS=1 reached the archive by od65-ing the discovered zp_config*.o member for an export of the bare `zp_ptr2`. libs/nistcurves v0.14.0 (upstream #154, SPEC 6.1 member isolation) moved the deprecated bare aliases out of zp_config.s into src/zp_aliases.s -> member zp_aliases_p256verify.o / _p256comb.o. From that pin, zp_config*.o exports no bare alias WHETHER OR NOT the flag took effect: the guard passed by reading an object that could no longer fail. That matters because this failure has NO link error. CLAUDE.md records the mechanism: a member built with a different knob string re-exports names the rest of the archive suppressed, one artifact carrying two configurations, dormant until a second contract library enters the link. Retargeted at every member of the archive rather than at the new member name, so the next re-homing cannot repeat this. Members are read from upstream's build directory exactly as the ZP slot checks already do -- listing an archive and reading the objects it names is not extraction, so 6.1 stays clean. A member the archive names but that is absent is a hard error, and a zero-member scan is a hard error, because a guard that silently scans nothing is the very shape being fixed. RED-GREEN, measured in this worktree at the v0.14.0 pin: GREEN, as shipped: $ bash tools/integration/build_nistcurves_p256.sh onchip [p256/onchip] ZP overrides verified in zp_config_p256verify.o; bare zp_* suppressed across 18 members rc=0 RED, same script with ` -D LIB_NO_BARE_EXPORTS=1` stripped from CONTRACT_DEFINES: ERROR: these archive members re-export the bare 'zp_ptr2' — LIB_NO_BARE_EXPORTS did not reach them: zp_aliases_p256verify.o One archive must carry one configuration (SPEC 6.2). rc=1 VACUITY of the old guard, on that same un-suppressed archive: $ od65 --dump-exports libs/nistcurves/build/zp_config_p256verify.o \ | grep -c '"zp_ptr2"' 0 <- old guard passes $ od65 --dump-exports libs/nistcurves/build/zp_aliases_p256verify.o \ | grep '"zp_ptr2"' Name: "zp_ptr2" The ZP_MEMBER discovery itself survives the pin unchanged: `ar65 t | grep '^zp_config'` still matches exactly one member, since zp_aliases_*.o does not share the prefix. Also in this file, since both are the same staleness: the pinned-version string in the c64-https#124 preflight diagnostic is now RESOLVED from the gitlink with `git describe --tags --exact-match` instead of carrying a hand-edited literal (it still said v0.11.2 -- a wrong version inside a message aimed at version staleness), and the ">= v0.11.2" floor block now lists the v0.12.0/v0.13.0/v0.14.0 reasons, including the #148 scope caveat. Co-Authored-By: Claude Opus 5 (1M context) --- tools/integration/build_nistcurves_p256.sh | 101 ++++++++++++++++++--- 1 file changed, 89 insertions(+), 12 deletions(-) diff --git a/tools/integration/build_nistcurves_p256.sh b/tools/integration/build_nistcurves_p256.sh index 3ac1fc5e..3f8b32bc 100755 --- a/tools/integration/build_nistcurves_p256.sh +++ b/tools/integration/build_nistcurves_p256.sh @@ -141,17 +141,25 @@ AR65="${AR65:-ar65}" # # Probing for those two says exactly what the next 200 lines depend on, and # keeps saying it correctly if upstream renames a tag under us. It is -# deliberately NOT the full requirement — CLAUDE.md records >= v0.11.2 for -# reasons this cannot see (v0.11.1's on-chip SHARED_CT_MUL_8X8 fix, v0.11.2's -# knob-staleness guard, both of which fail later and elsewhere). This gate -# exists to convert one specific illegible failure into a remedy, not to -# certify the pin. +# deliberately NOT the full requirement — CLAUDE.md records >= v0.14.0 for +# reasons this cannot see (the list is at the CONTRACT_DEFINES block below; +# every one of them fails later and elsewhere, and one of them does not fail +# at all — it changes what a signature check accepts). This gate exists to +# convert one specific illegible failure into a remedy, not to certify the +# pin. lib_preflight_fail() { local what="$1" local head; head="$(git -C "$LIB_DIR" rev-parse HEAD 2>/dev/null || true)" local found; found="$(git -C "$LIB_DIR" describe --tags --always 2>/dev/null || echo '')" local pin; pin="$(git -C "$PROJECT_ROOT" ls-tree HEAD libs/nistcurves 2>/dev/null | awk '{print $3}')" local diagnosis + # The tag for the PINNED sha, resolved rather than hardcoded: this line + # used to carry a literal "(v0.11.2)" that had to be edited by hand at + # every pin bump, and a wrong version in a diagnostic aimed at a + # version-staleness failure is worse than no version at all. Empty when + # the checkout cannot resolve it (which is itself one of the states this + # message is printed in), and the sha still identifies the pin. + local pintag; pintag="$(git -C "$LIB_DIR" describe --tags --exact-match "$pin" 2>/dev/null || true)" if [ -z "$head" ]; then diagnosis="The submodule is not checked out at all." elif [ "$head" != "$pin" ]; then @@ -170,7 +178,7 @@ ERROR: libs/nistcurves checkout is unusable for this build (c64-https#124). $what submodule checkout : $found - this repo pins : ${pin:0:12}${pin:+ (v0.11.2)} + this repo pins : ${pin:0:12}${pintag:+ ($pintag)} $diagnosis Fix it with: @@ -282,13 +290,41 @@ grep -q 'CONTRACT_ZP_DEFINES' "$LIB_DIR/Makefile" \ # and silently yields a WRONG # address with no diagnostic. # -# Requires libs/nistcurves >= v0.11.2: +# Requires libs/nistcurves >= v0.14.0: # v0.11.1 made SHARED_CT_MUL_8X8 assemble against the on-chip TU # (c64-nist-curves#123) — before that this needed a glue TU. # v0.11.2 added the knob-staleness guard: a changed CONTRACT_DEFINES used # to reuse stale objects and exit 0 with a DIFFERENT archive than # requested. That silent no-op is why an earlier attempt at this # change produced a comb image that would not boot. +# v0.12.0 added the SPEC §8.2 REU DMA settle (`nistcurves_reu_dma_wait`) +# across thirteen sites — a completion confirm plus a settle loop +# between a DMA and the next REU register write. +# v0.13.0 (c64-nist-curves#148) made the Lim-Lee comb FAIL CLOSED on an +# unusable anchor-table slot. Before it, `ecdsa_verify` accepted +# the collapsed u1·G = O case — a signature forgery, and +# c64-https-uci-comb.prg is a shipped product on that path +# (LIB_NISTCURVES_REU_BANKS_USED = $0004). Read the scope +# exactly: the guard catches a COLLAPSED anchor table, not a +# CORRUPT one. An attacker who can write REU bank 2 plants a +# valid point instead, reaches a forged R with Z != 0 throughout, +# and no post-condition on the result would see it. Upstream is +# emphatic about that distinction; do not widen the claim. +# v0.13.0 (c64-nist-curves#153) also fixed `reu_fetch_mul_row` to take the +# row index in A, as §8.2 had always documented; through v0.13.0 +# it read a library-private cached byte and ignored A entirely. +# That plus v0.13.0's `ec_scalar_mul` carry return is why +# LIB_NISTCURVES_ABI_VERSION moved 2 -> 4 (see the assert in +# src/lib_contract_asserts.s). Neither hop reaches our call +# surface: we never `jsr ec_scalar_mul` into the library, and we +# do not call the fetch. +# v0.14.0 (c64-nist-curves#154) moved the deprecated bare `zp_*` aliases +# out of `zp_config*.o` into their own archived TU +# (`zp_aliases*.o`), for SPEC §6.1 member isolation. The +# bare-export scan in section 2 below depends on this pin's +# member layout — and, more to the point, was VACUOUS against it +# until retargeted, because the member it used to read can no +# longer carry a bare alias whether or not the flag took. CONTRACT_DEFINES="-D SHARED_SQTAB_INIT -D SHARED_REU_MUL_INIT -D SHARED_REU_MUL_FETCH -D SHARED_CT_MUL_8X8 -D LIB_NO_BARE_EXPORTS=1 -D LIB_SHARED_SQTAB_BASE=0xBC00" # ZP-slot overrides go in the SEPARATE variable, not the one above: SPEC §6.2 # splits them because a globally-delivered slot define collides with every @@ -375,14 +411,55 @@ check_zp_slot nistcurves_zp_ptr2 0x0000003D check_zp_slot fp_mul_i 0x00000039 check_zp_slot fp_mul_j 0x0000003A -# The suppression gate must have reached this TU too — that is the whole -# point of routing the overrides through CONTRACT_ZP_DEFINES. -if "${OD65:-od65}" --dump-exports "$LIB_BUILD/$ZP_MEMBER" | grep -q '"zp_ptr2"'; then - echo "ERROR: $ZP_MEMBER re-exports the bare 'zp_ptr2' — LIB_NO_BARE_EXPORTS did not reach it." >&2 +# The suppression gate must have reached the archive too — that is the whole +# point of routing the overrides through CONTRACT_ZP_DEFINES rather than +# rebuilding one member with a different knob string. +# +# THIS SCAN COVERS EVERY MEMBER, and that is a correction, not thoroughness +# for its own sake. It used to od65 "$ZP_MEMBER" alone, which was right while +# the bare `zp_*` aliases were exported from zp_config.s. libs/nistcurves +# v0.14.0 moved them into their own translation unit (src/zp_aliases.s -> +# member zp_aliases_p256verify.o / _p256comb.o, upstream issue #154, SPEC +# §6.1 member isolation), so from that pin `zp_config*.o` exports no bare +# alias WHETHER OR NOT the suppression flag took effect and the old guard was +# vacuous — it passed by reading an object that could no longer fail. +# +# Naming the new member instead would put the guard back in the same trap the +# next time upstream re-homes an alias. Scanning the archive's whole member +# list cannot go vacuous that way: wherever a bare export lands, it is in some +# member of the archive we are about to link, and the loop names the member in +# the error so the report is no less specific than the old one. +# +# Members are read from upstream's build directory, exactly as the ZP check +# above does — listing an archive and reading the objects it names is not +# extraction, so SPEC §6.1 stays clean. A member the archive names but that is +# absent is a hard error, never a skipped iteration: a guard that silently +# scans nothing is the failure mode this whole block exists to close, and a +# wrong ZP slot has NO link error (it corrupts cert parsing at runtime). +BARE_OFFENDERS="" +SCANNED=0 +for m in $( "$AR65" t "$UPSTREAM_ARCHIVE" ); do + if [ ! -f "$LIB_BUILD/$m" ]; then + echo "ERROR: member '$m' named by $(basename "$UPSTREAM_ARCHIVE") but absent from $LIB_BUILD;" >&2 + echo " the bare-export scan cannot be completed and must not pass vacuously." >&2 + exit 1 + fi + SCANNED=$((SCANNED + 1)) + if "${OD65:-od65}" --dump-exports "$LIB_BUILD/$m" | grep -q '"zp_ptr2"'; then + BARE_OFFENDERS="$BARE_OFFENDERS $m" + fi +done +if [ "$SCANNED" -eq 0 ]; then + echo "ERROR: $(basename "$UPSTREAM_ARCHIVE") lists no members — nothing was scanned for bare zp_* exports." >&2 + exit 1 +fi +if [ -n "$BARE_OFFENDERS" ]; then + echo "ERROR: these archive members re-export the bare 'zp_ptr2' —" >&2 + echo " LIB_NO_BARE_EXPORTS did not reach them:$BARE_OFFENDERS" >&2 echo " One archive must carry one configuration (SPEC 6.2)." >&2 exit 1 fi -echo "[p256/$PROFILE] ZP overrides verified in $ZP_MEMBER; bare zp_* suppressed" +echo "[p256/$PROFILE] ZP overrides verified in $ZP_MEMBER; bare zp_* suppressed across $SCANNED members" cp "$UPSTREAM_ARCHIVE" "$ARCHIVE" From 7648173c33f287b54cc737646b0206d7b8e23318 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Sun, 6 Sep 2026 21:34:11 -0500 Subject: [PATCH 03/14] docs(claude.md): re-anchor at the v0.14.0 pin, and correct three measured margins Pin prose: the >= v0.11.2 build rule and the `libs/nistcurves@v0.11.2` line in Crypto ABI move to v0.14.0, with the new floor reasons pointed at the CONTRACT_DEFINES block that actually lists them. Adds the ABI = 4 fact and the #148 comb fail-closed fix, the latter with its scope stated exactly: it catches a COLLAPSED anchor table, not a CORRUPT one, and is no defence against an attacker who can write REU bank 2. Three margins this file carried were wrong, all measured here: CRYPTO_HOT under UCI claimed 81 B, is per-profile: 170 / 93 / 133 at v0.14.0 (36 / 193 / 23 at v0.11.2, so the 81 was already stale -- issue #193) comb CRYPTO_OVERLAY tail claimed ~223 B, is 120 B (159 at v0.11.2) ip65 free blocks claimed ~170-186 B NET_CODE and 16 B LOADER, are 56 B (beyond the 20 B the default target strings use) and 21 B The ip65 paragraph also gains the fact that makes its headroom arithmetic decidable: CRYPTO_OVERLAY ($4F8C-$5FFF) and CRYPTO_RESIDENT ($6000-$9FFF) are ADJACENT, so they are one 20,596 B pool and shuffling segments between them creates nothing. That is why the contiguous-region restructure is worth only the 22 B of boundary fragmentation, and why "route the library segment elsewhere" is not a general answer on ip65: the other free blocks are NET_CODE's tail, which is the HTTPS_HOST/HTTPS_PATH budget, and the smallest segment in the pool is 169 B. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 62 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 9bd6a9cf..c1a9e9f8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -43,10 +43,14 @@ Fresh clone (ip65 backend; UCI needs none of the ip65 steps): - To test blob provenance, **flip a byte** — never move the blob aside. `make` regenerates it deterministically, reproducing the baseline hash, which reads exactly like a live trap. That false positive has been hit. - - **`libs/nistcurves` must be >= v0.11.2** (`CONTRACT_ZP_DEFINES`, - knob-staleness guard). A stale checkout is caught in ~0.05 s by a - source probe in `tools/integration/build_nistcurves_p256.sh` (#124); - `tools/check_upstream_pins.py --worktree` reports checkout-vs-gitlink. + - **`libs/nistcurves` must be >= v0.14.0** (`CONTRACT_ZP_DEFINES`, + knob-staleness guard, the §8.2 REU DMA settle, the #148 comb + fail-closed fix, and the §6.1 `zp_aliases*.o` split the wrapper's + bare-export guard is written against — full list in the + `CONTRACT_DEFINES` block of `tools/integration/build_nistcurves_p256.sh`). + A stale checkout is caught in ~0.05 s by a source probe in that same + script (#124); `tools/check_upstream_pins.py --worktree` reports + checkout-vs-gitlink. **A flag change no longer needs `make clean` (#159).** make tracks source mtimes, not the command line, so this used to be a discipline you only had @@ -172,7 +176,7 @@ fixed buffers in crypto BSS. ChaCha20-Poly1305 in-tree, permanent: `chacha20_encrypt`, `poly1305_init/update/final`, `aead_encrypt/decrypt` SHA-256 in-tree: `sha256_init/update/final` - ECDSA P-256 sibling `libs/nistcurves@v0.11.2`: + ECDSA P-256 sibling `libs/nistcurves@v0.14.0`: `ecdsa_verify_256`, `ec_scalar_mul_var` (plus the `ec_base_x`, `ec_gx256` data — that is the whole surface we import). Dispatcher: @@ -183,6 +187,22 @@ fixed buffers in crypto BSS. range + on-curve check); c64-https does none of its own, and `Q` comes straight from the attacker-supplied certificate, so `ecdsa_verify.s` carries `.assert LIB_NISTCURVES_VERSION_MINOR >= 9`. + - `LIB_NISTCURVES_ABI_VERSION` is **4** from the v0.14.0 pin and + `src/lib_contract_asserts.s` pins it. Two hops from the 2 that stood + at v0.11.2 — v0.13.0 gave `ec_scalar_mul` a carry return, v0.14.0 + fixed `reu_fetch_mul_row` to take the row index in A as §8.2 always + said — and NEITHER reaches our call surface: we never `jsr + ec_scalar_mul` into the library (`ecdsa_verify.s` defines its own + shim) and we never call the fetch. The counter moving is the gate + telling you to check, not a break. + - v0.13.0 (upstream #148, reported from here) made the Lim-Lee comb + fail closed on an unusable anchor-table slot; before it, + `ecdsa_verify` accepted the collapsed u1·G = O case. That is a real + forgery and `c64-https-uci-comb.prg` shipped on that path. Keep the + scope exact: it catches a **collapsed** anchor table, not a + **corrupt** one. Anyone who can write REU bank 2 plants a valid + point, reaches a forged R with Z != 0 throughout, and no + post-condition on the result sees it. - Zero page: fe25519 `$2C-$37`, x25519 `$38-$3A`, ECDSA bignum `$22-$3C`, time-shared; sibling slots `fp_mul_i=$39`, `fp_mul_j=$3A`, `nistcurves_zp_ptr2=$3D` (verify in `build/labels.txt`). All defined @@ -476,9 +496,14 @@ already refused a step later, as `DF_ERR_TYPE = $04`). Test: (server-name validation took the comb tail from 714 to 223 B and broke `rig_https_wiki.py`, which now drives the menu instead). The harness write guard raises `MemoryPolicyError` before the wire. - - `CRYPTO_HOT` margin under UCI is **81 B** at v0.9.1+ and was one byte at - v0.6.0; 288 B of that was a one-off dead-data recovery upstream. Watch - it on every pin bump. + - `CRYPTO_HOT` margin under UCI is **per profile, and the one number this + file used to carry (81 B) was wrong by more than half.** Measured at the + v0.14.0 pin: **170 B** uci-onchip, **93 B** uci-comb, 133 B on the + unshipped REU default. At v0.11.2 it was 36 / 193 / 23 — so the 81 B + was already stale before this bump (#193), and the onchip figure only + grew because `LIB_NISTCURVES_P256_RODATA` moved to `CRYPTO_OVERLAY` in + `cfg/c64-https-uci.cfg` to absorb v0.12.0's +58 B of settle call sites. + Watch it on every pin bump, and measure all three. - `http_recv_response`: `Content-Length` (single-SP matcher, 16-bit sentinel `$FFFF`) and chunked (`http_state_body_chunked`, `HTTP_AUX_CODE`; chunks >64 KB desync) supported; body rendered via @@ -515,7 +540,7 @@ Model: `T(f) = D + C/f`. The REU profile has a ~42-56 s floor (row-fetch DMA anchored to the ~1 MHz bus, ~16 KB per `fp_mul`); onchip has none but ~1.9x the CPU work; comb halves the CPU work again but needs REU bank 2 and a boot precompute. **Read the pin, not the commit** — almost every -figure was taken at `libs/nistcurves` v0.6.0; the pin is v0.11.2 and the +figure was taken at `libs/nistcurves` v0.6.0; the pin is v0.14.0 and the only re-measured points are 48 MHz UCI REU (80.8 → 82.1 → 82.4 s, n=1; the +1.6% is v0.7.0's public-key validation, worth paying) and comb. @@ -607,7 +632,10 @@ UCI (`cfg/c64-https-uci.cfg`, W1 hot/cold split — the reference): build: TLS_DEFRAME_CODE (~1.4 KB), CERT_BUF_BSS (2,048 B), HTTPS_TARGET_RODATA, x509_name; comb adds RODATA/LIMLEE_BSS - (~223 B tail free). Also the slot for the + (**120 B** tail free measured at the + v0.14.0 pin — the ~223 B this file used + to claim was stale, it was 159 B at + v0.11.2). Also the slot for the (broken) overlay-embed flags. $6000-$9FFF CRYPTO_HOT resident code + rodata + small BSS $A000-$BFFF CRYPTO_COLD_SHADOW large BSS (RAM under BASIC ROM, $01=$36); @@ -633,9 +661,17 @@ ip65 (`cfg/c64-https-ip65.cfg`): capped so growth is a link error) $C000-$CFFF TCP_BUF 4 KB ring for the ip65 callback -ip65 is essentially full: largest free block ~170-186 B (NET_CODE tail), -40 B CRYPTO_RESIDENT, 22 B CRYPTO_OVERLAY, 16 B LOADER. PRG size is not a -headroom gauge. A contiguous-region cfg restructure is a known TODO. +ip65 is essentially full. Measured at the v0.11.2 pin: 56 B NET_CODE tail +(on top of the 20 B the default target strings already use), 40 B +CRYPTO_RESIDENT, 22 B CRYPTO_OVERLAY, 21 B LOADER — the "~170-186 B / +16 B LOADER" this file used to carry was stale. PRG size is not a headroom +gauge. **CRYPTO_OVERLAY and CRYPTO_RESIDENT are ADJACENT ($4F8C-$5FFF and +$6000-$9FFF), so they are one pool of 20,596 B, and no amount of shuffling +segments between them creates space** — that is why the contiguous-region +cfg restructure is only worth the 22 B of boundary fragmentation it +recovers. The other two free blocks are not reachable from that pool: +NET_CODE's tail is the `HTTPS_HOST`/`HTTPS_PATH` budget and the smallest +segment in the pool is 169 B. - `LOADER_OVERFLOW` carries ~125 B of `http.s` that outgrew LOADER. - `src/loadaddr.s` (PRG load address) and `src/exports.s` (promotes From 4265ae1eaf454b69e433a4fc437e1a66e6729037 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Sun, 6 Sep 2026 21:50:43 -0500 Subject: [PATCH 04/14] build: hoist ENABLE_P384_VERIFY out of the USE_NISTCURVES_ONCHIP block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The flag's `CA65FLAGS += -D ENABLE_P384_VERIFY=1` was nested inside `ifeq ($(USE_NISTCURVES_ONCHIP),1)`, so the two REU-profile builds — plain `make` and `make BACKEND=uci` — dropped it silently. Setting the flag on those two configurations produced a PRG byte-identical to the unflagged one. Red/green, PRG sha256, at the parent commit: make BACKEND=ip65 d780f719fac82e07bba9d30db804e853 make BACKEND=ip65 ENABLE_P384_VERIFY=1 d780f719fac82e07bba9d30db804e853 make BACKEND=uci 7c79a4e00a19685de7540970247c759a make BACKEND=uci ENABLE_P384_VERIFY=1 7c79a4e00a19685de7540970247c759a After this commit those two armed builds move to cbfd9d9b1155447f and 8b67ee949f8507b8 — the flag now does what it says on every profile. This matters because ENABLE_P384_VERIFY exists solely so the P-384 safety gate can be mutation-tested (CLAUDE.md, "Crypto ABI"). A mutation control that is a no-op on 2 of 5 configurations proves nothing about those two. The three onchip profiles were never affected by the nesting, and their armed PRGs are byte-identical across this move: BACKEND=ip65 USE_NISTCURVES_ONCHIP=1 b9f03169ababe20b (both) BACKEND=uci USE_NISTCURVES_ONCHIP=1 3c2712629063de69 (both) BACKEND=uci USE_NISTCURVES_ONCHIP_COMB=1 cc555c196a8b1673 (both) All five UNARMED PRGs are unchanged by this commit; no shipped image moves. Co-Authored-By: Claude Opus 5 (1M context) (cherry picked from commit f73bbc04d3b746de189caae74f3688a681044498) --- Makefile | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 52d1ff1d..388de09b 100644 --- a/Makefile +++ b/Makefile @@ -233,23 +233,6 @@ $(error USE_NISTCURVES_ONCHIP places LIB_NISTCURVES_MUL_CODE in CRYPTO_OVERLAY - endif CA65FLAGS += -D USE_NISTCURVES_ONCHIP=1 -# ENABLE_P384_VERIFY=1 — re-arms the P-384 verify arm in -# src/crypto/ecdsa_verify.s. OFF BY DEFAULT AND UNSAFE ON ITS OWN. -# -# The arm calls crypto_swap_to_p384_sha384, which DMAs $1E00 bytes from REU -# banks that only reu_p384_overlay_init writes — and that routine is itself -# `.ifdef USE_OVERLAY_P384_EMBED`, which no shipped build sets and which -# cannot currently be built at all (the SHA-384 table overflows OVERLAY_REGION -# by 1,536 B; see "Known issues"). Setting this flag WITHOUT a working overlay -# reproduces the c64-https#128-era hazard on purpose: live resident code -# overwritten, machine hung. -# -# It exists so the guard can be mutation-tested — a safety gate nobody can -# switch off is a gate nobody can prove is load-bearing. Turning it on is -# expected to make tools/test_p384_overlay_hazard.py FAIL. -ifeq ($(ENABLE_P384_VERIFY),1) -CA65FLAGS += -D ENABLE_P384_VERIFY=1 -endif ifeq ($(USE_NISTCURVES_ONCHIP_COMB),1) SIBLING_LIB_ARCHIVES := build/lib/nistcurves-p256-onchip-comb.a CA65FLAGS += -D USE_NISTCURVES_COMB=1 @@ -346,6 +329,38 @@ else CRYPTO_SRCS_EFFECTIVE := $(CRYPTO_SRCS_ALL) endif +# ENABLE_P384_VERIFY=1 — re-arms the P-384 verify arm in +# src/crypto/ecdsa_verify.s. OFF BY DEFAULT AND UNSAFE ON ITS OWN. +# +# The arm calls crypto_swap_to_p384_sha384, which DMAs $1E00 bytes from REU +# banks that only reu_p384_overlay_init writes — and that routine is itself +# `.ifdef USE_OVERLAY_P384_EMBED`, which no shipped build sets and which +# cannot currently be built at all (the SHA-384 table overflows OVERLAY_REGION +# by 1,536 B; see "Known issues"). Setting this flag WITHOUT a working overlay +# reproduces the c64-https#128-era hazard on purpose: live resident code +# overwritten, machine hung. +# +# It exists so the guard can be mutation-tested — a safety gate nobody can +# switch off is a gate nobody can prove is load-bearing. Turning it on is +# expected to make tools/test_p384_overlay_hazard.py FAIL. +# +# TOP LEVEL ON PURPOSE. This block used to sit inside +# `ifeq ($(USE_NISTCURVES_ONCHIP),1)`, so the two REU-profile builds — plain +# `make` and `make BACKEND=uci` — dropped the -D silently and the flag did +# nothing at all. Measured at the previous commit, PRG sha256, ip65 REU +# profile: +# +# make BACKEND=ip65 d780f719fac82e07… +# make BACKEND=ip65 ENABLE_P384_VERIFY=1 d780f719fac82e07… <- identical +# +# and the same for BACKEND=uci (7c79a4e00a19685d… both ways). The mutation +# test that proves this gate is load-bearing was a no-op on two of the five +# configurations. The three onchip profiles were unaffected and their armed +# PRGs are byte-identical across this move. +ifeq ($(ENABLE_P384_VERIFY),1) +CA65FLAGS += -D ENABLE_P384_VERIFY=1 +endif + # Per-backend source + object selection. ifeq ($(BACKEND),ip65) NET_SRCS := $(IP65_SRCS) From 7411673b99bfc8326d829d21641a6a82039e080f Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Sun, 6 Sep 2026 21:50:44 -0500 Subject: [PATCH 05/14] build: link the P-384 objects only under ENABLE_P384_VERIFY ecdsa_verify_384.o was in every shipped image and reachable from none of them. Its sole export, ecdsa_verify_384_tls, is imported only from inside ecdsa_verify.s's `.ifdef ENABLE_P384_VERIFY`; ca65 emits no import record for an unreferenced .import, so the object was pulled in purely because the wildcard named it on the ld65 command line. Deadness evidence (not read off the source gate): - od65 --dump-imports build/crypto/ecdsa_verify.o does not list ecdsa_verify_384_tls. - The string ecdsa_verify_384_tls appears in ZERO Imports-list entries across all five build/c64-https.map files (ip65-onchip, uci-onchip, uci-comb, plain ip65, plain uci). - Its own imports (crypto_swap_to_p384_{sha384,curve}, ecdsa_pubkey_{x,y}_384, tls_rec_buf, tls_transcript) all come from objects linked for other reasons, so dropping it resolves nothing away. - ec_scalar_mul_384_shim lives in the P-384 CURVE ARCHIVE, which the main link never names; it is unaffected. - p384_force_link.s was already inert (`.ifdef USE_NISTCURVES_P384`, undefined today) and contributes 0 B either way. Recovered, per build (PRG sha256 before -> after): ip65-onchip ba2be108 -> 7b953a8e CRYPTO_OVERLAY 22 -> 321 B free CRYPTO_RESIDENT 40 -> 73 B free uci-onchip 5f9e9fb9 -> f0a85c18 NET_CODE 67 -> 366 B free CRYPTO_HOT 36 -> 69 B free uci-comb c4234760 -> 4a184fdb NET_CODE 67 -> 366 B free CRYPTO_OVERLAY 159 -> 192 B free plain-ip65 d780f719 -> 0a85a1ff CRYPTO_OVERLAY 22 -> 321 B free CRYPTO_RESIDENT 150 -> 183 B free plain-uci 7c79a4e0 -> 18c26f5b NET_CODE 67 -> 366 B free CRYPTO_HOT 23 -> 56 B free plus 2 B of BSS in each (the cold-shadow gap below TABLES_BSS goes 44 -> 46 B). Behaviour is unchanged: the P-384 arm was already a `sec` reject, and it still is. Red/green on the mutation control, uci-onchip, after this commit: ENABLE_P384_VERIFY unset tools/test_p384_overlay_hazard.py exit 0 "0 / 7680 bytes changed, C=1, PASS" ENABLE_P384_VERIFY=1 tools/test_p384_overlay_hazard.py exit 1 "5575 / 7680 changed, DID NOT RETURN (hung)" so the gate is still provably load-bearing. tools/test_tls_p384_negotiation.py is 2/2 before and after; tools/test_ecdsa_p384_kat.py exits 1 with "required artifact missing: build/labels-p384-sha384.txt" before and after (the P-384 overlay build has never completed - see "Known issues"). Co-Authored-By: Claude Opus 5 (1M context) (cherry picked from commit d64067754c96ace0d7367521ef5ab972e2729aad) --- Makefile | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Makefile b/Makefile index 388de09b..191a7ae3 100644 --- a/Makefile +++ b/Makefile @@ -357,8 +357,41 @@ endif # test that proves this gate is load-bearing was a no-op on two of the five # configurations. The three onchip profiles were unaffected and their armed # PRGs are byte-identical across this move. +# +# The two P-384-only objects are gated on the SAME flag, so the lane is one +# switch and not two half-switches: +# +# src/crypto/ecdsa_verify_384.s the TLS-side P-384 dispatcher. Its only +# export is ecdsa_verify_384_tls, and the +# only `.import` of that symbol anywhere is +# the one inside ecdsa_verify.s's +# `.ifdef ENABLE_P384_VERIFY`. ca65 emits no +# import record for an .import nothing +# references, so with the flag off the object +# was linked and UNREACHABLE: it appears in +# no Imports-list entry of any of the five +# build/c64-https.map files, and od65 +# --dump-imports on ecdsa_verify.o does not +# list it. It cost 299 B of CRYPTO_AUX_CODE + +# 33 B of CRYPTO_RODATA + 2 B of BSS in every +# shipped image. +# src/crypto/p384_force_link.s already inert: its entire body is +# `.ifdef USE_NISTCURVES_P384`, and nothing +# defines that symbol today (the CA65FLAGS +# line for it is commented out below). Zero +# bytes either way; gated here so the lane's +# file set lives in one place. +# +# What this does NOT do: it does not delete the P-384 lane. Both files stay in +# tree, as does every other piece of P-384 plumbing, on the same policy the +# retired EMBED_P256_OVERLAY follows. `ENABLE_P384_VERIFY=1` restores the +# previous link line; the three onchip profiles' armed PRGs are byte-identical +# to the pre-gating ones (b9f03169…, 3c271262…, cc555c19…). +P384_SRCS := src/crypto/ecdsa_verify_384.s src/crypto/p384_force_link.s ifeq ($(ENABLE_P384_VERIFY),1) CA65FLAGS += -D ENABLE_P384_VERIFY=1 +else +CRYPTO_SRCS_EFFECTIVE := $(filter-out $(P384_SRCS),$(CRYPTO_SRCS_EFFECTIVE)) endif # Per-backend source + object selection. From c092f2cc259516eb9a4180a1a1caea3eeea9292c Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 05:46:29 -0500 Subject: [PATCH 06/14] build(ip65): converge HTTP_AUX_CODE2 onto CRYPTO_OVERLAY ip65 was the odd one out. cfg/c64-https-uci.cfg:252 and cfg/c64-https-uci-onchip.cfg:297 have always routed HTTP_AUX_CODE2 to CRYPTO_OVERLAY, next to the HTTP_AUX_CODE slice it was split off from; only cfg/c64-https-ip65.cfg sent it to the CRYPTO_RESIDENT tail. Its own comment gave the reason: "CRYPTO_OVERLAY cannot hold the whole W4 machinery on ip65". That precondition is gone. Gating the unreachable P-384 objects out of the link (previous commit) returned 299 B of CRYPTO_AUX_CODE + 33 B of CRYPTO_RODATA to every image, and CRYPTO_OVERLAY on ip65 now has room for the 169 B slice. So this is not a new trade-off being taken; it retires a workaround whose cause has been removed, and leaves all three cfgs agreeing on where the W4 helper slice lives. Measured on the integrated branch (ip65-onchip, BACKEND=ip65 USE_NISTCURVES_ONCHIP=1): CRYPTO_OVERLAY $4F8C-$5FFF top $5F67 152 B free CRYPTO_RESIDENT $6000-$9FFF top $9F6E 145 B free Without this move the same build overflows CRYPTO_RESIDENT by 57 B at the libs/nistcurves v0.14.0 pin; with it, both regions link with margin. The stale comment is replaced with what is now true. Co-Authored-By: Claude Opus 5 (1M context) --- cfg/c64-https-ip65.cfg | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cfg/c64-https-ip65.cfg b/cfg/c64-https-ip65.cfg index 7944f90d..3e966dc1 100644 --- a/cfg/c64-https-ip65.cfg +++ b/cfg/c64-https-ip65.cfg @@ -226,9 +226,12 @@ SEGMENTS { # LOADER is packed on ip65 (8 B free); under UCI it rides LOADER. HTTP_AUX_CODE: load = CRYPTO_OVERLAY, type = ro, optional = yes; # jsr-only helper slice split out of HTTP_AUX_CODE (body_begin / - # done_check / hex_digit): CRYPTO_OVERLAY cannot hold the whole W4 - # machinery on ip65, so this slice rides the CRYPTO_RESIDENT tail. - HTTP_AUX_CODE2: load = CRYPTO_RESIDENT, type = ro, optional = yes; + # done_check / hex_digit). It rode the CRYPTO_RESIDENT tail while + # CRYPTO_OVERLAY could not hold the whole W4 machinery on ip65; gating + # the unreachable P-384 object out of the link retired that constraint, + # so it now sits with HTTP_AUX_CODE — the placement cfg/c64-https-uci.cfg + # and cfg/c64-https-uci-onchip.cfg have always used. + HTTP_AUX_CODE2: load = CRYPTO_OVERLAY, type = ro, optional = yes; CRYPTO_CODE: load = CRYPTO_RESIDENT, type = ro; CRYPTO_RODATA: load = CRYPTO_RESIDENT, type = ro; # libs/nistcurves segment names (c64-lib-contract / cfa9085+). From e33041107b26ec84b4c3ab984a6032c87c567400 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 05:49:01 -0500 Subject: [PATCH 07/14] docs(claude.md): record the P-384 link gate and the new ip65 margins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three things changed under this file's feet: - ENABLE_P384_VERIFY now applies on all five profiles (it was nested inside the USE_NISTCURVES_ONCHIP block and silently dropped by the two REU builds), and it is now the ONLY thing that links src/crypto/ecdsa_verify_384.s and src/crypto/p384_force_link.s. The entry gains that command, because it is the one build that can still catch a P-384 symbol going away — and a warning that assembling the file proves nothing: `.import` of an undefined symbol is a LINK-time error in ca65, so `ca65 src/crypto/ecdsa_verify_384.s` succeeds with every import unresolved. - The Crypto ABI section records what gating costs: exactly two symbols, crypto_swap_to_p384_sha384 and crypto_swap_to_p384_curve, lose their only link-time consumer. Read off the Imports list of all five build/c64-https.map files, not estimated. Both are still exported unconditionally by crypto_swap.s and still occupy bytes. - The ip65 headroom paragraph is re-measured at the v0.14.0 pin with the gate and the HTTP_AUX_CODE2 move in place: 152 B CRYPTO_OVERLAY, 145 B CRYPTO_RESIDENT, 56 B NET_CODE tail, 21 B LOADER, 43 B below TABLES_BSS. The adjacency argument it already carried is what settled the bump, so it now says so: 20,631 B of content against 20,596 B of pool, 35 B short however the segments are arranged. The ip65 memory map also gains HTTP_AUX_CODE + HTTP_AUX_CODE2 in CRYPTO_OVERLAY's tenant list. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 59 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index c1a9e9f8..3b5646ef 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -138,7 +138,20 @@ Variables: the slot by 1,536 B. - `ENABLE_P384_VERIFY=1` — re-arms the P-384 verify arm. **Unsafe on its own** (overwrites live code — see Crypto ABI); exists so - `tools/test_p384_overlay_hazard.py` can be mutation-tested. + `tools/test_p384_overlay_hazard.py` can be mutation-tested. It is also + the **only** thing that links `src/crypto/ecdsa_verify_384.s` and + `src/crypto/p384_force_link.s` at all, so it is the one command that + keeps `ecdsa_verify_384.s` honest: + + make BACKEND=uci USE_NISTCURVES_ONCHIP=1 ENABLE_P384_VERIFY=1 + + **Assembling that file is worthless as coverage**: `.import` of a + symbol nothing defines is a LINK-time error in ca65, not an + assemble-time one, so `ca65 src/crypto/ecdsa_verify_384.s` succeeds + with every one of its imports unresolved. Only the armed link finds a + P-384 symbol that has gone away. The flag applies on all five profiles + since the hoist out of the `USE_NISTCURVES_ONCHIP` block — it used to + be silently dropped by the two REU-profile builds. - `HTTPS_HOST` / `HTTPS_PATH` / `HTTPS_SNI` / `HTTPS_PORT` / `HTTPS_BODY_TO_REU=1` — build-time target. Hosts >63 chars are a build error. The strings live in their own `HTTPS_TARGET_RODATA` segment @@ -231,6 +244,19 @@ The curve comes from the certificate, so the gate is what makes the advertisement change safe. No P-384 build target has ever completed (see Known issues); fix the build before re-wiring. +The lane is now gated at the **link line** as well as in the source: +`ecdsa_verify_384.o` used to be in every shipped image and reachable from +none of them (ca65 emits no import record for an `.import` nothing +references, so the wildcard pulled it in), costing 299 B of +`CRYPTO_AUX_CODE` + 33 B of `CRYPTO_RODATA` everywhere. Both P-384-only +objects now link only under `ENABLE_P384_VERIFY=1`. Measured consequence: +exactly two symbols lose their only link-time consumer — +`crypto_swap_to_p384_sha384` and `crypto_swap_to_p384_curve`. They are +still exported unconditionally by `src/crypto/shared/crypto_swap.s` and +still occupy bytes; nothing imports them in any of the five unarmed +builds. That is the whole surface change, and it is measured from the +`Imports list` of all five `build/c64-https.map` files, not estimated. + Sibling-library memory requirements: code + rodata in `CRYPTO_HOT` / `CRYPTO_RESIDENT` ($6000-$9FFF), never crossing $A000 (boot zeroes $A000-$BFFF); big BSS in `CRYPTO_COLD_SHADOW`; segments named per contract @@ -653,7 +679,8 @@ ip65 (`cfg/c64-https-ip65.cfg`): $2000-$3FFF NET_CODE ip65 blob + LOADER_OVERFLOW + CRYPTO_AUX_CODE2 + HTTPS_TARGET_RODATA $4000-$4F8B NET_BSS blob's BSS (live at runtime, EMPTY to ld65) - $4F8C-$5FFF CRYPTO_OVERLAY 4,212 B: TLS_CODE + CRYPTO_AUX_CODE + $4F8C-$5FFF CRYPTO_OVERLAY 4,212 B: TLS_CODE + CRYPTO_AUX_CODE + + HTTP_AUX_CODE + HTTP_AUX_CODE2 $6000-$9FFF CRYPTO_RESIDENT code + rodata, never crossing $A000 $A000-$BFFF CRYPTO_COLD_SHADOW BSS; `cert_buf` (1,536 B) pinned at $A000 and unioned with LIB_NISTCURVES_P256_BSS @@ -661,17 +688,23 @@ ip65 (`cfg/c64-https-ip65.cfg`): capped so growth is a link error) $C000-$CFFF TCP_BUF 4 KB ring for the ip65 callback -ip65 is essentially full. Measured at the v0.11.2 pin: 56 B NET_CODE tail -(on top of the 20 B the default target strings already use), 40 B -CRYPTO_RESIDENT, 22 B CRYPTO_OVERLAY, 21 B LOADER — the "~170-186 B / -16 B LOADER" this file used to carry was stale. PRG size is not a headroom -gauge. **CRYPTO_OVERLAY and CRYPTO_RESIDENT are ADJACENT ($4F8C-$5FFF and -$6000-$9FFF), so they are one pool of 20,596 B, and no amount of shuffling -segments between them creates space** — that is why the contiguous-region -cfg restructure is only worth the 22 B of boundary fragmentation it -recovers. The other two free blocks are not reachable from that pool: -NET_CODE's tail is the `HTTPS_HOST`/`HTTPS_PATH` budget and the smallest -segment in the pool is 169 B. +ip65 is essentially full. Measured at the v0.14.0 pin, with the P-384 +objects gated out of the link: 56 B NET_CODE tail (on top of the 20 B the +default target strings already use), 145 B CRYPTO_RESIDENT, 152 B +CRYPTO_OVERLAY, 21 B LOADER, and a 43 B hole below TABLES_BSS in +CRYPTO_COLD_SHADOW. PRG size is not a headroom gauge. **CRYPTO_OVERLAY and +CRYPTO_RESIDENT are ADJACENT ($4F8C-$5FFF and $6000-$9FFF), so they are one +pool of 20,596 B, and no amount of shuffling segments between them creates +space** — that is why the contiguous-region cfg restructure is only worth +the boundary fragmentation it recovers. That property is what settled the +v0.14.0 bump: pre-gating content was 20,631 B against 20,596 B of capacity, +35 B short *however* the segments were arranged, so ip65 could not be made +to link by moving anything. Gating the unreachable `ecdsa_verify_384.o` out +(332 B) is what created real space; `HTTP_AUX_CODE2` moving to +CRYPTO_OVERLAY only rebalances the two halves of the pool, and does it to +match what both UCI cfgs already do. The other free blocks are not +reachable from the pool: NET_CODE's tail is the `HTTPS_HOST`/`HTTPS_PATH` +budget and the smallest segment in the pool is 169 B. - `LOADER_OVERFLOW` carries ~125 B of `http.s` that outgrew LOADER. - `src/loadaddr.s` (PRG load address) and `src/exports.s` (promotes From 96fbf33ec0b573dc50f9e88f480f0c7eab2dce9c Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 06:45:14 -0500 Subject: [PATCH 08/14] docs(claude.md): three UCI margins were stale by exactly 33 B b313b5f measured these at the v0.14.0 pin, before the P-384 objects were gated out of the link, and e4fda6d refreshed only the ip65 numbers. The 33 B of CRYPTO_RODATA that gating returned lands in a different region per profile, so the correction is asymmetric: CRYPTO_HOT uci-onchip 170 -> 203 CRYPTO_HOT uci REU default 133 -> 166 CRYPTO_OVERLAY uci-comb 120 -> 153 Comb's CRYPTO_HOT is the one that does NOT move: it stays 93 B, because cfg/c64-https-uci-onchip.cfg already routes CRYPTO_RODATA to CRYPTO_OVERLAY, so comb's 33 B came back there instead. That asymmetry is now stated at both sites rather than left for the next reader to rediscover -- it is the third time in this branch that a per-profile figure has been corrected in one profile and left stale in the others. All three replacements are measured from build/c64-https.map on this branch, not derived from the 33 B. Docs only. No PRG changes; all five profile hashes are unchanged from d7e8592, re-verified after this commit. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 3b5646ef..f29a85bf 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -524,11 +524,15 @@ already refused a step later, as `DF_ERR_TYPE = $04`). Test: write guard raises `MemoryPolicyError` before the wire. - `CRYPTO_HOT` margin under UCI is **per profile, and the one number this file used to carry (81 B) was wrong by more than half.** Measured at the - v0.14.0 pin: **170 B** uci-onchip, **93 B** uci-comb, 133 B on the - unshipped REU default. At v0.11.2 it was 36 / 193 / 23 — so the 81 B - was already stale before this bump (#193), and the onchip figure only - grew because `LIB_NISTCURVES_P256_RODATA` moved to `CRYPTO_OVERLAY` in - `cfg/c64-https-uci.cfg` to absorb v0.12.0's +58 B of settle call sites. + v0.14.0 pin **with the P-384 objects gated out**: **203 B** uci-onchip, + **93 B** uci-comb, 166 B on the unshipped REU default. At v0.11.2 it was + 36 / 193 / 23 — so the 81 B was already stale before this bump (#193). + The onchip figure grew for two independent reasons: + `LIB_NISTCURVES_P256_RODATA` moved to `CRYPTO_OVERLAY` in + `cfg/c64-https-uci.cfg` to absorb v0.12.0's +58 B of settle call sites, + and gating returned 33 B of `CRYPTO_RODATA`. Comb is the exception at + 93 B because its cfg already routes `CRYPTO_RODATA` to `CRYPTO_OVERLAY`, + so its 33 B came back there instead — see the memory map below. Watch it on every pin bump, and measure all three. - `http_recv_response`: `Content-Length` (single-SP matcher, 16-bit sentinel `$FFFF`) and chunked (`http_state_body_chunked`, @@ -658,10 +662,13 @@ UCI (`cfg/c64-https-uci.cfg`, W1 hot/cold split — the reference): build: TLS_DEFRAME_CODE (~1.4 KB), CERT_BUF_BSS (2,048 B), HTTPS_TARGET_RODATA, x509_name; comb adds RODATA/LIMLEE_BSS - (**120 B** tail free measured at the - v0.14.0 pin — the ~223 B this file used - to claim was stale, it was 159 B at - v0.11.2). Also the slot for the + (**153 B** tail free measured at the + v0.14.0 pin with the P-384 objects gated + out; it was 120 B before gating returned + 33 B of CRYPTO_RODATA here, and the + ~223 B this file used to claim was stale + — it was 159 B at v0.11.2). Also the slot + for the (broken) overlay-embed flags. $6000-$9FFF CRYPTO_HOT resident code + rodata + small BSS $A000-$BFFF CRYPTO_COLD_SHADOW large BSS (RAM under BASIC ROM, $01=$36); From 27adc2e7e937cd537a8f0b02e025818bde784a6c Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 06:47:14 -0500 Subject: [PATCH 09/14] docs(claude.md): fix four more margin figures, two self-contradictory An adversarial sweep of EVERY free/margin/hole figure in this file against five measured maps -- rather than only the hunks this branch touched -- found six wrong. 807d5a6 fixed three; these are the other four, two of which made the file contradict itself. Self-contradictions, both now resolved to the measured value: LOADER free on ip65 :307 said 58 B, :683 said 21 B -> 21 B comb CRYPTO_OVERLAY :511 said 223 B, :650 said 120 B -> 153 B Six hundred lines apart in a file every session reads start to finish, and a file that contradicts itself is worse than one uniformly stale: it makes whichever number you happened to read feel confirmed. Both sites now say which is current and point at the Memory layout section, and the 58 B and 223 B are kept as dated history rather than deleted, since both were true when written (#142 and the server-name-validation episode respectively). Plain staleness: smallest segment in the ip65 pool 169 B -> 162 B 169 B is HTTP_AUX_CODE2. The smallest is LIB_NISTCURVES_MUL_CODE at 162 B, read off build/c64-https.map. The conservation conclusion is unaffected -- 162 > 56, so the NET_CODE tail still cannot absorb the smallest pool segment -- but the number naming it was wrong, and this is the sentence a future restructure would lean on. Also: :517's "at v0.11.2 it was 36 / 193 / 23" is CORRECT and stays. It was flagged as unverifiable because the v0.11.2 pin is no longer reachable from this branch (it fails the branch's own ABI assert). It is measurable on master at 48657f5, where the baseline lane measured exactly those three values before this work began, so the line now says where to check it. A figure that cannot be re-derived from the tree that carries it needs its provenance written down, not removing. Docs only. `git diff --name-only` is CLAUDE.md alone; no PRG changes, and all five profile hashes are re-verified unchanged from d7e8592 after this commit. Not squashed into d7e8592 or earlier, so the two in-flight e2e runs remain valid. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f29a85bf..143e5b0b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -308,10 +308,13 @@ drops a symbol fails the link by name on both backends. Surface: `net_dhcp` (alias), and `net_print_ip` — IP printing is consumer UI and is now `print_local_ip` in `boot.s`, one copy for both backends. - Byte accounting on ip65 (the tight one): LOADER went from 16 B free to - 58 B; `print_local_ip` rides LOADER_OVERFLOW, so the NET_CODE tail that - is `HTTPS_HOST`/`HTTPS_PATH`'s ip65 budget shrank from 170 to ~60 B - beyond the default strings (wikipedia's +46 B still builds on both ip65 - profiles; the theoretical 165 B host+path maximum no longer does). + 58 B **at the time of #142**; it is **21 B** at the v0.14.0 pin, which + is the number the Memory layout section carries and the one to use. + `print_local_ip` rides LOADER_OVERFLOW, so the NET_CODE tail that is + `HTTPS_HOST`/`HTTPS_PATH`'s ip65 budget shrank from 170 to ~60 B beyond + the default strings (56 B measured; wikipedia's +46 B still builds on + both ip65 profiles, with 14 B to spare — verified at this pin; the + theoretical 165 B host+path maximum no longer does). - `src/net/ip65/` — ip65/RR-Net (cs8900a). Blob loaded at $2000 via `.incbin`; `net.s` is the adapter; `ip65_symbols.inc` is the single @@ -520,13 +523,19 @@ already refused a step later, as `DF_ERR_TYPE = $04`). Test: - **CRYPTO_OVERLAY vs rig scratch**: new resident tenants in `$4200-$5FFF` shrink what the rigs' `MemoryArbiter` can hand out (server-name validation took the comb tail from 714 to 223 B and broke - `rig_https_wiki.py`, which now drives the menu instead). The harness - write guard raises `MemoryPolicyError` before the wire. + `rig_https_wiki.py`, which now drives the menu instead). Those are the + numbers from that episode; the comb tail is **153 B** at the v0.14.0 + pin — see the memory map below, and never size rig scratch from this + bullet's historical figures. The harness write guard raises + `MemoryPolicyError` before the wire. - `CRYPTO_HOT` margin under UCI is **per profile, and the one number this file used to carry (81 B) was wrong by more than half.** Measured at the v0.14.0 pin **with the P-384 objects gated out**: **203 B** uci-onchip, **93 B** uci-comb, 166 B on the unshipped REU default. At v0.11.2 it was - 36 / 193 / 23 — so the 81 B was already stale before this bump (#193). + 36 / 193 / 23 — measured on master at `48657f5`, which is where to check + it: the v0.11.2 pin is no longer reachable from this branch (it fails the + branch's own ABI assert). So the 81 B was already stale before this bump + (#193). The onchip figure grew for two independent reasons: `LIB_NISTCURVES_P256_RODATA` moved to `CRYPTO_OVERLAY` in `cfg/c64-https-uci.cfg` to absorb v0.12.0's +58 B of settle call sites, @@ -711,7 +720,8 @@ to link by moving anything. Gating the unreachable `ecdsa_verify_384.o` out CRYPTO_OVERLAY only rebalances the two halves of the pool, and does it to match what both UCI cfgs already do. The other free blocks are not reachable from the pool: NET_CODE's tail is the `HTTPS_HOST`/`HTTPS_PATH` -budget and the smallest segment in the pool is 169 B. +budget, and the smallest segment in the pool is `LIB_NISTCURVES_MUL_CODE` +at 162 B (not `HTTP_AUX_CODE2`'s 169 B, which this file used to name). - `LOADER_OVERFLOW` carries ~125 B of `http.s` that outgrew LOADER. - `src/loadaddr.s` (PRG load address) and `src/exports.s` (promotes From b918dbb1c63035f25749cc0eb14d06ed65db97d1 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 06:50:18 -0500 Subject: [PATCH 10/14] docs(claude.md): the REU-restore line is a security decision; per-profile hazard Two additions, both from an adversarial review of this branch. 1. PACKAGE_VARIANTS. The file said restoring a REU-profile image is "one line in PACKAGE_VARIANTS", framed purely as curation. Measured LIB_NISTCURVES_REU_BANKS_USED across all five builds: ip65-onchip $0000 uci-onchip $0000 uci-comb $0004 plain-ip65 $0003 plain-uci $0003 The shipped onchip products touch no REU bank and uci-comb claims bank 2, which is what the exposure argument for this bump rests on. But the two REU profiles read $0003 -- they DO library REU DMA, so they are exposed to the SPEC 8.2 REU DMA settle fix that libs/nistcurves v0.12.0 added. Restoring that one line therefore restores an image with a security-relevant dependency on the pin, and nothing said so. Now it does. 2. A maintenance hazard on the margin figures themselves. The recurring defect in this file is not that a number goes stale; it is that a number gets corrected in the ONE profile someone was looking at and left stale in the other four. Three instances in this bump alone, two of which left the file contradicting itself hundreds of lines apart -- which is worse than uniform staleness, because the reader who lands on either site sees a file that agrees with itself. The note says to re-measure all five off build/c64-https.map rather than deriving the rest by arithmetic, and gives the worked reason: the deltas are NOT uniform. Gating returned 33 B of CRYPTO_RODATA to CRYPTO_HOT in three profiles but to CRYPTO_OVERLAY in comb, because comb's cfg routes that segment differently -- so an "add 33 everywhere" pass would have been wrong in exactly one place, and that place is the shipped product. Docs only. `git diff --name-only` is CLAUDE.md alone; five hashes re-verified unchanged after this commit. Not squashed. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index 143e5b0b..20c52741 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -704,6 +704,16 @@ ip65 (`cfg/c64-https-ip65.cfg`): capped so growth is a link error) $C000-$CFFF TCP_BUF 4 KB ring for the ip65 callback +**Maintenance hazard for every margin figure below, and in the UCI section +above: they are PER PROFILE, and the recurring failure is that a figure gets +corrected in the profile someone was looking at and left stale in the other +four.** Three instances in the v0.14.0 bump alone, two of which left this +file contradicting itself hundreds of lines apart. When you change a number +here, re-measure it in all five builds off `build/c64-https.map` rather than +deriving the others by arithmetic — the deltas are not uniform, because a +segment recovered in one profile can land in a different region in another +(comb's `CRYPTO_RODATA` is the worked example: see the 33 B note above). + ip65 is essentially full. Measured at the v0.14.0 pin, with the P-384 objects gated out of the link: 56 B NET_CODE tail (on top of the 20 B the default target strings already use), 145 B CRYPTO_RESIDENT, 152 B @@ -745,7 +755,13 @@ between each, matrix in `tools/package/_common.sh`: c64-https-uci-comb.prg turbo + REU, fastest (needs bank 2 + boot precompute) REU-profile images were retired (curation: still fastest below ~18 MHz, -one line in `PACKAGE_VARIANTS` to restore). One product per .d64. The +one line in `PACKAGE_VARIANTS` to restore). **That line is a +security-relevant decision, not just a curation one.** Measured +`LIB_NISTCURVES_REU_BANKS_USED`: `$0000` for both shipped onchip products, +`$0004` for uci-comb, and **`$0003` for the two REU profiles** — they do +library REU DMA, so restoring one restores an image exposed to the +SPEC §8.2 REU DMA settle fix (libs/nistcurves v0.12.0). Check the pin +covers it before adding the line back. One product per .d64. The listener `c64-https-listener.py` is a single self-extracting file with no third-party deps; it needs an `ssl` with TLS 1.3 (macOS `/usr/bin/python3` is LibreSSL and cannot serve this client) and `--selftest` proves the path From 6ab2543d605db0d14b9faa9d504330a9bb70e03e Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 14:26:33 -0500 Subject: [PATCH 11/14] docs(readme): v0.14.0 pin, the P-384 link gate, and the unverified body MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit README was untouched by this branch and carried figures and claims the bump falsifies. All numbers below are measured on this branch's tip with `make clean` between products, read off `build/c64-https.map`. - The nistcurves pin is v0.14.0, not v0.11.2. The comb verify sweep is re-attributed to the v0.11.2 pin, where it was taken. - Free-space table re-measured for all three products. Every cell moved, and not uniformly, so the paragraph under it now says to read them per profile: ip65 CRYPTO_OVERLAY 22 -> 152 B and CRYPTO_RESIDENT 40 -> 145 B, UCI NET_CODE 67 -> 366 B (the 299 B of CRYPTO_AUX_CODE the unreachable P-384 object held), uci-onchip CRYPTO_OVERLAY 2,035 -> 1,804 B (LIB_NISTCURVES_P256_RODATA moved there), uci-comb CRYPTO_HOT 193 -> 93 B. The two CRYPTO_COLD_SHADOW cells also lose a byte: 44 / 1,578 were measured from the last used address, not the first free one, while every other cell in the same table was not. - Label counts: 2,398/2,729/2,864 -> 2,395/2,726/2,859. PRG sizes are unchanged at 47,105 / 62,977 / 62,977, which is the point that section already makes about size not being a measurement. - P-384 is now gated at the link line too (332 B recovered), and ENABLE_P384_VERIFY applies on all five profiles rather than being silently dropped by the REU ones — issue #207. - Restoring a REU-profile image in PACKAGE_VARIANTS is flagged as a security-relevant decision, with the measured LIB_NISTCURVES_REU_BANKS_USED per product ($0000 onchip, $0004 comb, $0003 for the two unshipped REU profiles). The wikipedia claims are corrected rather than softened. The release blurb and the Project Status entry both presented a 125,235 B byte-checked fetch; that does not reproduce on either tree. http_get returns carry=0 / HTTP 200 on bodies tens of kilobytes short of their Content-Length, intermittently — issue #211, which the README now cites in three places, along with #210 for why the rig on that path could not go red on it. The entry also states what has NOT been tested: ip65 against a large body, at any size. The handshake conclusions are left standing; only the body path is in question. Two facts in that block are owned by more than one branch, so they land here as the later branch in the merge order. Documentation only; no source, cfg or Makefile change on top of this branch, so no PRG hash moves. Co-Authored-By: Claude Opus 5 (1M context) --- README.md | 82 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 475118cb..1a18cdac 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,14 @@ An HTTPS client for the Commodore 64 in 6502 assembly. Implements TLS 1.3 over T > **Real-server milestone (2026-08-21/22).** The client now completes TLS 1.3 > handshakes and HTTP GETs against real public servers on the open internet — -> **github.com, browserleaks.com and lwn.net** all return HTTP 200 — and, as a -> demonstration, fetches the full 125 KB **Wikipedia article about the -> Commodore 64** over TLS into a 16 MB REU and scrolls it on the C64's own -> screen. Requires the UCI backend at turbo (comb profile). See the Project -> Status section and the "End-to-end HTTPS status" notes in `CLAUDE.md`. +> **github.com, browserleaks.com and lwn.net** all return HTTP 200. It also +> streams the **Wikipedia article about the Commodore 64** over TLS into a +> 16 MB REU and scrolls it on the C64's own screen — but **that body is not +> verified**: `http_get` intermittently reports success on a truncated body +> (issue #211), so treat the large-body demo as a demo. The handshake result +> is unaffected. Requires the UCI backend at turbo (comb profile). See the +> Project Status section and the "End-to-end HTTPS status" notes in +> `CLAUDE.md`. ## I just want to run it @@ -300,7 +303,7 @@ $4000-$4F8B NET_BSS ip65 blob's BSS (live at runtime; ld65 sees it as EMPTY, so do not read it as headroom) $4F8C-$5FFF CRYPTO_OVERLAY 4,212 B; holds TLS_CODE + CRYPTO_AUX_CODE - + HTTP_AUX_CODE + + HTTP_AUX_CODE + HTTP_AUX_CODE2 $6000-$9FFF CRYPTO_RESIDENT 16 KB code + rodata, incl. the libs/nistcurves P-256 verify path $A000-$BFFF CRYPTO_COLD_SHADOW 8 KB BSS under the BASIC ROM shadow @@ -325,7 +328,8 @@ $4200-$5FFF CRYPTO_OVERLAY 7,680 B, and NOT an empty overlay slot: CERT_BUF_BSS (2,048 B), X509_NAME_CODE, HTTP_SINK_CODE, HTTP_AUX_CODE2, HTTPS_TARGET_RODATA, the nistcurves - mul code, plus VIEWER_CODE (onchip) or + mul code and (from the v0.14.0 pin) its + P-256 rodata, plus VIEWER_CODE (onchip) or the comb rodata + LIMLEE_BSS (comb) $6000-$9FFF CRYPTO_HOT 16 KB code + rodata + UCI_BSS $A000-$BFFF CRYPTO_COLD_SHADOW 8 KB BSS (same tenants as ip65, less @@ -341,21 +345,37 @@ $E000-$FDFF OVERLAY_BLOB_CURVE_RAM P-384 curve overlay blob slot (empty An earlier version of this section called `CRYPTO_OVERLAY` "empty in the shipped build". That was wrong by about two orders of magnitude, and it is the kind of error that invites someone to put 2 KB there. The measured -free space in every region of every shipped product, tail of the last -segment to the end of the region: +free space in every region of every shipped product — first free address to +the end of the region — re-measured off `build/c64-https.map` at the +`libs/nistcurves` **v0.14.0** pin, with the unreachable P-384 objects gated +out of the link: | region | `ip65-onchip` | `uci-onchip` | `uci-comb` | |---|---:|---:|---:| | `LOADER` | 21 B | 148 B | 122 B | -| `NET_CODE` | 56 B | 67 B | 67 B | +| `NET_CODE` | 56 B | 366 B | 366 B | | `NET_BSS_TAIL` | — | 43 B | 43 B | -| `CRYPTO_OVERLAY` | 22 B | 2,035 B | **159 B** | -| `CRYPTO_RESIDENT` / `CRYPTO_HOT` | 40 B | 36 B | 193 B | -| `CRYPTO_COLD_SHADOW` (gap below the `$BA00` `TABLES_BSS` pin) | 44 B | 1,578 B | 1,578 B | - -So ip65 is genuinely full — its largest block is the 56 B `NET_CODE` tail, -which is also the budget a longer `HTTPS_HOST`/`HTTPS_PATH` eats into — and -`uci-comb` has 159 B of overlay tail, not the kilobytes the old text implied. +| `CRYPTO_OVERLAY` | 152 B | 1,804 B | **153 B** | +| `CRYPTO_RESIDENT` / `CRYPTO_HOT` | 145 B | 203 B | 93 B | +| `CRYPTO_COLD_SHADOW` (gap below the `$BA00` `TABLES_BSS` pin) | 43 B | 1,577 B | 1,577 B | + +Every cell moved, and not by a common factor — **read them per profile and +re-measure all three when you change one.** The UCI `NET_CODE` gain is the +299 B of `CRYPTO_AUX_CODE` that `ecdsa_verify_384.o` occupied in every image +while being reachable from none; `uci-onchip`'s overlay lost ground because +`LIB_NISTCURVES_P256_RODATA` moved there to absorb the v0.12.0 REU-settle +call sites, while `uci-comb`'s `CRYPTO_HOT` fell to 93 B because its cfg +already routed `CRYPTO_RODATA` to the overlay, so its share of the recovery +landed there instead. The two `CRYPTO_COLD_SHADOW` cells also lose a byte to +arithmetic: they used to be measured from the last *used* address rather than +the first free one. + +So ip65 is still genuinely full — 152 B is its largest block now, and the +56 B `NET_CODE` tail is still the budget a longer `HTTPS_HOST`/`HTTPS_PATH` +eats into. Note that ip65's `CRYPTO_OVERLAY` and `CRYPTO_RESIDENT` are +**adjacent** ($4F8C-$5FFF and $6000-$9FFF), so they are one 20,596 B pool and +moving segments between them creates nothing; the 332 B this bump recovered by +gating P-384 out of the link is what made the v0.14.0 pin fit at all. `uci-onchip` is the roomy one, and only because it ships neither the comb tables nor the comb rodata. @@ -398,6 +418,14 @@ profile, which was retired from the release lineup; every shipped image passes under Memory Map, and `PACKAGE_VARIANTS` in `tools/package/_common.sh`, which is the single source of truth for the matrix. +Restoring a REU-profile image is one line in `PACKAGE_VARIANTS`, and it is a +**security-relevant** line rather than a curation one. Measured +`LIB_NISTCURVES_REU_BANKS_USED`: `$0000` for both shipped onchip products — +they share one archive and do no library REU DMA — `$0004` for `uci-comb`, and +`$0003` for the two unshipped REU profiles. Only images with a non-zero value +are exposed to the defects a `libs/nistcurves` bump fixes in that path, so +check the pin covers them before adding the line back. + The knobs, all read straight from the Makefile: | variable | effect | @@ -475,15 +503,15 @@ it is supposed to detect. ## Project Status -Current status of the three shipped products (measured 2026-09-05 with cc65 -from Homebrew; `make clean` before each, then `stat` the PRG and +Current status of the three shipped products (re-measured at the +`libs/nistcurves` v0.14.0 pin with cc65 from Homebrew; `make clean` before each, then `stat` the PRG and `grep -c '^al ' build/labels.txt`): | product | PRG | labels | |---|---:|---:| -| `c64-https-ip65-onchip` | 47,105 B | 2,398 | -| `c64-https-uci-onchip` | 62,977 B | 2,729 | -| `c64-https-uci-comb` | 62,977 B | 2,864 | +| `c64-https-ip65-onchip` | 47,105 B | 2,395 | +| `c64-https-uci-onchip` | 62,977 B | 2,726 | +| `c64-https-uci-comb` | 62,977 B | 2,859 | The unshipped default profiles land on the same two PRG sizes (47,105 B / 62,977 B) with fewer labels, which is the point: **the PRG size is not a @@ -516,15 +544,15 @@ Progress: - ip65 on **real RR-Net silicon — a first, 2026-09-05.** An RR-Net (CS8900a) cartridge in a cartridge port, on its own wired 10.0.66.0/24 segment, ran the whole path at **stock 1 MHz with no turbo and no REU**: DHCP (the C64 took the pinned lease, read back from its own `net_local_ip` rather than from the server's lease file), a DNS lookup over the cartridge, a 141-byte ClientHello with the correct SNI on the cable, application data both ways, and **HTTP 200** with the body byte-checked out of `http_resp_buf` and `net_last_error` `$00`. Every check the rig ran passed. They are not all wire checks: the wire assertions that attribute traffic to the cartridge discriminate it by Ethernet source address, the rest read the C64's own memory back over DMA or assert host-side preconditions, and `tests/rig_ip65_rrnet_hw.py` says which is which. **1,979 s (33.0 min)** from `G` to done, n=1 on both sides — faster than the same profile in VICE at honest 1 MHz, and by **at least** the ~8% the raw figures show, because the VICE number predates the current `libs/nistcurves` pin and the newer pin is slower (the first Known Issues bullet below carries both that figure and the pin caveat). Our first measurement of the real cartridge port. The "body never appears on the wire in clear" check passed *conclusively*, because its positive control — the SNI, which genuinely is in the clear in the ClientHello — was found, making that a claim about the wire rather than about the searcher. **Scope:** this is `ip65-onchip` against the bundled local listener. It does not exercise ip65 against a real internet server, it says nothing about the two UCI images, and it does not touch the chain-validation or name-validation caveats above — `ip65-onchip` still does neither. - The same cartridge at **48 MHz turbo, 2026-09-06.** `TURBO_MHZ=48` on the same rig, the same build configuration and the same `G`-to-`CONNECTION CLOSED` boundary: **43.1 s, a 46x speed-up** over the 1 MHz run above. That comparison is like-for-like — same rig, same cartridge, real silicon on both sides — and is a different kind of claim from the VICE comparison in the bullet above, which crosses a `libs/nistcurves` pin and therefore stays a lower bound. The open risk was CS8900a register timing at turbo, which is the reason the rig defaults to stock speed, and it did not materialise: DHCP completed on the automatic attempt with no retries, because ip65's ~15 s budget rides CIA2 timer B and the CIA timers run at real phi2 at every CPU clock (measured, with the negative control that separates that from a CPU still at 1 MHz, in `docs/engineering-notes.md`; reproducer `tools/probe_cia_timer_rate.py`). **24 of 25 checks passed, and the one that failed has to be read before this run is quoted.** `check_tls_connected` samples `tls_state` over DMA, and at 48 MHz the window in which that value exists — between the traffic-key derivation and `tls_close` — fits inside a single poll. So the handshake's completion at turbo is **inference from converging evidence** (HTTP 200 and the exact body out of the C64's own buffer, `TLS HANDSHAKE OK` on screen, application data both ways on the cable) **rather than the direct observation the 1 MHz run had.** It is the weaker of the two results and the check was left red rather than softened; `tests/rig_ip65_rrnet_hw.py` says why, and issue #204 tracks the fix. **Nothing else widens:** still one device, one cartridge, one local listener, the same port-only deviation from the shipped image, and still no server-name validation on ip65. This adds a second clock and no more. - [x] **Real public-internet HTTPS (UCI/comb, turbo)** — github.com, browserleaks.com and lwn.net all return `http_status=200` on real U64E hardware at 48 MHz. Needed three pieces of work over the local-listener path: a streaming handshake-message deframer (`src/tls_deframe.s`) for flights where handshake messages don't align with TLS records; a 2048 B `cert_buf` under UCI so larger real leaves fit; and — the last blocker — clamping the UCI adapter's `SOCKET_READ` request to the receive ring's free space, without which any flight over ~4 KB lost its tail to a ring-wrap drop. Build-time target is `make HTTPS_HOST=` / `HTTPS_PATH=`; the rig is `tools/uci/rig_https_live.py`. -- [x] **Wikipedia article into REU + on-screen viewer (stretch goal, UCI/comb)** — `make HTTPS_HOST=en.wikipedia.org HTTPS_PATH='/w/index.php?title=Commodore_64&action=raw' HTTPS_BODY_TO_REU=1` streams the 125,235 B article body into REU bank 16 (`$10:0000`) and drops into a scroll viewer (`src/viewer.s`, CRSR/SPACE/F1/HOME/Q). Verified on U64E @ 48 MHz, body byte-checked against a host-side reference fetch. Rig: `tools/uci/rig_https_wiki.py`. +- [x] **Wikipedia article into REU + on-screen viewer (stretch goal, UCI/comb) — demonstrated, body NOT verified.** `make HTTPS_HOST=en.wikipedia.org HTTPS_PATH='/w/index.php?title=Commodore_64&action=raw' HTTPS_BODY_TO_REU=1` streams the article body into REU bank 16 (`$10:0000`) and drops into a scroll viewer (`src/viewer.s`, CRSR/SPACE/F1/HOME/Q); the handshake, the GET and the viewer all work on a U64E @ 48 MHz. **What does not hold is the byte count.** This entry used to claim 125,235 B byte-checked against a host-side reference fetch; that does not reproduce on either tree. `http_get` returns `carry=0` with `http_status=200` on bodies tens of kilobytes short of their `Content-Length`, intermittently and not as a function of size — reproduced offline against a local listener with no chunking involved, and seen live at 117,192 / 89,526 / 73,720 B against a same-day 125,703 B `curl` anchor. That is **issue #211**, and until it is closed no large-body fetch on any image should be treated as complete. It survived because the one rig on that path could not go red on a short body (**issue #210**). The defect is in the body path only: the handshake result above is unaffected, and nothing here changes what the client does or does not authenticate. **ip65 has never been tested against a body large enough to show this** — at any size, in fact, beyond the local listener's short one. Rig: `tools/uci/rig_https_wiki.py`. ### Known Issues -- **The handshake is slow, and the ECDSA P-256 verify dominates it.** Every figure here is quoted from the measurement record in `CLAUDE.md`. Except where noted they were taken at the **`libs/nistcurves` v0.6.0 pin**, and the pin is now v0.11.2, so treat them as a baseline rather than as current. The one profile re-measured at the current pin is comb: 46.986 / 24.440 / 16.402 s verify at 16 / 32 / 48 MHz (U64E, n=3, VIC blanking active). End-to-end handshake + GET against the local listener, U64E, master 2ceb5b1: **80.8 s** (REU profile, 48 MHz), **45.5 s** (onchip profile, 48 MHz), **1,157.7 s** (REU, stock 1 MHz). One point of that sweep has been carried forward: 48 MHz REU measures **82.1 s** at v0.9.1 and **82.4 s** at v0.10.1 (n=1 each, so the 0.4% step between them is noise; the 1.6% from v0.6.0 is the FIPS 186-5 public-key validation gate v0.7.0 added). No other clock or profile has been re-measured. On the REU-less stock-C64 path (ip65 + onchip, no REU, honest 1 MHz in VICE) the whole run measured **2,159.7 s = 36.0 min**, of which the verify stretch alone was 1,416.7 s. That is fine for the local listener, which holds the connection open; it exceeds a typical 10-30 s real-world server handshake window. -- **P-384 is parked, and doubly gated — it is not merely "stubbed".** An earlier version of this entry said the dispatcher "advertises `ecdsa_secp384r1_sha384` (0x0503)". It does not, and has not since v0.4.1: `sig_algs_ext_data` in `src/tls_handshake.s` carries exactly one scheme, `ecdsa_secp256r1_sha256` (0x0403), and `src/crypto/ecdsa_verify.s` compiles its P-384 arm to a `sec` reject unless `ENABLE_P384_VERIFY=1`. Both gates matter, because the curve comes from the certificate rather than from what we advertised — that combination is what closed the v0.4.0 hang in which a P-384 certificate made the overlay swap DMA over live resident code. Separately, **no P-384 build target has ever completed**: `make p384-overlay` from a clean tree stops at `No rule to make target 'build/labels.txt'`, and once a main build has produced that file it stops at `Segment 'LIB_NISTCURVES_SHA384_TABLES' overflows memory area 'OVERLAY_REGION' by 1536 bytes`. Certificates requiring P-384 are rejected, not verified. +- **The handshake is slow, and the ECDSA P-256 verify dominates it.** Every figure here is quoted from the measurement record in `CLAUDE.md`. Except where noted they were taken at the **`libs/nistcurves` v0.6.0 pin**, and the pin is now v0.14.0, so treat them as a baseline rather than as current. The one profile re-measured since is comb, at the v0.11.2 pin: 46.986 / 24.440 / 16.402 s verify at 16 / 32 / 48 MHz (U64E, n=3, VIC blanking active). End-to-end handshake + GET against the local listener, U64E, master 2ceb5b1: **80.8 s** (REU profile, 48 MHz), **45.5 s** (onchip profile, 48 MHz), **1,157.7 s** (REU, stock 1 MHz). One point of that sweep has been carried forward: 48 MHz REU measures **82.1 s** at v0.9.1 and **82.4 s** at v0.10.1 (n=1 each, so the 0.4% step between them is noise; the 1.6% from v0.6.0 is the FIPS 186-5 public-key validation gate v0.7.0 added). No other clock or profile has been re-measured. On the REU-less stock-C64 path (ip65 + onchip, no REU, honest 1 MHz in VICE) the whole run measured **2,159.7 s = 36.0 min**, of which the verify stretch alone was 1,416.7 s. That is fine for the local listener, which holds the connection open; it exceeds a typical 10-30 s real-world server handshake window. +- **P-384 is parked, and doubly gated — it is not merely "stubbed".** An earlier version of this entry said the dispatcher "advertises `ecdsa_secp384r1_sha384` (0x0503)". It does not, and has not since v0.4.1: `sig_algs_ext_data` in `src/tls_handshake.s` carries exactly one scheme, `ecdsa_secp256r1_sha256` (0x0403), and `src/crypto/ecdsa_verify.s` compiles its P-384 arm to a `sec` reject unless `ENABLE_P384_VERIFY=1`. Both gates matter, because the curve comes from the certificate rather than from what we advertised — that combination is what closed the v0.4.0 hang in which a P-384 certificate made the overlay swap DMA over live resident code. Separately, **no P-384 build target has ever completed**: `make p384-overlay` from a clean tree stops at `No rule to make target 'build/labels.txt'`, and once a main build has produced that file it stops at `Segment 'LIB_NISTCURVES_SHA384_TABLES' overflows memory area 'OVERLAY_REGION' by 1536 bytes`. Certificates requiring P-384 are rejected, not verified. From the v0.14.0 pin the lane is gated at the **link line** as well: `src/crypto/ecdsa_verify_384.s` and `src/crypto/p384_force_link.s` link only under `ENABLE_P384_VERIFY=1`. They used to be in every shipped image and reachable from none of it — ca65 emits no import record for an `.import` nothing references, so the wildcard pulled them in — at a cost of 332 B (299 B of `CRYPTO_AUX_CODE` + 33 B of `CRYPTO_RODATA`), which is the space that made the v0.14.0 bump fit on ip65 at all. `ENABLE_P384_VERIFY=1` now also applies on all five profiles: it used to be silently dropped by the two REU-profile builds, which is issue #207 — the mutation control that was supposed to fail under it passed vacuously there. - **`USE_X25519_SIBLING=1` links under neither backend, and each backend dies on a different segment.** The duplicate-symbol failure this entry used to record — `ld65: Error: Duplicate external identifier: 'reu_mul_tables_init'`, on **both** backends — was closed by the `libs/nistcurves` v0.10.1 / `libs/x25519` v0.11.0 bump plus a build-time deferral: `tools/integration/build_nistcurves_p256.sh` passes `-D SHARED_REU_MUL_INIT -D SHARED_REU_MUL_FETCH` through `CONTRACT_DEFINES`, so the library gates out its own copy of the SPEC §8.2 `reu_mul` provider that `src/boot.s` supplies itself. (This entry used to describe an archive-surgery workaround — dropping `reu_mul_init.o`. That is gone: the wrapper `cp`s the upstream archive unmodified, which is what §6.1 requires.) What replaced it is a placement problem, not a symbol collision. Measured at the `libs/x25519` **v0.16.0** pin and identical at v0.13.0, `make clean && make ... USE_X25519_SIBLING=1` stops with `Segment 'X25519_BSS' overflows memory area 'CRYPTO_OVERLAY' by 1536 bytes` under UCI and `Segment 'X25519_RODATA' overflows memory area 'CRYPTO_OVERLAY' by 3840 bytes` under ip65 (ip65's overlay slot is 4,212 B against UCI's 7,680 B). **An earlier version of this entry claimed the UCI link succeeded, and quoted 3,584 B for ip65. Both were wrong** — the UCI link has not produced a PRG, and 3,584 was a figure from a tree in which `HTTP_AUX_CODE` was not yet a `CRYPTO_OVERLAY` tenant. **Neither number is a total deficit, either:** ld65 warns once per memory area, at the first segment that tips it over, so everything placed after that segment is uncounted. ip65's real shortfall is **5,376 B**. The derivation, and the wrong explanation that fit the evidence first, are in `docs/engineering-notes.md` under "`USE_X25519_SIBLING=1` overflow — two relink experiments". The flag remains **off by default** and no shipped artifact contains the sibling; the in-tree X25519 in `src/crypto/{x25519,fe25519}.s` is what every release PRG is built from. Flipping the default is not a decision anyone can take on byte grounds today. - **Real-server reach is UCI/comb + turbo only, and has size limits.** The public-internet HTTPS above works on the comb profile at turbo; the stock-C64 ip65 path is far too slow for a real server's connection window (~36 min/handshake). Among real leaves, en.wikipedia.org's 1636 B leaf needs the 2048 B UCI `cert_buf` (fits); anything larger, or a server that ignores `max_fragment_length` and sends >548 B records (e.g. Cloudflare), is out of scope. Cloudflare additionally enforces a ~15 s connect-to-first-request deadline the C64 cannot meet and is deliberately unsupported. -- **The wikipedia stall was a client bug, now fixed.** Historical note for anyone bisecting: TLS flights larger than the ~4 KB UCI receive ring used to stall permanently, because `net_poll` requested a fixed 512 B and its fill loop dropped bytes past the ring's current free space (discarded as "delivered"). Fixed by clamping the `SOCKET_READ` request to ring free space (`src/net/uci/net.s`). It was never a firmware bug; github/browserleaks/lwn flights are under 4 KB and were unaffected. +- **The wikipedia stall was a client bug, now fixed.** Historical note for anyone bisecting: TLS flights larger than the ~4 KB UCI receive ring used to stall permanently, because `net_poll` requested a fixed 512 B and its fill loop dropped bytes past the ring's current free space (discarded as "delivered"). Fixed by clamping the `SOCKET_READ` request to ring free space (`src/net/uci/net.s`). It was never a firmware bug; github/browserleaks/lwn flights are under 4 KB and were unaffected. **That fix is not the end of the large-body story** — the body path still terminates early and reports success, intermittently, on both trees (issue #211). Do not read this bullet as saying large fetches are now sound. - **VICE 3.9** previously appeared to crash on chained HMAC-SHA256 calls (backend-independent — affects the crypto-only test suites), but this was caused by hardcoded port numbers bypassing the test harness port allocator. With proper `ViceInstanceManager` usage (no hardcoded ports), all N=1..10 chained calls succeed reliably. ## Test Automation @@ -756,7 +784,7 @@ python3 tools/uci/rig_http_local.py # HTTP GET against local listener python3 tools/uci/rig_http_live.py # HTTP GET against a real server python3 tools/uci/rig_https_local.py # HTTPS GET (TLS 1.3 + ECDSA-P256) python3 tools/uci/rig_https_live.py # HTTPS against a real public server -python3 tools/uci/rig_https_wiki.py # the 125 KB Wikipedia fetch into the REU +python3 tools/uci/rig_https_wiki.py # the Wikipedia fetch into the REU (body unverified, #211/#210) python3 tools/uci/rig_https_banner.py # the only rig that walks the menu into do_https_get python3 tools/uci/rig_https_print_body.py # wrapper: print the response body python3 tools/uci/rig_https_bad_finished.py # client must ABORT on a forged server Finished From 382d884dcd793fa11ecbc13eff6bf85db6388eda Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 14:43:37 -0500 Subject: [PATCH 12/14] docs(readme): the cold-shadow byte is segment growth, not an old miscount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two corrections to the free-space paragraph, both from adversarial review. Every value in the table above it survived; this is prose. 1. The claimed off-by-one never happened. This commit's parent said the old 44 / 1,578 CRYPTO_COLD_SHADOW cells had been measured from the last used address while the rest of the table was not. They were not: master measured under the same convention as the rest of the table yields 44 / 1,578, so the old cells were right. The byte is real segment growth at the v0.14.0 pin — a 3 B LIB_NISTCURVES_BSS appears and BSS shrinks by 2, walking CRYPTO_BSS's last address $B9D3 -> $B9D4 on ip65 and $B3D5 -> $B3D6 under UCI — which is a fact about the bump and worth stating in its own right. Worth naming what happened here: a correct measurement with a wrong story attached to it, written into the very paragraph that corrects other people's figures. It is the defect this branch documents, committed while documenting it. 2. "Every cell moved, and not by a common factor" was contradicted by the table printed directly above: ip65 LOADER and NET_CODE, uci-onchip LOADER, and both NET_BSS_TAIL cells are unchanged. Replaced with the claim that actually holds (the reasons do not generalise across profiles), and the four static cells are now named — an unchanged number is not evidence that a region was left alone. Documentation only; no PRG hash moves. Co-Authored-By: Claude Opus 5 (1M context) --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1a18cdac..f08dfc3a 100644 --- a/README.md +++ b/README.md @@ -359,16 +359,21 @@ out of the link: | `CRYPTO_RESIDENT` / `CRYPTO_HOT` | 145 B | 203 B | 93 B | | `CRYPTO_COLD_SHADOW` (gap below the `$BA00` `TABLES_BSS` pin) | 43 B | 1,577 B | 1,577 B | -Every cell moved, and not by a common factor — **read them per profile and -re-measure all three when you change one.** The UCI `NET_CODE` gain is the +Where a cell moved it moved for its own reason, and the reasons do not +generalise across profiles — **read them per profile, and re-measure all three +when you change one.** The UCI `NET_CODE` gain is the 299 B of `CRYPTO_AUX_CODE` that `ecdsa_verify_384.o` occupied in every image while being reachable from none; `uci-onchip`'s overlay lost ground because `LIB_NISTCURVES_P256_RODATA` moved there to absorb the v0.12.0 REU-settle call sites, while `uci-comb`'s `CRYPTO_HOT` fell to 93 B because its cfg already routed `CRYPTO_RODATA` to the overlay, so its share of the recovery -landed there instead. The two `CRYPTO_COLD_SHADOW` cells also lose a byte to -arithmetic: they used to be measured from the last *used* address rather than -the first free one. +landed there instead. Four cells did not move at all (`LOADER` and `NET_CODE` +on ip65, `LOADER` on `uci-onchip`, both `NET_BSS_TAIL` cells), which is its own +warning: an unchanged number here is not evidence that a region was left alone. +The single byte off each `CRYPTO_COLD_SHADOW` cell is real segment growth, not +a re-count of the old one — v0.14.0 adds a 3 B `LIB_NISTCURVES_BSS` while `BSS` +shrinks by 2, which walks `CRYPTO_BSS`'s last address from `$B9D3` to `$B9D4` +on ip65 and from `$B3D5` to `$B3D6` under UCI. So ip65 is still genuinely full — 152 B is its largest block now, and the 56 B `NET_CODE` tail is still the budget a longer `HTTPS_HOST`/`HTTPS_PATH` From f9825046683f2d18ca6f01ba9396292d5e4d0af9 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 14:45:17 -0500 Subject: [PATCH 13/14] docs(readme): name the artifacts, and tie the cfg move to this branch Two review findings, both about claims that are true only in a context the README did not state. - The wikipedia entry cited three live body counts and an offline reproduction, all device runs, without naming an image. It now says #211 carries the PRG sha256 of each, and why a commit does not substitute for one. Three products ship from this tree; the three live counts are three different PRGs. - The ip65 memory map's `+ HTTP_AUX_CODE2` is true because this branch's parent moved that segment in cfg/c64-https-ip65.cfg. On the other three branch trees it still rides the CRYPTO_RESIDENT tail, so the line is order-dependent and now says so, and says to read the cfg. Documentation only; no PRG hash moves. Co-Authored-By: Claude Opus 5 (1M context) --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f08dfc3a..c053f797 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,11 @@ $4000-$4F8B NET_BSS ip65 blob's BSS (live at runtime; ld65 sees it as EMPTY, so do not read it as headroom) $4F8C-$5FFF CRYPTO_OVERLAY 4,212 B; holds TLS_CODE + CRYPTO_AUX_CODE - + HTTP_AUX_CODE + HTTP_AUX_CODE2 + + HTTP_AUX_CODE + HTTP_AUX_CODE2 (that + last one rode the CRYPTO_RESIDENT tail + until the v0.14.0 bump moved it here in + cfg/c64-https-ip65.cfg — check the cfg, + not this line, on any other tree) $6000-$9FFF CRYPTO_RESIDENT 16 KB code + rodata, incl. the libs/nistcurves P-256 verify path $A000-$BFFF CRYPTO_COLD_SHADOW 8 KB BSS under the BASIC ROM shadow @@ -549,7 +553,7 @@ Progress: - ip65 on **real RR-Net silicon — a first, 2026-09-05.** An RR-Net (CS8900a) cartridge in a cartridge port, on its own wired 10.0.66.0/24 segment, ran the whole path at **stock 1 MHz with no turbo and no REU**: DHCP (the C64 took the pinned lease, read back from its own `net_local_ip` rather than from the server's lease file), a DNS lookup over the cartridge, a 141-byte ClientHello with the correct SNI on the cable, application data both ways, and **HTTP 200** with the body byte-checked out of `http_resp_buf` and `net_last_error` `$00`. Every check the rig ran passed. They are not all wire checks: the wire assertions that attribute traffic to the cartridge discriminate it by Ethernet source address, the rest read the C64's own memory back over DMA or assert host-side preconditions, and `tests/rig_ip65_rrnet_hw.py` says which is which. **1,979 s (33.0 min)** from `G` to done, n=1 on both sides — faster than the same profile in VICE at honest 1 MHz, and by **at least** the ~8% the raw figures show, because the VICE number predates the current `libs/nistcurves` pin and the newer pin is slower (the first Known Issues bullet below carries both that figure and the pin caveat). Our first measurement of the real cartridge port. The "body never appears on the wire in clear" check passed *conclusively*, because its positive control — the SNI, which genuinely is in the clear in the ClientHello — was found, making that a claim about the wire rather than about the searcher. **Scope:** this is `ip65-onchip` against the bundled local listener. It does not exercise ip65 against a real internet server, it says nothing about the two UCI images, and it does not touch the chain-validation or name-validation caveats above — `ip65-onchip` still does neither. - The same cartridge at **48 MHz turbo, 2026-09-06.** `TURBO_MHZ=48` on the same rig, the same build configuration and the same `G`-to-`CONNECTION CLOSED` boundary: **43.1 s, a 46x speed-up** over the 1 MHz run above. That comparison is like-for-like — same rig, same cartridge, real silicon on both sides — and is a different kind of claim from the VICE comparison in the bullet above, which crosses a `libs/nistcurves` pin and therefore stays a lower bound. The open risk was CS8900a register timing at turbo, which is the reason the rig defaults to stock speed, and it did not materialise: DHCP completed on the automatic attempt with no retries, because ip65's ~15 s budget rides CIA2 timer B and the CIA timers run at real phi2 at every CPU clock (measured, with the negative control that separates that from a CPU still at 1 MHz, in `docs/engineering-notes.md`; reproducer `tools/probe_cia_timer_rate.py`). **24 of 25 checks passed, and the one that failed has to be read before this run is quoted.** `check_tls_connected` samples `tls_state` over DMA, and at 48 MHz the window in which that value exists — between the traffic-key derivation and `tls_close` — fits inside a single poll. So the handshake's completion at turbo is **inference from converging evidence** (HTTP 200 and the exact body out of the C64's own buffer, `TLS HANDSHAKE OK` on screen, application data both ways on the cable) **rather than the direct observation the 1 MHz run had.** It is the weaker of the two results and the check was left red rather than softened; `tests/rig_ip65_rrnet_hw.py` says why, and issue #204 tracks the fix. **Nothing else widens:** still one device, one cartridge, one local listener, the same port-only deviation from the shipped image, and still no server-name validation on ip65. This adds a second clock and no more. - [x] **Real public-internet HTTPS (UCI/comb, turbo)** — github.com, browserleaks.com and lwn.net all return `http_status=200` on real U64E hardware at 48 MHz. Needed three pieces of work over the local-listener path: a streaming handshake-message deframer (`src/tls_deframe.s`) for flights where handshake messages don't align with TLS records; a 2048 B `cert_buf` under UCI so larger real leaves fit; and — the last blocker — clamping the UCI adapter's `SOCKET_READ` request to the receive ring's free space, without which any flight over ~4 KB lost its tail to a ring-wrap drop. Build-time target is `make HTTPS_HOST=` / `HTTPS_PATH=`; the rig is `tools/uci/rig_https_live.py`. -- [x] **Wikipedia article into REU + on-screen viewer (stretch goal, UCI/comb) — demonstrated, body NOT verified.** `make HTTPS_HOST=en.wikipedia.org HTTPS_PATH='/w/index.php?title=Commodore_64&action=raw' HTTPS_BODY_TO_REU=1` streams the article body into REU bank 16 (`$10:0000`) and drops into a scroll viewer (`src/viewer.s`, CRSR/SPACE/F1/HOME/Q); the handshake, the GET and the viewer all work on a U64E @ 48 MHz. **What does not hold is the byte count.** This entry used to claim 125,235 B byte-checked against a host-side reference fetch; that does not reproduce on either tree. `http_get` returns `carry=0` with `http_status=200` on bodies tens of kilobytes short of their `Content-Length`, intermittently and not as a function of size — reproduced offline against a local listener with no chunking involved, and seen live at 117,192 / 89,526 / 73,720 B against a same-day 125,703 B `curl` anchor. That is **issue #211**, and until it is closed no large-body fetch on any image should be treated as complete. It survived because the one rig on that path could not go red on a short body (**issue #210**). The defect is in the body path only: the handshake result above is unaffected, and nothing here changes what the client does or does not authenticate. **ip65 has never been tested against a body large enough to show this** — at any size, in fact, beyond the local listener's short one. Rig: `tools/uci/rig_https_wiki.py`. +- [x] **Wikipedia article into REU + on-screen viewer (stretch goal, UCI/comb) — demonstrated, body NOT verified.** `make HTTPS_HOST=en.wikipedia.org HTTPS_PATH='/w/index.php?title=Commodore_64&action=raw' HTTPS_BODY_TO_REU=1` streams the article body into REU bank 16 (`$10:0000`) and drops into a scroll viewer (`src/viewer.s`, CRSR/SPACE/F1/HOME/Q); the handshake, the GET and the viewer all work on a U64E @ 48 MHz. **What does not hold is the byte count.** This entry used to claim 125,235 B byte-checked against a host-side reference fetch; that does not reproduce on either tree. `http_get` returns `carry=0` with `http_status=200` on bodies tens of kilobytes short of their `Content-Length`, intermittently and not as a function of size — reproduced offline against a local listener with no chunking involved, and seen live at 117,192 / 89,526 / 73,720 B against a same-day 125,703 B `curl` anchor. Those are device runs of three different images and #211 names the PRG sha256 of each, which is what identifies them — a commit stops identifying an image the moment a docs commit lands on top of it. That is **issue #211**, and until it is closed no large-body fetch on any image should be treated as complete. It survived because the one rig on that path could not go red on a short body (**issue #210**). The defect is in the body path only: the handshake result above is unaffected, and nothing here changes what the client does or does not authenticate. **ip65 has never been tested against a body large enough to show this** — at any size, in fact, beyond the local listener's short one. Rig: `tools/uci/rig_https_wiki.py`. ### Known Issues From 999a391c2766c4c26938a2c0bbee3e65dd94f48d Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Mon, 7 Sep 2026 16:12:03 -0500 Subject: [PATCH 14/14] docs(claude.md): the wikipedia body is not byte-verified (#211) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The End-to-end HTTPS status section claimed the 125,235 B article was byte-verified. It does not reproduce on either tree: `http_get` returns carry=0 / http_status=200 on bodies tens of kilobytes short of their Content-Length, intermittently and not as a function of size. Measured offline against a local listener with Content-Length and no chunking (25,557 / 78,293 / 160,000 B at a constant 160,000 B request, plus one run that hung), and live at 117,192 / 89,526 / 73,720 B against a same-day 125,703 B curl anchor. README already carried this correction; CLAUDE.md did not. That asymmetry — a figure fixed where someone was looking and left stale in the canonical file — is the same shape as the six margin figures this branch corrects, and CLAUDE.md is the file read first each session. The handshake and GET results in that paragraph are unaffected; only the body-completeness claim is withdrawn. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 20c52741..e1bf329b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -429,8 +429,17 @@ engineering-notes. **Real servers work** (2026-08-21/22, U64E @ 48 MHz, comb): github.com, browserleaks.com, lwn.net all HTTP 200 (~32-39 s to Finished), and -en.wikipedia.org's C64 article — 125,235 B, chunked, into REU `$10:0000` -via `HTTPS_BODY_TO_REU=1`, byte-verified, shown by `src/viewer.s`. The +en.wikipedia.org's C64 article streamed into REU `$10:0000` via +`HTTPS_BODY_TO_REU=1` and shown by `src/viewer.s` — **handshake and GET +verified, body completeness NOT** (#211). This entry used to claim +125,235 B byte-verified; that does not reproduce on either tree. `http_get` +returns `carry=0`/`http_status=200` on bodies tens of KB short of their +`Content-Length`, intermittently and not as a function of size — measured +offline against a local listener with no chunking, and live at +117,192 / 89,526 / 73,720 B against a same-day 125,703 B anchor. It can also +hang outright. **Do not treat any large-body fetch as complete until #211 +closes**; it went unnoticed because the only rig on that path cannot go red +on a short body (#210). The handshake results above are unaffected. The local-listener handshake works on both backends (UCI at 48 MHz and 1 MHz; ip65 in VICE at honest 1 MHz, ~36 min).