| 58 | |
| 59 | |
| 60 | void mul(Ciphertext& ans,const Ciphertext& c0,const Ciphertext& c1, |
| 61 | const FHE_PK& pk) |
| 62 | { |
| 63 | CODE_LOCATION_NO_SCOPE |
| 64 | |
| 65 | if (c0.params!=c1.params) { throw params_mismatch(); } |
| 66 | if (ans.params!=c1.params) { throw params_mismatch(); } |
| 67 | |
| 68 | // Switch Modulus for c0 and c1 down to level 0 |
| 69 | Ciphertext cc0=c0,cc1=c1; |
| 70 | cc0.Scale(pk.p()); cc1.Scale(pk.p()); |
| 71 | |
| 72 | // Now do the multiply |
| 73 | auto d0 = cc0.cc0 * cc1.cc0; |
| 74 | auto d1 = cc0.cc0 * cc1.cc1 + cc0.cc1 * cc1.cc0; |
| 75 | auto d2 = cc0.cc1 * cc1.cc1; |
| 76 | d2.negate(); |
| 77 | |
| 78 | // Now do the switch key |
| 79 | d2.raise_level(); |
| 80 | d0.mul_by_p1(); |
| 81 | auto t = pk.bs()* d2; |
| 82 | add(d0,d0,t); |
| 83 | |
| 84 | d1.mul_by_p1(); |
| 85 | mul(t,pk.as(),d2); |
| 86 | add(d1,d1,t); |
| 87 | |
| 88 | ans.set(d0, d1, check_pk_id(c0.pk_id, c1.pk_id)); |
| 89 | ans.Scale(pk.p()); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | template<class T,class FD,class S> |
no test coverage detected