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.15k stars 763 forks source link

Extracting Ctxts from a packed Ctxt #257

Closed mikespittal closed 6 years ago

mikespittal commented 6 years ago

I have a range of l-bits (mod 2) packed into a single Ctxt using the encrypted array (ea), that represents an l-bit integer.

Is there any way I can 'get' the Ctxt that encrypts the MSB of that l-bit integer? (converting a packed cipher text into a set of unpacked cipher texts)

Any help will be really appreciated!!

shaih commented 6 years ago

Yes, you can use the replication interfaces of HElib for that purpose.

//! @brief The value in slot #pos is replicated in all other slots.
//! On an n-slot ciphertext, this algorithm performs O(log n) 1D rotations.  
void replicate(const EncryptedArray& ea, Ctxt& ctx, long pos);

This returns in ctx an encryption of the same bit in all the slots (which, I'm pretty sure, means that decrypting it will give you a polynomial which is just 0 or 1).

That said, unpacking is usually an inefficient way of computing stuff. It is very likely that there are faster ways of achieving whatever it is your application calls for. You can take a look at the HElib interfaces for linear transformations (matmul), permutations, binary arithmetic, etc.