TgCryptoRust 1.1.2__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tgcrypto/__init__.py +32 -0
- tgcryptors/__init__.py +27 -0
- tgcryptors/_native.cp312-win_amd64.pyd +0 -0
- tgcryptorust-1.1.2.dist-info/METADATA +249 -0
- tgcryptorust-1.1.2.dist-info/RECORD +9 -0
- tgcryptorust-1.1.2.dist-info/WHEEL +4 -0
- tgcryptorust-1.1.2.dist-info/licenses/COPYING +674 -0
- tgcryptorust-1.1.2.dist-info/licenses/COPYING.lesser +165 -0
- tgcryptorust-1.1.2.dist-info/sboms/tgcryptors-python.cyclonedx.json +942 -0
tgcrypto/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Compatibility shim for projects that import TgCrypto as ``tgcrypto``.
|
|
2
|
+
|
|
3
|
+
TgCryptoRust exposes its native extension as ``tgcryptors`` and re-exports the
|
|
4
|
+
same API here so existing Telegram clients can switch packages without code
|
|
5
|
+
changes.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from tgcryptors import ( # noqa: F401
|
|
9
|
+
Ctr256,
|
|
10
|
+
Ige256,
|
|
11
|
+
__version__,
|
|
12
|
+
cbc256_decrypt,
|
|
13
|
+
cbc256_encrypt,
|
|
14
|
+
ctr256_decrypt,
|
|
15
|
+
ctr256_encrypt,
|
|
16
|
+
ige256_decrypt,
|
|
17
|
+
ige256_encrypt,
|
|
18
|
+
runtime_info,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"__version__",
|
|
23
|
+
"ige256_encrypt",
|
|
24
|
+
"ige256_decrypt",
|
|
25
|
+
"ctr256_encrypt",
|
|
26
|
+
"ctr256_decrypt",
|
|
27
|
+
"cbc256_encrypt",
|
|
28
|
+
"cbc256_decrypt",
|
|
29
|
+
"runtime_info",
|
|
30
|
+
"Ctr256",
|
|
31
|
+
"Ige256",
|
|
32
|
+
]
|
tgcryptors/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""TgCryptoRust public Python API."""
|
|
2
|
+
|
|
3
|
+
from ._native import ( # noqa: F401
|
|
4
|
+
Ctr256,
|
|
5
|
+
Ige256,
|
|
6
|
+
__version__,
|
|
7
|
+
cbc256_decrypt,
|
|
8
|
+
cbc256_encrypt,
|
|
9
|
+
ctr256_decrypt,
|
|
10
|
+
ctr256_encrypt,
|
|
11
|
+
ige256_decrypt,
|
|
12
|
+
ige256_encrypt,
|
|
13
|
+
runtime_info,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"__version__",
|
|
18
|
+
"ige256_encrypt",
|
|
19
|
+
"ige256_decrypt",
|
|
20
|
+
"ctr256_encrypt",
|
|
21
|
+
"ctr256_decrypt",
|
|
22
|
+
"cbc256_encrypt",
|
|
23
|
+
"cbc256_decrypt",
|
|
24
|
+
"runtime_info",
|
|
25
|
+
"Ctr256",
|
|
26
|
+
"Ige256",
|
|
27
|
+
]
|
|
Binary file
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: TgCryptoRust
|
|
3
|
+
Version: 1.1.2
|
|
4
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Classifier: Programming Language :: Rust
|
|
9
|
+
Classifier: Programming Language :: Python
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Topic :: Security
|
|
19
|
+
Classifier: Topic :: Security :: Cryptography
|
|
20
|
+
Classifier: Topic :: Internet
|
|
21
|
+
Classifier: Topic :: Communications
|
|
22
|
+
Classifier: Topic :: Communications :: Chat
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
License-File: COPYING
|
|
26
|
+
License-File: COPYING.lesser
|
|
27
|
+
Summary: Rust-powered drop-in replacement for TgCrypto
|
|
28
|
+
Keywords: kurigram,telegram,crypto,cryptography,encryption,mtproto,aes,rust
|
|
29
|
+
License-Expression: LGPL-3.0-or-later
|
|
30
|
+
Requires-Python: >=3.9, <3.15
|
|
31
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
32
|
+
Project-URL: Homepage, https://github.com/joyccn/TgCryptoRust
|
|
33
|
+
Project-URL: Source, https://github.com/joyccn/TgCryptoRust
|
|
34
|
+
|
|
35
|
+
# TgCryptoRust
|
|
36
|
+
|
|
37
|
+
Rust-powered, AES-NI accelerated cryptography for Telegram clients.
|
|
38
|
+
|
|
39
|
+
[](https://github.com/joyccn/TgCryptoRust/actions/workflows/ci.yml)
|
|
40
|
+

|
|
41
|
+

|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
TgCryptoRust is a drop-in replacement for TgCrypto, implemented in Rust and
|
|
45
|
+
packaged for Python through PyO3 and maturin. It provides the Telegram-focused
|
|
46
|
+
AES-256 modes used by MTProto clients:
|
|
47
|
+
|
|
48
|
+
- AES-256-IGE for MTProto message encryption
|
|
49
|
+
- AES-256-CTR for CDN file encryption
|
|
50
|
+
- AES-256-CBC for Telegram Passport credentials
|
|
51
|
+
|
|
52
|
+
> [!IMPORTANT]
|
|
53
|
+
> This project is provided for educational and experimental purposes. The
|
|
54
|
+
> implementation follows public AES specifications and is tested against known
|
|
55
|
+
> vectors, but it has not received a formal third-party security audit. Do not
|
|
56
|
+
> treat it as a certified cryptographic module.
|
|
57
|
+
|
|
58
|
+
## Requirements
|
|
59
|
+
|
|
60
|
+
- Python 3.9 through 3.14
|
|
61
|
+
- Rust 1.83 or newer when building from source
|
|
62
|
+
|
|
63
|
+
Prebuilt wheels are intended for common desktop and server platforms. Rust is
|
|
64
|
+
only required when a wheel is not available for your platform or when you are
|
|
65
|
+
developing the project locally.
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
uv add TgCryptoRust
|
|
71
|
+
uv pip install TgCryptoRust
|
|
72
|
+
pip install TgCryptoRust
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Imports
|
|
76
|
+
|
|
77
|
+
Existing TgCrypto users can keep importing `tgcrypto`:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import tgcrypto
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
New code can import the branded module directly:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import tgcryptors
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Both modules expose the same API.
|
|
90
|
+
|
|
91
|
+
## Usage
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import os
|
|
95
|
+
import tgcrypto
|
|
96
|
+
|
|
97
|
+
data = os.urandom(1024)
|
|
98
|
+
key = os.urandom(32)
|
|
99
|
+
iv = os.urandom(32)
|
|
100
|
+
|
|
101
|
+
encrypted = tgcrypto.ige256_encrypt(data, key, iv)
|
|
102
|
+
decrypted = tgcrypto.ige256_decrypt(encrypted, key, iv)
|
|
103
|
+
|
|
104
|
+
assert decrypted == data
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### CTR Mode
|
|
108
|
+
|
|
109
|
+
CTR accepts arbitrary-length data. The `state` argument is a one-byte offset
|
|
110
|
+
inside the current keystream block and is kept for TgCrypto compatibility.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
import os
|
|
114
|
+
import tgcryptors
|
|
115
|
+
|
|
116
|
+
data = os.urandom(1000)
|
|
117
|
+
key = os.urandom(32)
|
|
118
|
+
iv = os.urandom(16)
|
|
119
|
+
state = b"\x00"
|
|
120
|
+
|
|
121
|
+
encrypted = tgcryptors.ctr256_encrypt(data, key, iv, state)
|
|
122
|
+
decrypted = tgcryptors.ctr256_decrypt(encrypted, key, iv, state)
|
|
123
|
+
|
|
124
|
+
assert decrypted == data
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### CBC Mode
|
|
128
|
+
|
|
129
|
+
CBC input must be aligned to 16-byte AES blocks.
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import os
|
|
133
|
+
import tgcrypto
|
|
134
|
+
|
|
135
|
+
data = os.urandom(1024)
|
|
136
|
+
key = os.urandom(32)
|
|
137
|
+
iv = os.urandom(16)
|
|
138
|
+
|
|
139
|
+
encrypted = tgcrypto.cbc256_encrypt(data, key, iv)
|
|
140
|
+
decrypted = tgcrypto.cbc256_decrypt(encrypted, key, iv)
|
|
141
|
+
|
|
142
|
+
assert decrypted == data
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Streaming API
|
|
146
|
+
|
|
147
|
+
Use the streaming classes when processing one logical stream in chunks. The key
|
|
148
|
+
schedule is expanded once and reused.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
import os
|
|
152
|
+
import tgcryptors
|
|
153
|
+
|
|
154
|
+
key = os.urandom(32)
|
|
155
|
+
iv = os.urandom(16)
|
|
156
|
+
data = os.urandom(1024)
|
|
157
|
+
|
|
158
|
+
stream = tgcryptors.Ctr256(key, iv)
|
|
159
|
+
encrypted = stream.update(data[:300]) + stream.update(data[300:])
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
IGE streaming is also available for block-aligned chunks:
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
import os
|
|
166
|
+
import tgcrypto
|
|
167
|
+
|
|
168
|
+
key = os.urandom(32)
|
|
169
|
+
iv = os.urandom(32)
|
|
170
|
+
data = os.urandom(1024)
|
|
171
|
+
|
|
172
|
+
stream = tgcrypto.Ige256(key, iv)
|
|
173
|
+
encrypted = stream.encrypt(data[:512]) + stream.encrypt(data[512:])
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Compatibility
|
|
177
|
+
|
|
178
|
+
TgCryptoRust keeps the TgCrypto-compatible function names, argument order, return
|
|
179
|
+
types, and validation behavior for:
|
|
180
|
+
|
|
181
|
+
- `ige256_encrypt(data, key, iv)`
|
|
182
|
+
- `ige256_decrypt(data, key, iv)`
|
|
183
|
+
- `ctr256_encrypt(data, key, iv, state)`
|
|
184
|
+
- `ctr256_decrypt(data, key, iv, state)`
|
|
185
|
+
- `cbc256_encrypt(data, key, iv)`
|
|
186
|
+
- `cbc256_decrypt(data, key, iv)`
|
|
187
|
+
|
|
188
|
+
The PyPI package name is `TgCryptoRust`. The native module is `tgcryptors`, and
|
|
189
|
+
the compatibility module is `tgcrypto`.
|
|
190
|
+
|
|
191
|
+
## Runtime Metadata
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
import tgcryptors
|
|
195
|
+
|
|
196
|
+
print(tgcryptors.__version__)
|
|
197
|
+
print(tgcryptors.runtime_info())
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Development
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
uv sync --python 3.14
|
|
204
|
+
uv run maturin develop --release
|
|
205
|
+
.venv/bin/python -m unittest discover -s tests -v
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Run the Rust checks:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
cargo fmt --all -- --check
|
|
212
|
+
cargo clippy --all-targets --all-features -- -D warnings
|
|
213
|
+
cargo test --release
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Build a wheel:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
uv build --wheel
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Architecture
|
|
223
|
+
|
|
224
|
+
- `tgcryptors-core` contains the Rust AES primitive and Telegram block modes.
|
|
225
|
+
- `tgcryptors-python` exposes the PyO3 extension module.
|
|
226
|
+
- `python/tgcrypto.py` re-exports `tgcryptors` for TgCrypto compatibility.
|
|
227
|
+
- `tests/` covers the public Python API and import compatibility.
|
|
228
|
+
|
|
229
|
+
On x86 and x86_64, AES-NI is detected at runtime when the crate is built with
|
|
230
|
+
the default `aesni` feature. Other targets use the software fallback. The
|
|
231
|
+
software fallback uses table lookups and is not guaranteed to be constant-time
|
|
232
|
+
on every CPU.
|
|
233
|
+
|
|
234
|
+
## Migration From TgrCrypto
|
|
235
|
+
|
|
236
|
+
`TgrCrypto` is deprecated in favor of `TgCryptoRust`.
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
pip uninstall TgrCrypto
|
|
240
|
+
pip install TgCryptoRust
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Existing code that imports `tgcrypto` can remain unchanged.
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
LGPL-3.0-or-later. See [COPYING](COPYING) and
|
|
248
|
+
[COPYING.lesser](COPYING.lesser).
|
|
249
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
tgcrypto/__init__.py,sha256=PLW-WenAzVqoHopyFWIAE759Ms1jfj9qVN6GRGo_mZE,709
|
|
2
|
+
tgcryptors/__init__.py,sha256=HlGiCjrJ-qc1Z-AffH5L132C1LQXEv9B7XJluuf9JMc,498
|
|
3
|
+
tgcryptors/_native.cp312-win_amd64.pyd,sha256=YKQLOuTxQVxswCb48JPPOcBAZJwluLVEZ01Zp8rC7AQ,381440
|
|
4
|
+
tgcryptorust-1.1.2.dist-info/METADATA,sha256=7swsH5MAwlItu09xTiHHEhi4u_rJDSxJ7GoBdDXX2dY,6805
|
|
5
|
+
tgcryptorust-1.1.2.dist-info/WHEEL,sha256=7JL-UNaeAKwqD3UoxVviXWxHIGMKiaMe0XUDAEHKDIs,97
|
|
6
|
+
tgcryptorust-1.1.2.dist-info/licenses/COPYING,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
|
|
7
|
+
tgcryptorust-1.1.2.dist-info/licenses/COPYING.lesser,sha256=-DHn7tV3SBaHqbwLSAJOXkC29lX83gc-3pZLUL5dVdk,7815
|
|
8
|
+
tgcryptorust-1.1.2.dist-info/sboms/tgcryptors-python.cyclonedx.json,sha256=6y78bK8XxMr0u4oBXusKFIxzJBV79EFeFCZanJngpcQ,29070
|
|
9
|
+
tgcryptorust-1.1.2.dist-info/RECORD,,
|