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

Uploaded CPython 3.12macOS 11.0+ ARM64

sealy-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (780.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

sealy-0.1.1-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.1-cp310-cp310-macosx_11_0_arm64.whl (780.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

sealy-0.1.1-cp39-cp39-macosx_11_0_arm64.whl (782.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: sealy-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 cd22de2167999761607214230c6b7eb9c411bc7070ef9e5bf808621c4a5130d4
MD5 b7e4c2fe3e11e1a560e33b46363972f3
BLAKE2b-256 75380834f5df24b830b2fe48e79028c360eabb9e69d849a0c5dab87205861882

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b52477e08779ebfa8f4d26a4d405c764870e4d2d7f06ea5201f1d29ef4e3bf9f
MD5 8ef5874612de64a47b7ec9ad4e2a88f5
BLAKE2b-256 7b97c3d4ebb1a937c7982b821b28765e534e64baea5f7090da6925804d263b52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 589d9341eb19fe811d40d93bea380c4249880a4b30fd1dc9d1eb410026bfeae3
MD5 be3485f60500ae04c13f5254e083eb2b
BLAKE2b-256 1e157835190a802e1e9c019ab60aad23eb95ed6397a1511d3031b142f1a8ab98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3dde6d7c3dbaba68a07800d87ff7042972e7036dd8740e3093018a3dc30cfa22
MD5 2459673cb12e6974631ae9ac47b70d71
BLAKE2b-256 ce65437e849d4b9857ba29698e472a2adee78d4fd760053049c8c4bb2ec42d8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2ab8b1173e9a7cf96812cf9677673b6742fd9eccf7e9fb56fc7b5ec0ab582b48
MD5 96332df939adbae34e6bf7b5d468cc8d
BLAKE2b-256 4f8af6df08218132ee7435eb34da8d5fad07906ffdc9c363656f85d287b64dd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b40dd5ad7516f6269338cfccab82909fe371e62d994f0e205860d06d063b1b56
MD5 8eccc97949c0cf1f06b398fd4ea8014b
BLAKE2b-256 5c9bbb883e8228e3d13616c8675fc991dc5e11bcae6cc1e96983ffc80568dd5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sealy-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f9ecac314c1a9bd3ad7d8deeb46992f2505ce4f14a9d36134d32cba7b5fe24d
MD5 38b64d7b9a2817a5adbc6502d928b562
BLAKE2b-256 0f4906649ea79a424e7ad3c3fd5179ff17dd663f4a6f249c17c9c33f28d57b3e

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