Garbled-circuit functions

Portable cryptographic building blocks for honest-execution garbling, with no IC imports, networking, game logic or ambient randomness. The fixed balanced eight-bit equality circuit is a correctness and composition fixture, not an application or a maliciously secure computation protocol.

The core provides 128-bit labels, Free-XOR/NOT, little-endian GF doubling, cached public-zero-key AES-128 hashing, ZRE Half-Gates and BLAKE3 derive-key/XOF private randomness. Each AND emits exactly tg || te (32 bytes), using four garbler hashes and two evaluator hashes. Default AES uses RustCrypto's portable constant-time software backend in Wasm; it is not a native crypto host call.

For the qualified IC engine, enable wasm-xof4 and aes-narrow. One/two/four AES blocks use the optional byte-vector kernel; eight-block batches retain the Boolean kernel. This choice requires hardware register-swizzle lowering for secret indices, as recorded in the supported-engine review. The independent aes-simd Boolean control uses no secret shuffle indices. The construction, labels and tables stay unchanged. batched-aes without aes-simd is the four-lane AES64 control; the featureless equations are the readable scalar control. The dominated GC AES32 selector was removed; the general-key AES32 primitive remains a separate measured reference.

For consecutive independent 32-byte secrets, wasm-query-batch additionally enables four-query BLAKE3 SIMD scheduling. It preserves the frozen suite and each stream's bytes; this differs from expanding four XOF blocks of one stream. The feature is opt-in. Native and feature-off builds use the same API with independent per-query readers. Lengths one through six also use those readers in the SIMD build; the measured dispatch cutoff is seven. Empty and query-range checks still finish before any output write.

Prepare a private seed/session prefix once, then create per-query streams:

use cdk_rsx_crypto_garbled_circuit::{PrgSession, Purpose};

let session = PrgSession::new(secret_seed, &session_id);
let mut stream = session.stream(query_id, Purpose::Garbling);
let mut secret = [0u8; 32];
stream.fill(&mut secret)?;

let mut secrets = [[0u8; 32]; 100];
session.fill_secrets(first_query_id, Purpose::Garbling, &mut secrets)?;

Batch output i equals the first 32 bytes of session.stream(first_query_id + i, purpose). The complete query range is checked before any write; overflow returns Error::PrgExhausted with all outputs unchanged. Empty batches succeed, including at u64::MAX. The caller owns the borrowed outputs and must erase them when no longer needed.

Each (session, query, purpose) must be unique for new material under a seed. The prepared owner retains only a secret chaining value and backend selector; it has no allocator or persistence dependency. prepare_equality8_with_session uses it for fresh garblings. Seed acquisition and durable query-ID management belong to the caller; this library makes no IC randomness calls.

Alice's pairs, offset and output secret have no public cloning, debugging or serialization. Bob receives only active labels and tables. Output recognition compares both candidates in constant time and consumes Alice's state. The caller supplies fresh secret seeds and query identities; fixed seeds belong only to tests and explicitly identified benchmark fixtures. Secret wiping is best effort and cannot erase copies a caller has made.

Use the low-level functions independently, or the equality helpers for tests. The test harness may select labels directly to test gates; that is not OT. The OT profile owns backend pins, parameters, checks and qualification status. No unqualified or simulated backend is exposed as a working chosen-message OT implementation.

suite.txt fixes the baseline construction and byte conventions; suite::id() hashes its exact UTF-8 bytes with BLAKE3. The allocation-free frame helpers encode and check a bounded 84-byte public header. Framing is not authentication, and callers remain responsible for authenticated peer identities, phase transitions, freshness and one-time material consumption.

The benchmark owns reproducible native tests, actual IC measurements, JSON/CSV evidence and the list of blocked cases. Independent fixtures come from Python integer equations and OpenSSL AES, rather than the Rust implementation under test. The instrumented build checks structural operation counts separately from the primary cost artifact. The optimized cost table compares matched kernel variants and retains whole-call costs alongside the crypto-body counters.

This fixed-key AES/128-bit-label baseline does not establish 128-bit security for unlimited instances. Malicious OT alone would not provide malicious garbling security, selective-failure protection or proof that a player's input matches external state. See R1 and R6. Signatures and authenticated envelopes remain separate reusable components and are excluded from gate costs.

evaluate_and_two fills one four-block AES batch with two independent gates. The fixed equality evaluator pairs each independent tree level while retaining all seven gates and 14 hashes. free_xnor and evaluate_xnor avoid temporary XOR/NOT owners; their bytes and logical operation counts match the separate operations. The readable featureless equations remain the reference control.

garble_and_two shares one eight-hash batch across two independent gates. The fixed equality helper pairs both garbler and evaluator tree levels without adding gates or changing tweaks. Every retained wire pair and hash owner keeps its normal wiping lifetime.