Path: blob/main/frontier/11-homomorphic-encryption/break/cpa-deterministic-encryption.ipynb
483 views
Break: CPA Attack on Deterministic Homomorphic Encryption
Module 11 | Breaking Weak Parameters
Without randomized encryption, homomorphic schemes leak plaintext equality --- and a chosen-plaintext attacker can identify every encrypted value.
Why This Matters
Homomorphic encryption promises computation on encrypted data. But if the encryption is deterministic (same plaintext always produces the same ciphertext), an attacker can:
Detect equality: two employees earn the same salary if their ciphertexts match.
Dictionary attack: encrypt all candidate values, compare with target ciphertexts.
Frequency analysis: the most common ciphertext reveals the most common value.
This is the CPA (Chosen-Plaintext Attack) model: the attacker can encrypt arbitrary messages and compare the results with target ciphertexts. Any deterministic scheme is trivially broken under CPA.
Proper FHE schemes (LWE-based) use randomized encryption, where the same plaintext produces different ciphertexts every time. This notebook demonstrates why randomness is essential.
The Scenario: A Deterministic "Homomorphic" Scheme
Consider a toy scheme that encrypts by a simple affine transformation:
where is the secret key. This is additively homomorphic:
But it is deterministic: always gives the same ciphertext.
Step 1: Deterministic Encryption Leaks Equality
Encrypt the same value multiple times. With deterministic encryption, the ciphertext is always identical. An observer immediately knows when two plaintexts are equal.
Step 2: CPA Dictionary Attack
In the CPA model, the attacker can encrypt any message they choose. With a deterministic scheme, the attacker simply encrypts all candidate plaintexts and looks for matches.
Step 3: The CPA Distinguishing Game
The formal definition of CPA security uses a distinguishing game:
Attacker chooses two messages .
Challenger flips a coin and encrypts .
Attacker sees the ciphertext and guesses .
The scheme is CPA-secure if no attacker can guess with probability significantly better than . With deterministic encryption, the attacker wins with probability .
Step 4: Randomized Encryption Defeats the Attack
Proper LWE-based FHE schemes add fresh random noise to every encryption. The same plaintext produces a different ciphertext each time, making CPA attacks impossible.
We use the toy LWE scheme from Notebook 11a: where is random and is small random noise.
Exercises
Exercise 1 (Guided): Frequency Analysis Attack
Generate 100 random salaries from the set , encrypt them deterministically, and show that the frequency distribution of ciphertexts exactly reveals the frequency distribution of salaries.
Exercise 2 (Independent)
Paillier encryption uses a random in each encryption: . Verify that encrypting the same message twice with Paillier produces different ciphertexts (see Notebook 11b for the implementation).
Why is textbook RSA () deterministic, and how does OAEP padding fix this?
In a system where ciphertexts are deterministic but the attacker does NOT have access to an encryption oracle, is the scheme still insecure? Consider the case where the plaintext space is small (e.g., binary yes/no votes).
Summary
| Property | Deterministic Scheme | Randomized (LWE) Scheme |
|---|---|---|
| Same plaintext, same ciphertext? | Yes --- equality leaked | No --- different every time |
| CPA attacker advantage | (total break) | (secure) |
| Dictionary attack | Trivial | Impossible |
| Frequency analysis | Directly reveals distribution | Ciphertexts uniformly distributed |
| Semantic security | No | Yes |
Key takeaways:
Deterministic encryption is never CPA-secure, regardless of the key size or algebraic structure.
Proper FHE schemes (BGV, BFV, CKKS) add fresh random noise in every encryption, achieving semantic security.
Paillier achieves randomization through a random ; LWE-based schemes through random and noise .
The cost of randomization is that ciphertexts are larger and decryption requires error correction.