panchajanya1999/sage-estimator

By panchajanya1999

Updated 4 months ago

ML-KEM + ML-DSA security estimation API with leaky-LWE side-channel analysis

Image
Security
Languages & frameworks
API management
0

818

panchajanya1999/sage-estimator repository overview

sage-estimator

REST API for precise ML-KEM (FIPS 203) and ML-DSA / Dilithium (FIPS 204) security estimation using malb/lattice-estimator and leaky-LWE-Estimator.

Computes BKZ blocksize, classical/quantum security bits, and decryption failure rates for any ML-KEM parameter set, plus dual MLWE + MSIS security for ML-DSA. Supports side-channel leakage analysis via the leaky-LWE-Estimator (Ducas et al.).

Quick Start

docker run -d --name sage-estimator \
  -p 5123:5000 \
  --memory 12g \
  -e CACHE_PATH=/data/cache.json \
  -v sage-data:/data \
  panchajanya1999/sage-estimator:latest

The service precomputes 6 standard parameter sets on startup (~10-15 min):

  • ML-KEM: 512, 768, 1024 (FIPS 203)
  • ML-DSA: 44, 65, 87 (FIPS 204)
# Health check
curl http://localhost:5123/health

# Check prewarm progress (ready when count = 6)
curl http://localhost:5123/cache

Endpoints

ML-KEM (FIPS 203)
MethodPathDescription
POST/estimateSubmit ML-KEM estimate — returns 200 if cached, 202 with job_id if computing
GET/verifyVerify ML-KEM against known beta values
ML-DSA / Dilithium (FIPS 204)
MethodPathDescription
POST/estimate_dilithiumSubmit ML-DSA estimate — computes MLWE + MSIS
GET/verify_dilithiumVerify ML-DSA standard sets
Common
MethodPathDescription
GET/healthService health check (includes active_jobs count)
GET/status/<job_id>Poll job status — 202 while computing, 200 when done
GET/cacheList all cached results
DELETE/cacheClear both ML-KEM and ML-DSA caches

ML-KEM Usage

# Submit estimate — cached result (200)
curl -X POST http://localhost:5123/estimate \
  -H 'Content-Type: application/json' \
  -d '{"k": 3, "eta1": 2, "eta2": 2, "du": 10, "dv": 4}'
# {"beta": 624, "classical": 182, ..., "source": "cached", "status": "done"}

# Submit estimate — new computation (202)
curl -X POST http://localhost:5123/estimate \
  -H 'Content-Type: application/json' \
  -d '{"k": 3, "eta1": 3, "eta2": 3, "du": 10, "dv": 4}'
# {"status": "computing", "job_id": "23cc08da", "elapsed": 0}

# Poll until done
curl http://localhost:5123/status/23cc08da
# {"beta": 660, "classical": 192, ..., "status": "done"}
ML-KEM Parameters
FieldRangeDescription
k2-8Module rank (lattice dimension = 256 * k)
eta11-5Secret noise parameter (CBD)
eta21-5Error noise parameter (CBD)
du8-12Ciphertext compression bits (u)
dv3-6Ciphertext compression bits (v)
Standard FIPS 203 Sets
Variantketa1eta2dudvbetaClassicalQuantum
ML-KEM-512232104382~111 bits~101 bits
ML-KEM-768322104624~182 bits~165 bits
ML-KEM-1024422115874~255 bits~231 bits

ML-DSA (Dilithium) Usage

The Dilithium endpoint computes both MLWE (key recovery) and MSIS (forgery resistance) security. Overall security = min(MLWE, MSIS).

# Submit ML-DSA-44 estimate
curl -X POST http://localhost:5123/estimate_dilithium \
  -H 'Content-Type: application/json' \
  -d '{"k": 4, "l": 4, "eta": 2, "gamma1": 131072, "gamma2": 95232}'
# {"status": "computing", "job_id": "e9a2863a", "elapsed": 0}

# Poll until done (~60-90 seconds)
curl http://localhost:5123/status/e9a2863a
# {"mlwe_beta": 424, "mlwe_classical": 123, "mlwe_quantum": 112,
#  "msis_beta": 1128, "msis_classical": 329, "msis_quantum": 298,
#  "status": "done", "source": "computed"}
ML-DSA Parameters
FieldRangeDescription
k2-8Matrix rows (FIPS 204: {4, 6, 8})
l2-7Matrix cols (FIPS 204: {4, 5, 7})
eta2 or 4Secret key coefficient bound
gamma1131072 or 524288Mask coefficient range (2^17 or 2^19)
gamma295232 or 261888Decomposition factor ((q-1)/88 or (q-1)/32)
Standard FIPS 204 Sets
VariantkletaMLWE betaMSIS betaClassicalQuantum
ML-DSA-444424241128~123 bits~112 bits
ML-DSA-656546241386~182 bits~165 bits
ML-DSA-878728631952~252 bits~228 bits
MSIS Estimation Notes

The MSIS estimate uses the native SIS.estimate() from the lattice-estimator with L2 (Euclidean) norm. The infinity norm estimator has an upstream gmpy2/SageMath compatibility bug. L2 norm provides a conservative upper bound — the real forgery problem (SelfTargetMSIS) is harder still.

Side-Channel Leakage Analysis (Leaky-LWE)

Both /estimate and /estimate_dilithium accept optional leakage parameters to model security degradation when an attacker has partial knowledge of the secret key via side channels (DPA, power analysis, etc.).

Uses the leaky-LWE-Estimator by Ducas et al. (DBDD_predict_diag variant for large dimensions).

Leakage Parameters
FieldTypeDescription
leak_type"perfect" or "approx"Leakage model (optional)
leak_amountint > 0Number of leaked coordinates/measurements
leak_variancefloat > 0Noise variance (approx only)
Leakage Models
  • Perfect ("perfect"): Exact bits leaked (e.g., DPA revealed N coordinates of the secret key). Models the worst-case scenario.
  • Approximate ("approx"): Noisy measurements (e.g., N power traces with variance sigma^2). Models realistic side-channel attacks.
ML-KEM Leakage Example
# ML-KEM-512 with 50 perfectly leaked coordinates
curl -X POST http://localhost:5123/estimate \
  -H 'Content-Type: application/json' \
  -d '{"k": 2, "eta1": 3, "eta2": 2, "du": 10, "dv": 4,
       "leak_type": "perfect", "leak_amount": 50}'

# Response includes standard + leaky fields:
# {"beta": 382, "classical": 111, ...,
#  "leaky_beta": 347.8, "leaky_classical": 101,
#  "leaky_quantum": 92, "security_loss_bits": 13, ...}

50 leaked coordinates (~10% of ML-KEM-512's 512-dimensional secret) drops classical security from ~111 to ~101 bits — a 13-bit loss.

ML-DSA Leakage Example
# ML-DSA-44 with 50 perfectly leaked coordinates
curl -X POST http://localhost:5123/estimate_dilithium \
  -H 'Content-Type: application/json' \
  -d '{"k": 4, "l": 4, "eta": 2, "gamma1": 131072, "gamma2": 95232,
       "leak_type": "perfect", "leak_amount": 50}'

# Response: mlwe_leaky_beta=335.8, mlwe_leaky_classical=98, security_loss=6 bits
# MSIS fields unchanged — forgery resistance is unaffected by key leakage

For ML-DSA, leakage analysis applies to MLWE only — MSIS (forgery resistance) is unaffected by key leakage.

Leaky Response Fields
FieldDescription
leaky_beta / mlwe_leaky_betaBKZ blocksize with leakage
leaky_classical / mlwe_leaky_classicalClassical bits with leakage
leaky_quantum / mlwe_leaky_quantumQuantum bits with leakage
security_loss_bits / mlwe_security_loss_bitsClassical bits lost
leak_typeLeakage model used
leak_amountNumber of leaked coordinates/measurements

Attack Strategies

The estimator runs 6 attacks against the Module-LWE instance:

AttackTypeDescription
usvpPrimal latticeUnique Shortest Vector Problem — primary security metric (beta)
bddPrimal latticeBounded Distance Decoding — finds closest lattice point to target
dualDual latticeDistinguishes LWE samples from uniform using short dual vectors
dual_hybridHybridCombines lattice reduction with guessing secret coordinates
arora-gbAlgebraicGroebner basis attack on polynomial system from LWE samples
bkwCombinatorialBlum-Kalai-Wasserman — trades memory for reduced operations

Caching

Results are cached in-memory and persisted to Docker volumes:

CacheFileContents
ML-KEM/data/cache.json(k, eta1, eta2, du, dv[, leak_*]) -> result
ML-DSA/data/dilithium_cache.json(k, l, eta, gamma1, gamma2[, leak_*]) -> result

Each unique parameter set is computed once (~30s-2min for ML-KEM, ~60-90s for ML-DSA, leaky adds ~2-5min via SageMath), then served instantly from cache.

Memory Requirements

Parameter SetRecommended Memory
ML-KEM-512 / ML-DSA-444 GB
ML-KEM-768 / ML-DSA-656 GB
ML-KEM-1024 / ML-DSA-878 GB
All sets + leaky-LWE12 GB

Architecture

  • Base image: condaforge/miniforge3 with SageMath via conda-forge
  • Platforms: linux/arm64, linux/amd64
  • Async API: Non-blocking submit + poll pattern for long computations
  • Deduplication: Duplicate submissions for the same params reuse existing jobs
  • Leaky-LWE: SageMath subprocess via DBDD_predict_diag (Ducas et al.)

References

Tag summary

Content type

Image

Digest

sha256:871c62dca

Size

1.9 GB

Last updated

4 months ago

docker pull panchajanya1999/sage-estimator