Skip to content

Commit 2fefb8d

Browse files
Added the missing m_ prefix to class data members in src/core and src/binfhe
1 parent d6ca063 commit 2fefb8d

6 files changed

Lines changed: 117 additions & 113 deletions

File tree

src/binfhe/include/binfhe-base-scheme.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ class BinFHEScheme {
6767

6868
explicit BinFHEScheme(BINFHE_METHOD method) {
6969
if (method == AP)
70-
ACCscheme = std::make_shared<RingGSWAccumulatorDM>();
70+
m_ACCscheme = std::make_shared<RingGSWAccumulatorDM>();
7171
else if (method == GINX)
72-
ACCscheme = std::make_shared<RingGSWAccumulatorCGGI>();
72+
m_ACCscheme = std::make_shared<RingGSWAccumulatorCGGI>();
7373
else if (method == LMKCDEY)
74-
ACCscheme = std::make_shared<RingGSWAccumulatorLMKCDEY>();
74+
m_ACCscheme = std::make_shared<RingGSWAccumulatorLMKCDEY>();
7575
else
7676
OPENFHE_THROW("method is invalid");
7777
}
@@ -145,8 +145,7 @@ class BinFHEScheme {
145145
* @return a shared pointer to the resulting ciphertext
146146
*/
147147
LWECiphertext EvalFunc(const std::shared_ptr<BinFHECryptoParams>& params, const RingGSWBTKey& EK,
148-
ConstLWECiphertext& ct, const std::vector<NativeInteger>& LUT,
149-
NativeInteger beta) const;
148+
ConstLWECiphertext& ct, const std::vector<NativeInteger>& LUT, NativeInteger beta) const;
150149

151150
/**
152151
* Evaluate a round down function
@@ -172,8 +171,8 @@ class BinFHEScheme {
172171
* @return a shared pointer to the resulting ciphertext
173172
*/
174173
LWECiphertext EvalSign(const std::shared_ptr<BinFHECryptoParams>& params,
175-
const std::map<uint32_t, RingGSWBTKey>& EKs, ConstLWECiphertext& ct,
176-
NativeInteger beta, bool schemeSwitch = false) const;
174+
const std::map<uint32_t, RingGSWBTKey>& EKs, ConstLWECiphertext& ct, NativeInteger beta,
175+
bool schemeSwitch = false) const;
177176

178177
/**
179178
* Evaluate digit decomposition over a large precision LWE ciphertext
@@ -232,8 +231,8 @@ class BinFHEScheme {
232231
ConstLWECiphertext& ct, const Func f, NativeInteger fmod) const;
233232

234233
protected:
235-
std::shared_ptr<LWEEncryptionScheme> LWEscheme{std::make_shared<LWEEncryptionScheme>()};
236-
std::shared_ptr<RingGSWAccumulator> ACCscheme{nullptr};
234+
std::shared_ptr<LWEEncryptionScheme> m_LWEscheme{std::make_shared<LWEEncryptionScheme>()};
235+
std::shared_ptr<RingGSWAccumulator> m_ACCscheme{nullptr};
237236

238237
/**
239238
* Checks type of input function

src/binfhe/lib/binfhe-base-scheme.cpp

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,34 @@ RingGSWBTKey BinFHEScheme::KeyGen(const std::shared_ptr<BinFHECryptoParams>& par
5151
RingGSWBTKey ek;
5252
LWEPrivateKey skN;
5353
if (keygenMode == SYM_ENCRYPT) {
54-
skN = LWEscheme->KeyGen(LWEParams->GetN(), LWEParams->GetQ());
54+
skN = m_LWEscheme->KeyGen(LWEParams->GetN(), LWEParams->GetQ());
5555
}
5656
else if (keygenMode == PUB_ENCRYPT) {
57-
ConstLWEKeyPair kpN = LWEscheme->KeyGenPair(LWEParams);
57+
ConstLWEKeyPair kpN = m_LWEscheme->KeyGenPair(LWEParams);
5858
skN = kpN->secretKey;
5959
ek.Pkey = kpN->publicKey;
6060
}
6161
else {
6262
OPENFHE_THROW("Invalid KeyGen mode");
6363
}
6464

65-
ek.KSkey = LWEscheme->KeySwitchGen(LWEParams, LWEsk, skN);
65+
ek.KSkey = m_LWEscheme->KeySwitchGen(LWEParams, LWEsk, skN);
6666

6767
const auto& RGSWParams = params->GetRingGSWParams();
6868
const auto& polyParams = RGSWParams->GetPolyParams();
6969
NativePoly skNPoly(polyParams);
7070
skNPoly.SetValues(std::move(skN->GetElement()), Format::COEFFICIENT);
7171
skNPoly.SetFormat(Format::EVALUATION);
7272

73-
ek.BSkey = ACCscheme->KeyGenAcc(RGSWParams, skNPoly, LWEsk);
73+
ek.BSkey = m_ACCscheme->KeyGenAcc(RGSWParams, skNPoly, LWEsk);
7474

7575
return ek;
7676
}
7777

7878
// Full evaluation as described in https://eprint.iacr.org/2020/086
7979
LWECiphertext BinFHEScheme::EvalBinGate(const std::shared_ptr<BinFHECryptoParams>& params, BINGATE gate,
80-
const RingGSWBTKey& EK, ConstLWECiphertext& ct1,
81-
ConstLWECiphertext& ct2, bool extended) const {
80+
const RingGSWBTKey& EK, ConstLWECiphertext& ct1, ConstLWECiphertext& ct2,
81+
bool extended) const {
8282
if (params == nullptr)
8383
OPENFHE_THROW("BinFHECryptoParams is empty");
8484
if (ct1 == nullptr)
@@ -92,21 +92,22 @@ LWECiphertext BinFHEScheme::EvalBinGate(const std::shared_ptr<BinFHECryptoParams
9292
NativeInteger Q{LWEParams->GetQ()};
9393

9494
// input cts expected with SMALL_DIM
95-
auto cct1 = (Q == ct1->GetModulus()) ? LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ct1) : std::make_shared<LWECiphertextImpl>(*ct1);
96-
const auto cct2 = (Q == ct2->GetModulus()) ? LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ct2) : ct2;
95+
auto cct1 = (Q == ct1->GetModulus()) ? m_LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ct1) :
96+
std::make_shared<LWECiphertextImpl>(*ct1);
97+
const auto cct2 = (Q == ct2->GetModulus()) ? m_LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ct2) : ct2;
9798

9899
// the additive homomorphic operation for XOR/NXOR is different from the other gates we compute
99100
// 2*(ct1 + ct2) mod 4 for XOR, 0 -> 0, 2 -> 1
100101
// XOR_FAST and XNOR_FAST are included for backwards compatibility; they map to XOR and XNOR
101102
if ((gate == XOR) || (gate == XNOR) || (gate == XOR_FAST) || (gate == XNOR_FAST)) {
102-
LWEscheme->EvalAddEq(cct1, cct2);
103-
LWEscheme->EvalAddEq(cct1, cct1);
103+
m_LWEscheme->EvalAddEq(cct1, cct2);
104+
m_LWEscheme->EvalAddEq(cct1, cct1);
104105
}
105106
else {
106107
// for all other gates, we simply compute (ct1 + ct2) mod 4
107108
// for AND: 0,1 -> 0 and 2,3 -> 1
108109
// for OR: 1,2 -> 1 and 3,0 -> 0
109-
LWEscheme->EvalAddEq(cct1, cct2);
110+
m_LWEscheme->EvalAddEq(cct1, cct2);
110111
}
111112

112113
// the accumulator result is encrypted w.r.t. the transposed secret key
@@ -125,13 +126,13 @@ LWECiphertext BinFHEScheme::EvalBinGate(const std::shared_ptr<BinFHECryptoParams
125126

126127
if (extended)
127128
return ctExt;
128-
return LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctExt);
129+
return m_LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctExt);
129130
}
130131

131132
// Full evaluation as described in https://eprint.iacr.org/2020/086
132133
LWECiphertext BinFHEScheme::EvalBinGate(const std::shared_ptr<BinFHECryptoParams>& params, BINGATE gate,
133-
const RingGSWBTKey& EK, const std::vector<LWECiphertext>& ctvector, bool extended) const {
134-
134+
const RingGSWBTKey& EK, const std::vector<LWECiphertext>& ctvector,
135+
bool extended) const {
135136
if (params == nullptr)
136137
OPENFHE_THROW("BinFHECryptoParams is empty");
137138

@@ -150,9 +151,12 @@ LWECiphertext BinFHEScheme::EvalBinGate(const std::shared_ptr<BinFHECryptoParams
150151
NativeInteger Q{LWEParams->GetQ()};
151152

152153
// input cts expected with SMALL_DIM
153-
auto ct = (Q == ctvector[0]->GetModulus()) ? LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctvector[0]) : std::make_shared<LWECiphertextImpl>(*ctvector[0]);
154+
auto ct = (Q == ctvector[0]->GetModulus()) ? m_LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctvector[0]) :
155+
std::make_shared<LWECiphertextImpl>(*ctvector[0]);
154156
for (uint32_t i = 1; i < length; ++i) {
155-
LWEscheme->EvalAddEq(ct, (Q == ctvector[i]->GetModulus()) ? LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctvector[i]) : ctvector[i]);
157+
m_LWEscheme->EvalAddEq(ct, (Q == ctvector[i]->GetModulus()) ?
158+
m_LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctvector[i]) :
159+
ctvector[i]);
156160
}
157161

158162
auto p = ctvector[0]->GetptModulus();
@@ -171,7 +175,7 @@ LWECiphertext BinFHEScheme::EvalBinGate(const std::shared_ptr<BinFHECryptoParams
171175
auto ctExt = std::make_shared<LWECiphertextImpl>(std::move(accVec[0].GetValues()), b);
172176

173177
if (!extended)
174-
ctExt = LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctExt);
178+
ctExt = m_LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctExt);
175179

176180
ctExt->SetptModulus(p);
177181
return ctExt;
@@ -200,8 +204,9 @@ LWECiphertext BinFHEScheme::Bootstrap(const std::shared_ptr<BinFHECryptoParams>&
200204
const auto& LWEParams = params->GetLWEParams();
201205
NativeInteger Q{LWEParams->GetQ()};
202206
// input ct expected with SMALL_DIM
203-
auto cct = (Q == ct->GetModulus()) ? LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ct) : std::make_shared<LWECiphertextImpl>(*ct);
204-
LWEscheme->EvalAddConstEq(cct, (ct->GetModulus() >> 2));
207+
auto cct = (Q == ct->GetModulus()) ? m_LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ct) :
208+
std::make_shared<LWECiphertextImpl>(*ct);
209+
m_LWEscheme->EvalAddConstEq(cct, (ct->GetModulus() >> 2));
205210

206211
// the accumulator result is encrypted w.r.t. the transposed secret key
207212
// we can transpose "a" to get an encryption under the original secret key
@@ -216,7 +221,7 @@ LWECiphertext BinFHEScheme::Bootstrap(const std::shared_ptr<BinFHECryptoParams>&
216221
auto ctExt = std::make_shared<LWECiphertextImpl>(std::move(accVec[0].GetValues()), b);
217222

218223
if (!extended)
219-
ctExt = LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctExt);
224+
ctExt = m_LWEscheme->SwitchCTtoqn(LWEParams, EK.KSkey, ctExt);
220225

221226
ctExt->SetptModulus(ct->GetptModulus());
222227
return ctExt;
@@ -257,7 +262,7 @@ LWECiphertext BinFHEScheme::EvalFunc(const std::shared_ptr<BinFHECryptoParams>&
257262
auto fLUT = [LUT](NativeInteger x, NativeInteger q, NativeInteger Q) -> NativeInteger {
258263
return LUT[x.ConvertToInt()];
259264
};
260-
LWEscheme->EvalAddConstEq(ct1, beta);
265+
m_LWEscheme->EvalAddConstEq(ct1, beta);
261266
return BootstrapFunc(params, EK, ct1, fLUT, q);
262267
}
263268

@@ -279,7 +284,7 @@ LWECiphertext BinFHEScheme::EvalFunc(const std::shared_ptr<BinFHECryptoParams>&
279284
// raise the modulus of ct1 : q -> 2q
280285
ct1->GetA().SetModulus(dq);
281286
auto ct2 = std::make_shared<LWECiphertextImpl>(*ct1);
282-
LWEscheme->EvalAddConstEq(ct2, beta);
287+
m_LWEscheme->EvalAddConstEq(ct2, beta);
283288

284289
// this is 1/4q_small or -1/4q_small mod q
285290
auto f0 = [](NativeInteger x, NativeInteger q, NativeInteger Q) -> NativeInteger {
@@ -289,9 +294,9 @@ LWECiphertext BinFHEScheme::EvalFunc(const std::shared_ptr<BinFHECryptoParams>&
289294
return (q >> 2);
290295
};
291296
auto ct3 = BootstrapFunc(params, EK, ct2, f0, dq);
292-
LWEscheme->EvalSubEq2(ct1, ct3);
293-
LWEscheme->EvalAddConstEq(ct3, beta);
294-
LWEscheme->EvalSubConstEq(ct3, q >> 1);
297+
m_LWEscheme->EvalSubEq2(ct1, ct3);
298+
m_LWEscheme->EvalAddConstEq(ct3, beta);
299+
m_LWEscheme->EvalSubConstEq(ct3, q >> 1);
295300

296301
// Now the input is within the range [0, q/2).
297302
// Note that for non-periodic function, the input q is boosted up to 2q
@@ -307,7 +312,7 @@ LWECiphertext BinFHEScheme::EvalFunc(const std::shared_ptr<BinFHECryptoParams>&
307312
}
308313

309314
// Else it's periodic function so we evaluate directly
310-
LWEscheme->EvalAddConstEq(ct1, beta);
315+
m_LWEscheme->EvalAddConstEq(ct1, beta);
311316
// this is 1/4q_small or -1/4q_small mod q
312317
auto f0 = [](NativeInteger x, NativeInteger q, NativeInteger Q) -> NativeInteger {
313318
if (x < (q >> 1))
@@ -316,9 +321,9 @@ LWECiphertext BinFHEScheme::EvalFunc(const std::shared_ptr<BinFHECryptoParams>&
316321
return (q >> 2);
317322
};
318323
auto ct2 = BootstrapFunc(params, EK, ct1, f0, q);
319-
LWEscheme->EvalSubEq2(ct, ct2);
320-
LWEscheme->EvalAddConstEq(ct2, beta);
321-
LWEscheme->EvalSubConstEq(ct2, q >> 2);
324+
m_LWEscheme->EvalSubEq2(ct, ct2);
325+
m_LWEscheme->EvalAddConstEq(ct2, beta);
326+
m_LWEscheme->EvalSubConstEq(ct2, q >> 2);
322327

323328
// Now the input is within the range [0, q/2).
324329
// Note that for non-periodic function, the input q is boosted up to 2q
@@ -339,12 +344,12 @@ LWECiphertext BinFHEScheme::EvalFloor(const std::shared_ptr<BinFHECryptoParams>&
339344
if (ct == nullptr)
340345
OPENFHE_THROW("Ciphertext is empty");
341346

342-
const auto& LWEParams = params->GetLWEParams();
347+
const auto& LWEParams = params->GetLWEParams();
343348
NativeInteger q{roundbits == 0 ? LWEParams->Getq() : beta * (1 << (roundbits + 1))};
344349
NativeInteger mod{ct->GetModulus()};
345350

346351
auto ct1 = std::make_shared<LWECiphertextImpl>(*ct);
347-
LWEscheme->EvalAddConstEq(ct1, beta);
352+
m_LWEscheme->EvalAddConstEq(ct1, beta);
348353

349354
auto ct1Modq = std::make_shared<LWECiphertextImpl>(*ct1);
350355
ct1Modq->SetModulus(q);
@@ -356,7 +361,7 @@ LWECiphertext BinFHEScheme::EvalFloor(const std::shared_ptr<BinFHECryptoParams>&
356361
return (q >> 2);
357362
};
358363
auto ct2 = BootstrapFunc(params, EK, ct1Modq, f1, mod);
359-
LWEscheme->EvalSubEq(ct1, ct2);
364+
m_LWEscheme->EvalSubEq(ct1, ct2);
360365

361366
auto ct2Modq = std::make_shared<LWECiphertextImpl>(*ct1);
362367
ct2Modq->SetModulus(q);
@@ -371,7 +376,7 @@ LWECiphertext BinFHEScheme::EvalFloor(const std::shared_ptr<BinFHECryptoParams>&
371376
return Q + (q >> 1) - x;
372377
};
373378
auto ct3 = BootstrapFunc(params, EK, ct2Modq, f2, mod);
374-
LWEscheme->EvalSubEq(ct1, ct3);
379+
m_LWEscheme->EvalSubEq(ct1, ct3);
375380

376381
return ct1;
377382
}
@@ -404,7 +409,7 @@ LWECiphertext BinFHEScheme::EvalSign(const std::shared_ptr<BinFHECryptoParams>&
404409
// round Q to 2betaQ/q
405410
// mod = mod / q * 2 * beta;
406411
mod = (mod << 1) * beta / q;
407-
cttmp = LWEscheme->ModSwitch(mod, cttmp);
412+
cttmp = m_LWEscheme->ModSwitch(mod, cttmp);
408413

409414
// if dynamic
410415
if (EKs.size() == 3) {
@@ -426,15 +431,15 @@ LWECiphertext BinFHEScheme::EvalSign(const std::shared_ptr<BinFHECryptoParams>&
426431
}
427432
}
428433
}
429-
LWEscheme->EvalAddConstEq(cttmp, beta);
434+
m_LWEscheme->EvalAddConstEq(cttmp, beta);
430435

431436
if (!schemeSwitch) {
432437
// if the ended q is smaller than q, we need to change the param for the final boostrapping
433438
auto f3 = [](NativeInteger x, NativeInteger q, NativeInteger Q) -> NativeInteger {
434439
return (x < q / 2) ? (Q / 4) : (Q - Q / 4);
435440
};
436441
cttmp = BootstrapFunc(params, curEK, cttmp, f3, q); // this is 1/4q_small or -1/4q_small mod q
437-
LWEscheme->EvalSubConstEq(cttmp, q >> 2);
442+
m_LWEscheme->EvalSubConstEq(cttmp, q >> 2);
438443
}
439444
else { // return the negated f3 and do not subtract q/4 for a more natural encoding in scheme switching
440445
// if the ended q is smaller than q, we need to change the param for the final boostrapping
@@ -481,7 +486,7 @@ std::vector<LWECiphertext> BinFHEScheme::EvalDecomp(const std::shared_ptr<BinFHE
481486
cttmp = EvalFloor(params, curEK, cttmp, beta);
482487
mod = mod / q * 2 * beta;
483488
// round Q to 2betaQ/q
484-
cttmp = LWEscheme->ModSwitch(mod, cttmp);
489+
cttmp = m_LWEscheme->ModSwitch(mod, cttmp);
485490

486491
if (EKs.size() == 3) { // if dynamic
487492
uint32_t binLog = static_cast<uint32_t>(std::ceil(std::log2(mod.ConvertToInt())));
@@ -525,8 +530,8 @@ RLWECiphertext BinFHEScheme::BootstrapGateCore(const std::shared_ptr<BinFHECrypt
525530
NativeInteger q2 = q1.ModAddFast(NativeInteger(qHalf), q);
526531

527532
bool swap = q1 >= q2;
528-
auto lb = swap? q2 : q1;
529-
auto ub = swap? q1 : q2;
533+
auto lb = swap ? q2 : q1;
534+
auto ub = swap ? q1 : q2;
530535

531536
// depending on whether the value is the range, it will be set
532537
// to either Q/8 or -Q/8 to match binary arithmetic
@@ -535,8 +540,8 @@ RLWECiphertext BinFHEScheme::BootstrapGateCore(const std::shared_ptr<BinFHECrypt
535540
NativeInteger Q2p = Q / (ct->GetptModulus() * 2) + 1;
536541
NativeInteger Q2pNeg = Q - Q2p;
537542

538-
auto lv = swap? Q2p : Q2pNeg;
539-
auto uv = swap? Q2pNeg : Q2p;
543+
auto lv = swap ? Q2p : Q2pNeg;
544+
auto uv = swap ? Q2pNeg : Q2p;
540545

541546
const uint32_t N = LWEParams->GetN();
542547
NativeVector m(N, Q);
@@ -564,7 +569,7 @@ RLWECiphertext BinFHEScheme::BootstrapGateCore(const std::shared_ptr<BinFHECrypt
564569
// the following loop is the bottleneck of bootstrapping/binary gate
565570
// evaluation
566571
auto acc = std::make_shared<RLWECiphertextImpl>(std::move(res));
567-
ACCscheme->EvalAcc(RGSWParams, ek, acc, ct->GetA());
572+
m_ACCscheme->EvalAcc(RGSWParams, ek, acc, ct->GetA());
568573
return acc;
569574
}
570575

@@ -604,7 +609,7 @@ RLWECiphertext BinFHEScheme::BootstrapFuncCore(const std::shared_ptr<BinFHECrypt
604609
// the following loop is the bottleneck of bootstrapping/binary gate
605610
// evaluation
606611
auto acc = std::make_shared<RLWECiphertextImpl>(std::move(res));
607-
ACCscheme->EvalAcc(RGSWParams, ek, acc, ct->GetA());
612+
m_ACCscheme->EvalAcc(RGSWParams, ek, acc, ct->GetA());
608613
return acc;
609614
}
610615

@@ -623,11 +628,11 @@ LWECiphertext BinFHEScheme::BootstrapFunc(const std::shared_ptr<BinFHECryptoPara
623628

624629
auto& LWEParams = params->GetLWEParams();
625630
// Modulus switching to a middle step Q'
626-
auto ctMS = LWEscheme->ModSwitch(LWEParams->GetqKS(), ctExt);
631+
auto ctMS = m_LWEscheme->ModSwitch(LWEParams->GetqKS(), ctExt);
627632
// Key switching
628-
auto ctKS = LWEscheme->KeySwitch(LWEParams, EK.KSkey, ctMS);
633+
auto ctKS = m_LWEscheme->KeySwitch(LWEParams, EK.KSkey, ctMS);
629634
// Modulus switching
630-
return LWEscheme->ModSwitch(fmod, ctKS);
635+
return m_LWEscheme->ModSwitch(fmod, ctKS);
631636
}
632637

633638
}; // namespace lbcrypto

0 commit comments

Comments
 (0)