Skip to main content

shircrypt

A modern, memory-safe, abi3 Rust cryptographic engine for Telegram MTProto 2.0 — built for Shirdal.

English | فارسی

Python 3.11+ Rust PyPI CI License: LGPL v3


shircrypt replaces legacy C-based MTProto crypto extensions (like TgCrypto) with a tiny, self-contained Rust + PyO3 (abi3-py311) core — delivering 4.67x faster throughput on average (and up to 11.84x on AES-CTR). 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

Benchmarks

shircrypt is 4.67x faster than TgCrypto overall (geometric mean across 30 cases: 5.11x on buffers >= 64 KiB, 3.93x on buffers <= 1 KiB).

shircrypt vs TgCrypto

Workload shircrypt (Rust) TgCrypto (C) Speed-up
CTR-256 (64 KiB) 827 MB/s 70 MB/s 11.84x
CBC-256 decrypt (64 KiB) 603 MB/s 82 MB/s 7.36x
CBC-256 encrypt (64 KiB) 322 MB/s 80 MB/s 4.02x
IGE-256 encrypt (64 KiB) 314 MB/s 81 MB/s 3.89x
IGE-256 decrypt (64 KiB) 196 MB/s 78 MB/s 2.49x
E2E 1 KiB MTProto 2.0 msg (KDF + IGE) 22.08 us 31.56 us* 1.44x

* TgCrypto has no built-in KDF, so the legacy pipeline pairs it with Python hashlib. Benchmarks pinned to a single core on Intel Xeon E5-2620 v4 (Python 3.11.18, Linux x86_64, 7 interleaved rounds). shircrypt releases the GIL on buffers >= 4096 bytes so concurrent threads/workers are never blocked. See the full benchmark report & methodology.

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:

  1. Instant install (via cryptography fallback, no Rust compile):
pkg install -y python-cryptography
pip install --no-build-isolation --no-deps -e .
  1. 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
pip install shircrypt TgCrypto && python3 benches/compare_tgcrypto.py

Security, Contributing & License

Metadata

Release files for shircrypt 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shircrypt 1.0.7
File Size Uploaded Provenance Actions
shircrypt-1.0.7.tar.gz 22.9 kB With provenance Details for shircrypt-1.0.7.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for shircrypt 1.0.7
File Actions
shircrypt-1.0.7-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for shircrypt-1.0.7-cp311-abi3-win_amd64.whl
shircrypt-1.0.7-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.7-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
shircrypt-1.0.7-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for shircrypt-1.0.7-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
shircrypt-1.0.7-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for shircrypt-1.0.7-cp311-abi3-macosx_11_0_arm64.whl
shircrypt-1.0.7-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for shircrypt-1.0.7-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 1.0 MB

Release files / shircrypt-1.0.7.tar.gz

Download URL shircrypt-1.0.7.tar.gz
Size 22.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1840354f4dd39ac21827c9f0de5e645e8e90a59dc8682c2ba2144e7411269e15
BLAKE2b-256 checksum
How to use checksums
5134e20dfb51f33d24d319b2fc4dbbe155fabab13cbf8b0cfec5d12514f72740
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 log

Release files / shircrypt-1.0.7-cp311-abi3-win_amd64.whl

Download URL shircrypt-1.0.7-cp311-abi3-win_amd64.whl
Size 145.9 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e18e0d06a51abafad56360ad607d23cf9949f9d2dae84eed8329dee826d1150b
BLAKE2b-256 checksum
How to use checksums
8a1068beb3fc5775d8555667e7b7e2be134ff4f0e728d04c7c6fb892eeae5af0
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 log

Release files / shircrypt-1.0.7-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL shircrypt-1.0.7-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 226.3 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
5b246616e742f707d77bf3c01d3920623d267ea0ab3de5e8a63115a8aabd888b
BLAKE2b-256 checksum
How to use checksums
0cebb6d2f706ff7ebb47e4aea378f541373b1bdebcdf1012043d167f1acf21fa
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 log

Release files / shircrypt-1.0.7-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL shircrypt-1.0.7-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 213.0 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
65287fe1c267acfc8bdc1c5b96b717bbaaccf6da2edffd2090432bbe462c6e66
BLAKE2b-256 checksum
How to use checksums
aa6aa9fd8460560173b409f189d47892de795ae96f6ec0b2afa0d60708f359e0
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 log

Release files / shircrypt-1.0.7-cp311-abi3-macosx_11_0_arm64.whl

Download URL shircrypt-1.0.7-cp311-abi3-macosx_11_0_arm64.whl
Size 204.2 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a2704d1c831aaef11463b7dd16f33d44655ce4c15eef7d539b034a35a33c5729
BLAKE2b-256 checksum
How to use checksums
01ec58da5966610bf272df4a85121bc7f80478a179ad0fa5f0cb3c820d564f45
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 log

Release files / shircrypt-1.0.7-cp311-abi3-macosx_10_12_x86_64.whl

Download URL shircrypt-1.0.7-cp311-abi3-macosx_10_12_x86_64.whl
Size 220.9 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
6f33d0aea19f3115e3b6adb8ebbb95b5e42ee454966f574dfb3020c03f0a0fcd
BLAKE2b-256 checksum
How to use checksums
c4f07b83baeabca018f94a73d036788442a59e66c2858adc328a962b668b7ec2
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 log

Security for shircrypt 1.0.7

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.

Select from 6 files

Attestation for shircrypt-1.0.7.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 log

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

Release history Release notifications | RSS feed

This release

1.0.7 This release

6 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page