-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathckks-functional-bootstrapping.cpp
More file actions
489 lines (404 loc) · 18.9 KB
/
ckks-functional-bootstrapping.cpp
File metadata and controls
489 lines (404 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
//==================================================================================
// BSD 2-Clause License
//
// Copyright (c) 2014-2025, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.
//
// Author TPOC: contact@openfhe.org
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//==================================================================================
#include "benchmark/benchmark.h"
#include "config_core.h"
#include "cryptocontext.h"
#include "gen-cryptocontext.h"
#include "gtest/gtest.h"
#include "math/hermite.h"
#include "scheme/ckksrns/ckksrns-fhe.h"
#include "scheme/ckksrns/ckksrns-utils.h"
#include "scheme/ckksrns/gen-cryptocontext-ckksrns.h"
#include "schemelet/rlwe-mp.h"
#include <complex>
#include <map>
#include <vector>
using namespace lbcrypto;
struct fbt_config {
BigInteger QBFVInit;
BigInteger PInput;
BigInteger POutput;
BigInteger Q;
BigInteger Bigq;
double scaleTHI;
double scaleStepTHI;
size_t order;
uint32_t numSlots;
uint32_t ringDim;
uint32_t dnum;
std::vector<uint32_t> lvlb;
};
[[maybe_unused]] const BigInteger Q1(BigInteger(1) << 1);
[[maybe_unused]] const BigInteger Q2(BigInteger(1) << 2);
[[maybe_unused]] const BigInteger Q4(BigInteger(1) << 4);
[[maybe_unused]] const BigInteger Q8(BigInteger(1) << 8);
[[maybe_unused]] const BigInteger Q12(BigInteger(1) << 12);
[[maybe_unused]] const BigInteger Q32(BigInteger(1) << 32);
[[maybe_unused]] const BigInteger Q33(BigInteger(1) << 33);
[[maybe_unused]] const BigInteger Q35(BigInteger(1) << 35);
[[maybe_unused]] const BigInteger Q38(BigInteger(1) << 38);
[[maybe_unused]] const BigInteger Q47(BigInteger(1) << 47);
[[maybe_unused]] const BigInteger Q55(BigInteger(1) << 55);
[[maybe_unused]] const BigInteger Q60(BigInteger(1) << 60);
[[maybe_unused]] const BigInteger Q71(BigInteger(1) << 71);
[[maybe_unused]] const BigInteger Q80(BigInteger(1) << 80);
// clang-format off
[[maybe_unused]] std::map<uint32_t, fbt_config> arblut_configs = {
// QBFVInit, PInput, POutput, Q, Bigq, scaleTHI, scaleStepTHI, order, numSlots, ringDim, dnum, lvlBudget
{1, { Q60, Q1, Q1, Q33, Q33, 1.0, 1.0, 1, 1 << 15, 1 << 15, 3, {3, 3}}},
{2, { Q60, Q2, Q2, Q35, Q35, 16.0, 1.0, 1, 1 << 16, 1 << 16, 3, {4, 4}}},
{4, { Q60, Q4, Q4, Q38, Q38, 32.0, 1.0, 1, 1 << 16, 1 << 16, 3, {4, 4}}},
{8, { Q60, Q8, Q8, Q47, Q47, 32.0, 1.0, 1, 1 << 16, 1 << 16, 4, {3, 3}}},
{12, { Q80, Q12, Q12, Q55, Q55, 2000.0, 1.0, 1, 1 << 17, 1 << 17, 3, {4, 4}}},
{32, { Q80, Q32, Q4, Q71, Q47, 256.0, 16.0, 1, 1 << 16, 1 << 16, 4, {3, 3}}}
};
// clang-format on
[[maybe_unused]] static void ArbLUTBits(benchmark::internal::Benchmark* b) {
for (uint32_t bits : {12, 8, 4, 2, 1})
b->ArgName("bits")->Arg(bits);
}
[[maybe_unused]] static void FBTSetup(benchmark::State& state) {
auto t = arblut_configs[12];
bool flagSP = (t.numSlots <= t.ringDim / 2); // sparse packing
auto numSlotsCKKS = flagSP ? t.numSlots : t.numSlots / 2;
auto a = t.PInput.ConvertToInt<int64_t>();
auto b = t.POutput.ConvertToInt<int64_t>();
auto f = [a, b](int64_t x) -> int64_t {
return (x % a - a / 2) % b;
};
std::vector<int64_t> x = {
(t.PInput.ConvertToInt<int64_t>() / 2), (t.PInput.ConvertToInt<int64_t>() / 2) + 1, 0, 3, 16, 33, 64,
(t.PInput.ConvertToInt<int64_t>() - 1)};
if (x.size() < t.numSlots)
x = Fill<int64_t>(x, t.numSlots);
std::vector<int64_t> coeffint;
std::vector<std::complex<double>> coeffcomp;
bool binaryLUT = (t.PInput.ConvertToInt() == 2) && (t.order == 1);
if (binaryLUT) // coeffs for [1, cos^2(pi x)], not [1, cos(2pi x)]
coeffint = {f(1), f(0) - f(1)};
else // divided by 2
coeffcomp = GetHermiteTrigCoefficients(f, t.PInput.ConvertToInt(), t.order, t.scaleTHI);
uint32_t dcrtBits = t.Bigq.GetMSB() - 1;
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetSecretKeyDist(SPARSE_ENCAPSULATED);
parameters.SetSecurityLevel(HEStd_NotSet);
parameters.SetScalingModSize(dcrtBits);
parameters.SetScalingTechnique(FIXEDMANUAL);
parameters.SetFirstModSize(dcrtBits);
parameters.SetNumLargeDigits(t.dnum);
parameters.SetBatchSize(numSlotsCKKS);
parameters.SetRingDim(t.ringDim);
uint32_t depth = 0;
if (binaryLUT)
depth += FHECKKSRNS::GetFBTDepth(t.lvlb, coeffint, t.PInput, t.order, SPARSE_ENCAPSULATED);
else
depth += FHECKKSRNS::GetFBTDepth(t.lvlb, coeffcomp, t.PInput, t.order, SPARSE_ENCAPSULATED);
parameters.SetMultiplicativeDepth(depth);
auto cc = GenCryptoContext(parameters);
cc->Enable(PKE);
cc->Enable(KEYSWITCH);
cc->Enable(LEVELEDSHE);
cc->Enable(ADVANCEDSHE);
cc->Enable(FHE);
auto keyPair = cc->KeyGen();
while (state.KeepRunning()) {
if (binaryLUT)
cc->EvalFBTSetup(coeffint, numSlotsCKKS, t.PInput, t.POutput, t.Bigq, keyPair.publicKey, {0, 0}, t.lvlb, 0,
0, t.order);
else
cc->EvalFBTSetup(coeffcomp, numSlotsCKKS, t.PInput, t.POutput, t.Bigq, keyPair.publicKey, {0, 0}, t.lvlb, 0,
0, t.order);
}
cc->ClearStaticMapsAndVectors();
}
[[maybe_unused]] static void FBTKeyGen(benchmark::State& state) {
auto t = arblut_configs[12];
bool flagSP = (t.numSlots <= t.ringDim / 2); // sparse packing
auto numSlotsCKKS = flagSP ? t.numSlots : t.numSlots / 2;
auto a = t.PInput.ConvertToInt<int64_t>();
auto b = t.POutput.ConvertToInt<int64_t>();
auto f = [a, b](int64_t x) -> int64_t {
return (x % a - a / 2) % b;
};
std::vector<int64_t> x = {
(t.PInput.ConvertToInt<int64_t>() / 2), (t.PInput.ConvertToInt<int64_t>() / 2) + 1, 0, 3, 16, 33, 64,
(t.PInput.ConvertToInt<int64_t>() - 1)};
if (x.size() < t.numSlots)
x = Fill<int64_t>(x, t.numSlots);
std::vector<int64_t> coeffint;
std::vector<std::complex<double>> coeffcomp;
bool binaryLUT = (t.PInput.ConvertToInt() == 2) && (t.order == 1);
if (binaryLUT) // coeffs for [1, cos^2(pi x)], not [1, cos(2pi x)]
coeffint = {f(1), f(0) - f(1)};
else // divided by 2
coeffcomp = GetHermiteTrigCoefficients(f, t.PInput.ConvertToInt(), t.order, t.scaleTHI);
uint32_t dcrtBits = t.Bigq.GetMSB() - 1;
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetSecretKeyDist(SPARSE_ENCAPSULATED);
parameters.SetSecurityLevel(HEStd_NotSet);
parameters.SetScalingModSize(dcrtBits);
parameters.SetScalingTechnique(FIXEDMANUAL);
parameters.SetFirstModSize(dcrtBits);
parameters.SetNumLargeDigits(t.dnum);
parameters.SetBatchSize(numSlotsCKKS);
parameters.SetRingDim(t.ringDim);
uint32_t depth = 0;
if (binaryLUT)
depth += FHECKKSRNS::GetFBTDepth(t.lvlb, coeffint, t.PInput, t.order, SPARSE_ENCAPSULATED);
else
depth += FHECKKSRNS::GetFBTDepth(t.lvlb, coeffcomp, t.PInput, t.order, SPARSE_ENCAPSULATED);
parameters.SetMultiplicativeDepth(depth);
auto cc = GenCryptoContext(parameters);
cc->Enable(PKE);
cc->Enable(KEYSWITCH);
cc->Enable(LEVELEDSHE);
cc->Enable(ADVANCEDSHE);
cc->Enable(FHE);
auto keyPair = cc->KeyGen();
if (binaryLUT)
cc->EvalFBTSetup(coeffint, numSlotsCKKS, t.PInput, t.POutput, t.Bigq, keyPair.publicKey, {0, 0}, t.lvlb, 0, 0,
t.order);
else
cc->EvalFBTSetup(coeffcomp, numSlotsCKKS, t.PInput, t.POutput, t.Bigq, keyPair.publicKey, {0, 0}, t.lvlb, 0, 0,
t.order);
while (state.KeepRunning()) {
cc->EvalBootstrapKeyGen(keyPair.secretKey, numSlotsCKKS);
cc->EvalMultKeyGen(keyPair.secretKey);
}
cc->ClearStaticMapsAndVectors();
}
[[maybe_unused]] static void FBTArbLUT(benchmark::State& state) {
auto t = arblut_configs[state.range(0)];
bool flagSP = (t.numSlots <= t.ringDim / 2); // sparse packing
auto numSlotsCKKS = flagSP ? t.numSlots : t.numSlots / 2;
auto a = t.PInput.ConvertToInt<int64_t>();
auto b = t.POutput.ConvertToInt<int64_t>();
auto f = [a, b](int64_t x) -> int64_t {
return (x % a - a / 2) % b;
};
std::vector<int64_t> x = {
(t.PInput.ConvertToInt<int64_t>() / 2), (t.PInput.ConvertToInt<int64_t>() / 2) + 1, 0, 3, 16, 33, 64,
(t.PInput.ConvertToInt<int64_t>() - 1)};
if (x.size() < t.numSlots)
x = Fill<int64_t>(x, t.numSlots);
std::vector<int64_t> coeffint;
std::vector<std::complex<double>> coeffcomp;
bool binaryLUT = (t.PInput.ConvertToInt() == 2) && (t.order == 1);
if (binaryLUT) // coeffs for [1, cos^2(pi x)], not [1, cos(2pi x)]
coeffint = {f(1), f(0) - f(1)};
else // divided by 2
coeffcomp = GetHermiteTrigCoefficients(f, t.PInput.ConvertToInt(), t.order, t.scaleTHI);
uint32_t dcrtBits = t.Bigq.GetMSB() - 1;
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetSecretKeyDist(SPARSE_ENCAPSULATED);
parameters.SetSecurityLevel(HEStd_NotSet);
parameters.SetScalingModSize(dcrtBits);
parameters.SetScalingTechnique(FIXEDMANUAL);
parameters.SetFirstModSize(dcrtBits);
parameters.SetNumLargeDigits(t.dnum);
parameters.SetBatchSize(numSlotsCKKS);
parameters.SetRingDim(t.ringDim);
uint32_t depth = 0;
if (binaryLUT)
depth += FHECKKSRNS::GetFBTDepth(t.lvlb, coeffint, t.PInput, t.order, SPARSE_ENCAPSULATED);
else
depth += FHECKKSRNS::GetFBTDepth(t.lvlb, coeffcomp, t.PInput, t.order, SPARSE_ENCAPSULATED);
parameters.SetMultiplicativeDepth(depth);
auto cc = GenCryptoContext(parameters);
cc->Enable(PKE);
cc->Enable(KEYSWITCH);
cc->Enable(LEVELEDSHE);
cc->Enable(ADVANCEDSHE);
cc->Enable(FHE);
auto keyPair = cc->KeyGen();
if (binaryLUT)
cc->EvalFBTSetup(coeffint, numSlotsCKKS, t.PInput, t.POutput, t.Bigq, keyPair.publicKey, {0, 0}, t.lvlb, 0, 0,
t.order);
else
cc->EvalFBTSetup(coeffcomp, numSlotsCKKS, t.PInput, t.POutput, t.Bigq, keyPair.publicKey, {0, 0}, t.lvlb, 0, 0,
t.order);
cc->EvalBootstrapKeyGen(keyPair.secretKey, numSlotsCKKS);
cc->EvalMultKeyGen(keyPair.secretKey);
auto ep = SchemeletRLWEMP::GetElementParams(keyPair.secretKey, depth);
auto ctxtBFV = SchemeletRLWEMP::EncryptCoeff(x, t.QBFVInit, t.PInput, keyPair.secretKey, ep);
SchemeletRLWEMP::ModSwitch(ctxtBFV, t.Q, t.QBFVInit);
auto ctxt = SchemeletRLWEMP::ConvertRLWEToCKKS(*cc, ctxtBFV, keyPair.publicKey, t.Bigq, numSlotsCKKS, depth);
while (state.KeepRunning()) {
Ciphertext<DCRTPoly> ctxtAfterFBT;
if (binaryLUT)
ctxtAfterFBT = cc->EvalFBT(ctxt, coeffint, t.PInput.GetMSB() - 1, ep->GetModulus(), t.scaleTHI, 0, t.order);
else
ctxtAfterFBT =
cc->EvalFBT(ctxt, coeffcomp, t.PInput.GetMSB() - 1, ep->GetModulus(), t.scaleTHI, 0, t.order);
ctxtAfterFBT.reset();
}
cc->ClearStaticMapsAndVectors();
}
[[maybe_unused]] static void FBTSignDigit32(benchmark::State& state) {
auto t = arblut_configs[32];
bool flagSP = (t.numSlots <= t.ringDim / 2); // sparse packing
auto numSlotsCKKS = flagSP ? t.numSlots : t.numSlots / 2;
auto a = t.PInput.ConvertToInt<int64_t>();
auto b = t.POutput.ConvertToInt<int64_t>();
auto funcMod = [b](int64_t x) -> int64_t {
return (x % b);
};
auto funcStep = [a, b](int64_t x) -> int64_t {
return (x % a) >= (b / 2);
};
std::vector<int64_t> x = {
t.PInput.ConvertToInt<int64_t>() / 2, t.PInput.ConvertToInt<int64_t>() / 2 + 1, 0, 3, 16, 33, 64,
t.PInput.ConvertToInt<int64_t>() - 1};
if (x.size() < t.numSlots)
x = Fill<int64_t>(x, t.numSlots);
auto exact(x);
std::transform(x.begin(), x.end(), exact.begin(),
[&](int64_t elem) { return (elem >= t.PInput.ConvertToDouble() / 2.); });
std::vector<int64_t> coeffintMod;
std::vector<std::complex<double>> coeffcompMod;
std::vector<std::complex<double>> coeffcompStep;
bool binaryLUT = (t.POutput.ConvertToInt() == 2) && (t.order == 1);
if (binaryLUT) {
coeffintMod = {funcMod(1), funcMod(0) - funcMod(1)}; // coeffs for [1, cos^2(pi x)], not [1, cos(2pi x)]
}
else {
coeffcompMod =
GetHermiteTrigCoefficients(funcMod, t.POutput.ConvertToInt(), t.order, t.scaleTHI); // divided by 2
coeffcompStep = GetHermiteTrigCoefficients(funcStep, t.POutput.ConvertToInt(), t.order,
t.scaleStepTHI); // divided by 2
}
uint32_t dcrtBits = t.Bigq.GetMSB() - 1;
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetSecretKeyDist(SPARSE_ENCAPSULATED);
parameters.SetSecurityLevel(HEStd_NotSet);
parameters.SetScalingModSize(dcrtBits);
parameters.SetScalingTechnique(FIXEDMANUAL);
parameters.SetFirstModSize(dcrtBits);
parameters.SetNumLargeDigits(t.dnum);
parameters.SetBatchSize(numSlotsCKKS);
parameters.SetRingDim(t.ringDim);
uint32_t depth = 0;
if (binaryLUT)
depth += FHECKKSRNS::GetFBTDepth(t.lvlb, coeffintMod, t.PInput, t.order, SPARSE_ENCAPSULATED);
else
depth += FHECKKSRNS::GetFBTDepth(t.lvlb, coeffcompMod, t.PInput, t.order, SPARSE_ENCAPSULATED);
parameters.SetMultiplicativeDepth(depth);
auto cc = GenCryptoContext(parameters);
cc->Enable(PKE);
cc->Enable(KEYSWITCH);
cc->Enable(LEVELEDSHE);
cc->Enable(ADVANCEDSHE);
cc->Enable(FHE);
auto keyPair = cc->KeyGen();
if (binaryLUT)
cc->EvalFBTSetup(coeffintMod, numSlotsCKKS, t.POutput, t.PInput, t.Bigq, keyPair.publicKey, {0, 0}, t.lvlb, 0,
0, t.order);
else
cc->EvalFBTSetup(coeffcompMod, numSlotsCKKS, t.POutput, t.PInput, t.Bigq, keyPair.publicKey, {0, 0}, t.lvlb, 0,
0, t.order);
cc->EvalBootstrapKeyGen(keyPair.secretKey, numSlotsCKKS);
cc->EvalMultKeyGen(keyPair.secretKey);
auto ep = SchemeletRLWEMP::GetElementParams(keyPair.secretKey, depth);
std::vector<int64_t> coeffint;
std::vector<std::complex<double>> coeffcomp;
if (binaryLUT)
coeffint = coeffintMod;
else
coeffcomp = coeffcompMod;
while (state.KeepRunning()) {
auto ctxtBFV = SchemeletRLWEMP::EncryptCoeff(x, t.QBFVInit, t.PInput, keyPair.secretKey, ep);
SchemeletRLWEMP::ModSwitch(ctxtBFV, t.Q, t.QBFVInit);
uint32_t QBFVBits = t.Q.GetMSB() - 1;
auto Q = t.Q;
auto PInput = t.PInput;
BigInteger QNew;
const bool checkgt2 = t.POutput.ConvertToInt() > 2;
const uint32_t pDigitBits = t.POutput.GetMSB() - 1;
uint64_t scaleTHI = t.scaleTHI;
bool step = false;
bool go = QBFVBits > dcrtBits;
size_t levelsToDrop = 0;
uint32_t postScalingBits = 0;
// For arbitrary digit size, pNew > 2, the last iteration needs to evaluate step pNew not mod pNew.
// Currently this only works when log(pNew) divides log(p).
while (go) {
auto encryptedDigit = ctxtBFV;
// Apply mod q
encryptedDigit[0].SwitchModulus(t.Bigq, 1, 0, 0);
encryptedDigit[1].SwitchModulus(t.Bigq, 1, 0, 0);
auto ctxt =
SchemeletRLWEMP::ConvertRLWEToCKKS(*cc, encryptedDigit, keyPair.publicKey, t.Bigq, numSlotsCKKS, depth);
// Bootstrap the digit.
Ciphertext<DCRTPoly> ctxtAfterFBT;
if (binaryLUT)
ctxtAfterFBT = cc->EvalFBT(ctxt, coeffint, pDigitBits, ep->GetModulus(),
scaleTHI * (1 << postScalingBits), levelsToDrop, t.order);
else
ctxtAfterFBT = cc->EvalFBT(ctxt, coeffcomp, pDigitBits, ep->GetModulus(),
scaleTHI * (1 << postScalingBits), levelsToDrop, t.order);
auto polys = SchemeletRLWEMP::ConvertCKKSToRLWE(ctxtAfterFBT, Q);
if (!step) {
QNew = Q >> pDigitBits;
// Subtract digit and switch mod from Q to QNew for BFV ciphertext
ctxtBFV[0] = (ctxtBFV[0] - polys[0]).MultiplyAndRound(QNew, Q);
ctxtBFV[0].SwitchModulus(QNew, 1, 0, 0);
ctxtBFV[1] = (ctxtBFV[1] - polys[1]).MultiplyAndRound(QNew, Q);
ctxtBFV[1].SwitchModulus(QNew, 1, 0, 0);
Q >>= pDigitBits;
PInput >>= pDigitBits;
QBFVBits -= pDigitBits;
postScalingBits += pDigitBits;
}
else {
ctxtBFV[0] = std::move(polys[0]);
ctxtBFV[1] = std::move(polys[1]);
}
go = QBFVBits > dcrtBits;
if (checkgt2 && !go && !step) {
if (!binaryLUT)
coeffcomp = coeffcompStep;
scaleTHI = t.scaleStepTHI;
step = true;
go = true;
int64_t lvlsToDrop = GetMultiplicativeDepthByCoeffVector(coeffcompMod, true) -
GetMultiplicativeDepthByCoeffVector(coeffcompStep, true);
if (coeffcompMod.size() > 4 && lvlsToDrop > 0)
levelsToDrop = lvlsToDrop;
}
}
}
cc->ClearStaticMapsAndVectors();
}
BENCHMARK(FBTArbLUT)->Unit(benchmark::kSecond)->Iterations(4)->Apply(ArbLUTBits);
BENCHMARK(FBTSignDigit32)->Unit(benchmark::kSecond)->Iterations(4);
BENCHMARK(FBTSetup)->Unit(benchmark::kSecond)->Iterations(10);
BENCHMARK(FBTKeyGen)->Unit(benchmark::kSecond)->Iterations(4);
BENCHMARK_MAIN();