WarpCrypto

WarpCrypto: TgCrypto, Rewritten in Rust

WarpCrypto is a Python extension written in Rust (built with PyO3 and maturin). It implements the cryptography Telegram’s MTProto protocol needs, and works as a drop-in replacement for TgCrypto.

What It Implements

Key Features

Performance Work

Most of the speed comes from keeping the hot loop inside the AES backend. IGE chains block to block, so the dispatch cost of each block call used to dominate. Running the whole loop inside the backend removed it. CTR keeps an 8-block unroll so blocks are processed in parallel.

Cutting redundant buffer copies gave unpack_message a 41.8% speedup on 1 MiB messages, with output byte-identical to earlier builds.

Try It

pip install WarpCrypto
import os
import warpcrypto

data = os.urandom(1024)
key, iv = os.urandom(32), os.urandom(32)

encrypted = warpcrypto.ige256_encrypt(data, key, iv)
assert warpcrypto.ige256_decrypt(encrypted, key, iv) == data

See the source on GitHub!

← All projects