commit ec0650caea9d9fb6da96f19c192fa97888ee313d
parent 84f231a54a3385ce4415f7a3c67f1439cbceadd4
Author: finwo <finwo@pm.me>
Date: Sat, 10 Oct 2026 18:01:07 +0200
Switch to keccak-fast
Diffstat:
7 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/.dep b/.dep
@@ -1 +1 @@
-coruus/keccak-tiny https://git.finwo.net/misc/dep-repository/archives/heads/pkg/coruus/keccak-tiny.tar.gz
+finwo/keccak-fast https://git.finwo.net/lib/keccak-fast.c/archives/heads/main.tar.gz
diff --git a/src/sfinx.c b/src/sfinx.c
@@ -1,6 +1,6 @@
#include "sfinx.h"
-#include <coruus/keccak-tiny.h>
+#include <finwo/keccak-fast.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -51,15 +51,15 @@ static inline uint32_t _sfinx_e4m4_encode(uint32_t value, uint8_t *out) {
static inline void _sfinx_hash(sfinx_hash hash, const uint8_t *in, size_t in_len, uint8_t *out) {
switch (hash) {
- case SFINX_HASH_224: sha3_224(out, 28, in, in_len); break;
- case SFINX_HASH_256: sha3_256(out, 32, in, in_len); break;
- case SFINX_HASH_384: sha3_384(out, 48, in, in_len); break;
- case SFINX_HASH_512: sha3_512(out, 64, in, in_len); break;
+ case SFINX_HASH_224: kf_sha3_224(out, 28, in, in_len); break;
+ case SFINX_HASH_256: kf_sha3_256(out, 32, in, in_len); break;
+ case SFINX_HASH_384: kf_sha3_384(out, 48, in, in_len); break;
+ case SFINX_HASH_512: kf_sha3_512(out, 64, in, in_len); break;
}
}
static inline void _sfinx_shake256(const uint8_t *in, size_t in_len, uint8_t *out, size_t out_len) {
- shake256(out, out_len, in, in_len);
+ kf_shake256(out, out_len, in, in_len);
}
size_t sfinx_hash_len(sfinx_hash hash) {
diff --git a/target/common/.dep b/target/common/.dep
@@ -1,2 +1,2 @@
cofyc/argparse https://git.finwo.net/misc/dep-repository/archives/heads/pkg/cofyc/argparse.tar.gz
-coruus/keccak-tiny https://git.finwo.net/misc/dep-repository/archives/heads/pkg/coruus/keccak-tiny.tar.gz
+finwo/keccak-fast https://git.finwo.net/lib/keccak-fast.c/archives/heads/main.tar.gz
diff --git a/test/Makefile b/test/Makefile
@@ -8,7 +8,11 @@ TESTS := $(patsubst %.c,%,$(SRCS))
BINS := $(addprefix $(OUT)/,$(TESTS))
SH := $(filter-out _tap.sh,$(wildcard *.sh))
-KECCAK := ../lib/coruus/keccak-tiny/keccak-tiny.c
+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
LIB := ../src/keypair.c $(wildcard ../src/fmt/*.c)
.PHONY: all
@@ -17,14 +21,14 @@ all: $(BINS)
$(OUT):
@mkdir -p $(OUT)
-$(KECCAK):
+$(HASH):
@cd .. && dep install
-$(OUT)/09-ref: 09-ref.c ref/sfinx_ref.c ../src/sfinx.c _tap.c $(LIB) $(KECCAK) | $(OUT)
- @$(CC) $(CFLAGS) $< $(LIB) $(KECCAK) -o $@
+$(OUT)/09-ref: 09-ref.c ref/sfinx_ref.c ../src/sfinx.c _tap.c $(LIB) $(HASH) | $(OUT)
+ @$(CC) $(CFLAGS) $< $(LIB) $(HASH) -o $@
-$(OUT)/%: %.c ../src/sfinx.c _tap.c $(LIB) $(KECCAK) | $(OUT)
- @$(CC) $(CFLAGS) $< $(LIB) $(KECCAK) -o $@
+$(OUT)/%: %.c ../src/sfinx.c _tap.c $(LIB) $(HASH) | $(OUT)
+ @$(CC) $(CFLAGS) $< $(LIB) $(HASH) -o $@
.PHONY: run
run: all
diff --git a/test/ref/sfinx_ref.c b/test/ref/sfinx_ref.c
@@ -1,12 +1,12 @@
// Reference signer {{{
//
// Independent re-derivation of the sfinx scheme
-// shares only the keccak-tiny primitive with src/sfinx.c
+// shares only the keccak-fast primitive with src/sfinx.c
// a second code path, not a second language, so it checks the scheme logic and
// the byte layout, not the hash (the hash is anchored by test_openssl.sh)
// nothing here is production code, all symbols are static and prefixed ref_
-#include <coruus/keccak-tiny.h>
+#include <finwo/keccak-fast.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
@@ -31,15 +31,15 @@ static size_t ref_len(int bits) {
static void ref_sha3(int bits, const uint8_t *in, size_t in_len, uint8_t *out) {
switch (bits) {
- case 224: sha3_224(out, 28, in, in_len); break;
- case 256: sha3_256(out, 32, in, in_len); break;
- case 384: sha3_384(out, 48, in, in_len); break;
- case 512: sha3_512(out, 64, in, in_len); break;
+ case 224: kf_sha3_224(out, 28, in, in_len); break;
+ case 256: kf_sha3_256(out, 32, in, in_len); break;
+ case 384: kf_sha3_384(out, 48, in, in_len); break;
+ case 512: kf_sha3_512(out, 64, in, in_len); break;
}
}
static void ref_shake(const uint8_t *in, size_t in_len, uint8_t *out, size_t out_len) {
- shake256(out, out_len, in, in_len);
+ kf_shake256(out, out_len, in, in_len);
}
static uint32_t ref_e4m4_decode(uint8_t byte) {
diff --git a/test/test_embed.sh b/test/test_embed.sh
@@ -1,6 +1,6 @@
#!/bin/sh
# Reads export.mk for the library source list, compiles a program that includes
-# only sfinx.h against that list plus keccak-tiny, then exercises the crypto and
+# only sfinx.h against that list plus keccak-fast, then exercises the crypto and
# the key format API. No CLI, no util, no argparse is reachable.
set -eu
HERE=$(cd "$(dirname "$0")" && pwd)
@@ -8,7 +8,8 @@ ROOT=$(cd "${HERE}/.." && pwd)
. "${HERE}/_tap.sh"
CC=${CC:-cc}
-KECCAK="${ROOT}/lib/coruus/keccak-tiny/keccak-tiny.c"
+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"
tap_begin "embed: library stands alone"
@@ -26,13 +27,13 @@ else
tap 0 "sfinx.h includes only stddef and stdint" "${bad}"
fi
-if [ ! -f "${KECCAK}" ]; then
+if [ ! -f "${HASH_FIRST}" ]; then
(cd "${ROOT}" && dep install) >/dev/null 2>&1 || true
fi
-if [ -f "${KECCAK}" ] && [ -f "${ROOT}/lib/.dep/include/coruus/keccak-tiny.h" ]; then
+if [ -f "${HASH_FIRST}" ] && [ -f "${ROOT}/lib/.dep/include/finwo/keccak-fast.h" ]; then
tap 1 "root dep installed" ""
else
- tap 0 "root dep installed" "dep install did not provide keccak-tiny"
+ tap 0 "root dep installed" "dep install did not provide keccak-fast"
fi
TMP=$(mktemp -d)
@@ -162,7 +163,7 @@ int main(void) {
EOF
if "${CC}" -Wall -Wextra -O2 -I"${ROOT}/src" -I"${ROOT}/lib/.dep/include" "${TMP}/embed.c" ${LIB_SRCS} \
- "${KECCAK}" -o "${TMP}/embed" >"${TMP}/build.log" 2>&1; then
+ ${HASH} -o "${TMP}/embed" >"${TMP}/build.log" 2>&1; then
tap 1 "embed program builds against the library only" ""
else
tap 0 "embed program builds against the library only" "$(cat "${TMP}/build.log")"
diff --git a/test/test_openssl.sh b/test/test_openssl.sh
@@ -23,13 +23,14 @@ tap 1 "openssl and od available" ""
TMP=$(mktemp -d)
trap 'rm -rf "${TMP}"' EXIT
-KECCAK="${ROOT}/lib/coruus/keccak-tiny/keccak-tiny.c"
-if [ ! -f "${KECCAK}" ]; then
+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"
+if [ ! -f "${HASH_FIRST}" ]; then
(cd "${ROOT}" && dep install) >/dev/null 2>&1 || true
fi
if "${CC}" -Wall -Wextra -O2 -I"${ROOT}" -I"${ROOT}/src" -I"${ROOT}/lib/.dep/include" \
- "${HERE}/ref/hash.c" "${KECCAK}" -o "${TMP}/hash" >"${TMP}/build.log" 2>&1; then
+ "${HERE}/ref/hash.c" ${HASH} -o "${TMP}/hash" >"${TMP}/build.log" 2>&1; then
tap 1 "hash helper builds" ""
else
tap 0 "hash helper builds" "$(cat "${TMP}/build.log")"