tgcrypto2 (Zig backend)
Fast and Portable Cryptography Extension Library for Pyrogram — reimplemented
in Zig 0.16, drop-in compatible with the original C extension, plus a native
xor(a, b) helper.
Build & publish to PyPI
python -m pip install --upgrade build twine
python -m build # produces sdist + wheel in dist/
twine upload dist/*
ziglang==0.16.0 is declared as a [build-system] requires dependency in
pyproject.toml, so pip/build fetches it automatically into an isolated
build environment — no system Zig install needed, and no .so is committed
to the repo. When someone runs pip install tgcrypto2, setup.py's custom
build_ext step shells out to python -m ziglang build so to compile
src/tgcrypto.zig fresh for their platform/Python version, then places the
resulting _tgcrypto extension where Python expects it.
Local development build
pip install -e .
python -m pytest
What's inside
ige256_encrypt,ige256_decryptctr256_encrypt,ctr256_decryptcbc256_encrypt,cbc256_decryptxor— native byte-wise XOR (not in the original C_tgcrypto; added so callers don't need a slow Python-bignumxorfallback)
All six original functions match the reference C implementation's behavior and signatures exactly (verified against the full upstream NIST/random test suite — 3871 tests, all passing).
Free-threading (Python 3.13+ / PEP 703)
_tgcrypto opts into running under a free-threaded (Py_GIL_DISABLED,
python3.1xt) interpreter via the Py_mod_gil module slot. This matters
because a C extension that does not declare support gets silently
downgraded by CPython: the GIL is re-enabled for the entire process for
as long as that module stays imported, not just for that module — so an
unaware dependency can quietly take away the benefit of free-threading from
everything else running in the same interpreter.
This module is safe to opt in because every exported function is stateless
per call: each allocates and returns a fresh output buffer, and the AES
context (std.crypto.core.aes) lives on the stack for the duration of a
single call with no shared mutable state. The one thing to be aware of:
ctr256_*/cbc256_* mutate the caller-supplied iv/state buffer in
place (matching the reference C behavior and this project's own upstream
tests, which pass plain bytes). If the same bytearray is handed to
two threads concurrently, that's a data race in the caller's Python code —
no different from any two threads mutating a shared mutable object without
a lock, and not something the GIL was protecting either, since the GIL is
already released around the actual compute.
On Python < 3.13 (no Py_mod_gil slot exists) this is a no-op — the module
builds and behaves identically to a normal GIL-bound extension.
Metadata
Release files for vugusu 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| vugusu-2.0.1-cp315-cp315-musllinux_1_2_x86_64.whl | CPython 3.15 | CPython 3.15 | Linux musl 1.2+ x86-64 | Details |
| vugusu-2.0.1-cp315-cp315-manylinux_2_28_x86_64.whl | CPython 3.15 | CPython 3.15 | Linux glibc 2.28+ x86-64 | Details |
| vugusu-2.0.1-cp314-cp314-musllinux_1_2_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux musl 1.2+ x86-64 | Details |
| vugusu-2.0.1-cp314-cp314-manylinux_2_28_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.28+ x86-64 | Details |
| vugusu-2.0.1-cp313-cp313-musllinux_1_2_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux musl 1.2+ x86-64 | Details |
| vugusu-2.0.1-cp313-cp313-manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64 | Details |
| vugusu-2.0.1-cp312-cp312-musllinux_1_2_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux musl 1.2+ x86-64 | Details |
| vugusu-2.0.1-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details |
| vugusu-2.0.1-cp311-cp311-musllinux_1_2_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux musl 1.2+ x86-64 | Details |
| vugusu-2.0.1-cp311-cp311-manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.28+ x86-64 | Details |
Total release size: 10.1 MB
Release files / vugusu-2.0.1-cp315-cp315-musllinux_1_2_x86_64.whl
| Download URL | vugusu-2.0.1-cp315-cp315-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.15 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
0515525a789a3dcbf2d56c380e04a9d70122b671bf9fad2e44f08e22898d63ab
|
|
BLAKE2b-256 checksum How to use checksums |
154427ad0c669a1b776dfff4772464a6b56dcf2292c931778b5716b5ab75f469
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp315-cp315-manylinux_2_28_x86_64.whl
| Download URL | vugusu-2.0.1-cp315-cp315-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.15 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1228f0dfba01bcb5831a9d1146f3b6c3842004b95514088597b6a9c4c3c73360
|
|
BLAKE2b-256 checksum How to use checksums |
b681498ec4b447ec6461055c90d14ec36c7a51a42a8268a7e7db8645c127c0bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp314-cp314-musllinux_1_2_x86_64.whl
| Download URL | vugusu-2.0.1-cp314-cp314-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.14 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
8f6ee0d3dd467bbe0444da5701934b34f870e2eddf70a1edd0e4196a974f196a
|
|
BLAKE2b-256 checksum How to use checksums |
ff7927500c293ac7f85e611b0e9ee76e0a80829e87dbe051efa34dff10734323
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | vugusu-2.0.1-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
6f587c8b811b485e42b16079eab6feeed42864aa5348b98b1ad4657203dc9bf7
|
|
BLAKE2b-256 checksum How to use checksums |
710f98782307d61b8b01b04d63e1fc7684e495284707a56def5ccd0bc81479b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | vugusu-2.0.1-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
341d99481db2d9423b91e95dbb4e3d8037ed8ac468055b3edecd9264a2f980b8
|
|
BLAKE2b-256 checksum How to use checksums |
4cf70a0490518cb2a70b3f5db2179cf7e65b789e098498314069420ae0d20e98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | vugusu-2.0.1-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
9e32c1df35ead9728cfc12b69efd495f8121437df200c66d639f98886dd0d5dc
|
|
BLAKE2b-256 checksum How to use checksums |
3ba80329ddbce663f22304dd7c948edbd9ce261c5747d4e335225733ca3dba2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | vugusu-2.0.1-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
e12a25319aa94d647dfe93864eb4a29ebc2abeb2d0998796635298af84d27374
|
|
BLAKE2b-256 checksum How to use checksums |
e2de0924234add017622a96e3d14ab0a772052c669cecf791676b3c4ab965c99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | vugusu-2.0.1-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
856ba1bb6bb9c6a9b9865ffa1120429542192066422680af5bd7a6bda37d2548
|
|
BLAKE2b-256 checksum How to use checksums |
75c6160e901010ee5f072baae0be94f3ab25d2cd9c536217c5b2a138ccf93db5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | vugusu-2.0.1-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
53be43f61564e40e85a613b91a0bd186b3fc419fc13e8c165a38c3606c70dec1
|
|
BLAKE2b-256 checksum How to use checksums |
0340c3c584c5ff777975f829de2a628a93928355ed5b81f4d0230154b87d2136
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / vugusu-2.0.1-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | vugusu-2.0.1-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
f74855eed59a0c441970b45f97abfc418ca80321d0b41fc0e2d174d6879e2eee
|
|
BLAKE2b-256 checksum How to use checksums |
d85744669cdcd8b84e23416f54c4578add1eb156ef56809fd634d4883498b6cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|