Files
zeekay 08a45df14c p3q-sha3 + p3q-gpu-sha3: pluggable Sha3Backend for libluxgpu 0.4 FFI
Adds a Sha3Backend trait in p3q-sha3 with CPU + GPU impls. The CPU
backend is the audited FIPS 202 reference (sha3 crate); the GPU
backend (new crate p3q-gpu-sha3) dlopens libluxgpu and dispatches
through lux_gpu_sha3_256_batch / lux_gpu_shake256_batch. Transparent
CPU fallback whenever dlopen fails, GPU context creation fails, or
libluxgpu panics inside FFI (catch_unwind boundary). KAT parity
enforced against FIPS 202 reference vectors.

The verifier opts in via --features gpu-sha3. Per-query Merkle
authentications fan out into one verify_proof_batch per Merkle root
(trace + each FRI layer); the backend gets one call per root rather
than O(num_queries * log N) serial hashes. CpuShake overrides
tuple_hash256_batch with a streaming impl that avoids per-input
payload allocations — the CPU-only build is now 1017 us/iter
(down from 1308 us serial baseline on the toy AIR).

libluxgpu 0.4 exposes SHAKE256 (0x1F domain) but not cSHAKE256 (0x04),
so the audited transcript binding (cSHAKE / TupleHash / KMAC) still
runs on CPU. The wiring is in place: when libluxgpu adds a native
cSHAKE batch the override drops into p3q-gpu-sha3 with zero verifier
change.

Hard constraints honoured:
- p3q-sha3 stays #![forbid(unsafe_code)]; p3q-gpu-sha3 is the
  second `unsafe`-allowed crate (alongside p3q-c-abi), each unsafe
  block paired with catch_unwind
- GpuShake field order is load-bearing: `gpu` drops before `lib` to
  avoid use-after-free on the destroy fn-ptr at shutdown
- transcript bytes UNCHANGED — Sha3Backend contract guarantees
  byte-identical output on every backend
- 101/101 workspace tests pass with and without --features gpu-sha3

Bench (toy AIR, 256-iter avg, three runs each):
  CPU-only:        1015.2 / 1018.6 / 1017.4 us/iter
  --features gpu-sha3: 1010.3 / 1020.0 / 1019.4 us/iter
2026-05-31 01:24:42 -07:00

28 lines
1.1 KiB
TOML

[package]
name = "p3q-gpu-sha3"
description = "P3Q SHA3-256 / SHAKE256 GPU backend (libluxgpu 0.4 FFI). Optional plug-in for p3q-sha3 when --features gpu-sha3 is enabled."
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true
rust-version.workspace = true
keywords = ["sha3", "shake256", "gpu", "ffi", "post-quantum"]
categories = ["cryptography", "external-ffi-bindings"]
[dependencies]
p3q-sha3 = { workspace = true }
# dlopen-based FFI: the libluxgpu.dylib / .so is loaded at runtime, not
# linked at build time, so that p3q binaries stay portable across hosts
# that may or may not have the GPU library installed.
libloading = "0.8"
# This crate is the ONE place in the workspace where `unsafe` is
# unavoidable: dlsym'd C entry points return `*mut LuxGPU` opaque
# pointers and consume raw `*const u8` buffers. Every unsafe block is
# paired with a `catch_unwind` boundary so a libluxgpu panic NEVER
# crosses the FFI seam back into the audited verifier.
[lints.rust]
unsafe_code = "allow"