fe25519: take the carry out by multiplying, not by a left shift of a negative value

fe25519_carry's c << 51, with c negative after fe25519_sub, is
undefined in C99; the nightly's sanitized mesh boot stopped on it
(2026-11-20, run 333), reaching it through CI's signed capsules.
c * 2^51 is the same value. test_fe25519 (16 checks: values that
send a limb negative, and RFC 8032 tests 1 and 2 signed and verified)
runs in make -C v4 test and under ASan+UBSan in sanitize; it failed
first under UBSan at fe25519.c:31:26. Gates pass, POST 990/990.
The acceptance protocol runs before it reaches a PR (ruled: the next
PR, not #198).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-20 14:01:15 +00:00
parent 40e9773885
commit 1990a40f09
7 changed files with 1871 additions and 6 deletions
+22 -3
View File
@@ -31,7 +31,7 @@ HERE := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
SRCS := $(wildcard $(HERE)/src/*.c)
# test_mesh_boot.c is the kernel's boot of the fabric, linked as the hosted product is (its own rule,
# `mesh-boot`, below), not one of the per-width tests.
TESTS := $(filter-out %/test_mesh_boot.c %/test_inference.c %/test_mkf18a.c,$(wildcard $(HERE)/tests/test_*.c))
TESTS := $(filter-out %/test_mesh_boot.c %/test_inference.c %/test_mkf18a.c %/test_fe25519.c,$(wildcard $(HERE)/tests/test_*.c))
# Cell widths to build and verify. 32 is the F18/Zynq case, 64 the aarch64
# host case; see DECOMPOSITION.md D-5.
@@ -357,11 +357,30 @@ $(foreach w,$(WIDTHS),$(foreach t,$(TESTS),$(eval $(call TEST_RULE,$(w),$(t)))))
$(foreach w,$(WIDTHS),$(foreach t,$(TESTS),$(eval $(call RUN_RULE,$(w),$(t)))))
$(foreach w,$(WIDTHS),$(foreach t,$(TESTS),$(eval $(call SAN_RULE,$(w),$(t)))))
sanitize: $(foreach w,$(WIDTHS),$(foreach t,$(TESTS),san-$(w)-$(notdir $(t)))) san-mesh-boot $(foreach w,$(WIDTHS),san-mkf18a-$(w))
sanitize: $(foreach w,$(WIDTHS),$(foreach t,$(TESTS),san-$(w)-$(notdir $(t)))) san-mesh-boot $(foreach w,$(WIDTHS),san-mkf18a-$(w)) san-fe25519
@echo "all v4 tests passed under ASan+UBSan"
.PHONY: $(foreach w,$(WIDTHS),$(foreach t,$(TESTS),run-$(w)-$(notdir $(t)) san-$(w)-$(notdir $(t))))
# THE KERNEL'S FIELD ARITHMETIC (kernel/src/crypto/fe25519.c), the Ed25519 that verifies signed capsules:
# tests/test_fe25519.c, plainly and under ASan+UBSan. Written 2026-11-20 for the nightly's failure that
# day (logs/20261120-fe25519/): the sanitized mesh boot reached it only through CI's signed capsules.
# Without -Wpedantic, as the kernel and mkcapsule build it: its __int128 is not ISO C.
$(BINDIR)/test_fe25519: $(HERE)/tests/test_fe25519.c $(CRYPTO_SRCS) $(HERE)/Makefile
@mkdir -p $(BINDIR)
$(CC) $(CSTD) -Wall -Wextra -Werror $(OPT) -isystem $(ROOT)/kernel/include $(HERE)/tests/test_fe25519.c $(CRYPTO_SRCS) -o $@
$(BINDIR)/san-test_fe25519: $(HERE)/tests/test_fe25519.c $(CRYPTO_SRCS) $(HERE)/Makefile
@mkdir -p $(BINDIR)
$(CC) $(CSTD) -Wall -Wextra -Werror -O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all \
-isystem $(ROOT)/kernel/include $(HERE)/tests/test_fe25519.c $(CRYPTO_SRCS) -o $@
.PHONY: fe25519 san-fe25519
fe25519: $(BINDIR)/test_fe25519
@echo " [fe25519]"
@$(BINDIR)/test_fe25519
san-fe25519: $(BINDIR)/san-test_fe25519
@echo " [ASan+UBSan fe25519]"
@$(BINDIR)/san-test_fe25519
# THE MESH BOOT (system/mesh.c; #189, ENGINE step 4 Phase 1, Task 5b): the kernel's boot of the
# fabric, tested on the host with tests/test_mesh_boot.c as its owner. Linked as the hosted product
# is, with the registry (src/manage.c) and a mesh node's ROM; 64-bit cells, as the capsules are.
@@ -472,7 +491,7 @@ $(foreach w,$(WIDTHS),$(eval $(call F18A_RULE,$(w))))
.PHONY: artifacts
artifacts: $(foreach w,$(WIDTHS),$(BINDIR)/mkf18a-$(w))
test: $(addprefix test-,$(WIDTHS)) mesh-boot mesh-boot-on mesh-boot-noop inference artifacts $(foreach w,$(WIDTHS),mkf18a-$(w))
test: $(addprefix test-,$(WIDTHS)) mesh-boot mesh-boot-on mesh-boot-noop inference artifacts $(foreach w,$(WIDTHS),mkf18a-$(w)) fe25519
@echo "all v4 tests passed"
clean: