sfinx

sphincs+ inspired signing utility
git clone git://git.finwo.net/app/sfinx
Log | Files | Refs | README | LICENSE

commit ff825e315593511fb42d28a45820cde17b297668
parent d52201bcffcad63bbddfbb27e3cc1df80581a1a2
Author: finwo <finwo@pm.me>
Date:   Sun, 11 Oct 2026 06:41:11 +0200

Fix darwin compilation

Diffstat:
MMakefile | 8++++----
Msrc/sfinx.c | 3+--
Mtarget/common/Makefile | 4++++
Atarget/darwin-arm64/.gitkeep | 0
Mtest/Makefile | 5+----
Mtest/bench.c | 3+--
Mtest/test_threading.sh | 11+++++++++--
7 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile @@ -16,10 +16,10 @@ build/${TARGET}/${BIN}: build/${TARGET} $(WATCH) $(MAKE) --directory build/${TARGET} TARGET=${TARGET} build/${TARGET}: $(WATCH) - mkdir -p build/${TARGET} - cp -rT src/ build/${TARGET}/src - cp -rT target/common/ build/${TARGET} - cp -rT target/${TARGET}/ build/${TARGET} + mkdir -p build/${TARGET}/src + cp -R src/. build/${TARGET}/src/ + cp -R target/common/. build/${TARGET}/ + cp -R target/${TARGET}/. build/${TARGET}/ .PHONY: targets targets: diff --git a/src/sfinx.c b/src/sfinx.c @@ -773,8 +773,7 @@ sfinx_status sfinx_verify(const uint8_t *pubkey, size_t pubkey_len, const uint8_ c = len + 2; if (path_len == 0) { _sfinx_hash(hash, msg, msg_len, org); - _sfinx_wots_rebuild(hash, org, sig + at, leaf); - return memcmp(leaf, pubkey, len) == 0 ? SFINX_OK : SFINX_ERR_VERIFY; + return _sfinx_wots_verify(hash, pubkey, org, sig + at) ? SFINX_OK : SFINX_ERR_VERIFY; } joined = malloc(path_len + msg_len); if (!joined) { diff --git a/target/common/Makefile b/target/common/Makefile @@ -12,7 +12,11 @@ LDFLAGS?= # Drop unreferenced code: dependencies export whole libraries, of which we use a part CFLAGS +=-ffunction-sections -fdata-sections +ifeq ($(shell uname -s),Darwin) +LDFLAGS+=-Wl,-dead_strip +else LDFLAGS+=-Wl,--gc-sections +endif # pthread backs the optional worker pool in sfinx.c; the library manifest leaves it to the consumer CFLAGS +=-pthread diff --git a/target/darwin-arm64/.gitkeep b/target/darwin-arm64/.gitkeep diff --git a/test/Makefile b/test/Makefile @@ -10,10 +10,7 @@ BINS := $(addprefix $(OUT)/,$(TESTS)) SH := $(filter-out _tap.sh,$(wildcard *.sh)) HASH := ../lib/finwo/keccak-fast/src/keccak-fast.c \ - ../lib/finwo/keccak-fast/src/backend/scalar.c \ - ../lib/finwo/keccak-fast/src/backend/scalar_bmi.c \ - ../lib/finwo/keccak-fast/src/backend/avx2.c \ - ../lib/finwo/keccak-fast/src/backend/avx512.c + $(wildcard ../lib/finwo/keccak-fast/src/backend/*.c) LIB := ../src/keypair.c $(wildcard ../src/fmt/*.c) .PHONY: all diff --git a/test/bench.c b/test/bench.c @@ -53,7 +53,7 @@ static args_result parse_args(int argc, char **argv, bench_args *out) { out->path_len = SFINX_PATH_LEN_DEFAULT; out->reps = 3; - for (int i = 1; i < argc; i++) { + for (int i = 1; i < argc; i += 2) { const char *flag = argv[i]; const char *value = i + 1 < argc ? argv[i + 1] : NULL; uint32_t parsed = 0; @@ -76,7 +76,6 @@ static args_result parse_args(int argc, char **argv, bench_args *out) { fprintf(stderr, "unknown flag: %s\n", flag); return ARGS_ERR; } - i++; } if (sfinx_hash_len(out->hash) == 0) { diff --git a/test/test_threading.sh b/test/test_threading.sh @@ -11,7 +11,7 @@ CC=${CC:-cc} tap_begin "sfinx threading" HASH_FIRST="${ROOT}/lib/finwo/keccak-fast/src/keccak-fast.c" -HASH="${HASH_FIRST} ${ROOT}/lib/finwo/keccak-fast/src/backend/scalar.c ${ROOT}/lib/finwo/keccak-fast/src/backend/scalar_bmi.c ${ROOT}/lib/finwo/keccak-fast/src/backend/avx2.c ${ROOT}/lib/finwo/keccak-fast/src/backend/avx512.c" +HASH="${HASH_FIRST} ${ROOT}/lib/finwo/keccak-fast/src/backend/*.c" if [ ! -f "${HASH_FIRST}" ]; then (cd "${ROOT}" && dep install) >/dev/null 2>&1 || true fi @@ -46,8 +46,15 @@ else fi if build "${TMP}/tsan" -pthread -fsanitize=thread >"${TMP}/b3.log" 2>&1; then - if TSAN_OPTIONS="halt_on_error=1" "${TMP}/tsan" >"${TMP}/t.log" 2>&1; then + set +e + TSAN_OPTIONS="halt_on_error=1" "${TMP}/tsan" >"${TMP}/t.log" 2>&1 + tsan_status=$? + set -e + if [ "${tsan_status}" -eq 0 ]; then tap 1 "thread sanitizer reports no races" "" + elif [ "${tsan_status}" -ge 128 ]; then + TAP_NO=$((TAP_NO + 1)) + printf 'ok %s - thread sanitizer available # SKIP runtime crashed (signal %s)\n' "${TAP_NO}" "$((tsan_status - 128))" else tap 0 "thread sanitizer reports no races" "$(tail -n 5 "${TMP}/t.log" 2>/dev/null || true)" fi