Fast and Portable Cryptography Extension Library (Rust)
Project description
WarpCrypto
Fast Cryptography Extension Library — Rust Implementation
WarpCrypto is a high-performance cryptography library written in Rust as a Python extension (via PyO3 + maturin). It implements the cryptographic algorithms required by Telegram's MTProto protocol:
AES-256-IGE— used in MTProto v2.0AES-256-CTR— used for CDN encrypted fileskdf— key derivation function per MTProto 2.0 specpack_message/unpack_message— combined KDF+AES-IGE in a single call (1 GIL release vs 3 for tgcrypto)
Features
- 3–5× faster than tgcrypto (C extension) in multi-client benchmarks
- AES-NI hardware acceleration via the
aescrate's runtime CPU feature detection (cpufeatures) - Zero-copy IGE with block-aligned GenericArray operations
- Block-based CTR — processes 16-byte blocks with
chunks_exact_mut, not byte-by-byte - Proper state propagation — IV and state bytearrays are mutated in-place matching tgcrypto exactly
- Memory safe — Rust's type system guarantees no buffer overflows, use-after-free, or data races
- Zero compiler warnings
Requirements
- Python 3.8 or higher
- Rust toolchain (for building from source; pre-built wheels available for most platforms)
Installation
pip install WarpCrypto
Install from source:
pip install maturin
maturin build --release
pip install target/wheels/*.whl
API
def ige256_encrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
def ige256_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray) -> bytes: ...
def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray) -> bytes: ...
def kdf(auth_key: bytes, msg_key: bytes, outgoing: bool) -> tuple[bytes, bytes]: ...
def pack_message(data: bytes, salt: int, session_id: bytes, auth_key: bytes, auth_key_id: bytes) -> bytes: ...
def unpack_message(packed: bytes, session_id: bytes, auth_key: bytes, auth_key_id: bytes) -> bytes: ...
Usage
IGE Mode (MTProto 2.0)
import os
import warpcrypto
data = os.urandom(10 * 1024 * 1024)
key = os.urandom(32)
iv = os.urandom(32)
ige_encrypted = warpcrypto.ige256_encrypt(data, key, iv)
ige_decrypted = warpcrypto.ige256_decrypt(ige_encrypted, key, iv)
assert data == ige_decrypted
CTR Mode (CDN)
import os
import warpcrypto
data = os.urandom(10 * 1024 * 1024)
key = os.urandom(32)
enc_iv = bytearray(os.urandom(16))
dec_iv = bytearray(enc_iv)
ctr_encrypted = warpcrypto.ctr256_encrypt(data, key, enc_iv, bytearray(1))
ctr_decrypted = warpcrypto.ctr256_decrypt(ctr_encrypted, key, dec_iv, bytearray(1))
assert data == ctr_decrypted
KDF (MTProto 2.0 key derivation)
import warpcrypto
auth_key = bytes(range(256))
msg_key = os.urandom(16)
aes_key, aes_iv = warpcrypto.kdf(auth_key, msg_key, outgoing=True) # x=0
aes_key, aes_iv = warpcrypto.kdf(auth_key, msg_key, outgoing=False) # x=8
Testing
pip install pytest
pytest
Performance
WarpCrypto outperforms tgcrypto (C extension) by 3–5× across all client counts (1–128 concurrent clients). Performance scales with AES-NI availability (most x86_64 and Apple Silicon CPUs).
License
LGPLv3+ — Originally by Dan. Rust port maintained by Riajul.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file warpcrypto-2.0.1-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 139.8 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30130bc0ede5b792ae733604c5a33c2965e6b068eba841cb748b35f5be236082
|
|
| MD5 |
ebf0f1df8b1344c9e22d1bdeaf11f3f5
|
|
| BLAKE2b-256 |
6b9e92921c510cdb8f114bffd0a3b6ddbb380d6d61755d72de34ec939067fc1f
|
File details
Details for the file warpcrypto-2.0.1-cp314-cp314-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp314-cp314-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 230.0 kB
- Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
402b320eaabfaf17e3f4139dd3565bc65b08b8a647ba58eebded6fa6426cd480
|
|
| MD5 |
345c6e748856802ab7755e97dc539f07
|
|
| BLAKE2b-256 |
f52878cee5bd141be6bb1d4067467a536ce8ebb9027034608dae71ee3b3cb65d
|
File details
Details for the file warpcrypto-2.0.1-cp314-cp314-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp314-cp314-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 219.0 kB
- Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2b25a59f43b8fce5eb422364cb81efa67be36497fa2a95d64ce112c247ea0e2
|
|
| MD5 |
8d431594911e7fe32d6917aebd518ffe
|
|
| BLAKE2b-256 |
d8845b813d461dced6cee37fe00a4490f5574ed75f416c7e9d97e5bcb30e4270
|
File details
Details for the file warpcrypto-2.0.1-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 209.5 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b8945070c471b9ca8df250563b92053fc1287fea86c0bcd9c0283b7b7bc95b0
|
|
| MD5 |
c7e9e8afab146a365235e7bd332ec3f5
|
|
| BLAKE2b-256 |
0610f52d59f388e900975087e53ec73e08392d3658203f4ad78708aa0dafccc8
|
File details
Details for the file warpcrypto-2.0.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 139.7 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd62b8bc01dba7ef5463d191a9c6d6d55df255562b77b55b4257293efa450d9a
|
|
| MD5 |
f5796727a3e417a0eae3649f56c14733
|
|
| BLAKE2b-256 |
539b7d4040aaf0724c7ca377269749cc10a839a037fe89c5c9c8f50188a7672d
|
File details
Details for the file warpcrypto-2.0.1-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 229.5 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
738dd6671ca897d37436131ff14a9f68c9e0ec8bc03b39e36a2ad56a52a1f877
|
|
| MD5 |
59e16e54545988a6dc0677ed701ef957
|
|
| BLAKE2b-256 |
ec4de9886c6a8355f5027d68ddd3828b2b668035b2d329e32d2b1898edff4e49
|
File details
Details for the file warpcrypto-2.0.1-cp313-cp313-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp313-cp313-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 218.3 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abb114214c1cc954bd8b2b87f9f7355f815b8a68206e76ee074b9db099362568
|
|
| MD5 |
0250e77f53cff03eb3aa88dc972761ed
|
|
| BLAKE2b-256 |
fcda8b08b2532294f52ff57db8e28d58cc0f5fc759d94163e789bc7c07a66a6d
|
File details
Details for the file warpcrypto-2.0.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 209.2 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee3851dcb6bb865c35848bd8cd6a89377418a6f6d7b48e4b9e7d6deb44ce4c1b
|
|
| MD5 |
9ad749edf23754f07ef502cf6f310e2f
|
|
| BLAKE2b-256 |
36f3af691f7ec0e2375e6f162bfcb214f985c1ca69c8219b5b9013bb6434e809
|
File details
Details for the file warpcrypto-2.0.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 139.7 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
083107fb198c1f4a37588f15bb1722759320acd14e6f0947d9f2e3271d237fca
|
|
| MD5 |
edb1cdce61c82a84ae639153c92480a1
|
|
| BLAKE2b-256 |
b71c50059c21e8f19dbf31347352197d5ce1cdad052ac70952fe756254e17b5c
|
File details
Details for the file warpcrypto-2.0.1-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 229.7 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83ae4ca68017d10a48d91b48b27cefd716000562bb587e3ec3e7bce4fd0e6f0b
|
|
| MD5 |
0279e47c88e9879fdc6f39ccebd2af2c
|
|
| BLAKE2b-256 |
21c1e040cc635f08d65e5439491e1a4a18f62e27cfa68287c7d92aff2c7c58f6
|
File details
Details for the file warpcrypto-2.0.1-cp312-cp312-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp312-cp312-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 218.6 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
327762b5b5039eeb470f1e4deef3ca69a89113ba94e8c22c39fc575ab090e839
|
|
| MD5 |
e4df77470a32700f1a028efc3523e38f
|
|
| BLAKE2b-256 |
a09c169995d4398b388ce6333b3111910d8acd35da2548c51623bde3b899fffb
|
File details
Details for the file warpcrypto-2.0.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 209.1 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ad775677c29e1a987a0b162145bd7cb7011d62adb3770e09ed0fa31e8f14144
|
|
| MD5 |
866a91f633cf4587d32f9b310c947a7c
|
|
| BLAKE2b-256 |
c8539ce3118681cd2471a2d38aa5d7da2aad201bc0939d9f4d07295ba9b13be8
|
File details
Details for the file warpcrypto-2.0.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 141.9 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
111729b89e77bd995022ff4995c7ccd493a2172506b1d1c798899b679cd11256
|
|
| MD5 |
bd5959189f44c76138e877a99f686350
|
|
| BLAKE2b-256 |
7855352de43c9d6cb7a25ffd3be527270370124bf072ac36b050976c9744ef63
|
File details
Details for the file warpcrypto-2.0.1-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 230.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd0f63edb4bf327df74a09ec2459b40e15b69adde1be0be6761a33bec7794b30
|
|
| MD5 |
eb70efc65a14679c54c0ad7db143a732
|
|
| BLAKE2b-256 |
c6d26a20beb852950b2558dd5e3f29ddc45333d615c91b4c9ddc8e4aea129362
|
File details
Details for the file warpcrypto-2.0.1-cp311-cp311-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp311-cp311-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 219.7 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e600cdff9272eddd3cc92c706be2c5637844f6c17727b4b42d45df2bbefaee85
|
|
| MD5 |
b43b5947667b56e2182a588d24e5de33
|
|
| BLAKE2b-256 |
d850d9c89a9fca480bd49fb2d51a02529d3c6ed581d9c13e23057ebbd6d9f391
|
File details
Details for the file warpcrypto-2.0.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 210.7 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
260d83d9edebe3d6604eeb072064ac0947eb7cf4351f06652bab0aca71cd682d
|
|
| MD5 |
c2301a8a64986cb0bed2fd7df06745d8
|
|
| BLAKE2b-256 |
b16fca6c6189750bde2c45a4fb093af3e7a8da9aeedd99d454654a9262e83a6f
|
File details
Details for the file warpcrypto-2.0.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 142.0 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd2e237d40fec25d44f2cf06157845f7cc6981d9d91148a5e5a4df93aad142db
|
|
| MD5 |
6c1a1190e5c977504449fa4d77f3fa77
|
|
| BLAKE2b-256 |
5c0ece54f179e7f63022dcae453718527446dd95a4fd92e50a3c12730508367d
|
File details
Details for the file warpcrypto-2.0.1-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 230.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1946e73c86b1d603077ff6cfef52376e0a7fdbd316caaf258bda054b1b22c90c
|
|
| MD5 |
8c2a6c73a3d90eccd4fbc036a7dfe282
|
|
| BLAKE2b-256 |
1940cc4a114215cb7e57a612007df571b3a31fe1abcdce5d77e1af41f5b6a491
|
File details
Details for the file warpcrypto-2.0.1-cp310-cp310-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp310-cp310-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 219.5 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10eca3cc35ea98e027c757a515bd67e6aac045d201d017a08924ab32f2023f30
|
|
| MD5 |
e0203a5b50d4650c72f9b808b30877e9
|
|
| BLAKE2b-256 |
02e6cd6e78626f9d36e4cbb6778dd1c7743ce28414da9c3da29a6bd9c4e8043f
|
File details
Details for the file warpcrypto-2.0.1-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 210.8 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
315dc8bf7b76c867cc56058d45f50681185d6c96601e0036463370cc47009854
|
|
| MD5 |
41c9d6a406f9975e47b5defdac2cc0d2
|
|
| BLAKE2b-256 |
170f90b5cc75ed3c9ecb4cb3a6c20dc33f5e62d6cd6e2f6b3ffc721d1aca2397
|
File details
Details for the file warpcrypto-2.0.1-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 142.4 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a5757ab2ca0a8199834af01efb7cf27d5404f8280ae26c43cd5ccb681e66406
|
|
| MD5 |
a43404ef4ba6858e3feb6fa81f80e0fe
|
|
| BLAKE2b-256 |
42e51a9277ba27658e19b556c7ef8d4d232bea664e02d3647c4316f490cb0332
|
File details
Details for the file warpcrypto-2.0.1-cp39-cp39-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp39-cp39-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 230.8 kB
- Tags: CPython 3.9, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48fe6cd19a61cc628b5ee8185d5900bdbe0783a0efcc81de2fded305bd7e4511
|
|
| MD5 |
bcafe9ae7760e0b3c3687879551fe85d
|
|
| BLAKE2b-256 |
f5cb3d25770e0719a3046e3930bda9872bbaeb756aa8bc949ebd2807377b0ea5
|
File details
Details for the file warpcrypto-2.0.1-cp39-cp39-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp39-cp39-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 219.9 kB
- Tags: CPython 3.9, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2332837ea4d0a24bd3278af9d4c039957566ad59c2548fd9e57684746045c4a
|
|
| MD5 |
ee2dfc10c7a8f78d1cd3d8fc8b9dfa47
|
|
| BLAKE2b-256 |
c6c5477e98e879ea7b7756fb3d9f9e3fb72379a7287e0a73169ebfed878a983d
|
File details
Details for the file warpcrypto-2.0.1-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: warpcrypto-2.0.1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 211.3 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7d78418b499cfc7ca53b2848917247a6f409fd730f9ce6a920d29e5a68f2542
|
|
| MD5 |
ff9ed7e1394ca5f2fd57a063836d7139
|
|
| BLAKE2b-256 |
8d9716208109b18633b2f28057cff3abc2a0ea99e315ac04c6becebb6beef72f
|