mirror of
https://github.com/mii443/FINAL.git
synced 2025-08-22 15:05:36 +00:00
NTRU scheme: homomorphic XOR gate implemented
This commit is contained in:
@ -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
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user