LWE scheme: homomorphic XOR gate implemented

This commit is contained in:
hilder.vitor
2022-03-11 10:22:00 +01:00
parent 5218543f67
commit b2aa2d2cda
2 changed files with 24 additions and 2 deletions

View File

@ -143,10 +143,18 @@ class SchemeLWE
* @param[in] ct_2 encryption of the second input bit
*/
void or_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE& ct2) const;
/**
* Computes the XOR gate of two given ciphertexts ct1 and ct2
* @param[out] ct_res encryptions of the outuput of the NAND gate
* @param[in] ct_1 encryption of the first input bit
* @param[in] ct_2 encryption of the second input bit
*/
void xor_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE& ct2) const;
};
#endif
#endif

View File

@ -470,4 +470,18 @@ void SchemeLWE::or_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE& c
ct_res = parLWE.or_const - (ct1 + ct2);
bootstrap(ct_res);
//cout << "OR: " << float(clock()-start)/CLOCKS_PER_SEC << endl;
}
}
void SchemeLWE::xor_gate(Ctxt_LWE& ct_res, const Ctxt_LWE& ct1, const Ctxt_LWE& ct2) const
{
if (ct_res.a.size() != parLWE.n)
ct_res.a = vector<int>(parLWE.n);
for (size_t i = 0; i < parLWE.n; i++)
ct_res.a[i] = parLWE.mod_q_base(2*(ct1.a[i] + ct2.a[i])); // a = 2*(ct1.a + ct2.a)
ct_res.b = parLWE.mod_q_base(2*(ct1.b + ct2.b)); // b = 2*(ct1.b + ct2.b)
bootstrap(ct_res);
}