Experimental session PRGs
cdk-rsx-crypto-prg provides caller-seeded ChaCha8/12 game profiles and a
ChaCha20 control. It performs no allocation, entropy acquisition, IC call,
networking, persistence, or OT operation. The existing garbled-circuit BLAKE3
suite is unchanged. These profiles deliberately produce different bytes and
have separate identifiers; none claims that suite's compliance or malicious OT
security.
| Profile | Rounds | BLAKE3 derive-key context |
|---|---|---|
game-prg-chacha8-v1 |
8 | p2p-gc-bench/game-prg/chacha8/v1/session-key |
game-prg-chacha12-v1 |
12 | p2p-gc-bench/game-prg/chacha12/v1/session-key |
control-prg-chacha20-v1 |
20 | p2p-gc-bench/game-prg/chacha20-control/v1/session-key |
Session::new(seed, &session_id, profile) derives one private 32-byte key using
the named BLAKE3 context over exactly seed[32] || session_id[32]. Session
preparation is a separate operation from subsequent stream construction and
fills. session.stream(query, purpose_byte) initializes the selected IETF
ChaCha variant at block counter zero, with the 12-byte nonce
LE64(query) || purpose_byte || [0; 3]. There is no per-query BLAKE3 work.
Stream::fill(&mut output) overwrites every byte, regardless of its previous
contents, and preserves byte-for-byte chunking equivalence. It checks its
u64 byte-position addition and the complete IETF limit of 2^32 * 64 bytes
before modifying output or advancing state. Empty fills are no-ops, including
at the terminal position. Session::stream_at(query, purpose, position) starts
an independent owner at an explicit position in the same stream. It generates
at most 63 skipped bytes into wiped scratch, and rejects positions past the
limit. It does not introduce fresh randomness or authorize a replacement
query identity.
Session::fill_secrets(first_query, purpose, &mut [[u8; 32]]) fills independent
consecutive query domains in one call. Each output exactly matches the first
32 bytes of its ordinary stream. SIMD processes four different queries at once;
it never substitutes one long stream for those independent domains. Query-range
overflow rejects before writing any byte; empty output succeeds even at the
last query ID. No allocation or entropy call occurs.
The native cipher wrapper's checked API reserves the final counter block.
The public stream owns the complete byte-domain check before invoking either
private overwrite backend. The underlying counter can wrap only after
generating its final valid block; the private position then permits at most
that block's cached remaining bytes and rejects any subsequent nonempty fill.
No public mutable seek or raw cipher access can bypass this guard.
Session and stream owners have private state and no Clone, Debug or Serde
implementation. The caller must provide private entropy and avoid repeating
query/purpose domains for independent logical work. Fixed benchmark seeds are
public fixtures. Session-key compromise exposes every stream in that session;
these primitives provide no reseeding, forward secrecy or backtracking
resistance. A TEE's confidentiality and entropy guarantees belong to the host
threat model, outside this crate.
Session keys, temporary KDF state, temporary cipher-key copies, cipher state
and buffered keystream have wiping owners. Explicit cipher/zeroize and
chacha20/zeroize features cover the buffer and core respectively. A
compile-time trait check prevents removing those cleanup features silently.
The tests inspect the actual dropped session-key bytes in retained storage;
they also require upstream drop-wiping contracts for every cipher variant.
Compiler spills, registers and caller-owned copies/output are outside that
source-level guarantee.
The implementation pins RustCrypto ChaCha 0.10.2
and cipher 0.5.2,
both MIT OR Apache-2.0. Their established ARX arithmetic has no secret-indexed
lookup tables. The featureless control uses the portable scalar backend. Enable wasm-simd
for row SIMD on individual blocks and four-counter SIMD on bulk output.
The public byte stream, nonce convention and counter limits remain identical.
The Wasm64 feature uses the repository's pinned nightly compiler; no native
cryptography host calls are involved. Fixed-size unaligned vector loads/stores
and volatile vector wiping are confined to one private module. The native path retains the upstream wrapper. The SIMD path uses a private
overwrite/cache owner, writes complete tail rows directly to the caller, and
reuses counter-independent work across bulk groups. Both preserve the same
public stream preflight, exact byte sequence and drop wiping. The
original ChaCha paper
introduces the 8/12/20-round family. RFC 8439
defines the 20-round IETF construction; it does not standardize the reduced
round profiles here. Reduced-round security margins are an explicit
experimental choice, with no new quantitative security claim from this work.
Tests include 88 pinned Botan vectors covering all three round counts, an independent test-only scalar interpreter, KDF/profile/query/purpose separation, overwrite/chunking/continuation, and the final full and partial counter blocks. UPSTREAM.json records exact revisions, URLs and file hashes. The fixture's original 64-bit nonces are extended with a leading zero word only where this produces the identical initial IETF state throughout the tested counter domain; this conversion exists only in test data. The Botan license accompanies its original and extracted fixtures.
See the measured function table for actual IC scalar/SIMD comparisons. Complete-output differential probes include the last four counter blocks. Secret-generation body costs and full checked benchmark updates are distinct; session preparation remains separate. No performance improvement is inferred from the round count alone.