Skip to main content

Fast and Portable Cryptography Extension Library for Pyrogram, Rust rewrite of TgCrypto

Project description

TgCryptoX

Fast and Portable Cryptography Extension Library for Pyrogram.

Provides AES-256 encryption/decryption in IGE, CTR, and CBC modes, implemented in Rust with PyO3 bindings.

Installation

pip install TgCryptoX

Usage

import tgcrypto
import os

# AES-256-IGE
key = os.urandom(32)
iv = os.urandom(32)
data = os.urandom(64)

encrypted = tgcrypto.ige256_encrypt(data, key, iv)
decrypted = tgcrypto.ige256_decrypt(encrypted, key, iv)

# AES-256-CTR
key = os.urandom(32)
iv = bytearray(os.urandom(16))
state = bytearray(b"\x00")
data = os.urandom(100)

encrypted = tgcrypto.ctr256_encrypt(data, key, iv, state)

# AES-256-CBC
key = os.urandom(32)
iv = bytearray(os.urandom(16))
data = os.urandom(64)

encrypted = tgcrypto.cbc256_encrypt(data, key, iv)

Benchmark

Tested on Apple M-series (aarch64), Python 3.14, with ARMv8 hardware AES enabled.

Size Mode TgCrypto (C) TgCryptoX (Rust)
16B IGE Encrypt 409ns 418ns
256B IGE Encrypt 658ns 604ns
4KB IGE Encrypt 4.7us 4.8us
64KB IGE Encrypt 72.0us 71.8us
1MB IGE Encrypt 1.12ms 1.11ms
1MB IGE Decrypt 1.09ms 1.09ms
1MB CBC Encrypt 1.33ms 1.34ms
1MB CBC Decrypt 171.8us 162.8us
1MB CTR 1.28ms 1.37ms

Performance is on par with the original C implementation.

Why Rust?

TgCrypto (C) TgCryptoX (Rust)
AES core T-table lookup, vulnerable to cache-timing side-channel attacks RustCrypto aes crate: auto-detected hardware AES (AES-NI / ARMv8) + constant-time fixsliced software fallback, side-channel resistant
Memory safety Manual malloc/free, risk of leaks and buffer overflows Compile-time memory safety guaranteed by Rust's ownership system, no use-after-free or buffer overflows
Python bindings Hand-written Python C API (~244 lines), error-prone Auto-generated via PyO3 macros (~120 lines), type-safe
GIL release Manual Py_BEGIN/END_ALLOW_THREADS Managed by py.detach()
Build system setuptools + C compiler configuration Single-command build with maturin, no C toolchain needed
Cross-platform wheels Complex cibuildwheel configuration required Native multi-platform support via maturin
Code size ~900 lines C + ~80 lines setup.py ~250 lines Rust + ~30 lines TOML

Acknowledgements

This project is a Rust rewrite of TgCrypto by Pyrogram. Thanks to the original project for the API design, test vectors, and inspiration.

License

LGPL-3.0-or-later

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

tgcryptox-1.0.1.tar.gz (37.9 kB view details)

Uploaded Source

Built Distributions

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

tgcryptox-1.0.1-cp314-cp314-win_amd64.whl (117.8 kB view details)

Uploaded CPython 3.14Windows x86-64

tgcryptox-1.0.1-cp314-cp314-manylinux_2_34_x86_64.whl (220.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

tgcryptox-1.0.1-cp314-cp314-macosx_11_0_arm64.whl (187.4 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

tgcryptox-1.0.1-cp313-cp313-win_amd64.whl (117.8 kB view details)

Uploaded CPython 3.13Windows x86-64

tgcryptox-1.0.1-cp313-cp313-manylinux_2_34_x86_64.whl (220.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

tgcryptox-1.0.1-cp313-cp313-macosx_11_0_arm64.whl (187.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

tgcryptox-1.0.1-cp312-cp312-win_amd64.whl (117.8 kB view details)

Uploaded CPython 3.12Windows x86-64

tgcryptox-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl (221.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

tgcryptox-1.0.1-cp312-cp312-macosx_11_0_arm64.whl (187.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file tgcryptox-1.0.1.tar.gz.

File metadata

  • Download URL: tgcryptox-1.0.1.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tgcryptox-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d89854889d865e5e49315da34107ff72abdc56c9d8edf74beb1a371be7a39f5e
MD5 c20bc95fe291186fa5cf82fc187aeaae
BLAKE2b-256 648b75a92a57a9425a13eb61a55ef6ce7c34a2a0d3cf68987fc1a6f10da80f0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1.tar.gz:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: tgcryptox-1.0.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 117.8 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tgcryptox-1.0.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 520e2d2d2602a3faf26fb9b259ef6b5c4dc62d1c8dacbc4fae381c6d4c8db70e
MD5 9a524010b093ec962960dd0726c3a9f5
BLAKE2b-256 d9c9439790024207102bbadcea440d75429bb877e6c13b2a9f95d0fc6c7f9f56

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp314-cp314-win_amd64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for tgcryptox-1.0.1-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b5320d0c91d624ae9570ee1970dd9ea8a247d926d8bf00d1756fd64f95e3a1a3
MD5 2e34fdc0f20848dd7057220d6aa10c2e
BLAKE2b-256 279e42f95b1d1a8c347faccdc5bf5f695ef12e28a326bb4d1ef5c50341a50fe5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp314-cp314-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tgcryptox-1.0.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8fca6d655d38a6891873c643b0e3907fbcad8260aae767044f443b74d4478f3a
MD5 076e1dda3f6f357c6773f486325ae302
BLAKE2b-256 a952243b735e3b9e036a808bee60ee7648f6a52da8838a92b6da313743bc7ae0

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: tgcryptox-1.0.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 117.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tgcryptox-1.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 394d6b5722bbcdf04ec6563292cb6f488f14cb4f913aeb181dffc8c23850d067
MD5 fccf0790db944b34d6f0289a1725f113
BLAKE2b-256 9d15a42e0b376a1379f7e066b6d84f7742d14a1b4df44a1461f7be0cf262c52d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp313-cp313-win_amd64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for tgcryptox-1.0.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b19881ba0e5a3f40719adfe685799c6bd2b042c99e55d544bab056c8a935f3a8
MD5 429675eacb580f83b3869654c73624a0
BLAKE2b-256 8d5f8ed4705be7517f41b4c0c408d04659fa35c55efffd99ee88107501089fd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tgcryptox-1.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4dba3ab1b737f4a23e4305e75c6eaac1d06d812da252269d0005664d9a16e84
MD5 7726dca2ab1fec54f5fd55320436bb47
BLAKE2b-256 9afebd2cd1d361cedc863105af5d8c45e67fc51689e70f4230f2eb8f6e9019eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: tgcryptox-1.0.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 117.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tgcryptox-1.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 65b42b49593cff4f55923ef3cafe9025e25d6725a380a78f54f9673d14ad7fbe
MD5 48024511596af5e438ccdd3ef4473052
BLAKE2b-256 da4a5c530459eea37eb98f35e39695aa3a671b320bcdc5ab68434ab1dfbc17a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp312-cp312-win_amd64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for tgcryptox-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f144f528409047cff37be53c3af82eb604986a5ceaa8a35835d481fc44f0ec4a
MD5 c194e168d991e4d549ae3b43f2c7a071
BLAKE2b-256 eb834cc4321dbaf4958c544e2e3c21921f7bf51035f7707a7d71ed2c5bea0365

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tgcryptox-1.0.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tgcryptox-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 59e8e7690b8ab71eb7e386b9c4c79ad3051fb84af175c3f23a92fc22bd5cf140
MD5 753de3f8512c359e6dc96cc5b7bc284f
BLAKE2b-256 559e667bc93f2bcce5016a125af672f507e2dc758ba9e5e8a7188b7457c7b3ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for tgcryptox-1.0.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: ci.yml on SychO3/tgcryptoX

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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