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
475 stars 78 forks source link

Invalid encryption parameters for certain primes in BFV #215

Closed meirgold closed 1 year ago

meirgold commented 1 year ago

Hi,

When trying to generate a BFV context with certain primes, I get an error saying: ValueError: encryption parameters are not valid for batching

The code I use is as following:

ctxt = Pyfhel()
ctxt.contextGen("bfv", n=2**15, t=383953334664724481, sec=128)

The number p=383953334664724481 is a prime number, it fulfills the requirement that p-1 is divisible by 2^15, but still is not accepted. A different prime of the same bitsize such as: 420125484881412097 does work, so I trust this is not a bitsize limitation. I also see this issue with lower polynomial modulus values and lower primes, however, I noticed that the more bits I use for the prime, the more common the issue is. Is there an additional constraint that I'm not aware of that causes this issue?

I'm running on: ubuntu 22.04 python version: 3.10.12 C compiler version: GCC 11.4.0 Pyfhel version: 3.4.1

Thanks,

Meir

AlexanderViand-Intel commented 1 year ago

Yes, there's one more condition which the first prime fails but the second one passes:

Note that when using batching (recall Section 7.4) t needs to be a prime such that t = 1 (mod 2n).

(From the old Seal Manual, Section 8.5)

meirgold commented 1 year ago

right... sorry, I must have mis-interpreted the requirement. Thanks for the clarification

AlexanderViand-Intel commented 1 year ago

Oh, I see now that you were already thinking of this constraint - note that it has to hold modulo 2n and not modulo n :)