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.11k stars 760 forks source link

Ciphertext Rotation with slots that greater than expected size #438

Closed DylanWangWQF closed 3 years ago

DylanWangWQF commented 3 years ago

I want to do some rotations, expect the ciphertext to be (m(v_1, v_2, ..., v_slots)) and the right-rotated (2) ciphertext should be (m({v_slots - 1}, v_slots, v_1, v_2, ..., v_{slots-2}). But in fact the number of slots in the ciphertext usually greater than v_slots. For example, we got the ciphertext with 2048 slots, but I want to rotate the encrypted vector with 2000 values. Extra 48 slots with value0 are not what I want.

DylanWangWQF commented 3 years ago

In the project snucrypto/HEAAN, it seems that we can determine the number of slots in the ciphertext. For example, ctxt = encrypt(vector, nslots, logp, logQ); In general, I want to choose the exact number of slots in the ciphertext, so that I can do a set of rotations and matrix multiplications. Does it support this function now? Thanks in advance!

DylanWangWQF commented 3 years ago

BTW, If I want to set 4096 slots in the ciphertext, how to get the related parameters? I tried many times, got 4732, 4100, etc..

long m = FindM(/*k=*/80, /*nBits=*/500, /*c=*/2, /*p=*/9467, /*d=*/1, /*s=*/4096, /*chosen_m=*/0, /*verbose=*/true);
Params param(/*m=*/9466, /*p=*/9467, /*r=*/1, /*bits=*/500, /*c=*/2);

Print Context:

m = 9466, p = 9467, phi(m) = 4732
  ord(p) = 1
  normBnd = 1.27324
  polyNormBnd = 1.27324
  factors = [2 4733]
  generator 5 has order (== Z_m^*) of 4732
r = 1
nslots = 4732
hwt = 0
ctxtPrimes = [6,7,8]
specialPrimes = [9,10]
number of bits = 256

security level = 52.7597

Hi, @shaih Could you give me some suggestions?