Skip to main content

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

Release files for tf-seal 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for tf-seal 0.1.0
File Interpreter ABI Platform
tf_seal-0.1.0-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details

Release files / tf_seal-0.1.0-cp37-cp37m-manylinux1_x86_64.whl

Download URL tf_seal-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
Size 324.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
75fa589075015eb401c2c0bfe3d75aec81b117063d204abd5f1c29f3ca616f1a
BLAKE2b-256 checksum
How to use checksums
ebb7ecfaa0325f0da16347258b3f49cf2000093f1c63fad7cc0b94689b190440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page