sealy


Namesealy JSON
Version 0.1.5 PyPI version JSON
download
home_pageNone
SummaryMicrosoft SEAL bindings for Python
upload_time2024-08-08 02:03:28
maintainerNone
docs_urlNone
authormarcosfpr <mfprezende@gmail.com>
requires_python>=3.8
licenseNone
keywords fhe homomorphic encryption ckks bfv seal ai machine-learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![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">SEALy</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>

## 🌟 SEALy

Microsoft SEAL bindings for Rust and Python.

SEALy is a project that aims to create 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 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](https://img.shields.io/badge/build-passing-brightgreen)](https://github.com/marcosfpr/sealy) |
| Linux x86_64  | [![sealy-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(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:

```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 -->

## 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/6c/8f/ee335fa4b570aaad2f0ef429f285ca8f6da1303f34b3325304c4afc08dc8/sealy-0.1.5.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\">SEALy</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 SEALy\n\nMicrosoft SEAL bindings for Rust and Python.\n\nSEALy is a project that aims to create 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.\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 batch 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 | [![sealy-w64](https://img.shields.io/badge/build-passing-brightgreen)](https://github.com/marcosfpr/sealy) |\n| Linux x86_64  | [![sealy-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(plaintext)\nencoded_factor = encoder.encode(factor)\n\nciphertext = encryptor.encrypt(encoded_plaintext)\nciphertext_result = evaluator.multiply_plain(ciphertext, encoded_factor)\n\ndecrypted = decryptor.decrypt(ciphertext_result)\ndecoded = encoder.decode(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 sealy::{\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(&params, 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(&plaintext)?;\n\tlet encoded_factor = encoder.encode(&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(&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.1.5",
    "project_urls": {
        "Changelog": "https://github.com/marcosfpr/sealy/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/marcosfpr/sealy/blob/main/README.md",
        "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": "2e02d5a64faf6ddf11446c317f42aeca0ae0cab9f420b4219752fc74c70b9c6a",
                "md5": "06e3d2a75b8a5e6b0500be5227a8bb96",
                "sha256": "7a2af9e452ac0e4187c308a96fd556cc0d90c54e6c0bf5e531043c6a49900ca5"
            },
            "downloads": -1,
            "filename": "sealy-0.1.5-cp310-cp310-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "06e3d2a75b8a5e6b0500be5227a8bb96",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.8",
            "size": 810537,
            "upload_time": "2024-08-08T02:03:22",
            "upload_time_iso_8601": "2024-08-08T02:03:22.402356Z",
            "url": "https://files.pythonhosted.org/packages/2e/02/d5a64faf6ddf11446c317f42aeca0ae0cab9f420b4219752fc74c70b9c6a/sealy-0.1.5-cp310-cp310-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0f576a18ba3b8867538c8ef09c3c70fe6a79e8134c1e4fdeccb699c62d956205",
                "md5": "5a4a6643a959d37404e24cd27e341e4b",
                "sha256": "f49e6081289bed1762455fadb88771b390a06e8ea43928c0ac73ea50d98c38b6"
            },
            "downloads": -1,
            "filename": "sealy-0.1.5-cp310-cp310-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "5a4a6643a959d37404e24cd27e341e4b",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.8",
            "size": 1801910,
            "upload_time": "2024-08-08T02:03:17",
            "upload_time_iso_8601": "2024-08-08T02:03:17.194340Z",
            "url": "https://files.pythonhosted.org/packages/0f/57/6a18ba3b8867538c8ef09c3c70fe6a79e8134c1e4fdeccb699c62d956205/sealy-0.1.5-cp310-cp310-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c4d4931cb0d8c6db579a3c19bb8e1b704288c75db37d9a6bd5d078e25d87b82e",
                "md5": "003c88a40f53fe96f3469a558773144f",
                "sha256": "0e54889be41236856ef4c77b8cc93608362da61df9ee4391073f3a7f7509e6f0"
            },
            "downloads": -1,
            "filename": "sealy-0.1.5-cp311-cp311-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "003c88a40f53fe96f3469a558773144f",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.8",
            "size": 810447,
            "upload_time": "2024-08-08T02:03:23",
            "upload_time_iso_8601": "2024-08-08T02:03:23.959618Z",
            "url": "https://files.pythonhosted.org/packages/c4/d4/931cb0d8c6db579a3c19bb8e1b704288c75db37d9a6bd5d078e25d87b82e/sealy-0.1.5-cp311-cp311-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4e8dc42e5ef45debe25381290b41d18ff0ff4de515b92593cd7bfc1d02459200",
                "md5": "d483725a3487c71a823de3d04df209b1",
                "sha256": "7c591644d9fd2bac965ec8aa0ce7bd77d19df0c22e5d0648d7d3dc3a69894930"
            },
            "downloads": -1,
            "filename": "sealy-0.1.5-cp312-cp312-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "d483725a3487c71a823de3d04df209b1",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 812220,
            "upload_time": "2024-08-08T02:03:25",
            "upload_time_iso_8601": "2024-08-08T02:03:25.229740Z",
            "url": "https://files.pythonhosted.org/packages/4e/8d/c42e5ef45debe25381290b41d18ff0ff4de515b92593cd7bfc1d02459200/sealy-0.1.5-cp312-cp312-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3395ba620f3e9de4541fdda409886626c0d02e973cebf2d688dc8373ec5db5b1",
                "md5": "fed55c3094f7e4c68b2436798275d6b8",
                "sha256": "c02ee275dc580dc8db5a5736607c9673a9238160ea9d6bef31aee0816bbf556c"
            },
            "downloads": -1,
            "filename": "sealy-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "fed55c3094f7e4c68b2436798275d6b8",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 1803529,
            "upload_time": "2024-08-08T02:03:20",
            "upload_time_iso_8601": "2024-08-08T02:03:20.492889Z",
            "url": "https://files.pythonhosted.org/packages/33/95/ba620f3e9de4541fdda409886626c0d02e973cebf2d688dc8373ec5db5b1/sealy-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f7e6c57d36333419ed3d36798d0a732bb91e38b250fc24fb8d429173d2e08644",
                "md5": "ce896c30b1eb0c8187bc026743c7f834",
                "sha256": "d1b09b3005563f5faa9a4098573736483037a6d074124bba4ef589f860dbf2ce"
            },
            "downloads": -1,
            "filename": "sealy-0.1.5-cp39-cp39-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "ce896c30b1eb0c8187bc026743c7f834",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.8",
            "size": 811465,
            "upload_time": "2024-08-08T02:03:26",
            "upload_time_iso_8601": "2024-08-08T02:03:26.864264Z",
            "url": "https://files.pythonhosted.org/packages/f7/e6/c57d36333419ed3d36798d0a732bb91e38b250fc24fb8d429173d2e08644/sealy-0.1.5-cp39-cp39-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6c8fee335fa4b570aaad2f0ef429f285ca8f6da1303f34b3325304c4afc08dc8",
                "md5": "a0f1b4599855102169e8ed147159da32",
                "sha256": "8528644b0503c92d1044d29405cae7603dd9843a383452b65de7ec949c196d22"
            },
            "downloads": -1,
            "filename": "sealy-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "a0f1b4599855102169e8ed147159da32",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 5338711,
            "upload_time": "2024-08-08T02:03:28",
            "upload_time_iso_8601": "2024-08-08T02:03:28.246214Z",
            "url": "https://files.pythonhosted.org/packages/6c/8f/ee335fa4b570aaad2f0ef429f285ca8f6da1303f34b3325304c4afc08dc8/sealy-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-08 02:03:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "marcosfpr",
    "github_project": "sealy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sealy"
}
        
Elapsed time: 0.40835s