Skip to main content

๐Ÿ”ฎ The Magic Seed

How ML-KEM Shrinks 3,456 Bytes to 32โ€‹


๐ŸŽฏ The Simple Storyโ€‹

Imagine you need to send someone the entire city of New York:

Problem: It's too big!

Solution: Send them a magic seed instead!

You tell them: "Plant this seed and you'll get the whole city!"

When they "plant" it (run a program), New York grows out of that one tiny seed!

That's how ML-KEM sends huge matrices as just 32 bytes - like sending a seed instead of the entire city!


๐Ÿง  Mental Modelโ€‹

Hold this picture in your head:

Normal way (impossible):

Full Matrix A:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 256 coeffs โ”‚ ร— 9 polynomials
โ”‚ (2,304 total) โ”‚ = 3,456 bytes raw!
โ”‚ โ”‚ Too big to send!
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“
Sender toReceiver: [3,456 bytes]
Too slow!

Better way (magic):

1. Bob picks random 32-byte seed
2. Expands seed โ†’ generates entire matrix
3. Stores seed, not matrix!

Sender toReceiver: [32 bytes] โ† Just the seed!
Instant!

Receiver re-expands โ†’ same matrix Bob created!

Think of it like:

๐ŸŒฑ Plant a tree (seed โ†’ full tree)

๐Ÿ“š Read a book (index โ†’ full story)

๐Ÿ”‘ Recipe card (list of steps โ†’ full meal)

ML-KEM: Seed โ†’ Expand โ†’ 3,456 bytes (deterministic!)


๐Ÿ“Š See It Happenโ€‹

Let's watch the magic seed process:


๐ŸŽฎ Try It Yourselfโ€‹

Question 1: Matrix A = 9 polynomials ร— 256 coefficients = 2,304 coefficients ร— 12 bits each = 27,648 bits. How many bytes raw?

Show Answer

Total bits: 2,304 ร— 12 = 27,648 bits

Convert to bytes: 27,648 รท 8 = 3,456 bytes

Answer: 3,456 bytes raw


Question 2: If we use the seed compression trick, how many bytes do we send instead?

Show Answer

Traditional: Send 3,456 bytes directly

Seed trick: Send just 32-byte seed

Compression ratio: 3,456 รท 32 = 108ร— smaller!

Answer: 32 bytes (99% smaller!)


Question 3: Why is this better than sending the raw matrix? Speed?

Show Answer

Assume 1 second to send 1 kilobyte:

Raw: 3,456 bytes ร— 1 sec/KB = ~3.5 seconds Seed: 32 bytes ร— 1 sec/KB = ~0.03 seconds (instant!)

Speedup: 100ร— faster transmission (like 3 seconds vs 0.03 seconds)

Answer: 100ร— faster to send seed vs raw matrix!


๐Ÿ”ข The Mathโ€‹

Problem: Huge Matricesโ€‹

In ML-KEM, matrix A has:

AโˆˆRqkร—k\mathbf{A} \in R_q^{k \times k}

Where:

  • k=3k = 3 for ML-KEM768
  • kร—k=9k \times k = 9 polynomial entries
  • Each polynomial has 256 coefficients

Total: 9ร—256=2,3049 \times 256 = 2,304 coefficients

Each coefficient: 12 bits (0 to 3,328)

Raw size: 2,304ร—12=27,6482,304 \times 12 = 27,648 bits = 3,456 bytes

Sending 3,456 bytes = Too slow!

Solution: Pseudo-Random Generator (PRG)โ€‹

Idea: Store a small seed, expand when needed!

  1. Bob generates: 32-byte random seed SS
  2. Bob uses PRG: Expand SS โ†’ Matrix A\mathbf{A}
  3. Bob stores: Just SS (not A\mathbf{A}!)
  4. When needed: Re-expand SS โ†’ A\mathbf{A} (deterministic)

PRG property: Same seed โ†’ same output (always!)

Deterministic Expansionโ€‹

Given seed SS, PRG computes:

A=PRG(S)\mathbf{A} = \text{PRG}(S)

PRG:{0,1}256โ†’Zqnร—n\text{PRG}: \{0, 1\}^{256} \rightarrow \mathbb{Z}_q^{n \times n}

Maps 256-bit seed to 3,456-byte matrix deterministically!


๐Ÿ’ก Why We Careโ€‹

Transmission Speedโ€‹

Without seed:

  • Send 3,456 bytes = 3.4 KB
  • At 1 KB/s: ~3.5 seconds

With seed:

  • Send 32 bytes = 0.03 KB
  • At 1 KB/s: ~0.03 seconds

100ร— faster!

Storage Efficiencyโ€‹

Public key contains:

  • Matrix expansion (3,456 โ†’ 864 bytes)
  • Vector t (1,152 โ†’ 320 bytes)

Total: 1,184 bytes (still much smaller than 4.6 KB!)

Security Propertyโ€‹

The seed approach doesn't just shrink sizeโ€”it's essential for ML-KEM:

  • Attacker sees: 32-byte seed
  • Can re-expand: To get matrix A
  • But matrix A is: Deterministically generated
  • Security: Based on seed hardness + MLWE hardness

Seed just tells you HOW to recompute A, doesn't give you A itself!


โœ… Quick Checkโ€‹

Can you explain the seed trick to a 5-year-old?

Try saying this out loud:

"The seed trick is like storing a recipe card instead of the entire meal. When you want the meal, you just follow the recipe. ML-KEM sends a tiny seed, and the receiver expands it to get the whole matrix!"

Can you compute seed compression?

Try this examples:

Matrix has 2,304 coefficients ร— 12 bits = 27,648 bits

Send raw: 27,648 รท 8 = 3,456 bytes Send seed: 32 bytes

Compression ratio: 3,456 รท 32 = 108ร—

Speedup: Sending takes 100ร— less time!


๐ŸŽ“ Key Takeawaysโ€‹

โœ… Seed trick = Store 32 bytes, expand to 3,456 bytes โœ… PRG = Pseudo-random generator (deterministic) โœ… Compression = 108ร— smaller, 100ร— faster โœ… Re-expand = Same seed โ†’ same matrix (always!) โœ… Public key = Seed + vector t (1,184 bytes total) โœ… Security still fine = Seed hardness + MLWE hardness


๐ŸŽ‰ What You'll Learn Nextโ€‹

Now you understand encoding and the seed trick! Next, we'll understand key generation:

๐Ÿ”‘ Making the Key โ†’ Key Generation

How ML-KEM็”Ÿๆˆ (generates) public/private key pairs!