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

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

sealy-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (865.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

sealy-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (864.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

sealy-0.1.4-cp310-cp310-manylinux_2_34_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

sealy-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (864.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

sealy-0.1.4-cp39-cp39-macosx_11_0_arm64.whl (865.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: sealy-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 5bbddb00a4b03f6fd67644ef98c586e11f8d4cf55cb607318fd7a888f63dad08
MD5 bb6c6dec5eb2f43404b6f9b36b4fcbcb
BLAKE2b-256 3634840aa1136b48dbe15d53d0591e706d0b673fe785700443b7829b77e7a0b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ce7ff977d33aab25b0ff77519634b3297b04572f880d48ef29c623725ed6c133
MD5 14b8a67ec0db878c1f3262d72616b6eb
BLAKE2b-256 616b4cc4c56e4bee0398ad74f561377fb79000e90f9488b4af0d5c6f4fe57b6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0bd6638dd9f80262212685e6b39d9eb949a6469505248d00e897eba57f764bbc
MD5 f639715adfe8d8c3a5e76c978184bc76
BLAKE2b-256 92cdc8846e79ffce56e9b047dc8f089bd02f76a110bdaf46d227b4cd3d7c4198

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4ae0e539e7d295584383d6e809a7dd6640c8758f6e1f03ecd4ecfc34687ecb37
MD5 c6e2bbcb5648e1282d3cdecf580de007
BLAKE2b-256 748b2045d565ebd551b7766391b3241586a3e405aa12b9ffc88b5c3625029771

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.4-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2e722e0d3d0417fbf8b62e940109c3507ade83a696e01c2d815b24c527fa42e8
MD5 93c37b3a27b693dfbdb8c6966054f608
BLAKE2b-256 22d39131a47191c99e1035b6eb0e77d4ed7cd42734f427dcb25175b1bb61f828

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be610464a19b804860462a606ae229d45e4ff125e7a41547a40f8a001494348a
MD5 0395d5b685cab09a324853948e7c17c4
BLAKE2b-256 686f75a00a6193f971de0ca66fd136e20c4a0eadee463d68828e423bf276008d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c712f9393155f506b3effdbe6b492831450cd936b683e771913ac431d329a1cc
MD5 694f4817ff3fe7cd84cf4410960ee6a3
BLAKE2b-256 d1b6fc2f6fa4876cc07010745ebe7aa093f1c45e9a6a4ad32102fe84d67de3cf

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