homenc / HElib

HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
https://homenc.github.io/HElib
Other
3.13k stars 765 forks source link

Modify plaintext length #152

Closed JoFLV closed 7 years ago

JoFLV commented 7 years ago

Hi all,

i am playing around with the HElib project. I wanted to know if it is easily possible to generate random plaintextarrays with different array lengths. My goal is to check if there are runtime differences in using different plaintext lengths. Even after looking deeper in the code i could not find a suitable solution.

Thanks in advance JoFLV

shaih commented 7 years ago

A single ciphertext has a set number of "slots", depending on the specific parameters (specifically the m and p parameters). So in this sense, once you fixed these parameters you cannot modify the array size.

You can always concatenate two cipehrtexts to get an array of twice the size, you will have to write the logic yourself to treat these two ciphertexts as a single array (i.e., apply the same operations to these ciphertexts, decrypt them together, etc.)

JoFLV commented 7 years ago

Thanks for your fast reply. Is there a formula to calculate m for a given fixed p and a given fixed plaintextarraylength ?

Thanks and Regards

shaih commented 7 years ago

Unfortunately, no such formula. Given m and p it is easy to compute the number of slots, but essentially the only way to find good m is to try many of them until you find one that's appropriate. Choosing parameters for FHE is currently somewhat of a black art, this area can certainly use more research.

JoFLV commented 7 years ago

Choosing parameters seems to be still complex. I agree this area can use more research.

You mentioned it is easy to compute the number of slots for given m and p - how does it work ? Is there a code snippet in the project ?

Thanks for your support

shaih commented 7 years ago

You mentioned it is easy to compute the number of slots for given m and p - how does it work?

You need to find the order of p in the multiplicative group $Z_m^*$ (namely the smallest integer e such that p^e=1 mod m). Once you found that number e, the number of slots is phi(m)/e. One (very wasteful) way of doing it with HElib is

  PAlgebra pa(m,p);
  cout << pa.getNSlots();
JoFLV commented 7 years ago

Thanks for your help