# jpaulmora/pyrit architecture

> Architecture diagram of the GitHub repository jpaulmora/pyrit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jpaulmora/pyrit
- Repository: https://github.com/jpaulmora/pyrit

## Overview

##### Project type and purpose
- Pyrit is a command-line driven, open-source tool (Python2 with C/C++ extension modules) for massively pre-computing WPA/WPA2-PSK keys in a space–time trade-off.
- It exposes a CLI, intrinsic library (“cpyrit” package), a plugin architecture for CPU/GPU compute back-ends (CPU/SSE2, CUDA, OpenCL, etc.), and a storage/RPC layer for distributed operation.

##### File structure
Top-level
- pyrit_cli.py – the user-facing entry point
- setup.py – installation script
- README.md, COPYING, LICENSE, CHANGELOG, MANIFEST.in
- .github/ – CI, funding, issue templates, etc.
Core library (cpyrit/)
- cpyrit.py – high-level Python APIs (Job management, storage access, core dispatch)
- network.py – RPC server/client for remote compute/storage
- storage.py – abstraction over local/remote database (e.g. MySQL)
- util.py, pckttools.py, config.py, cpufeatures.h – helpers & feature detection
- _cpyrit_cpu.* – C extension for CPU/SSE2 kernels
Modules/ (plugin back-ends)
- cpyrit_calpp/ – C++ accelerated FFT (“calpp”) implementation
- cpyrit_cuda/ – NVIDIA CUDA back-end
- cpyrit_opencl/ – OpenCL back-end
Test/
- test_pyrit.py and sample packet dumps for unit/integration tests

##### README for additional insights
- Confirms multi-platform (Linux, BSD, MacOS X) support
- Highlights three compute platforms (CPU, CUDA, OpenCL)
- Describes storage options: single DB server, local-network direct DB access, untrusted-network via RPC
- Emphasizes distributed architecture: many computation nodes share one storage or RPC interface

a. Main components
1. CLI Client (pyrit_cli.py)
2. Core Engine (cpyrit Python package)
3. Compute Back-ends (CPU/SSE2, Calpp, CUDA, OpenCL modules)
4. Storage Layer (MySQL/PostgreSQL or local file; accessed via storage.py)
5. RPC Interface (network.py)
6. Remote Worker Nodes (instances of CLI or headless engine connecting over RPC)
b. Relationships & data flow
- User invokes CLI → CLI calls Core Engine
- Core Engine reads configuration → selects storage backend
- For “init” or “benchmark” commands: Engine dispatches work to Compute Back-end module
- Compute Back-end (C extension) executes PBKDF2-HMAC-SHA1 loops, returns results to Engine
- Engine writes pre-computed keys (PMKs) to Storage via storage.py (direct DB or over RPC)
- Other Worker Nodes poll Storage or RPC for unprocessed jobs → fetch work → compute → push results
c. Architectural patterns & design principles
- Layered architecture: CLI → Engine → Compute Modules → Storage/RPC
- Plugin pattern for compute back-ends, discoverable via Python’s setuptools entry points (setup.py in each module)
- Distributed system: Master storage or RPC server coordinates multiple workers
- Separation of concerns: network vs. storage vs. compute logic
d. Key technologies/frameworks
- Python2 core with C/C++ extension modules (CPython C-API)
- SSE2 assembly for CPU acceleration
- NVIDIA CUDA (cuptikernel)
- OpenCL kernels (.cl files)
- MySQL/PostgreSQL (via Python DB-API) or flatfile for storage
- RPC implemented over sockets (JSON or custom protocol)

##### Detail
- Version or compile-time flags (e.g., SSE2, CUDA compute capability) near each compute back-end
- Configuration file (config.py) feeding into both Engine and Network modules
- Plugin discovery mechanism (setuptools entry points) to illustrate how new back-ends can be added

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Local Deployment
    subgraph "Local Deployment"
        CLI["pyrit_cli.py"]:::python
        Engine["cpyrit.py"]:::python
        Config["config.py"]:::python
        Util1["util.py"]:::helper
        Pckt["pckttools.py"]:::helper
        CPUFeat["cpufeatures.h"]:::helper
        Storage["storage.py"]:::storage
        Network["network.py"]:::network
    end

    %% Compute Modules
    subgraph "Compute Back-ends"
        subgraph "CPU/SSE2 Backend"
            CPU_C["_cpyrit_cpu.c"]:::extension
            CPU_H["_cpyrit_cpu.h"]:::extension
            CPU_SSE2["_cpyrit_cpu_sse2.S"]:::extension
        end
        subgraph "Calpp Plugin"
            Calpp_setup["setup.py"]:::extension
            Calpp_cpp["_cpyrit_calpp.cpp"]:::extension
            Calpp_h["_cpyrit_calpp.h"]:::extension
            Calpp_k1["_cpyrit_calpp_kernel.cpp"]:::extension
            Calpp_k2["_cpyrit_calpp_kernel_generator.cpp"]:::extension
        end
        subgraph "CUDA Plugin"
            CUDA_setup["setup.py"]:::extension
            CUDA_c["_cpyrit_cuda.c"]:::extension
            CUDA_h["_cpyrit_cuda.h"]:::extension
            CUDA_kernel["_cpyrit_cudakernel.cu"]:::extension
        end
        subgraph "OpenCL Plugin"
            OCL_setup["setup.py"]:::extension
            OCL_c["_cpyrit_opencl.c"]:::extension
            OCL_h["_cpyrit_opencl.h"]:::extension
            OCL_kernel["_cpyrit_oclkernel.cl"]:::extension
        end
    end

    %% Distributed Components
    DB[(Database Storage)]:::db
    RPCS["RPC Server"]:::network

    subgraph "Remote Worker Cluster"
        W_CLI["pyrit_cli.py"]:::python
        W_Engine["cpyrit.py"]:::python
    end

    %% Flows
    CLI -->|"invokes"| Engine
    Config -->|"loads config"| Engine
    Config -->|"loads config"| Network
    Util1 -->|"helpers"| Engine
    Pckt -->|"packet parsing"| Engine
    CPUFeat -->|"feature detect"| Engine
    Engine -->|"dispatch job"| CPU_C
    Engine -->|"dispatch job"| Calpp_cpp
    Engine -->|"dispatch job"| CUDA_c
    Engine -->|"dispatch job"| OCL_c
    CPU_C -->|"compute via C-API"| Engine
    Calpp_cpp -->|"compute FFT"| Engine
    CUDA_c -->|"compute CUDA"| Engine
    OCL_c -->|"compute OpenCL"| Engine
    Engine -->|"store results"| Storage
    Storage -->|"DB-API SQL"| DB
    Engine -->|"RPC client"| RPCS
    RPCS -->|"RPC JSON over TCP"| W_Engine
    W_Engine -->|"dispatch job"| CPU_C
    W_Engine -->|"dispatch job"| Calpp_cpp
    W_Engine -->|"dispatch job"| CUDA_c
    W_Engine -->|"dispatch job"| OCL_c
    W_Engine -->|"store results"| Storage

    %% Click Events
    click CLI "https://github.com/jpaulmora/pyrit/blob/master/pyrit_cli.py"
    click Engine "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/cpyrit.py"
    click Config "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/config.py"
    click Util1 "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/util.py"
    click Pckt "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/pckttools.py"
    click CPUFeat "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/cpufeatures.h"
    click Storage "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/storage.py"
    click Network "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/network.py"
    click CPU_C "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/_cpyrit_cpu.c"
    click CPU_H "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/_cpyrit_cpu.h"
    click CPU_SSE2 "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/_cpyrit_cpu_sse2.S"
    click Calpp_setup "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_calpp/setup.py"
    click Calpp_cpp "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_calpp/_cpyrit_calpp.cpp"
    click Calpp_h "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_calpp/_cpyrit_calpp.h"
    click Calpp_k1 "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_calpp/_cpyrit_calpp_kernel.cpp"
    click Calpp_k2 "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_calpp/_cpyrit_calpp_kernel_generator.cpp"
    click CUDA_setup "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_cuda/setup.py"
    click CUDA_c "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_cuda/_cpyrit_cuda.c"
    click CUDA_h "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_cuda/_cpyrit_cuda.h"
    click CUDA_kernel "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_cuda/_cpyrit_cudakernel.cu"
    click OCL_setup "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_opencl/setup.py"
    click OCL_c "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_opencl/_cpyrit_opencl.c"
    click OCL_h "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_opencl/_cpyrit_opencl.h"
    click OCL_kernel "https://github.com/jpaulmora/pyrit/blob/master/modules/cpyrit_opencl/_cpyrit_oclkernel.cl"
    click W_CLI "https://github.com/jpaulmora/pyrit/blob/master/pyrit_cli.py"
    click W_Engine "https://github.com/jpaulmora/pyrit/blob/master/cpyrit/cpyrit.py"

    %% Styles
    classDef python fill:#bbdefb,stroke:#0d47a1,color:#0d47a1;
    classDef helper fill:#e1bee7,stroke:#6a1b9a,color:#6a1b9a;
    classDef storage fill:#c8e6c9,stroke:#2e7d32,color:#2e7d32;
    classDef network fill:#ffe0b2,stroke:#fb8c00,color:#e65100;
    classDef extension fill:#ffccbc,stroke:#d84315,color:#d84315;
    classDef db fill:#b3e5fc,stroke:#0277bd,color:#0277bd;
```
