Skip to main content

Crates.io PyPI CI


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 tensor 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 seal-w64
Linux x86_64 seal-w64

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_int(plaintext)
encoded_factor = encoder.encode_int(factor)

ciphertext = encryptor.encrypt(encoded_plaintext)
ciphertext_result = evaluator.multiply_plain(ciphertext, encoded_factor)

decrypted = decryptor.decrypt(ciphertext_result)
decoded = encoder.decode_int(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(&params, 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_u64(&plaintext)?;
	let encoded_factor = encoder.encode_u64(&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_u64(&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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Release files for sealy 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sealy 0.3.0
File Size Uploaded
sealy-0.3.0.tar.gz 5.3 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for sealy 0.3.0
File
sealy-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
sealy-0.3.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
sealy-0.3.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
sealy-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details
sealy-0.3.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
sealy-0.3.0-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details

Total release size: 10.7 MB

Release files / sealy-0.3.0.tar.gz

Download URL sealy-0.3.0.tar.gz
Size 5.3 MB
Tags Source
SHA-256 checksum
How to use checksums
7bb633be774f29433cf3083acbf10fce530e7d6b779535127d311107e2b20f8d
BLAKE2b-256 checksum
How to use checksums
ebe94870f7c420fa3bedcf15a9fc6c6700851dc59dc748fc57c93c37e630bdc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.7.4

Release files / sealy-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL sealy-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
Size 1.1 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
f18adc29bb1b10dbe2fd74e4c036a21da8f3258fa6238da0332f1027f04bad1d
BLAKE2b-256 checksum
How to use checksums
dba6e830a26ba9ebf7a66bc06496c1e7769574f664464de32976a862c539a9b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.7.4

Release files / sealy-0.3.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL sealy-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Size 817.3 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
dd0b7d983bd5d5c2c5b1c8f0d13302914ba697e9fc3efe0b9ae3217314475aab
BLAKE2b-256 checksum
How to use checksums
426e5c5243b2741c1999ec1698a77397a369ebabec31013df93eb488f07ee5e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.7.4

Release files / sealy-0.3.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL sealy-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Size 818.7 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
93a23546e6356445eb4150cb61ee3fe6d78244793ff568d6bab5d31ee3ec60b7
BLAKE2b-256 checksum
How to use checksums
e00ebfc0b670c1615eeb7b623d9f4dae84b9e10828366477953b2238d8949ded
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.7.4

Release files / sealy-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL sealy-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
872c2a4b5f2a4c042df0c15f903b4527acc45868e7be001343d9fcd0e48d9be5
BLAKE2b-256 checksum
How to use checksums
a6413123374877d75fb6e26f30bf368515ce938012793a64cd181cdd5ab5e559
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.7.4

Release files / sealy-0.3.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL sealy-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Size 818.8 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a58cf90223ca0092aee36fce20561c5b69e84239c82b332647a33279fb27362d
BLAKE2b-256 checksum
How to use checksums
509688d993bbf6d203ec311c17a5e9f1c72e144305d4fbe06034994aea69a0bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.7.4

Release files / sealy-0.3.0-cp39-cp39-macosx_11_0_arm64.whl

Download URL sealy-0.3.0-cp39-cp39-macosx_11_0_arm64.whl
Size 820.4 kB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
67d09a69ea32d03f0c6adde4fad1a01fdc394c1a2acf1334e7bd31474decb579
BLAKE2b-256 checksum
How to use checksums
04a0598d9aec298de55fe266eb7626b6f334c1ee4d0f9053a5bde5d07ac0168e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.7.4

Release history Release notifications | RSS feed

This release

0.3.0 This release

7 release files

0.2.0

7 release files

0.1.5

7 release files

0.1.4

7 release files

0.1.3

7 release files

0.1.2

7 release files

0.1.1

7 release files

0.1.0

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page