-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a5fbcce
Showing
106 changed files
with
7,858 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
AllowShortIfStatementsOnASingleLine: true | ||
BasedOnStyle: llvm | ||
FixNamespaceComments: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/.*/ | ||
/build/ | ||
/dist/ | ||
eva.egg-info/ | ||
__pycache__/ | ||
|
||
# In-source build files | ||
Makefile | ||
CMakeCache.txt | ||
cmake_install.cmake | ||
CPackConfig.cmake | ||
CPackSourceConfig.cmake | ||
compile_commands.json | ||
CMakeFiles/ | ||
*.pb.cc | ||
*.pb.h | ||
*.a | ||
*.so | ||
*.whl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[submodule "third_party/pybind11"] | ||
path = third_party/pybind11 | ||
url = https://github.com/pybind/pybind11 | ||
ignore = untracked | ||
[submodule "third_party/Galois"] | ||
path = third_party/Galois | ||
url = https://github.com/IntelligentSoftwareSystems/Galois.git | ||
ignore = untracked |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT license. | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
cmake_policy(SET CMP0079 NEW) | ||
cmake_policy(SET CMP0076 NEW) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
project(eva | ||
VERSION 1.0.0 | ||
LANGUAGES CXX | ||
) | ||
|
||
option(USE_GALOIS "Use the Galois library for multicore homomorphic evaluation" OFF) | ||
if(USE_GALOIS) | ||
message("Galois based multicore support enabled") | ||
add_definitions(-DEVA_USE_GALOIS) | ||
endif() | ||
|
||
find_package(SEAL 3.6 REQUIRED) | ||
find_package(Protobuf 3.6 REQUIRED) | ||
find_package(Python COMPONENTS Interpreter Development) | ||
|
||
if(NOT Python_VERSION_MAJOR EQUAL 3) | ||
message(FATAL_ERROR "EVA requires Python 3. Please ensure you have it | ||
installed in a location searched by CMake.") | ||
endif() | ||
|
||
add_subdirectory(third_party/pybind11) | ||
if(USE_GALOIS) | ||
add_subdirectory(third_party/Galois EXCLUDE_FROM_ALL) | ||
endif() | ||
|
||
add_subdirectory(eva) | ||
add_subdirectory(python) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Microsoft Open Source Code of Conduct | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
|
||
Resources: | ||
|
||
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) | ||
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) | ||
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Contributing | ||
|
||
The EVA project welcomes contributions and suggestions. Most contributions require you to | ||
agree to a Contributor License Agreement (CLA) declaring that you have the right to, | ||
and actually do, grant us the rights to use your contribution. For details, visit | ||
https://cla.microsoft.com. | ||
|
||
Please submit all pull requests on the **contrib** branch. We will handle the final merge onto the main branch. | ||
|
||
When you submit a pull request, a CLA-bot will automatically determine whether you need | ||
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the | ||
instructions provided by the bot. You will only need to do this once across all repositories using our CLA. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) Microsoft Corporation. | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
# EVA - Compiler for Microsoft SEAL | ||
|
||
EVA is a compiler for homomorphic encryption, that automates away the parts that require cryptographic expertise. | ||
This gives you a simple way to write programs that operate on encrypted data without having access to the secret key. | ||
|
||
Think of EVA as the "C compiler" of the homomorphic world. Homomorphic computations written in EVA IR (Encrypted Vector Arithmetic Intermediate Representation) get compiled to the "assembly" of the homomorphic encryption library API. Just like C compilers free you from tricky tasks like register allocation, EVA frees you from *encryption parameter selection, rescaling insertion, <small>relinearization</small>*... | ||
|
||
EVA targets [Microsoft SEAL](https://github.com/microsoft/SEAL) — the industry leading library for fully-homomorphic encryption — and currently supports the CKKS scheme for deep computations on encrypted approximate fixed-point arithmetic. | ||
|
||
## Getting Started | ||
|
||
EVA is a native library written in C++17 with bindings for Python. Both Linux and Windows are supported. The instructions below show how to get started with EVA on Ubuntu. For building on Windows [EVA's Azure Pipelines script](azure-pipelines.yml) is a useful reference. | ||
|
||
### Installing Dependencies | ||
|
||
To install dependencies on Ubuntu 20.04: | ||
``` | ||
sudo apt install cmake libboost-all-dev libprotobuf-dev protobuf-compiler | ||
``` | ||
|
||
Clang is recommended for compilation, as SEAL is faster when compiled with it. To install clang and set it as default: | ||
``` | ||
sudo apt install clang | ||
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 | ||
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100 | ||
``` | ||
|
||
Next install Microsoft SEAL version 3.6: | ||
``` | ||
git clone -b v3.6.0 https://github.com/microsoft/SEAL.git | ||
cd SEAL | ||
cmake -DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=OFF . | ||
make -j | ||
sudo make install | ||
``` | ||
*Note that SEAL has to be installed with transparent ciphertext checking turned off, as it is not possible in general to statically ensure a program will not produce a transparent ciphertext. This does not affect the security of ciphertexts encrypted with SEAL.* | ||
|
||
### Building and Installing EVA | ||
|
||
#### Building EVA | ||
|
||
EVA builds with CMake version ≥ 3.13: | ||
``` | ||
git submodule update --init | ||
cmake . | ||
make -j | ||
``` | ||
The build process creates a `setup.py` file in `python/`. To install the package for development with PIP: | ||
``` | ||
python3 -m pip install -e python/ | ||
``` | ||
To create a Python Wheel package for distribution in `dist/`: | ||
``` | ||
python3 python/setup.py bdist_wheel --dist-dir='.' | ||
``` | ||
|
||
To check that the installed Python package is working correctly, run all tests with: | ||
``` | ||
python3 tests/all.py | ||
``` | ||
|
||
EVA does not yet support installing the native library for use in other CMake projects (contributions very welcome). | ||
|
||
#### Multicore Support | ||
|
||
EVA features highly scalable multicore support using the [Galois library](https://github.com/IntelligentSoftwareSystems/Galois). It is included as a submodule, but is turned off by default for faster builds and easier debugging. To build EVA with Galois configure with `USE_GALOIS=ON`: | ||
``` | ||
cmake -DUSE_GALOIS=ON . | ||
``` | ||
|
||
### Running the Examples | ||
|
||
The examples use EVA's Python APIs. To install dependencies with PIP: | ||
``` | ||
python3 -m pip install -r examples/requirements.txt | ||
``` | ||
|
||
To run for example the image processing example in EVA/examples: | ||
``` | ||
cd examples/ | ||
python3 image_processing.py | ||
``` | ||
This will compile and run homomorphic evaluations of a Sobel edge detection filter and a Harris corner detection filter on `examples/baboon.png`, producing results of homomorphic evaluation in `*_encrypted.png` and reference results from normal execution in `*_reference.png`. | ||
The script also reports the mean squared error between these for each filter. | ||
|
||
## Programming with PyEVA | ||
|
||
PyEVA is a thin Python-embedded DSL for producing EVA programs. | ||
We will walk you through compiling a PyEVA program with EVA and running it on top of SEAL. | ||
|
||
### Writing and Compiling Programs | ||
|
||
A program to evaluate a fixed polynomial 3x<sup>2</sup>+5x-2 on 1024 encrypted values can be written: | ||
``` | ||
from eva import * | ||
poly = EvaProgram('Polynomial', vec_size=1024) | ||
with poly: | ||
x = Input('x') | ||
Output('y', 3*x**2 + 5*x - 2) | ||
``` | ||
Next we will compile this program for the [CKKS encryption scheme](https://eprint.iacr.org/2016/421.pdf). | ||
Two additional pieces of information EVA currently requires to compile for CKKS are the *fixed-point scale for inputs* and the *maximum ranges of coefficients in outputs*, both represented in number of bits: | ||
``` | ||
poly.set_output_ranges(30) | ||
poly.set_input_scales(30) | ||
``` | ||
Now the program can be compiled: | ||
``` | ||
from eva.ckks import * | ||
compiler = CKKSCompiler() | ||
compiled_poly, params, signature = compiler.compile(poly) | ||
``` | ||
The `compile` method transforms the program in-place and returns: | ||
|
||
1. the compiled program; | ||
2. encryption parameters for Microsoft SEAL with which the program can be executed; | ||
3. a signature object, that specifies how inputs and outputs need to be encoded and decoded. | ||
|
||
The compiled program can be inspected by printing it in the DOT format for the [Graphviz](https://graphviz.org/) visualization software: | ||
``` | ||
print(compiled_poly.to_DOT()) | ||
``` | ||
The output can be viewed as a graph in, for example, a number of Graphviz editors available online. | ||
|
||
### Generating Keys and Encrypting Inputs | ||
|
||
Encryption keys can now be generated using the encryption parameters: | ||
``` | ||
from eva.seal import * | ||
public_ctx, secret_ctx = generate_keys(params) | ||
``` | ||
Next a dictionary of inputs is created and encrypted using the public context and the program signature: | ||
``` | ||
inputs = { 'x': [i for i in range(compiled_poly.vec_size)] } | ||
encInputs = public_ctx.encrypt(inputs, signature) | ||
``` | ||
|
||
### Homomorphic Execution | ||
|
||
Everything is now in place for executing the program with Microsoft SEAL: | ||
``` | ||
encOutputs = public_ctx.execute(compiled_poly, encInputs) | ||
``` | ||
|
||
### Decrypting Results | ||
|
||
Finally, the outputs can be decrypted using the secret context: | ||
``` | ||
outputs = secret_ctx.decrypt(encOutputs, signature) | ||
``` | ||
For debugging it is often useful to compare homomorphic results to unencrypted computation. | ||
The `evaluate` method can be used to execute an EVA program on unencrypted data. | ||
The two sets of results can then be compared with for example Mean Squared Error: | ||
|
||
``` | ||
from eva.metric import valuation_mse | ||
reference = evaluate(compiled_poly, inputs) | ||
print('MSE', valuation_mse(outputs, reference)) | ||
``` | ||
|
||
## Contributing | ||
|
||
The EVA project welcomes contributions and suggestions. Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details. | ||
|
||
## Credits | ||
|
||
This project is a collaboration between the Microsoft Research's Research in Software Engineering (RiSE) group and Cryptography and Privacy Research group. | ||
|
||
A huge credit goes to [Dr. Roshan Dathathri](https://roshandathathri.github.io/), who as an intern built the first version of EVA, along with all the transformations required for targeting the CKKS scheme efficiently and the parallelizing runtime required to make execution scale. | ||
|
||
Many thanks to [Sangeeta Chowdhary](https://www.ilab.cs.rutgers.edu/~sc1696/), who as an intern put a huge amount of work into making EVA ready for release. | ||
|
||
## Publications | ||
|
||
Roshan Dathathri, Blagovesta Kostova, Olli Saarikivi, Wei Dai, Kim Laine, Madanlal Musuvathi. *EVA: An Encrypted Vector Arithmetic Language and Compiler for Efficient Homomorphic Computation*. PLDI 2020. [arXiv](https://arxiv.org/abs/1912.11951) [DOI](https://doi.org/10.1145/3385412.3386023) | ||
|
||
Roshan Dathathri, Olli Saarikivi, Hao Chen, Kim Laine, Kristin Lauter, Saeed Maleki, Madanlal Musuvathi, Todd Mytkowicz. *CHET: An Optimizing Compiler for Fully-Homomorphic Neural-Network Inferencing*. PLDI 2019. [DOI](https://doi.org/10.1145/3314221.3314628) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK --> | ||
|
||
## Security | ||
|
||
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). | ||
|
||
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. | ||
|
||
## Reporting Security Issues | ||
|
||
**Please do not report security vulnerabilities through public GitHub issues.** | ||
|
||
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). | ||
|
||
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). | ||
|
||
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). | ||
|
||
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: | ||
|
||
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) | ||
* Full paths of source file(s) related to the manifestation of the issue | ||
* The location of the affected source code (tag/branch/commit or direct URL) | ||
* Any special configuration required to reproduce the issue | ||
* Step-by-step instructions to reproduce the issue | ||
* Proof-of-concept or exploit code (if possible) | ||
* Impact of the issue, including how an attacker might exploit the issue | ||
|
||
This information will help us triage your report more quickly. | ||
|
||
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. | ||
|
||
## Preferred Languages | ||
|
||
We prefer all communications to be in English. | ||
|
||
## Policy | ||
|
||
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). | ||
|
||
<!-- END MICROSOFT SECURITY.MD BLOCK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Support | ||
|
||
## How to file issues and get help | ||
|
||
This project uses GitHub Issues to track bugs and feature requests. Please search the existing | ||
issues before filing new issues to avoid duplicates. For new issues, file your bug or | ||
feature request as a new Issue. | ||
|
||
For help and questions about using this project, you can contact the EVA compiler team at | ||
[evacompiler@microsoft.com](mailto:evacompiler@microsoft.com). | ||
We are very interested in helping early adopters start to use EVA. | ||
|
||
## Microsoft Support Policy | ||
|
||
Support for EVA is limited to the resources listed above. |
Oops, something went wrong.