data61 / python-paillier

A library for Partially Homomorphic Encryption in Python
Other
605 stars 134 forks source link

a = 5, b=5, why enc(a) == enc(b) returns false? #96

Closed yoopaan closed 2 years ago

yoopaan commented 3 years ago
from phe import paillier
a = 5
b = 5

encA =  public_key.encrypt(5)
encB =  public_key.encrypt(5)

print(encA==encB) #False

If A and B are equal, are their corresponding ciphertexts equal?

manglemix commented 3 years ago

no, as a random obfuscator is included in the encryption such that encryptions of the same plaintext are different numbers. This is to prevent an attacker from learning the plaintext based on patterns of similarities

yoopaan commented 2 years ago

Does paillier support homomorphic equality function? In other words, how to judge that two ciphertexts are equal?

manglemix commented 2 years ago

There are non interactive zero knowledge proofs that the encryptor can generate to prove that two ciphertext are equal. But this is not currently supported in this package. You have to find a paper that describes one of these methods and implement this yourself