# desert-oasis/dual-sync-mitm architecture

> Architecture diagram of the GitHub repository desert-oasis/dual-sync-mitm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/desert-oasis/dual-sync-mitm
- Repository: https://github.com/desert-oasis/dual-sync-mitm

## Overview

This repository provides two C++ demonstrations of meet-in-the-middle preimage attacks against 44-step SHA-256: a standard preimage attack and a partial-target pseudo-preimage variant. Each executable enters its attack from `main`; the attack code builds neutral structures, expands SHA-256 states forward and backward, and matches candidates. The second variant documents that it omits the padding rule. Both directories also contain a conventional SHA-256 implementation, but the sampled excerpts do not establish whether the attack routines call it; those connections are therefore omitted.

Main entry points: [`SHA256-44_partial_pseudo_preimage/src/main.cpp`](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp) (Attack entry), [`SHA256-44/src/main.cpp`](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp) (Neutral structure), [`SHA256-44/include/SHA256.h`](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/include/SHA256.h) (SHA-256 API), [`SHA256-44_partial_pseudo_preimage/include/SHA256.h`](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/include/SHA256.h) (SHA-256 API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_standard["Standard preimage attack"]
  node_std_entry["Attack entry<br/>[main.cpp]"]
  node_std_is["Neutral structure<br/>[main.cpp]"]
  node_std_forward["Forward expansion<br/>[main.cpp]"]
  node_std_backward["Backward expansion<br/>[main.cpp]"]
  node_std_match["Candidate matching<br/>[main.cpp]"]
  node_std_table["Match table<br/>[main.cpp]"]
  node_std_output["Attack results<br/>[main.cpp]"]
end

subgraph group_partial["Partial-target attack"]
  node_part_entry["Attack entry<br/>[main.cpp]"]
  node_part_is["Neutral structure<br/>[main.cpp]"]
  node_part_forward["Forward expansion<br/>[main.cpp]"]
  node_part_backward["Backward expansion<br/>[main.cpp]"]
  node_part_match["Partial matching<br/>[main.cpp]"]
  node_part_table["Match table<br/>[main.cpp]"]
  node_part_output["Trial results<br/>[main.cpp]"]
end

subgraph group_sha["SHA-256 utility"]
  node_std_sha["SHA-256 implementation<br/>[SHA256.cpp]"]
  node_std_api["SHA-256 API<br/>[SHA256.h]"]
  node_part_sha["SHA-256 implementation<br/>[SHA256.cpp]"]
  node_part_api["SHA-256 API<br/>[SHA256.h]"]
end

node_user(("Engineer"))

node_user -->|"runs"| node_std_entry
node_std_entry -->|"calls PseudoPreimage_MITM"| node_std_is
node_std_is -->|"seeds states"| node_std_forward
node_std_is -->|"seeds states"| node_std_backward
node_std_forward -->|"stores match keys"| node_std_table
node_std_backward -->|"looks up keys"| node_std_table
node_std_backward -->|"checks candidates"| node_std_match
node_std_match -->|"reports results"| node_std_output
node_user -->|"runs"| node_part_entry
node_part_entry -->|"calls BuildIS"| node_part_is
node_part_entry -->|"runs trial expansion"| node_part_forward
node_part_entry -->|"runs trial expansion"| node_part_backward
node_part_forward -->|"stores match keys"| node_part_table
node_part_backward -->|"looks up keys"| node_part_table
node_part_backward -->|"checks target bits"| node_part_match
node_part_entry -->|"reports trials"| node_part_output
node_std_api -->|"declares"| node_std_sha
node_part_api -->|"declares"| node_part_sha

click node_std_entry "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp"
click node_std_is "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp"
click node_std_forward "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp"
click node_std_backward "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp"
click node_std_match "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp"
click node_std_table "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp"
click node_std_output "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp"
click node_part_entry "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp"
click node_part_is "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp"
click node_part_forward "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp"
click node_part_backward "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp"
click node_part_match "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp"
click node_part_table "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp"
click node_part_output "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp"
click node_std_sha "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/SHA256.cpp"
click node_std_api "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/include/SHA256.h"
click node_part_sha "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/SHA256.cpp"
click node_part_api "https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/include/SHA256.h"

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_std_entry,node_std_is,node_std_forward,node_std_backward,node_std_match,node_std_table,node_std_output toneBlue
class node_part_entry,node_part_is,node_part_forward,node_part_backward,node_part_match,node_part_table,node_part_output toneAmber
class node_std_sha,node_std_api,node_part_sha,node_part_api toneMint
class node_user toneIndigo
```

## Components

### Standard preimage attack

- [Attack entry](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp): `SHA256-44/src/main.cpp`
- [Neutral structure](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp): `SHA256-44/src/main.cpp`
- [Forward expansion](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp): `SHA256-44/src/main.cpp`
- [Backward expansion](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp): `SHA256-44/src/main.cpp`
- [Candidate matching](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp): `SHA256-44/src/main.cpp`
- [Match table](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp): `SHA256-44/src/main.cpp`
- [Attack results](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/main.cpp): `SHA256-44/src/main.cpp`

### Partial-target attack

- [Attack entry](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp): `SHA256-44_partial_pseudo_preimage/src/main.cpp`
- [Neutral structure](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp): `SHA256-44_partial_pseudo_preimage/src/main.cpp`
- [Forward expansion](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp): `SHA256-44_partial_pseudo_preimage/src/main.cpp`
- [Backward expansion](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp): `SHA256-44_partial_pseudo_preimage/src/main.cpp`
- [Partial matching](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp): `SHA256-44_partial_pseudo_preimage/src/main.cpp`
- [Match table](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp): `SHA256-44_partial_pseudo_preimage/src/main.cpp`
- [Trial results](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/main.cpp): `SHA256-44_partial_pseudo_preimage/src/main.cpp`

### SHA-256 utility

- [SHA-256 implementation](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/src/SHA256.cpp): `SHA256-44/src/SHA256.cpp`
- [SHA-256 API](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44/include/SHA256.h): `SHA256-44/include/SHA256.h`
- [SHA-256 implementation](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/src/SHA256.cpp): `SHA256-44_partial_pseudo_preimage/src/SHA256.cpp`
- [SHA-256 API](https://github.com/desert-oasis/dual-sync-mitm/blob/main/SHA256-44_partial_pseudo_preimage/include/SHA256.h): `SHA256-44_partial_pseudo_preimage/include/SHA256.h`

### Other components

- **Engineer**

## Connections

- Engineer → Attack entry: runs
- Attack entry → Neutral structure: calls PseudoPreimage_MITM
- Neutral structure → Forward expansion: seeds states
- Neutral structure → Backward expansion: seeds states
- Forward expansion → Match table: stores match keys
- Backward expansion → Match table: looks up keys
- Backward expansion → Candidate matching: checks candidates
- Candidate matching → Attack results: reports results
- Engineer → Attack entry: runs
- Attack entry → Neutral structure: calls BuildIS
- Attack entry → Forward expansion: runs trial expansion
- Attack entry → Backward expansion: runs trial expansion
- Forward expansion → Match table: stores match keys
- Backward expansion → Match table: looks up keys
- Backward expansion → Partial matching: checks target bits
- Attack entry → Trial results: reports trials
- SHA-256 API → SHA-256 implementation: declares
- SHA-256 API → SHA-256 implementation: declares
