From 39389f046622b4af107e87b5380c2349517dbb7b Mon Sep 17 00:00:00 2001 From: rtalbi <dr_talbi@esi.dz> Date: Thu, 4 Apr 2019 18:44:46 +0200 Subject: [PATCH] Added dot product test --- CONFIG/DAPPLE.config | 2 +- CRYPTO/EvalDotProd.h | 2 +- TEST/TESTBuildingBlocks.cpp | 14 ++++++++++++++ TEST/TESTBuildingBlocks.h | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CONFIG/DAPPLE.config b/CONFIG/DAPPLE.config index 137abc78..d57291a1 100755 --- a/CONFIG/DAPPLE.config +++ b/CONFIG/DAPPLE.config @@ -1,6 +1,6 @@ # Experiments parameters perf{ - testBuildingBlocks="false"; + testBuildingBlocks="true"; PrivacyPreservation="false"; MLAlgorithm="lr"; runs_number ="30"; diff --git a/CRYPTO/EvalDotProd.h b/CRYPTO/EvalDotProd.h index 3477dfc8..9d1ffca2 100755 --- a/CRYPTO/EvalDotProd.h +++ b/CRYPTO/EvalDotProd.h @@ -1,5 +1,5 @@ #ifndef DAPPLE_EVALDOTPROD_H -#define DAPPLE_EVALDOTPROD__H +#define DAPPLE_EVALDOTPROD_H #include "DTPKC.h" // Header of the DTPKC cryptosystem's class diff --git a/TEST/TESTBuildingBlocks.cpp b/TEST/TESTBuildingBlocks.cpp index 85df97c1..27e4e528 100755 --- a/TEST/TESTBuildingBlocks.cpp +++ b/TEST/TESTBuildingBlocks.cpp @@ -580,12 +580,14 @@ void TESTBuildingBlocks::run (bool deserialize, int keysize, int prec, int error vector<Cipher> C_av, C_bv, C_cv; mpz_class output =0; + mpz_class output2 =0; for(int i=0; i < 8; i++) { C_av.push_back(dtpkc.enc(av[i],dtpkc.pkw)); C_bv.push_back(dtpkc.enc(bv[i],dtpkc.pkw)); C_cv.push_back(dtpkc.enc(cv[i],dtpkc.pkw)); output = output + alpha2 * (av[i]-bv[i])*cv[i]; + output2 = output2 + cv[i]*bv[i]; } EvalLrUpdate evalLrUpdate(C_av, C_bv, C_cv ,alpha, dtpkc); @@ -598,6 +600,18 @@ void TESTBuildingBlocks::run (bool deserialize, int keysize, int prec, int error if (abs(int(output.get_ui()- C.get_ui())) > 3 ) cptF++; cout<<"Test(" << cpt << ") <<LRupdate> gave : " << C.get_str() << " expected result " << output << " state :" << state << endl; + + + EvalDotProd evalDotProd(C_cv, C_bv , C_bv.size(), dtpkc); + C_C = evalDotProd.EvalDotProd_U1_step3(evalDotProd.EvalDotProd_U2_step2(evalDotProd.EvalDotProd_U1_step1())); + C = dtpkc.Sdec(C_C); + if ( dtpkc.n - C < 10000000000000 ) C= 0 - (dtpkc.n - dtpkc.Sdec(C_C)); + else + state = (abs(int(output2.get_ui()- C.get_ui())) < 3 ) ? " passed":" failed"; + + if (abs(int(output2.get_ui()- C.get_ui())) > 3 ) cptF++; + + cout<<"Test(" << cpt << ") <<Dot Product> gave : " << C.get_str() << " expected result " << output2 << " state :" << state << endl; //cout << dtpkc.n << endl; /** diff --git a/TEST/TESTBuildingBlocks.h b/TEST/TESTBuildingBlocks.h index c058b167..66e75658 100755 --- a/TEST/TESTBuildingBlocks.h +++ b/TEST/TESTBuildingBlocks.h @@ -13,7 +13,7 @@ #include "../CRYPTO/EvalAddPow2.h" #include "../CRYPTO/EvalStandardDiv.h" #include "../CRYPTO/EvalSigmoid.h" - +#include "../CRYPTO/EvalDotProd.h" #include "../UTIL/mpz_class.hh" #include "../UTIL/num_th_alg.hh" -- GitLab