TL;DR
Homomorphic encryption is a way to encrypt data so that a computer can work on the encrypted values without decrypting them. If the computer adds or multiplies two ciphertexts, the result decrypts to the sum or product of the original numbers. This solves the problem of trusting a server with private data: the server can compute on it, but it never sees it.
Builds on: Public-Key Cryptography, Ring (Abstract Algebra) · Leads to: private machine learning and Secure Aggregation, where many parties' data must be combined without being revealed
Where it's used
Cloud computing on private records. A clinic or bank may want a cloud provider to run a calculation on its records without the provider reading them. The clinic encrypts the records, the provider computes on the ciphertexts, and only the clinic holds the key to read the answer.
Private statistics. Several organisations may want the total of their private counts, such as the number of users who did something, without revealing their own counts. Each sends encrypted counts to a combining server, which adds them, and only the total is decrypted. Protocols of this kind are one reason the idea is studied for federated learning.
Private search and lookup. A user can ask a server whether a record is in a database without revealing which record it is. The server works on the encrypted query and returns an encrypted answer.
How it works
Take a tiny example with a public-key scheme in which the keys are built from two small primes. Choose the primes p = 3 and q = 11, so n = p × q = 33. Choose the public exponent e = 3 and the private exponent d = 7. These are valid, because 3 × 7 = 21 leaves remainder 1 when divided by φ(33) = 20, where φ counts the numbers below 33 that share no factor with it: φ(33) = 2 × 10 = 20. The encryption of a message m is c = m^e mod n, and decryption is m = c^d mod n.
- Encrypt two numbers. Encrypt 2: 2³ = 8, so the ciphertext is 8. Encrypt 4: 4³ = 64, and 64 mod 33 = 31, so the ciphertext is 31. Check: each ciphertext is a number between 0 and 32.
- Multiply the ciphertexts. The server computes 8 × 31 = 248, and 248 mod 33 = 17. It never learns that 2 and 4 were involved. Check: the server did only multiplication and reduction mod 33.
- Decrypt the result. The key holder computes 17⁷ mod 33 and gets 8. Check: 8 is 2 × 4, the product of the original numbers.
- Why it worked. Encryption is a power, so (m₁ × m₂)³ = m₁³ × m₂³. Multiplying the ciphertexts therefore gives an encryption of the product. Check: 8 is the encryption of 2, and 2 × 4 = 8.
This is the whole idea: the scheme preserves one operation, and the decrypted result matches the operation on the originals. The rest of the lesson asks what it takes to preserve both addition and multiplication, which is what the word fully refers to.
- identity (no encryption)
- m → m³ mod 33
The math
A ring has an addition and a multiplication with the usual rules, and a structure-preserving map between two rings is called a homomorphism. An encryption scheme is homomorphic for an operation when the operation can be carried out on ciphertexts.
Let Enc be an encryption function, Dec its decryption, and ⊕ and ⊗ addition and multiplication of plaintexts. Let ⊞ and ⊠ be operations on ciphertexts. The scheme is homomorphic when, for all plaintexts a and b,
It is fully homomorphic when both operations are supported, because together they can express any computable function.
Step 1 in symbols
Encryption is Enc(m) = m^e mod n. With e = 3 and n = 33, Enc(2) = 2³ mod 33 = 8 and Enc(4) = 4³ mod 33 = 31. Here "mod n" means the remainder after dividing by n, as in modular arithmetic.
Step 2 in symbols
The ciphertext operation is ⊠, ordinary multiplication followed by reduction mod n: Enc(2) ⊠ Enc(4) = (8 × 31) mod 33 = 17.
Step 3 in symbols
Decryption is Dec(c) = c^d mod n with d = 7. So Dec(17) = 17⁷ mod 33. Compute the powers by repeated squaring: 17² = 289 ≡ 25, 17⁴ ≡ 25² = 625 ≡ 31, and 17⁷ = 17⁴ × 17² × 17 ≡ 31 × 25 × 17 ≡ 8 (mod 33).
Step 4 in symbols
Why multiplication commutes with encryption: (m₁ m₂)^e = m₁^e m₂^e, so Enc(m₁ m₂) = Enc(m₁) Enc(m₂) mod n. This is the homomorphism for multiplication. Multiplication by itself is not enough for a general computation, and the scheme must also support addition.
Noise in lattice schemes
Modern fully homomorphic schemes are built on polynomials over rings, with security based on a hard problem called learning with errors: a noisy linear system whose noise is hard to remove. Each ciphertext carries a small random error. Adding ciphertexts adds the errors, and multiplying them makes the error grow faster. Decryption works while the error stays below a threshold. When the error grows past that threshold, the result is garbage, so the scheme needs a step that resets the noise. That step is called bootstrapping, and it is the expensive part.
Worked examples
The key is n = 33, e = 3, d = 7. Encrypt 3 and 5, multiply the ciphertexts, and decrypt.
- Enc(3) = 3³ mod 33 = 27.
- Enc(5) = 5³ mod 33 = 125 mod 33 = 26.
- Multiply: 27 × 26 = 702, and 702 mod 33 = 702 − 33 × 21 = 702 − 693 = 9.
- Decrypt: 9⁷ mod 33. Compute 9² = 81 ≡ 15, 9⁴ ≡ 15² = 225 ≡ 27, and 9⁷ = 9⁴ × 9² × 9 ≡ 27 × 15 × 9 = 3645 ≡ 3645 − 33 × 110 = 3645 − 3630 = 15.
Interpretation: decryption gives 15, which is 3 × 5. The server multiplied encrypted numbers and the key holder read the product.
The same key is used. The server holds Enc(2), Enc(2) and Enc(4) and must compute the encrypted product of 2, 2 and 4.
- Enc(2) = 8, and Enc(4) = 31.
- Multiply the first two ciphertexts: 8 × 8 = 64, and 64 mod 33 = 31.
- Multiply by the third: 31 × 31 = 961, and 961 mod 33 = 961 − 33 × 29 = 961 − 957 = 4.
- Decrypt 4: 4⁷ mod 33. Compute 4² = 16, 4⁴ = 256 ≡ 256 − 231 = 25, and 4⁷ = 4⁴ × 4² × 4 ≡ 25 × 16 × 4 = 1600 ≡ 1600 − 1584 = 16.
Interpretation: the decrypted result is 16 = 2 × 2 × 4. The server never saw any of the three numbers.
A survey tool wants to count yes votes without reading any single vote. It uses exponential ElGamal, a public-key scheme where a message m is encoded as g^m mod p. Here p = 23 and g = 5. A yes vote is 1, a no vote is 0. The product of ciphertexts adds the hidden votes in the exponent: g^a × g^b = g^(a+b).
This is a toy: it leaves out the public key and the random value that a real exponential ElGamal ciphertext carries, so it shows only the product rule.
Each vote is encoded as 5 for yes and 1 for no. Take three votes: yes, no, yes.
- Encrypt: 5, 1, 5.
- The server multiplies: 5 × 1 × 5 = 25, and 25 mod 23 = 2.
- The key holder decrypts by finding the power of 5 that gives 2. Its table of powers of 5 mod 23 starts 5⁰ = 1, 5¹ = 5, 5² = 2, 5³ = 10, and so on.
- The power is 2, so the tally is 2.
Interpretation: two votes were yes. The server saw only the encrypted votes and their product.
Try it: four votes are yes, yes, yes, no. The server multiplies their encryptions and gets 10 mod 23. Using the same table, how many yes votes are there? Answer: 10 = 5³ mod 23, so there are 3 yes votes.
Common mistakes and tradeoffs
It is tempting to think that encrypting data and computing on it are the same as computing on plaintext. In fact the scheme only supports the operations it was designed for, and each operation has a cost. Textbook RSA, as in Example 1, supports multiplication but not addition, so it is not fully homomorphic. Fully homomorphic schemes support both, but every operation adds noise and the bootstrapping step is slow.
It is tempting to think that the server learns nothing, because it sees only ciphertexts. In fact it can still learn things from the shape of the computation, such as how many operations were performed or which inputs were used together. Good designs hide those patterns, and the protocol around the scheme matters as much as the scheme.
It is tempting to think that the exponential ElGamal tally in Example 3 is secure as shown. In fact it is not: the encryption used no randomness, so two people who vote the same way send the same ciphertext. A real scheme adds random values to each encryption, and the lookup, which is a discrete logarithm, is feasible only for small totals.
When to use it. Use homomorphic encryption when a party must compute on data it is not allowed to read, and the computation is small or can be batched, such as summing or comparing values.
When not to use it. Do not use it for everyday web traffic or for general computation over large data. The overhead over plain computation is large in typical settings, and an ordinary trusted server with symmetric encryption is simpler.
Alternatives. Secret sharing splits the data among several servers that jointly compute, so no single server sees the data. Secure multi-party computation combines such shares with other protocols. A trusted execution environment hardware-isolates the computation, which requires trusting the hardware instead of the mathematics.
History
Public-key encryption was introduced in the 1970s. In 1978, Rivest, Shamir and Adleman published the RSA scheme, and in the same year Rivest, Adleman and Dertouzos asked whether encrypted data could be processed without decryption. They called such schemes privacy homomorphisms. For about three decades, practical schemes supported only one operation at a time, and several were later broken.
In 2009, Craig Gentry showed how to build a fully homomorphic scheme, supporting both addition and multiplication, using ideal lattices and bootstrapping. The construction was too slow for most uses, but it proved that the goal was possible. Later schemes made the cost much lower and focused on practical settings, which is why the topic now shows up in private machine learning and data analysis.
Recap
- A homomorphic scheme lets a computer operate on ciphertexts so that the decrypted result matches the operation on the plaintexts.
- Textbook RSA is multiplicatively homomorphic, which the worked examples use to show the idea by hand.
- Fully homomorphic schemes support addition and multiplication together, which makes any computation possible in principle.
- Their security uses noisy problems such as learning with errors, and each operation grows the noise, so bootstrapping is needed.
- The main cost is speed, so they suit small or batched computations on private data.
Read next: Secure Aggregation, which combines private data from many parties, and the open problems in federated learning, which list homomorphic encryption among the tools for it.
Check yourself
QuestionRecall: what does it mean for an encryption scheme to be homomorphic for multiplication?Show answer
Multiplying two ciphertexts gives a ciphertext whose decryption is the product of the two plaintexts. The server can multiply without learning the numbers.
QuestionComputation: with n = 33, e = 3 and d = 7, encrypt 6 and 2, multiply the ciphertexts, and decrypt the result.Show answer
Enc(6) = 6³ mod 33 = 216 mod 33 = 216 − 198 = 18. Enc(2) = 8. The product is 18 × 8 = 144, and 144 mod 33 = 144 − 132 = 12. Decrypt: 12⁷ mod 33. Compute 12² = 144 ≡ 12, so 12 to any power is 12 (mod 33). The result is 12, which is 6 × 2.
QuestionWhy: why does textbook RSA not count as fully homomorphic?Show answer
Its homomorphism is only for multiplication. Adding two RSA ciphertexts does not give an encryption of the sum in general. A fully homomorphic scheme must support both operations, because together they can express any computable function.
QuestionApplied: a hospital wants a cloud service to compute an average of encrypted patient counts without reading them. Name one property of fully homomorphic schemes that makes this slow, and what would reduce the cost.Show answer
Each operation adds noise, so the scheme needs bootstrapping to reset it, and that step is expensive. Batching many values into one ciphertext, or limiting the computation to a small number of operations, reduces the cost. For a plain sum, a scheme that supports only addition is simpler still.
Sources
- Wikipedia, "Homomorphic encryption": https://en.wikipedia.org/wiki/Homomorphic_encryption
- Rivest, Shamir, Adleman (1978), "A method for obtaining digital signatures and public-key cryptosystems": https://doi.org/10.1145/359340.359342