diff --git a/bin/ckks.o b/bin/ckks.o index f3e2ce74b322285685d2a403fc6cef174094f9c0..eea74b8fe3a4d9aabe4ec020ca887b674612099a 100644 Binary files a/bin/ckks.o and b/bin/ckks.o differ diff --git a/bin/evalkey.o b/bin/evalkey.o index e6440f8b4c2062a013146f0e44ba409475399f18..074e988607447c5f791d73b2cc816999c28e98ab 100644 Binary files a/bin/evalkey.o and b/bin/evalkey.o differ diff --git a/bin/polynomial.o b/bin/polynomial.o index 85c713ba9381c4b08f003d14563c751776a81b7d..98458cd5468e8305bf6916295bfc62c8605de048 100644 Binary files a/bin/polynomial.o and b/bin/polynomial.o differ diff --git a/bin/pubkey.o b/bin/pubkey.o index ed114a7969e2488aa3e90825a8f52ae3a0452ab3..deacc305c00ea25f96ee5f79ffbfd14374b63887 100644 Binary files a/bin/pubkey.o and b/bin/pubkey.o differ diff --git a/run b/run index d630e8fb57da53d34b4b5ac06d8fe066fb4675c9..b4f07aa828b550f23c6d96b2287e1cd1ec7e1f57 100755 Binary files a/run and b/run differ diff --git a/src/ckks.cpp b/src/ckks.cpp index 12725cea556a7c4ff38a9e84537faee20bd8d200..8530b2b2c4a75660cfd94ef7d5bbc425c7bcb05e 100644 --- a/src/ckks.cpp +++ b/src/ckks.cpp @@ -78,7 +78,21 @@ Ciphertext CKKS::mult(Ciphertext ct1, Ciphertext ct2){ Polynomial d3_1 = (d3 * evk.a).scaleRoundCoeff(1.0/1000.0); Polynomial outC0 = d1.modCoeff(ql) + d3_0.modCoeff(ql); + // cout << "d0': " ; + // outC0.printPol(); + Polynomial outC1 = d2.modCoeff(ql) + d3_1.modCoeff(ql); + // cout << "d1'*s: "; + // (outC1*sk.s).printPol(); + + Polynomial test = outC0 + (outC1 * sk.s); + cout << "d0' + d1'*s: "; + (test.modCoeff(ql)).printPol(); + cout << endl; + + Polynomial test2 = d1 + (d2*sk.s) + (d3 * sk.s*sk.s); + cout << "d0 + d1*s + d2*s^2: "; + (test2.modCoeff(ql)).printPol(); // Rescale ql = (double)ql / (double)pl[level-1]; diff --git a/src/evalkey.cpp b/src/evalkey.cpp index 7715cf188d918b491829f427e384de11e0c31669..ab390c58c8c634932541f781e6db39481a9a1c3f 100644 --- a/src/evalkey.cpp +++ b/src/evalkey.cpp @@ -9,10 +9,10 @@ using namespace std; EvalKey::EvalKey(Polynomial _s, int q){ a = Polynomial(4); b = Polynomial(4); - p = 1000; + p = 10000; s = _s; cout << q << endl; - generateA(4, q); + generateA(4, 4); computeB(q); } @@ -30,10 +30,11 @@ void EvalKey::generateA(int degree, int q){ } void EvalKey::computeB(int q){ + cout << "eval" << endl; double e[4] = {0.0, 0.0, 0.0, 0.0}; Polynomial err(4, e); Polynomial ev = (s * s).scaleCoeff(p); - Polynomial temp = (a.scaleCoeff(-1.0)) * s + err + ev; + Polynomial temp = ((a.scaleCoeff(-1.0)) * s) + ev; Polynomial res = temp.modCoeff(q * p); b.setDegree(res.degree); diff --git a/src/polynomial.cpp b/src/polynomial.cpp index 9389ddb75288cc0da9c91610bb5e8b1484c2c0fa..1e0520f78a99ed79db179c7c27580e7e56127564 100644 --- a/src/polynomial.cpp +++ b/src/polynomial.cpp @@ -69,6 +69,9 @@ Polynomial Polynomial::dot (Polynomial const &obj){ Polynomial Polynomial::operator + (Polynomial const &obj){ int deg = max(obj.degree, degree); double coeff[deg]; + for (int i = 0; i<deg; i++){ + coeff[i] = 0; + } for(int i=0; i<deg; i++){ coeff[i] = coeffs[i] + obj.coeffs[i]; } @@ -80,6 +83,10 @@ Polynomial Polynomial::operator + (Polynomial const &obj){ Polynomial Polynomial::operator * (Polynomial const &obj){ int deg = degree + obj.degree -1; double coeff[deg]; + for (int i = 0; i<deg; i++){ + coeff[i] = 0; + } + for(int i=0; i<degree; i++){ for(int j=0; j<obj.degree; j++){ coeff[i+j] += coeffs[i] * obj.coeffs[j]; diff --git a/src/pubkey.cpp b/src/pubkey.cpp index 8472f7c60b0a15c3f6b68b60963cfd9b4d0378e5..7835cf26ca0065cfa0475503c899a0da12921b50 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -11,7 +11,7 @@ PubKey::PubKey(Polynomial _s, int q){ b = Polynomial(4); s = _s; - generateA(4, q); + generateA(4, 4); computeB(q); } diff --git a/test.cpp b/test.cpp index 0e2dcafe35ad877272b266bbb5d0e5709126ee3f..56f1a4ea38f9f9ecd3e4ad9d48602cf299ab10b7 100644 --- a/test.cpp +++ b/test.cpp @@ -39,7 +39,7 @@ int main(){ // } // cout << endl; Polynomial ptOut = ckks.decrypt(ctadd); - + dcomparr output = enc.decode(ptOut); for(int i=0; i<4; i++){ cout << output.arr[i]/64.0 << " ";