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.dev44.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.dev44.tar.gz.

File metadata

  • Download URL: swarmauri_mre_crypto_shamir-0.2.0.dev44.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.dev44.tar.gz
Algorithm Hash digest
SHA256 c03cbf1b5a51d24bebe2dabb8831a64fffbe49f4bbca6cfc7b7162edbc37a6cf
MD5 ae8488204440771e66fb4bcc15b2c1d3
BLAKE2b-256 4d84569229b2125289ca7457da5ecb978e82b5c7d15d2b4dd13a017409ba9893

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_mre_crypto_shamir-0.2.0.dev44-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.dev44-py3-none-any.whl
Algorithm Hash digest
SHA256 783c3f03347bb5733a5f8d590a010c12568d4f777f68a27c473c194748db7cd6
MD5 b09603b4c094d48ea26b0dd21c8c158e
BLAKE2b-256 2e378f0ab056f4f7d841ac51f7f597c2802e7793e7fc85ea5a177202cd217fd1

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