Skip to content

Commit a68c33c

Browse files
authored
778 fix lmkcdey parameter sets (#799)
* increase mod of STD128Q_LMKCDEY within binfhecontext.cpp * update BINFHE_PARAMSETs * update LPF BINFHE_PARAMSETs * add approximate probability of failure to binfhe-constants * created binfhe-paramsets benchmark * added LPF sets to binfhe-constants-impl.cpp * added comments for BinFHEContext::GenerateLUTviaFunctionv()
1 parent 4eed808 commit a68c33c

File tree

7 files changed

+336
-233
lines changed

7 files changed

+336
-233
lines changed

benchmark/src/binfhe-paramsets.cpp

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//==================================================================================
2+
// BSD 2-Clause License
3+
//
4+
// Copyright (c) 2014-2024, NJIT, Duality Technologies Inc. and other contributors
5+
//
6+
// All rights reserved.
7+
//
8+
// Author TPOC: contact@openfhe.org
9+
//
10+
// Redistribution and use in source and binary forms, with or without
11+
// modification, are permitted provided that the following conditions are met:
12+
//
13+
// 1. Redistributions of source code must retain the above copyright notice, this
14+
// list of conditions and the following disclaimer.
15+
//
16+
// 2. Redistributions in binary form must reproduce the above copyright notice,
17+
// this list of conditions and the following disclaimer in the documentation
18+
// and/or other materials provided with the distribution.
19+
//
20+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
//==================================================================================
31+
32+
#include "benchmark/benchmark.h"
33+
#include "binfhecontext.h"
34+
35+
#include <random>
36+
37+
using namespace lbcrypto;
38+
39+
[[maybe_unused]] static void FHEW_BTKEYGEN(benchmark::State& state, BINFHE_PARAMSET s, BINFHE_METHOD m) {
40+
auto cc = BinFHEContext();
41+
cc.GenerateBinFHEContext(s, m);
42+
for (auto _ : state)
43+
cc.BTKeyGen(cc.KeyGen());
44+
}
45+
46+
[[maybe_unused]] static void FHEW_ENCRYPT(benchmark::State& state, BINFHE_PARAMSET s, BINFHE_METHOD m) {
47+
auto cc = BinFHEContext();
48+
cc.GenerateBinFHEContext(s, m);
49+
auto sk = cc.KeyGen();
50+
auto x = std::bind(std::uniform_int_distribution<LWEPlaintext>(0, 1), std::default_random_engine());
51+
for (auto _ : state)
52+
auto ct = cc.Encrypt(sk, x());
53+
}
54+
55+
[[maybe_unused]] static void FHEW_NOT(benchmark::State& state, BINFHE_PARAMSET s, BINFHE_METHOD m) {
56+
auto cc = BinFHEContext();
57+
cc.GenerateBinFHEContext(s, m);
58+
auto sk = cc.KeyGen();
59+
auto x = std::bind(std::uniform_int_distribution<LWEPlaintext>(0, 1), std::default_random_engine());
60+
for (auto _ : state)
61+
auto ct = cc.EvalNOT(cc.Encrypt(sk, x()));
62+
}
63+
64+
[[maybe_unused]] static void FHEW_BINGATE2(benchmark::State& state, BINFHE_PARAMSET s, BINFHE_METHOD m, BINGATE g) {
65+
auto cc = BinFHEContext();
66+
cc.GenerateBinFHEContext(s, m);
67+
auto sk = cc.KeyGen();
68+
cc.BTKeyGen(sk);
69+
auto x = std::bind(std::uniform_int_distribution<LWEPlaintext>(0, 1), std::default_random_engine());
70+
for (auto _ : state)
71+
auto ct = cc.EvalBinGate(g, cc.Encrypt(sk, x(), SMALL_DIM, 4), cc.Encrypt(sk, x(), SMALL_DIM, 4));
72+
}
73+
74+
[[maybe_unused]] static void FHEW_BINGATE3(benchmark::State& state, BINFHE_PARAMSET s, BINFHE_METHOD m, BINGATE g) {
75+
auto cc = BinFHEContext();
76+
cc.GenerateBinFHEContext(s, m);
77+
auto sk = cc.KeyGen();
78+
cc.BTKeyGen(sk);
79+
auto x = std::bind(std::uniform_int_distribution<LWEPlaintext>(0, 1), std::default_random_engine());
80+
for (auto _ : state)
81+
auto ct = cc.EvalBinGate(
82+
g, std::vector<LWECiphertext>{cc.Encrypt(sk, x(), SMALL_DIM, 6), cc.Encrypt(sk, x(), SMALL_DIM, 6),
83+
cc.Encrypt(sk, x(), SMALL_DIM, 6)});
84+
}
85+
86+
[[maybe_unused]] static void FHEW_BINGATE4(benchmark::State& state, BINFHE_PARAMSET s, BINFHE_METHOD m, BINGATE g) {
87+
auto cc = BinFHEContext();
88+
cc.GenerateBinFHEContext(s, m);
89+
auto sk = cc.KeyGen();
90+
cc.BTKeyGen(sk);
91+
auto x = std::bind(std::uniform_int_distribution<LWEPlaintext>(0, 1), std::default_random_engine());
92+
for (auto _ : state)
93+
auto ct = cc.EvalBinGate(
94+
g, std::vector<LWECiphertext>{cc.Encrypt(sk, x(), SMALL_DIM, 8), cc.Encrypt(sk, x(), SMALL_DIM, 8),
95+
cc.Encrypt(sk, x(), SMALL_DIM, 8), cc.Encrypt(sk, x(), SMALL_DIM, 8)});
96+
}
97+
98+
// clang-format off
99+
BENCHMARK_CAPTURE(FHEW_BINGATE2, TOY_2_GINX_OR, TOY, GINX, OR)->Unit(benchmark::kMillisecond);
100+
BENCHMARK_CAPTURE(FHEW_BINGATE2, MEDIUM_2_GINX_OR, MEDIUM, GINX, OR)->Unit(benchmark::kMillisecond);
101+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD128_2_AP_OR, STD128_AP, AP, OR)->Unit(benchmark::kMillisecond);
102+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD128_2_GINX_OR, STD128, GINX, OR)->Unit(benchmark::kMillisecond);
103+
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD128_3_GINX_OR, STD128_3, GINX, OR3)->Unit(benchmark::kMillisecond);
104+
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD128_4_GINX_OR, STD128_4, GINX, OR4)->Unit(benchmark::kMillisecond);
105+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD128Q_2_GINX_OR, STD128Q, GINX, OR)->Unit(benchmark::kMillisecond);
106+
#if NATIVEINT >= 64
107+
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD128Q_3_GINX_OR, STD128Q_3, GINX, OR3)->Unit(benchmark::kMillisecond);
108+
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD128Q_4_GINX_OR, STD128Q_4, GINX, OR4)->Unit(benchmark::kMillisecond);
109+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD192_2_GINX_OR, STD192, GINX, OR)->Unit(benchmark::kMillisecond);
110+
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD192_3_GINX_OR, STD192_3, GINX, OR3)->Unit(benchmark::kMillisecond);
111+
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD192_4_GINX_OR, STD192_4, GINX, OR4)->Unit(benchmark::kMillisecond);
112+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD192Q_2_GINX_OR, STD192Q, GINX, OR)->Unit(benchmark::kMillisecond);
113+
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD192Q_3_GINX_OR, STD192Q_3, GINX, OR3)->Unit(benchmark::kMillisecond);
114+
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD192Q_4_GINX_OR, STD192Q_4, GINX, OR4)->Unit(benchmark::kMillisecond);
115+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD256_2_GINX_OR, STD256, GINX, OR)->Unit(benchmark::kMillisecond);
116+
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD256_3_GINX_OR, STD256_3, GINX, OR3)->Unit(benchmark::kMillisecond);
117+
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD256_4_GINX_OR, STD256_4, GINX, OR4)->Unit(benchmark::kMillisecond);
118+
#endif
119+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD256Q_2_GINX_OR, STD256Q, GINX, OR)->Unit(benchmark::kMillisecond);
120+
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD256Q_3_GINX_OR, STD256Q_3, GINX, OR3)->Unit(benchmark::kMillisecond);
121+
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD256Q_4_GINX_OR, STD256Q_4, GINX, OR4)->Unit(benchmark::kMillisecond);
122+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD128_2_LMKCDEY_OR, STD128_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond);
123+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD128Q_2_LMKCDEY_OR, STD128Q_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond);
124+
#if NATIVEINT >= 64
125+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD192_2_LMKCDEY_OR, STD192_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond);
126+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD192Q_2_LMKCDEY_OR, STD192Q_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond);
127+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD256_2_LMKCDEY_OR, STD256_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond);
128+
#endif
129+
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD256Q_2_LMKCDEY_OR, STD256Q_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond);
130+
BENCHMARK_CAPTURE(FHEW_BINGATE2, LPF_STD128_2_GINX_OR, LPF_STD128, GINX, OR)->Unit(benchmark::kMillisecond);
131+
BENCHMARK_CAPTURE(FHEW_BINGATE2, LPF_STD128Q_2_GINX_OR, LPF_STD128Q, GINX, OR)->Unit(benchmark::kMillisecond);
132+
BENCHMARK_CAPTURE(FHEW_BINGATE2, LPF_STD128_2_LMKCDEY_OR, LPF_STD128_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond);
133+
BENCHMARK_CAPTURE(FHEW_BINGATE2, LPF_STD128Q_2_LMKCDEY_OR, LPF_STD128Q_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond);
134+
// clang-format on
135+
136+
BENCHMARK_MAIN();

src/binfhe/examples/boolean-multi-input.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main() {
4242

4343
auto cc = BinFHEContext();
4444

45-
cc.GenerateBinFHEContext(STD128_4_LMKCDEY, LMKCDEY);
45+
cc.GenerateBinFHEContext(STD128_4, GINX);
4646

4747
// Sample Program: Step 2: Key Generation
4848

src/binfhe/include/binfhe-constants.h

+36-53
Original file line numberDiff line numberDiff line change
@@ -45,61 +45,44 @@ using LWEPlaintextModulus = uint64_t;
4545
/**
4646
* @brief Security levels for predefined parameter sets
4747
*/
48+
// clang-format off
4849
enum BINFHE_PARAMSET {
49-
TOY, // no security
50-
MEDIUM, // 108 bits of security for classical and 100 bits for quantum
51-
STD128_LMKCDEY, // Optimized for LMKCDEY (using Gaussian secrets) -
52-
// more than 128 bits of security for classical computer attacks -
53-
// optimize runtime by finding a non-power-of-two n
54-
STD128_AP, // Optimized for AP (has higher failure probability for GINX) -
55-
// more than 128 bits of security for classical computer attacks -
56-
// optimize runtime by finding a non-power-of-two n
57-
STD128, // more than 128 bits of security for classical computer attacks -
58-
// optimize runtime by finding a non-power-of-two n
59-
STD192, // more than 192 bits of security for classical computer attacks -
60-
// optimize runtime by finding a non-power-of-two n
61-
STD256, // more than 256 bits of security for classical computer attacks -
62-
// optimize runtime by finding a non-power-of-two n
63-
STD128Q, // more than 128 bits of security for quantum attacks -
64-
// optimize runtime by finding a non-power-of-two n
65-
STD128Q_LMKCDEY, // Optimized for LMKCDEY (using Gaussian secrets) -
66-
// more than 128 bits of security for quantum attacks -
67-
// optimize runtime by finding a non-power-of-two n
68-
STD192Q, // more than 192 bits of security for quantum attacks -
69-
// optimize runtime by finding a non-power-of-two n
70-
STD256Q, // more than 256 bits of security for quantum attacks -
71-
// optimize runtime by finding a non-power-of-two n
72-
STD128_3, // more than 128 bits of security for classical computer attacks -
73-
// optimize runtime by finding a non-power-of-two n for 3 binary inputs
74-
STD128_3_LMKCDEY, // Optimized for LMKCDEY (using Gaussian secrets) -
75-
// more than 128 bits of security for classical computer attacks -
76-
// optimize runtime by finding a non-power-of-two n for 3 binary inputs
77-
STD128Q_3, // more than 128 bits of security for quantum computer attacks -
78-
// optimize runtime by finding a non-power-of-two n for 3 binary inputs
79-
STD128Q_3_LMKCDEY, // Optimized for LMKCDEY (using Gaussian secrets) -
80-
// more than 128 bits of security for quantum computer attacks -
81-
// optimize runtime by finding a non-power-of-two n for 3 binary inputs
82-
STD192Q_3, // more than 192 bits of security for quantum computer attacks -
83-
// optimize runtime by finding a non-power-of-two n for 3 binary inputs
84-
STD256Q_3, // more than 256 bits of security for quantum computer attacks -
85-
// optimize runtime by finding a non-power-of-two n for 3 binary inputs
86-
STD128_4, // more than 128 bits of security for classical computer attacks -
87-
// optimize runtime by finding a non-power-of-two n for 4 binary inputs
88-
STD128_4_LMKCDEY, // Optimized for LMKCDEY (using Gaussian secrets) -
89-
// more than 128 bits of security for classical computer attacks -
90-
// optimize runtime by finding a non-power-of-two n for 4 binary inputs
91-
STD128Q_4, // more than 128 bits of security for quantum computer attacks -
92-
// optimize runtime by finding a non-power-of-two n for 4 binary inputs
93-
STD128Q_4_LMKCDEY, // Optimized for LMKCDEY (using Gaussian secrets) -
94-
// more than 128 bits of security for quantum computer attacks -
95-
// optimize runtime by finding a non-power-of-two n for 4 binary inputs
96-
STD192Q_4, // more than 192 bits of security for quantum computer attacks -
97-
// optimize runtime by finding a non-power-of-two n for 4 binary inputs
98-
STD256Q_4, // more than 256 bits of security for quantum computer attacks -
99-
// optimize runtime by finding a non-power-of-two n for 4 binary inputs
100-
SIGNED_MOD_TEST // special parameter set for confirming the signed modular
101-
// reduction in the accumulator updates works correctly
50+
// NAME, // Description : Approximate Probability of Failure
51+
TOY, // no security : 2^(-360)
52+
MEDIUM, // 108 bits of security for classical and 100 bits for quantum : 2^(-70)
53+
STD128_AP, // more than 128 bits of security for classical computer attacks : 2^(-50)
54+
STD128, // more than 128 bits of security for classical computer attacks : 2^(-40)
55+
STD128_3, // STD128 for 3 binary inputs : 2^(-50)
56+
STD128_4, // STD128 for 4 binary inputs : 2^(-50)
57+
STD128Q, // more than 128 bits of security for quantum attacks : 2^(-40)
58+
STD128Q_3, // STD128Q for 3 binary inputs : 2^(-50)
59+
STD128Q_4, // STD128Q for 4 binary inputs : 2^(-50)
60+
STD192, // more than 192 bits of security for classical computer attacks : 2^(-40)
61+
STD192_3, // STD192 for 3 binary inputs : 2^(-60)
62+
STD192_4, // STD192 for 4 binary inputs : 2^(-70)
63+
STD192Q, // more than 192 bits of security for quantum attacks : 2^(-80)
64+
STD192Q_3, // STD192Q for 3 binary inputs : 2^(-80)
65+
STD192Q_4, // STD192Q for 4 binary inputs : 2^(-50)
66+
STD256, // more than 256 bits of security for classical computer attacks : 2^(-80)
67+
STD256_3, // STD256 for 3 binary inputs : 2^(-70)
68+
STD256_4, // STD256 for 4 binary inputs : 2^(-50)
69+
STD256Q, // more than 256 bits of security for quantum attacks : 2^(-60)
70+
STD256Q_3, // STD256Q for 3 binary inputs : 2^(-80)
71+
STD256Q_4, // STD256Q for 4 binary inputs : 2^(-50)
72+
STD128_LMKCDEY, // STD128 optimized for LMKCDEY (using Gaussian secrets) : 2^(-50)
73+
STD128Q_LMKCDEY, // STD128Q optimized for LMKCDEY (using Gaussian secrets) : 2^(-50)
74+
STD192_LMKCDEY, // STD192 optimized for LMKCDEY (using Gaussian secrets) : 2^(-60)
75+
STD192Q_LMKCDEY, // STD192Q optimized for LMKCDEY (using Gaussian secrets) : 2^(-70)
76+
STD256_LMKCDEY, // STD256 optimized for LMKCDEY (using Gaussian secrets) : 2^(-50)
77+
STD256Q_LMKCDEY, // STD256Q optimized for LMKCDEY (using Gaussian secrets) : 2^(-60)
78+
LPF_STD128, // STD128 configured with lower probability of failures : 2^(-120)
79+
LPF_STD128Q, // STD128Q configured with lower probability of failures : 2^(-75)
80+
LPF_STD128_LMKCDEY, // LPF_STD128 optimized for LMKCDEY (using Gaussian secrets) : 2^(-100)
81+
LPF_STD128Q_LMKCDEY, // LPF_STD128Q optimized for LMKCDEY (using Gaussian secrets) : 2^(-90)
82+
SIGNED_MOD_TEST // special parameter set for confirming the signed modular : 2^(-40)
83+
// reduction in the accumulator updates works correctly
10284
};
85+
// clang-format on
10386
std::ostream& operator<<(std::ostream& s, BINFHE_PARAMSET f);
10487

10588
/**

src/binfhe/include/binfhecontext.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class BinFHEContext : public Serializable {
116116
* @param timeOptimization whether to use dynamic bootstrapping technique
117117
* @return creates the cryptocontext
118118
*/
119-
void GenerateBinFHEContext(BINFHE_PARAMSET set, bool arbFunc, uint32_t logQ = 11, int64_t N = 0,
119+
void GenerateBinFHEContext(BINFHE_PARAMSET set, bool arbFunc, uint32_t logQ = 11, uint32_t N = 0,
120120
BINFHE_METHOD method = GINX, bool timeOptimization = false);
121121

122122
/**

src/binfhe/include/rgsw-cryptoparameters.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class RingGSWCryptoParams : public Serializable {
8888
m_numAutoKeys(numAutoKeys) {
8989
if (!IsPowerOfTwo(baseG))
9090
OPENFHE_THROW("Gadget base should be a power of two.");
91-
if ((method == LMKCDEY) & (numAutoKeys == 0))
91+
if ((method == LMKCDEY) && (numAutoKeys == 0))
9292
OPENFHE_THROW("numAutoKeys should be greater than 0.");
9393
auto logQ{log(m_Q.ConvertToDouble())};
9494
m_digitsG = static_cast<uint32_t>(std::ceil(logQ / log(static_cast<double>(m_baseG))));

0 commit comments

Comments
 (0)