* Simulate an execution of KeyGen to check that these nplayers seeds * produce the correct public key. */
| 205 | * produce the correct public key. |
| 206 | */ |
| 207 | void check_randomness(vector<octetStream>& seeds, |
| 208 | const Ciphertext& actual_sw,const FHE_PK& pk, |
| 209 | const Ciphertext& enc_dash, |
| 210 | int num_players) |
| 211 | { |
| 212 | const FHE_Params& params=actual_sw.get_params(); |
| 213 | |
| 214 | vector<DistKeyGen> playerKeys(num_players, {params, pk.p()}); |
| 215 | DistKeyGen globalKey(params, pk.p()); |
| 216 | |
| 217 | Rq_Element b(Rq_Element(params.FFTD(), evaluation, evaluation)); |
| 218 | Rq_Element zero(Rq_Element(params.FFTD(), polynomial,polynomial)); |
| 219 | zero.assign_zero(); |
| 220 | |
| 221 | Ciphertext ed(params), ed_sum(params), ezero(params), ezero_sum(params); |
| 222 | PRNG G; |
| 223 | |
| 224 | // Re-create the randomness from these seeds |
| 225 | for (int i = 0; i < num_players; i++) |
| 226 | { G.SetSeed(seeds[i].get_data()); |
| 227 | #ifdef VERBOSE_KEYGEN |
| 228 | cout << "\tSeed for player " << i << " is..." << seeds[i] << endl; |
| 229 | #endif |
| 230 | playerKeys[i].Gen_Random_Data(G); |
| 231 | globalKey += playerKeys[i]; |
| 232 | } |
| 233 | mul(b, globalKey.a, globalKey.secret); |
| 234 | mul(globalKey.e, globalKey.e, pk.p()); |
| 235 | add(b, b, globalKey.e); |
| 236 | |
| 237 | // Check the main pk (a,b) |
| 238 | if (!pk.a().equals(globalKey.a)) |
| 239 | throw bad_keygen("a doesn't match"); |
| 240 | if (!pk.b().equals(b)) |
| 241 | throw bad_keygen("b doesn't match"); |
| 242 | |
| 243 | |
| 244 | // Compute the key-switching data |
| 245 | for (int i = 0; i < num_players; i++) |
| 246 | { |
| 247 | Rq_Element zero_q(params.FFTD(), evaluation, evaluation); |
| 248 | zero_q.assign_zero(); |
| 249 | Encrypt_Rq_Element(ed, zero_q, playerKeys[i].rc1, pk); |
| 250 | add(ed_sum, ed_sum, ed); |
| 251 | pk.quasi_encrypt(ezero, zero, playerKeys[i].rc2); |
| 252 | add(ezero_sum, ezero_sum, ezero); |
| 253 | } |
| 254 | |
| 255 | globalKey.secret.raise_level(); |
| 256 | Rq_Element ps(globalKey.secret); |
| 257 | ps.mul_by_p1(); ps.negate(); |
| 258 | |
| 259 | Rq_Element enc0(ed_sum.c0()); |
| 260 | Rq_Element enc1(ed_sum.c1()); |
| 261 | |
| 262 | add(enc0, enc0, ps); |
| 263 | |
| 264 | if (enc1 != enc_dash.c1()) |
no test coverage detected