Skip to main content

Secure streaming file encryption with O(1) memory usage

Project description

KREL

PyPI License Python

Secure streaming file encryption with constant memory usage.

Features

  • Simple API - Encrypt files with 3 lines of code
  • Streaming - Process unlimited file sizes with O(1) memory
  • Instant rekey - Change passwords in constant time without re-encryption
  • Battle-tested crypto - XChaCha20-Poly1305, Argon2id, BLAKE3
  • Safe by default - Automatic password zeroization

Install

pip install krel

Quick Start

from krel import encrypt, decrypt, rekey

# Encrypt
encrypt("file.pdf", "file.pdf.krel", "password")

# Decrypt
decrypt("file.pdf.krel", "file.pdf", "password")

# Change password instantly
rekey("file.pdf.krel", "old-password", "new-password")

Usage

Basic Operations

from krel import encrypt, decrypt, verify_password

# Encrypt a file
encrypt("document.txt", "document.txt.krel", "my-password")

# Decrypt
decrypt("document.txt.krel", "document.txt", "my-password")

# Check password without decrypting
if verify_password("document.txt.krel", "my-password"):
    print("Correct password")

Password Change

from krel import rekey

# O(1) password change - no re-encryption needed
rekey("file.krel", "old-password", "new-password")

Error Handling

from krel import decrypt, AuthenticationError, IntegrityError

try:
    decrypt("file.krel", "output.txt", "password")
except AuthenticationError:
    print("Wrong password")
except IntegrityError:
    print("File corrupted")

Async API

For large files or high performance:

from krel import encrypt_async, decrypt_async

await encrypt_async("large.iso", "large.iso.krel", "password")
await decrypt_async("large.iso.krel", "large.iso", "password")

API

Functions

  • encrypt(source, dest, password) - Encrypt a file
  • decrypt(source, dest, password) - Decrypt a file
  • rekey(path, old_pass, new_pass) - Change password
  • verify(path) -> bool - Check file integrity
  • verify_password(path, password) -> bool - Verify password

All functions have async versions: encrypt_async(), decrypt_async(), etc.

Exceptions

  • KrelError - Base exception
  • AuthenticationError - Wrong password
  • IntegrityError - File corrupted

Security

Cryptography

  • Encryption: XChaCha20-Poly1305 (AEAD)
  • KDF: Argon2id (256 MB, 3 iterations)
  • Hashing: BLAKE3
  • Chunk size: 64 KiB

Memory Safety

  • Passwords automatically zeroed after use
  • Constant memory usage regardless of file size
  • Secure key wrapping with commitment

Performance

  • Throughput: ~500 MB/s (CPU-dependent)
  • Memory: ~130 KiB constant
  • Rekey: O(n) but no decryption/encryption

File Format

Header (128 bytes)
├─ Magic: "KREL"
├─ Version: 1
├─ Salt: 16 bytes
├─ Nonce base: 16 bytes
├─ Wrapped DEK: 48 bytes
└─ Commitment: 32 bytes

Encrypted chunks
└─ Chunk: 65552 bytes (64 KiB + 16 byte tag)

Trailer (36 bytes)
├─ Integrity hash: 32 bytes
└─ Magic: "KREL"

Examples

See examples/ directory for more usage patterns.

License

MIT - see LICENSE file.

Author

Muran-prog

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

krel-0.1.2.tar.gz (29.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

krel-0.1.2-cp38-abi3-win_amd64.whl (451.0 kB view details)

Uploaded CPython 3.8+Windows x86-64

krel-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (495.3 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

krel-0.1.2-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (890.8 kB view details)

Uploaded CPython 3.8+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file krel-0.1.2.tar.gz.

File metadata

  • Download URL: krel-0.1.2.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krel-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c2007ff2d72bcf1670203f6031cc7c938634de3058160fc452b8989a64164326
MD5 d62599aed3ff1dc13428f3614f014fbb
BLAKE2b-256 ddd77d6eeb61c10715b852bce725f85fa9606e646d4bd390a63923d60d8b6db0

See more details on using hashes here.

Provenance

The following attestation bundles were made for krel-0.1.2.tar.gz:

Publisher: release.yml on Muran-prog/krel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krel-0.1.2-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: krel-0.1.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 451.0 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krel-0.1.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5d233e5b074f6f686c802b20207df87b7a8064609f846b4880bdfb62625b594d
MD5 a206a4fb1131fc322f8682ab686f566d
BLAKE2b-256 9584fa241ae12fc648227b4b6572ae4a3ea3177d1e32ea4866001cfa0516abec

See more details on using hashes here.

Provenance

The following attestation bundles were made for krel-0.1.2-cp38-abi3-win_amd64.whl:

Publisher: release.yml on Muran-prog/krel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krel-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for krel-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e612ee1d57aab5579e63a6ba3737a5a00a765e2362a819e2d22f4a6efc37939
MD5 cc93410e2a6fb74a8bdb55b7db80cd9d
BLAKE2b-256 1e7ce39022b79b81a258b29d980d7b53861db07e7098a71ecc25177d80b9d318

See more details on using hashes here.

Provenance

The following attestation bundles were made for krel-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Muran-prog/krel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krel-0.1.2-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for krel-0.1.2-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 de56ccfcae81d131f7326c0eb4a1e70af18e842221bdca1d3fd1d43a9345be72
MD5 070c0de085d20a1a905c0f9e5aa848a1
BLAKE2b-256 cc521e94adcfae6b00507a41e48f5d11b3a87109d1e6abe32238ea747c1eb579

See more details on using hashes here.

Provenance

The following attestation bundles were made for krel-0.1.2-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on Muran-prog/krel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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