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.2.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.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (805.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

sealy-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (803.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

sealy-0.1.2-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.2-cp310-cp310-macosx_11_0_arm64.whl (803.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

sealy-0.1.2-cp39-cp39-macosx_11_0_arm64.whl (804.7 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for sealy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 410bfffc56071a4725090e7904f52def53227187510d4ac5c8e288a698759293
MD5 a3463a6994f48c2dca7c3d249a6d0be9
BLAKE2b-256 c6bb46d67b8f25976b3f6c4e2d743fbd76356e530893a29f0ac5b0ce46f8ec0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5a7a1a0ddd80ec2cfa3c6369b680fa584f5f1cc1210c7f1224464b5459db3802
MD5 623dc29e3e2e414ed2690888ba2b2f50
BLAKE2b-256 ecd6d987db2e683b7336499086440c7f78ef14b7420604c2b967d3332caf69ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a72946b35c0a251ab5c6166553f8548783a1814704e94b49166f654f9da51801
MD5 6fbae3b15d7a11b82a80ea9650cbba1f
BLAKE2b-256 4f227520d32697c740f88126ac23e9d0cb5e15c6aea1319dcd86e395a750bb27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9174e3f64b841d4a791e7434c70751d6cb21b7c0f0f162501aa08a7c2c862e3
MD5 523c1a72240c4a4936838769610287f3
BLAKE2b-256 508f0c2afb6d4e3fdeea093e6a0c930967b2db734ea993a52a252f05b9a5f92b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 605b0e2ee506aad2575641a2d1d5d56be2e1af9285b7bfb4198d97059c563181
MD5 939d44abc97663787c9d0dd2cd0a2f48
BLAKE2b-256 ee7b8091e76480b44b8c7edde11158f4a1f1eb110a09e048abf5e722acb58d4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0fb37660655d886c808c1bea3f4fc727353c3a38be49dec0ad52117b0d75d126
MD5 06d17ce727170ec12b3851e69930fba4
BLAKE2b-256 5e6fad73f1b0082e3e796fd929b002a47feb1a6c4592db11d959d810e877c772

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f8ce830574d9a16aa45cbcaf4b2e7ed76039fde7b944868a1a9ab1b6d87f801
MD5 5d1773bf4a2ace668a7c487300be80d8
BLAKE2b-256 9cfc7a49ba81a40d531e00c85ff7297d91f447e220bc1bcebe7a88fd20100283

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