How prtmsh/steganography-cu works
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)