code wiki / (root) / nx_ml_kem_768.nx

nx_ml_kem_768.nx

buildroot/runtime/nx_ml_kem_768.nx

5515 B138 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic ml
docsdependenciesstructsconstsfunctions

about

ml_kem_768.nx -- ML-KEM-768 post-quantum key encapsulation. NIST FIPS 203 (August 2024). Lattice-based (Module-LWE), security category 3 (AES-192 equivalent against both classical and quantum adversaries). Drop-in replacement for the X25519 key-exchange primitive we ship today -- X25519 is broken by Shor's algorithm once a sufficiently large fault-tolerant quantum computer exists. ML-KEM stays secure even then. Parameters (FIPS 203 Table 2, ML-KEM-768): n = 256 polynomial degree q = 3329 modulus k = 3 module rank eta1 = 2 secret / error distribution parameter eta2 = 2 noise distribution parameter d_u = 10 ciphertext compression (u part) d_v = 4 ciphertext compression (v part) Key / ciphertext sizes: public key = 1184 bytes secret key = 2400 bytes ciphertext = 1088 bytes shared secret = 32 bytes Status (2026-04-23): SKELETON. Structures + API signatures + test vectors scaffolded. Heart of the impl -- NTT over Z_3329[x]/(x^256+1), sample_poly, compress/decompress, K-PKE wrapping -- is bounded ~600 LoC port from the NIST reference and will ship next. Dependencies: - sha3.nx (shipped) for SHAKE-128/256 + SHA3-256/512 - rand.nx (shipped) for 32-byte randomness at keygen + encap Invariants: ML1 Output bytes match FIPS 203 Appendix A test vectors. ML2 Constant-time critical paths (sample_ntt / compress / decapsulate re-encrypt) -- no secret-dependent branches. ML3 Zero dynamic allocation in decap hot path (fixed-size buffers) for embedded deployability.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_ml_kem_768.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap ml_kem_768_keygen ml_kem_768_encaps ml_kem_768_decaps

structs

none

consts

68const MLKEM_N: i64 = 256
69const MLKEM_Q: i64 = 3329
70const MLKEM_K: i64 = 3
71const MLKEM_ETA1: i64 = 2
72const MLKEM_ETA2: i64 = 2
73const MLKEM_DU: i64 = 10
74const MLKEM_DV: i64 = 4
76const MLKEM_PK_BYTES: i64 = 1184
77const MLKEM_SK_BYTES: i64 = 2400
78const MLKEM_CT_BYTES: i64 = 1088
79const MLKEM_SS_BYTES: i64 = 32
81const MLKEM_ERR_PENDING: i64 = -1
82const MLKEM_ERR_RANDOM: i64 = -2
83const MLKEM_ERR_DECAP: i64 = -3

functions

91func ml_kem_768_keygen(pk_out: *u8, sk_out: *u8) -> i64
called by 1: main
104func ml_kem_768_encaps(pk_in: *u8,
called by 1: main
117func ml_kem_768_decaps(sk_in: *u8, ct_in: *u8,
called by 1: main
127func main() -> i64