| 23 | } |
| 24 | |
| 25 | void first_phase(string filename, int n_mults, int circuit_sec) |
| 26 | { |
| 27 | // specify number of multiplications (at most one) and function privacy parameter |
| 28 | // increase the latter to accommodate more operations |
| 29 | FHE_Params params(n_mults, circuit_sec); |
| 30 | |
| 31 | // generate parameters for computation modulo a 32-bit prime |
| 32 | params.basic_generation_mod_prime(32); |
| 33 | |
| 34 | // find computation modulus (depends on parameter generation) |
| 35 | cout << "computation modulo " << params.get_plaintext_modulus() << endl; |
| 36 | |
| 37 | // generate key pair |
| 38 | FHE_KeyPair pair(params); |
| 39 | pair.generate(); |
| 40 | |
| 41 | Plaintext_mod_prime plaintext(params); |
| 42 | |
| 43 | // set first two plaintext slots |
| 44 | plaintext.set_element(0, 4); |
| 45 | plaintext.set_element(1, -1); |
| 46 | |
| 47 | // encrypt |
| 48 | Ciphertext ciphertext = pair.pk.encrypt(plaintext); |
| 49 | |
| 50 | // store for second phase |
| 51 | octetStream os; |
| 52 | params.pack(os); |
| 53 | pair.pk.pack(os); |
| 54 | ciphertext.pack(os); |
| 55 | plaintext.pack(os); |
| 56 | pair.sk.pack(os); |
| 57 | ofstream out(filename); |
| 58 | os.output(out); |
| 59 | } |
| 60 | |
| 61 | void second_phase(string filename) |
| 62 | { |
no test coverage detected