ibarrond / Pyfhel

PYthon For Homomorphic Encryption Libraries, perform encrypted computations such as sum, mult, scalar product or matrix multiplication in Python, with NumPy compatibility. Uses SEAL/PALISADE as backends, implemented using Cython.
https://pyfhel.readthedocs.io/
Apache License 2.0
487 stars 78 forks source link

How to Compare two ciphertexts? #80

Closed vrush0022 closed 3 years ago

vrush0022 commented 3 years ago

Is there any way I can compare two cyphertext? I would like to perform c2a<c2b.

ibarrond commented 3 years ago

Unfortunately, Homomorphic Encryption (HE) does not support comparison between ciphertexts.

You can easily translate a comparison ca > cb into the extraction of the sign bit (MSB) of ca-cb. However, individual bit extraction/manipulation cannot be done with HE.

This problem is treated extensively in the literature, since this functionality is required for non-linear activation functions in Neural Networks, and other comparisons in Machine Learning. The two standard approaches to implement it are:

  1. Use linear activation functions instead (square, polynomial approximations of RELU).
  2. Switch to Garbled Circuits for this computation (e.g.: Gazelle).
  3. Rely on Secret Sharing for this computation (e.g.: SecureNN).

In short, you cannot compare two ciphertexts with Pyfhel.