feat(permutation): batch key derivation API (plan step 1) - #283
Open
coderdan wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 tofrom_seed— independent derivation, independentSeedRejectedoutcome (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.random_permutationnow fills its random words via chunkedfill_bytes(64 words per call) instead of onenext_u64call 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 thatfill_bytesconsumes the ChaCha20 keystream identically to repeatednext_u64calls 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-seedfrom_seed, order pinned via distinct seedsbatch_of_nothing_is_emptytest_fill_bytes_matches_next_u64_stream: 512-byte fill vs 64next_u64calls, word-by-wordNot in this PR (later steps)
SCHEDULE_256for 8-bit ORE blockshttps://claude.ai/code/session_012cUAnQ2qY9RD5TaAKyZpUm