Coder Social home page Coder Social logo

lab41 / pyseal Goto Github PK

View Code? Open in Web Editor NEW
222.0 18.0 85.0 1.32 MB

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.

License: Other

Makefile 0.05% C++ 88.57% M4 0.05% C# 6.40% Python 1.86% Shell 0.01% C 0.02% Dockerfile 0.03% Jupyter Notebook 3.01%

pyseal's Introduction

This repository is a proof of concept for adding a Python wrapper to the (Simple Encrypted Arithmetic Library (SEAL))[http://sealcrypto.org/], a homomorphic encryption library, developed by researchers in the Cryptography Research Group at Microsoft Research. Currently, this uses the version 2.3 codebase and dockerizes the library build (including a shared runtime), C++ example build, and Python wrapper build. The Python wrapper is using pybind11.

To build the wrapped Python version of SEAL, first run the executable build-docker.sh. This creates a seal package that can be imported in Python; to see examples of how to use this package in cryptography tasks, run the executable run-docker.sh (which runs the examples implemented in SEALPythonExamples/examples.py).

When using the SEAL library for basic encryption tasks, the first step is to create a new EncryptionParameters object, and to set its modulus attributes. The polynomial modulus should be set to a power-of-2 cyclotomic polynomial (x^(2^n) + 1 for some n), the coefficient modulus should be set to seal.coeff_modulus_128() (a good int argument is 2048), and the plain modulus can be set to any positive integer (using a power of 2 or a prime would be a good choice).

After creating the EncryptionParameters object, we create a SEALContext object to store our parameters, passing in our encryption parameters as the argument in the constructor for the context; the context, among other things, checks the validity of the parameters.

The last objects to instantiate before we can complete various encryption tasks are:

  • KeyGenerator object (which takes in the context as its constructor argument and generates a public/private key pair as well as evaluation keys).
  • Encryptor object (which takes in the context and the public key as its constructor arguments and encrypts plaintext polynomials).
  • Decryptor object (which takes in the context and the secret key as its constructor arguments and decrypts plaintext polynomials).
  • IntegerEncoder object (which takes in the context's plain modulus as its constructor argument and encodes integers as plaintext polynomials and decodes plaintext polnomials as integers).
  • Evaluator object (which takes in the context as its constructor argument, and performs computations on encrypted data and relinearizes encrypted data after multiplication operations).
  • EvaluationKeys object (which requires no arguments for the constructor and is passed to a KeyGenerator to generate evaluation keys and is also passed to an Evaluator when relinearizing).

Once these objects are all instantiated, we can homomorphically encrypt and perform computations on encrypted data as follows:

  • Use the IntegerEncoder object to encode our data as plaintext polynomials.
  • Use the Encryptor object to encrypt the plaintext polynomials obtained above.
  • Use the Evaluator object to perform computations on encrypted data (taking care to relinearize after multiplication operations).
  • Use the Decryptor object to decrypt the encrypted computational output(s).
  • Use the IntegerEncoder object to decode the decrypted output(s) (which are plaintext polynomials) and convert them back into integer data.
  • Due to the homomorphic encryption scheme, the final data obtained with the above procedure should match the output of performing our computations on the raw, unencrypted data we started with, so long as we do not incur excessive corruption with our computations on the encrypted data (to check whether we are safe on this front, we can check to make sure that the noise budget of a given encrypted datum is sufficiently large; the consumption of this noise budget reflects the corruption incurred).

The above protocol is the simplest procedure and use case for SEAL homomorphic encryption, and can be seen in Example Basics: I in our SEALPythonExamples/examples.py file. To see more sophisticated use cases, refer to the later examples in the same file.

Original home: https://www.microsoft.com/en-us/research/project/simple-encrypted-arithmetic-library/

pyseal's People

Contributors

adityachivu avatar alexandertitus avatar cglewis avatar gregs5 avatar kimlaine avatar kshashwat avatar nilslukas avatar paradyx avatar pcejrowski avatar toddstavish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyseal's Issues

Python APIs

Hello everyone,

I can't find if there are python APIs that allow to interact with the container. Can anyone help me?

How to use SEAL keys on some other system?

I want to use keys on other system for evaluation and decryption. How I will be able to do that because I think it is generating random keys and even generating on other system keys will not be same.
Kindly help .
Thanks in advance!

Make PySeal Pickleable

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)

SEAL 3.0

Hi, is there any plan to update PySEAL to use SEAL 3.0?

subtraction issue

When I subtract some number from another number, the result becomes weird like 8818 - 769 = 1.81e^18. Does anyone have the same problem?

Saving secret_key and public key

I'm trying to save the secret_key and public_key in a file to use it after that in other files. How can I do that?. I see the method save, but I don't know how to use it.

Thanks so much

matplotlib

is it possible to import matplotlib in the example?

Fork pybind11 so CyberReboot owns a copy

The pySEAL docker image currently clones a public repository for pybind11
git clone https://github.com/pybind/pybind11.git

I would like to request that CyberReboot forks pybind11 so we can point the docker image to our own hosted repo to prevent our build from breaking if they update the software without our knowledge.

Thanks!

Error Installing Pybin11

Hello,

I have been using PySEAL library for the past two months and it worked just fine. However, Since yesterday that it crushed and simply does not go beyond step 20/31 where it yields the following ERROR:

ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-mkj1j5gc/cppimport/setup.py'"'"'; file='"'"'/tmp/pip-install-mkj1j5gc/cppimport/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-yjjxevxm
cwd: /tmp/pip-install-mkj1j5gc/cppimport/
Complete output (5 lines):
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-mkj1j5gc/cppimport/setup.py", line 3, in
version = open('VERSION').read()
FileNotFoundError: [Errno 2] No such file or directory: 'VERSION'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

It was very strange because everything worked just fine even five minutes before it crushed. I tried a couple of fixes like upgrading pip and wheels but it didnt work. Then I though maybe it had something to do with the latest update to docker but moving back to the previous version also did not seem to work.

Am I the only one having these issues? Any suggestions for the fix?

Thanks.

How to import a CSV file in SEALPythonExamples/examples.py using pandas

I have made necessary changes to import pandas library. I have put a 'dataset.csv' file in both the /SEALPythonExamples and /SEALExamples folder and also in thePySEAL main folder. But whenever I try to import the CSV file using pandas.read_csv() function, following error occurs -

"FileNotFoundError: [Errno 2] File b'dataset.csv' does not exist: b'dataset.csv'"

Compilation errors

Currently, /run-docker.shoutputs the following error:

Unable to find image 'seal-io:latest' locally

because we renamed the container. Replace the line with

docker run -it seal-save python3 SEALPythonExamples/examples.py

Furthermore, there are simple syntactical errors in the SEALPython/wrapper.cpp (e.g. line 185).

Will make a PR shortly to fix them.

Encode/Encrypt text message

Hello everybody,

I wanted to encrypt a text message with PySEAL and then decrypt it. Now I noticed that there is no Encoder that uses a string as input for encoding a Plaintext object.

Is there a suitable solution for this e.g. has someone implemented an own StringEncoder?

Get storage of plaintext and ciphertext?

Hi,

I just started trying to play with PySEAL. I am wondering is there any possibility that we can fetch the encoded vector of plaintext and ciphertext? The only finding by me is that we can use the to_string() function to print their string representation. Do I need to parse this vector from this string?

Thanks,
Shengzhong

Encrypted decision tree classifier

I want to implement homomorphic encryption in python.
Want to encrypt CSV file and use it to test the decision tree ..how can I do it ?

Converting enrypted numpy array to seal object.

I am sending data from one computer to another in an encrypted form but I cant decrypt it because it is there as numpy array after converting from bytes. Decryptor is not accepting it because it does not belong to seal. I am new on this topic may be I am missing something. Kindly help me in this issue.
Thank you!

No Release File

I am trying to run build-docker.sh, but getting this errors:

---> Running in 5465c03ccd56
E: The repository 'http://security.ubuntu.com/ubuntu artful-security Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu artful Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu artful-updates Release' does not have a Release file.
E: The repository 'http://archive.ubuntu.com/ubuntu artful-backports Release' does not have a Release file.

Possible solution: change ubuntu from 17.10 on 18.10 in Dockerfile (worked for me).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.