Skip to main content

Microsoft SEAL bindings for Python

Project description

Crates.io PyPI CI


SEALy

Microsoft SEAL bindings for Rust and Python

🌟 SEALy

Microsoft SEAL bindings for Rust and Python.

SEALy is a project that aims to create 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 sealy-w64
Linux x86_64 sealy-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(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 sealy::{
	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(&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.

  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

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

sealy-0.1.3.tar.gz (5.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sealy-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

sealy-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (809.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

sealy-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (808.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

sealy-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

sealy-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (808.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

sealy-0.1.3-cp39-cp39-macosx_11_0_arm64.whl (809.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file sealy-0.1.3.tar.gz.

File metadata

  • Download URL: sealy-0.1.3.tar.gz
  • Upload date:
  • Size: 5.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.7.0

File hashes

Hashes for sealy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8eb3e887aa0e25bc84bdc32382580484b3b7119f84ac20c452af51dafc16ed09
MD5 2e760505bda293b5fbf2401d1aecde75
BLAKE2b-256 f2478276c4ab1cdd110cd2cdb6ebf99228fad1db645b051392071b694ad9a014

See more details on using hashes here.

File details

Details for the file sealy-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for sealy-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3205ec6767376518d33e9059cc7f33c9cd9e28d05526e93a79f24d64e8411078
MD5 bc6c474530ed731b9afc5afa9ef73de5
BLAKE2b-256 026cebd95c6d9487942efe9877617a62899ae82b5daed182708e3e30bd1b153c

See more details on using hashes here.

File details

Details for the file sealy-0.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sealy-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1254c312b59c88b45c36bec48aee56bb23b5b468a330a42fa0cf4b9e89b28afb
MD5 09bbccdec5540cd560a947dfb5d3c69a
BLAKE2b-256 128925cd321a6f445779d0b29e620ce05305b65c37b96332d23939dc57df9058

See more details on using hashes here.

File details

Details for the file sealy-0.1.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sealy-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3efe57fe8630a4b32c17f521fe80bf458281fc165977388cf0af6b9821402a6
MD5 04bc645473df4104d0250cc01cbdf247
BLAKE2b-256 027d15e7163efdd4e9b7760bcce334c5327e7f861377c8d3cc7fe75685f20e69

See more details on using hashes here.

File details

Details for the file sealy-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for sealy-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9e3e3a3e6ee1193780d991b98c2a6398907a0d6e2bb0328e01b1c7986da10444
MD5 23e16d83b66e31e96c0c5405eda58d5c
BLAKE2b-256 ccaf2f2d15c91c0abeb039adb32fbb2ede901c6439a74dca58c6d8edc725d9c8

See more details on using hashes here.

File details

Details for the file sealy-0.1.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sealy-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f967e96cc17da326e166f2bc696f5b2ee4e9fc2cf6445c3ede301f8817b11a5
MD5 85a2c43884c94646b56c7a696c4da26a
BLAKE2b-256 bf25c89a55fd7ace40a77ae188f940131357cc7883414655da37281045a9fb4a

See more details on using hashes here.

File details

Details for the file sealy-0.1.3-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sealy-0.1.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26e2faefe7ba6e54bdefab240770bcb59f15ce2e20aaba70853ed2e8163e18b2
MD5 49dabdd018d0d422069dfc85b46a9332
BLAKE2b-256 1da72b8c9c76ec79077187d1fb78401ef0a97e0f62fa4e962493b62bc2776fd9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page