Caloogy Blog
中文

Homomorphic Encryption Explained

Date
Apr 9, 2026
Series
Cryptography
Reading
19 min
Topics
Homomorphic encryptionFHELatticeLWE

The one-sentence version

Homomorphic encryption lets someone compute directly on ciphertexts without decrypting them, and the resulting ciphertext decrypts to exactly what the same computation on the plaintexts would give. In the language of abstract algebra: the decryption map Dec\mathrm{Dec} is (approximately) a ring homomorphism on "valid ciphertexts", that is, Dec(c1+c2)=Dec(c1)+Dec(c2),Dec(c1⋅c2)=Dec(c1)⋅Dec(c2).\mathrm{Dec}(c_1 + c_2) = \mathrm{Dec}(c_1) + \mathrm{Dec}(c_2),\qquad \mathrm{Dec}(c_1 \cdot c_2) = \mathrm{Dec}(c_1)\cdot \mathrm{Dec}(c_2).

This article has three layers:

  1. The intuition: no mathematics needed
  2. Real-world use: private cloud computing, medical and genomic data, joint bank risk control, private machine learning, electronic voting, private information retrieval, the state of the industry and the performance cost
  3. The mathematics: RSA, Paillier, ElGamal, ring homomorphisms, LWE/RLWE, noise, modulus switching, bootstrapping and BGV/BFV/CKKS, with small worked examples

Layer 1: The Intuition

1.1 Working on a locked box through gloves

Imagine a jeweler with a craftsman he doesn't trust, fearing he will steal the gold. So the jeweler arranges this:

  1. The gold goes into a locked transparent glove box, with a pair of gloves reaching in from the side.
  2. The craftsman puts his hands in the gloves and can melt, draw and solder the gold into a necklace inside the box.
  3. But the craftsman can't open the lock, so he can't touch the gold or take it away.
  4. When he finishes, the box goes back to the jeweler, who alone has the key and opens it to get the finished piece.

The correspondence:

Analogy In homomorphic encryption
The gold Your private data (plaintext)
The locked glove box Ciphertext
The craftsman A cloud server / third party
Working through gloves Computing on ciphertexts
The key The private key, which only you have
The finished necklace The result, visible only after decryption

The key point: the craftsman works the whole time, yet never learns what the gold looks like. Ordinary encryption only achieves "locked for storage and transport", and has to be unlocked before any computation; homomorphic encryption achieves "can be processed while locked".

1.2 What "computing directly on ciphertexts" means

Take the simplest example. You have two numbers, 33 and 55, and want a cloud server to compute 3+53+5 for you, without the server knowing the two numbers.

Cloud server (no private key)

You (with the private key)

encrypt

upload

download

Plaintexts 3 and 5

Ciphertexts Enc(3), Enc(5)

Decrypt to get 8

'Add' the ciphertexts

Get ciphertext Enc(8)

All the server sees is two strings of gibberish. It performs some "ciphertext addition" on them and gets a third string of gibberish. You decrypt the third string and get exactly 88. The server knows neither that the inputs were 33 and 55 nor that the result is 88.

Note that "ciphertext addition" is generally not adding the two strings of digits directly. For Paillier, it is multiplying two ciphertexts; for lattice schemes, it really is adding vectors or polynomials. The exact operation depends on the scheme, as Layer 3 explains.

1.3 Three levels: PHE, SHE, FHE

Any computation can ultimately be broken down into addition and multiplication (XOR and AND gates, on bits), so the key questions are which operations can be done on ciphertexts, and how many times.

Type Full name What it can do Typical examples
PHE Partially Homomorphic Encryption Supports only one operation (only addition or only multiplication), any number of times RSA (multiplication), ElGamal (multiplication), Paillier (addition)
SHE Somewhat Homomorphic Encryption Supports both addition and multiplication, but a limited number of times; do too many and it can't be decrypted Some lattice schemes before Gentry; BGV/BFV without bootstrapping
FHE Fully Homomorphic Encryption Supports both addition and multiplication without limit, computing any function Schemes from Gentry 2009 on; BGV/BFV/CKKS with bootstrapping, TFHE

One way to remember them:

A historical aside

In 1978, RSA's inventors Rivest and Adleman, together with Dertouzos, proposed the idea of a "privacy homomorphism", asking whether arbitrary computation on encrypted data was possible. The question stayed open for 31 years, until Craig Gentry gave the first fully homomorphic encryption scheme in his 2009 PhD thesis.

1.4 Why it's called "homomorphic"

"Homomorphism" is a mathematical word meaning literally "the same shape". In abstract algebra, a ring homomorphism φ:R→S\varphi: R \to S is a map satisfying

φ(a+b)=φ(a)+φ(b),φ(ab)=φ(a)φ(b).\varphi(a+b) = \varphi(a) + \varphi(b),\qquad \varphi(ab) = \varphi(a)\varphi(b).

It "carries" the operations of RR into SS: operate then map equals map then operate.

Homomorphic encryption says exactly this, usually viewed in the other direction: decryption, the map from ciphertexts to plaintexts, preserves operations, that is,

Dec(c1⊕c2)=Dec(c1)+Dec(c2),Dec(c1⊗c2)=Dec(c1)⋅Dec(c2),\mathrm{Dec}(c_1 \oplus c_2) = \mathrm{Dec}(c_1) + \mathrm{Dec}(c_2),\qquad \mathrm{Dec}(c_1 \otimes c_2) = \mathrm{Dec}(c_1)\cdot \mathrm{Dec}(c_2),

where ⊕,⊗\oplus, \otimes are the corresponding operations in the ciphertext space. In other words, "computing in the ciphertext world" and "computing in the plaintext world" have the same shape, hence the name.

Strictly speaking, though, decryption in modern fully homomorphic schemes is only an approximate homomorphism, because each operation brings in a little noise. Layer 3 covers this in detail.


Layer 2: Real-World Use

2.1 Private cloud computing (outsourced computation)

This is the original motivation for homomorphic encryption. A company wants to use computing power in the cloud, but its data is sensitive (finances, medical records, user behavior):

It protects "data in use". Transport encryption (TLS) protects "data in transit" and disk encryption protects "data at rest", and the moment of computation is exactly the gap neither covers.

2.2 Medical and genomic data analysis

Data sharing among hospitals and research institutions is strictly limited by law (such as HIPAA in the US and GDPR in the EU). Homomorphic encryption allows:

Since 2014 academia has held the annual iDASH competition in privacy-preserving genomic analysis, with homomorphic encryption always a main track; tasks have included genome-wide association studies (GWAS) and logistic regression training on ciphertexts.

2.3 Joint risk control and anti-money-laundering among banks

Money launderers often scatter funds across many banks, and each bank sees only its own segment, not the whole picture; yet banks can't freely share customer data with each other.

Homomorphic encryption works like this: each bank encrypts transaction features and hands them to a joint analyst, who assembles a cross-bank flow graph and computes risk scores on ciphertexts, finally decrypting only the conclusion "this account is suspicious". Similar ideas are used for joint credit scoring and cross-institution blacklist queries. Real systems often combine homomorphic encryption with secure multi-party computation (MPC) and private set intersection (PSI).

2.4 Private machine learning inference

The model is on the server, the data is with the user, and neither wants to hand theirs over:

  1. The user encrypts the input (a chest X-ray, say, or speech features) and sends it to the server;
  2. The server runs inference with a plaintext model on the encrypted input, with matrix multiplication implemented by homomorphic addition and multiplication;
  3. An encrypted prediction comes back, which only the user can decrypt.

The difficulty is activation functions. Non-polynomial functions like ReLU and sigmoid can't be computed directly. Common approaches are low-degree polynomial approximation (where CKKS excels) or direct table lookup with TFHE's programmable bootstrapping. Zama's Concrete ML is a tool that automatically compiles scikit-learn and PyTorch models into FHE circuits.

2.5 Electronic voting

Voting was one of the earliest successful applications of homomorphic encryption, using additive homomorphism:

The open-source Helios voting system uses exponential ElGamal (see section 3.3) for homomorphic tallying, along with zero-knowledge proofs that each ballot really is 00 or 11 and not a cheating ballot like Enc(1000)\mathrm{Enc}(1000).

2.6 Private information retrieval (PIR)

You want to look up a record in a public database, without the database knowing which one you looked up.

With homomorphic encryption: encode the query as an encrypted "selection vector" Enc(0),…,Enc(1),…,Enc(0)\mathrm{Enc}(0), \dots, \mathrm{Enc}(1), \dots, \mathrm{Enc}(0) (only position ii is 11), and the server computes

∑jEnc(ej)⋅DBj=Enc(DBi).\sum_j \mathrm{Enc}(e_j)\cdot \mathrm{DB}_j = \mathrm{Enc}(\mathrm{DB}_i).

The server performs the same operation on every record, so it has no idea what ii is. Real schemes compress the selection vector and use recursive layers to reduce communication.

2.7 The state of the industry

1978RSA is found to bemultiplicativelyhomomorphicRivest et al. proposeprivacyhomomorphisms1985ElGamal1999Paillier's additivehomomorphism2005Regev introduces theLWE problem2009Gentry's first fullyhomomorphic scheme(bootstrapping)2011-2012BGV, BFV2016TFHE (fastbootstrapping)2017CKKS (approximatereal-numberarithmetic)2024Apple deploys it in iOS18 (Live Caller IDLookup)A short history of homomorphic encryption

Main open-source libraries

Library Maintainer Schemes supported Notes
Microsoft SEAL Microsoft Research BFV, BGV, CKKS C++, good documentation, the first choice for beginners
OpenFHE Community (successor to PALISADE, with DARPA funding background) BGV, BFV, CKKS, FHEW, TFHE-style schemes The most complete, supporting many bootstrapping methods and scheme switching
TFHE-rs / Concrete Zama (France) TFHE Rust; Boolean and integer circuits, programmable bootstrapping; also used for encrypted smart contracts on blockchains (fhEVM)
HElib IBM BGV, CKKS An earlier implementation
Lattigo Tune Insight / EPFL BFV, BGV, CKKS Go; supports multiparty (threshold) homomorphic encryption
swift-homomorphic-encryption Apple BFV Used for Apple's own PIR deployment

A real deployment: Apple

In addition, Google has open-sourced FHE compilers (HEIR and others), Intel offers the HEXL acceleration library, and DARPA's DPRIVE program funds dedicated FHE accelerator chips. On standardization, ISO/IEC 18033-6 already includes partially homomorphic schemes like ElGamal and Paillier, while standardization of fully homomorphic schemes (driven by the HomomorphicEncryption.org community) is still under way.

2.8 The performance cost

The main problems of homomorphic encryption are that it is slow and big.

Dimension Cost (orders of magnitude, varying widely with scheme, parameters and hardware)
Compute speed About 10310^3 to 10610^6 times slower than plaintext computation
Ciphertext expansion One RLWE ciphertext is often several hundred KB to several MB
Bootstrapping The most expensive operation. TFHE single-bit bootstrapping takes milliseconds on a CPU; one CKKS bootstrap may take seconds to tens of seconds, but handles thousands of slots at once
Programming difficulty Everything must be written as a "circuit": no data-dependent branches (if x > 0 must be rewritten as a polynomial or table lookup), and loop counts must be fixed

For an order-of-magnitude example: with parameters n=214n = 2^{14} and log⁡2q≈438\log_2 q \approx 438, a ciphertext consists of two polynomials, about

2×214×438 bit≈1.4×107 bit≈1.8 MB.2 \times 2^{14} \times 438 \ \text{bit} \approx 1.4\times 10^{7}\ \text{bit} \approx 1.8\ \text{MB}.

Fortunately, with batching (see section 3.7), one ciphertext can hold thousands of numbers for SIMD parallel computation, and the amortized cost is much lower.

Why it's still worth using

Where "data absolutely can't leave a certain boundary" (medicine, finance, government, cross-border data flows), being able to use it beats not being able to; and many applications (PIR, voting, simple statistics, small-model inference) need only shallow circuits, with entirely acceptable overhead.


Layer 3: The Mathematics

3.1 RSA's multiplicative homomorphism

Textbook RSA: choose two large primes p,qp, q, let n=pqn = pq and φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1), take ee with gcd⁡(e,φ(n))=1\gcd(e, \varphi(n)) = 1, and d≡e−1(modφ(n))d \equiv e^{-1} \pmod{\varphi(n)}.

Enc(m)=me mod n,Dec(c)=cd mod n.\mathrm{Enc}(m) = m^e \bmod n,\qquad \mathrm{Dec}(c) = c^d \bmod n.

The multiplicative homomorphism is almost obvious:

Enc(a)⋅Enc(b)=aebe=(ab)e=Enc(ab)(modn).\mathrm{Enc}(a)\cdot \mathrm{Enc}(b) = a^e b^e = (ab)^e = \mathrm{Enc}(ab) \pmod n.

In the language of abstract algebra, x↦xex \mapsto x^e is a homomorphism from the multiplicative monoid (Zn,⋅)(\mathbb{Z}_n, \cdot) to itself (restricted to the unit group Zn×\mathbb{Z}_n^\times, it is a group automorphism). But it doesn't preserve addition: in general (a+b)e≠ae+be(a+b)^e \neq a^e + b^e. So RSA is only PHE.

A worked example: RSA's multiplicative homomorphism

Take p=5p = 5 and q=11q = 11, so n=55n = 55 and φ(n)=40\varphi(n) = 40. Take e=3e = 3; from 3⋅27=81≡1(mod40)3 \cdot 27 = 81 \equiv 1 \pmod{40} we get d=27d = 27.

  • Enc(2)=23=8\mathrm{Enc}(2) = 2^3 = 8
  • Enc(3)=33=27\mathrm{Enc}(3) = 3^3 = 27
  • Multiply the ciphertexts: 8⋅27=216≡216−3⋅55=51(mod55)8 \cdot 27 = 216 \equiv 216 - 3\cdot 55 = 51 \pmod{55}
  • Encrypt 66 directly: 63=216≡51(mod55)6^3 = 216 \equiv 51 \pmod{55}, and the two agree
  • Decrypt: 5127≡6(mod55)51^{27} \equiv 6 \pmod{55}

So Enc(2)⋅Enc(3)=Enc(6)\mathrm{Enc}(2)\cdot\mathrm{Enc}(3) = \mathrm{Enc}(6), that is, Enc(2) Enc(3)=Enc(2⋅3)\mathrm{Enc}(2)\,\mathrm{Enc}(3) = \mathrm{Enc}(2\cdot 3). (Checked with Python.)

Why textbook RSA is insecure

  1. Determinism: the same mm encrypts to the same result every time. If the plaintext space is small (a vote has only "yes/no"), an attacker can encrypt every possible plaintext and compare. Secure public-key encryption must be randomized to achieve semantic security (IND-CPA).
  2. Malleability: without knowing mm, an attacker can replace cc with c⋅2ec \cdot 2^e, and the recipient decrypts 2m2m. For something like "transfer amount" this is a disaster. Note that homomorphism itself is malleability, so no homomorphic encryption can reach the strongest IND-CCA2 security, and it can only aim for IND-CPA.
  3. Small-plaintext attacks: if e=3e = 3 and m3<nm^3 < n, then c=m3c = m^3 never wraps around in the integers, and taking the cube root gives mm directly.

RSA in actual use always applies random padding first (such as OAEP), and padding happens to destroy the homomorphism. So RSA's homomorphism is more a teaching example than a practical tool.

3.2 Paillier: additive homomorphism

Paillier (1999) is the most widely used additively homomorphic scheme, based on the composite residuosity assumption: distinguishing "nn-th powers" from "random elements" in Zn2×\mathbb{Z}_{n^2}^\times is hard.

Key generation: take large primes p,qp, q, with n=pqn = pq, λ=lcm⁡(p−1,q−1)\lambda = \operatorname{lcm}(p-1, q-1) and g=n+1g = n + 1. Define L(x)=x−1nL(x) = \dfrac{x - 1}{n} and let μ=λ−1 mod n\mu = \lambda^{-1} \bmod n. The public key is (n,g)(n, g) and the private key is (λ,μ)(\lambda, \mu).

Encryption: for plaintext m∈Znm \in \mathbb{Z}_n, pick a random r∈Zn×r \in \mathbb{Z}_n^\times,

Enc(m;r)=gmrn mod n2.\mathrm{Enc}(m; r) = g^m r^n \bmod n^2.

Decryption:

Dec(c)=L ⁣(cλ mod n2)⋅μ mod n.\mathrm{Dec}(c) = L\!\left(c^\lambda \bmod n^2\right)\cdot \mu \bmod n.

Why decryption works:

Additive homomorphism:

Enc(m1;r1)⋅Enc(m2;r2)=gm1+m2(r1r2)n=Enc(m1+m2; r1r2)(modn2).\mathrm{Enc}(m_1; r_1)\cdot\mathrm{Enc}(m_2; r_2) = g^{m_1+m_2}(r_1 r_2)^n = \mathrm{Enc}(m_1 + m_2;\ r_1 r_2) \pmod{n^2}.

Multiplying ciphertexts corresponds to adding plaintexts. There is also scalar multiplication: Enc(m)k=Enc(km)\mathrm{Enc}(m)^k = \mathrm{Enc}(km). So Paillier can compute "linear combinations of encrypted data", such as weighted sums and averages, but not the product of two encrypted plaintexts.

The group homomorphism view

The map Zn×Zn×→Zn2×\mathbb{Z}_n \times \mathbb{Z}_n^\times \to \mathbb{Z}_{n^2}^\times, (m,r)↦gmrn(m, r) \mapsto g^m r^n is a group isomorphism: the operation on the left is (m1,r1)⋅(m2,r2)=(m1+m2, r1r2)(m_1, r_1)\cdot(m_2, r_2) = (m_1 + m_2,\ r_1 r_2), and on the right it is multiplication. Both sides have order nφ(n)n\varphi(n). Paillier's additive homomorphism is a direct corollary of this isomorphism.

A worked example: Paillier's additive homomorphism

Take p=5p = 5 and q=7q = 7, so n=35n = 35, n2=1225n^2 = 1225, g=36g = 36 and λ=lcm⁡(4,6)=12\lambda = \operatorname{lcm}(4, 6) = 12. Since gλ=(1+n)12≡1+12ng^\lambda = (1+n)^{12} \equiv 1 + 12n, L(gλ)=12L(g^\lambda) = 12, so μ=12−1 mod 35=3\mu = 12^{-1} \bmod 35 = 3 (because 12⋅3=36≡112 \cdot 3 = 36 \equiv 1).

Encrypt m1=4m_1 = 4 with r1=2r_1 = 2:

  • g4≡1+4⋅35=141(mod1225)g^{4} \equiv 1 + 4\cdot 35 = 141 \pmod{1225}
  • 235≡18(mod1225)2^{35} \equiv 18 \pmod{1225}
  • c1=141⋅18=2538≡88(mod1225)c_1 = 141 \cdot 18 = 2538 \equiv 88 \pmod{1225}

Encrypt m2=6m_2 = 6 with r2=3r_2 = 3:

  • g6≡1+6⋅35=211(mod1225)g^{6} \equiv 1 + 6\cdot 35 = 211 \pmod{1225}
  • 335≡607(mod1225)3^{35} \equiv 607 \pmod{1225}
  • c2=211⋅607=128077≡677(mod1225)c_2 = 211 \cdot 607 = 128077 \equiv 677 \pmod{1225}

Multiply the ciphertexts: c=c1c2=88⋅677=59576≡776(mod1225)c = c_1 c_2 = 88 \cdot 677 = 59576 \equiv 776 \pmod{1225}

Decrypt cc:

  • 77612≡526(mod1225)776^{12} \equiv 526 \pmod{1225}
  • L(526)=526−135=15L(526) = \dfrac{526 - 1}{35} = 15
  • 15⋅3=45≡10(mod35)15 \cdot 3 = 45 \equiv 10 \pmod{35}

This gives 10=4+610 = 4 + 6. For comparison, decrypting c1c_1 alone: 8812≡45688^{12} \equiv 456, L(456)=13L(456) = 13, 13⋅3=39≡413\cdot 3 = 39 \equiv 4, which is correct.

Two additional points (both checked with Python):

  • Scalar multiplication: c13≡372(mod1225)c_1^3 \equiv 372 \pmod{1225}, which decrypts to 12=3⋅412 = 3 \cdot 4.
  • Plaintexts add in Z35\mathbb{Z}_{35}: Enc(30)⋅Enc(10)\mathrm{Enc}(30)\cdot\mathrm{Enc}(10) decrypts to 40 mod 35=540 \bmod 35 = 5, so in practice nn must be much larger than any possible result.

3.3 ElGamal: multiplicative homomorphism, and the additive "exponential" version

Let G=⟨g⟩G = \langle g \rangle be a cyclic group with a hard discrete logarithm (such as a subgroup of Zp×\mathbb{Z}_p^\times or an elliptic curve group). The private key is xx and the public key is h=gxh = g^x.

Enc(m;k)=(gk, mhk),Dec(c1,c2)=c2⋅c1−x.\mathrm{Enc}(m; k) = (g^k,\ m h^k),\qquad \mathrm{Dec}(c_1, c_2) = c_2 \cdot c_1^{-x}.

It is naturally randomized (a fresh kk each time) and IND-CPA secure under the DDH assumption. Multiplying componentwise gives

(gk1,m1hk1)⋅(gk2,m2hk2)=(gk1+k2, m1m2 hk1+k2)=Enc(m1m2; k1+k2),(g^{k_1}, m_1 h^{k_1})\cdot (g^{k_2}, m_2 h^{k_2}) = (g^{k_1+k_2},\ m_1 m_2\, h^{k_1+k_2}) = \mathrm{Enc}(m_1 m_2;\ k_1 + k_2),

so ElGamal is multiplicatively homomorphic.

A worked example: ElGamal

Take p=23p = 23 and g=5g = 5 (a generator of Z23×\mathbb{Z}_{23}^\times), with private key x=6x = 6 and public key h=56≡8(mod23)h = 5^6 \equiv 8 \pmod{23}.

  • Enc(3;k=2)=(52, 3⋅82)≡(2, 8)\mathrm{Enc}(3; k=2) = (5^2,\ 3\cdot 8^2) \equiv (2,\ 8)
  • Enc(4;k=7)=(57, 4⋅87)≡(17, 2)\mathrm{Enc}(4; k=7) = (5^7,\ 4\cdot 8^7) \equiv (17,\ 2)
  • Multiply componentwise: (2⋅17, 8⋅2)≡(11, 16)(2\cdot 17,\ 8 \cdot 2) \equiv (11,\ 16)
  • Decrypt: 116≡911^6 \equiv 9, 9−1≡189^{-1} \equiv 18, 16⋅18=288≡12(mod23)16 \cdot 18 = 288 \equiv 12 \pmod{23}

This gives 12=3⋅412 = 3 \cdot 4. (Checked with Python.)

Exponential ElGamal: put the plaintext in the exponent, encrypting gmg^m instead of mm:

Enc(m;k)=(gk, gmhk).\mathrm{Enc}(m; k) = (g^k,\ g^m h^k).

Multiplying then gives gm1+m2g^{m_1+m_2}, which makes it additively homomorphic. The cost is that decryption yields only gmg^m, and another discrete logarithm must be solved to get mm, so it suits only small mm. Tallying votes fits exactly (the total can't exceed the number of voters), and this is what Helios does.

The common limits of PHE

RSA, Paillier and ElGamal each have only one operation, and their security all rests on factoring or discrete logarithms, which Shor's algorithm breaks on a quantum computer. The lattice schemes below solve both problems at once.

3.4 Ring homomorphisms, and why encryption is only an "approximate ring homomorphism"

Recall the definition: a map φ:R→S\varphi: R \to S between rings satisfying

φ(a+b)=φ(a)+φ(b),φ(ab)=φ(a)φ(b),φ(1)=1,\varphi(a + b) = \varphi(a) + \varphi(b),\qquad \varphi(ab) = \varphi(a)\varphi(b),\qquad \varphi(1) = 1,

is called a ring homomorphism.

Why we want a ring homomorphism: any function f:F2k→F2f: \mathbb{F}_2^k \to \mathbb{F}_2 can be written as a polynomial over F2\mathbb{F}_2 (addition == XOR, multiplication == AND), and similarly for functions on Zt\mathbb{Z}_t. If decryption Dec\mathrm{Dec} is a ring homomorphism, then for any polynomial PP,

Dec(P(c1,…,ck))=P(Dec(c1),…,Dec(ck)).\mathrm{Dec}\big(P(c_1, \dots, c_k)\big) = P\big(\mathrm{Dec}(c_1), \dots, \mathrm{Dec}(c_k)\big).

That is, "computing PP on ciphertexts" equals "computing PP on plaintexts", which computes any function: full homomorphism.

Why it can't really be a ring homomorphism: if Enc\mathrm{Enc} itself were a deterministic ring homomorphism φ:Zt→S\varphi: \mathbb{Z}_t \to S, an attacker could mount an algebraic attack with the public operations. A ring homomorphism must satisfy φ(1)=1S\varphi(1) = 1_S, and 1S1_S is public, so an attacker can compute φ(2)=1S+1S\varphi(2) = 1_S + 1_S, φ(3)=1S+1S+1S\varphi(3) = 1_S + 1_S + 1_S and so on, listing the ciphertext of every plaintext in a table and looking up any ciphertext, with no security whatsoever. In abstract algebra terms, by the first isomorphism theorem im⁡φ≅Zt/ker⁡φ\operatorname{im}\varphi \cong \mathbb{Z}_t/\ker\varphi, the structure of the image is completely determined by public algebraic data.

The solution: add noise. In modern schemes,

What truly preserves operations is the phase map, an exact homomorphism; "rounding" is compatible with the operations only while the noise is small enough. So encryption is an approximate ring homomorphism: the homomorphism holds as long as the noise hasn't grown too large.

3.5 LWE and RLWE

The LWE problem (Learning With Errors, Regev 2005): take a modulus qq and a secret vector s∈Zqns \in \mathbb{Z}_q^n. You are given many pairs

(ai, bi=⟨ai,s⟩+ei mod q),(a_i,\ b_i = \langle a_i, s\rangle + e_i \bmod q),

where aia_i is uniformly random and eie_i is a small random error. The task is to find ss (the search version), or to distinguish these (ai,bi)(a_i, b_i) from uniformly random pairs (the decision version).

A minimal LWE encryption (symmetric key, encrypting one bit m∈{0,1}m \in \{0, 1\}): let Δ=⌊q/2⌋\Delta = \lfloor q/2 \rfloor,

Enc(m)=(a, b)=(a, ⟨a,s⟩+e+Δm),phase φs(a,b)=b−⟨a,s⟩=Δm+e.\mathrm{Enc}(m) = (a,\ b) = \big(a,\ \langle a, s\rangle + e + \Delta m\big),\qquad \text{phase } \varphi_s(a, b) = b - \langle a, s\rangle = \Delta m + e.

Decryption checks whether the phase is closer to 00 or to Δ\Delta. The key observation: the phase map φs\varphi_s is Zq\mathbb{Z}_q-linear (a module homomorphism), so adding two ciphertexts adds their phases:

φs(c1+c2)=Δ(m1+m2)+(e1+e2).\varphi_s(c_1 + c_2) = \Delta(m_1 + m_2) + (e_1 + e_2).

A worked example: homomorphic addition on LWE (addition modulo 2)

Take q=97q = 97, Δ=48\Delta = 48 and secret s=(5,11)s = (5, 11).

Encrypt m1=1m_1 = 1 with a=(23,40)a = (23, 40) and e1=2e_1 = 2: ⟨a,s⟩=115+440=555≡70\langle a, s\rangle = 115 + 440 = 555 \equiv 70 and b=70+2+48=120≡23b = 70 + 2 + 48 = 120 \equiv 23, so c1=((23,40), 23)c_1 = \big((23, 40),\ 23\big). The phase is =23−70≡50=48+2= 23 - 70 \equiv 50 = 48 + 2, close to Δ\Delta, so it decrypts to 11.

Encrypt m2=1m_2 = 1 with a=(61,7)a = (61, 7) and e2=−3e_2 = -3: ⟨a,s⟩=305+77=382≡91\langle a, s\rangle = 305 + 77 = 382 \equiv 91 and b=91−3+48=136≡39b = 91 - 3 + 48 = 136 \equiv 39, so c2=((61,7), 39)c_2 = \big((61, 7),\ 39\big). The phase is =45=48−3= 45 = 48 - 3, which decrypts to 11.

Add: c1+c2=((84,47), 62)c_1 + c_2 = \big((84, 47),\ 62\big). ⟨(84,47),s⟩=420+517=937≡64\langle (84, 47), s\rangle = 420 + 517 = 937 \equiv 64, and the phase is =62−64≡−2≡95= 62 - 64 \equiv -2 \equiv 95. −2-2 is close to 00, so it decrypts to 00, and 1⊕1=01 \oplus 1 = 0, which is correct.

Here 2Δ=96≡−1(mod97)2\Delta = 96 \equiv -1 \pmod{97}, so the phase equals −1+e1+e2=−2-1 + e_1 + e_2 = -2. The noise went from ∣e∣≤3|e| \le 3 to 22 plus a rounding error, and decryption is correct as long as the absolute value of the total noise doesn't exceed q/4≈24q/4 \approx 24. (Checked with Python.)

RLWE (Ring-LWE, Lyubashevsky–Peikert–Regev 2010): replace vectors with the polynomial ring

Rq=Zq[x]/(xn+1),n=2k.R_q = \mathbb{Z}_q[x]/(x^n + 1),\qquad n = 2^k.

Samples become (a, b=a⋅s+e)∈Rq2(a,\ b = a\cdot s + e) \in R_q^2, where a,s,ea, s, e are all polynomials and ee has small coefficients. There are two benefits:

Why xn+1x^n + 1: when nn is a power of 22, xn+1=Φ2n(x)x^n + 1 = \Phi_{2n}(x) is the 2n2n-th cyclotomic polynomial, irreducible over Q\mathbb{Q} (Eisenstein's criterion applied after x↦x+1x \mapsto x+1). Because xn≡−1x^n \equiv -1, multiplication in this quotient ring is a "negacyclic convolution", convenient to compute, and its geometric properties (the canonical embedding) are good, keeping noise growth under control. This is exactly the quotient ring F[x]/(f)F[x]/(f) from abstract algebra.

3.6 Noise growth, modulus switching, bootstrapping

Ciphertext multiplication and the "evaluation homomorphism"

In RLWE schemes, a ciphertext (c0,c1)(c_0, c_1) can be viewed as a linear polynomial in an unknown yy: c(y)=c0+c1y∈Rq[y]c(y) = c_0 + c_1 y \in R_q[y]. The first step of decryption is substituting y=sy = s:

evs:Rq[y]→Rq,c(y)↦c(s)=c0+c1s.\mathrm{ev}_s: R_q[y] \to R_q,\qquad c(y) \mapsto c(s) = c_0 + c_1 s.

This is exactly the evaluation homomorphism from abstract algebra, an exact ring homomorphism. So the product of two ciphertexts is defined as the polynomial product:

c(y)⋅c′(y)=c0c0′+(c0c1′+c1c0′) y+c1c1′ y2,c(y)\cdot c'(y) = c_0c_0' + (c_0c_1' + c_1c_0')\,y + c_1c_1'\, y^2,

which after substituting ss is exactly c(s)⋅c′(s)c(s)\cdot c'(s). After multiplying, the ciphertext is quadratic in yy (three components), and relinearization (using a public encryption of s2s^2, the key-switching key) turns it back into a linear one.

How noise grows: in BGV style, let the phase be c(s)=m+tec(s) = m + t e (the plaintext is in the "low bits", read modulo tt).

Operation Phase Noise size
Addition (m+m′)+t(e+e′)(m + m') + t(e + e') Adds: ∣e∣+∣e′∣\lvert e\rvert + \lvert e' \rvert
Multiplication mm′+t (me′+m′e+tee′)mm' + t\,(me' + m'e + t ee') Roughly multiplies: ∼t ∣e∣∣e′∣\sim t\,\lvert e\rvert \lvert e' \rvert

Addition grows noise linearly, and multiplication grows it quadratically. After LL levels of consecutive multiplication, the noise is roughly B2LB^{2^L}, an exponential explosion. Once the noise exceeds the order of q/2q/2, reduction "wraps around" and decryption fails. This is why SHE can do only a limited number of multiplications.

Modulus switching (the core technique of BGV): after each multiplication, scale the whole ciphertext down,

c ↦ c′=⌊q′q c⌉,q′<q.c \ \mapsto\ c' = \Big\lfloor \tfrac{q'}{q}\, c \Big\rceil,\qquad q' < q.

The noise shrinks by the factor q′/qq'/q too, while (with suitable correction) the plaintext is unchanged. In other words, the absolute size of the noise is pressed back to its original level, at the cost of a smaller modulus and less "remaining room". In practice one takes q=q0q1⋯qLq = q_0 q_1 \cdots q_L as a product of a chain of primes, "dropping" one prime after each level of multiplication, turning exponential noise growth into growth linear in the number of levels LL. This chain of primes is represented using the Chinese Remainder Theorem (the RNS representation), also from abstract algebra.

multiply

modulus switch

multiply

modulus switch

bootstrap

Fresh ciphertext
small noise
modulus q_L

Noise grows

Noise pressed back
modulus drops to q_(L-1)

...

Modulus q_0
no levels left

Gentry's bootstrapping: what happens when the levels run out? Gentry's idea is to "run the decryption algorithm homomorphically":

  1. In advance, encrypt the private key ss under itself (or another public key), and publish Enc(s)\mathrm{Enc}(s), called the bootstrapping key.
  2. Take a ciphertext cc whose noise is nearly full. The server treats each bit of cc as a constant and Enc(s)\mathrm{Enc}(s) as the encrypted input, and homomorphically computes the decryption circuit Dec(⋅,c)\mathrm{Dec}(\cdot, c): Eval(Dec(⋅, c), Enc(s))=Enc(Dec(s,c))=Enc(m).\mathrm{Eval}\big(\mathrm{Dec}(\cdot,\ c),\ \mathrm{Enc}(s)\big) = \mathrm{Enc}\big(\mathrm{Dec}(s, c)\big) = \mathrm{Enc}(m).
  3. The result is still a ciphertext of mm, but its noise comes only from "computing the decryption circuit", independent of the noise in the original cc.

As long as a scheme can homomorphically compute its own decryption circuit and still has room for at least one more multiplication (called bootstrappable), ciphertexts can be "refreshed" without limit, upgrading SHE to FHE.

Two details

  • Publishing Enc(s)\mathrm{Enc}(s) (encrypting ss under itself) needs an extra circular security assumption, which hasn't been proved, though no attack on it is known.
  • In the glove box analogy: the contents of box A are nearly impossible to see, so put all of box A inside a new clean box B, and lock A's key in B as well (the key is encrypted, so no one can use it directly). Then, through B's gloves, use A's key to open A. The contents are now in the clean box B, and no one ever saw the plaintext.

3.7 The differences among BGV, BFV, CKKS (and TFHE)

The ciphertexts of the three main RLWE schemes all live in Rq=Zq[x]/(xn+1)R_q = \mathbb{Z}_q[x]/(x^n + 1). They differ in where the plaintext sits in the phase:

Scheme Shape of the phase c0+c1sc_0 + c_1 s Plaintext space Good for
BGV (2011) m+t em + t\,e, plaintext in the low bits Rt=Zt[x]/(xn+1)R_t = \mathbb{Z}_t[x]/(x^n + 1), exact integer arithmetic Exact integer arithmetic modulo tt; manages noise with modulus switching
BFV (2012) Δm+e\Delta m + e, Δ=⌊q/t⌋\Delta = \lfloor q/t \rfloor, plaintext in the high bits Also RtR_t, exact integer arithmetic Exact integer arithmetic; "scale-invariant" and simpler to implement (used by SEAL and Apple)
CKKS (2017) Δm+e\Delta m + e, but ee is treated as approximation error Complex (real) vectors, approximate arithmetic Floating-point computation, machine learning, statistics; after multiplication, rescale divides by Δ\Delta
TFHE / FHEW LWE samples, with bits or small integers as plaintext {0,1}\{0,1\} or Zt\mathbb{Z}_t (very small tt) Arbitrary Boolean circuits, comparisons, table lookups; every gate bootstraps, and bootstrapping is very fast

Hard lattice problems LWE / RLWE

Exact integer arithmetic

Approximate real arithmetic

Bit / small-integer arithmetic

BGV: plaintext in low bits
modulus switching

BFV: plaintext in high bits
scale-invariant

CKKS: error as lost precision
rescale

TFHE / FHEW:
fast bootstrap on every operation
programmable bootstrap = table lookup

The core idea of CKKS: floating-point arithmetic has rounding errors anyway, so treat encryption noise as part of the rounding error. The plaintext mm is "the true value times a scaling factor Δ\Delta, rounded", and decryption yields m+em + e. As long as ee is small relative to Δ\Delta, you only lose a few bits of precision. After multiplication the phase becomes Δ2mm′+⋯\Delta^2 m m' + \cdots, and rescale (dividing by Δ\Delta and lowering the modulus) restores the scale, which is the same operation as modulus switching.

Batching (SIMD) and the Chinese Remainder Theorem: for BGV/BFV, if the prime t≡1(mod2n)t \equiv 1 \pmod{2n}, then Zt\mathbb{Z}_t contains a primitive 2n2n-th root of unity ζ\zeta, so xn+1x^n + 1 splits into nn linear factors over Zt[x]\mathbb{Z}_t[x], and the Chinese Remainder Theorem gives

Rt=Zt[x]/(xn+1)  ≅  ∏i=1nZt[x]/(x−ζ2i−1)  ≅  Ztn.R_t = \mathbb{Z}_t[x]/(x^n + 1) \;\cong\; \prod_{i=1}^{n} \mathbb{Z}_t[x]/(x - \zeta^{2i-1}) \;\cong\; \mathbb{Z}_t^n.

This is a ring isomorphism, so one multiplication in RtR_t equals one multiplication in each of nn slots. One ciphertext handles nn numbers at once (1638416384 when n=214n = 2^{14}). CKKS uses a similar idea: the canonical embedding R→CnR \to \mathbb{C}^{n} packs n/2n/2 complex numbers into one polynomial.

3.8 Summary: homomorphic encryption through abstract algebra

Abstract algebra concept Role in homomorphic encryption
Group / ring homomorphisms The definition of homomorphism itself; RSA and ElGamal are multiplicative group homomorphisms, and Paillier is a group isomorphism
Quotient ring F[x]/(f)F[x]/(f) The ring Zq[x]/(xn+1)\mathbb{Z}_q[x]/(x^n + 1) where ciphertexts and plaintexts live
Evaluation homomorphism evs\mathrm{ev}_s The first step of decryption, c0+c1sc_0 + c_1 s, which also explains ciphertext multiplication
Irreducible polynomials xn+1=Φ2nx^n + 1 = \Phi_{2n} is irreducible, giving the ring a good structure
Chinese Remainder Theorem Batching Rt≅ZtnR_t \cong \mathbb{Z}_t^n; RNS representation and modulus switching
Ideals and kernels If Enc\mathrm{Enc} were an exact homomorphism, the structure of its kernel and image would leak information, so noise must be added

Further Reading