| 59 | } |
| 60 | |
| 61 | void second_phase(string filename) |
| 62 | { |
| 63 | // read from file |
| 64 | ifstream in(filename); |
| 65 | octetStream os; |
| 66 | os.input(in); |
| 67 | FHE_Params params; |
| 68 | FHE_PK pk(params); |
| 69 | FHE_SK sk(params); |
| 70 | Plaintext_mod_prime plaintext(params); |
| 71 | Ciphertext ciphertext(params); |
| 72 | |
| 73 | // parameter must be set correctly first |
| 74 | params.unpack(os); |
| 75 | pk.unpack(os); |
| 76 | ciphertext.unpack(os); |
| 77 | plaintext.unpack(os); |
| 78 | |
| 79 | if (params.n_mults() == 0) |
| 80 | // public-private multiplication is always available |
| 81 | ciphertext *= plaintext; |
| 82 | else |
| 83 | // private-private multiplication only with matching parameters |
| 84 | ciphertext = ciphertext.mul(pk, ciphertext); |
| 85 | |
| 86 | // re-randomize for circuit privacy |
| 87 | ciphertext.rerandomize(pk); |
| 88 | |
| 89 | // read secret key and decrypt |
| 90 | sk.unpack(os); |
| 91 | plaintext = sk.decrypt(ciphertext); |
| 92 | |
| 93 | cout << "should be 16: " << plaintext.element(0) << endl; |
| 94 | cout << "should be 1: " << plaintext.element(1) << endl; |
| 95 | assert(plaintext.element(0) == 16); |
| 96 | assert(plaintext.element(1) == 1); |
| 97 | } |