Rust-powered, AES-NI accelerated drop-in replacement for TgCrypto
Note
The cryptographic algorithms implemented in this library — AES-256-IGE, AES-256-CTR, and AES-256-CBC — are provided for educational and experimental purposes. While the implementation follows NIST FIPS 197 specifications and has been validated against official test vectors, it has not undergone a formal third-party security audit. Use in production systems requiring certified cryptographic modules is at your own discretion.
- Python 3.9 - 3.14
- Rust 1.83+ (build from source only)
Prebuilt wheels are published for supported CPython versions and common desktop/server platforms. Rust is only required when your platform needs to build from source.
# Recommended
uv add TgrCrypto
# Install into the active environment with uv
uv pip install TgrCrypto
# Or use pip
pip install TgrCryptoIf a wheel is not available for your platform, install Rust 1.83+ first and then rerun the install command.
import tgcrypto
import os
# IGE-256 (data must be a multiple of 16 bytes)
data = os.urandom(1024)
key = os.urandom(32)
iv = os.urandom(32)
enc = tgcrypto.ige256_encrypt(data, key, iv)
dec = tgcrypto.ige256_decrypt(enc, key, iv)
# CTR-256 (arbitrary length)
data = os.urandom(1024)
key = os.urandom(32)
iv = os.urandom(16)
state = bytes(1)
enc = tgcrypto.ctr256_encrypt(data, key, iv, state)
dec = tgcrypto.ctr256_decrypt(enc, key, iv, state)
# CBC-256 (data must be a multiple of 16 bytes)
data = os.urandom(1024)
key = os.urandom(32)
iv = os.urandom(16)
enc = tgcrypto.cbc256_encrypt(data, key, iv)
dec = tgcrypto.cbc256_decrypt(enc, key, iv)For incremental processing of large data:
import tgcrypto
import os
key = os.urandom(32)
iv = os.urandom(16)
data = os.urandom(1024)
stream = tgcrypto.Ctr256(key, iv)
chunk1 = stream.update(data[:512])
chunk2 = stream.update(data[512:])IGE also supports incremental block-aligned processing:
import tgcrypto
import os
key = os.urandom(32)
iv = os.urandom(32)
data = os.urandom(1024)
stream = tgcrypto.Ige256(key, iv)
chunk1 = stream.encrypt(data[:512])
chunk2 = stream.encrypt(data[512:])For support logs or release checks:
import tgcrypto
print(tgcrypto.__version__)
print(tgcrypto.runtime_info())TgrCrypto is a transparent drop-in replacement for TgCrypto:
import tgcrypto # works with both TgCrypto and TgrCryptoFunction names, arguments, return types, and validation behavior are intended
to match TgCrypto for the supported AES-256-IGE, AES-256-CTR, and AES-256-CBC
APIs. The package name is TgrCrypto, while the import name remains
tgcrypto.
# Build a wheel through the configured PEP 517 backend
uv build --wheel
# Or build and install an editable local extension for development
uv pip install maturin
uv run maturin develop --release# Run Rust tests
cargo test --release
# Run Python API tests after building the local extension
uv sync --python 3.14
uv run maturin develop --release
.venv/bin/python -m unittest discover -s tests -v
# Build a wheel through the configured PEP 517 backend
uv build --wheel
# Run with clippy
cargo clippy --all-targets --all-features -- -D warningsLGPL-3.0-or-later — see COPYING and COPYING.lesser.