[![Crates.io][crates-badge]][crates-url]
[![PyPI][pypi-badge]][pypi-url]
[![CI][ci-badge]][ci-url]
[crates-badge]: https://img.shields.io/crates/v/sealy.svg
[crates-url]: https://crates.io/crates/sealy
[pypi-badge]: https://img.shields.io/pypi/pyversions/sealy
[pypi-url]: https://pypi.org/project/sealy/
[ci-badge]: https://img.shields.io/github/actions/workflow/status/marcosfpr/sealy/pypublish.yml
[ci-url]: https://github.com/marcosfpr/sealy/actions?query=+branch%3Amain
<br />
<p align="center">
<h3 align="center">seal bindings</h3>
<p align="center">
<a href="https://www.microsoft.com/en-us/research/project/microsoft-seal"><strong>Microsoft SEAL bindings for Rust and Python</strong></a>
<br />
</p>
</p>
## 🌟 seal
FFI bindings from the famous [SEAL](https://github.com/microsoft/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](https://github.com/sunscreen-tech/sunscreen/tree/d9f64f4283b7a4471dd0247b6f5ef769051a649f/seal_fhe) crate, with the support for the CKKS scheme and the addition of new features like tensor 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 | [![seal-w64](https://img.shields.io/badge/build-passing-brightgreen)](https://github.com/marcosfpr/sealy) |
| Linux x86_64 | [![seal-w64](https://img.shields.io/badge/build-passing-brightgreen)](https://github.com/marcosfpr/sealy) |
### Instalation
#### Python
Make sure your OS is supported. If it is, just type:
```sh
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.
```python
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_int(plaintext)
encoded_factor = encoder.encode_int(factor)
ciphertext = encryptor.encrypt(encoded_plaintext)
ciphertext_result = evaluator.multiply_plain(ciphertext, encoded_factor)
decrypted = decryptor.decrypt(ciphertext_result)
decoded = encoder.decode_int(decrypted)
print(decoded[:3]) # [2, 4, 6]
```
#### Rust
Equivalent code from above's example, written in rust:
```rust
use seal::{
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(¶ms, 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_u64(&plaintext)?;
let encoded_factor = encoder.encode_u64(&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_u64(&decrypted);
println!("{:?}", &decoded.into_iter().take(3).collect::<Vec<_>>()); // [2, 4, 6]
Ok(())
}
```
<!-- ROADMAP -->
## Roadmap
The project is in the early stages of development.
See the [open issues](https://github.com/marcosfpr/sealy/issues) for a list of issues and proposed features.
**OBS**: To propose new features or report bugs, check out the correct templates.
<!-- CONTRIBUTING -->
## 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
Raw data
{
"_id": null,
"home_page": null,
"name": "sealy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "marcos pontes <mfprezende@gmail.com>",
"keywords": "fhe, homomorphic, encryption, ckks, bfv, seal, ai, machine-learning",
"author": "marcosfpr <mfprezende@gmail.com>",
"author_email": "marcos pontes <mfprezende@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/eb/e9/4870f7c420fa3bedcf15a9fc6c6700851dc59dc748fc57c93c37e630bdc0/sealy-0.3.0.tar.gz",
"platform": null,
"description": "[![Crates.io][crates-badge]][crates-url]\n[![PyPI][pypi-badge]][pypi-url]\n[![CI][ci-badge]][ci-url]\n\n[crates-badge]: https://img.shields.io/crates/v/sealy.svg\n[crates-url]: https://crates.io/crates/sealy\n[pypi-badge]: https://img.shields.io/pypi/pyversions/sealy\n[pypi-url]: https://pypi.org/project/sealy/\n[ci-badge]: https://img.shields.io/github/actions/workflow/status/marcosfpr/sealy/pypublish.yml\n[ci-url]: https://github.com/marcosfpr/sealy/actions?query=+branch%3Amain\n\n<br />\n<p align=\"center\">\n <h3 align=\"center\">seal bindings</h3>\n\n <p align=\"center\">\n <a href=\"https://www.microsoft.com/en-us/research/project/microsoft-seal\"><strong>Microsoft SEAL bindings for Rust and Python</strong></a>\n <br />\n </p>\n</p>\n\n## \ud83c\udf1f seal\n\nFFI bindings from the famous [SEAL](https://github.com/microsoft/SEAL) library for Rust and Python. \nThe main goal of this project is to provide a simple and fast way to install SEAL for both programming languages.\n\n### Built With\n\nThe SEAL bindings are a continuation from the [seal_fhe](https://github.com/sunscreen-tech/sunscreen/tree/d9f64f4283b7a4471dd0247b6f5ef769051a649f/seal_fhe) crate, with the support for the CKKS scheme and the addition of new features like tensor encoders, that allow us to overcome the size barriers of the ciphertext tensors and create AI applications easily with high-dimensional encrypted ciphertext.\n\n### Prerequisites\n\nCurrently, this crate is available only for a few architectures. Please, make sure that your operating system is compatible with any build that is working:\n\n| System | Support |\n| :-----------: | :--------------------------------------------------------------------------------------------------------: |\n| MacOSX aarch6 | [![seal-w64](https://img.shields.io/badge/build-passing-brightgreen)](https://github.com/marcosfpr/sealy) |\n| Linux x86_64 | [![seal-w64](https://img.shields.io/badge/build-passing-brightgreen)](https://github.com/marcosfpr/sealy) |\n\n### Instalation\n\n#### Python\n\nMake sure your OS is supported. If it is, just type:\n\n```sh\npip install sealy\n```\n\nIf 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.\n\n#### Rust\n\n```\ncargo add sealy\n```\n\n### Usage\n\n#### Python\n\nHere is a simple example of multiplying a ciphertext array to a plaintext array.\n\n```python\nfrom sealy import (BFVEncoder, BfvEncryptionParametersBuilder, BFVEvaluator,\n CoefficientModulus, Context, Decryptor, DegreeType,\n Encryptor, KeyGenerator, PlainModulus, SecurityLevel)\n\nparams = (\n BfvEncryptionParametersBuilder()\n .with_poly_modulus_degree(DegreeType(8192))\n .with_coefficient_modulus(\n CoefficientModulus.create(DegreeType(8192), [50, 30, 30, 50, 50])\n )\n .with_plain_modulus(PlainModulus.batching(DegreeType(8192), 32))\n .build()\n)\n\nctx = Context(params, False, SecurityLevel(128))\ngen = KeyGenerator(ctx)\n\nencoder = BFVEncoder(ctx)\n\npublic_key = gen.create_public_key()\nsecret_key = gen.secret_key()\n\nencryptor = Encryptor(ctx, public_key)\ndecryptor = Decryptor(ctx, secret_key)\nevaluator = BFVEvaluator(ctx)\n\nplaintext = [1, 2, 3]\nfactor = [2, 2, 2]\n\nencoded_plaintext = encoder.encode_int(plaintext)\nencoded_factor = encoder.encode_int(factor)\n\nciphertext = encryptor.encrypt(encoded_plaintext)\nciphertext_result = evaluator.multiply_plain(ciphertext, encoded_factor)\n\ndecrypted = decryptor.decrypt(ciphertext_result)\ndecoded = encoder.decode_int(decrypted)\n\nprint(decoded[:3]) # [2, 4, 6]\n```\n\n#### Rust\n\nEquivalent code from above's example, written in rust:\n\n```rust\nuse seal::{\n\tBFVEncoder, BFVEvaluator, BfvEncryptionParametersBuilder, CoefficientModulus, Context,\n\tDecryptor, DegreeType, Encoder, Encryptor, Evaluator, KeyGenerator, PlainModulus,\n\tSecurityLevel,\n};\n\nfn main() -> anyhow::Result<()> {\n\tlet params = BfvEncryptionParametersBuilder::new()\n\t\t.set_poly_modulus_degree(DegreeType::D8192)\n\t\t.set_coefficient_modulus(\n\t\t\tCoefficientModulus::create(DegreeType::D8192, &[50, 30, 30, 50, 50]).unwrap(),\n\t\t)\n\t\t.set_plain_modulus(PlainModulus::batching(DegreeType::D8192, 32)?)\n\t\t.build()?;\n\n\tlet ctx = Context::new(¶ms, false, SecurityLevel::TC128)?;\n\tlet gen = KeyGenerator::new(&ctx)?;\n\n\tlet encoder = BFVEncoder::new(&ctx)?;\n\n\tlet public_key = gen.create_public_key();\n\tlet secret_key = gen.secret_key();\n\n\tlet encryptor = Encryptor::with_public_key(&ctx, &public_key)?;\n\tlet decryptor = Decryptor::new(&ctx, &secret_key)?;\n\tlet evaluator = BFVEvaluator::new(&ctx)?;\n\n\tlet plaintext: Vec<i64> = vec![1, 2, 3];\n\tlet factor = vec![2, 2, 2];\n\n\tlet encoded_plaintext = encoder.encode_u64(&plaintext)?;\n\tlet encoded_factor = encoder.encode_u64(&factor)?;\n\n\tlet ciphertext = encryptor.encrypt(&encoded_plaintext)?;\n\tlet ciphertext_result = evaluator.multiply_plain(&ciphertext, &encoded_factor)?;\n\n\tlet decrypted = decryptor.decrypt(&ciphertext_result)?;\n\tlet decoded = encoder.decode_u64(&decrypted);\n\n\tprintln!(\"{:?}\", &decoded.into_iter().take(3).collect::<Vec<_>>()); // [2, 4, 6]\n\n\tOk(())\n}\n```\n\n<!-- ROADMAP -->\n\n## Roadmap\n\nThe project is in the early stages of development.\n\nSee the [open issues](https://github.com/marcosfpr/sealy/issues) for a list of issues and proposed features.\n\n**OBS**: To propose new features or report bugs, check out the correct templates.\n\n<!-- CONTRIBUTING -->\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Microsoft SEAL bindings for Python",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/marcosfpr/sealy",
"Repository": "https://github.com/marcosfpr/sealy"
},
"split_keywords": [
"fhe",
" homomorphic",
" encryption",
" ckks",
" bfv",
" seal",
" ai",
" machine-learning"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "509688d993bbf6d203ec311c17a5e9f1c72e144305d4fbe06034994aea69a0bc",
"md5": "554b39b30ffd84ffaa88d15c12e195c0",
"sha256": "a58cf90223ca0092aee36fce20561c5b69e84239c82b332647a33279fb27362d"
},
"downloads": -1,
"filename": "sealy-0.3.0-cp310-cp310-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "554b39b30ffd84ffaa88d15c12e195c0",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.8",
"size": 818771,
"upload_time": "2024-10-22T23:22:35",
"upload_time_iso_8601": "2024-10-22T23:22:35.005915Z",
"url": "https://files.pythonhosted.org/packages/50/96/88d993bbf6d203ec311c17a5e9f1c72e144305d4fbe06034994aea69a0bc/sealy-0.3.0-cp310-cp310-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a6413123374877d75fb6e26f30bf368515ce938012793a64cd181cdd5ab5e559",
"md5": "db0f2f07ada27f477cb3a58a6e0bfeb7",
"sha256": "872c2a4b5f2a4c042df0c15f903b4527acc45868e7be001343d9fcd0e48d9be5"
},
"downloads": -1,
"filename": "sealy-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl",
"has_sig": false,
"md5_digest": "db0f2f07ada27f477cb3a58a6e0bfeb7",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.8",
"size": 1057229,
"upload_time": "2024-10-22T23:22:30",
"upload_time_iso_8601": "2024-10-22T23:22:30.071812Z",
"url": "https://files.pythonhosted.org/packages/a6/41/3123374877d75fb6e26f30bf368515ce938012793a64cd181cdd5ab5e559/sealy-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e00ebfc0b670c1615eeb7b623d9f4dae84b9e10828366477953b2238d8949ded",
"md5": "2978f63a5c0e76c8439d1b63a84739a4",
"sha256": "93a23546e6356445eb4150cb61ee3fe6d78244793ff568d6bab5d31ee3ec60b7"
},
"downloads": -1,
"filename": "sealy-0.3.0-cp311-cp311-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "2978f63a5c0e76c8439d1b63a84739a4",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.8",
"size": 818743,
"upload_time": "2024-10-22T23:22:36",
"upload_time_iso_8601": "2024-10-22T23:22:36.944369Z",
"url": "https://files.pythonhosted.org/packages/e0/0e/bfc0b670c1615eeb7b623d9f4dae84b9e10828366477953b2238d8949ded/sealy-0.3.0-cp311-cp311-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "426e5c5243b2741c1999ec1698a77397a369ebabec31013df93eb488f07ee5e2",
"md5": "8df52b4555b0600e396fbe0bf488a552",
"sha256": "dd0b7d983bd5d5c2c5b1c8f0d13302914ba697e9fc3efe0b9ae3217314475aab"
},
"downloads": -1,
"filename": "sealy-0.3.0-cp312-cp312-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "8df52b4555b0600e396fbe0bf488a552",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.8",
"size": 817281,
"upload_time": "2024-10-22T23:22:39",
"upload_time_iso_8601": "2024-10-22T23:22:39.143057Z",
"url": "https://files.pythonhosted.org/packages/42/6e/5c5243b2741c1999ec1698a77397a369ebabec31013df93eb488f07ee5e2/sealy-0.3.0-cp312-cp312-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "dba6e830a26ba9ebf7a66bc06496c1e7769574f664464de32976a862c539a9b3",
"md5": "b407bb5760b754277d8fd93b7893125c",
"sha256": "f18adc29bb1b10dbe2fd74e4c036a21da8f3258fa6238da0332f1027f04bad1d"
},
"downloads": -1,
"filename": "sealy-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl",
"has_sig": false,
"md5_digest": "b407bb5760b754277d8fd93b7893125c",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.8",
"size": 1058636,
"upload_time": "2024-10-22T23:22:32",
"upload_time_iso_8601": "2024-10-22T23:22:32.659152Z",
"url": "https://files.pythonhosted.org/packages/db/a6/e830a26ba9ebf7a66bc06496c1e7769574f664464de32976a862c539a9b3/sealy-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "04a0598d9aec298de55fe266eb7626b6f334c1ee4d0f9053a5bde5d07ac0168e",
"md5": "7e969446d95165fdc30080b365ee2648",
"sha256": "67d09a69ea32d03f0c6adde4fad1a01fdc394c1a2acf1334e7bd31474decb579"
},
"downloads": -1,
"filename": "sealy-0.3.0-cp39-cp39-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "7e969446d95165fdc30080b365ee2648",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.8",
"size": 820358,
"upload_time": "2024-10-22T23:22:40",
"upload_time_iso_8601": "2024-10-22T23:22:40.986960Z",
"url": "https://files.pythonhosted.org/packages/04/a0/598d9aec298de55fe266eb7626b6f334c1ee4d0f9053a5bde5d07ac0168e/sealy-0.3.0-cp39-cp39-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ebe94870f7c420fa3bedcf15a9fc6c6700851dc59dc748fc57c93c37e630bdc0",
"md5": "7107d01a3ffecc7779b44d508b657ac2",
"sha256": "7bb633be774f29433cf3083acbf10fce530e7d6b779535127d311107e2b20f8d"
},
"downloads": -1,
"filename": "sealy-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "7107d01a3ffecc7779b44d508b657ac2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 5342990,
"upload_time": "2024-10-22T23:22:43",
"upload_time_iso_8601": "2024-10-22T23:22:43.209249Z",
"url": "https://files.pythonhosted.org/packages/eb/e9/4870f7c420fa3bedcf15a9fc6c6700851dc59dc748fc57c93c37e630bdc0/sealy-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-22 23:22:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "marcosfpr",
"github_project": "sealy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sealy"
}