Operations for rotations in ciphertext using SEAL

330 Views Asked by At

Just wanted to know if it is possible for us to perform some operations on rotated ciphertexts such that only part of the ciphertext takes part in the operation and not the whole object. Let's say we want only the slot_count/2 part of the ct to take part in the operation and the latter slot_count/2 should be left as it is. Any ideas how to go about it? I am currently using the BFV scheme

1

There are 1 best solutions below

0
On

Since we can't really choose which slots will be rotated, the general way to achieve this is more of a workaround:

Given seal::Ciphertext x, int steps and appropriate evaluator/encoder and keys as in the Seal Rotation Example (including Explanations) we can do the following:

  1. make a copy of x seal::Ciphertext copy = x;
  2. rotate the copy evaluator.rotate_vector_inplace(copy, steps, galoisKeys); (assuming you're using the CKKS scheme)
  3. multiply with a mask (plaintext with 0 or 1 in the slots)
std::vector<unsigned long int> mask = {1,1,1,1,1,0,0,0,0 /*...*/};
seal::Plaintext mask_ptxt;
encoder.encode(mask, mask_ptxt);
evaluator.multiply_plain_inplace(copy, mask_ptxt);
  1. multiply the original with the inverse mask
 std::vector<unsigned long int> inv_mask = {0,0,0,0,0,1,1,1,1 /*...*/};
 seal::Plaintext inv_mask_ptxt;
 encoder.encode(inv_mask , inv_mask_ptxt);
 evaluator.multiply_plain_inplace(x, mask_ptxt);
  1. add the original and rotated ciphertext together evaluator.add_inplace(x,copy);