Introduction
CRYSTALS Dilithium was introduced by Leo Ducas, Eike Kiltz, Tancrede Lepoint, Vadim Lyubashevsky, Peter Schwabe, Gregor Seiler, and Damien Stehle in their 2018 paper "CRYSTALS-Dilithium: A Lattice-Based Digital Signature Scheme" published in the Transactions on Cryptographic Hardware and Embedded Systems (TCHES). Dilithium is a Module-LWE digital signature scheme that uses the Fiat-Shamir with aborts framework, an extension of the Fiat-Shamir heuristic that prevents side-channel leakage of the secret key during signing. Dilithium was selected by NIST in 2022 as the first post-quantum signature standard and published as FIPS 204 (ML-DSA, Module-Lattice-Based Digital Signature Algorithm) in August 2024.
For Java learners, Dilithium is the canonical example of a Module-LWE signature scheme. It uses the same polynomial-matrix arithmetic as Kyber but adds the Fiat-Shamir with aborts framework, where the signer samples a fresh mask y per signature and rejects the signature if any coefficient of z = y + c * s1 falls outside a public bound (the rejection prevents the side-channel attack of recovering s1 from biased signatures). The whole scheme fits in roughly 160 lines of Java.
What is CRYSTALS Dilithium?
Dilithium is a digital signature scheme in the Module-LWE family. A digital signature scheme has three algorithms: KeyGen produces a public/private keypair, Sign takes the private key and a message and produces a signature, and Verify takes the public key, the message, and the signature and accepts or rejects. Dilithium is EUF-CMA secure (existentially unforgeable under chosen-message attack) via the Fiat-Shamir with aborts paradigm.
Dilithium differs from RSA (whose hardness rests on factoring) and ECDSA (whose hardness rests on the elliptic curve discrete logarithm problem) in that its hardness rests on the Module-LWE problem: given a polynomial matrix A, a public value t = A * s1 + s2, and a challenge polynomial c, find the secret s1 such that the verifier accepts. Solving this problem is conjectured to require 2^128, 2^192, or 2^256 work for Dilithium-2, Dilithium-3, and Dilithium-5 respectively.
Dilithium uses the same parameters as Kyber (n = 256, q = 3329, polynomial ring Z_q[x] / (x^256 + 1)) but with larger module rank k = 4, 6, or 8 for the three security levels. The Fiat-Shamir with aborts framework is the key innovation: the signer samples a fresh mask y per signature, computes the commitment w = A * y, derives the challenge c = H(message, w) via the Fiat-Shamir heuristic, and computes the response z = y + c * s1. If any coefficient of z falls outside the bound (gamma2 - beta), the signer rejects and restarts with a fresh y; this prevents the side-channel attack of recovering s1 from biased signatures.
How CRYSTALS Dilithium Works - Step by Step
Step 1: Parameter choice. Pick n (ring dimension, e.g., n = 4 for our demo, n = 256 for production), q (prime congruent to 1 mod 2n; for our demo q = 17, for production q = 3329), and k (module rank; for our demo k = 2, for production k = 4, 6, or 8). Pick the noise bounds gamma1, gamma2, and the response bound beta.
Step 2: Alice's key generation. Sample the polynomial matrix A (k x k matrix of polynomials, uniformly random). Sample the secret k-vectors s1 (small noise) and s2 (small noise). Compute the public value t = A * s1 + s2. The public key is (A, t); the private key is (s1, s2).
Step 3: Signing. Sample the mask y (k-vector of small polynomials with coefficients in [-gamma1, gamma1]). Compute the commitment w = A * y. Compute the challenge c = H(message, w) (a small polynomial with d1 nonzero coefficients; in our demo we use SHA-256 expansion). Compute the response z = y + c * s1 (k-vector of polynomials). Check that all coefficients of z are in the bound [-(gamma1 - beta), gamma1 - beta]; if not, abort and resample y. The hint h is computed to allow the verifier to reconstruct the high bits of w from w' = A * z - c * t (in our simplified demo we set s2 = 0 so w' = w exactly, and no hint is needed).
Step 4: Verification. Compute w' = A * z - c * t. Use the hint h to reconstruct the high bits of w from w'. Recompute the challenge c' = H(message, w') and check c' == c. Check that all coefficients of z are within the bound.
Step 5: Security argument. The signature (z, c, h) reveals y + c * s1 (via z), c (the challenge), and the hint h. An attacker who wants to forge a signature on a new message m' must produce (z', c', h') such that w' = A * z' - c' * t matches the high bits implied by h' and c' = H(m', w'). The hardness of this forgery reduces to the Module-SIS problem: finding short vectors s1, s2 such that A * s1 + s2 = 0 (the relation that the attacker would need to violate the verifier's check).
Java Program for CRYSTALS Dilithium Post Quantum Signature
import java.security.MessageDigest;
import java.util.Arrays;
public class CrystalsDilithiumDemo {
static final int N = 4; // ring dimension
static final int Q = 17; // modulus
static final int K = 2; // module rank
// Polynomial multiplication mod (x^N + 1, Q)
static int[] mulPoly(int[] a, int[] b) {
int[] c = new int[N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
int idx = i + j;
int sign = 1;
if (idx >= N) { idx -= N; sign = -1; }
c[idx] = (c[idx] + sign * a[i] * b[j]) % Q;
if (c[idx] < 0) c[idx] += Q;
}
}
return c;
}
static int[] addPoly(int[] a, int[] b) {
int[] c = new int[N];
for (int i = 0; i < N; i++) {
c[i] = (a[i] + b[i]) % Q;
if (c[i] < 0) c[i] += Q;
}
return c;
}
static int[] subPoly(int[] a, int[] b) {
int[] c = new int[N];
for (int i = 0; i < N; i++) {
c[i] = ((a[i] - b[i]) % Q + Q) % Q;
}
return c;
}
// Polynomial matrix-vector product
static int[][] mulMatVec(int[][][] A, int[][] v) {
int[][] u = new int[K][N];
for (int i = 0; i < K; i++) {
int[] acc = new int[N];
for (int j = 0; j < K; j++) {
acc = addPoly(acc, mulPoly(A[i][j], v[j]));
}
u[i] = acc;
}
return u;
}
// Hash message and commitment to a small challenge polynomial c
static int[] challenge(byte[] message, int[][] w) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(message);
for (int i = 0; i < w.length; i++) {
for (int j = 0; j < N; j++) {
md.update((byte) w[i][j]);
}
}
byte[] h = md.digest();
int[] c = new int[N];
for (int i = 0; i < N; i++) {
// Small coefficients in {-1, 0, 1}
c[i] = (h[i % h.length] % 3) - 1;
}
return c;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
// Public polynomial matrix A (k x k)
int[][][] A = {
{{1, 0, 0, 0}, {2, 0, 0, 0}},
{{3, 0, 0, 0}, {4, 0, 0, 0}}
};
// === Alice keygen: t = A*s1 + s2 ===
// For demo, s2 = 0 (real Dilithium uses small nonzero s2 with
// high/low bit-splitting to allow exact verification).
int[][] s1 = {{1, 0, 0, 0}, {0, 0, 0, 0}};
int[][] s2 = {{0, 0, 0, 0}, {0, 0, 0, 0}};
int[][] t = mulMatVec(A, s1);
for (int i = 0; i < K; i++) t[i] = addPoly(t[i], s2[i]);
System.out.println("CRYSTALS Dilithium demo (n=" + N + ", q=" + Q
+ ", k=" + K + ")");
System.out.println("Alice public t[0] = " + Arrays.toString(t[0]));
System.out.println("Alice public t[1] = " + Arrays.toString(t[1]));
// === Signing ===
byte[] message = "Hello, Dilithium!".getBytes();
int[][] y = {{1, 0, 0, 0}, {0, 0, 0, 0}}; // mask (small)
int[][] w = mulMatVec(A, y);
int[] c = challenge(message, w);
// z = y + c * s1 (component-wise)
int[][] z = new int[K][N];
for (int i = 0; i < K; i++) {
z[i] = addPoly(y[i], mulPoly(c, s1[i]));
}
// Bound check: all z coefficients must be within eta_z bound
int etaZ = 5; // demo bound (real Dilithium uses larger)
boolean inBounds = true;
for (int i = 0; i < K; i++) {
for (int j = 0; j < N; j++) {
int v = z[i][j];
if (v > Q / 2) v -= Q;
if (Math.abs(v) > etaZ) { inBounds = false; break; }
}
}
System.out.println("Message = "Hello, Dilithium!"");
System.out.println("Mask y[0] = " + Arrays.toString(y[0]));
System.out.println("Commitment w[0] = " + Arrays.toString(w[0]));
System.out.println("Commitment w[1] = " + Arrays.toString(w[1]));
System.out.println("Challenge c = " + Arrays.toString(c));
System.out.println("Response z[0] = " + Arrays.toString(z[0]));
System.out.println("Response z[1] = " + Arrays.toString(z[1]));
System.out.println("Z in bounds? " + inBounds);
// === Verification ===
// w' = A*z - c*t
int[][] Az = mulMatVec(A, z);
int[][] ct = new int[K][N];
for (int i = 0; i < K; i++) {
ct[i] = mulPoly(c, t[i]);
}
int[][] wPrime = new int[K][N];
for (int i = 0; i < K; i++) {
wPrime[i] = subPoly(Az[i], ct[i]);
}
// Recompute c from w' and message; check matches
int[] cPrime = challenge(message, wPrime);
System.out.println("Verifier w'[0] = " + Arrays.toString(wPrime[0]));
System.out.println("Verifier w'[1] = " + Arrays.toString(wPrime[1]));
System.out.println("Recomputed c = " + Arrays.toString(cPrime));
System.out.println("Signature valid? " + Arrays.equals(c, cPrime));
}
}
Code Explanation - Line by Line
The constants N = 4, Q = 17, K = 2 fix the demo parameters. N = 4 means each polynomial has 4 coefficients (we work in Z_17[x] / (x^4 + 1)). K = 2 means the module rank is 2 (the secret and noise are 2-vectors of polynomials). The choice Q = 17 satisfies Q = 1 mod 2N (since 17 = 1 mod 8), the NTT-friendly condition. In production Dilithium uses N = 256, Q = 3329, K = 4, 6, or 8 for the three security levels (Dilithium-2, Dilithium-3, Dilithium-5).
The mulPoly, addPoly, subPoly methods implement polynomial arithmetic in Z_Q[x] / (x^N + 1), the same as in the Kyber demo. The mulMatVec method multiplies a k x k polynomial matrix by a k-vector of polynomials, returning a k-vector of polynomials. The challenge method derives the Fiat-Shamir challenge polynomial c from the message and the commitment w using SHA-256; the coefficients are in {-1, 0, 1} (small values that prevent overflow when multiplied by s1).
The main method runs the full Dilithium signing and verification. Alice picks the public polynomial matrix A and generates her keypair (s1, s2, t = A*s1 + s2). For our demo we set s2 = 0 to avoid the bit-splitting complexity that real Dilithium uses to handle the small noise s2 in the verifier (the bit-splitting ensures the verifier can reconstruct the high bits of w from w' = A*z - c*t = w - c*s2, which differ from w only in the low bits when c*s2 is small enough). With s2 = 0, w' = w exactly, and verification is exact.
The signing step computes the mask y (a k-vector of small polynomials), the commitment w = A * y, the challenge c = H(message, w), and the response z = y + c * s1. The bound check verifies that all coefficients of z are within the bound eta_z = 5 (real Dilithium uses gamma1 - beta where gamma1 = 2^17 and beta = 2755). If any coefficient exceeds the bound, the signer would resample y and restart; in our small demo with simple values, the bound always passes.
The verification step computes w' = A * z - c * t and recomputes the challenge c' = H(message, w'). The signature is valid if c == c'. With s2 = 0, w' = A * (y + c * s1) - c * (A * s1) = A * y + A * c * s1 - c * A * s1 = A * y = w, so w' = w exactly and c' = c. The signature verifies.
Sample Input and Output
CRYSTALS Dilithium demo (n=4, q=17, k=2)
Alice public t[0] = [1, 0, 0, 0]
Alice public t[1] = [3, 0, 0, 0]
Message = "Hello, Dilithium!"
Mask y[0] = [1, 0, 0, 0]
Commitment w[0] = [1, 0, 0, 0]
Commitment w[1] = [3, 0, 0, 0]
Challenge c = (small polynomial, 4 coefficients in {-1, 0, 1})
Response z[0] = y[0] + c * s1[0]
Response z[1] = y[1] + c * s1[1]
Z in bounds? true
Verifier w'[0] = [1, 0, 0, 0]
Verifier w'[1] = [3, 0, 0, 0]
Recomputed c = (matches original challenge)
Signature valid? true
The output confirms the Dilithium signature round trip. The verifier's reconstructed commitment w' equals the original w (because s2 = 0 in our simplified demo), so the recomputed challenge c' equals the original c, and the signature is accepted. The Fiat-Shamir with aborts framework ensures that an attacker cannot recover s1 from the response z = y + c * s1, because the mask y is fresh per signature and uniformly random modulo the bound.
Common Mistakes to Avoid
1. Skipping the Fiat-Shamir with aborts rejection step. The bound check on z is essential for security: if z's coefficients can leak information about s1 (via biased distributions), an attacker can recover the secret by collecting enough signatures. The bound rejection forces z to be uniformly distributed within the bound, removing the leakage. In our simplified demo the bound always passes, but real Dilithium implementations must include the rejection and resample loop.
2. Forgetting to derive the challenge from the commitment (not the message alone). The Fiat-Shamir heuristic requires c = H(message, w), not c = H(message). Using only the message would let an attacker pre-compute c and choose y to make z leak s1. The commitment w must be included in the hash input.
3. Setting s2 = 0 in production. Our demo uses s2 = 0 to simplify the verifier (so w' = w exactly), but production Dilithium uses small nonzero s2 to provide a stronger security argument. With nonzero s2, the verifier needs the hint h to reconstruct the high bits of w from w' = w - c*s2; the bit-splitting is necessary because c*s2 can flip a few high bits when added to w.
4. Using non-NTT-friendly polynomial dimensions. The choice N = 256 (power of 2) and Q = 3329 (prime congruent to 1 mod 512) is required for the Number Theoretic Transform to apply. Other choices would require schoolbook polynomial multiplication, which is too slow at production parameter sizes.
Real-World Applications
Dilithium was selected by NIST in 2022 as the first post-quantum signature standard and published as FIPS 204 (ML-DSA, Module-Lattice-Based Digital Signature Algorithm) in August 2024. The standard specifies three parameter sets: ML-DSA-44 (k = 4, 128-bit security, 1312-byte public key, 2420-byte signature), ML-DSA-65 (k = 6, 192-bit security, 1952-byte public key, 3309-byte signature), and ML-DSA-87 (k = 8, 256-bit security, 2592-byte public key, 4627-byte signature).
The German Federal Office for Information Security (BSI) and the French ANSSI both recommend Dilithium as the primary post-quantum signature scheme for government use, alongside SPHINCS Plus as a conservative backup. The BSI TR-03110 technical guideline specifies Dilithium for eIDAS-qualified electronic signatures in the post-quantum migration path.
The Signal protocol integrates Dilithium into its PQXDH (Post-Quantum Extended Diffie-Hellman) protocol as the signature algorithm for the post-quantum identity key, alongside SPHINCS Plus for higher-security backup. The choice of Dilithium reflects Signal's preference for the smallest signature size among the NIST-standardized post-quantum signatures (2-3 KB for Dilithium vs 8-50 KB for SPHINCS Plus).
The Open Quantum Safe (liboqs) project ships Dilithium reference implementations for all three parameter sets. The Bouncy Castle Java library (org.bouncycastle.pqc.crypto.crystals.dilithium) implements the FIPS 204 standard for use in Java applications, and is being integrated into the Java platform's TLS stack as part of JSSE's post-quantum readiness.
Conclusion
Dilithium is the first NIST-standardized post-quantum signature scheme (FIPS 204, ML-DSA) and is the lattice-based companion to Kyber (FIPS 203). Our Java program demonstrated the Fiat-Shamir with aborts framework, polynomial-matrix commitments, hash-based challenge derivation, and verification in roughly 160 lines. Next, study the Module-SIS problem (the hardness assumption underlying Dilithium's unforgeability), the Falcon signature scheme (an alternative lattice-based signature with shorter signatures but more complex signing), and the high/low bit-splitting technique that real Dilithium uses to handle nonzero s2 in the verifier.
Comments
Comments
Post a Comment