{"id":13830943,"url":"https://github.com/tf-encrypted/tf-seal","last_synced_at":"2025-04-09T09:32:35.507Z","repository":{"id":57474893,"uuid":"195807587","full_name":"tf-encrypted/tf-seal","owner":"tf-encrypted","description":"Bridge between TensorFlow and the Microsoft SEAL homomorphic encryption library","archived":false,"fork":false,"pushed_at":"2020-01-22T11:44:54.000Z","size":85,"stargazers_count":95,"open_issues_count":18,"forks_count":16,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-09-18T15:24:40.922Z","etag":null,"topics":["cryptography","homomorphic-encryption","machine-learning","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tf-encrypted.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-08T12:28:53.000Z","updated_at":"2024-03-05T00:58:54.000Z","dependencies_parsed_at":"2022-09-10T04:05:04.399Z","dependency_job_id":null,"html_url":"https://github.com/tf-encrypted/tf-seal","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tf-encrypted%2Ftf-seal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tf-encrypted%2Ftf-seal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tf-encrypted%2Ftf-seal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tf-encrypted%2Ftf-seal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tf-encrypted","download_url":"https://codeload.github.com/tf-encrypted/tf-seal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223381907,"owners_count":17136305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","homomorphic-encryption","machine-learning","tensorflow"],"created_at":"2024-08-04T10:01:13.173Z","updated_at":"2024-11-06T17:18:10.411Z","avatar_url":"https://github.com/tf-encrypted.png","language":"C++","readme":"# TF SEAL\n\nTF SEAL provides a bridge between [TensorFlow](https://tensorflow.org) and the [Microsoft SEAL](https://github.com/microsoft/SEAL) homomorphic encryption library, making it easier than ever to use this library to compute on encrypted data. It currently offers low-level operations for interacting with Microsoft SEAL via TensorFlow with [work in progress](#road-map) on a high-level integration into [TF Encrypted](https://tf-encrypted.io).\n\n[![PyPI](https://img.shields.io/pypi/v/tf-seal.svg)](https://pypi.org/project/tf-seal/) [![CircleCI Badge](https://circleci.com/gh/tf-encrypted/tf-seal/tree/master.svg?style=svg)](https://circleci.com/gh/tf-encrypted/tf-seal/tree/master)\n\n## Usage\n\nThe following demonstrates how the low-level interface can be used to perform a matrix multiplication using homomorphic encryption inside of TensorFlow.\n\n```python\nimport numpy as np\nimport tensorflow as tf\nimport tf_seal as tfs\n\npublic_keys, secret_key = tfs.seal_key_gen(gen_relin=True, gen_galois=True)\n\n# sample inputs in the form of tf.Tensors\na = tf.random.normal(shape=(2, 3), dtype=tf.float32)\nb = tf.random.normal(shape=(2, 3), dtype=tf.float32)\n\n# the plaintext equivalent of our computation\nc = tf.matmul(a, tf.transpose(b))\n\n# encrypt inputs, yielding tf_seal.Tensors\na_encrypted = tfs.convert_to_tensor(a, secret_key, public_keys)\nb_encrypted = tfs.convert_to_tensor(b, secret_key, public_keys)\n\n# perform computation on encrypted data\n# - note that because of how the data is laid out in memory,\n#   tf_seal.matmul expects the right-hand matrix to be ordered\n#   column-major wise, i.e. already transposed\nc_encrypted = tfs.matmul(a_encrypted, b_encrypted)\n\nwith tf.Session() as sess:\n    expected, actual = sess.run([c, c_encrypted])\n    np.testing.assert_almost_equal(actual, expected, decimal=3)\n```\n\n## Documentation\n\nBlog posts:\n- [Bridging Microsoft SEAL into TensorFlow](https://medium.com/dropoutlabs/bridging-microsoft-seal-into-tensorflow-b04cc2761ad4)\n\n## Road map\n\nWe are currently working on integrating TF SEAL into [TF Encrypted](https://tf-encrypted.io) such that privacy-preserving machine learning applications can instead access the library through a high-level interface and take advantage of e.g. the Keras API. This includes adding logic that helps optimize homomorphic encryption for a perticular computation, making use even easier.\n\n\u003cimg src=\"https://raw.githubusercontent.com/tf-encrypted/assets/master/tf-seal/app-stack.png\" width=\"45%\" /\u003e\n\n## Installation\n\nWe recommend using [Miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Anaconda](https://www.anaconda.com/distribution/) to set up and use a Python 3.7 environment for all instructions below:\n\n```\nconda create -n tfseal python=3.7 -y\nsource activate tfseal\n```\n\nAfter installing the [custom build of TensorFlow](#custom-tensorflow) you can install [TF SEAL from PyPI](https://pypi.org/project/tf-seal/) using pip:\n\n```\npip install tf-seal\n```\n\n## Examples\n\nThere is currently one example displaying how we can run a simple logistic regression prediction with TF SEAL.\n\nOnce TF SEAL is installed we can run the example by simplying running:\n\n```\npython logistic_regression.py\n```\n\n## Development\n\nWe recommend using [Miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Anaconda](https://www.anaconda.com/distribution/) to set up and use a Python 3.7 environment for all instructions below:\n\n```\nconda create -n tfseal-dev python=3.7 -y\nsource activate tfseal-dev\n```\n\nThe basic requirements are:\n\n- Python (== 3.7)\n- [Bazel](https://docs.bazel.build/versions/master/install.html) (\u003e= 0.26.1)\n- CMake\n- [TensorFlow built with C++17](#custom-tensorflow)\n\nThe remaining PyPI packages can then be installed using:\n\n```\npip install -r requirements-dev.txt\n```\n\n### Testing\n\nAll tests can be run via Bazel with:\n\n```\nmake test\n```\n\n### Building\n\nThe pip package can be built using:\n\n```\nmake build\n```\n\nwith the resulting wheel file placed in `./artifacts`.\n\n## Custom TensorFlow\n\nA 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](https://github.com/dropoutlabs/tensorflow) built with C++17 can be installed as shown below.\n\n#### Ubuntu binary\n\n```\nwget https://storage.googleapis.com/tf-pips/tf-c++17-support/tf_nightly-1.14.0-cp37-cp37m-linux_x86_64.whl\npip install tf_nightly-1.14.0-cp37-cp37m-linux_x86_64.whl\n```\n\n#### macOS binary\n\n```\nwget https://storage.googleapis.com/tf-pips/tf-c++17-support/tf_nightly-1.14.0-cp37-cp37m-macosx_10_7_x86_64.whl\npip install tf_nightly-1.14.0-cp37-cp37m-macosx_10_7_x86_64.whl\n```\n\n#### From source\n\nWe recommend using [Miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Anaconda](https://www.anaconda.com/distribution/) to first set up and use a Python 3.7 environment:\n\n```\nconda create -n customtf python=3.7 -y\nsource activate customtf\n```\n\nThis requires that [Bazel](https://docs.bazel.build/versions/master/install.html) (== 0.26.1) has been installed. The patched version of TensorFlow may then be built using:\n\n```\ngit clone https://github.com/tf-encrypted/tf-seal.git\ncd tf-seal\npip install -r requirements-customtf.txt\n\nmake tensorflow\npip install -U tf_nightly-1.14.0-cp37-cp37m-*\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftf-encrypted%2Ftf-seal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftf-encrypted%2Ftf-seal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftf-encrypted%2Ftf-seal/lists"}