Skip to main content

quantaegis_ml_dsa/
params.rs

1//! NIST FIPS 204 ML-DSA parameter sets (Table 1 and Table 2).
2
3/// Field prime modulus `q = 2^23 - 2^13 + 1 = 8_380_417`.
4pub(crate) const Q: u32 = 8_380_417;
5
6/// Polynomial ring degree `n = 256`.
7pub(crate) const N: usize = 256;
8
9/// Dropped low-order bits from `t`: `d = 13`.
10pub(crate) const D: u32 = 13;
11
12/// Primitive 512-th root of unity modulo `q`: `zeta = 1753`.
13pub(crate) const ZETA: u32 = 1753;
14
15/// Multiplicative inverse of `n = 256` modulo `q`: `256^{-1} mod 8380417 = 8_347_681`.
16pub(crate) const INV_N: u32 = 8_347_681;
17
18/// Seed length `xi` in bytes (32 bytes = 256 bits).
19pub const SEED_LEN: usize = 32;
20
21/// Signing randomness length `rnd` in bytes (32 bytes = 256 bits).
22pub const RND_LEN: usize = 32;
23
24/// Public key hash `tr = SHAKE256(pk, 64)` length in bytes.
25pub(crate) const TR_LEN: usize = 64;
26
27/// Message representative `mu = SHAKE256(tr || M', 64)` length in bytes.
28pub const MU_LEN: usize = 64;
29
30/// Maximum context string length allowed by FIPS 204 Algorithm 2 & 3 (`255` bytes).
31pub const MAX_CTX_LEN: usize = 255;
32
33/// `GAMMA2` for ML-DSA-44: `(q - 1) / 88 = 95_232`.
34pub(crate) const GAMMA2_44: u32 = (Q - 1) / 88;
35
36/// `GAMMA2` for ML-DSA-65 and ML-DSA-87: `(q - 1) / 32 = 261_888`.
37pub(crate) const GAMMA2_65_87: u32 = (Q - 1) / 32;
38
39/// `GAMMA1` for ML-DSA-44: `2^17 = 131_072`.
40pub(crate) const GAMMA1_44: u32 = 1 << 17;
41
42/// `GAMMA1` for ML-DSA-65 and ML-DSA-87: `2^19 = 524_288`.
43pub(crate) const GAMMA1_65_87: u32 = 1 << 19;
44
45/// Encoded byte length of one `t1` polynomial (10 bits/coeff * 256 / 8 = 320 bytes).
46pub(crate) const T1_POLY_LEN: usize = 320;
47
48/// Encoded byte length of one `t0` polynomial (13 bits/coeff * 256 / 8 = 416 bytes).
49pub(crate) const T0_POLY_LEN: usize = 416;
50
51/// Parameter constants for **ML-DSA-44** (NIST Security Category 2).
52pub(crate) mod p44 {
53    use super::{GAMMA1_44, GAMMA2_44};
54
55    pub(crate) const K: usize = 4;
56    pub(crate) const L: usize = 4;
57    pub(crate) const ETA: u32 = 2;
58    pub(crate) const TAU: usize = 39;
59    pub(crate) const BETA: u32 = 78;
60    pub(crate) const GAMMA1: u32 = GAMMA1_44;
61    pub(crate) const GAMMA2: u32 = GAMMA2_44;
62    pub(crate) const OMEGA: usize = 80;
63    pub(crate) const C_TILDE_LEN: usize = 32;
64    pub(crate) const W1_LEN: usize = K * 192; // 768
65    pub(crate) const PK_LEN: usize = 1312;
66    pub(crate) const SK_LEN: usize = 2560;
67    pub(crate) const SIG_LEN: usize = 2420;
68}
69
70/// Parameter constants for **ML-DSA-65** (NIST Security Category 3).
71pub(crate) mod p65 {
72    use super::{GAMMA1_65_87, GAMMA2_65_87};
73
74    pub(crate) const K: usize = 6;
75    pub(crate) const L: usize = 5;
76    pub(crate) const ETA: u32 = 4;
77    pub(crate) const TAU: usize = 49;
78    pub(crate) const BETA: u32 = 196;
79    pub(crate) const GAMMA1: u32 = GAMMA1_65_87;
80    pub(crate) const GAMMA2: u32 = GAMMA2_65_87;
81    pub(crate) const OMEGA: usize = 55;
82    pub(crate) const C_TILDE_LEN: usize = 48;
83    pub(crate) const W1_LEN: usize = K * 128; // 768
84    pub(crate) const PK_LEN: usize = 1952;
85    pub(crate) const SK_LEN: usize = 4032;
86    pub(crate) const SIG_LEN: usize = 3309;
87}
88
89/// Parameter constants for **ML-DSA-87** (NIST Security Category 5).
90pub(crate) mod p87 {
91    use super::{GAMMA1_65_87, GAMMA2_65_87};
92
93    pub(crate) const K: usize = 8;
94    pub(crate) const L: usize = 7;
95    pub(crate) const ETA: u32 = 2;
96    pub(crate) const TAU: usize = 60;
97    pub(crate) const BETA: u32 = 120;
98    pub(crate) const GAMMA1: u32 = GAMMA1_65_87;
99    pub(crate) const GAMMA2: u32 = GAMMA2_65_87;
100    pub(crate) const OMEGA: usize = 75;
101    pub(crate) const C_TILDE_LEN: usize = 64;
102    pub(crate) const W1_LEN: usize = K * 128; // 1024
103    pub(crate) const PK_LEN: usize = 2592;
104    pub(crate) const SK_LEN: usize = 4896;
105    pub(crate) const SIG_LEN: usize = 4627;
106}