Giter Club home page Giter Club logo

seal-python's Introduction

Microsoft SEAL For Python

Microsoft SEAL is an easy-to-use open-source (MIT licensed) homomorphic encryption library developed by the Cryptography Research group at Microsoft.

pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++ code.

This is a python binding for the Microsoft SEAL library.

Contents

Build

  • Linux

    Clang++ (>= 5.0) or GNU G++ (>= 6.0), CMake (>= 3.12)

    # Optional
    sudo apt-get install git build-essential cmake python3 python3-dev python3-pip
    
    # Get the repository or download from the releases
    git clone https://github.com/Huelse/SEAL-Python.git
    cd SEAL-Python
    
    # Numpy is essential
    pip3 install -r requirements.txt
    
    # Init the SEAL and pybind11
    git submodule update --init --recursive
    # Get the newest repositories (unnecessary)
    # git submodule update --remote
    
    # Build the SEAL lib
    cd SEAL
    cmake -S . -B build -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_USE_ZSTD=OFF
    cmake --build build
    cd ..
    
    # Run the setup.py
    python3 setup.py build_ext -i
  • Windows

    Visual Studio 2019 or newer is required. And use the x64 Native Tools Command Prompt for Visual Studio 2019 command prompt to configure and build the Microsoft SEAL library. It's usually can be found in your Start Menu.

    # Same as above
    # Build the SEAL library
    cmake -S . -B build -G Ninja -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_USE_ZSTD=OFF
    cmake --build build
    
    # Run the setup.py
    python setup.py build_ext -i

    Generally, the Ninja generator is better than the "Visual Studio 16 2019" generator, and there is more information in the Microsoft SEAL official illustrate.

  • Docker

    requires: Docker

    To build source code into a docker image (from this directory):

    docker build -t huelse/seal -f Dockerfile .

    To use the image by running it as an interactive container:

    docker run -it huelse/seal

Note

  • Serialize

    In most situations, you can use the SEAL's native serialize API to save the data, here is an example:

    cipher.save('cipher')
    
    load_cipher = Ciphertext()
    load_cipher.load(context, 'cipher')  # work if the context is valid.

    Support type: Encryptionparams, Ciphertext, Plaintext, SecretKey, Publickey, Relinkeys, Galoiskeys

    Particularly, if you want to use the pickle to serialize your data, you need to do these things like below:

    # 1. Modify the serializable object's header file in SEAL and switch the wrapper.
    python helper.py
    
    # 2. Rebuild the SEAL lib like above
    cmake --build build
    
    # 3. Run the setup.py
    python setup.py build_ext -i

    Then, you can pickle the data object like this:

    import pickle
    
    cipher.set_parms(parms)  # necessary
    cipher_dump = pickle.dumps(cipher)
    cipher_load = pickle.loads(cipher_dump)

    Generally, we don't use compression library.

  • Other

    There are a lot of changes in the latest SEAL lib, we try to make the API in python can be used easier, it may remain some problems we unknown, if any problems(bugs), Issue please.

    Email: [email protected]

FAQ

  1. ImportError: undefined symbol

    Build a shared SEAL library cmake . -DBUILD_SHARED_LIBS=ON, and get the libseal.so,

    then change the path in setup.py, and rebuild.

  2. ImportError: libseal.so... cannot find

    a. sudo ln -s /path/to/libseal.so /usr/lib

    b. add /usr/local/lib or the SEAL/native/lib to /etc/ld.so.conf and refresh it sudo ldconfig

    c. build in cmake.

  3. BuildError: C++17 at least

  4. ModuleNotFoundError: No module named 'seal'

    The .so or .pyd file must be in the current directory, or you have install it already.

Contributing

seal-python's People

Contributors

carlee0 avatar dreamingraven avatar huelse avatar uriariel avatar yuntaobc avatar

Watchers

 avatar

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.