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.5.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.5-cp312-cp312-manylinux_2_34_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

sealy-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (812.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

sealy-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (810.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

sealy-0.1.5-cp310-cp310-manylinux_2_34_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

sealy-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (810.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

sealy-0.1.5-cp39-cp39-macosx_11_0_arm64.whl (811.5 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: sealy-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 8528644b0503c92d1044d29405cae7603dd9843a383452b65de7ec949c196d22
MD5 a0f1b4599855102169e8ed147159da32
BLAKE2b-256 6c8fee335fa4b570aaad2f0ef429f285ca8f6da1303f34b3325304c4afc08dc8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c02ee275dc580dc8db5a5736607c9673a9238160ea9d6bef31aee0816bbf556c
MD5 fed55c3094f7e4c68b2436798275d6b8
BLAKE2b-256 3395ba620f3e9de4541fdda409886626c0d02e973cebf2d688dc8373ec5db5b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c591644d9fd2bac965ec8aa0ce7bd77d19df0c22e5d0648d7d3dc3a69894930
MD5 d483725a3487c71a823de3d04df209b1
BLAKE2b-256 4e8dc42e5ef45debe25381290b41d18ff0ff4de515b92593cd7bfc1d02459200

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e54889be41236856ef4c77b8cc93608362da61df9ee4391073f3a7f7509e6f0
MD5 003c88a40f53fe96f3469a558773144f
BLAKE2b-256 c4d4931cb0d8c6db579a3c19bb8e1b704288c75db37d9a6bd5d078e25d87b82e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.5-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f49e6081289bed1762455fadb88771b390a06e8ea43928c0ac73ea50d98c38b6
MD5 5a4a6643a959d37404e24cd27e341e4b
BLAKE2b-256 0f576a18ba3b8867538c8ef09c3c70fe6a79e8134c1e4fdeccb699c62d956205

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a2af9e452ac0e4187c308a96fd556cc0d90c54e6c0bf5e531043c6a49900ca5
MD5 06e3d2a75b8a5e6b0500be5227a8bb96
BLAKE2b-256 2e02d5a64faf6ddf11446c317f42aeca0ae0cab9f420b4219752fc74c70b9c6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d1b09b3005563f5faa9a4098573736483037a6d074124bba4ef589f860dbf2ce
MD5 ce896c30b1eb0c8187bc026743c7f834
BLAKE2b-256 f7e6c57d36333419ed3d36798d0a732bb91e38b250fc24fb8d429173d2e08644

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