shircrypt
A modern, memory-safe, abi3 Rust cryptographic engine for Telegram MTProto 2.0 — built for Shirdal.
English | فارسی
shircrypt replaces legacy C-based MTProto crypto extensions (like TgCrypto) with a tiny, self-contained Rust + PyO3 (abi3-py311) core. It compiles once for Python 3.11 through 3.15+, requires zero C/OpenSSL system libraries, leverages hardware AES-NI and ARMv8 Crypto, releases the GIL on large buffers, and wipes key material from RAM via zeroize.
Architecture
Python Caller (bytes / bytearray / memoryview)
│
shircrypt.__init__ (auto-select)
┌────────────┴────────────┐
▼ ▼
_shircrypt (Rust) _fallback (Python)
(PyO3 abi3-py311, (cryptography backend
AES-NI / ARMv8 CE, when wheel is absent)
zeroize, GIL-free)
Why shircrypt over TgCrypto?
| Feature | shircrypt |
TgCrypto |
Pure Python |
|---|---|---|---|
| Python ABI | abi3-py311 (one wheel for 3.11–3.15+) |
Rebuilds required per Python version | Version-independent |
| System Dependencies | None (pure Rust crates) | C compiler + Python headers | None / OpenSSL |
| Memory Safety & Key Wiping | Memory-safe Rust + zeroize |
Manual C pointers | Managed |
| Hardware Acceleration | AES-NI (x86_64) & ARMv8 Crypto (Termux/ARM64) | AES-NI / C loop | Slow block loop |
| GIL Behavior | Released for payloads >= 4096 bytes |
Released | Holds GIL |
| MTProto 2.0 KDF | Native compute_msg_key & mtproto2_kdf |
Not included | Python hashlib |
| Fallback Support | Automatic cryptography fallback |
Fails if not compiled | N/A |
Installation
pip install shircrypt
If you want the optional fallback backend on unsupported platforms:
pip install "shircrypt[fallback]"
Termux (Android)
You can use shircrypt on Termux in two ways:
- Instant install (via
cryptographyfallback, no Rust compile):
pkg install -y python-cryptography
pip install --no-build-isolation --no-deps -e .
- Native Rust core (maximum speed with ARMv8 Crypto):
pkg install -y rust binutils maturin
maturin develop --release
Quickstart
import os
import shircrypt
print("Active backend:", shircrypt.BACKEND) # "rust" or "cryptography"
key = os.urandom(32)
iv_ige = os.urandom(32)
plaintext = b"0123456789abcdef" * 4
# AES-256-IGE (MTProto 2.0 packets)
ciphertext = shircrypt.ige256_encrypt(plaintext, key, iv_ige)
decrypted = shircrypt.ige256_decrypt(ciphertext, key, iv_ige)
assert decrypted == plaintext
# AES-256-CTR with byte-offset seeking (chunked file transfers)
iv_ctr = os.urandom(16)
stream_chunk = shircrypt.ctr256_crypt(b"chunk-data", key, iv_ctr, offset=1024)
# MTProto 2.0 Key Derivation
auth_key = os.urandom(256)
msg_key = shircrypt.compute_msg_key(auth_key, plaintext, from_client=True)
aes_key, aes_iv = shircrypt.mtproto2_kdf(auth_key, msg_key, from_client=True)
Documentation
Running Tests & Benchmarks
python3 -m unittest discover -s tests -v
python3 benches/bench_shircrypt.py
Security, Contributing & License
- Security vulnerabilities: SECURITY.md
- Contributing guidelines: CONTRIBUTING.md
- Changelog: CHANGELOG.md
- License: LGPL-3.0-or-later
Metadata
Release files for shircrypt 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shircrypt-1.0.3.tar.gz | 19.2 kB | With provenance | Details for shircrypt-1.0.3.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| shircrypt-1.0.3-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for shircrypt-1.0.3-cp311-abi3-win_amd64.whl |
| shircrypt-1.0.3-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for shircrypt-1.0.3-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| shircrypt-1.0.3-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details for shircrypt-1.0.3-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| shircrypt-1.0.3-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for shircrypt-1.0.3-cp311-abi3-macosx_11_0_arm64.whl |
| shircrypt-1.0.3-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details for shircrypt-1.0.3-cp311-abi3-macosx_10_12_x86_64.whl |
Total release size: 998.4 kB
Release files / shircrypt-1.0.3.tar.gz
| Download URL | shircrypt-1.0.3.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71f7a2af440ae1baeac259e582ea50e8833fcfc699f966ea86052b34d4090a55
|
|
BLAKE2b-256 checksum How to use checksums |
37b172ec2c4310c9ff8ca29d505de7db6de634736b272adec552cbb3cc00a709
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 26, 2026.
Transparency logRelease files / shircrypt-1.0.3-cp311-abi3-win_amd64.whl
| Download URL | shircrypt-1.0.3-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 139.4 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8ea93c47bca3ecb66c425db2c4456129b9465d2470be0fc587af0b588d480b12
|
|
BLAKE2b-256 checksum How to use checksums |
9b7bff4544d9add53ac5d9c096ca697c0fbe280b46eeccf925176c7bef91f8e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 26, 2026.
Transparency logRelease files / shircrypt-1.0.3-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | shircrypt-1.0.3-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 219.4 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
bd685fb1d6089e57d26367ba81aac9e2d7a6584514f115c69e9d30de84a5537f
|
|
BLAKE2b-256 checksum How to use checksums |
eb074301f3c64004c684eff3a00a8439d6ae6714c26cf15cb6988a2e42b0b9fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 26, 2026.
Transparency logRelease files / shircrypt-1.0.3-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | shircrypt-1.0.3-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 207.3 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4d8371059303fbdf9aad368f43961a18771c42a675b215cdb5ab440d52b36188
|
|
BLAKE2b-256 checksum How to use checksums |
1154ae063290c6d63aad58fe965a8083eb2ee7f32130c5578a18015bc39e8b51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 26, 2026.
Transparency logRelease files / shircrypt-1.0.3-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | shircrypt-1.0.3-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 198.6 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f3372690bf92dc110263ee563001d652ff76f0125d3b9f64a5517fd33463035e
|
|
BLAKE2b-256 checksum How to use checksums |
407f340184cb2430dc81ee5b34a40862b652a447154cd38371f93ffb258b7150
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 26, 2026.
Transparency logRelease files / shircrypt-1.0.3-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | shircrypt-1.0.3-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 214.5 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8050226145f69749040026f4e0bff90f2168989a2d40f9d4145179bb2eea7a69
|
|
BLAKE2b-256 checksum How to use checksums |
d020f4627abd5ea21deb67b03798770f2c45ca056b97b334662f07f2688db56a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 26, 2026.
Transparency logSecurity for shircrypt 1.0.3
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.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for shircrypt-1.0.3.tar.gz
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 Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.