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.1.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.1-cp38-abi3-win_amd64.whl (450.9 kB view details)

Uploaded CPython 3.8+Windows x86-64

krel-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (495.4 kB view details)

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

krel-0.1.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (890.6 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.1.tar.gz.

File metadata

  • Download URL: krel-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 7121cc0c16a296ad4ae1e17eea13884f0ef7078065eacdabef03e37863141f5e
MD5 ac99f64cea7885f0ff5fe6e97c4c5d5c
BLAKE2b-256 972d23f9e74637b650571904c56734e9c78a5f4e0dfab8ac42ca76a728a5091d

See more details on using hashes here.

Provenance

The following attestation bundles were made for krel-0.1.1.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.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: krel-0.1.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 450.9 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.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 11af6697b6a6b05edf2607e1ae1c26b3d38fc0c3925a4906ef052ec8d9be38f7
MD5 1c7251a9ed3b46fd52ec99b0daf09be5
BLAKE2b-256 117d0b2e0771b886e7df3b68e1f4b09fd52364f883c80e092c095ab028d38c8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for krel-0.1.1-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.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for krel-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ab42f9f1b2aae878705bb28b7142b3e5983820ef7063fe7f21a35f4e8571ff77
MD5 adb79ffada7a9760a48510328f1c3e73
BLAKE2b-256 b99f916582991a6d7cde91157e09f2d8790f1be145afe30735cf39d5da327a75

See more details on using hashes here.

Provenance

The following attestation bundles were made for krel-0.1.1-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.1-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.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 41f1138c0cba76b6265961742561a985c32af391074a80a8e355fe91159be3c5
MD5 31cdee0bbdaeeb44fef04ccd3ba1e9d5
BLAKE2b-256 6d48df2d3a4d5c4e3756fc52ed8e21411e5a870f9f3651aca2d0565e7c1bb846

See more details on using hashes here.

Provenance

The following attestation bundles were made for krel-0.1.1-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