Skip to main content

quantaegis_ml_kem/
params.rs

1//! NIST FIPS 203 (ML-KEM) parameter constants (Table 2).
2
3/// Polynomial degree `n = 256` in `R_q = Z_q[X] / (X^256 + 1)`.
4pub const N: usize = 256;
5
6/// Prime modulus `q = 3329 = 2^8 * 13 + 1`.
7pub const Q: u16 = 3329;
8
9/// Prime modulus as `u32`.
10pub const Q_U32: u32 = 3329;
11
12/// Shared secret byte length (32 bytes across all ML-KEM parameter sets).
13pub const SHARED_SECRET_LEN: usize = 32;
14
15/// Random seed byte length (`d`, `z`, `m`, `rho`, `sigma` are all 32 bytes).
16pub const SEED_LEN: usize = 32;
17
18/// Encoded byte length of a single polynomial with 12-bit coefficients (`384` bytes).
19pub const POLY_BYTES: usize = 384;
20
21/// ML-KEM-512 parameter constants (NIST Security Category 1).
22pub mod ml_kem_512 {
23    /// Module rank `k = 2`.
24    pub const K: usize = 2;
25    /// CBD parameter `eta_1 = 3`.
26    pub const ETA1: usize = 3;
27    /// CBD parameter `eta_2 = 2`.
28    pub const ETA2: usize = 2;
29    /// Ciphertext `u` compression bits `d_u = 10`.
30    pub const DU: usize = 10;
31    /// Ciphertext `v` compression bits `d_v = 4`.
32    pub const DV: usize = 4;
33    /// Encapsulation key length in bytes (`384 * k + 32 = 800`).
34    pub const EK_LEN: usize = 800;
35    /// Decapsulation key length in bytes (`768 * k + 96 = 1632`).
36    pub const DK_LEN: usize = 1632;
37    /// Ciphertext length in bytes (`32 * (d_u * k + d_v) = 768`).
38    pub const CT_LEN: usize = 768;
39}
40
41/// ML-KEM-768 parameter constants (NIST Security Category 3).
42pub mod ml_kem_768 {
43    /// Module rank `k = 3`.
44    pub const K: usize = 3;
45    /// CBD parameter `eta_1 = 2`.
46    pub const ETA1: usize = 2;
47    /// CBD parameter `eta_2 = 2`.
48    pub const ETA2: usize = 2;
49    /// Ciphertext `u` compression bits `d_u = 10`.
50    pub const DU: usize = 10;
51    /// Ciphertext `v` compression bits `d_v = 4`.
52    pub const DV: usize = 4;
53    /// Encapsulation key length in bytes (`384 * k + 32 = 1184`).
54    pub const EK_LEN: usize = 1184;
55    /// Decapsulation key length in bytes (`768 * k + 96 = 2400`).
56    pub const DK_LEN: usize = 2400;
57    /// Ciphertext length in bytes (`32 * (d_u * k + d_v) = 1088`).
58    pub const CT_LEN: usize = 1088;
59}
60
61/// ML-KEM-1024 parameter constants (NIST Security Category 5).
62pub mod ml_kem_1024 {
63    /// Module rank `k = 4`.
64    pub const K: usize = 4;
65    /// CBD parameter `eta_1 = 2`.
66    pub const ETA1: usize = 2;
67    /// CBD parameter `eta_2 = 2`.
68    pub const ETA2: usize = 2;
69    /// Ciphertext `u` compression bits `d_u = 11`.
70    pub const DU: usize = 11;
71    /// Ciphertext `v` compression bits `d_v = 5`.
72    pub const DV: usize = 5;
73    /// Encapsulation key length in bytes (`384 * k + 32 = 1568`).
74    pub const EK_LEN: usize = 1568;
75    /// Decapsulation key length in bytes (`768 * k + 96 = 3168`).
76    pub const DK_LEN: usize = 3168;
77    /// Ciphertext length in bytes (`32 * (d_u * k + d_v) = 1568`).
78    pub const CT_LEN: usize = 1568;
79}