NTRU scheme: homomorphic XOR gate implemented

This commit is contained in:
hilder.vitor
2022-03-11 10:48:48 +01:00
parent f943091bf0
commit a1665c2ddc
2 changed files with 25 additions and 2 deletions

View File

@ -164,6 +164,15 @@ class SchemeNTRU
* @param[in] ct_2 encryption of the second input bit
*/
void or_gate(Ctxt_NTRU& ct_res, const Ctxt_NTRU& ct1, const Ctxt_NTRU& ct2) const;
/**
* Computes the XOR gate of two given ciphertexts ct1 and ct2
* @param[out] ct_res encryptions of the outuput of the XOR 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_NTRU& ct_res, const Ctxt_NTRU& ct1, const Ctxt_NTRU& ct2) const;
};
#endif

View File

@ -283,3 +283,17 @@ void SchemeNTRU::or_gate(Ctxt_NTRU& ct_res, const Ctxt_NTRU& ct1, const Ctxt_NTR
bootstrap(ct_res);
//cout << "OR: " << float(clock()-start)/CLOCKS_PER_SEC << endl;
}
void SchemeNTRU::xor_gate(Ctxt_NTRU& ct_res, const Ctxt_NTRU& ct1, const Ctxt_NTRU& ct2) const
{
if (ct_res.data.size() != parNTRU.n)
ct_res.data = vector<int>(parNTRU.n);
for (size_t i = 0; i < parNTRU.n; i++){
ct_res.data[i] = 2*(ct1.data[i] + ct2.data[i]);
ct_res.data[i] = parNTRU.mod_q_base(ct_res.data[i]); // res = 2*(ct1 + ct2) % q
}
bootstrap(ct_res);
}