c-xwing — Hybrid Post-Quantum KEM (ML-KEM-768 + X25519)
Abstract
Freestanding, zero-allocation C11 implementation of X-Wing
(draft-connolly-cfrg-xwing-kem), NIST FIPS 203 ML-KEM-768, RFC 7748 X25519,
and FIPS 202 SHA-3/SHAKE (~930 LOC total).
1. Hybrid Construction¶
KeyGen(seed[32]): (d_M, z_M, sk_X) = SHAKE256(seed, 96) (pk_M, sk_M) = ML-KEM-768.KeyGen_internal(d_M, z_M) pk_X = X25519(sk_X, 9) pk = pk_M (1184 B) || pk_X (32 B) [1216 B] Encaps(pk, eseed[64]): (ct_M, ss_M) = ML-KEM-768.Encaps_internal(pk_M, eseed[0..32]) ct_X = X25519(eseed[32..64], 9) ss_X = X25519(eseed[32..64], pk_X) ss = SHA3-256(ss_M || ss_X || ct_X || pk_X || "\./" || "/^\") ct = ct_M (1088 B) || ct_X (32 B) [1120 B]
2. Design Notes¶
-
Defense-in-depth & crypto-agility: combines module-lattice security
(ML-KEM-768) with Curve25519 behind a uniform zero-allocation
xw_kem_vtable_tinterface, allowing protocols to swap KEMs cleanly. -
Division-free constant-time math: reductions mod
q = 3329and ciphertext compression (d = 1, 4, 10) use 40-bit Barrett multiplication with compiler optimization barriers—zero hardwaredivinstructions or secret-dependent branches. - 5-limb radix-2^51 X25519: uses 128-bit limb products on 64-bit hosts with an ISO C11 32-bit fallback for Cortex-M4 targets, plus an 11-multiply addition chain for field inversion.
3. Verification & Benchmarks¶
- Standard KATs
- NIST ACVP FIPS 203 (KeyGen, Encaps, Decaps, Implicit-Reject, KeyCheck), RFC 7748, IETF X-Wing (3/3)
- Timing
- dudect |t| = 0.25 (Decaps valid vs reject) and |t| = 0.95 (X25519), N = 40,000
- Performance
- ML-KEM Encaps 55 us (133k cyc); X-Wing Encaps 126 us (305k cyc), Decaps 109 us (258k cyc)
- Footprint
- ~930 LOC C11, 0 heap/OS symbols, compiles freestanding on x86_64 and ARM Cortex-M4