Microsoft SEAL bindings for Python
Project description
seal bindings
Microsoft SEAL bindings for Rust and Python
🌟 seal
FFI bindings from the famous SEAL library for Rust and Python. The main goal of this project is to provide a simple and fast way to install SEAL for both programming languages.
Built With
The SEAL bindings are a continuation from the seal_fhe crate, with the support for the CKKS scheme and the addition of new features like batch encoders, that allow us to overcome the size barriers of the ciphertext tensors and create AI applications easily with high-dimensional encrypted ciphertext.
Prerequisites
Currently, this crate is available only for a few architectures. Please, make sure that your operating system is compatible with any build that is working:
System | Support |
---|---|
MacOSX aarch6 | |
Linux x86_64 |
Instalation
Python
Make sure your OS is supported. If it is, just type:
pip install sealy
If the OS/Platform that you use it is not in the supported list, feel free too try to clone this project and build yourself locally.
Rust
cargo add sealy
Usage
Python
Here is a simple example of multiplying a ciphertext array to a plaintext array.
from sealy import (BFVEncoder, BfvEncryptionParametersBuilder, BFVEvaluator,
CoefficientModulus, Context, Decryptor, DegreeType,
Encryptor, KeyGenerator, PlainModulus, SecurityLevel)
params = (
BfvEncryptionParametersBuilder()
.with_poly_modulus_degree(DegreeType(8192))
.with_coefficient_modulus(
CoefficientModulus.create(DegreeType(8192), [50, 30, 30, 50, 50])
)
.with_plain_modulus(PlainModulus.batching(DegreeType(8192), 32))
.build()
)
ctx = Context(params, False, SecurityLevel(128))
gen = KeyGenerator(ctx)
encoder = BFVEncoder(ctx)
public_key = gen.create_public_key()
secret_key = gen.secret_key()
encryptor = Encryptor(ctx, public_key)
decryptor = Decryptor(ctx, secret_key)
evaluator = BFVEvaluator(ctx)
plaintext = [1, 2, 3]
factor = [2, 2, 2]
encoded_plaintext = encoder.encode(plaintext)
encoded_factor = encoder.encode(factor)
ciphertext = encryptor.encrypt(encoded_plaintext)
ciphertext_result = evaluator.multiply_plain(ciphertext, encoded_factor)
decrypted = decryptor.decrypt(ciphertext_result)
decoded = encoder.decode(decrypted)
print(decoded[:3]) # [2, 4, 6]
Rust
Equivalent code from above's example, written in rust:
use seal::{
BFVEncoder, BFVEvaluator, BfvEncryptionParametersBuilder, CoefficientModulus, Context,
Decryptor, DegreeType, Encoder, Encryptor, Evaluator, KeyGenerator, PlainModulus,
SecurityLevel,
};
fn main() -> anyhow::Result<()> {
let params = BfvEncryptionParametersBuilder::new()
.set_poly_modulus_degree(DegreeType::D8192)
.set_coefficient_modulus(
CoefficientModulus::create(DegreeType::D8192, &[50, 30, 30, 50, 50]).unwrap(),
)
.set_plain_modulus(PlainModulus::batching(DegreeType::D8192, 32)?)
.build()?;
let ctx = Context::new(¶ms, false, SecurityLevel::TC128)?;
let gen = KeyGenerator::new(&ctx)?;
let encoder = BFVEncoder::new(&ctx)?;
let public_key = gen.create_public_key();
let secret_key = gen.secret_key();
let encryptor = Encryptor::with_public_key(&ctx, &public_key)?;
let decryptor = Decryptor::new(&ctx, &secret_key)?;
let evaluator = BFVEvaluator::new(&ctx)?;
let plaintext: Vec<i64> = vec![1, 2, 3];
let factor = vec![2, 2, 2];
let encoded_plaintext = encoder.encode(&plaintext)?;
let encoded_factor = encoder.encode(&factor)?;
let ciphertext = encryptor.encrypt(&encoded_plaintext)?;
let ciphertext_result = evaluator.multiply_plain(&ciphertext, &encoded_factor)?;
let decrypted = decryptor.decrypt(&ciphertext_result)?;
let decoded = encoder.decode(&decrypted);
println!("{:?}", &decoded.into_iter().take(3).collect::<Vec<_>>()); // [2, 4, 6]
Ok(())
}
Roadmap
The project is in the early stages of development.
See the open issues for a list of issues and proposed features.
OBS: To propose new features or report bugs, check out the correct templates.
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for sealy-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9475ab5eebab0812b17ee6c527a2c3e73c8e003606e7673fce92f425a9ee35c |
|
MD5 | d1999ed44d08a61e0e03707889096ac2 |
|
BLAKE2b-256 | 28be6a796b1a4a404aa6f2ab038f2c5b671cb0fa5e7f6c5e578a230bbb0fa2dc |
Hashes for sealy-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98a585cf43bd4388dac052dc6301c1df6900b8cf7161c17f2821958e1be6de3c |
|
MD5 | e1dce454d39be48ba4447709cc772876 |
|
BLAKE2b-256 | 688c252405b72f1e8d743d8365581037a1a922dcc3273b0debc24080066ef696 |
Hashes for sealy-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea3e7a84c4162ac57375993e1c8a139fe14dd55d947cb8ed240a6ee2b07db708 |
|
MD5 | 047f06910bc36b88f84fffe5a4149a0f |
|
BLAKE2b-256 | 9c13b3ce03e197f907675244dc217e7058144ffa42519c06b3c6b57f402abf17 |
Hashes for sealy-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc39685d0b225e17b88407e09803e168d3851309a8afd0f454ff092b7762a105 |
|
MD5 | 7696cdf25e74ecabc422f9035c4310cf |
|
BLAKE2b-256 | 117433db1262643985f5edb943477772b8be8a5e00fb53c0e86ead32a14b8fd8 |
Hashes for sealy-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc072e5e2f66b282e144c260047c1e8995ef3079bb566e06a9bb53d4ad8da682 |
|
MD5 | 361edb556310f2926abb32540f055d31 |
|
BLAKE2b-256 | 88a0437d85be5732c0c1bcdc155b715453cf6bfb174eb57f9f380fec007a448a |
Hashes for sealy-0.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54b04843fb361b32102cfc41da03e56b89098b0f943cff18cb48a8f16eab491c |
|
MD5 | ffc7ae7c6a7b70dd7cd810c5937ae5b4 |
|
BLAKE2b-256 | 190be7080029ba3ec5b143b7880ee3816facf86fdfdc5206dcb2ea768ee7baa8 |