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/sig/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 / sig / Makefile` 95 lines ยท 4190 bytes Raw Blame History 1 # AIENOS in-house signatures in C: Ed25519 (RFC 8032, pure Ed25519) and 2 # SHA-512 (FIPS 180-4). No outside library. Library objects import no heap, 3 # clock or I/O; the test uses hosted libc. 4 # 5 # make build out/libaienos_sig.a 6 # make test known-answer + negative + round-trip tests (host, not QEMU) 7 # make sanitize the same test under ASan+UBSan (Linux) 8 # make mutants remove each GUARD-tagged rule in turn; tests must fail 9 # make clean 10 11 CC ?= cc 12 AR ?= ar 13 CFLAGS ?= -std=gnu11 -O2 -Wall -Wextra -Werror -fstack-protector-strong 14 OUT ?= out 15 16 SRCS = sha512.c `ed25519`.c ct.c 17 OBJS = $(SRCS:%.c=$(OUT)/%.o) 18 LIB = $(OUT)/libaienos_sig.a 19 TEST = $(OUT)/sig_test 20 HDRS = aienos_sig.h sig_internal.h 21 TEST_HDRS = tests/rfc8032_vectors.h 22 SANFLAGS = -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all -g 23 24 all: $(LIB) 25 26 $(OUT): 27 mkdir -p $(OUT) 28 29 $(OUT)/%.o: %.c $(HDRS) | $(OUT) 30 $(CC) $(CFLAGS) -c -o $@ $< 31 32 $(LIB): $(OBJS) 33 $(AR) rcs $@ $^ 34 35 $(TEST): tests/sig_test.c $(TEST_HDRS) $(LIB) $(HDRS) 36 $(CC) $(CFLAGS) -o $@ tests/sig_test.c $(LIB) 37 38 test: $(TEST) lib-checks 39 ./$(TEST) 40 41 # The library objects must not allocate, read a clock, or do their own I/O. 42 lib-checks: $(OBJS) 43 @bad=$$(nm -u $(OBJS) | awk 'NF {print $$NF}' | sed 's/^_//' | grep -xE 'malloc|calloc|realloc|free|aligned_alloc|posix_memalign|mmap|clock_gettime|time|gettimeofday|open|openat|read|write|pread|pwrite|fopen|fread|fwrite|printf|fprintf|puts|getrandom'); \ 44 if [ -n "$$bad" ]; then echo "lib-checks FAIL: library imports $$bad"; exit 1; fi 45 @echo "lib-checks PASS (no heap, clock or direct I/O in libaienos_sig objects)" 46 47 sanitize: | $(OUT) 48 ifeq ($(shell uname -s),Linux) 49 $(CC) $(CFLAGS) $(SANFLAGS) -o $(OUT)/sig_test_asan tests/sig_test.c $(SRCS) 50 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/sig_test_asan 51 else 52 @echo "sanitize: Linux only" 53 endif 54 55 # Mutants: delete each GUARD-tagged line in turn (file:guard). The tests must 56 # fail (or crash) for every mutant, or that rule is not tested. 57 MUTANTS = sha512.c:sha-pad sha512.c:sha-len \ 58 `ed25519`.c:clamp-low `ed25519`.c:clamp-high `ed25519`.c:clamp-254 \ 59 `ed25519`.c:y-canonical `ed25519`.c:on-curve `ed25519`.c:x-zero-sign `ed25519`.c:x-sign \ 60 `ed25519`.c:sc-sub `ed25519`.c:s-range `ed25519`.c:a-small-order `ed25519`.c:r-small-order \ 61 `ed25519`.c:r-check 62 63 $(OUT)/t_sig_test.o: tests/sig_test.c $(TEST_HDRS) $(HDRS) | $(OUT) 64 $(CC) $(CFLAGS) -Wno-error -I. -c -o $@ $< 65 66 mutants: $(OBJS) $(OUT)/t_sig_test.o | $(OUT) 67 @ulimit -c 0; fail=0; n=0; \ 68 dups=$$(printf '%s\n' $(MUTANTS) | sed 's/.*://' | sort | uniq -d); \ 69 [ -z "$$dups" ] || { echo "duplicate guard names (parallel runs would collide):" $$dups; echo "AIENOS_SIG_MUTANTS: FAIL"; exit 1; }; \ 70 for m in $(MUTANTS); do \ 71 f=$${m%%:*}; g=$${m#*:}; n=$$((n+1)); \ 72 rm -f $(OUT)/mut_$$g.msg $(OUT)/mut_$$g.fail $(OUT)/mut_$$g.killed; \ 73 ( grep -q "GUARD:$$g \*/" $$f || { echo "mutant $$g: guard tag missing" > $(OUT)/mut_$$g.msg; echo 1 > $(OUT)/mut_$$g.fail; exit 0; }; \ 74 sed "/GUARD:$$g \*\//d" $$f > $(OUT)/mut_$$g.c; \ 75 others=$$(for s in $(SRCS); do [ $$s = $$f ] || echo $(OUT)/$${s%.c}.o; done); \ 76 $(CC) $(CFLAGS) -Wno-error -I. -c -o $(OUT)/mut_$$g.o $(OUT)/mut_$$g.c \ 77 && $(CC) $(CFLAGS) -Wno-error -o $(OUT)/mut_$$g $(OUT)/t_sig_test.o $(OUT)/mut_$$g.o $$others \ 78 || { echo "mutant $$g: does not compile" > $(OUT)/mut_$$g.msg; echo 1 > $(OUT)/mut_$$g.fail; exit 0; }; \ 79 if ./$(OUT)/mut_$$g > $(OUT)/mut_$$g.log 2>&1; then \ 80 echo "mutant $$g: SURVIVED (FAIL)" > $(OUT)/mut_$$g.msg; echo 1 > $(OUT)/mut_$$g.fail; \ 81 else echo "mutant $$g: killed" > $(OUT)/mut_$$g.msg; : > $(OUT)/mut_$$g.killed; fi \ 82 ) & \ 83 done; \ 84 wait; \ 85 for m in $(MUTANTS); do \ 86 g=$${m#*:}; \ 87 if [ -f $(OUT)/mut_$$g.msg ]; then cat $(OUT)/mut_$$g.msg; else echo "mutant $$g: no result recorded (FAIL)"; fi; \ 88 [ -f $(OUT)/mut_$$g.killed ] && [ ! -f $(OUT)/mut_$$g.fail ] || fail=1; \ 89 done; \ 90 if [ $$fail -eq 0 ]; then echo "AIENOS_SIG_MUTANTS: PASS ($$n/$$n killed)"; else echo "AIENOS_SIG_MUTANTS: FAIL"; exit 1; fi 91 92 clean: 93 rm -rf $(OUT) 94 95 .PHONY: all test lib-checks sanitize mutants clean