Numerical Methods for Comparison on Homomorphically Encrypted Numbers

Jung Hee Cheon, Dongwoo Kim, Duhyeong Kim, Hun-Hee Lee, Keewoo LeeIACR ePrint 2019

TL;DR

This paper introduces a breakthrough numerical approach for performing comparison and min/max operations on word-wise Homomorphically Encrypted (HE) data. By replacing traditional high-degree polynomial approximations with efficient iterative algorithms, the authors achieve quasi-optimal computational complexity, enabling encrypted comparisons that are orders of magnitude faster than previous methods.

What Problem Does This Paper Address?

Homomorphic Encryption (HE) allows us to compute on data while it remains encrypted, a holy grail for privacy-preserving applications. However, HE schemes generally fall into two camps: bit-wise (which are great at logic and comparisons but painfully slow at arithmetic) and word-wise (which are fast at arithmetic but struggle with non-polynomial functions like "is $a > b$?").

Previously, word-wise schemes tried to handle comparisons using general polynomial approximations (like Taylor series or minimax polynomials). The problem is that to get high precision, these polynomials require a massive degree, leading to exponential computational costs. This paper tackles the "comparison bottleneck" in word-wise HE, making it practical to find the maximum value or count items above a threshold without decrypting them.

Methods

The authors move away from "one-shot" high-degree polynomials and instead embrace iterative numerical methods. Their core idea is that a complex function can be approximated by composing a simple, low-degree polynomial with itself multiple times ($g \circ g \circ \dots \circ g$).

Key components include:

  • Iterative Inverse and Square Root: They adapt Goldschmidt’s division algorithm for calculating $1/x$ and Wilkes’ algorithm for $\sqrt{x}$. These converge exponentially, meaning you get more bits of precision with each iteration.
  • The Min/Max Identity: They use the mathematical identity $\max(a, b) = \frac{a+b}{2} + \frac{|a-b|}{2}$. Since $|x| = \sqrt{x^2}$, they can use their iterative square root algorithm to find the maximum.
  • The Comparison Identity: To compare $a$ and $b$, they approximate a step function using a scaled sigmoid-like structure: $\frac{a^k}{a^k + b^k}$. As $k$ grows, this value approaches 1 if $a > b$ and 0 if $a < b$.
  • HEAAN Integration: The algorithms are designed for the HEAAN scheme, which naturally supports the "rounding-off" operations needed to keep intermediate values manageable during iterations.

Datasets

The paper evaluates its algorithms using synthetic datasets designed to test precision and speed:

  • Pairs of 32-bit integers: Used to benchmark the basic Max and Comp (comparison) algorithms.
  • Arrays of 7-bit and 8-bit integers: Used for higher-level applications like finding the index of the maximum element (MaxIdx) and "Threshold Counting" (counting how many numbers in a set exceed a specific value).
  • The experiments were conducted using the HEAAN library on a standard Linux server (Intel Xeon CPU).

Key Insights and Ideas

  • Composition vs. Degree: The "aha moment" is realizing that computational complexity in HE is better optimized by the structure of the polynomial rather than just its degree. An iterative algorithm with $d$ steps has a complexity of $\Theta(d)$, even though it represents a polynomial of degree $2^d$.
  • Numerical Stability: By scaling inputs to specific ranges (like $[0, 1]$ or $[1/2, 3/2]$), they ensure the iterative methods converge reliably.
  • Amortization is King: Because word-wise HE (specifically HEAAN) uses SIMD (Single Instruction, Multiple Data) packing, they can perform thousands of comparisons simultaneously. While a single comparison might take seconds of total CPU time, the amortized time per comparison drops to mere milliseconds.

Key Results

The performance gains are significant compared to traditional minimax polynomial approximations:

  • Complexity: Their min/max algorithm achieves $\Theta(\alpha)$ complexity for an error rate of $2^{-\alpha}$, whereas previous methods required $\Theta(2^{\alpha/2})$.
  • Speed: Finding the maximum of two 32-bit integers takes just 1.14 milliseconds (amortized).
  • Comparison: Comparing two 32-bit integers takes 3.5 milliseconds (amortized).
  • Scalability: They can find the index of the maximum among 16 encrypted integers in about 75.9 ms (amortized).
  • Real-world Impact: The authors note that their method enabled a privacy-preserving clustering analysis [15] to run 400 times faster than the previous state-of-the-art bit-wise implementation.

Limitations and Future Work

  • Approximation, Not Exact: These are numerical approximations. If two numbers are extremely close together, the algorithm requires more iterations (higher $k$) to distinguish them, or it might return a value near 0.5 for a comparison.
  • Parameter Tuning: The depth of the HE circuit increases with the number of iterations. Users must carefully balance the desired precision ($\alpha$) with the available multiplicative depth of their HE parameters.
  • Equality Testing: While the paper focuses on min/max and comparison ($>$), it doesn't deeply explore strict equality ($=$), which is a distinct challenge in approximate HE.

The authors suggest that these iterative building blocks could be further optimized for specific machine learning tasks, such as ReLU activation functions in encrypted neural networks.

Summary updated

BibTeX
@article{cheon2019numerical,
  author = {Jung Hee Cheon and Dongwoo Kim and Duhyeong Kim and Hun-Hee Lee and Keewoo Lee},
  title = {{Numerical Methods for Comparison on Homomorphically Encrypted Numbers}},
  journal = {IACR Cryptol. ePrint Arch.},
  year = {2019},
}
Figure