Skip to main content

Shamir secret sharing based MRE crypto provider for Swarmauri

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_mre_crypto_shamir


swarmauri_mre_crypto_shamir

Shamir Secret Sharing based multi-recipient encryption (MRE) provider for the Swarmauri framework. The provider splits an AES-256-GCM content encryption key using Shamir's threshold scheme and distributes shares to recipients.

Features

  • AES-256-GCM payload encryption
  • Threshold k-of-n key sharing via Shamir secret sharing
  • Envelope rewrapping with optional payload rotation
  • Optional authenticated data (AAD) handling

Extras

The plugin supports optional canonicalization extras:

  • cbor – enables CBOR canonicalization via cbor2

Installation

Choose the tool that matches your workflow:

# pip
pip install swarmauri_mre_crypto_shamir

# Poetry
poetry add swarmauri_mre_crypto_shamir

# uv (project dependency)
uv add swarmauri_mre_crypto_shamir

# uv (one-off virtual environment)
uv pip install swarmauri_mre_crypto_shamir

Install extras, such as CBOR canonicalization support, with swarmauri_mre_crypto_shamir[cbor].

Quickstart

ShamirMreCrypto encrypts a payload with a fresh AES-256-GCM content encryption key, splits the key into Shamir shares, and stores the encrypted payload and shares in a multi-recipient envelope. Provide a threshold with opts["threshold_k"] (defaults to a simple majority) to control how many shares are required to decrypt.

import asyncio

from swarmauri_mre_crypto_shamir import ShamirMreCrypto


async def main() -> None:
    provider = ShamirMreCrypto()

    recipients = [
        {"kid": "alice"},
        {"kid": "bob"},
        {"kid": "carol"},
    ]

    plaintext = b"Secret launch codes"

    envelope = await provider.encrypt_for_many(
        recipients,
        plaintext,
        opts={"threshold_k": 2},
    )

    print("Mode:", envelope["mode"])
    print("Recipients:", [entry["id"] for entry in envelope["recipients"]])
    print(
        "Threshold:",
        int.from_bytes(envelope["shared"]["threshold_k"], "big"),
    )

    recovered = await provider.open_for_many(
        [{"kid": "alice"}, {"kid": "carol"}],
        envelope,
    )

    assert recovered == plaintext
    print("Recovered plaintext:", recovered.decode("utf-8"))


if __name__ == "__main__":
    asyncio.run(main())

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

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

swarmauri_mre_crypto_shamir-0.2.0.dev33.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_mre_crypto_shamir-0.2.0.dev33.tar.gz.

File metadata

  • Download URL: swarmauri_mre_crypto_shamir-0.2.0.dev33.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_mre_crypto_shamir-0.2.0.dev33.tar.gz
Algorithm Hash digest
SHA256 8cc5522c8a05a50c54db56033a87d273a9751bcfbc226375b253ccccd47b6345
MD5 861cfe07a278bf2e0034529ae4b46029
BLAKE2b-256 fe30a6907956d9d2bb72069994fa399cd56ec209df647d2af7e194b94a90212d

See more details on using hashes here.

File details

Details for the file swarmauri_mre_crypto_shamir-0.2.0.dev33-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_mre_crypto_shamir-0.2.0.dev33-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_mre_crypto_shamir-0.2.0.dev33-py3-none-any.whl
Algorithm Hash digest
SHA256 74bf1cb6a91ddc1078bb52833f5ad345fa59606518eb80af610a37493e9441d5
MD5 da54acfe6f0cfc0c8edd5b5bd74d41e3
BLAKE2b-256 a71d75f9efa77f52ddb68ed49b738a330868dceef44b89b91356099b34410a1d

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