microsoft / SEAL-Embedded

A Microsoft-SEAL-compatible implementation of homomorphic encryption targeting Azure Sphere and other embedded devices.
MIT License
48 stars 15 forks source link

Problem with rotation when i load a key #7

Closed Geordat closed 2 years ago

Geordat commented 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 Screenshot from 2022-04-25 10-35-53

Geordat commented 2 years ago

I solved it by storing the gal keys