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
+3
View File
@@ -0,0 +1,3 @@
fe25519_sub(0, 1) ...
done: v[0]=2251799813685228
exit 0
+10
View File
@@ -0,0 +1,10 @@
cc -std=c99 -Wall -Wextra -Werror -O2 -g -isystem /home/user/LithosAnanke/kernel/include /home/user/LithosAnanke/v4/tests/test_fe25519.c /home/user/LithosAnanke/kernel/src/crypto/ed25519.c /home/user/LithosAnanke/kernel/src/crypto/fe25519.c /home/user/LithosAnanke/kernel/src/crypto/scalar25519.c /home/user/LithosAnanke/kernel/src/crypto/sha512.c -o /home/user/LithosAnanke/v4/build/test_fe25519
[fe25519]
fe25519: the field mod 2^255-19
16 checks, 0 failures
cc -std=c99 -Wall -Wextra -Werror -O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all \
-isystem /home/user/LithosAnanke/kernel/include /home/user/LithosAnanke/v4/tests/test_fe25519.c /home/user/LithosAnanke/kernel/src/crypto/ed25519.c /home/user/LithosAnanke/kernel/src/crypto/fe25519.c /home/user/LithosAnanke/kernel/src/crypto/scalar25519.c /home/user/LithosAnanke/kernel/src/crypto/sha512.c -o /home/user/LithosAnanke/v4/build/san-test_fe25519
[ASan+UBSan fe25519]
fe25519: the field mod 2^255-19
16 checks, 0 failures
exit 0
+10
View File
@@ -0,0 +1,10 @@
cc -std=c99 -Wall -Wextra -Werror -O2 -g -isystem /home/user/LithosAnanke/kernel/include /home/user/LithosAnanke/v4/tests/test_fe25519.c /home/user/LithosAnanke/kernel/src/crypto/fe25519.c -o /home/user/LithosAnanke/v4/build/test_fe25519
[fe25519]
fe25519: the field mod 2^255-19
8 checks, 0 failures
cc -std=c99 -Wall -Wextra -Werror -O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all \
-isystem /home/user/LithosAnanke/kernel/include /home/user/LithosAnanke/v4/tests/test_fe25519.c /home/user/LithosAnanke/kernel/src/crypto/fe25519.c -o /home/user/LithosAnanke/v4/build/san-test_fe25519
[ASan+UBSan fe25519]
/home/user/LithosAnanke/kernel/src/crypto/fe25519.c:31:26: runtime error: left shift of negative value -1
make: *** [Makefile:382: san-fe25519] Error 1
exit 2
File diff suppressed because it is too large Load Diff