Closed Geordat closed 2 years ago
In the following code ,when I load a secret key and i encrypt then and i decrypt a ciphertext everything works fine. But when i try to rotate the ciphertext it outputs wrong values .Do i have to also save the gal keys .How can I fix this ;
int main(int argc, char *argv[]) { size_t degree = 8192; double scale = pow(2, 25);
EncryptionParameters parms(scheme_type::ckks); seal::SEALContext context = setup_seale_prime_default(degree, parms); KeyGenerator keygen(context); Evaluator evaluator(context); CKKSEncoder encoder(context);
SecretKey sk = keygen.secret_key(); RelinKeys relin_keys; keygen.create_relin_keys(relin_keys); GaloisKeys gal_keys; keygen.create_galois_keys(gal_keys); //sk_seal_save("key",sk,false); sk_seal_load("key",context,sk); Decryptor decryptor(context, sk);
Ciphertext ct; PublicKey pk; Plaintext pt; vector res;
vector test = {1.0, 2.0, 3.0}; encoder.encode(test, scale, pt); Encryptor encryptor(context, sk); encryptor.encrypt_symmetric(pt, ct);
//evaluator.rotate_vector(ct,-1, gal_keys, ct); decryptor.decrypt(ct,pt); encoder.decode(pt,res); for(int i = 0; i < 10; i++) cout << res[i] << " ";
cout<<endl; return 0; } In the following image the first example is with rotation and the second one is without
I solved it by storing the gal keys
In the following code ,when I load a secret key and i encrypt then and i decrypt a ciphertext everything works fine. But when i try to rotate the ciphertext it outputs wrong values .Do i have to also save the gal keys .How can I fix this ;
int main(int argc, char *argv[]) { size_t degree = 8192; double scale = pow(2, 25);
EncryptionParameters parms(scheme_type::ckks); seal::SEALContext context = setup_seale_prime_default(degree, parms); KeyGenerator keygen(context); Evaluator evaluator(context); CKKSEncoder encoder(context);
SecretKey sk = keygen.secret_key(); RelinKeys relin_keys; keygen.create_relin_keys(relin_keys); GaloisKeys gal_keys; keygen.create_galois_keys(gal_keys); //sk_seal_save("key",sk,false); sk_seal_load("key",context,sk); Decryptor decryptor(context, sk);
Ciphertext ct; PublicKey pk; Plaintext pt; vector res;
vector test = {1.0, 2.0, 3.0};
encoder.encode(test, scale, pt);
Encryptor encryptor(context, sk);
encryptor.encrypt_symmetric(pt, ct);
//evaluator.rotate_vector(ct,-1, gal_keys, ct); decryptor.decrypt(ct,pt); encoder.decode(pt,res); for(int i = 0; i < 10; i++) cout << res[i] << " ";
cout<<endl; return 0; } In the following image the first example is with rotation and the second one is without