# DF-3566 — SipHash24_TestVectors trips SipHash KASSERT → INVARIANTS-kernel panic

## What

`sys/crypto/siphash/siphash_test.c` runs its 64-vector table starting at the
**empty-message** vector (i=0). For i=0 it calls `SipHash_Update(&ctx, in, 0)`.
`sys/crypto/siphash/siphash.c` asserts `(!final && len > 0) || (final && len == 0)`
in `SipBuf()` (siphash.c:92) — a zero-length non-final update is a contract
violation and panics any kernel built with INVARIANTS.

Reachability today: **none through any shipped build** — `siphash_test.c` is in
no build target (not in `sys/conf/files`, not in `sys/crypto/Makefile`); nothing
in-tree references `SipHash24_TestVectors()` except its own header declaration.
It is developer/test-harness code: anyone who wires it into an INVARIANTS
kernel (its documented purpose) gets an immediate panic at module init/test
start. Severity Low: local DoS, developer-facing, dead code by default.

## Build (module, in-guest)

    # /tmp/sipmod/Makefile:
    KMOD=   siphashtest
    SRCS=   trigger.c siphash_test.c
    SYSDIR=/usr/src/sys
    .include "${SYSDIR}/conf/kmod.mk"

    cd /tmp/sipmod && make

`trigger.c` is a 25-line DEV/DECLARE_MODULE shim whose MOD_LOAD handler calls
`SipHash24_TestVectors()`. `siphash_test.c` is the unmodified kernel source
(md5 3b580668a665816235b2c715bb293734, identical to the audited tree).

## Run (baseline — expect panic)

    kldload /tmp/sipmod/siphashtest.ko

Expected: `panic: SipBuf: invalid parameters`, DDB prompt `db>`, ssh dead.
Observed: exactly that — see `panic.txt` for the full serial-console trace
(SipHash24_TestVectors → SipHash_Update → SipBuf → panic).

## Run (patched — expect all vectors pass, no panic)

Same module with `siphash_test_fixed.c` (`if (i > 0)` guard around the Update):

    kldload /tmp/sipmod_fixed/siphashtest_fixed.ko

Observed: `siphashtest: calling SipHash24_TestVectors()` /
`siphashtest: result=1 (no panic)` in dmesg, clean `kldunload`, guest healthy
(`kldload_fixed.log`). result=1 means **all 64 vectors match in-kernel**.

## Userland cross-check

`siphash_kat.c` compiles the unmodified `siphash.c` + `siphash_test.c` as
userland objects (shim for `sys/systm.h`/`sys/libkern.h` only):

- abort-style KASSERT shim → `KASSERT FAILED: (!final && len > 0) ...`,
  SIGABRT (run.userland.log) — same trip, no kernel needed.
- warn-style shim → `KASSERT-WARN` once, then
  `SIPHASH24_TESTVECTORS=1 (ALL 64 VECTORS MATCH)` (run.userland.warn.log):
  with the assertion bypassed the empty-message vector computes correctly
  (SipBuf is a functional no-op for len==0), so the vector table itself is
  sound and the one-line guard is the complete fix.

## Environment

DragonFly dfbsd 6.5-DEVELOPMENT #0 (X86_64_GENERIC, INVARIANTS) — see
`env.txt`. Guest restored with `vm.sh reset with-src` after the panic runs.
