homenc / HElib

HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
https://homenc.github.io/HElib
Other
3.11k stars 760 forks source link

Victor new encoding api #393

Closed victorshoup closed 3 years ago

victorshoup commented 3 years ago

In addition to adding new encoding APIs (see the new EncodedPtxt class and related class, the new PtxtArray class, and various methods added to EncryptedArray), below is a list of other changes that I made along the way.

This is a big PR...I was hoping there would not be conflicts, which is why I asked to minimize changes to the master branch....oh well...we'll have to sort it out.

I also realize that doing a PR on Homenc is probably not the correct thing to do according to our new workflow. I don't really understand the current workflow, to be honest. If you need me to do something else, let me know.

NumbTh: new functions RandomReal and RandomComplex

EncryptedArray.cpp: line 429, replaced call to convert to balanced_zzX

NumbTh.h:

EncryptedArray.h: deleted operator= for the EncryptedArray class PAlgebra.h: deleted operator= for the PAlgebraMod and PAlebra classes Context.h: deleted operator= for the Context class

EncryptedArray.h: got rid of unnecessary convert routines covered by new base cases in NumbTh.h, and renamed remaining ones to project and project_and_round. We could have added new convert base cases in NumbTh.h, but these are lossy conversions, so it did not seem like a good idea.

Ctxt.cpp: a couple of places ptxtSpace was updated without updating intFactor. Resolved by invoking reducePtxtSpace.

Ctxt.cpp: fixed some bugs and simplified semantics of Ctxt::addPart so that the primeSet of the ctxt does not change. This required changing some logic in the relinearization code to ensure that the temporary Ctxt is initially constructed with the right prime set

DoubleCRT.h: added DoubleCRT constructors of the form DoubleCRT(num, context, indexSet), where num is a ZZ or long. This is convenient, and makes the operator= and constructors more consistent.

NumbTh.h: changed default parameter for convert(Vec,Vec) so that the default is symmetric=false. The original default was very counter-intuitive and inconsidtent with other convert operators. The only remaining calls to this were in zzX.cpp.

Ctxt.h: fixed bugs in multByConstantCKKS. This also necessitated a change in TestCKKS.

EncryptedArray.h: added convenenice functions rotate(Ctxt,k), shift(Ctxt,k), rotate1D(Ctxt,i,k), shift1D(Ctxt,i,k)

matmul.{h,cpp}: moved CKKS matmul to the new encoding APIs, added PtxtArray support for CKKS, added convenience classes MatMul_CKKS and EncodedMatMul_CKKS to make it much easier to initialize a CKKS matrix descriptor. Also added *= functions for both PtxtArray and Ctxt classes. Also made PtxtArray functions work for CKKS as well.

replicate.{h,cpp}: replaced ZZX/DoubleCRT encodings by [Fat]EncodedPtxt. This means that the code should work as is for CKKS (need to write some unit tests).

EaCx.cpp: implemented shift1D and shift for CKKS

permutations.{h,cpp}: updated permutation code to support CKKS along with BGV. Also added convenience class PermIndepPrecomp and PermPrecomp to simlify usage.

shaih commented 3 years ago

Closed this pull request for now, pending more tests and resolving conflicts