# openssh/libopenssh architecture

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

- Interactive diagram: https://gitdiagram.com/openssh/libopenssh
- Repository: https://github.com/openssh/libopenssh

## Overview

##### Project Type Analysis
This is a library project that transforms OpenSSH from a standalone application into a reusable library. The project contains core SSH functionality, testing components, and memory leak detection tools.

##### Main Components

A. Core Library Components (ssh/):
- Authentication Module
- Encryption Module
- Key Management
- Protocol Handlers
- Connection Management
- Buffer Management

B. Supporting Tools:
- Memory Leak Detection (leakmalloc/)
- Unit Testing Framework (unittests/)
- Regression Testing Suite (regress/)

**┌─────────────────────────────────────────────┐**
- Client Applications            │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- libopenssh API Layer            │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Core Library Components           │
- ┬─────────────┬────────────────┤
- Auth       │  Crypto     │  Key           │
- Module     │  Module     │  Management    │
- ┼─────────────┼────────────────┤
- Protocol   │  Connection │  Buffer        │
- Handlers   │  Management │  Management    │
- ┴─────────────┴────────────────┘
- ↓
**┌─────────────────────────────────────────────┐**
- Support Components              │
- ┬─────────────┬────────────────┤
- Memory     │  Unit       │  Regression    │
- Leak Det.  │  Tests      │  Tests         │
- ┴─────────────┴────────────────┘

##### Component Details

a) Core Library Components:
- Authentication (auth*.c files)
- Crypto (cipher*.c files)
- Key Management (key.c, ssh-keygen.c)
- Protocol Implementation (ssh1.h, ssh2.h)
- Buffer Management (sshbuf*.c files)

b) Testing Components:
- Unit Tests (unittests/)
- Regression Tests (regress/)
- Test Helpers (test_helper/)

c) Development Tools:
- Memory Leak Detection (leakmalloc/)

##### Implementation Details

- Use rectangles for modules
- Use hexagons for tools
- Use diamonds for decision points
- Version information
- File relationships where relevant

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Applications"]
        App1[Client App 1]
        App2[Client App 2]
        App3[Client App 3]
    end

    subgraph API["LibOpenSSH API Layer"]
        APIInterface["API Interface"]:::api
    end

    subgraph Core["Core Library Components"]
        subgraph Auth["Authentication Components"]
            AuthMod["Authentication Module"]:::core
            KeyMgmt["Key Management"]:::core
        end

        subgraph Crypto["Cryptographic Components"]
            EncMod["Encryption Module"]:::core
            BuffMgmt["Buffer Management"]:::core
        end

        subgraph Network["Network Components"]
            ProtHandler["Protocol Handlers"]:::core
            ConnMgmt["Connection Management"]:::core
            ChanMgmt["Channel Management"]:::core
            PacketHandler["Packet Handling"]:::core
        end
    end

    subgraph Support["Support Components"]
        MemLeak["Memory Leak Detection"]:::support
        UnitTest["Unit Testing Framework"]:::support
        RegTest["Regression Testing Suite"]:::support
    end

    %% Relationships
    App1 & App2 & App3 --> APIInterface
    APIInterface --> AuthMod & EncMod & ProtHandler
    AuthMod --> KeyMgmt
    EncMod --> BuffMgmt
    ProtHandler --> ConnMgmt & ChanMgmt & PacketHandler
    MemLeak -.-> Core
    UnitTest -.-> Core
    RegTest -.-> Core

    %% Click Events
    click APIInterface "https://github.com/openssh/libopenssh/blob/master/ssh/ssh_api.c"
    click AuthMod "https://github.com/openssh/libopenssh/blob/master/ssh/auth.c"
    click KeyMgmt "https://github.com/openssh/libopenssh/blob/master/ssh/key.c"
    click EncMod "https://github.com/openssh/libopenssh/blob/master/ssh/cipher.c"
    click BuffMgmt "https://github.com/openssh/libopenssh/blob/master/ssh/sshbuf.c"
    click ProtHandler "https://github.com/openssh/libopenssh/blob/master/ssh/ssh1.h"
    click ConnMgmt "https://github.com/openssh/libopenssh/blob/master/ssh/sshconnect.c"
    click ChanMgmt "https://github.com/openssh/libopenssh/blob/master/ssh/channels.c"
    click PacketHandler "https://github.com/openssh/libopenssh/blob/master/ssh/packet.c"
    click MemLeak "https://github.com/openssh/libopenssh/tree/master/leakmalloc/leakmalloc/"
    click UnitTest "https://github.com/openssh/libopenssh/tree/master/unittests/"
    click RegTest "https://github.com/openssh/libopenssh/tree/master/regress/"

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333,stroke-width:2px
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px
    classDef support fill:#FFB347,stroke:#333,stroke-width:2px
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["API Component"]:::api
        L3["Support Tool"]:::support
        L4["External Component"]:::default
    end
```
