# prtmsh/steganography-cu architecture

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

- Interactive diagram: https://gitdiagram.com/prtmsh/steganography-cu
- Repository: https://github.com/prtmsh/steganography-cu

## Overview

##### Project Type and Purpose
- This is an open-source, command-line steganography tool written in C++17 with CUDA acceleration.
- Its purpose is to embed and extract invisible text watermarks in images by encoding bits into the LSB of the blue channel of pseudo-randomly selected interior pixels.
- It leverages three main domains: image I/O (OpenCV), cryptographic hashing (OpenSSL), and GPU compute (CUDA).

##### File Structure
- Top-level files:
- CMakeLists.txt – build orchestration for C++, CUDA, and third-party libs
- main.cpp – CLI parsing and high-level control flow
- watermark.cu / watermark.h – GPU kernels and related helper functions
- examples/ – sample input and output images
- No dedicated “frontend” vs. “backend” subfolders; all core logic lives in two modules (host code + device code).
- Dependencies are implicit in CMakeLists.txt (find_package(OpenCV …), find_package(OpenSSL …), enable CUDA).

##### README for Additional Insights
- Workflow phases are clearly defined: border‐hashing, pseudo-random pixel selection, bit embedding/extraction.
- Core external services/libraries: OpenCV for image I/O, OpenSSL for SHA-256, CUDA runtime for parallel compute.
- Key design patterns: deterministic seeding (border → hash → PRNG), pipelined data transformations (image → pixels → bits → image).

a. Main Components
- CLI Module (main.cpp)
- Image I/O Layer (OpenCV)
- Hashing Layer (OpenSSL)
- PRNG Module (C++ Mersenne Twister)
- CUDA Kernel Module (watermark.cu)
- Disk Storage (examples/, input/output images)
- Build System (CMake)
b. Component Relationships & Data Flows
1. User invokes CLI executable (`watermark --mode embed|extract`).
2. CLI uses OpenCV to read the input image into host memory.
3. CLI calls OpenSSL to compute SHA-256 of the image border.
4. The hash seeds std::mt19937 to generate a pseudo-random list of interior pixel coordinates.
5. Host code packages the message (with 16-bit header) into a bitstream.
6. Bitstream and selected coordinates are transferred to the GPU.
7. CUDA kernels embed/extract bits into/from the LSB of the blue channel in parallel.
8. Resulting image buffer is copied back to host memory.
9. OpenCV writes the modified image out as PNG.
c. Architectural Patterns & Principles
- Pipeline pattern: sequential stages (I/O → Hashing → Selection → Embedding → Output).
- Determinism through seed control: guarantees reproducible embedding/extraction paths.
- Separation of concerns: cryptography (OpenSSL), image handling (OpenCV), and parallel compute (CUDA) are decoupled modules.
d. Key Technologies & Frameworks
- CMake (build configuration)
- C++17 STL (mt19937, threadsafe containers)
- CUDA toolkit & nvcc (parallel kernels)
- OpenCV (cv::Mat, imread/imwrite)
- OpenSSL libcrypto (SHA256)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Compile-time configuration
    subgraph "Compile-Time"
        CMake["CMakeLists.txt"]:::build
    end

    %% Runtime flow
    subgraph "Runtime"
        User["User"]:::external
        CLI["CLI Module\n(main.cpp)"]:::host
        IO["Image I/O Layer\n(OpenCV)"]:::external
        Hash["Hashing Layer\n(OpenSSL)"]:::external
        PRNG["PRNG Module\n(std::mt19937)"]:::host
        Pack["Bitstream Packaging\n(host)"]:::host
        Transfer["Host→GPU Transfer"]:::host
        GPU["CUDA Kernel Module\n(watermark.cu/.h)"]:::cuda
        Retrieve["GPU→Host Retrieve"]:::host
        Write["Image Output\n(OpenCV)"]:::external
        Disk["Disk Storage\n(examples/)"]:::external
        Error["Error Handler\n(exit)"]:::host
    end

    %% Data flow
    User -->|"invokes CLI"| CLI
    CLI -->|"cv::Mat image"| IO
    IO -->|"image data"| CLI
    CLI -->|"if image too small\nerror exit"| Error
    CLI -->|"SHA256 hash"| Hash
    Hash -->|"hash seed"| PRNG
    PRNG -->|"coords list"| Pack
    CLI -->|"message + header"| Pack
    Pack -->|"bitstream + coords"| Transfer
    Transfer --> GPU
    GPU -->|"modified image buffer"| Retrieve
    Retrieve -->|"cv::Mat output"| Write
    Write -->|"PNG file"| Disk

    %% Legend
    subgraph Legend
        ext["External Dependency"]:::external
        hostDef["Host-Side Module"]:::host
        cudaDef["CUDA Module"]:::cuda
        buildDef["Build System"]:::build
    end

    %% Click events
    click CLI "https://github.com/prtmsh/steganography-cu/blob/main/main.cpp"
    click IO "https://github.com/prtmsh/steganography-cu/blob/main/main.cpp"
    click Hash "https://github.com/prtmsh/steganography-cu/blob/main/main.cpp"
    click PRNG "https://github.com/prtmsh/steganography-cu/blob/main/main.cpp"
    click GPU "https://github.com/prtmsh/steganography-cu/blob/main/watermark.cu"
    click GPU "https://github.com/prtmsh/steganography-cu/blob/main/watermark.h"
    click Disk "https://github.com/prtmsh/steganography-cu/tree/main/examples/"
    click CMake "https://github.com/prtmsh/steganography-cu/blob/main/CMakeLists.txt"

    %% Styles
    classDef external fill:#a8d5a2,stroke:#333,stroke-width:1px
    classDef host fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef cuda fill:#add8e6,stroke:#333,stroke-width:1px
    classDef build fill:#f9e79f,stroke:#333,stroke-width:1px
```
