ARM-CE / AES-NI accelerated Telegram crypto via OpenSSL EVP
Project description
โก cipheron
ARM-CE / AES-NI accelerated Telegram crypto via OpenSSL EVP
Drop-in replacement for
tgcrypto,cryptg, andcryptogram: with 5โ6ร faster IGE by routing AES through OpenSSL's hardware engine instead of software T-tables.
๐ฌ A personal note
I originally built cipheron in 2024 for my own personal use: I was frustrated that Telegram crypto on ARM devices (Termux, Android, Raspberry Pi) was bottlenecked by software AES even though the hardware was perfectly capable of going 5ร faster. So I fixed it. ๐
If cipheron helps speed up your bots, userbots, or Telegram clients: don't forget to โญ star the repo, it means a lot!
And do check out cryptogram (PyPI): the excellent project that inspired this work. cipheron builds on the same idea and takes it further with full OpenSSL EVP dispatch.
๐ง Why cipheron exists
Every Telegram message, file chunk, and MTProto packet is encrypted with AES-256-IGE. Popular libraries like tgcrypto and cryptogram implement IGE using AES_encrypt(): a software path that bypasses ARM Crypto Extensions and AES-NI entirely.
cipheron fixes this by routing all AES operations through OpenSSL's EVP_CipherUpdate(), which dispatches to hardware automatically:
EVP_CipherUpdate() โ OpenSSL engine dispatch โ aes_v8_encrypt (ARM-CE) โ 843 MB/s โ
AES_encrypt() โ software T-table path โ ~130 MB/s โ tgcrypto / cryptogram stuck here โ
On a device with ARM Crypto Extensions confirmed at 843 MB/s CBC, cipheron IGE lands at ~600โ800 MB/s: making crypto essentially free and your network the only bottleneck.
๐ฆ Installation
pip install cipheron
Termux / Android (ARM):
pkg install clang openssl python
pip install cipheron
Verify hardware acceleration:
python -c "import cipheron; print(cipheron.get_backend(), '|', cipheron.has_aesni())"
# C/EVP+ARM-CE | True
๐ Drop-in replacement: Pyrogram & Telethon
Method 1: sys.modules hijack โ
recommended
Add two lines before any Pyrogram/Telethon import: zero other code changes needed:
import sys
import cipheron
# Pyrogram uses tgcrypto internally
sys.modules['tgcrypto'] = cipheron
# Telethon uses cryptg internally
sys.modules['cryptg'] = cipheron
# Now import normally โ cipheron handles all crypto transparently โก
from pyrogram import Client
# or
from telethon import TelegramClient
Method 2: Direct API (same as tgcrypto)
import cipheron
# IGE-256 โ used for every MTProto message & file chunk
encrypted = cipheron.ige256_encrypt(data, key, iv)
decrypted = cipheron.ige256_decrypt(encrypted, key, iv)
# CTR-256 โ obfuscated transport layer
out, state = cipheron.ctr256_encrypt(data, key, iv, state)
out, state = cipheron.ctr256_decrypt(data, key, iv, state)
# CBC-256
encrypted = cipheron.cbc256_encrypt(data, key, iv)
decrypted = cipheron.cbc256_decrypt(encrypted, key, iv)
# PQ factorization โ Telegram handshake (unique to cipheron!)
p, q = cipheron.factorize_pq_pair(pq_int)
# Runtime detection
print(cipheron.has_aesni()) # True on ARM-CE / AES-NI hardware
print(cipheron.get_backend()) # "C/EVP+ARM-CE"
Method 3: Replace all frameworks at once
import sys, cipheron
for name in ('tgcrypto', 'cryptg', 'cryptogram'):
sys.modules[name] = cipheron
# Works transparently with any Telegram framework โ
๐ Benchmark Results
ARM Device (Termux / Android): ARM Crypto Extensions active
openssl speed -evp aes-256-cbc โ 843 MB/s โ hardware AES confirmed โ
843 MB/s = ARM Crypto Extensions are 100% active!
โโ IGE ENCRYPT (MB/s) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Size tgcrypto cryptogram cipheron speedup
16 KB ~130 ~100 ~750 โฒ 5.8ร ๐
256 KB ~125 ~85 ~680 โฒ 5.4ร ๐
1 MB ~128 ~90 ~700 โฒ 5.5ร ๐
8 MB ~130 ~88 ~720 โฒ 5.5ร ๐
โโ CTR ENCRYPT (MB/s) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
16 KB ~150 ~800 ~840 โฒ 5.6ร ๐
256 KB ~148 ~810 ~830 โฒ 5.6ร ๐
โโ CBC ENCRYPT (MB/s) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
16 KB ~155 ~820 ~843 โฒ 5.4ร ๐
Correctness: IGE โ PASS CTR โ PASS CBC โ PASS
Why 843 MB/s matters: cipheron routes IGE through the same hardware path as CBC. That's the entire trick: and it makes all the difference.
x86 Desktop (AES-NI): Verified benchmark
โโ IGE ENCRYPT (MB/s) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Size tgcrypto cryptogram cipheron speedup
16 KB 172 102 792 โฒ 4.60ร ๐
256 KB 133 87 353 โฒ 2.65ร ๐
1 MB 140 90 418 โฒ 2.99ร ๐
8 MB 144 90 422 โฒ 2.93ร ๐
โโ CTR ENCRYPT (MB/s) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
16 KB 153 964 โฒ 957 โฒ 6.27ร ๐
256 KB 152 967 โฒ 963 โฒ 6.33ร ๐
โโ CBC ENCRYPT (MB/s) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
16 KB 180 970 โฒ 972 โฒ 5.39ร ๐
Correctness: IGE โ PASS CTR โ PASS
Run your own benchmark
import os, time, cipheron, tgcrypto
KEY = os.urandom(32)
IV = os.urandom(32)
D = os.urandom(1024 * 1024)
N = 100
t = time.perf_counter()
for _ in range(N): cipheron.ige256_encrypt(D, KEY, IV)
print(f'cipheron : {N / (time.perf_counter() - t) * 1024:.0f} MB/s')
t = time.perf_counter()
for _ in range(N): tgcrypto.ige256_encrypt(D, KEY, IV)
print(f'tgcrypto : {N / (time.perf_counter() - t) * 1024:.0f} MB/s')
๐ Real-world impact
| Use case | Mode | cipheron vs tgcrypto |
|---|---|---|
| Telegram file upload / download | IGE | 5โ6ร faster on ARM |
| Every MTProto message | IGE | 5โ6ร faster |
| Pyrogram obfuscated transport | CTR | 4โ6ร faster |
| Telegram CDN file chunks | CTR | 4โ6ร faster |
| Bot handling 1000s of msgs/sec | IGE | biggest real-world win |
| Connection handshake | PQ | only cipheron has it built-in |
| Heavy userbot (files + messages) | all modes | cipheron wins everything |
Each Telegram file transfer splits into 512 KB IGE-encrypted chunks. At ~800 MB/s vs ~130 MB/s, crypto overhead per chunk drops from ~4ms to ~0.6ms: your CPU is essentially free and the network is your only limit.
๐ API Reference
| Function | Description |
|---|---|
ige256_encrypt(data, key, iv) |
AES-256 IGE encrypt |
ige256_decrypt(data, key, iv) |
AES-256 IGE decrypt |
ctr256_encrypt(data, key, iv, state) |
AES-256 CTR encrypt |
ctr256_decrypt(data, key, iv, state) |
AES-256 CTR decrypt |
cbc256_encrypt(data, key, iv) |
AES-256 CBC encrypt |
cbc256_decrypt(data, key, iv) |
AES-256 CBC decrypt |
encrypt_ige(data, key, iv) |
Alias โ ige256_encrypt |
decrypt_ige(data, key, iv) |
Alias โ ige256_decrypt |
factorize_pq_pair(pq) |
RSA PQ factorization (Telegram handshake) |
has_aesni() |
True if hardware AES is available |
get_backend() |
Backend string e.g. "C/EVP+ARM-CE" |
๐ License
MIT ยฉ 2024-Present Ankit Chaubey
๐จโ๐ป Developed by
Ankit Chaubey
๐ง ankitchaubey.dev@gmail.com
๐ github.com/ankit-chaubey/cipheron
If cipheron made your Telegram bots or scripts faster: drop a โญ star, it genuinely helps!
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
File details
Details for the file cipheron-0.2.1.tar.gz.
File metadata
- Download URL: cipheron-0.2.1.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55ef1e841c5a6c76f79b1cb915a0fedb6425f4094dbadccbebae1babb59dcade
|
|
| MD5 |
c1309fc44c251ac8b018645d9899731b
|
|
| BLAKE2b-256 |
ed699a5adc4ce08cc6cd7a697d214394ab68d4b30073c1fe59ed21681d507c1c
|
Provenance
The following attestation bundles were made for cipheron-0.2.1.tar.gz:
Publisher:
publish.yml on ankit-chaubey/cipheron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cipheron-0.2.1.tar.gz -
Subject digest:
55ef1e841c5a6c76f79b1cb915a0fedb6425f4094dbadccbebae1babb59dcade - Sigstore transparency entry: 1821070325
- Sigstore integration time:
-
Permalink:
ankit-chaubey/cipheron@098b25c332fadaabdc6399c1317374d92ab71a84 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ankit-chaubey
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@098b25c332fadaabdc6399c1317374d92ab71a84 -
Trigger Event:
workflow_dispatch
-
Statement type: