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_decrypt
All functions match the reference C implementation's behavior and signatures exactly (verified against the full upstream NIST/random test suite).
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 tgcrypto-zig 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| tgcrypto_zig-0.1.1-cp314-cp314-manylinux_2_28_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.28+ x86-64 | Details |
| tgcrypto_zig-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64 | Details |
| tgcrypto_zig-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details |
| tgcrypto_zig-0.1.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: 4.0 MB
Release files / tgcrypto_zig-0.1.1-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | tgcrypto_zig-0.1.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 |
4d08e21af4a69d88f796f28039fca7a2e939d34a0f173ad12cab5c4e00d22f00
|
|
BLAKE2b-256 checksum How to use checksums |
a361740bb830047d8539cef2e7b6717e5d223c71fd72949f433ee65be2ab7009
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / tgcrypto_zig-0.1.1-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | tgcrypto_zig-0.1.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 |
35b60c95acf7929d87cf5d593bfc7c8efd699a93ff4e327a43b83d559410466b
|
|
BLAKE2b-256 checksum How to use checksums |
fa9a851202eae3140e27300d6f4f3025c5e2d32432b7fe64309937899c565b89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / tgcrypto_zig-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | tgcrypto_zig-0.1.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 |
5c7419abf27f1a7e713e9dc0c41c2c2e9ba8310b4de14db3c649fb27664bef61
|
|
BLAKE2b-256 checksum How to use checksums |
5ed35762c4898237a538a30c45e0d31cbf732d635969ac756916617285a44e7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / tgcrypto_zig-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | tgcrypto_zig-0.1.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 |
4bf2a11f1a4e712a89715f5e9fe5496f66685e304c78e30b5674fad8552e19f7
|
|
BLAKE2b-256 checksum How to use checksums |
59060d016f3c60897d78459e12d6ff026e1121ee443d8705f48c2e873c28fe8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|