-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HElib 1.2.0, November 2020 ========================= (tagged as v1.2.0) October-November 2020 --------------------- * Mitigation for potential CKKS vulnerability. * Additional API changes for parameters to the CKKS encoding functions. * New infrastructure for benchmarks * Updated ClonedPtr * Additional Ctxt tests * Bug Fixes: Co-Authored-by: Flavio Bergamaschi anadyomeni@gmx.com Co-authored-by: Jack Crawford jack.crawford@sky.com Co-Authored-by: Shai Halevi shaih@alum.mit.edu Co-authored-by: Hamish Hunt hamishun@gmail.com Co-authored-by: Victor Shoup shoup@cs.nyu.edu Co-authored-by: Enrico Steffinlongo enrylongo@gmail.com
- Loading branch information
Showing
53 changed files
with
2,522 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* Copyright (C) 2020 IBM Corp. | ||
* This program is Licensed under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. See accompanying LICENSE file. | ||
*/ | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <iostream> | ||
|
||
#include <helib/helib.h> | ||
|
||
#include "bgv_common.h" | ||
|
||
namespace { | ||
|
||
static void adding_two_ciphertexts(benchmark::State& state, Meta& meta) | ||
{ | ||
helib::Ptxt<helib::BGV> ptxt1(meta.data->context); | ||
helib::Ptxt<helib::BGV> ptxt2(meta.data->context); | ||
|
||
ptxt1.random(); | ||
ptxt2.random(); | ||
|
||
helib::Ctxt ctxt1(meta.data->publicKey); | ||
helib::Ctxt ctxt2(meta.data->publicKey); | ||
|
||
meta.data->publicKey.Encrypt(ctxt1, ptxt1); | ||
meta.data->publicKey.Encrypt(ctxt2, ptxt1); | ||
// Benchmark adding ciphertexts | ||
for (auto _ : state) | ||
ctxt1 += ctxt2; | ||
std::cout << "Additions performed = " << state.iterations() << std::endl; | ||
} | ||
|
||
static void multiplying_two_ciphertexts(benchmark::State& state, Meta& meta) | ||
{ | ||
helib::Ptxt<helib::BGV> ptxt1(meta.data->context); | ||
helib::Ptxt<helib::BGV> ptxt2(meta.data->context); | ||
|
||
ptxt1.random(); | ||
ptxt2.random(); | ||
|
||
helib::Ctxt ctxt1(meta.data->publicKey); | ||
helib::Ctxt ctxt2(meta.data->publicKey); | ||
|
||
meta.data->publicKey.Encrypt(ctxt1, ptxt1); | ||
meta.data->publicKey.Encrypt(ctxt2, ptxt2); | ||
// Benchmark adding ciphertexts | ||
for (auto _ : state) | ||
ctxt1.multiplyBy(ctxt2); | ||
std::cout << "Multiplications performed = " << state.iterations() | ||
<< std::endl; | ||
} | ||
|
||
static void encrypting_ciphertexts(benchmark::State& state, Meta& meta) | ||
{ | ||
helib::Ptxt<helib::BGV> ptxt(meta.data->context); | ||
ptxt.random(); | ||
|
||
helib::Ctxt ctxt(meta.data->publicKey); | ||
|
||
// Benchmark encrypting ciphertexts | ||
for (auto _ : state) | ||
meta.data->publicKey.Encrypt(ctxt, ptxt); | ||
std::cout << "Encryptions performed = " << state.iterations() << std::endl; | ||
} | ||
|
||
static void decrypting_ciphertexts(benchmark::State& state, Meta& meta) | ||
{ | ||
helib::Ptxt<helib::BGV> ptxt(meta.data->context); | ||
ptxt.random(); | ||
|
||
helib::Ctxt ctxt(meta.data->publicKey); | ||
|
||
meta.data->publicKey.Encrypt(ctxt, ptxt); | ||
helib::Ptxt<helib::BGV> decrypted_result(meta.data->context); | ||
|
||
// Benchmark decrypting ciphertexts | ||
for (auto _ : state) | ||
meta.data->secretKey.Decrypt(decrypted_result, ctxt); | ||
std::cout << "Decryptions performed = " << state.iterations() << std::endl; | ||
} | ||
|
||
Meta fn; | ||
Params tiny_params(/*m=*/257, /*p=*/2, /*r=*/1, /*L=*/5800); | ||
BENCHMARK_CAPTURE(adding_two_ciphertexts, tiny_params, fn(tiny_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->Iterations(200); | ||
BENCHMARK_CAPTURE(multiplying_two_ciphertexts, tiny_params, fn(tiny_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->Iterations(200); | ||
BENCHMARK_CAPTURE(encrypting_ciphertexts, tiny_params, fn(tiny_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->Iterations(200); | ||
BENCHMARK_CAPTURE(decrypting_ciphertexts, tiny_params, fn(tiny_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->Iterations(200); | ||
|
||
Params small_params(/*m=*/8009, /*p=*/2, /*r=*/1, /*L=*/5800); | ||
BENCHMARK_CAPTURE(adding_two_ciphertexts, small_params, fn(small_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->Iterations(200); | ||
BENCHMARK_CAPTURE(multiplying_two_ciphertexts, small_params, fn(small_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->MinTime(200); | ||
BENCHMARK_CAPTURE(encrypting_ciphertexts, small_params, fn(small_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->Iterations(200); | ||
BENCHMARK_CAPTURE(decrypting_ciphertexts, small_params, fn(small_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->Iterations(200); | ||
|
||
Params big_params(/*m=*/32003, /*p=*/2, /*r=*/1, /*L=*/5800); | ||
BENCHMARK_CAPTURE(adding_two_ciphertexts, big_params, fn(big_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->Iterations(200); | ||
BENCHMARK_CAPTURE(multiplying_two_ciphertexts, big_params, fn(big_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->MinTime(200); | ||
BENCHMARK_CAPTURE(encrypting_ciphertexts, big_params, fn(big_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->MinTime(200); | ||
BENCHMARK_CAPTURE(decrypting_ciphertexts, big_params, fn(big_params)) | ||
->Unit(benchmark::kMillisecond) | ||
->MinTime(200); | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* Copyright (C) 2020 IBM Corp. | ||
* This program is Licensed under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. See accompanying LICENSE file. | ||
*/ | ||
|
||
#include <memory> | ||
|
||
#include <helib/helib.h> | ||
|
||
struct Params | ||
{ | ||
const long m, p, r, L; | ||
const std::vector<long> gens; | ||
const std::vector<long> ords; | ||
Params(long _m, | ||
long _p, | ||
long _r, | ||
long _L, | ||
const std::vector<long>& _gens = {}, | ||
const std::vector<long>& _ords = {}) : | ||
m(_m), p(_p), r(_r), L(_L), gens(_gens), ords(_ords) | ||
{} | ||
Params(const Params& other) : | ||
Params(other.m, other.p, other.r, other.L, other.gens, other.ords) | ||
{} | ||
bool operator!=(Params& other) const { return !(*this == other); } | ||
bool operator==(Params& other) const | ||
{ | ||
return m == other.m && p == other.p && r == other.r && L == other.L && | ||
gens == other.gens && ords == other.ords; | ||
} | ||
}; | ||
|
||
struct ContextAndKeys | ||
{ | ||
const Params params; | ||
|
||
helib::Context context; | ||
helib::SecKey secretKey; | ||
const helib::PubKey publicKey; | ||
const helib::EncryptedArray& ea; | ||
|
||
ContextAndKeys(Params& _params) : | ||
params(_params), | ||
context(params.m, params.p, params.r, params.gens, params.ords), | ||
secretKey((helib::buildModChain(context, params.L, /*c=*/2), context)), | ||
publicKey((secretKey.GenSecKey(), | ||
helib::addSome1DMatrices(secretKey), | ||
secretKey)), | ||
ea(*(context.ea)) | ||
{ | ||
context.printout(); | ||
} | ||
}; | ||
|
||
struct Meta | ||
{ | ||
std::unique_ptr<ContextAndKeys> data; | ||
Meta& operator()(Params& params) | ||
{ | ||
// Only change if nullptr or different. | ||
if (data == nullptr || data->params != params) | ||
data = std::make_unique<ContextAndKeys>(params); | ||
return *this; | ||
} | ||
}; |
Oops, something went wrong.