purecrypt
Security notice. Pure Python cannot provide constant-time execution. Secret-key operations (signing, decryption, key exchange) are hardened against the obvious leaks: RSA blinding, fixed-iteration scalar multiplication with mask-selected adds, uniform error paths, and constant-time-style comparisons. Residual timing variance in the interpreter remains, so do not run secret-key operations where a co-located attacker can measure timing. Public-data operations such as certificate validation and signature verification are unaffected. For high-assurance deployments use audited native implementations such as
cryptography(OpenSSL) orPyNaCl(libsodium).
Pure-Python cryptographic primitives for Python 3.10+. No
dependencies, no Rust, no C extensions: only hashlib, hmac and
secrets from the standard library.
Install
pip install purecrypt
Contents
- AES-128/192/256 with ECB, CBC, CTR and GCM (AEAD)
- ChaCha20, Poly1305, ChaCha20-Poly1305 and XChaCha20-Poly1305
- Ed25519 signatures and X25519 key exchange
- ECDSA and ECDH over P-256, P-384, P-521 and secp256k1 (RFC 6979 deterministic signatures)
- RSA: key generation, PSS and PKCS#1 v1.5 signatures, OAEP and PKCS#1 v1.5 encryption, PKCS#1/PKCS#8/SPKI serialization, encrypted PKCS#8 (PBES2/AES-CBC)
- X.509 certificate parsing, signature verification, RFC 5280 chain validation and RFC 6125 hostname matching
- HKDF, PBKDF2, scrypt and Argon2id
- Minimal DER/PEM handling for key serialization
- SHA-2, SHA-3, SHAKE, BLAKE2 and HMAC facades over hashlib
Example
from purecrypt.aes import gcm_decrypt, gcm_encrypt
from purecrypt.eddsa import Ed25519PrivateKey
from purecrypt.x509 import Certificate, validate_chain, verify_hostname
key, nonce = b"k" * 32, b"n" * 12
ct, tag = gcm_encrypt(key, nonce, b"secret", aad=b"hdr")
assert gcm_decrypt(key, nonce, ct, tag, aad=b"hdr") == b"secret"
priv = Ed25519PrivateKey.generate()
sig = priv.sign(b"message")
priv.public_key().verify(sig, b"message")
leaf = Certificate.from_pem(pem_text)
validate_chain(leaf, intermediates, trust_roots)
verify_hostname(leaf, "example.com")
Known limitations
- No constant-time guarantees. Python semantics preclude them.
- Secret zeroization is best-effort (mutable buffers are wiped where practical, but interpreter copies are out of scope).
- RSA PKCS#1 v1.5 decryption is inherently Bleichenbacher-prone. Use OAEP.
- X.509 validation covers RFC 5280 path rules and RFC 6125 hostnames, but there is no revocation checking (no CRL or OCSP) and no name or policy constraint enforcement. A critical extension whose semantics are not enforced fails validation.
- No TLS. That is a different and much larger problem.
Development
uv sync --group dev
make check
License: 0BSD. Quad4 Software, https://quad4.io
Release files for purecrypt 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| purecrypt-0.1.1.tar.gz | 222.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| purecrypt-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 281.4 kB
Release files / purecrypt-0.1.1.tar.gz
| Download URL | purecrypt-0.1.1.tar.gz |
|---|---|
| Size | 222.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0140b2de8241cb2dbe9c1c7917c00450291eeb7d80e8f589c67d371459b6a076
|
|
BLAKE2b-256 checksum How to use checksums |
8e9a18860f9e8449b9a766e5e9e649e002c2ba6a823f1ab0c3b6ee24bc67ebe3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency logRelease files / purecrypt-0.1.1-py3-none-any.whl
| Download URL | purecrypt-0.1.1-py3-none-any.whl |
|---|---|
| Size | 59.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1d4b7b37e778daf5dcd6dfa91d84c9eacbe7ac563fff939d5c2d4a29a2937cb
|
|
BLAKE2b-256 checksum How to use checksums |
e0fa0f59f83b53abb0e7768908a7d3f24b9dd07d314785789cddb86a27ee77e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.
Transparency log