Lab41 / PySEAL

This repository is a fork of Microsoft Research's homomorphic encryption implementation, the Simple Encrypted Arithmetic Library (SEAL). This code wraps the SEAL build in a docker container and provides Python API's to the encryption library.
Other
226 stars 86 forks source link

Make PySeal Pickleable #16

Closed nilslukas closed 6 years ago

nilslukas commented 6 years ago

Ciphertext and Plaintext modules are not pickleable. Would be great if that worked +1: (Can't use pickle to serialize objects. Could be used for multithreading)

cem-ozturk commented 6 years ago

Hi @NilsHendrikLukas , did you find any alternative solution to pickle or anyway to save the ciphertext objects to a file?

toddstavish commented 6 years ago

PySEAL has native dependencies, subsequently it may be unpickleable.

On Fri, Jun 29, 2018 at 8:34 AM, c3m0zturk notifications@github.com wrote:

Hi @NilsHendrikLukas https://github.com/NilsHendrikLukas , did you find any alternative solution to pickle or anyway to save the ciphertext objects to a file?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Lab41/PySEAL/issues/16#issuecomment-401340810, or mute the thread https://github.com/notifications/unsubscribe-auth/AARCxmCCn3SjtRnzGBvbvV6J_A_CTx-Rks5uBh7AgaJpZM4TGhL6 .

nilslukas commented 6 years ago

@c3m0zturk Saving the ciphertext object to a file shouldn't be a problem. SEAL already provides a 'save' and 'load' function that take streams as parameters. I couldn't get python streams to work, but the easiest workaround would probably be to add an extra function which creates an ostream to a file and embed it into SEAL/ciphertext.cpp:

#include <fstream>
[..]
 void Ciphertext::save_to_file() const
    {
        ofstream outfile("ciphertext.bin", std::ofstream::binary);
        save(outfile);
        outfile.close();
    }

Then in SEAL/ciphertext.h add a function header

void save_to_file() const;

and in SEALPython/wrapper.cpp add the following line

py::class_<Ciphertext>(m, "Ciphertext")
    .def(py::init<>())
    [...] /* all other definitions */
    .def("save_to_file", (void (Ciphertext::*)()) &Ciphertext::save_to_file, "Saves ciphertext to file")
adityachivu commented 6 years ago

@NilsHendrikLukas Thanks for the update! @c3m0zturk and I used a similar workaround by writing a new function that takes string input for file path. We included save/load for PublicKey and SecretKey as well.

@toddstavish I have made these changes on my fork. Does it make sense to submit a PR?

toddstavish commented 6 years ago

Yes, a PR would be happily received. Sorry for missing this in the original port. I designed this set up and an extremely talented intern finished it up. Thought we had covered all of the major functions.

On Tue, Jul 17, 2018 at 3:01 AM Aditya Chivukula notifications@github.com wrote:

@NilsHendrikLukas https://github.com/NilsHendrikLukas Thanks for the update! @c3m0zturk https://github.com/c3m0zturk and I used a similar workaround by writing a new function that takes string input for file path. We included save/load for PublicKey and SecretKey as well.

@toddstavish https://github.com/toddstavish I have made these changes on my fork. Does it make sense to submit a PR?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Lab41/PySEAL/issues/16#issuecomment-405528871, or mute the thread https://github.com/notifications/unsubscribe-auth/AARCxlmHrz7ZugMrhuiSZ_5xsVK4qJdJks5uHbXsgaJpZM4TGhL6 .

nilslukas commented 6 years ago

@toddstavish I also made a PR to add Pickle serialization. It does not conflict with any native dependencies, thus it should be platform independent. I think this feature is quite important, because now with Pythons multiprocessing library one can get linear speedups depending on the number of cores (limited by the number of used plaintext moduli ofc).