From 56b7db0f8e05e7db283a8580d63d5fc20a0e7cab Mon Sep 17 00:00:00 2001 From: nindanaoto Date: Sun, 27 Mar 2022 16:22:32 +0900 Subject: [PATCH] Added trgswenc to benchmark --- benchmark/bench.cpp | 56 ++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/benchmark/bench.cpp b/benchmark/bench.cpp index aff7445..d8504f0 100644 --- a/benchmark/bench.cpp +++ b/benchmark/bench.cpp @@ -4,13 +4,22 @@ #include "../include/tfhe++.hpp" #include "google-benchmark/include/benchmark/benchmark.h" +void BM_TRGSWenc(benchmark::State& state) +{ + const std::unique_ptr sk(new TFHEpp::SecretKey()); + TFHEpp::TRGSWFFT res; + for (auto _ : state) res=TFHEpp::trgswfftSymEncrypt({}, TFHEpp::lvl1param::α, sk->key.lvl1);; +} + void BM_HomGate(benchmark::State& state) { std::random_device seed_gen; std::default_random_engine engine(seed_gen()); std::uniform_int_distribution binary(0, 1); const std::unique_ptr sk(new TFHEpp::SecretKey()); - const std::unique_ptr gk(new TFHEpp::GateKey(*sk)); + TFHEpp::EvalKey ek; + ek.emplacebkfft(*sk); + ek.emplaceiksk(*sk); TFHEpp::TLWE ca = TFHEpp::tlweSymEncrypt( binary(engine), TFHEpp::lvl0param::α, sk->key.lvl0); @@ -18,7 +27,7 @@ void BM_HomGate(benchmark::State& state) TFHEpp::tlweSymEncrypt( binary(engine), TFHEpp::lvl0param::α, sk->key.lvl0); TFHEpp::TLWE res; - for (auto _ : state) TFHEpp::HomNAND(res, ca, cb, *gk); + for (auto _ : state) TFHEpp::HomNAND(res, ca, cb, ek); } void BM_HomMUX(benchmark::State& state) @@ -27,7 +36,9 @@ void BM_HomMUX(benchmark::State& state) std::default_random_engine engine(seed_gen()); std::uniform_int_distribution binary(0, 1); const std::unique_ptr sk(new TFHEpp::SecretKey()); - const std::unique_ptr gk(new TFHEpp::GateKey(*sk)); + TFHEpp::EvalKey ek; + ek.emplacebkfft(*sk); + ek.emplaceiksk(*sk); TFHEpp::TLWE ca = TFHEpp::tlweSymEncrypt( binary(engine), TFHEpp::lvl0param::α, sk->key.lvl0); @@ -38,7 +49,7 @@ void BM_HomMUX(benchmark::State& state) TFHEpp::tlweSymEncrypt( binary(engine), TFHEpp::lvl0param::α, sk->key.lvl0); TFHEpp::TLWE res; - for (auto _ : state) TFHEpp::HomMUX(res, cs, ca, cb, *gk); + for (auto _ : state) TFHEpp::HomMUX(res, cs, ca, cb, ek); } void BM_TLWE2TRLWE(benchmark::State& state) @@ -47,14 +58,15 @@ void BM_TLWE2TRLWE(benchmark::State& state) std::default_random_engine engine(seed_gen()); std::uniform_int_distribution binary(0, 1); const std::unique_ptr sk(new TFHEpp::SecretKey()); - const std::unique_ptr gk(new TFHEpp::GateKey(*sk)); + TFHEpp::EvalKey ek; + ek.emplacebkfft(*sk); TFHEpp::TLWE ca = TFHEpp::tlweSymEncrypt( binary(engine), TFHEpp::lvl0param::α, sk->key.lvl0); TFHEpp::TRLWE res; for (auto _ : state) - TFHEpp::GateBootstrappingTLWE2TRLWEFFT( - res, ca, gk->bkfftlvl01); + TFHEpp::BlindRotate( + res, ca, *ek.bkfftlvl01,TFHEpp::μpolygen()); } void BM_IKS(benchmark::State& state) @@ -63,13 +75,14 @@ void BM_IKS(benchmark::State& state) std::default_random_engine engine(seed_gen()); std::uniform_int_distribution binary(0, 1); const std::unique_ptr sk(new TFHEpp::SecretKey()); - const std::unique_ptr gk(new TFHEpp::GateKey(*sk)); + TFHEpp::EvalKey ek; + ek.emplaceiksk(*sk); TFHEpp::TLWE ca = TFHEpp::tlweSymEncrypt( binary(engine), TFHEpp::lvl1param::α, sk->key.lvl1); TFHEpp::TLWE res; for (auto _ : state) - TFHEpp::IdentityKeySwitch(res, ca, gk->ksk); + TFHEpp::IdentityKeySwitch(res, ca, *ek.iksklvl10); } void BM_SEI(benchmark::State& state) @@ -78,7 +91,6 @@ void BM_SEI(benchmark::State& state) std::default_random_engine engine(seed_gen()); std::uniform_int_distribution binary(0, 1); const std::unique_ptr sk(new TFHEpp::SecretKey()); - const std::unique_ptr gk(new TFHEpp::GateKey(*sk)); std::array pmu; for (int j = 0; j < TFHEpp::lvl1param::n; j++) pmu[j] = binary(engine) ? TFHEpp::lvl1param::μ : -TFHEpp::lvl1param::μ; @@ -142,16 +154,24 @@ void BM_CB(benchmark::State& state) std::default_random_engine engine(seed_gen()); std::uniform_int_distribution binary(0, 1); const std::unique_ptr sk(new TFHEpp::SecretKey()); - const std::unique_ptr< - TFHEpp::CircuitKey> - ck(new TFHEpp::CircuitKey(*sk)); - TFHEpp::TLWE ca = - TFHEpp::tlweSymEncrypt( - binary(engine), TFHEpp::lvl0param::α, sk->key.lvl0); - TFHEpp::TRGSWFFT res; - for (auto _ : state) TFHEpp::CircuitBootstrappingFFT(res, ca, *ck); + TFHEpp::EvalKey ek; + using iksP = TFHEpp::lvl10param; + using bkP = TFHEpp::lvl02param; + using privksP = TFHEpp::lvl21param; + ek.emplaceiksk(*sk); + ek.emplacebkfft(*sk); + ek.emplaceprivksk4cb(*sk); + TFHEpp::TLWE ca = + TFHEpp::tlweSymEncrypt( + binary(engine), TFHEpp::lvl1param::α, sk->key.lvl1); + TFHEpp::TRGSWFFT res; + for (auto _ : state) TFHEpp::CircuitBootstrappingFFT(res, ca, ek); } +BENCHMARK(BM_TRGSWenc) + ->Iterations(1) + ->Repetitions(100) + ->DisplayAggregatesOnly(true); BENCHMARK(BM_HomGate) ->Iterations(1) ->Repetitions(100)