From fe261e2a1ccab87d82209a6784b0e3b9b0004c1b Mon Sep 17 00:00:00 2001 From: "hilder.vitor" Date: Fri, 11 Mar 2022 12:58:21 +0100 Subject: [PATCH] Created ct_not_const to speed up SchemeNTRU::not_gate --- include/ntruhe.h | 9 +++++++++ src/ntruhe.cpp | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/ntruhe.h b/include/ntruhe.h index 46eea2b..7eb8ed4 100644 --- a/include/ntruhe.h +++ b/include/ntruhe.h @@ -74,6 +74,7 @@ class SchemeNTRU Ctxt_NTRU ct_nand_const; Ctxt_NTRU ct_and_const; Ctxt_NTRU ct_or_const; + Ctxt_NTRU ct_not_const; void mask_constant(Ctxt_NTRU& ct, int constant); @@ -98,6 +99,13 @@ class SchemeNTRU //cout << "Encryption of OR: " << float(clock()-start)/CLOCKS_PER_SEC << endl; } + inline void set_not_const() + { + encrypt(ct_not_const, 1); + } + + + public: SchemeNTRU() @@ -112,6 +120,7 @@ class SchemeNTRU set_nand_const(); set_and_const(); set_or_const(); + set_not_const(); } /** * Encrypts a bit using matrix NTRU. diff --git a/src/ntruhe.cpp b/src/ntruhe.cpp index d4868d4..4862dee 100644 --- a/src/ntruhe.cpp +++ b/src/ntruhe.cpp @@ -298,6 +298,7 @@ void SchemeNTRU::xor_gate(Ctxt_NTRU& ct_res, const Ctxt_NTRU& ct1, const Ctxt_NT void SchemeNTRU::not_gate(Ctxt_NTRU& ct_res, const Ctxt_NTRU& ct) const { - nand_gate(ct_res, ct, ct); + ct_res = ct_not_const; + ct_res -= ct; }