Fixed user-key derivation example

This is a proposed application protocol for deriving a 32-byte user key from already available secret material. It does not produce RFC 5869 HKDF outputs or implement the RFC 9180 HPKE key schedule. Existing protocol consumers must keep their specified KDF. BLAKE3 replaces the derivation stage only; X25519 agreement still produces the secret material. No password stretching or low-entropy-secret protection is added.

The construction is exactly standard BLAKE3.derive_key("rsx.user-key.v1", secret_material32 || user_id32). The context is the 15 literal UTF-8 bytes shown, without a terminator. Both input fields are exactly 32 bytes, secret first; output is exactly 32 bytes. Caller code supplies an already canonical binary user identifier. No variable-width text, principal encoding, length guessing or ambiguous concatenation is used. Changing the domain, field widths or order defines a different protocol. The literal domain is frozen for reproducible benchmark comparisons. Each real application must choose a globally unique context identifying its application and purpose, as required by the standard BLAKE3 derive-key API. This example domain is not a universal user-key namespace. The general blake_candidates::Blake3DeriveKey::new(context) and .derive(material) API continues to accept caller-selected domains and arbitrary-length material.

user_kdf::Blake3UserKey::prepare_public_domain() computes only the public derive-context hash. fixed_public_domain() instead uses its checked constant: 689195c7a6e31f2226263310d8e6c5bbf85e5c6c204c9467255bcd2b3468ef50. This is hash_derive_key_context(domain), never ordinary hash(domain) and never a secret key. The official BLAKE3 API explicitly permits retaining this public context hash, including hardcoding it. The native example reproduces the bytes and tests independently verify them.

Blake3UserKey is the intentional generic algorithm reference for benchmarks and controls. Each .derive() constructs one exact 64-byte stack input and uses the selected upstream compression backend with standard material/start/end/root flags and counter zero. .derive4() constructs four independent 64-byte stack inputs and calls the existing four-lane kernel; it never hashes a concatenation of users. Owned material buffers and scalar chaining state are explicitly wiped. Callers own their input and output copies; compiler temporaries are not covered by a complete-erasure promise. The object retains only the public domain context.

For this fixed domain and exact secret32 || user_id32 material, use h::blake_candidates::user_derive4::derive4, also reexported as h::user_kdf::derive4, for groups of four independent users on the canonical Wasm SIMD build. It loads both borrowed fields directly into message-word vectors, avoiding joined byte buffers and generic chunk finalization. All owned message, state and output-word vectors are wiped; only caller-owned outputs survive. It precomputes only the public context and retains no secret state. The SIMD implementation notes describe its exact contract.

Actual IC qualification supports this recommendation for N100: twenty-five four-user groups inside one call, with every full output checked. The helper requires exactly four typed pairs; process each remaining one to three users with the generic scalar .derive() rather than padding dummy users. Other batch sizes have correctness coverage without a measured performance threshold. Native and feature-disabled builds use the scalar lane model, so the measured Wasm SIMD ranking does not apply to them. Caller-selected application domains continue to use Blake3DeriveKey::new(context); the fixed-domain fast helper does not silently substitute this example domain for theirs.

The direct scalar experiment lost its matched actual-IC comparison and was removed. Its source patch, costs and artifact pins are preserved in the experiment record. That record separates the SIMD kernel gain from changes to artifact page layout. Current instruction costs belong in the maintained benchmark table.

The official specification defines the two-stage derive-key mode, single-chunk root flags and KDF usage. The official README describes public application contexts and non-password key material. No new compression algorithm, SDK behavior or allocator is introduced here.

Measurement contract

benches/crypto/cases/src/user_kdf_blake3.rs stages only raw synthetic IKM/ID values and independent expected answers. All scalar/four-way paths construct their material inside run, retain every complete output and check all users after timing. Case size must be 32, the canonical user-ID width shared with HKDF619. Actual derive-key material remains 64 bytes (IKM32 || ID32), and actual batch is 1..500; N100 is the primary population. The driver sees one grouped invocation for exactly N logical user derivations. Four-way tails execute the remaining users individually, without duplication.

Primary distinct-secret cases use independent synthetic preexisting 32-byte material representative of X25519 outputs. No X25519 calculation is measured or claimed. Secondary shared-master cases use one common raw master with varying IDs and the same derive-key protocol. Public deterministic fixture values do not constitute production entropy. The earlier distinct keyed-PRF experiment remains in frozen commits e2970c70 and ad39176b; its bespoke helpers and cases are removed from the supported user-KDF surface.

Fixture bytes exactly match the HKDF619 user-key cohort: xorshift13/7/17 emits each low byte from seed (seed ^ 0xc127893e568b23a9) + index with wrapping u64 arithmetic for distinct secrets, or index zero for a shared master. ID bytes 0..8 contain the big-endian fixture seed, bytes 8..24 are zero, and bytes 24..32 contain big-endian index+1 when distinct=true, otherwise one.

fresh-context hashes the public domain for every user. domain-in-call hashes it once inside every measured call; the SIMD variant includes that same work. Only fixed-public-domain variants exclude runtime domain hashing, by using the validated public build-time constant. No user result, secret-dependent prefix, master schedule or validated user context is cached across calls. Actual IC instruction/page qualification remains separate from native correctness checks. The paired generic-paired-simd4 and direct-parts-simd4 cases use identical fixture layouts, corpora and complete-output checks to compare the generic control and direct helper. Their generic wrapper remains unchanged so the control continues to exercise its own algorithm.