Skip to content

feat(permutation): batch key derivation API (plan step 1) - #283

Open
coderdan wants to merge 1 commit into
feat/280-oblivious-shufflefrom
feat/batch-permutation-derivation
Open

feat(permutation): batch key derivation API (plan step 1)#283
coderdan wants to merge 1 commit into
feat/280-oblivious-shufflefrom
feat/batch-permutation-derivation

Conversation

@coderdan

Copy link
Copy Markdown
Contributor

Step 1 of the batch/SIMD plan for #280 follow-up. Stacked on #282.

What

  • PermutationKey::from_seeds: derives one key per seed, in order, each lane exactly equivalent to from_seed — independent derivation, independent SeedRejected outcome (a rejected seed invalidates only its own lane). Exists for bulk workloads (ORE batch encryption per-block permutations) and fixes the API shape so a future vectorized backend can derive lanes in parallel while staying bit-identical to scalar derivation.
  • Bulk-filled packing: random_permutation now fills its random words via chunked fill_bytes (64 words per call) instead of one next_u64 call per word — cuts per-call RNG overhead, no output change.

Why output is provably unchanged

test_fill_bytes_matches_next_u64_stream (vitaminc-random) pins that fill_bytes consumes the ChaCha20 keystream identically to repeated next_u64 calls under little-endian interpretation. If a rand/chacha upgrade ever changes stream consumption, that test fails loudly. The permutation README doctests (seeded, hardcoded outputs) also still pass unchanged.

Tests

  • batch_matches_single_seed_derivation: batch output equals per-seed from_seed, order pinned via distinct seeds
  • batch_of_nothing_is_empty
  • test_fill_bytes_matches_next_u64_stream: 512-byte fill vs 64 next_u64 calls, word-by-word

Not in this PR (later steps)

https://claude.ai/code/session_012cUAnQ2qY9RD5TaAKyZpUm

Add PermutationKey::from_seeds, deriving one key per seed with per-seed
SeedRejected outcomes, so bulk workloads (ORE batch encryption) get a
stable API shape that a future vectorized backend can implement without
changing derived output.

Pack the shuffle's random words with chunked fill_bytes instead of one
next_u64 call per word. A pinned test in vitaminc-random proves the two
consume the keystream identically, so seed-derived keys are unchanged.

Claude-Session: https://claude.ai/code/session_012cUAnQ2qY9RD5TaAKyZpUm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant