Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 135 additions & 24 deletions CLAUDE.md

Large diffs are not rendered by default.

82 changes: 65 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -346,6 +329,71 @@ 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.
#
# 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.
ifeq ($(BACKEND),ip65)
NET_SRCS := $(IP65_SRCS)
Expand Down
Loading