2018-11-09 21:39:54 +03:00
# Introduction
2018-12-01 04:41:23 +03:00
Microsoft Simple Encrypted Arithmetic Library (Microsoft SEAL) is an easy-to-use
homomorphic encryption library developed by researchers in the Cryptography
2019-01-30 03:12:43 +03:00
Research group at Microsoft Research. Microsoft SEAL is written in modern standard C++ and
2018-12-01 04:41:23 +03:00
has no external dependencies, making it easy to compile and run in many different
environments.
2018-11-09 21:39:54 +03:00
2018-12-01 04:41:23 +03:00
For more information about the Microsoft SEAL project, see [http://sealcrypto.org ](http://sealcrypto.org ).
2018-11-09 21:39:54 +03:00
# License
2018-12-01 04:41:23 +03:00
2019-01-30 03:12:43 +03:00
Microsoft SEAL is licensed under the MIT license; see LICENSE.
2018-12-01 04:41:23 +03:00
# Building and using SEAL
## Windows
2019-01-30 03:12:43 +03:00
Microsoft SEAL comes with a Microsoft Visual Studio 2017 solution file SEAL.sln that can be
2018-12-01 04:41:23 +03:00
used to conveniently build the library, examples, and unit tests.
2019-01-30 03:12:43 +03:00
#### Debug and Release builds
2018-12-01 04:41:23 +03:00
2019-01-30 03:12:43 +03:00
You can easily switch from Visual Studio build configuration menu whether Microsoft SEAL should be
2018-12-01 04:41:23 +03:00
built in Debug mode (no optimizations) or in Release mode. Please note that Debug
mode should not be used except for debugging SEAL itself, as the performance will be
orders of magnitude worse than in Release mode.
#### Library
2019-01-30 03:12:43 +03:00
Build the Microsoft SEAL project (native/src/SEAL.vcxproj) from SEAL.sln. Building Microsoft SEAL results
2019-01-30 03:55:03 +03:00
in the static library seal.lib to be created in `native/lib/$(Platform)/$(Configuration)` . When
linking with applications, you need to add `native/src/` (full path) as an include directory
2018-12-01 04:41:23 +03:00
for SEAL header files.
#### Examples
2019-01-30 03:55:03 +03:00
Build the SEALExamples project (`native/examples/SEALExamples.vcxproj`) from SEAL.sln.
This results in an executable sealexamples.exe to be created in `native/bin/$(Platform)/$(Configuration)` .
2018-12-01 04:41:23 +03:00
#### Unit tests
The unit tests require the Google Test framework to be installed. The appropriate
2019-01-30 03:55:03 +03:00
NuGet package is already listed in `native/tests/packages.config` , so once you attempt to build
the SEALTest project (`native/tests/SEALTest.vcxproj`) from SEAL.sln Visual Studio will
2018-12-01 04:41:23 +03:00
automatically download and install it for you.
## Linux and OS X
2019-01-30 03:12:43 +03:00
Microsoft SEAL is very easy to configure and build in Linux and OS X using CMake (>= 3.10).
2018-12-01 04:41:23 +03:00
A modern version of GNU G++ (>= 6.0) or Clang++ (>= 5.0) is needed. In OS X the
Xcode toolchain (>= 9.3) will work.
In OS X you will need CMake with command line tools. For this, you can either
1. install the cmake package with [Homebrew ](https://brew.sh ), or
2. download CMake directly from [https://cmake.org/download ](https://cmake.org/download ) and [enable command line tools ](https://stackoverflow.com/questions/30668601/installing-cmake-command-line-tools-on-a-mac ).
Below we give instructions for how to configure, build, and install SEAL either
system-wide (global install), or for a single user (local install). A system-wide
install requires elevated (root) privileges.
2019-01-30 03:12:43 +03:00
#### Debug and Release builds
2018-12-01 04:41:23 +03:00
2019-01-30 03:12:43 +03:00
You can easily switch from CMake configuration options whether Microsoft SEAL should be built in
2018-12-01 04:41:23 +03:00
Debug mode (no optimizations) or in Release mode. Please note that Debug mode should not
2019-01-30 03:12:43 +03:00
be used except for debugging Microsoft SEAL itself, as the performance will be orders of magnitude
2018-12-01 04:41:23 +03:00
worse than in Release mode.
### Global install
#### Library
2019-01-30 03:12:43 +03:00
If you have root access to the system you can install Microsoft SEAL system-wide as follows:
2018-12-01 04:46:17 +03:00
````
2019-01-28 22:01:54 +03:00
cd native/src
2018-12-01 04:46:17 +03:00
cmake .
make
sudo make install
2019-01-28 22:01:54 +03:00
cd ../..
2018-12-01 04:46:17 +03:00
````
2018-12-01 04:41:23 +03:00
#### Examples
To build the examples do:
2018-12-01 04:46:17 +03:00
````
2019-01-28 22:01:54 +03:00
cd native/examples
2018-12-01 04:46:17 +03:00
cmake .
make
2019-01-28 22:01:54 +03:00
cd ../..
2018-12-01 04:46:17 +03:00
````
2018-12-01 04:41:23 +03:00
2019-01-30 03:55:03 +03:00
After completing the above steps the sealexamples executable can be found in `native/bin/` .
See `native/examples/CMakeLists.txt` for how to link Microsoft SEAL with your own project using cmake.
2018-12-01 04:41:23 +03:00
#### Unit tests
To build the unit tests, make sure you have the Google Test library (libgtest-dev)
installed. Then do:
2018-12-01 04:46:17 +03:00
````
2019-01-28 22:01:54 +03:00
cd native/tests
2018-12-01 04:46:17 +03:00
cmake .
make
2019-01-28 22:01:54 +03:00
cd ../..
2018-12-01 04:46:17 +03:00
````
2018-12-01 04:41:23 +03:00
2019-01-30 03:55:03 +03:00
After completing these steps the sealtest executable can be found in `native/bin/` . All unit
2018-12-01 04:41:23 +03:00
tests should pass successfully.
### Local install
#### Library
2019-01-30 03:12:43 +03:00
To install Microsoft SEAL locally, e.g., to ~/mylibs, do the following:
2018-12-01 04:46:17 +03:00
````
2019-01-28 22:01:54 +03:00
cd native/src
2018-12-01 04:46:17 +03:00
cmake -DCMAKE_INSTALL_PREFIX=~/mylibs .
make
make install
2019-01-28 22:01:54 +03:00
cd ../..
2018-12-01 04:46:17 +03:00
````
2018-12-01 04:41:23 +03:00
#### Examples
To build the examples do:
2018-12-01 04:46:17 +03:00
````
2019-01-28 22:01:54 +03:00
cd native/examples
2018-12-01 04:46:17 +03:00
cmake -DCMAKE_PREFIX_PATH=~/mylibs .
make
2019-01-28 22:01:54 +03:00
cd ../..
2018-12-01 04:46:17 +03:00
````
2018-12-01 04:41:23 +03:00
2019-01-30 03:55:03 +03:00
After completing the above steps the sealexamples executable can be found in `native/bin/` .
See `native/examples/CMakeLists.txt` for how to link Microsoft SEAL with your own project using cmake.
2018-12-01 04:41:23 +03:00
#### Unit tests
To build the unit tests, make sure you have the Google Test library (libgtest-dev)
installed. Then do:
2018-12-01 04:46:17 +03:00
````
2019-01-28 22:01:54 +03:00
cd native/tests
2018-12-01 04:46:17 +03:00
cmake -DCMAKE_PREFIX_PATH=~/mylibs .
make
2019-01-28 22:01:54 +03:00
cd ../..
2018-12-01 04:46:17 +03:00
````
2018-12-01 04:41:23 +03:00
2019-01-30 03:55:03 +03:00
After completing these steps the sealtest executable can be found in `native/bin/` . All unit
2018-12-01 04:41:23 +03:00
tests should pass successfully.
2019-01-30 03:12:43 +03:00
# Building and using Microsoft SEAL for .NET
2019-01-23 02:57:56 +03:00
2019-01-30 03:12:43 +03:00
Microsoft SEAL provides a .NET Standard library that wraps the functionality in Microsoft SEAL
for use in .NET development.
2019-01-23 02:57:56 +03:00
## Windows
The Microsoft Visual Studio 2017 solution file SEAL.sln contains the projects necessary
2019-01-30 03:12:43 +03:00
to build the .NET assembly, a backing native shared library, .NET examples and unit tests.
2019-01-23 02:57:56 +03:00
#### Native library
2019-01-30 03:12:43 +03:00
Microsoft SEAL for .NET requires a native library that is invoked by the managed .NET library.
2019-01-30 03:55:03 +03:00
Build the SEALNetNative project (`dotnet/native/SEALNetNative.vcxproj`) from SEAL.sln. Building SEALNetNative results
in the dynamic library sealnetnative.dll being created in `dotnet/lib/$(Platform)/$(Configuration)` . This library is
2019-01-30 03:12:43 +03:00
meant to be used only by the .NET library, not by end users. The library needs to be
present in the same directory as your executable when developing a .NET application.
2019-01-23 02:57:56 +03:00
2019-01-30 03:12:43 +03:00
#### .NET library
2019-01-23 02:57:56 +03:00
2019-01-30 03:55:03 +03:00
Once you have built the shared native library (see above), build the SEALNet project (`dotnet/src/SEALNet.csproj`) from SEAL.sln. Building SEALNet results
in the assembly SEALNet.dll being created in `dotnet/lib/$(Configuration)/netstandard2.0` . This
2019-01-23 02:57:56 +03:00
is the assembly you can reference in your application.
2019-01-30 03:12:43 +03:00
#### .NET examples
2019-01-23 02:57:56 +03:00
2019-01-30 03:55:03 +03:00
Build the SEALNetExamples project (`dotnet/examples/SEALNetExamples.csproj`) from SEAL.sln.
2019-01-23 02:57:56 +03:00
This results in the assembly SEALNetExamples.dll being created in
2019-01-30 03:55:03 +03:00
`dotnet/bin/$(Configuration)/netcoreapp2.1` . The project takes care of copying the
2019-01-28 22:01:54 +03:00
native SEALNetNative library to the output directory.
2019-01-23 02:57:56 +03:00
2019-01-30 03:12:43 +03:00
#### .NET unit tests
2019-01-23 02:57:56 +03:00
2019-01-30 03:55:03 +03:00
Build the SEALNet Test project (`dotnet/tests/SEALNetTest.csproj`) from SEAL.sln. This results
in the SEALNetTest.dll assembly being created in `dotnet/lib/$(Configuration)/netcoreapp2.1` .
2019-01-28 22:01:54 +03:00
The project takes care of copying the native SEALNetNative library to the output directory.
2019-01-23 02:57:56 +03:00
2019-01-30 03:12:43 +03:00
### Using Microsoft SEAL for .NET in your own application
2019-01-23 02:57:56 +03:00
2019-01-30 03:12:43 +03:00
To use Microsoft SEAL for .NET in your own application you need to:
2019-01-23 02:57:56 +03:00
1. Add a reference in your project to SEALNet.dll
2019-01-30 03:12:43 +03:00
2. Ensure sealnetnative.dll is available for your application when run. The easiest way to ensure
this is to copy sealnetnative.dll to the same directory where your application's executable
2019-01-23 02:57:56 +03:00
is located.
## Linux and OS X
2019-01-30 03:12:43 +03:00
Microsoft SEAL for .NET relies on a native shared library that can be easily configured and built
2019-01-23 02:57:56 +03:00
using CMake (>= 3.10) and a modern version of GNU G++ (>= 6.0) or Clang++ (>= 5.0). In OS X
the Xcode toolchain (>= 9.3) will work.
2019-01-30 03:12:43 +03:00
For compiling .NET code you will need to install a .NET Core SDK (>= 2.1). You can follow
2019-01-23 02:57:56 +03:00
these [instructions for installing in Linux ](https://dotnet.microsoft.com/download?initial-os=linux ),
2019-01-30 03:12:43 +03:00
or for [installing in OS X ](https://dotnet.microsoft.com/download?initial-os=macos ).
2019-01-23 02:57:56 +03:00
### Local use of shared native library
2019-01-30 03:12:43 +03:00
If you only intend to run the examples and unit tests provided with Microsoft SEAL, you do not need to
install the shared native library, you only need to compile it. The SEALNetExamples and SEALNetTest projects
2019-01-23 02:57:56 +03:00
take care of copying the native shared library to the appropriate assembly output directory.
2019-01-24 03:12:44 +03:00
To compile the shared native library you will need to:
2019-01-30 03:12:43 +03:00
1. Compile Microsoft SEAL as a static library with Position-Independent Code (PIC);
2. Compile shared native library.
2019-01-24 03:12:44 +03:00
The instructions for compiling SEAL are similar to the instructions described previously for a
local install of SEAL.
2019-01-30 03:12:43 +03:00
Assuming Microsoft SEAL was built using default options, we can now use this library to compile the shared native library required for .NET:
2019-01-23 02:57:56 +03:00
````
2019-01-28 22:01:54 +03:00
cd dotnet/native
2019-01-24 03:12:44 +03:00
cmake -DCMAKE_PREFIX_PATH=~/mylibs .
2019-01-23 02:57:56 +03:00
make
cd ../..
````
2019-01-30 03:12:43 +03:00
#### .NET library
2019-01-23 02:57:56 +03:00
2019-01-30 03:55:03 +03:00
To build the .NET Standard library, do the following:
2019-01-23 02:57:56 +03:00
````
2019-01-28 22:01:54 +03:00
cd dotnet/src
2019-01-23 02:57:56 +03:00
dotnet build
cd ../..
````
You can use the dotnet parameter `--configuration` to build either a Debug or Release version of the assembly.
2019-01-30 03:55:03 +03:00
This will result in a SEALNet.dll assembly being created in `dotnet/lib/$(Configuration)/netstandard2.0` . This
2019-01-23 02:57:56 +03:00
assembly is the one you will want to reference in your own projects.
#### Examples
2019-01-30 03:12:43 +03:00
To build and run the .NET examples do:
2019-01-23 02:57:56 +03:00
````
2019-01-28 22:01:54 +03:00
cd dotnet/examples
2019-01-23 02:57:56 +03:00
dotnet run
cd ../..
````
2019-01-30 03:12:43 +03:00
As mentioned before, the .NET project will copy the shared native library to the assembly output directory.
2019-01-23 02:57:56 +03:00
You can use the dotnet parameter `--configuration-` to run either Debug or Release versions of the examples.
#### Unit tests
2019-01-30 03:12:43 +03:00
To build and run the .NET unit tests do:
2019-01-23 02:57:56 +03:00
````
2019-01-28 22:01:54 +03:00
cd dotnet/tests
2019-01-23 02:57:56 +03:00
dotnet test
cd ../..
````
All unit tests should pass. You can use the dotnet parameter `--configuration` to run Debug or Relase unit tests,
and you can use `--verbosity detailed` to print the list of unit tests that are being run.
2019-01-30 03:55:03 +03:00
### Using Microsoft SEAL for .NET in your own application
2019-01-23 02:57:56 +03:00
2019-01-30 03:12:43 +03:00
To use Microsoft SEAL for .NET in your own application you need to:
2019-01-23 02:57:56 +03:00
1. Add a reference in your project to SEALNet.dll
2. Ensure the shared native library is available for your application when run. The easiest way to ensure
2019-01-28 22:01:54 +03:00
this is to copy libsealnetnative.so to the same directory where your application's executable
2019-01-23 02:57:56 +03:00
is located.
In Linux or Mac OS, if you have root access to the system, you have the option to install the shared native
library globally. Then your application will always be able to find and load it.
To install the shared native library globally, do the following:
````
2019-01-28 22:01:54 +03:00
cd dotnet/native
cmake -DCMAKE_PREFIX_PATH=~/mylibs .
2019-01-23 02:57:56 +03:00
make
sudo make install
cd ../..
````
2018-12-01 04:41:23 +03:00
# Documentation
The code-base contains extensive and thoroughly commented examples that should
2019-01-30 03:55:03 +03:00
serve as a self-contained introduction to using SEAL (see `native/examples/examples.cpp` or `dotnet/examples/Examples.cs` ). In
2018-12-01 04:41:23 +03:00
addition, the header files contain detailed comments for the public API.