Static private geometry circuit functions
cdk-rsx-crypto-private-los is a reusable no_std + alloc circuit compiler and
staged Free-XOR/Half-Gates runtime. It ships MAP_0, MAP_4, MAP_16, MAP_64,
PROXIMITY_1, PROXIMITY_2, PROXIMITY_4, EQUALITY_8 and the separately named
SELECTOR_256 comparator. Public geometry compiles during the build; online
secret decisions execute only the generated Boolean circuit. There is no game
application, IC dependency or runtime circuit registry.
These are honest-execution circuit functions. The crate supplies no OT, authentication, entropy source, input binding or malicious-party protocol. Measured IC stage costs remain separate from the unavailable full private protocol.
A position byte is x | (y << 4), with x/y in 0..15. Its doubled tile centre is
(2*x+1, 2*y+1). The proximity programs use integer tile coordinates directly:
abs(ax-bx) <= R && abs(ay-by) <= R, with the public radius fixed to 1, 2 or 4
at compilation. This is a closed axis-aligned square: the diagonal offset
(R,R) is included. Distances do not wrap at the grid edges. The programs have
distinct names private_proximity_2d/radius-1, private_proximity_2d/radius-2
and private_proximity_2d/radius-4, with no walls or visibility-mask inputs.
LOS walls are closed axis-aligned segments with integer vertices in 0..16, doubled before geometric interpretation. Endpoint contact blocks; identical positions are visible. All 256 position bytes are valid. The exact 0/4/16/64 maps are reproducible prefixes in maps.rs, with no duplicate segments or outer-boundary-only shortcuts.
| Program | AND | XOR | AND depth | Live Alice/Bob bits | Request payload |
|---|---|---|---|---|---|
| MAP_0 | 0 | 0 | 0 | 0/0 | 16 B |
| MAP_4 | 276 | 533 | 18 | 8/8 | 8,960 B |
| MAP_16 | 703 | 1,234 | 20 | 8/8 | 22,624 B |
| MAP_64 | 2,265 | 3,527 | 22 | 8/8 | 72,608 B |
| PROXIMITY_1 | 17 | 32 | 8 | 8/8 | 672 B |
| PROXIMITY_2 | 17 | 32 | 8 | 8/8 | 672 B |
| PROXIMITY_4 | 17 | 28 | 8 | 8/8 | 672 B |
| EQUALITY_8 | 7 | 8 | 3 | 8/8 | 352 B |
| SELECTOR_256 | 255 | 510 | 8 | 256/8 | 12,256 B |
These are static compiler counts and exact payload sizes, separate from runtime cost measurements. Every proximity program uses eight logical chosen-label OTs, has no constant label, and constructs a 756-byte request frame and 100-byte reply frame: 856 bytes across both directions before external OT/authentication. The proximity benchmark records its separate stage-measurement scope.
LOS declares eight input bits per party. Dead inputs require neither active labels nor logical OT. The empty map is constant true: it sends one random active constant label, with complemented output meaning and no exposed delta. The selector consumes arbitrary 256-bit Alice data and an eight-bit Bob index. It does not generate a LOS visibility mask; preprocessing is unmeasured in its benchmark comparison.
Alice stages the caller-owned buffers and private owners before online work.
The caller supplies private seed material and a unique query domain under the
session; repeating a domain repeats randomness. PackedBits borrows exact
length packed bytes, least-significant bit first.
use cdk_rsx_crypto_private_los::*;
let program = &MAP_16;
let session = PrgSession::new(private_seed, &session_id);
let hasher = GateHasher::new();
let mut scratch = AliceWorkspace::new(program);
let mut material = RandomMaterial::new(program);
let mut query = AliceQuery::new(program);
let mut request = GarbledRequest::new(program);
material.fill(&session, unique_query_id)?;
garble_into(program, &hasher, &mut material,
PackedBits::from_byte(&alice_position), &mut scratch, &mut query, &mut request)?;
let sender_inputs = query.ot_sender_inputs()?;
// Give these live input indices and pairs only to an actual OT sender.
Bob receives the request payload and his live labels through an external OT adapter. He never receives Alice's pairs, global delta or output map.
let request = RequestView::parse(program, &request_payload)?;
let mut labels = BobLabels::new(program);
labels.receive(&chosen_labels_from_ot)?;
let mut scratch = BobWorkspace::new(program);
let mut output = OutputLabel::new();
evaluate_into(program, &hasher, &request, &labels, &mut scratch, &mut output)?;
encode_output_into(&output, &mut reply_payload)?; // exactly 16 bytes
Alice alone recognizes the complete returned label with
query.decode(parse_output(&reply_payload)?). Decode consumes the private output
map even on rejection. Random material is also single-use. Workspaces are
cleared during each operation and can be reused for sequential queries; live
private query owners and unresolved protocol identities remain caller-owned.
Private owners have no Clone, Debug or serialization and perform explicit
best-effort wiping. Caller copies, compiler spills and registers are outside
that guarantee.
Payload encoders write exact caller-sized buffers; borrowed parsing does not
construct a second payload. Framed APIs reuse the existing 84-byte header.
Authenticate frames and bind the expected header to the exact public program,
map, session and query. The benchmark's separate application descriptor hash
shows this binding; the primitive equality-suite identity alone is insufficient
for distinct map or proximity-radius contracts. Each reply is 16 payload bytes
or 100 framed bytes.
The fixture-label-selection feature permits local correctness-harness label
selection only; it is not OT.
The compiler shares signed five-bit dx/dy and the determinant expression
T = 2*(ax*by-bx*ay) + dy-dx. Reduced orientation at public vertex (k,l) is
T + 2*dx*l - 2*dy*k. This expression is affine in each of its six coordinates,
so its extrema occur at the 64 corners of their coordinate box: exactly
[-480,480]. Signed ten bits therefore suffice. Intermediate arithmetic is
modulo 2^10 and only the exact final sign/zero is tested. The build also compares
ten-bit and conservative twelve-bit circuits over all 65,536 position pairs per
map. The frozen compiler proof
and independent review
record the widths, constant folding, dead-gate removal, sharing and AND-depth
schedule. Complemented edges make NOT free; adjacent independent ANDs reuse the
existing paired kernels.
For proximity, zero-extending each four-bit coordinate before subtraction gives
an exact signed five-bit difference in [-15,15]. For R=2^k, bits above k
must equal the sign; bit k either matches the sign or denotes the single
allowed positive boundary +R, whose lower bits must all be zero. The radius-1
case simplifies its low-bit boundary directly. A zero low difference is tested
by equality of input residues, allowing unused low sum gates to disappear.
The existing complemented edges, constant folding, sharing, dead-gate removal
and balanced reductions produce the circuits above. This does not claim a
globally minimal circuit.
Build checks compare every one of the 65,536 position pairs per radius against
ordinary integer subtraction and absolute value. The dedicated
proximity tests independently check the generated programs
over all 196,608 pairs, including grid edges, identical positions and square
corners. With fixture-label-selection, they also exercise complete
Alice-to-Bob-to-Alice frames at boundary and representative inputs, exact logical
counts, fresh queries and single-use output maps. The shared runtime's existing
role separation and best-effort wiping apply without a separate crypto path.
Native independent geometry checks cover all 262,144 map/position pairs.
Installed-Wasm and independent OpenSSL/noble byte reconstruction qualify complete
frames; a separate instrumented image checks logical gates and hashes. The
benchmark guide documents timing boundaries,
actual N1/10/100, exact bytes and blocked IC OT. Default features stay portable;
optional wasm-simd, wasm-xof4, wasm-query-batch, batched-aes, aes-simd and
aes-narrow forward existing GC backends. Narrow AES retains its supported-engine
hardware register-swizzle assumption.