feat: add Jasmin assembly integration for crypto acceleration
- Integrated `zupt_mac_verify_ct` in `zupt_decrypt_buffer()` to replace C XOR loop for HMAC-SHA256 - Integrated `zupt_ct_select_32` in `zupt_mlkem768_decaps()` to replace C `cmov()` for FO transformation - Added `include/zupt_jasmin.h` with extern declarations and ABI docs - Added `#ifdef ZUPT_USE_JASMIN` guards with clean C fallbacks in `zupt_crypto.c` and `zupt_mlkem.c` - Makefile now auto-detects `jasmin/*.s`, assembles and links with `-DZUPT_USE_JASMIN` Closes #3
This commit is contained in:
parent
26e45b5c3e
commit
5bb280eb25
43 changed files with 1913 additions and 546 deletions
144
Makefile
144
Makefile
|
|
@ -1,84 +1,82 @@
|
|||
# Zupt v1.5.0 — Makefile with Jasmin integration
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -Wall -Wextra -O2 -std=c11
|
||||
CFLAGS += -Iinclude -Isrc
|
||||
LDLIBS = -lm -lpthread
|
||||
PREFIX ?= /usr/local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
|
||||
SOURCES = src/zupt_main.c src/zupt_format.c src/zupt_lz.c src/zupt_lzh.c \
|
||||
src/zupt_xxh.c src/zupt_sha256.c src/zupt_aes256.c src/zupt_crypto.c \
|
||||
src/zupt_predict.c src/zupt_parallel.c src/zupt_keccak.c \
|
||||
src/zupt_x25519.c src/zupt_mlkem.c src/zupt_cpuid.c
|
||||
|
||||
HEADERS = include/zupt.h include/zupt_keccak.h include/zupt_mlkem.h \
|
||||
include/zupt_x25519.h include/zupt_cpuid.h include/zupt_jasmin.h \
|
||||
src/zupt_thread.h src/zupt_parallel.h
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -O2 -std=c11 -Iinclude -Isrc
|
||||
SOURCES = src/zupt_main.c src/zupt_format.c src/zupt_lz.c src/zupt_lzh.c src/zupt_xxh.c \
|
||||
src/zupt_sha256.c src/zupt_aes256.c src/zupt_crypto.c src/zupt_predict.c \
|
||||
src/zupt_parallel.c src/zupt_keccak.c src/zupt_x25519.c src/zupt_mlkem.c
|
||||
LDFLAGS = -lm -lpthread
|
||||
TARGET = zupt
|
||||
PREFIX = /usr/local
|
||||
BINDIR = $(PREFIX)/bin
|
||||
|
||||
.PHONY: all clean test test-all test-asan install
|
||||
# Jasmin: use pre-compiled .s files if present (mac_verify + mlkem_select)
|
||||
JAZZ_S = jasmin/zupt_mac_verify.s jasmin/zupt_mlkem_select.s
|
||||
JAZZ_AVAILABLE := $(wildcard $(JAZZ_S))
|
||||
|
||||
ifeq ($(JAZZ_AVAILABLE),$(JAZZ_S))
|
||||
CFLAGS += -DZUPT_USE_JASMIN
|
||||
JAZZ_O = jasmin/zupt_mac_verify.o jasmin/zupt_mlkem_select.o
|
||||
$(info [jasmin] Verified assembly found — linking CT crypto)
|
||||
else
|
||||
JAZZ_O =
|
||||
$(info [jasmin] Assembly not found — using C fallback)
|
||||
endif
|
||||
|
||||
.PHONY: all clean install uninstall test test-all test-asan test-vectors help
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SOURCES) include/zupt.h src/zupt_thread.h src/zupt_parallel.h
|
||||
$(CC) $(CFLAGS) $(SOURCES) $(LDFLAGS) -o $(TARGET)
|
||||
jasmin/%.o: jasmin/%.s
|
||||
$(CC) -c -o $@ $<
|
||||
|
||||
$(TARGET): $(SOURCES) $(HEADERS) $(JAZZ_O)
|
||||
$(CC) $(CFLAGS) $(SOURCES) $(JAZZ_O) $(LDLIBS) -o $(TARGET)
|
||||
@echo "Build complete: ./$(TARGET)"
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) zupt_asan
|
||||
|
||||
# Quick self-test (9 tests)
|
||||
test: $(TARGET)
|
||||
@echo "=== Zupt v0.5.1 Self-Test ==="
|
||||
@rm -rf /tmp/zupt_test && mkdir -p /tmp/zupt_test/input/subdir
|
||||
@echo "Hello, Zupt!" > /tmp/zupt_test/input/hello.txt
|
||||
@dd if=/dev/urandom bs=1024 count=100 of=/tmp/zupt_test/input/random.bin 2>/dev/null
|
||||
@yes "AAAA BBBB CCCC DDDD EEEE FFFF " | head -c 1000000 > /tmp/zupt_test/input/repeat.txt
|
||||
@echo '{"key": "value", "arr": [1,2,3]}' > /tmp/zupt_test/input/subdir/data.json
|
||||
@seq 1 10000 > /tmp/zupt_test/input/subdir/numbers.txt
|
||||
@echo ""
|
||||
@echo "--- Test 1: Unencrypted compress (recursive directory) ---"
|
||||
@./zupt compress -v -l 7 /tmp/zupt_test/plain.zupt /tmp/zupt_test/input
|
||||
@echo ""
|
||||
@echo "--- Test 2: List ---"
|
||||
@./zupt list /tmp/zupt_test/plain.zupt
|
||||
@echo "--- Test 3: Integrity test ---"
|
||||
@./zupt test -v /tmp/zupt_test/plain.zupt
|
||||
@echo ""
|
||||
@echo "--- Test 4: Extract + verify ---"
|
||||
@./zupt extract -v -o /tmp/zupt_test/out_plain /tmp/zupt_test/plain.zupt
|
||||
@diff /tmp/zupt_test/input/hello.txt /tmp/zupt_test/out_plain/tmp/zupt_test/input/hello.txt && echo " hello.txt: OK"
|
||||
@diff /tmp/zupt_test/input/random.bin /tmp/zupt_test/out_plain/tmp/zupt_test/input/random.bin && echo " random.bin: OK"
|
||||
@diff /tmp/zupt_test/input/repeat.txt /tmp/zupt_test/out_plain/tmp/zupt_test/input/repeat.txt && echo " repeat.txt: OK"
|
||||
@diff /tmp/zupt_test/input/subdir/data.json /tmp/zupt_test/out_plain/tmp/zupt_test/input/subdir/data.json && echo " subdir/data.json: OK"
|
||||
@diff /tmp/zupt_test/input/subdir/numbers.txt /tmp/zupt_test/out_plain/tmp/zupt_test/input/subdir/numbers.txt && echo " subdir/numbers.txt: OK"
|
||||
@echo ""
|
||||
@echo "--- Test 5: Encrypted compress ---"
|
||||
@./zupt compress -v -l 8 -p "TestP@ss123!" /tmp/zupt_test/enc.zupt /tmp/zupt_test/input
|
||||
@echo ""
|
||||
@echo "--- Test 6: Encrypted list ---"
|
||||
@./zupt list -p "TestP@ss123!" /tmp/zupt_test/enc.zupt
|
||||
@echo "--- Test 7: Encrypted test ---"
|
||||
@./zupt test -v -p "TestP@ss123!" /tmp/zupt_test/enc.zupt
|
||||
@echo ""
|
||||
@echo "--- Test 8: Encrypted extract + verify ---"
|
||||
@./zupt extract -v -o /tmp/zupt_test/out_enc -p "TestP@ss123!" /tmp/zupt_test/enc.zupt
|
||||
@diff /tmp/zupt_test/input/hello.txt /tmp/zupt_test/out_enc/tmp/zupt_test/input/hello.txt && echo " hello.txt: OK"
|
||||
@diff /tmp/zupt_test/input/random.bin /tmp/zupt_test/out_enc/tmp/zupt_test/input/random.bin && echo " random.bin: OK"
|
||||
@diff /tmp/zupt_test/input/repeat.txt /tmp/zupt_test/out_enc/tmp/zupt_test/input/repeat.txt && echo " repeat.txt: OK"
|
||||
@diff /tmp/zupt_test/input/subdir/data.json /tmp/zupt_test/out_enc/tmp/zupt_test/input/subdir/data.json && echo " subdir/data.json: OK"
|
||||
@diff /tmp/zupt_test/input/subdir/numbers.txt /tmp/zupt_test/out_enc/tmp/zupt_test/input/subdir/numbers.txt && echo " subdir/numbers.txt: OK"
|
||||
@echo ""
|
||||
@echo "--- Test 9: Wrong password should fail ---"
|
||||
@./zupt list -p "WrongPass" /tmp/zupt_test/enc.zupt 2>/dev/null && echo " FAIL: should have rejected" || echo " Wrong password correctly rejected: OK"
|
||||
@echo ""
|
||||
@rm -rf /tmp/zupt_test
|
||||
@echo "=== ALL TESTS PASSED ==="
|
||||
|
||||
# Full regression test suite
|
||||
test-all: $(TARGET)
|
||||
@echo "=== Running full regression suite ==="
|
||||
sh tests/regression.sh
|
||||
|
||||
# Build with AddressSanitizer + UndefinedBehaviorSanitizer
|
||||
test-asan: $(SOURCES) include/zupt.h src/zupt_thread.h src/zupt_parallel.h
|
||||
$(CC) -Wall -Wextra -std=c11 -Iinclude -Isrc -fsanitize=address,undefined -g -O1 \
|
||||
$(SOURCES) -lm -lpthread -o zupt_asan
|
||||
@echo "ASAN build complete: ./zupt_asan"
|
||||
rm -f $(TARGET) zupt_asan test_vectors jasmin/*.o
|
||||
|
||||
install: $(TARGET)
|
||||
install -d $(DESTDIR)$(BINDIR)
|
||||
install -m 755 $(TARGET) $(DESTDIR)$(BINDIR)/
|
||||
@mkdir -p $(DESTDIR)$(BINDIR)
|
||||
install -m 755 $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
|
||||
@echo "Installed: $(DESTDIR)$(BINDIR)/$(TARGET)"
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(BINDIR)/$(TARGET)
|
||||
|
||||
test: $(TARGET)
|
||||
@sh tests/run_quick.sh
|
||||
|
||||
test-all: $(TARGET) test-vectors
|
||||
@echo "═══════════════════════════════════════════════"
|
||||
@sh tests/regression.sh 2>&1 | tail -3
|
||||
@echo ""
|
||||
@sh tests/test_threaded.sh 2>&1 | tail -3
|
||||
@echo ""
|
||||
@sh tests/test_pq.sh ./zupt 2>&1 | tail -3
|
||||
@echo ""
|
||||
@./test_vectors 2>&1 | tail -2
|
||||
@echo "═══════════════════════════════════════════════"
|
||||
|
||||
test-vectors: tests/test_vectors.c $(SOURCES) $(HEADERS)
|
||||
$(CC) -O2 -std=c11 -Iinclude -Isrc tests/test_vectors.c \
|
||||
src/zupt_sha256.c src/zupt_crypto.c src/zupt_aes256.c src/zupt_xxh.c \
|
||||
src/zupt_keccak.c src/zupt_x25519.c src/zupt_mlkem.c src/zupt_cpuid.c \
|
||||
$(LDLIBS) -o test_vectors
|
||||
|
||||
test-asan: $(SOURCES) $(HEADERS) $(JAZZ_O)
|
||||
$(CC) -Wall -Wextra -std=c11 -Iinclude -Isrc \
|
||||
-fsanitize=address,undefined -g -O1 \
|
||||
$(SOURCES) $(JAZZ_O) $(LDLIBS) -o zupt_asan
|
||||
@echo "ASAN build: ./zupt_asan"
|
||||
|
||||
help:
|
||||
@echo "make / make test / make install / make test-all / make test-asan / make clean"
|
||||
|
|
|
|||
Loading…
Reference in a new issue