Metadata-Version: 2.4
Name: cryptography-suite
Version: 4.0.0rc1
Summary: Policy-driven envelope encryption for Python: cloud key services, post-quantum recipients, quorum recovery, and verified streaming (pre-release; not independently audited).
Author-email: Mojtaba Zaferanloo <psychevus@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Psychevus/cryptography-suite
Project-URL: Documentation, https://psychevus.github.io/cryptography-suite
Project-URL: Source, https://github.com/Psychevus/cryptography-suite
Project-URL: Changelog, https://github.com/Psychevus/cryptography-suite/blob/main/CHANGELOG.md
Project-URL: Tracker, https://github.com/Psychevus/cryptography-suite/issues
Keywords: cryptography,envelope-encryption,kms,key-management,hpke,post-quantum,ml-kem,cose,aead,key-commitment,streaming-encryption,security
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Security :: Cryptography
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography>=50.0.0
Provides-Extra: dev
Requires-Dist: bandit; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: hypothesis; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pip-audit; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: furo; extra == "docs"
Requires-Dist: myst-parser; extra == "docs"
Requires-Dist: sphinxcontrib-mermaid; extra == "docs"
Dynamic: license-file

# Cryptography Suite

[![Quality gate](https://github.com/Psychevus/cryptography-suite/actions/workflows/quality-gate.yml/badge.svg)](https://github.com/Psychevus/cryptography-suite/actions/workflows/quality-gate.yml)
[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/Psychevus/cryptography-suite/blob/main/LICENSE)

**Policy-driven envelope encryption for Python.** One small API seals data
under a fresh key, wraps that key for every recipient you configure (a cloud
key service, an offline escrow key, a quorum of custodians), binds the result
to its context, and opens it only when every byte and every binding verifies.

Project page: [psychevus.com/work/cryptography-suite](https://psychevus.com/work/cryptography-suite) · in-browser lab: [psychevus.com/lab/envelope](https://psychevus.com/lab/envelope)

> **Status: 4.0.0rc1 is a release candidate, a pre-release.** The envelope
> format, the public API, the command line, and the JSON documents are frozen
> for 4.0; a change to any of them restarts the public review.
> It is not independently audited, and it is under public review for at
> least 60 days before 4.0.0
> ([review guide](https://github.com/Psychevus/cryptography-suite/blob/main/docs/v4/security/review-guide.md)).
> Evaluate it, but do not protect production data with it yet. Install it
> with `pip install --pre cryptography-suite`; without `--pre`, pip selects
> 3.0.0, the retired v3 educational toolkit, which is unrelated to this API.

## Why

- **No cryptographic decisions for the caller.** No algorithms, key sizes,
  nonces, or KDFs to choose: AES-256-GCM under a fresh 256-bit key per
  envelope, with key commitment and a STREAM record construction.
- **Your key service, your control.** AWS KMS, Google Cloud KMS, Azure Key
  Vault and Managed HSM, and HashiCorp Vault Transit, through clients you
  build. Keys never leave the service, and every wrap is bound to its
  envelope.
- **Recoverable by design.** Every envelope can carry several recipients: a
  second region, an offline escrow key, or a k-of-n quorum of custodians.
  Rotation rewraps in place and never drops one.
- **Post-quantum ready.** Hybrid ML-KEM recipients and an ML-DSA-signed audit
  trail, alongside classical keys, in the same format.
- **Safe at any size.** Streams in bounded memory, publishes output only after
  the last record verifies, and reads authenticated byte ranges of large
  objects without reading the rest.
- **Built to be checked.** A byte-level specification with test vectors, a
  248-case conformance suite, an independent JavaScript implementation, 100%
  line and branch coverage, fuzzing, mutation testing, and a published threat
  model.

## Install

```console
git clone https://github.com/Psychevus/cryptography-suite.git
python -m pip install ./cryptography-suite
```

Python 3.11 or later. The core depends only on
[pyca/cryptography](https://cryptography.io); each key-service integration
is a separate distribution
([installation](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/installation.md)).

## Quick start

This runs as is, with a key held in the process:

```python
from cryptography_suite import EncryptionContext, Policy, Protector
from cryptography_suite.providers.hpke import HpkeRecipientProvider, generate_private_key

identity = generate_private_key()  # in production: a key-service key
provider = HpkeRecipientProvider()
key = provider.add_identity("invoices", identity)
protector = Protector(provider=provider, policy=Policy(), primary_key=key)

context = EncryptionContext({"tenant": "acme"}, purpose="invoice-archive")
envelope = protector.seal(b"invoice 2026-0042: 1,200 EUR", context=context)
assert protector.open(envelope, context=context) == b"invoice 2026-0042: 1,200 EUR"
```

The context is authenticated but never stored: an envelope sealed for one
tenant cannot be opened as another's. Any change to the envelope's bytes, or
a different context, raises a typed error with a stable code.

## A production shape

A key-service primary key, an offline escrow key, an enterprise policy, and a
signed audit trail:

<!-- not-run: needs an AWS account -->
```python
from cryptography_suite import KeyRef, Policy, Protector
from cryptography_suite.providers.hpke import HpkeRecipientProvider, load_public_key_text
from cryptography_suite_aws_kms import PROVIDER_ID as AWS, AwsKmsProvider

escrow = HpkeRecipientProvider(provider_id="com.example.escrow")
escrow.add_recipient("break-glass", load_public_key_text(escrow_public_key))

protector = Protector(
    providers=[AwsKmsProvider(kms_client), escrow],
    policy=Policy.enterprise(approved_providers=[AWS, escrow.provider_id]),
    primary_key=KeyRef(AWS, "alias/payments"),
    additional_keys=[KeyRef(escrow.provider_id, "break-glass")],
    audit_sink=audit_chain,
)
```

Every envelope is wrapped for both keys. If the KMS key is disabled or the
region is lost, the escrow key opens everything; when the KMS key rotates,
`rewrap` moves envelopes to the new version and keeps the escrow recipient.
Only keys you configure are trusted for opening, so an envelope made under
someone else's key is never accepted as yours.

## Features

| | |
| --- | --- |
| Key services | AWS KMS, Google Cloud KMS (including ML-KEM and X-Wing keys), Azure Key Vault and Managed HSM, HashiCorp Vault Transit; [your own](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/custom-providers.md) with a conformance kit |
| Public-key recipients | HPKE (RFC 9180) with X25519, P-384, ML-KEM-768 + X25519, and ML-KEM-1024 + P-384; sealers hold only public keys |
| Recovery | Escrow keys, [k-of-n quorum recovery](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/quorum-recovery.md) in which no custodian's key moves, rewrap without re-encryption |
| Scale | [Hierarchical keys](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/multi-tenant.md): one key-service call per tenant key per cache period instead of one per envelope |
| Large data | [Streaming](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/streaming.md) up to 1 TiB, atomic file output, authenticated range reads |
| Audit | Secret-free events, a [signed hash-chained trail](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/audit-and-observability.md) (Ed25519, or Ed25519 with ML-DSA-65), OpenTelemetry metrics |
| Policy | Immutable [policies](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/policy.md) with content-derived identifiers that only narrow when combined; a FIPS profile |
| Interoperability | [COSE-HPKE](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/cose.md) messages and keys; a [JavaScript implementation](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/javascript.md) for browsers, Node.js, Deno, and edge runtimes |
| Command line | [`cryptosuite`](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/cli.md) with atomic output, JSON status, and stable exit codes |
| From v3 | [Verified migration](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/migrating-from-v3.md) of v3 encrypted files into v4 envelopes, without writing plaintext, and an inventory and policy-checked import of v3 keys |

## Documentation

- [Quick start](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/quickstart.md)
  and [concepts](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/concepts.md)
- [Key services](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/key-services.md),
  with the permissions each operation needs
- [Rotation and recovery](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/rotation-and-recovery.md),
  the [production checklist](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/production.md), and the
  [incident runbooks](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/runbooks.md)
- [Support and compatibility](https://github.com/Psychevus/cryptography-suite/blob/main/docs/reference/support.md) and the
  [release readiness report](https://github.com/Psychevus/cryptography-suite/blob/main/docs/v4/release-readiness.md)
- [Errors](https://github.com/Psychevus/cryptography-suite/blob/main/docs/reference/errors.md),
  the [envelope format](https://github.com/Psychevus/cryptography-suite/blob/main/docs/v4/spec/envelope-format.md),
  and [runnable examples](https://github.com/Psychevus/cryptography-suite/tree/main/examples)

The full documentation, with the API reference, is built from
[`docs/`](https://github.com/Psychevus/cryptography-suite/tree/main/docs).

## Assurance

What has been done, and what has not:

- The format is specified byte by byte, with test vectors checked by an
  independent reader, and a
  [conformance suite](https://github.com/Psychevus/cryptography-suite/tree/main/conformance)
  that the Python and JavaScript implementations both pass.
- Every primitive is checked against Project Wycheproof, HPKE against the
  CFRG vectors, and COSE-HPKE against the draft's examples.
- CI enforces 100% line and branch coverage, combined across Linux, macOS,
  and Windows; tests every single-bit change and truncation of envelopes
  against every reader; and fuzzes every untrusted input weekly.
- An internal audit, including mutation testing, found and addressed
  twelve issues ([RFC-0031](https://github.com/Psychevus/cryptography-suite/blob/main/docs/v4/rfcs/RFC-0031-security-audit.md)).
  The [threat model](https://github.com/Psychevus/cryptography-suite/blob/main/docs/v4/security/threat-model.md)
  states each security claim with the tests that support it.
- **No independent audit has been done yet.** It is a release gate for 4.0.0
  ([proposed scope](https://github.com/Psychevus/cryptography-suite/blob/main/docs/v4/security/audit-scope.md)).

Report vulnerabilities privately, as described in
[SECURITY.md](https://github.com/Psychevus/cryptography-suite/blob/main/SECURITY.md).

## Contributing

See [CONTRIBUTING.md](https://github.com/Psychevus/cryptography-suite/blob/main/CONTRIBUTING.md).
The design is recorded in
[RFCs](https://github.com/Psychevus/cryptography-suite/tree/main/docs/v4/rfcs),
and changes are listed in the
[changelog](https://github.com/Psychevus/cryptography-suite/blob/main/CHANGELOG.md).

## License

[MIT](https://github.com/Psychevus/cryptography-suite/blob/main/LICENSE).
