Skip to content

Commit c5ad214

Browse files
authored
Merge pull request #1128 from openfheorg/dev
Updates to v1.5.0
2 parents aa39198 + badeffb commit c5ad214

157 files changed

Lines changed: 6333 additions & 5644 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
native_backend: "all"
1616
mb2_jobs: "mb2"
1717
mb4_jobs: "mb4_tcm"
18-
mb6_jobs: "mb6"
18+
mb6_jobs: "mb6_ntl"
1919
# cmake_args_map holds job specific additional cmake options. compiler flags, native_backend flag and
2020
# OpenMP flag are set in generic_workflow.yml
2121
cmake_args_map: '{

CMakeLists.txt

Lines changed: 133 additions & 90 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ OpenFHE also supports hybrid vectorized schemes, with the goal of enabling the F
1212
* Switching between CKKS and FHEW/TFHE to evaluate non-smooth functions, e.g., comparison, using (scalar) FHEW/TFHE functional bootstrapping
1313
* Switching between RLWE (a scheme equivalent to the coefficient-encoded additive BFV scheme) and CKKS to evaluate arbitrary lookup tables over vectors of integers, e.g., modular reduction, comparison or S-box, using vectorized functional bootstrapping implemented in CKKS
1414

15+
OpenFHE also supports partial schemes, called schemelets, such as RLWE which is equivalent to the coefficient-encoded additive BFV scheme. In OpenFHE, the RLWE schemelet is the starting point for the vectorized functional bootstrapping capability, which allows the evaluation of arbitrary lookup tables over vectors of integers, e.g., modular reduction, comparison or Sbox, using CKKS in an intermediate step.
16+
1517
OpenFHE also includes the following multiparty extensions of FHE:
1618
* Threshold FHE for BGV, BFV, and CKKS schemes
1719
* Interactive bootstrapping for Threshold CKKS

benchmark/src/binfhe-paramsets.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ BENCHMARK_CAPTURE(FHEW_BINGATE2, STD128_2_GINX_OR, STD128, GINX, OR)->Unit(bench
103103
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD128_3_GINX_OR, STD128_3, GINX, OR3)->Unit(benchmark::kMillisecond)->MinTime(5.0);
104104
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD128_4_GINX_OR, STD128_4, GINX, OR4)->Unit(benchmark::kMillisecond)->MinTime(5.0);
105105
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD128Q_2_GINX_OR, STD128Q, GINX, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
106-
#if NATIVEINT >= 64
107106
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD128Q_3_GINX_OR, STD128Q_3, GINX, OR3)->Unit(benchmark::kMillisecond)->MinTime(5.0);
107+
#if NATIVEINT >= 64
108108
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD128Q_4_GINX_OR, STD128Q_4, GINX, OR4)->Unit(benchmark::kMillisecond)->MinTime(5.0);
109109
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD192_2_GINX_OR, STD192, GINX, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
110110
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD192_3_GINX_OR, STD192_3, GINX, OR3)->Unit(benchmark::kMillisecond)->MinTime(5.0);
@@ -124,8 +124,8 @@ BENCHMARK_CAPTURE(FHEW_BINGATE3, STD128_3_LMKCDEY_OR, STD128_3_LMKCDEY, LMKCDEY,
124124
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD128_4_LMKCDEY_OR, STD128_4_LMKCDEY, LMKCDEY, OR4)->Unit(benchmark::kMillisecond)->MinTime(5.0);
125125
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD128Q_2_LMKCDEY_OR, STD128Q_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
126126
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD128Q_3_LMKCDEY_OR, STD128Q_3_LMKCDEY, LMKCDEY, OR3)->Unit(benchmark::kMillisecond)->MinTime(5.0);
127-
#if NATIVEINT >= 64
128127
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD128Q_4_LMKCDEY_OR, STD128Q_4_LMKCDEY, LMKCDEY, OR4)->Unit(benchmark::kMillisecond)->MinTime(5.0);
128+
#if NATIVEINT >= 64
129129
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD192_2_LMKCDEY_OR, STD192_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
130130
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD192_3_LMKCDEY_OR, STD192_3_LMKCDEY, LMKCDEY, OR3)->Unit(benchmark::kMillisecond)->MinTime(5.0);
131131
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD192_4_LMKCDEY_OR, STD192_4_LMKCDEY, LMKCDEY, OR4)->Unit(benchmark::kMillisecond)->MinTime(5.0);
@@ -135,10 +135,10 @@ BENCHMARK_CAPTURE(FHEW_BINGATE4, STD192Q_4_LMKCDEY_OR, STD192Q_4_LMKCDEY, LMKCDE
135135
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD256_2_LMKCDEY_OR, STD256_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
136136
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD256_3_LMKCDEY_OR, STD256_3_LMKCDEY, LMKCDEY, OR3)->Unit(benchmark::kMillisecond)->MinTime(5.0);
137137
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD256_4_LMKCDEY_OR, STD256_4_LMKCDEY, LMKCDEY, OR4)->Unit(benchmark::kMillisecond)->MinTime(5.0);
138+
#endif
138139
BENCHMARK_CAPTURE(FHEW_BINGATE2, STD256Q_2_LMKCDEY_OR, STD256Q_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
139140
BENCHMARK_CAPTURE(FHEW_BINGATE3, STD256Q_3_LMKCDEY_OR, STD256Q_3_LMKCDEY, LMKCDEY, OR3)->Unit(benchmark::kMillisecond)->MinTime(5.0);
140141
BENCHMARK_CAPTURE(FHEW_BINGATE4, STD256Q_4_LMKCDEY_OR, STD256Q_4_LMKCDEY, LMKCDEY, OR4)->Unit(benchmark::kMillisecond)->MinTime(5.0);
141-
#endif
142142
BENCHMARK_CAPTURE(FHEW_BINGATE2, LPF_STD128_2_GINX_OR, LPF_STD128, GINX, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
143143
BENCHMARK_CAPTURE(FHEW_BINGATE2, LPF_STD128Q_2_GINX_OR, LPF_STD128Q, GINX, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
144144
BENCHMARK_CAPTURE(FHEW_BINGATE2, LPF_STD128_2_LMKCDEY_OR, LPF_STD128_LMKCDEY, LMKCDEY, OR)->Unit(benchmark::kMillisecond)->MinTime(5.0);
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
//==================================================================================
2+
// BSD 2-Clause License
3+
//
4+
// Copyright (c) 2014-2025, 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 "config_core.h"
34+
#include "cryptocontext.h"
35+
#include "gen-cryptocontext.h"
36+
#include "gtest/gtest.h"
37+
#include "scheme/ckksrns/ckksrns-fhe.h"
38+
#include "scheme/ckksrns/ckksrns-utils.h"
39+
#include "scheme/ckksrns/gen-cryptocontext-ckksrns.h"
40+
41+
#include <vector>
42+
43+
using namespace lbcrypto;
44+
45+
struct boot_config {
46+
uint32_t ringDim;
47+
uint32_t slots;
48+
uint32_t dcrtBits;
49+
uint32_t firstMod;
50+
uint32_t numDigits;
51+
uint32_t lvlsAfter;
52+
uint32_t iters;
53+
std::vector<uint32_t> lvlb;
54+
SecretKeyDist skdst;
55+
ScalingTechnique stech;
56+
};
57+
58+
// clang-format off
59+
[[maybe_unused]] std::vector<boot_config> boot_configs = {
60+
// ringDm, slots, dcrtBits, firstMod, numDigits, lvlsAfter, iters, lvlb, skdst, stech
61+
{ 1 << 16, 1 << 15, 54, 60, 15, 9, 1, {3, 3}, UNIFORM_TERNARY, FLEXIBLEAUTO},
62+
{ 1 << 16, 1 << 15, 50, 57, 11, 9, 2, {3, 3}, UNIFORM_TERNARY, FLEXIBLEAUTO},
63+
{ 1 << 16, 1 << 15, 50, 57, 16, 10, 2, {3, 3}, UNIFORM_TERNARY, FLEXIBLEAUTO},
64+
{ 1 << 16, 1 << 15, 52, 57, 10, 8, 2, {3, 3}, UNIFORM_TERNARY, FIXEDMANUAL},
65+
{ 1 << 16, 1 << 15, 52, 57, 16, 9, 2, {3, 3}, UNIFORM_TERNARY, FIXEDMANUAL},
66+
{ 1 << 17, 1 << 16, 59, 60, 0, 5, 1, {4, 4}, SPARSE_TERNARY, FLEXIBLEAUTO},
67+
{ 1 << 17, 1 << 16, 59, 60, 0, 5, 1, {4, 4}, SPARSE_ENCAPSULATED, FLEXIBLEAUTO},
68+
{ 1 << 16, 1 << 5, 59, 60, 0, 5, 1, {1, 1}, SPARSE_TERNARY, FLEXIBLEAUTO},
69+
{ 1 << 16, 1 << 5, 59, 60, 0, 5, 1, {1, 1}, SPARSE_ENCAPSULATED, FLEXIBLEAUTO},
70+
{ 1 << 17, 1 << 5, 59, 60, 0, 5, 1, {1, 1}, SPARSE_TERNARY, FLEXIBLEAUTO},
71+
{ 1 << 17, 1 << 5, 59, 60, 0, 5, 1, {1, 1}, SPARSE_ENCAPSULATED, FLEXIBLEAUTO},
72+
{ 1 << 17, 1 << 16, 59, 60, 0, 10, 1, {4, 4}, SPARSE_ENCAPSULATED, FLEXIBLEAUTO},
73+
{ 1 << 17, 1 << 5, 59, 60, 0, 10, 1, {1, 1}, SPARSE_ENCAPSULATED, FLEXIBLEAUTO},
74+
{ 1 << 17, 1 << 16, 59, 60, 0, 10, 2, {4, 4}, SPARSE_ENCAPSULATED, FLEXIBLEAUTO},
75+
{ 1 << 17, 1 << 5, 59, 60, 0, 10, 2, {1, 1}, SPARSE_ENCAPSULATED, FLEXIBLEAUTO},
76+
// TODO: enable following once STC Composite Scaling operational
77+
// { 1 << 17, 1 << 16, 78, 96, 0, 10, 2, {4, 4}, SPARSE_TERNARY, COMPOSITESCALINGAUTO},
78+
};
79+
// clang-format on
80+
81+
[[maybe_unused]] static void BootConfigs(benchmark::internal::Benchmark* b) {
82+
for (uint32_t i = 0; i < boot_configs.size(); ++i)
83+
b->ArgName("Config")->Arg(i);
84+
}
85+
86+
[[maybe_unused]] static void CKKSBoot(benchmark::State& state) {
87+
auto t = boot_configs[state.range(0)];
88+
89+
CCParams<CryptoContextCKKSRNS> parameters;
90+
parameters.SetSecurityLevel(HEStd_128_classic);
91+
parameters.SetRingDim(t.ringDim);
92+
parameters.SetScalingModSize(t.dcrtBits);
93+
parameters.SetFirstModSize(t.firstMod);
94+
parameters.SetNumLargeDigits(t.numDigits);
95+
parameters.SetSecretKeyDist(t.skdst);
96+
parameters.SetScalingTechnique(t.stech);
97+
parameters.SetKeySwitchTechnique(HYBRID);
98+
uint32_t depth = t.lvlsAfter + FHECKKSRNS::GetBootstrapDepth(t.lvlb, t.skdst) + (t.iters - 1);
99+
parameters.SetMultiplicativeDepth(depth);
100+
101+
auto cc = GenCryptoContext(parameters);
102+
cc->Enable(PKE);
103+
cc->Enable(KEYSWITCH);
104+
cc->Enable(LEVELEDSHE);
105+
cc->Enable(ADVANCEDSHE);
106+
cc->Enable(FHE);
107+
108+
cc->EvalBootstrapSetup(t.lvlb, {0, 0}, t.slots);
109+
110+
auto keyPair = cc->KeyGen();
111+
cc->EvalMultKeyGen(keyPair.secretKey);
112+
cc->EvalBootstrapKeyGen(keyPair.secretKey, t.slots);
113+
114+
std::vector<double> x = {0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0};
115+
116+
auto ptxt = cc->MakeCKKSPackedPlaintext(x, 1, depth - 1, nullptr, t.slots);
117+
ptxt->SetLength(t.slots);
118+
119+
auto ctxt = cc->Encrypt(keyPair.publicKey, ptxt);
120+
121+
while (state.KeepRunning())
122+
auto ctxtAfter = cc->EvalBootstrap(ctxt, t.iters);
123+
124+
cc->ClearStaticMapsAndVectors();
125+
}
126+
127+
[[maybe_unused]] static void CKKSBootStC(benchmark::State& state) {
128+
auto t = boot_configs[state.range(0)];
129+
130+
CCParams<CryptoContextCKKSRNS> parameters;
131+
parameters.SetSecurityLevel(HEStd_128_classic);
132+
parameters.SetRingDim(t.ringDim);
133+
parameters.SetScalingModSize(t.dcrtBits);
134+
parameters.SetFirstModSize(t.firstMod);
135+
parameters.SetNumLargeDigits(t.numDigits);
136+
parameters.SetSecretKeyDist(t.skdst);
137+
parameters.SetScalingTechnique(t.stech);
138+
parameters.SetKeySwitchTechnique(HYBRID);
139+
uint32_t depth = t.lvlsAfter + FHECKKSRNS::GetBootstrapDepth(t.lvlb, t.skdst) + (t.iters - 1);
140+
parameters.SetMultiplicativeDepth(depth);
141+
142+
auto cc = GenCryptoContext(parameters);
143+
cc->Enable(PKE);
144+
cc->Enable(KEYSWITCH);
145+
cc->Enable(LEVELEDSHE);
146+
cc->Enable(ADVANCEDSHE);
147+
cc->Enable(FHE);
148+
149+
cc->EvalBootstrapSetup(t.lvlb, {0, 0}, t.slots, 0, true, true);
150+
151+
auto keyPair = cc->KeyGen();
152+
cc->EvalMultKeyGen(keyPair.secretKey);
153+
cc->EvalBootstrapKeyGen(keyPair.secretKey, t.slots);
154+
155+
std::vector<double> x = {0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0};
156+
157+
auto ptxt = cc->MakeCKKSPackedPlaintext(x, 1, depth - 1 - t.lvlb[1], nullptr, t.slots);
158+
ptxt->SetLength(t.slots);
159+
160+
auto ctxt = cc->Encrypt(keyPair.publicKey, ptxt);
161+
162+
while (state.KeepRunning())
163+
auto ctxtAfter = cc->EvalBootstrap(ctxt, t.iters);
164+
165+
cc->ClearStaticMapsAndVectors();
166+
}
167+
168+
BENCHMARK(CKKSBoot)->Unit(benchmark::kSecond)->Iterations(4)->Apply(BootConfigs);
169+
BENCHMARK(CKKSBootStC)->Unit(benchmark::kSecond)->Iterations(4)->Apply(BootConfigs);
170+
171+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)