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

File metadata

  • Download URL: swarmauri_mre_crypto_shamir-0.2.0.dev46.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.dev46.tar.gz
Algorithm Hash digest
SHA256 018c7dca2481294205566e5f6f81a2598b0b284428c52bcbd7d88c7b4d5453f4
MD5 eadde748cc200cfb5783d4496864d7c5
BLAKE2b-256 092d394ba8f558a48259b456a2c0457cc5635e1ec8930deca2939ae1caa0fd4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_mre_crypto_shamir-0.2.0.dev46-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.dev46-py3-none-any.whl
Algorithm Hash digest
SHA256 a55122a90e0acecd0532a18b0382aeb7755d54cd2d79cdc03d960728cafc2923
MD5 d453c1f81487e7154da472455f63bc9e
BLAKE2b-256 a3d187cc12a31c4d0eb9d58aa62b3edf95fddc408b5692b4cfadf271f6825892

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