palisade-crypto
v0.0.1
Published
JS bindings for Palisade Homomorphic Encryption Library
Downloads
3
Readme
General information
palisade-wasm is the official web-assembly port of the PALISADE homomorphic library. palisade-wasm supports all homomorphic encryption schemes supported by PALISADE and exposes an API similar to the C++ API for PALISADE.
All versions of PALISADE starting with v1.11.3 are supported.
palisade-wasm is licensed under the BSD-3 license.
Notes specific to palisade-wasm
- The
palisade-wasmport is somewhat slower than the C++ version of PALISADE due to a normal slowdown incurred in web assembly builds (typically 2x) and additional slow-down due to the use of 64-bit arithmetic in PALISADE (64-bit arithmetic is emulated in WASM). - We optimized
palisade-wasmforBGVrns,CKKS, andFHEWschemes. The users should typically expect a slowdown of 2x-3x as compared toclangbuilds and about 4x-5x as compared togccbuilds. - We did not optimize
BFVrnsandBFVrnsB. So a more significant slowdown is expected for some operations in these schemes, specifically the homomorphic multplication. We recommend usingBGVrnsinstead ofBFVrnsandBFVrnsBin use cases where homomorphic computations usingpalisade-wasmneed to be performed. In scenarios where only client operations, i.e., key generation, encryption, and decryption, are needed, either scheme can be used. - Web assembly running environment is typically limited to 4GB of RAM.
palisade-wasmdoes not currently support multi-threading.
Examples
palisade-wasm comes with the following examples, which are the JS versions of selected C++ PALISADE examples:
- boolean.js: shows an example of Boolean circuit evaluation using FHEW (in the TFHE/GINX mode)
- boolean_serial_binary.js: shows an example with serialization/deserialization of Boolean circuit evaluation using FHEW (in the TFHE/GINX mode)
- pre_buffer.js: demonstrates use of PALISADE for encryption, proxy re-encryption and decryption of packed vector of binary data
- simple_integer.js: simple example showing homomorphic additions, multiplications, and rotations for vectors of integers using BFVrns
- simple_integer_bgvrns.js: simple example showing homomorphic additions, multiplications, and rotations for vectors of integers using BGVrns
- simple_integer_serial_buffer.js: simple example showing typical serialization/deserialization calls for a prototype computing homomorphic additions, multiplications, and rotations for vectors of integers using BFVrns
- simple_real_numbers.js: simple example showing homomorphic additions, multiplications, and rotations for vectors of real numbers using CKKS
- threshold_fhe.js: shows several examples of threshold FHE in BGVrns, BFVrns, and CKKS
Build instructions from source
- Install
emscriptenusing the instructions at https://emscripten.org/docs/getting_started/downloads.html. - Install
NodeJsif not already installed. - Clone PALISADE either from https://gitlab.com/palisade/palisade-development or https://gitlab.com/palisade/palisade-release.
- Cd to the PALISADE folder (either
palisade-developmentorpalisade-release) and createembuilddirectory. - Run
export PREFIX=~/install/location
mkdir embuild
cd embuild
emcmake cmake .. -DCMAKE_INSTALL_PREFIX=${PREFIX}
emmake make -jNWhere N is number of cores available.
to do the cmake configuration. Here, ~/install/location can be replaced with any empty directory at the desired location where palisade binaries should be installed.
- Run
emmake make installto install the binaries in the desired location.
To include the unit tests, examples, or benchmarks, the corresponding cmake flags can be set to "ON" instead of "OFF".
Clone the
palisade-wasmrepository and cd topalisade-wasm.Run the following commands to build the NodeJS bindings.
mkdir build
cd build
emcmake cmake .. -DPalisade_DIR=${PREFIX}/lib/Palisade
emmake makeThis should install emscripten libraries in palisade-wasm/lib directory.
- Now run the examples in the following directories using
nodejs
- examples/js/binfhe/
- examples/js/pke/
Running web-assembly unit tests
Compile PALISADE in the embuild directory using the following CMake flags
emcmake cmake .. -DBUILD_UNITTESTS=ON -DCMAKE_INSTALL_PREFIX=~/install/locationRun unit tests using nodejs:
nodejs unittest/binfhe_tests.js
nodejs unittest/pke_tests.jsRunning web-assembly benchmarks
Compile PALISADE in the embuild directory using the following CMake flags
emcmake cmake .. -DBUILD_BENCHMARKS=ON -DCMAKE_INSTALL_PREFIX=~/install/locationRun benchmarks using nodejs, e.g.,
nodejs benchmark/lib-benchmark.jsTypescript Development
For usage examples, we would like to test our code using the same import syntax
as any other user.
To achieve this, run npm link followed by npm link palisade-crypto.
Building
To build the distributed package, run npm run build_package
followed by npm pack
