Skip to main content

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.0
  • AES-256-CTR — used for CDN encrypted files
  • kdf — key derivation function per MTProto 2.0 spec
  • pack_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 -C target-cpu=native (automatic runtime detection)
  • 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).

Clients tgcrypto (ops/s) WarpCrypto (ops/s) Speedup
1 82,018 306,232 3.73×
16 128,655 371,855 2.89×
64 121,142 406,384 3.35×
128 94,975 501,293 5.28×

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

warpcrypto-2.0.0-cp314-cp314-win_amd64.whl (140.5 kB view details)

Uploaded CPython 3.14Windows x86-64

warpcrypto-2.0.0-cp314-cp314-manylinux_2_34_x86_64.whl (230.6 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

warpcrypto-2.0.0-cp314-cp314-macosx_11_0_arm64.whl (210.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

warpcrypto-2.0.0-cp313-cp313-win_amd64.whl (140.3 kB view details)

Uploaded CPython 3.13Windows x86-64

warpcrypto-2.0.0-cp313-cp313-manylinux_2_34_x86_64.whl (230.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

warpcrypto-2.0.0-cp313-cp313-macosx_11_0_arm64.whl (209.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

warpcrypto-2.0.0-cp312-cp312-win_amd64.whl (140.4 kB view details)

Uploaded CPython 3.12Windows x86-64

warpcrypto-2.0.0-cp312-cp312-manylinux_2_34_x86_64.whl (230.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

warpcrypto-2.0.0-cp312-cp312-macosx_11_0_arm64.whl (209.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

warpcrypto-2.0.0-cp311-cp311-win_amd64.whl (142.5 kB view details)

Uploaded CPython 3.11Windows x86-64

warpcrypto-2.0.0-cp311-cp311-manylinux_2_34_x86_64.whl (230.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

warpcrypto-2.0.0-cp311-cp311-macosx_11_0_arm64.whl (211.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

warpcrypto-2.0.0-cp310-cp310-win_amd64.whl (142.6 kB view details)

Uploaded CPython 3.10Windows x86-64

warpcrypto-2.0.0-cp310-cp310-manylinux_2_34_x86_64.whl (231.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

warpcrypto-2.0.0-cp310-cp310-macosx_11_0_arm64.whl (211.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

warpcrypto-2.0.0-cp39-cp39-win_amd64.whl (142.6 kB view details)

Uploaded CPython 3.9Windows x86-64

warpcrypto-2.0.0-cp39-cp39-manylinux_2_34_x86_64.whl (231.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

warpcrypto-2.0.0-cp39-cp39-macosx_11_0_arm64.whl (211.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file warpcrypto-2.0.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 9ba1e1725f166c0c434bc6dd7920014600b688826110520911ae3b81b7aed409
MD5 259933723c3fb4a853296dbb1bf057ee
BLAKE2b-256 2cbda3772dbd14fe3af7144dcabe90ea78a36656e46ebb28b666c72af8f0f21e

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7c9fd2bf3b8460c0e12a99ec9552a01cf9263870ba6b66b278628908123ff784
MD5 73dbe65dc2d8f97ba851e3ca367a22e3
BLAKE2b-256 21b5a9739e84635354273ee4a3a874299f4631c301356de12eba35eedea4b485

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a0b9b03c34e70bd2d7b2c767c7486e5712c08f8ab5d729039e60ef808a196e9f
MD5 8bb75f282a3b42e9790b71c06cbd77e3
BLAKE2b-256 bd797b25bd5780450fa0ea037a01206a30d16125c5b41c60286f0cca5e8e1436

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2bb40d1ffcab207c9a4d9ad532b65103d1c2f2264a8f3c13436617201a98ddb3
MD5 d2acf9340a383d6d0ccb154381de924c
BLAKE2b-256 80d4c81d5372ac8beecef7be33a48f369dc40bbb93f287ae7af928f24ad3a816

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 cfc8196f7b757816eaf87ad171ee5f1946693daebc9665db5456d7b1b9cd7d13
MD5 0c27540f1044e8e400e3dce11e9f559b
BLAKE2b-256 5d8c5ec86c887772596761f2787ce8e80c700af70c6dffe82662e5690ca77f30

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f49b224bd74b91c345086cb26708be1af234e18b8bb89102579acaa4141d9e28
MD5 ad8fd33303921be35295d7bd96e5db24
BLAKE2b-256 20f116aabff1d4ab625bc34e0b340127af36dbe16e1f90a6395825115d311518

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c3b0f8d72daa31e49e05f2cc5b7582d655d95ac8982b3c1366284411c66b77ab
MD5 1dff97c030f20f4fb8373e17988e690d
BLAKE2b-256 2106b9ace26e774eba56aea44897c7c752726ec0626e84fbedcd9d4503f06efb

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a7540642f619fbba28335e098eaa93261ff513541ce0dfe97c25171184ba6aa1
MD5 ac6d32679e598495e59575a25b3e2775
BLAKE2b-256 0199d6514abbb214f89e2a896291ed62268db92ffe4489187696a689f98cf33d

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3188c7e360d52a372895f6cc8fd05d4a423c2c1884b9e4567675c0429ce14259
MD5 6fd33b4e4a6691c81f8bddd450a53e8f
BLAKE2b-256 8a8d342c6134714061f7a9a1edd1073d59ca76bab9566951837f6e12de235422

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3588a06123f7129025d165f108c87be7343536f411e6ef3075c7043a63f0d4f2
MD5 fae34174b4212a89960541359702ce94
BLAKE2b-256 97830b477bf04cf19ba5c7d8bf959a0581b4a7dd0032f16a7e7a60711b7a4d06

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4f6649506dd546bbf074d62856d03a63a65c9b76c86bd884fe5ce1c3f167d20c
MD5 8605b22b6115995e9d88c6c51b35d697
BLAKE2b-256 1d4bc86d5bc8cb935a49bb17993c162a85c7c850c941774d19955995cc1fc01d

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fbdcb28861fe6c7fcc2bac7a14c1890c92cb9b223dbb28ed97a91c220a5bd338
MD5 5e9d6603e452bbd536415de232c63d95
BLAKE2b-256 717ff9020cd7d2a277fb837df24531e6a5e67686a72b2daeb30f126cc1c0d2f3

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e71f062e85e910a7289e42859c6178cfd5305920eabce0df1b5fe9bf46da93af
MD5 bd4b5b6d0451a080bf2feeae164a2e8f
BLAKE2b-256 4f4812bbcf1456e52bf01b609e5dcbf5821465c5864fc0d3facf522efeb326cb

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 93e1b2aa30f20f970110f9baef67abd3a2246d0d39ba09a807edabbad36583e9
MD5 9e5861cb386ac9a01cfbc3dc280b7030
BLAKE2b-256 e85bc1ef6a6357d303f3de13da2b8c126f9730c4bd9dbd3d189901fe8a7ac623

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 69ef5762a1835460a8681f3bb691fd2c41add47eb6c0793cf1f021007e5edeef
MD5 35490520009a8c163cb95016528285d7
BLAKE2b-256 b0c23c9b53db9f8048d1e6bfa85dc8de4fccbc1586f16776e59007664ef9c0cf

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 903053141fab094ed0258e6a3af7d1411c31a38f5d6f2a4f2ebf12166f74edd2
MD5 8195c43432db8a5c871253028e42b32d
BLAKE2b-256 5120dfd99653f76822da974ae3f18d8ca829e0046894b6f6db86ffed41db3bc2

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 52ca261e1eab57da23281c1f68644b4080e75aca4e7d22062b77d394387fcd6c
MD5 e24b152a14ae8d30036f58622428f8df
BLAKE2b-256 8e0744d3d810da47dc23dc133074a63d23eb5a1e803ddbe31a2a34dcf5652097

See more details on using hashes here.

File details

Details for the file warpcrypto-2.0.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for warpcrypto-2.0.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 62c665a731d37443fbb7f3d688538ecc336f9e56ee26e45856dc18089cf9f280
MD5 403a1b2921a6f5fb5c2db006401f99b4
BLAKE2b-256 17f72ef5089a827fe7593d4d2791e08b54b00ad95493cd4f5a69ba97b546df94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page