# xcyclonev3/tgcrypto-pyrofork architecture

> Architecture diagram of the GitHub repository xcyclonev3/tgcrypto-pyrofork, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xcyclonev3/tgcrypto-pyrofork
- Repository: https://github.com/xcyclonev3/tgcrypto-pyrofork

## Overview

TgCrypto is a C-backed Python extension providing AES-256 encryption modes for Telegram-related workloads. A Python caller supplies data, key, and IV (plus streaming state for CTR); the extension validates buffers, dispatches to a mode implementation, and returns encrypted or decrypted bytes. The modes use portable AES or, when available, CPU hardware instructions. The README documents the three modes and their use cases. Some implementation connections rely on the source index or README because excerpts are incomplete.

Main entry points: [`tgcrypto/tgcrypto.c`](https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/tgcrypto.c) (Extension API), [`tgcrypto`](https://github.com/xcyclonev3/tgcrypto-pyrofork/tree/master/tgcrypto) (CPU AES backends), [`tgcrypto/ige256.c`](https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/ige256.c) (AES-IGE), [`tgcrypto/ctr256.c`](https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/ctr256.c) (AES-CTR)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_python_api["Python API"]
  node_extension["Extension API<br/>[tgcrypto.c]"]
end

subgraph group_cipher_modes["Cipher Modes"]
  node_ige["AES-IGE<br/>[ige256.c]"]
  node_ctr["AES-CTR<br/>[ctr256.c]"]
  node_cbc["AES-CBC<br/>[cbc256.c]"]
end

subgraph group_aes_engines["AES Engines"]
  node_portable_aes["Portable AES<br/>[aes256.c]"]
  node_hardware_aes["CPU AES backends"]
end

node_python_user(("Python caller"))
node_cpu(("CPU capabilities"))

node_python_user -->|"calls API"| node_extension
node_extension -->|"dispatches IGE"| node_ige
node_extension -->|"dispatches CTR"| node_ctr
node_extension -->|"dispatches CBC"| node_cbc
node_ige -->|"uses AES"| node_portable_aes
node_ctr -->|"uses AES"| node_portable_aes
node_cbc -->|"uses AES"| node_portable_aes
node_ige -.->|"dispatches when available"| node_hardware_aes
node_ctr -->|"dispatches when available"| node_hardware_aes
node_cbc -->|"dispatches when available"| node_hardware_aes
node_cpu -.->|"enables acceleration"| node_hardware_aes

click node_extension "https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/tgcrypto.c"
click node_ige "https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/ige256.c"
click node_ctr "https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/ctr256.c"
click node_cbc "https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/cbc256.c"
click node_portable_aes "https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/aes256.c"
click node_hardware_aes "https://github.com/xcyclonev3/tgcrypto-pyrofork/tree/master/tgcrypto"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_extension toneBlue
class node_ige,node_ctr,node_cbc toneAmber
class node_portable_aes,node_hardware_aes toneMint
class node_python_user,node_cpu toneIndigo
```

## Components

### Python API

- [Extension API](https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/tgcrypto.c): `tgcrypto/tgcrypto.c`

### Cipher Modes

- [AES-IGE](https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/ige256.c): `tgcrypto/ige256.c`
- [AES-CTR](https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/ctr256.c): `tgcrypto/ctr256.c`
- [AES-CBC](https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/cbc256.c): `tgcrypto/cbc256.c`

### AES Engines

- [Portable AES](https://github.com/xcyclonev3/tgcrypto-pyrofork/blob/master/tgcrypto/aes256.c): `tgcrypto/aes256.c`
- [CPU AES backends](https://github.com/xcyclonev3/tgcrypto-pyrofork/tree/master/tgcrypto): `tgcrypto`

### Other components

- **Python caller**
- **CPU capabilities**

## Connections

- Python caller → Extension API: calls API (evidence: `README.md`)
- Extension API → AES-IGE: dispatches IGE (evidence: `tgcrypto/tgcrypto.c`)
- Extension API → AES-CTR: dispatches CTR (evidence: `tgcrypto/tgcrypto.c`)
- Extension API → AES-CBC: dispatches CBC (evidence: `tgcrypto/tgcrypto.c`)
- AES-IGE → Portable AES: uses AES (evidence: `tgcrypto/ige256.c`)
- AES-CTR → Portable AES: uses AES (evidence: `tgcrypto/ctr256.c`)
- AES-CBC → Portable AES: uses AES (evidence: `tgcrypto/cbc256.c`)
- AES-IGE → CPU AES backends: dispatches when available (evidence: `tgcrypto/ige256.c`)
- AES-CTR → CPU AES backends: dispatches when available (evidence: `tgcrypto/ctr256.c`)
- AES-CBC → CPU AES backends: dispatches when available (evidence: `tgcrypto/cbc256.c`)
- CPU capabilities → CPU AES backends: enables acceleration (evidence: `README.md`)
