Fully Homomorphic Encryption

A Deep Dive into BGV, BFV, and CKKS: Modern Fully Homomorphic Encryption Schemes

Chuck Chen
 · 

Fully Homomorphic Encryption (FHE) represents one of the most significant achievements in modern cryptography, enabling computation on encrypted data without decryption. This post provides a comprehensive technical analysis of three dominant FHE schemes: BGV (Brakerski-Gentry-Vaikuntanathan), BFV (Brakerski-Fan-Vercauteren), and CKKS (Cheon-Kim-Kim-Song). We’ll explore their mathematical foundations using consistent notation and compare their approaches to critical challenges in homomorphic computation.

Mathematical Notations and Concepts

We use the following consistent notation to describe the BGV, BFV, and CKKS schemes.

Core Mathematical Structures

SymbolDefinition
Z,R,C\mathbb{Z}, \mathbb{R}, \mathbb{C}Integers, Real numbers, and Complex numbers
Zq\mathbb{Z}_qIntegers modulo qq, i.e., {0,…,qβˆ’1}\{0, \dots, q-1\}
RqR_qPolynomial ring Zq[X]/(XN+1)\mathbb{Z}_q[X]/(X^N + 1) (degree <N<N, coeff. mod qq)
NNPolynomial degree (power of 2, e.g., 2112^{11} to 2152^{15})
←\leftarrowSampling from a distribution (e.g., e←χe \leftarrow \chi)
βŒŠβ‹…βŒ‰,βŒŠβ‹…βŒ‹\lfloor \cdot \rceil, \lfloor \cdot \rfloorRounding to nearest integer, Floor function
βˆ₯βˆ₯β‹…βˆ₯βˆ₯∞\|\|\cdot\|\|_\inftyInfinity norm (maximum absolute value of coefficients)

Cryptographic Variables & Operations

SymbolMeaningNotes
ssSecret keyPolynomial in RR (often small/binary)
pk,evkpk, evkPublic key, Evaluation keypk=(pk0,pk1)pk=(pk_0, pk_1), evkevk used for relinearization
ctctCiphertextPair of polynomials (c0,c1)∈Rq2(c_0, c_1) \in R_q^2
mmPlaintext messageEncoded data as a polynomial
e,Ο‡e, \chiError, Error dist.Small noise drawn from Discrete Gaussian Ο‡\chi
uuEphemeral keySmall random polynomial used in encryption
[β‹…]q[\cdot]_qModulo reductionCoefficient-wise reduction into [0,qβˆ’1][0, q-1]

Scheme Parameters

SymbolDescriptionContext
q,tq, tCiphertext / Plaintext modulusqq is large, tt is small (BGV/BFV)
Ξ”\DeltaScaling factor⌊q/tβŒ‹\lfloor q/t \rfloor (BFV) or precision scale (CKKS)
LLMultiplicative depthNumber of levels allowed in the circuit
w,Pw, PRelinearization basesBase ww or large factor PP for key switching
zβƒ—\vec{z}Complex vectorInput data vector for CKKS ∈CN/2\in \mathbb{C}^{N/2}
Οƒ,Ξ»\sigma, \lambdaNoise std. dev, Security paramtypically Ξ»=128\lambda=128 bits

The Foundation: Ring Learning With Errors (RLWE)

All three schemes build upon the Ring Learning With Errors (RLWE) problem, which provides their cryptographic security. Let’s establish our common notation:

  • R=Z[X]/(XN+1)R = \mathbb{Z}[X]/(X^N + 1) where NN is a power of 2 (typically 2048, 4096, or 8192)
  • Rq=R/qR=Zq[X]/(XN+1)R_q = R/qR = \mathbb{Z}_q[X]/(X^N + 1) for modulus qq
  • Rt=R/tR=Zt[X]/(XN+1)R_t = R/tR = \mathbb{Z}_t[X]/(X^N + 1) for plaintext modulus tt
  • Ο‡\chi denotes the error distribution (typically discrete Gaussian)

The RLWE problem asks: given many pairs (ai,bi=aiβ‹…s+ei)∈Rq2(a_i, b_i = a_i \cdot s + e_i) \in R_q^2 where s∈Rqs \in R_q is secret and ei←χe_i \leftarrow \chi, it is computationally hard to recover ss.

Common Framework

Despite their differences, BGV, BFV, and CKKS share a common structure. Let’s define the core operations using unified notation:

Key Generation

All three schemes generate keys similarly:

Secret Key Generation: s←χ orΒ s←R2Β (binaryΒ secret)s \leftarrow \chi \text{ or } s \leftarrow R_2 \text{ (binary secret)}

Public Key Generation: pk=(pk0,pk1)=([βˆ’aβ‹…s+e]q,a)pk = (pk_0, pk_1) = ([-a \cdot s + e]_q, a) where a←Rqa \leftarrow R_q uniformly random and e←χe \leftarrow \chi.

Evaluation Key Generation (for relinearization): evk=(evk0,evk1)=([βˆ’aβ‹…s+e+Pβ‹…s2]Pβ‹…q,a)evk = (evk_0, evk_1) = ([-a \cdot s + e + P \cdot s^2]_{P \cdot q}, a) where PP is a large integer used for key switching.

Basic Ciphertext Structure

A fresh ciphertext encrypting message mm has the form: ct=(c0,c1)∈Rq2ct = (c_0, c_1) \in R_q^2

The invariant maintained is: c0+c1β‹…s=m+e(modq)c_0 + c_1 \cdot s = m + e \pmod{q} where ee is small noise.

Message Encoding and SIMD Batching

A crucial aspect of modern FHE implementation is SIMD (Single Instruction, Multiple Data) packing. Instead of encrypting a single number into a massive polynomial (which is inefficient), we β€œpack” a vector of messages into a single polynomial.

BGV and BFV: Integer Batching (CRT Packing)

For BGV and BFV, the plaintext space is the ring Rt=Zt[X]/(XN+1)R_t = \mathbb{Z}_t[X]/(X^N + 1). If we choose the plaintext modulus tt to be a prime such that t≑1(mod2N)t \equiv 1 \pmod{2N}, the polynomial XN+1X^N + 1 factors completely into linear terms (Xβˆ’ΞΆi)(X - \zeta_i) in Zt\mathbb{Z}_t.

By the Chinese Remainder Theorem (CRT), there is an isomorphism: Rt≅Zt×Zt×...×Zt(N slots)R_t \cong \mathbb{Z}_t \times \mathbb{Z}_t \times ... \times \mathbb{Z}_t \quad (N \text{ slots})

Encoding: Given a vector of integers mβƒ—=(m0,m1,...,mNβˆ’1)∈ZtN\vec{m} = (m_0, m_1, ..., m_{N-1}) \in \mathbb{Z}_t^N, we construct a unique polynomial m(X)∈Rtm(X) \in R_t such that: m(ΞΆi)=mi(modt)m(\zeta_i) = m_i \pmod t This is efficiently computed using a Number Theoretic Transform (NTT).

Decoding: Evaluate the decrypted polynomial m(X)m(X) at the roots ΢i\zeta_i to recover the vector m⃗\vec{m}.

Homomorphic SIMD: Addition/Multiplication of polynomials mA(X)β‹…mB(X)m_A(X) \cdot m_B(X) corresponds to component-wise operations on the vectors: mβƒ—AβŠ™mβƒ—B\vec{m}_A \odot \vec{m}_B.

CKKS: Complex Batching (Canonical Embedding)

CKKS works with vectors of complex numbers CN/2\mathbb{C}^{N/2}. It utilizes the Canonical Embedding σ:R→CN\sigma: R \rightarrow \mathbb{C}^N.

Encoding: Given a vector zβƒ—βˆˆCN/2\vec{z} \in \mathbb{C}^{N/2}:

  1. Expand to a conjugate-symmetric vector in CN\mathbb{C}^N.
  2. Apply the inverse Canonical Embedding (essentially an inverse FFT) to map the vector to a polynomial with real coefficients.
  3. Scale the coefficients by Ξ”\Delta and round to the nearest integers to get m(X)∈Rm(X) \in R.

Decoding:

  1. Scale down the coefficients of the decrypted polynomial by Ξ”\Delta.
  2. Apply the Canonical Embedding (FFT) to recover the vector of values.

This mapping allows performing approximate arithmetic on N/2N/2 complex slots simultaneously.

BGV: Encoding in Least Significant Bits

The BGV scheme encodes messages in the least significant bits of ciphertext coefficients, employing modulus switching to manage noise growth.

BGV Encryption

Given plaintext m∈Rtm \in R_t:

  1. Sample u←R2u \leftarrow R_2 (small polynomial)
  2. Sample e0,e1←χe_0, e_1 \leftarrow \chi
  3. Compute: c0=pk0β‹…u+e0+mc_0 = pk_0 \cdot u + e_0 + m c1=pk1β‹…u+e1c_1 = pk_1 \cdot u + e_1
  4. Return ct=(c0,c1)∈Rq2ct = (c_0, c_1) \in R_q^2

BGV Decryption

mβ€²=[c0+c1β‹…s]qβ€Šmodβ€Štm' = [c_0 + c_1 \cdot s]_q \bmod t

The decryption is correct if the noise ∣∣c0+c1β‹…sβˆ’m∣∣∞<q/(2t)||c_0 + c_1 \cdot s - m||_\infty < q/(2t).

BGV Homomorphic Operations

Addition: ctadd=ct1+ct2=(c0(1)+c0(2),c1(1)+c1(2))ct_{add} = ct_1 + ct_2 = (c_0^{(1)} + c_0^{(2)}, c_1^{(1)} + c_1^{(2)})

Multiplication:

  1. Compute tensor product: ctmultβ€²=(d0,d1,d2)ct_{mult}' = (d_0, d_1, d_2) where:

    • d0=c0(1)β‹…c0(2)d_0 = c_0^{(1)} \cdot c_0^{(2)}
    • d1=c0(1)β‹…c1(2)+c1(1)β‹…c0(2)d_1 = c_0^{(1)} \cdot c_1^{(2)} + c_1^{(1)} \cdot c_0^{(2)}
    • d2=c1(1)β‹…c1(2)d_2 = c_1^{(1)} \cdot c_1^{(2)}
  2. Relinearization reduces back to degree 2 (covered below)

BGV Modulus Switching

After operations, reduce modulus from qq to qβ€²=q/pq' = q/p: ciβ€²=⌊qβ€²qβ‹…ciβŒ‰c_i' = \lfloor \frac{q'}{q} \cdot c_i \rceil

This scales down both the ciphertext and noise proportionally.

BFV: Encoding in Most Significant Bits

BFV encodes messages in the most significant bits, using a different multiplication strategy.

BFV Encryption

Given plaintext m∈Rtm \in R_t:

  1. Sample u←R3u \leftarrow R_3 (ternary polynomial)
  2. Sample e0,e1←χe_0, e_1 \leftarrow \chi
  3. Compute: c0=pk0β‹…u+e0+Ξ”β‹…mc_0 = pk_0 \cdot u + e_0 + \Delta \cdot m c1=pk1β‹…u+e1c_1 = pk_1 \cdot u + e_1 where Ξ”=⌊q/tβŒ‹\Delta = \lfloor q/t \rfloor
  4. Return ct=(c0,c1)∈Rq2ct = (c_0, c_1) \in R_q^2

BFV Decryption

mβ€²=⌊tqβ‹…[c0+c1β‹…s]qβŒ‰β€Šmodβ€Štm' = \lfloor \frac{t}{q} \cdot [c_0 + c_1 \cdot s]_q \rceil \bmod t

BFV Homomorphic Operations

Addition: Same as BGV

Multiplication:

  1. Compute intermediate values in Z[X]/(XN+1)\mathbb{Z}[X]/(X^N + 1) (without mod qq): c~0=c0(1)β‹…c0(2)\tilde{c}_0 = c_0^{(1)} \cdot c_0^{(2)} c~1=c0(1)β‹…c1(2)+c1(1)β‹…c0(2)\tilde{c}_1 = c_0^{(1)} \cdot c_1^{(2)} + c_1^{(1)} \cdot c_0^{(2)} c~2=c1(1)β‹…c1(2)\tilde{c}_2 = c_1^{(1)} \cdot c_1^{(2)}

  2. Scale and round: ci=⌊tqβ‹…c~iβŒ‰β€Šmodβ€Šqc_i = \lfloor \frac{t}{q} \cdot \tilde{c}_i \rceil \bmod q

  3. Apply relinearization to reduce from 3 to 2 components

CKKS: Approximate Arithmetic for Real Numbers

CKKS fundamentally differs by supporting approximate arithmetic on complex/real numbers.

CKKS Encoding

CKKS uses a special encoding that maps vectors of complex numbers to polynomials:

Encode:CN/2β†’R\text{Encode}: \mathbb{C}^{N/2} \rightarrow R zβƒ—=(z0,z1,...,zN/2βˆ’1)↦m(X)\vec{z} = (z_0, z_1, ..., z_{N/2-1}) \mapsto m(X)

This uses the canonical embedding via primitive NN-th roots of unity.

CKKS Encryption

Given encoded message m∈Rm \in R at scale Ξ”\Delta:

  1. Sample u←R3u \leftarrow R_3
  2. Sample e0,e1←χe_0, e_1 \leftarrow \chi
  3. Compute: c0=pk0β‹…u+e0+mc_0 = pk_0 \cdot u + e_0 + m c1=pk1β‹…u+e1c_1 = pk_1 \cdot u + e_1
  4. Return ct=(c0,c1)∈RqL2ct = (c_0, c_1) \in R_{q_L}^2 at level LL

CKKS Decryption and Decoding

  1. Decrypt: mβ€²=c0+c1β‹…sβ€Šmodβ€ŠqLm' = c_0 + c_1 \cdot s \bmod q_L
  2. Decode: z⃗′=Decode(m′/Δ)\vec{z}' = \text{Decode}(m'/\Delta)

The result z⃗′\vec{z}' approximates the original vector within some error bound.

CKKS Homomorphic Operations

Addition: Standard component-wise addition (same scale required)

Multiplication:

  1. Multiply as in BGV/BFV to get (d0,d1,d2)(d_0, d_1, d_2)
  2. Relinearize to (c0β€²,c1β€²)(c_0', c_1')
  3. Rescale (unique to CKKS): ciβ€²β€²=⌊ciβ€²/pβŒ‰c_i'' = \lfloor c_i'/p \rceil where pp is a prime in the modulus chain

The rescaling step is crucial: it reduces both the scale (from Ξ”2\Delta^2 to Ξ”\Delta) and the modulus (from qLq_L to qLβˆ’1=qL/pq_{L-1} = q_L/p).

Relinearization: Converting Degree-3 to Degree-2 Ciphertexts

After multiplication, all schemes produce degree-3 ciphertexts that must be reduced:

Key Switching Technique

Given (d0,d1,d2)(d_0, d_1, d_2) where the invariant is d0+d1β‹…s+d2β‹…s2=mβ‹…mβ€²+ed_0 + d_1 \cdot s + d_2 \cdot s^2 = m \cdot m' + e:

  1. Decompose d2d_2 into base-ww digits: d2=βˆ‘i=0kβˆ’1d2,iβ‹…wid_2 = \sum_{i=0}^{k-1} d_{2,i} \cdot w^i

  2. Use evaluation key components: c0β€²=d0+βˆ‘i=0kβˆ’1d2,iβ‹…evk0,ic_0' = d_0 + \sum_{i=0}^{k-1} d_{2,i} \cdot evk_{0,i} c1β€²=d1+βˆ‘i=0kβˆ’1d2,iβ‹…evk1,ic_1' = d_1 + \sum_{i=0}^{k-1} d_{2,i} \cdot evk_{1,i}

The result (c0β€²,c1β€²)(c_0', c_1') maintains the same message but with slightly increased noise.

Noise Management Strategies

The three schemes employ distinct approaches to noise management:

BGV: Modulus Switching

  • Actively reduces noise after each level
  • Maintains constant noise magnitude
  • Requires careful parameter ladder: qL>qLβˆ’1>...>q0q_L > q_{L-1} > ... > q_0

BFV: Scale-Invariant Approach

  • Keeps modulus qq fixed throughout computation
  • Noise grows but remains manageable through careful analysis
  • Simpler parameter selection than BGV

CKKS: Rescaling

  • Naturally reduces noise through rescaling after multiplication
  • Trades precision for noise reduction
  • Allows deeper circuits than exact schemes for approximate computation

Parameter Selection

Key parameters affect security, correctness, and performance:

Common Parameters

  • Polynomial degree NN: Higher values increase security and capacity but slow operations
  • Modulus bit-length: Balances security and noise budget
  • Standard deviation Οƒ\sigma of error distribution: Affects security and correctness

Scheme-Specific Considerations

BGV:

  • Modulus chain: qL=∏i=0Lpiq_L = \prod_{i=0}^L p_i where each piβ‰ˆ240βˆ’60p_i \approx 2^{40-60}
  • Typically requires L=L = depth of circuit

BFV:

  • Single large modulus: qβ‰ˆ2109βˆ’880q \approx 2^{109-880} depending on NN and depth
  • Plaintext modulus tt often prime for better noise tolerance

CKKS:

  • Scale Ξ”β‰ˆ240\Delta \approx 2^{40} for good precision
  • Special primes for rescaling in modulus chain
  • Can handle deeper circuits due to approximate nature

Practical Performance Comparison

Computational Efficiency

  • Addition: All schemes have similar performance (O(N)O(N) operations)
  • Multiplication: BFV slightly slower due to scaling step; CKKS benefits from rescaling
  • Bootstrapping: BGV/BFV require complex exact bootstrapping; CKKS has simpler approximate bootstrapping

Use Case Suitability

BGV: Best for:

  • Integer arithmetic with known depth
  • Applications requiring exact computation
  • Scenarios where modulus switching overhead is acceptable

BFV: Best for:

  • Integer arithmetic with simpler parameter selection
  • Batched operations on binary or small integer data
  • Applications where fixed modulus simplifies implementation

CKKS: Best for:

  • Machine learning and statistical computations
  • Signal processing and scientific computing
  • Deep circuits where approximation is acceptable

Security Considerations

All three schemes base security on RLWE hardness, but parameters must be chosen carefully:

SecurityΒ levelβ‰ˆNβ‹…log⁑qΟƒ2\text{Security level} \approx \frac{N \cdot \log q}{\sigma^2}

Current recommendations (128-bit security):

  • N=214,log⁑qβ‰ˆ438N = 2^{14}, \log q \approx 438 bits
  • N=213,log⁑qβ‰ˆ218N = 2^{13}, \log q \approx 218 bits
  • N=212,log⁑qβ‰ˆ109N = 2^{12}, \log q \approx 109 bits

Implementation Considerations

Library Support

Popular libraries implement these schemes with optimizations:

  • SEAL (Microsoft): BFV and CKKS
  • HElib (IBM): BGV and CKKS
  • PALISADE/OpenFHE: All three schemes
  • TenSEAL: Python wrapper focusing on CKKS for ML

Optimization Techniques

  1. NTT/FFT acceleration: Polynomial multiplication in O(Nlog⁑N)O(N \log N)
  2. RNS representation: For large moduli in BGV/BFV
  3. Batching: SIMD operations on packed plaintexts
  4. Key compression: Reduce evaluation key size

Future Directions

Recent research (2024-2025) focuses on:

  • Bootstrapping improvements: Faster refresh procedures
  • Compiler tools: Automatic parameter selection and circuit optimization
  • Hardware acceleration: FPGA/ASIC implementations
  • Standardization: Homomorphic Encryption Standard ongoing work

Conclusion

BGV, BFV, and CKKS each offer unique advantages for different homomorphic encryption applications. BGV provides fine-grained noise control through modulus switching, BFV simplifies implementation with fixed modulus, and CKKS enables efficient approximate arithmetic for real-world numerical computations. Understanding their mathematical foundations and trade-offs is crucial for selecting the appropriate scheme for specific applications.

The consistent mathematical framework presented here demonstrates that despite surface-level differences, these schemes share fundamental principles rooted in RLWE hardness. As FHE continues to mature, we can expect further optimizations and potentially new schemes that combine the best features of existing approaches.

References and Further Reading

For those interested in diving deeper into the mathematical foundations and recent developments: