I get an error when I rotate the ciphertext vector,

143 Views Asked by At

I want to rotate the product vector of two ciphertext vectors, but I get an error and I don't know how I should try to solve it. It is correct when I rotate a ciphertext vector, but when this ciphertext vector is a product, an error occurs.

int main() {
    EncryptionParameters parms(scheme_type::BFV);

    parms.set_poly_modulus_degree(poly_modulus_degree);
    parms.set_coeff_modulus(CoeffModulus::BFVDefault(poly_modulus_degree));
    parms.set_plain_modulus(PlainModulus::Batching(poly_modulus_degree, 20));
    auto context = SEALContext::Create(parms);
    KeyGenerator keygen(context);
    PublicKey psk=keygen.public_key();
    SecretKey sk=keygen.secret_key();
    RelinKeys rlk=keygen.relin_keys();
  GaloisKeys glk=keygen.galois_keys();
  Encryptor encryptor(context, psk);
  Decryptor decryptor(context, sk);
  Evaluator evaluator(context);
  BatchEncoder batch_encoder(context);

  size_t slot_count = batch_encoder.slot_count();
  size_t row_size = slot_count / 2;

  mt19937 rnd(time(NULL));
  vector<uint64_t> v(slot_count,0ull);
  for(int i=0;i<1000;i++){
      v[i]=rnd()%1000;
  }
  print_matrix(v,row_size);
  Plaintext pr;
  Ciphertext cr;
  batch_encoder.encode(v,pr);
  encryptor.encrypt(pr,cr);
  evaluator.multiply_inplace(cr,cr);
  decryptor.decrypt(cr,pr);
  batch_encoder.decode(pr,v);
  print_matrix(v,row_size);
  //error::  what():  encrypted size must be 2
  evaluator.rotate_rows(cr,pow(2,0),glk,cr);
  return 0;

}

1

There are 1 best solutions below

0
On

It is complaining that the size of the ciphertext is larger than 2. You need to perform a relinearization on the cipher cr right after the evaluator.multiply_inplace(cr,cr); which will lower the size back down to 2:

...
evaluator.multiply_inplace(cr,cr);
evaluator.relinearize_inplace(cr, rlk);
...

You can read more information from Microsoft SEAL's code relinkeys.h.