commit 281803cc9430967245621910a4eea86efcf752db
parent 9a442bac4584f7be428b34273d17fa2c046ef7e3
Author: finwo <finwo@pm.me>
Date: Tue, 13 Oct 2026 11:09:54 +0200
Add configurable version, test & doc fixes
Diffstat:
6 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
@@ -2,6 +2,9 @@ TARGET:=$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(shell uname -m)
BIN:=sfinx
+SFINX_VERSION?=0.2.0
+export SFINX_VERSION
+
FIND:=$(shell command -v gfind find)
WATCH?=
diff --git a/docs/scheme.md b/docs/scheme.md
@@ -110,7 +110,7 @@ parent = H(bitlen (1) | mask (1) | prefix (k) | left (L) | right (L))
- `bitlen` is 0..8, the number of sub-byte bits in the position. `mask` holds those bits in its top `bitlen` positions with the low `8 - bitlen` bits zeroed, so a prefix has one encoding.
- `left` is the child reached by a 0 bit, `right` the child reached by a 1 bit.
- Keying by position is what moves the tree from collision resistance to second-preimage resistance.
-- Leaf and parent inputs coincide in length at `L*L - 2` bytes. The verifier's walk is fixed by `N` and the subtree height, so a leaf is never read as a parent.
+- A leaf input is `c * L` bytes and a parent input `2 + k + 2L`, so the two coincide at `L*L + 2L` bytes, where the prefix is `k = L*L - 2`. The verifier's walk is fixed by `N` and the subtree height, so a leaf is never read as a parent.
## Tree structure
diff --git a/src/sfinx.c b/src/sfinx.c
@@ -821,8 +821,12 @@ const char *sfinx_strerror(sfinx_status status) {
return "unknown error";
}
+#ifndef SFINX_VERSION
+#define SFINX_VERSION "n/a-dev"
+#endif
+
const char *sfinx_version(void) {
- return "0.1.0";
+ return SFINX_VERSION;
}
size_t sfinx_signature_len(sfinx_hash hash, size_t path_len) {
diff --git a/target/common/Makefile b/target/common/Makefile
@@ -22,6 +22,10 @@ endif
CFLAGS +=-pthread
LDFLAGS+=-pthread
+ifneq ($(SFINX_VERSION),)
+CFLAGS +=-DSFINX_VERSION='"$(SFINX_VERSION)"'
+endif
+
INCLUDES:=
INCLUDES+=-I src
diff --git a/test/11-reuse.c b/test/11-reuse.c
@@ -6,35 +6,42 @@
#define MSG "sfinx reuse regression"
#define MSG_LEN (sizeof(MSG) - 1)
-// Without N in the key, an N=1 signature shares its layer-1 key with any longer one on the same path[0]
-
-static void layer1_pubkey(const uint8_t *seed, size_t seed_len, size_t path_len, uint8_t first, uint8_t *out) {
- uint8_t key[64];
- memcpy(key, seed, seed_len);
- _sfinx_e4m4_encode((uint32_t)path_len, key + seed_len);
- key[seed_len + 1] = first;
- _sfinx_wots_pubkey(SFINX_HASH_256, key, seed_len + 2, out);
+// Two WOTS signatures from one key sit on the same chains, so one walks forward onto the other
+static size_t chains_linked(sfinx_hash hash, const uint8_t *a, const uint8_t *b, size_t len, size_t count) {
+ uint8_t walk[SFINX_HASH_LEN_MAX];
+ size_t linked = 0;
+ for (size_t i = 0; i < count; i++) {
+ for (int dir = 0; dir < 2; dir++) {
+ const uint8_t *from = dir ? b : a;
+ const uint8_t *to = dir ? a : b;
+ memcpy(walk, from + i * len, len);
+ for (size_t step = 0; step < 256; step++) {
+ if (memcmp(walk, to + i * len, len) == 0) {
+ linked++;
+ dir = 2;
+ break;
+ }
+ _sfinx_hash(hash, walk, len, walk);
+ }
+ }
+ }
+ return linked;
}
int main(void) {
static const uint8_t seed[] = "sfinx reuse seed";
uint8_t path1[] = {0x0a};
uint8_t path2[] = {0x0a, 0x1b};
- uint8_t pub1[SFINX_HASH_LEN_MAX];
- uint8_t pub2[SFINX_HASH_LEN_MAX];
uint8_t sig1[4096];
uint8_t sig2[4096];
size_t len = sfinx_hash_len(SFINX_HASH_256);
size_t seed_len = strlen((const char *)seed);
size_t n1 = sfinx_signature_len(SFINX_HASH_256, 1);
size_t n2 = sfinx_signature_len(SFINX_HASH_256, 2);
+ size_t linked;
tap_begin("sfinx cross-length key reuse");
- layer1_pubkey(seed, seed_len, 1, path1[0], pub1);
- layer1_pubkey(seed, seed_len, 2, path2[0], pub2);
- tap(memcmp(pub1, pub2, len) != 0, "layer-1 key differs across path lengths", "one key serves both");
-
tap(sfinx_tree_sign(SFINX_HASH_256, seed, seed_len, path1, 1, (const uint8_t *)MSG, MSG_LEN, sig1, n1, NULL) ==
SFINX_OK,
"N=1 signs", "sign failed");
@@ -45,8 +52,8 @@ int main(void) {
tap(memcmp(sig1 + n1 - 8 * len, sig2 + n2 - 8 * len, 8 * len) != 0, "layer-1 auth paths differ across path lengths",
"auth paths are identical");
- tap(memcmp(sig1 + 3, sig2 + n2 - (len + 10) * len, (len + 2) * len) != 0, "layer-1 proofs are not a reuse pair",
- "proofs come from one key");
+ linked = chains_linked(SFINX_HASH_256, sig1 + 3, sig2 + n2 - (len + 10) * len, len, len + 2);
+ tap(linked == 0, "layer-1 proofs do not chain onto each other", "%zu of %zu chains link", linked, len + 2);
return tap_plan();
}
diff --git a/test/Makefile b/test/Makefile
@@ -3,6 +3,10 @@ CFLAGS ?= -Wall -Wextra -O2
CFLAGS += -I.. -I../src -I../lib/.dep/include
CFLAGS += -pthread
+ifneq ($(SFINX_VERSION),)
+CFLAGS += -DSFINX_VERSION='"$(SFINX_VERSION)"'
+endif
+
include ../lib/.dep/config.mk
OUT := ../build/test