Skip to content
This repository was archived by the owner on May 30, 2026. It is now read-only.

joyccn/TgrCrypto

Repository files navigation

TgrCrypto

Important

TgrCrypto is deprecated and archived.

Development has moved to TgCryptoRS: https://github.com/joyccn/TgCryptoRS

New projects should install TgCryptoRS. Existing code that imports tgcrypto can keep the same import when using TgCryptoRS.

CI License Python

Migration

pip uninstall TgrCrypto
pip install TgCryptoRS
import tgcrypto  # still supported by TgCryptoRS

This repository is kept as historical source for the old package name.

Legacy README

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.

Requirements

  • Python 3.9 - 3.14
  • Rust 1.83+ (build from source only)

Installation

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 TgrCrypto

If a wheel is not available for your platform, install Rust 1.83+ first and then rerun the install command.

Usage

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)

Streaming API

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:])

Runtime metadata

For support logs or release checks:

import tgcrypto

print(tgcrypto.__version__)
print(tgcrypto.runtime_info())

Compatibility

TgrCrypto is a transparent drop-in replacement for TgCrypto:

import tgcrypto  # works with both TgCrypto and TgrCrypto

Function 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.

Source builds

# 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

Contributing

# 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 warnings

License

LGPL-3.0-or-later — see COPYING and COPYING.lesser.

Packages

 
 
 

Contributors