Skip to main content

Bridge between TensorFlow and the Microsoft SEAL homomorphic encryption library.

Project description

TF Seal

TF Seal provides a bridge between TF Encrypted and the Microsoft SEAL homomorphic encryption library, making it easier than ever to use this library to compute on encrypted data directly from TensorFlow.

PyPI CircleCI Badge

Usage

The following demonstrates how to perform a matrix multiplication using homomorphic encryption inside of TensorFlow.

import numpy as np
import tensorflow as tf

import tf_seal as tfs

public_keys, secret_key = tfs.seal_key_gen(gen_relin=True, gen_galois=True)

# encrypted input -> tf_seal.Tensor
a_plain = np.random.normal(size=(2, 2)).astype(np.float32)
a = tfs.constant(a_plain, secret_key, public_keys)

# public weights
b = np.random.normal(size=(2, 2)).astype(np.float32)

# because of how the data is laid out in memory tfs.matmul expects
# the b matrix to be order column-major wise
c = tfs.matmul(a, b.transpose())

with tf.Session() as sess:
    print(sess.run(c))

Installation

We recommend using Miniconda or Anaconda to set up and use a Python 3.7 environment for all instructions below:

conda create -n tfseal python=3.7 -y
source activate tfseal

Custom TensorFlow

A custom build of TensorFlow is currently needed to run TF Seal due to a mismatch between the C++ version used by the official TensorFlow build (C++11) and the one needed by Microsoft SEAL (C++17). A patched version of TensorFlow built with C++17 can be installed as shown below.

Ubuntu

wget https://storage.googleapis.com/tf-pips/tf-c++17-support/tf_nightly-1.14.0-cp37-cp37m-linux_x86_64.whl
pip install tf_nightly-1.14.0-cp37-cp37m-linux_x86_64.whl

macOS

wget https://storage.googleapis.com/tf-pips/tf-c++17-support/tf_nightly-1.14.0-cp37-cp37m-macosx_10_7_x86_64.whl
pip install tf_nightly-1.14.0-cp37-cp37m-macosx_10_7_x86_64.whl

After installing the custom build of TensorFlow you can install TF Seal from PyPi using pip:

pip install tf-seal

Examples

There is currently one example displaying how we can run a simple logistic regression prediction with TF SEAL.

Once TF SEAL is installed we can run the example by simplying running:

python logistic_regression.py

Development

We recommend using Miniconda or Anaconda to set up and use a Python 3.7 environment for all instructions below:

conda create -n tfseal-dev python=3.7 -y
source activate tfseal-dev

Requirements

Ubuntu

CMake can be installed simply with apt:

sudo apt install cmake

Bazel is a little more involved, the following instructions can be installed, recommend installing Bazel 0.26.1: https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu

The remaining PyPI packages can then be installed using:

pip install -r requirements-dev.txt

Once the custom TensorFlow is installed you will be able to start development.

macOS

We need the following items:

Using Homebrew we make sure that both Bazel and CMake are installed:

brew tap bazelbuild/tap
brew install bazelbuild/tap/bazel
brew install cmake

The remaining PyPI packages can then be installed using:

pip install -r requirements-dev.txt

Once the custom TensorFlow is installed you will be able to start development.

Testing

Once the development environment is set up you can run:

make test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

tf_seal-0.1.0rc3-cp37-cp37m-manylinux1_x86_64.whl (324.8 kB view hashes)

Uploaded CPython 3.7m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page