Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/net/Makefile # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / net / Makefile` 203 lines ยท 11685 bytes Raw Blame History 1 # AIENOS M6-A hosted network stack, in C. No Rust, no Python, no outside 2 # library: SHA-256 is the in-house copy in ../argus/sha256.c. 3 # Protocol objects import no heap, clock or I/O; tests use hosted libc. 4 # Hosted only: native binding waits for a C kernel, production keys for M5. 5 # 6 # make build out/libaienos_net.a 7 # make test protocol tests + control-transport loss/recovery + virtio-net + RTL8127 chip model 8 # (QEMU config dumps, simulated hostile device) + lib-checks 9 # + diff-check (pinned C/Rust-reference agreement digest) 10 # make sanitize the same tests under ASan+UBSan (Linux) 11 # make receipt run everything on a clean tree, write receipts/.txt 12 # make diff-corpus write out/diff_corpus.bin and out/diff_c.txt for the 13 # external Rust-reference driver (see README.md) 14 # make secure M6-B: X25519 RFC 7748 + secure transport tests, ASan/UBSan, 15 # guard mutants; prints AIENOS_NET_SECURE: PASS/FAIL 16 # make mutants delete each GUARD line in x25519.c / aienos_sec.c / aienos_ctl.c; tests must fail 17 # make clean 18 19 CC ?= cc 20 AR ?= ar 21 CFLAGS ?= -std=gnu11 -O2 -Wall -Wextra -Werror -fstack-protector-strong 22 OUT ?= out 23 SEED ?= 0x6a5e11 24 ITERS ?= 200000 25 26 # Differential corpus (fixed) and the output digest both C and the unmodified 27 # Rust reference produced on it. Change only with a new recorded Rust run. 28 DIFF_SEED = 0xa1e5 29 DIFF_COUNT = 200000 30 DIFF_DIGEST = `9ddf33a859ade2d92d0e86a213d29d682708b0ac308239a7b6f003dbf9a5cdfe` 31 # The same corpus through the default build. It differs from the Rust digest 32 # only on records the reference refused as InvalidRegion, because the C parser 33 # no longer region-checks vendor caps of cfg_type outside 1..4 (QEMU PCI_CFG, 34 # Lane 26). The Rust digest above is still checked with a reference-compat 35 # build (out/net_diff_ref). C-only pin, recorded 2026-10-01; no Rust run. 36 DIFF_DIGEST_FIXED = `034151b28953e23cbcdc2b805885ea88887b3da52e46369e8c01bd5b276241cb` 37 38 SRCS = aienos_net.c aienos_virtio_pci.c aienos_virtio_net.c aienos_ctl.c x25519.c aienos_sec.c aienos_rtl8127.c aienos_report.c 39 # M6-B links (never edits) the in-house AES-GCM-SIV/HMAC and Ed25519 code. 40 CRYPTO_SRCS = ../crypto/aes.c ../crypto/polyval.c ../crypto/gcm_siv.c ../crypto/hmac.c ../crypto/ct.c 41 SIG_SRCS = ../sig/`ed25519`.c ../sig/sha512.c ../sig/ct.c 42 DEP_SRCS = ../argus/sha256.c $(CRYPTO_SRCS) $(SIG_SRCS) 43 DEP_OBJS = $(OUT)/sha256.o $(OUT)/crypto_aes.o $(OUT)/crypto_polyval.o $(OUT)/crypto_gcm_siv.o \ 44 $(OUT)/crypto_hmac.o $(OUT)/crypto_ct.o $(OUT)/sig_`ed25519`.o $(OUT)/sig_sha512.o $(OUT)/sig_ct.o 45 OBJS = $(SRCS:%.c=$(OUT)/%.o) $(DEP_OBJS) 46 SEC_GUARD_FILES = x25519.c aienos_sec.c aienos_ctl.c 47 LIB = $(OUT)/libaienos_net.a 48 SANFLAGS = -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all -g 49 50 all: $(LIB) 51 52 $(OUT): 53 mkdir -p $(OUT) 54 55 $(OUT)/%.o: %.c $(wildcard *.h) | $(OUT) 56 $(CC) $(CFLAGS) -c -o $@ $< 57 58 $(OUT)/sha256.o: ../argus/sha256.c ../argus/sha256.h | $(OUT) 59 $(CC) $(CFLAGS) -c -o $@ ../argus/sha256.c 60 $(OUT)/crypto_%.o: ../crypto/%.c $(wildcard ../crypto/*.h) | $(OUT) 61 $(CC) $(CFLAGS) -c -o $@ $< 62 $(OUT)/sig_%.o: ../sig/%.c $(wildcard ../sig/*.h) | $(OUT) 63 $(CC) $(CFLAGS) -c -o $@ $< 64 65 $(LIB): $(OBJS) 66 $(AR) rcs $@ $^ 67 68 $(OUT)/net_test: tests/net_test.c $(LIB) 69 $(CC) $(CFLAGS) -o $@ $< $(LIB) 70 $(OUT)/ctl_test: tests/ctl_test.c $(LIB) 71 $(CC) $(CFLAGS) -o $@ $< $(LIB) 72 $(OUT)/net_diff: tests/net_diff.c $(LIB) 73 $(CC) $(CFLAGS) -o $@ $< $(LIB) 74 $(OUT)/vnet_test: tests/vnet_test.c $(LIB) 75 $(CC) $(CFLAGS) -o $@ $< $(LIB) 76 $(OUT)/net_diff_ref: tests/net_diff.c $(SRCS) $(DEP_SRCS) $(wildcard *.h) | $(OUT) 77 $(CC) $(CFLAGS) -DAIENOS_VIRTIO_PCI_REFERENCE_COMPAT -o $@ tests/net_diff.c $(SRCS) $(DEP_SRCS) 78 $(OUT)/rtl8127_test: tests/rtl8127_test.c $(LIB) 79 $(CC) $(CFLAGS) -o $@ $< $(LIB) 80 $(OUT)/x25519_test: tests/x25519_test.c $(LIB) 81 $(CC) $(CFLAGS) -o $@ $< $(LIB) 82 $(OUT)/sec_test: tests/sec_test.c $(LIB) 83 $(CC) $(CFLAGS) -o $@ $< $(LIB) 84 85 test: lib-checks $(OUT)/net_test $(OUT)/ctl_test $(OUT)/vnet_test $(OUT)/rtl8127_test $(OUT)/x25519_test $(OUT)/sec_test diff-check 86 ./$(OUT)/net_test $(SEED) $(ITERS) 87 ./$(OUT)/ctl_test 88 ./$(OUT)/x25519_test 89 ./$(OUT)/sec_test 90 ./$(OUT)/vnet_test 91 ./$(OUT)/rtl8127_test 92 93 # Protocol objects must not allocate, read a clock or do their own I/O. 94 lib-checks: $(OBJS) 95 @for o in $(SRCS:%.c=$(OUT)/%.o); do \ 96 if nm -u $$o | awk '{print $$NF}' | sed 's/^_//' | grep -qxE 'malloc|calloc|realloc|free|clock_gettime|time|gettimeofday|open|read|write|recv|recvfrom|send|sendto|socket|fopen|printf|rand|random|getrandom'; then \ 97 echo "lib-checks FAIL: $$o allocates, reads a clock, does I/O or uses ambient randomness"; exit 1; fi; done 98 @if grep -n 'CT_IDENTITY_[A-Z]* ' aienos_ctl.h | grep -v 'CT_IDENTITY_TEST' | grep -q .; then \ 99 echo "lib-checks FAIL: an identity kind other than TEST is defined (production keys wait for M5)"; exit 1; fi 100 @grep -q 'NOT-FOR-PRODUCTION' aienos_ctl.c || { echo "lib-checks FAIL: TEST label missing"; exit 1; } 101 @grep -q "NOT-FOR-PRODUCTION" aienos_sec.c || { echo "lib-checks FAIL: M6-B TEST label missing"; exit 1; } 102 @echo "lib-checks PASS (no heap, clock, I/O or ambient randomness; TEST identity only)" 103 104 diff-corpus: $(OUT)/net_diff $(OUT)/net_diff_ref 105 ./$(OUT)/net_diff gen $(DIFF_SEED) $(DIFF_COUNT) > $(OUT)/diff_corpus.bin 106 ./$(OUT)/net_diff run < $(OUT)/diff_corpus.bin > $(OUT)/diff_c.txt 107 ./$(OUT)/net_diff_ref run < $(OUT)/diff_corpus.bin > $(OUT)/diff_ref.txt 108 @echo "corpus $$(sha256sum $(OUT)/diff_corpus.bin | cut -d' ' -f1)" 109 @echo "c-out $$(sha256sum $(OUT)/diff_c.txt | cut -d' ' -f1)" 110 111 diff-check: diff-corpus 112 @got=$$(sha256sum $(OUT)/diff_ref.txt | cut -d' ' -f1); \ 113 if [ "$$got" = "$(DIFF_DIGEST)" ]; then echo "NET_RUST_DIFFERENTIAL_PINNED: PASS ($(DIFF_COUNT) records, reference-compat build)"; \ 114 else echo "NET_RUST_DIFFERENTIAL_PINNED: FAIL (got $$got, pinned $(DIFF_DIGEST))"; exit 1; fi 115 @got=$$(sha256sum $(OUT)/diff_c.txt | cut -d' ' -f1); \ 116 if [ "$$got" = "$(DIFF_DIGEST_FIXED)" ]; then echo "NET_DIFFERENTIAL_FIXED_PINNED: PASS (C-only pin)"; \ 117 else echo "NET_DIFFERENTIAL_FIXED_PINNED: FAIL (got $$got, pinned $(DIFF_DIGEST_FIXED))"; exit 1; fi 118 @paste -d'\t' $(OUT)/diff_ref.txt $(OUT)/diff_c.txt | awk -F'\t' \ 119 '$$1 != $$2 { d++; if ($$1 != "V Err InvalidRegion") bad++ } \ 120 END { if (NR != $(DIFF_COUNT) || bad) { print "NET_DIFFERENTIAL_DIVERGENCE: FAIL (" bad+0 " records differ outside the PCI_CFG fix)"; exit 1 } \ 121 print "NET_DIFFERENTIAL_DIVERGENCE: PASS (" d+0 " records differ, all reference InvalidRegion)" }' 122 123 sanitize: | $(OUT) 124 ifeq ($(shell uname -s),Linux) 125 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/net_test_asan tests/net_test.c $(SRCS) $(DEP_SRCS) 126 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/ctl_test_asan tests/ctl_test.c $(SRCS) $(DEP_SRCS) 127 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/net_diff_asan tests/net_diff.c $(SRCS) $(DEP_SRCS) 128 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/net_test_asan $(SEED) 50000 129 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/ctl_test_asan 130 ./$(OUT)/net_diff_asan gen $(DIFF_SEED) 20000 > $(OUT)/asan_corpus.bin 131 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/net_diff_asan run < $(OUT)/asan_corpus.bin > /dev/null 132 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/x25519_test_asan tests/x25519_test.c $(SRCS) $(DEP_SRCS) 133 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/sec_test_asan tests/sec_test.c $(SRCS) $(DEP_SRCS) 134 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/x25519_test_asan 135 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/sec_test_asan 136 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/vnet_test_asan tests/vnet_test.c $(SRCS) $(DEP_SRCS) 137 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/vnet_test_asan 138 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/rtl8127_test_asan tests/rtl8127_test.c $(SRCS) $(DEP_SRCS) 139 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/rtl8127_test_asan 140 @echo "NET_SANITIZE: PASS" 141 else 142 @echo "sanitize: Linux only" 143 endif 144 145 # Mutants (native/sig pattern): delete one "GUARD:name" line at a time from 146 # the M6-B sources and the Lane 19 resend jitter in aienos_ctl.c; the X25519, 147 # secure transport and control-transport tests must then fail. A 148 # mutant that compiles and passes all three tests SURVIVED, and fails this target. 149 NET_MUT_TEST_OBJS = $(OUT)/t_x25519_test.o $(OUT)/t_sec_test.o $(OUT)/t_ctl_test.o 150 $(OUT)/t_%_test.o: tests/%_test.c $(wildcard *.h) | $(OUT) 151 $(CC) $(CFLAGS) -Wno-error -I. -c -o $@ $< 152 153 mutants: $(OBJS) $(NET_MUT_TEST_OBJS) | $(OUT) 154 @killed=0; total=0; survived=""; list=""; \ 155 for f in $(SEC_GUARD_FILES); do \ 156 for g in $$(grep -o 'GUARD:[a-z0-9-]*' $$f | cut -d: -f2); do \ 157 case " $$list " in *" $$g "*) echo "mutant $$g: guard tag appears twice, parallel runs would collide"; survived="$$survived $$g"; continue ;; esac; \ 158 total=$$((total+1)); mdir=$(OUT)/mut_$$g; rm -rf $$mdir; mkdir -p $$mdir; list="$$list $$g"; \ 159 ( cp *.h $$mdir/; \ 160 sed "/GUARD:$$g \*\//d" $$f > $$mdir/$$f; \ 161 if cmp -s $$f $$mdir/$$f; then echo "mutant $$g: guard line not found" > $$mdir/msg; echo "$$g" > $$mdir/surv; exit 0; fi; \ 162 others=""; for s in $(SRCS); do [ "$$s" = "$$f" ] || others="$$others $(OUT)/$${s%.c}.o"; done; \ 163 if ! $(CC) $(CFLAGS) -Wno-error -I. -c -o $$mdir/m.o $$mdir/$$f 2>/dev/null || \ 164 ! $(CC) $(CFLAGS) -Wno-error -o $$mdir/x25519_t $(OUT)/t_x25519_test.o $$mdir/m.o $$others $(DEP_OBJS) 2>/dev/null || \ 165 ! $(CC) $(CFLAGS) -Wno-error -o $$mdir/sec_t $(OUT)/t_sec_test.o $$mdir/m.o $$others $(DEP_OBJS) 2>/dev/null || \ 166 ! $(CC) $(CFLAGS) -Wno-error -o $$mdir/ctl_t $(OUT)/t_ctl_test.o $$mdir/m.o $$others $(DEP_OBJS) 2>/dev/null; then \ 167 echo "mutant $$g: does not compile (counts as not killed)" > $$mdir/msg; echo "$$g" > $$mdir/surv; exit 0; fi; \ 168 case "$$f" in \ 169 x25519.c) order="$$mdir/x25519_t $$mdir/sec_t $$mdir/ctl_t" ;; \ 170 aienos_sec.c) order="$$mdir/sec_t $$mdir/x25519_t $$mdir/ctl_t" ;; \ 171 *) order="$$mdir/ctl_t $$mdir/x25519_t $$mdir/sec_t" ;; \ 172 esac; \ 173 pass=1; for b in $$order; do if ! ./$$b >/dev/null 2>&1; then pass=0; break; fi; done; \ 174 if [ $$pass -eq 1 ]; then echo "mutant $$g: SURVIVED" > $$mdir/msg; echo "$$g" > $$mdir/surv; \ 175 else echo "mutant $$g: killed" > $$mdir/msg; : > $$mdir/killed; fi \ 176 ) & \ 177 done; \ 178 done; \ 179 wait; \ 180 for g in $$list; do \ 181 mdir=$(OUT)/mut_$$g; \ 182 if [ -f $$mdir/msg ]; then cat $$mdir/msg; else echo "mutant $$g: no result recorded (counts as not killed)"; fi; \ 183 if [ -f $$mdir/killed ] && [ ! -f $$mdir/surv ]; then killed=$$((killed+1)); else survived="$$survived $$g"; fi; \ 184 done; \ 185 echo "NET_SECURE_MUTANTS: $$killed/$$total killed"; \ 186 [ -z "$$survived" ] && [ $$total -ge 12 ] || { echo "NET_SECURE_MUTANTS: FAIL (not killed:$$survived)"; exit 1; } 187 188 # M6-B verdict. Hosted only: proves the protocol code, not a native binding, 189 # real keys, timing behaviour or a formal protocol proof (see README.md). 190 secure: 191 @ok=1; \ 192 $(MAKE) --no-print-directory test || ok=0; \ 193 $(MAKE) --no-print-directory sanitize || ok=0; \ 194 $(MAKE) --no-print-directory mutants || ok=0; \ 195 if [ $$ok = 1 ]; then echo "AIENOS_NET_SECURE: PASS"; else echo "AIENOS_NET_SECURE: FAIL"; exit 1; fi 196 197 receipt: 198 sh ./receipt.sh 199 200 clean: 201 rm -rf $(OUT) 202 203 .PHONY: all test lib-checks diff-corpus diff-check sanitize mutants secure receipt clean