What's wrong
ctr256_encrypt and ctr256_decrypt only accept bytes for iv/state. pyrogram (and kurigram, pyrofork, etc) always pass bytearray, so calling this library from pyrogram-based projects crashes:
import tgcrypto, os
key = os.urandom(32)
iv = bytearray(os.urandom(16))
state = bytearray(1)
tgcrypto.ctr256_encrypt(b"data", key, iv, state)
TypeError: 'bytearray' object is not an instance of 'bytes'
Why it matters
pyrogram uses bytearray for iv/state on purpose — it mutates them in place to carry the CTR counter across chunks (needed for its obfuscated TCP transport and CDN file downloads). This means the crash happens right at connection time, so a pyrogram/kurigram bot can't connect to Telegram at all with this library installed as the crypto backend — not just an edge case.
What would fix it
- Accept
bytearray for iv/state (matching how TgCrypto's own docs show it being used), and
- Make sure the counter state can actually be carried forward between calls — right now the function only returns ciphertext, with no way to continue a stream across multiple calls.
Happy to test a fix if useful.
Environment
- TgCryptoRust 1.3.0
- Python 3.12.3 and Python 3.14.7 (both reproduced, clean uv venvs)
- Reproduced against pyrogram (official, latest) and kurigram 2.2.24
What's wrong
ctr256_encryptandctr256_decryptonly acceptbytesforiv/state. pyrogram (and kurigram, pyrofork, etc) always passbytearray, so calling this library from pyrogram-based projects crashes:Why it matters
pyrogram uses
bytearrayforiv/stateon purpose — it mutates them in place to carry the CTR counter across chunks (needed for its obfuscated TCP transport and CDN file downloads). This means the crash happens right at connection time, so a pyrogram/kurigram bot can't connect to Telegram at all with this library installed as the crypto backend — not just an edge case.What would fix it
bytearrayforiv/state(matching how TgCrypto's own docs show it being used), andHappy to test a fix if useful.
Environment