Path: blob/main/frontier/11-homomorphic-encryption/sage/11b-partially-homomorphic-schemes.ipynb
483 views
Notebook 11b: Partially Homomorphic Schemes
Module 11: Homomorphic Encryption
Motivating Question. Before FHE existed, cryptographers knew about schemes that were homomorphic for one operation, either addition or multiplication, but not both. Can we still do useful things with just one operation? Absolutely: Paillier (additive) lets you compute sums and averages on encrypted data, which is enough for voting, auctions, and basic statistics.
Prerequisites. You should be comfortable with:
The FHE dream and noise concepts (Notebook 11a)
RSA encryption basics (Module 04)
Discrete logarithm groups (Module 05)
Learning objectives. By the end of this notebook you will be able to:
Demonstrate RSA's multiplicative homomorphism.
Implement Paillier encryption and its additive homomorphism.
Show ElGamal's multiplicative homomorphism.
Understand why partial homomorphism is useful but not sufficient for general computation.
See why we need both operations for FHE.
1. RSA: Multiplicatively Homomorphic
Bridge from Notebook 11a. We said FHE needs both addition and multiplication on ciphertexts. Let's start with schemes that give us just one. RSA, the oldest public-key scheme, turns out to be multiplicatively homomorphic!
Recall textbook RSA:
Public key: , Private key:
The homomorphic property:
Checkpoint 1. RSA multiplication on ciphertexts is exact, no noise accumulates! The catch: textbook RSA is deterministic (same message → same ciphertext), so it's not CPA-secure. More importantly, RSA only supports multiplication, not addition.
2. Paillier: Additively Homomorphic
The Paillier cryptosystem (1999) is additively homomorphic: you can add ciphertexts to get the encryption of the sum. It works in .
Key generation:
Choose primes . Let ,
(standard choice)
Encrypt: where is random
Decrypt: where
Homomorphic addition:
Checkpoint 2. In Paillier, multiplying two ciphertexts produces the encryption of the sum. This is because , the exponents add. Like RSA, there's no noise growth, additions are unlimited.
3. ElGamal: Multiplicatively Homomorphic
ElGamal encryption is multiplicatively homomorphic, like RSA, but with the advantage of being probabilistic (CPA-secure).
Key generation: Choose group , generator , secret , public
Encrypt: for random
Homomorphic multiplication:
4. The Limitation: Why Partial Isn't Enough
| Scheme | Addition | Multiplication | Noise | CPA-secure |
|---|---|---|---|---|
| RSA | No | Yes (unlimited) | None | No (deterministic) |
| Paillier | Yes (unlimited) | No | None | Yes |
| ElGamal | No | Yes (unlimited) | None | Yes |
None of these give us both operations. Why does that matter?
Checkpoint 3. Partial homomorphism is already useful (voting, statistics, auctions), but it can't evaluate arbitrary functions. The key insight for FHE: if you have both addition and multiplication, you can evaluate any arithmetic circuit, and therefore any computation. This is why Gentry's breakthrough was so important.
Crypto foreshadowing. The next notebook introduces BGV, a scheme based on LWE that supports both addition and multiplication, but with noise growth that limits the computation depth. BGV uses modulus switching to manage this noise, avoiding the expensive bootstrapping for many practical circuits.
5. Exercises
Exercise 1 (Worked): Paillier Weighted Sum
Problem. Three employees have salaries . Compute the average salary using Paillier without revealing individual salaries.
Solution:
Exercise 2 (Guided): ElGamal Chain
Problem. Encrypt the values 2, 3, 5, 7 with ElGamal. Multiply all four ciphertexts homomorphically and verify the decrypted result equals .
Fill in the TODOs:
Exercise 3 (Independent): Paillier Auction
Problem. Design a sealed-bid auction using Paillier:
Five bidders submit encrypted bids: 100, 150, 200, 125, 175.
The auctioneer computes the encrypted total of all bids.
Show that the auctioneer can compute the total but cannot determine individual bids.
Challenge: Can Paillier alone determine the highest bid? Why or why not?
Summary
| Scheme | Homomorphic For | Noise | Key Property |
|---|---|---|---|
| RSA | Multiplication | None | Deterministic, not CPA-secure |
| Paillier | Addition + scalar multiply | None | Probabilistic, additive group structure in |
| ElGamal | Multiplication | None | Probabilistic, multiplicative group structure in |
| FHE | Both (but with noise) | Grows per operation | Requires noise management (next notebooks) |
Partially homomorphic schemes are fast, practical, and noise-free, but they can only compute one type of operation. FHE trades noise-free operation for universality: both addition and multiplication, which is enough to evaluate any circuit.
Next: 11c: The BGV Scheme