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

File metadata

  • Download URL: swarmauri_mre_crypto_shamir-0.2.0.dev47.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.dev47.tar.gz
Algorithm Hash digest
SHA256 3d87ca1f7136a6abab3040279b7ea8b93d5b5e1c36cafdf839a0ac15b4bfab6b
MD5 12bbe70289aa8f9c19cb6a1a85cc338e
BLAKE2b-256 7c15a001289fd8cbc108d50b18617797ec0b53de4ae48827ed6324ea5f9aba05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_mre_crypto_shamir-0.2.0.dev47-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.dev47-py3-none-any.whl
Algorithm Hash digest
SHA256 f07bc5b3b23c917f360c93320c83a68567c79473f5386a15200b051285203e16
MD5 337b7021df4f9e6204a9556888718812
BLAKE2b-256 6e21db7b1b6eef83068afbecc0342e8e4b2086c9a56ee7271b392cbe77131c9f

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