# dmtf/libspdm architecture

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

- Interactive diagram: https://gitdiagram.com/dmtf/libspdm
- Repository: https://github.com/dmtf/libspdm

## Overview

##### Main Components

- SPDM Core Libraries – Representing the essential protocol components (e.g., common utilities, requester and responder libraries, message processing logic). For example, components under:
- library/spdm_common_lib
- library/spdm_requester_lib
- library/spdm_responder_lib

- SPDM Secured Message Layer – This manages the encoding, decoding, key exchange, and secure session management. Include:
- library/spdm_secured_message_lib

- library/spdm_transport_mctp_lib
- library/spdm_transport_pcidoe_lib

- Crypto Abstraction Layer – This layer abstracts cryptographic operations. It includes defined headers (in include/hal/library/cryptlib.h) and multiple OS-specific implementations that wrap Mbed TLS, OpenSSL, or even null/dummy cryptographic libraries found in os_stub. Represent:
- Cryptography engine with subcomponents for mbedtls (os_stub/cryptlib_mbedtls), openssl (os_stub/cryptlib_openssl), and fallback alternatives.

- os_stub, platform_lib, and related directories.

- Industry Standard Interfaces – The library also supports standards such as PCI, CXL, and MCTP, so include a branch showing “Standards Interfaces” (found in include/industry_standard).

- Unit Testing and Fuzzing Infrastructure – Add a separate section for the testing harness:
- Unit tests under unit_test/
- Fuzzing and symbolic execution aids
- Test executables for both requester and responder simulation

##### Relationships and Data Flow

- Interactions between the protocol core and the secured message library – the core sends requests to the secured message encoder/decoder, which in turn calls upon the crypto abstraction layer for cryptographic operations.
- Crypto abstraction layer to the OS Stub. Indicate that the cryptographic library may be chosen at build time (via mbedtls, openssl, etc.).
- Transport layer as a bridge between the SPDM layer and the physical or simulated interconnect interfaces. For example, the requester’s messages are packaged via the MCTP or PCIe modules.

##### Architectural Patterns and Design Principles

- Modularity: Separate components (e.g., different libraries for requester, responder, secured messaging) should be individually labeled.
- Abstraction & Adapters: Emphasize that the crypto and OS-specific operations are abstracted via wrapper libraries.
- Specification Compliance: Note that many modules refer to published standards (SPDM, SPDM over MCTP, PCIe, CXL).

##### Technologies and Frameworks

- Cryptographic technologies (Mbed TLS, OpenSSL, and FIPS support) and refer to the operating systems and toolchains (Visual Studio, GCC, CLANG).

##### Detail and Clarity

- Separate core protocol logic from transport and crypto responsibilities.
- Annotations if needed that mention relevant specifications (e.g., DSP0274 for SPDM protocols and DSP0277 for secured messages).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Testing & Integration Layer
    subgraph "Testing & Integration"
        UT("Unit Testing & Fuzzing"):::test
        IE("Integration/Emulator"):::integration
    end

    %% SPDM Core Layer
    subgraph "SPDM Core Layer"
        CH1("spdm_common_lib.h"):::header
        CH2("spdm_requester_lib.h"):::header
        CH3("spdm_responder_lib.h"):::header
        A("SPDM Common Core"):::core
        B("SPDM Requester Core"):::core
        C("SPDM Responder Core"):::core
    end

    %% Secured Message Layer
    subgraph "Secured Message Layer"
        S("Secured Message Handler"):::secured
    end

    %% Transport Layer
    subgraph "Transport Layer"
        TH1("spdm_transport_mctp_lib.h"):::header
        TH2("spdm_transport_pcidoe_lib.h"):::header
        T1("Transport MCTP Adapter"):::transport
        T2("Transport PCIe DOE Adapter"):::transport
    end

    %% Crypto Abstraction Layer
    subgraph "Crypto Abstraction Layer"
        CR("Crypto Abstraction Header"):::crypto
        CM("Crypto (mbedtls)"):::crypto
        CO("Crypto (openssl)"):::crypto
        CN("Crypto (null)"):::crypto
    end

    %% OS Abstraction Layer
    subgraph "OS Abstraction Layer"
        OS("OS Stub & Platform Abstractions"):::os
    end

    %% Industry Standard Interfaces
    IS("Industry Standard Interfaces"):::industry

    %% Relationships & Data Flow

    %% Testing & Integration interactions
    IE -- "interacts" --> B
    IE -- "interacts" --> C
    B -- "interacts" --> IE
    C -- "interacts" --> IE
    UT -- "feedback" --> A
    UT -- "feedback" --> B
    UT -- "feedback" --> C
    UT -- "feedback" --> S
    UT -- "feedback" --> T1
    UT -- "feedback" --> T2

    %% Industry Standards to Core
    IS -- "defines" --> A
    IS -- "defines" --> B
    IS -- "defines" --> C

    %% Core Headers to Core
    CH1 --- A
    CH2 --- B
    CH3 --- C

    %% Core to Secured Message
    B -- "sends_request" --> S
    C -- "sends_response" --> S

    %% Secured Message to Crypto
    S -- "calls" --> CR

    %% Crypto Header branching to implementations and OS
    CR -- "uses" --> CM
    CR -- "uses" --> CO
    CR -- "uses" --> CN
    CR -- "depends_on" --> OS

    %% Core to Transport Layers
    B -- "packages_msg" --> T1
    B -- "packages_msg" --> T2
    C -- "packages_msg" --> T1
    C -- "packages_msg" --> T2

    %% Transport Headers to Transport Adapters
    TH1 --- T1
    TH2 --- T2

    %% Click Events for SPDM Core Libraries
    click A "https://github.com/dmtf/libspdm/tree/main/library/spdm_common_lib"
    click B "https://github.com/dmtf/libspdm/tree/main/library/spdm_requester_lib"
    click C "https://github.com/dmtf/libspdm/tree/main/library/spdm_responder_lib"
    click CH1 "https://github.com/dmtf/libspdm/blob/main/include/library/spdm_common_lib.h"
    click CH2 "https://github.com/dmtf/libspdm/blob/main/include/library/spdm_requester_lib.h"
    click CH3 "https://github.com/dmtf/libspdm/blob/main/include/library/spdm_responder_lib.h"

    %% Click Events for Secured Message Layer
    click S "https://github.com/dmtf/libspdm/tree/main/library/spdm_secured_message_lib"

    %% Click Events for Transport Layer
    click T1 "https://github.com/dmtf/libspdm/tree/main/library/spdm_transport_mctp_lib"
    click T2 "https://github.com/dmtf/libspdm/tree/main/library/spdm_transport_pcidoe_lib"
    click TH1 "https://github.com/dmtf/libspdm/blob/main/include/library/spdm_transport_mctp_lib.h"
    click TH2 "https://github.com/dmtf/libspdm/blob/main/include/library/spdm_transport_pcidoe_lib.h"

    %% Click Events for Crypto Abstraction Layer
    click CR "https://github.com/dmtf/libspdm/blob/main/include/hal/library/cryptlib.h"
    click CM "https://github.com/dmtf/libspdm/tree/main/os_stub/cryptlib_mbedtls"
    click CO "https://github.com/dmtf/libspdm/tree/main/os_stub/cryptlib_openssl"
    click CN "https://github.com/dmtf/libspdm/tree/main/os_stub/cryptlib_null"

    %% Click Events for OS Abstraction Layer
    click OS "https://github.com/dmtf/libspdm/tree/main/os_stub"

    %% Click Event for Industry Standard Interfaces
    click IS "https://github.com/dmtf/libspdm/tree/main/include/industry_standard"

    %% Click Event for Unit Testing
    click UT "https://github.com/dmtf/libspdm/tree/main/unit_test"

    %% Styles
    classDef core fill:#a6cee3,stroke:#1f78b4,stroke-width:2px;
    classDef secured fill:#ffcc99,stroke:#ff8c00,stroke-width:2px;
    classDef transport fill:#ccebc5,stroke:#33a02c,stroke-width:2px;
    classDef crypto fill:#ffff99,stroke:#b15928,stroke-width:2px;
    classDef os fill:#f4cae4,stroke:#d62728,stroke-width:2px;
    classDef test fill:#d9d9d9,stroke:#b3b3b3,stroke-width:2px;
    classDef integration fill:#fddaec,stroke:#d45087,stroke-width:2px;
    classDef header fill:#e5e5e5,stroke:#737373,stroke-width:2px;
    classDef industry fill:#e6e6fa,stroke:#8a2be2,stroke-width:2px;
```
