# microsoft/ms-tpm-20-ref architecture

> Architecture diagram of the GitHub repository microsoft/ms-tpm-20-ref, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/ms-tpm-20-ref
- Repository: https://github.com/microsoft/ms-tpm-20-ref

## Overview

This is the official TPM 2.0 reference implementation, including a TCP-accessible simulator. The principal workflow is a client sending TPM requests to the simulator and receiving TPM results; the README documents the simulator protocol, while the sampled implementation excerpts show selected command, session, context, and platform behavior. Several architectural links—especially simulator-to-core dispatch—are not visible in the excerpts, so those links are marked unverified rather than asserted as source-confirmed.

Main entry points: [`TPMCmd/tpm/src/main/SessionProcess.c`](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/main/SessionProcess.c) (Command execution), [`TPMCmd/Simulator/src/TcpServer.c`](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Simulator/src/TcpServer.c) (TCP server), [`TPMCmd/tpm/src/crypt`](https://github.com/microsoft/ms-tpm-20-ref/tree/main/TPMCmd/tpm/src/crypt) (Cryptographic operations), [`TPMCmd/Simulator/src/TPMCmds.c`](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Simulator/src/TPMCmds.c) (Simulator commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sim["Simulator interface"]
  node_tcp["TCP server<br/>[TcpServer.c]"]
  node_simcmd["Simulator commands<br/>[TPMCmds.c]"]
  node_simentry["Simulator entry<br/>[TPMCmdp.c]"]
end

subgraph group_core["TPM command engine"]
  node_engine["Command execution<br/>[SessionProcess.c]"]
  node_command["TPM command handlers"]
  node_crypto["Cryptographic operations"]
end

subgraph group_state["TPM state and policy"]
  node_context["Context protection<br/>[Context_spt.c]"]
  node_sessioncmd["Session creation<br/>[StartAuthSession.c]"]
  node_sessionproc["Session processing<br/>[SessionProcess.c]"]
  node_sessionstate["Session context state<br/>[Session.c]"]
  node_policy["Policy authorization<br/>[PolicyAuthorize.c]"]
  node_audit["Session audit digest"]
end

subgraph group_platform["Platform services"]
  node_nv[("NV persistence<br/>[NVMem.c]")]
  node_clock["TPM clock<br/>[Clock.c]"]
  node_pcr["PCR platform services<br/>[PlatformPcr.c]"]
  node_platform["Platform interface<br/>[Platform.h]"]
  node_config["TPM profile<br/>[TpmProfile.h]"]
end

node_client(("TSS client"))

node_client -->|"sends requests"| node_tcp
node_tcp -.->|"dispatches commands"| node_simcmd
node_simcmd -.->|"invokes simulator"| node_simentry
node_tcp -.->|"forwards requests"| node_engine
node_sessioncmd -->|"creates sessions"| node_sessionstate
node_policy -->|"hashes policy data"| node_crypto
node_context -->|"derives protection key"| node_crypto
node_audit -->|"signs attestation"| node_crypto
node_engine -->|"processes sessions"| node_sessionproc
node_engine -.->|"checks NV state"| node_nv
node_engine -.->|"reads TPM time"| node_clock
node_platform -.->|"provides NV access"| node_nv

click node_tcp "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Simulator/src/TcpServer.c"
click node_simcmd "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Simulator/src/TPMCmds.c"
click node_simentry "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Simulator/src/TPMCmdp.c"
click node_engine "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/main/SessionProcess.c"
click node_command "https://github.com/microsoft/ms-tpm-20-ref/tree/main/TPMCmd/tpm/src/command"
click node_crypto "https://github.com/microsoft/ms-tpm-20-ref/tree/main/TPMCmd/tpm/src/crypt"
click node_context "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/command/Context/Context_spt.c"
click node_sessioncmd "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/command/Session/StartAuthSession.c"
click node_sessionproc "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/main/SessionProcess.c"
click node_sessionstate "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/subsystem/Session.c"
click node_policy "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/command/EA/PolicyAuthorize.c"
click node_audit "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/command/Attestation/GetSessionAuditDigest.c"
click node_nv "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Platform/src/NVMem.c"
click node_clock "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Platform/src/Clock.c"
click node_pcr "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Platform/src/PlatformPcr.c"
click node_platform "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Platform/include/Platform.h"
click node_config "https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/TpmConfiguration/TpmConfiguration/TpmProfile.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_tcp,node_simcmd,node_simentry,node_client toneBlue
class node_engine,node_command,node_crypto toneAmber
class node_context,node_sessioncmd,node_sessionproc,node_sessionstate,node_policy,node_audit toneMint
class node_nv,node_clock,node_pcr,node_platform,node_config toneRose
```

## Components

### Simulator interface

- [TCP server](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Simulator/src/TcpServer.c): `TPMCmd/Simulator/src/TcpServer.c`
- [Simulator commands](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Simulator/src/TPMCmds.c): `TPMCmd/Simulator/src/TPMCmds.c`
- [Simulator entry](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Simulator/src/TPMCmdp.c): `TPMCmd/Simulator/src/TPMCmdp.c`

### TPM command engine

- [Command execution](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/main/SessionProcess.c): `TPMCmd/tpm/src/main/SessionProcess.c`
- [TPM command handlers](https://github.com/microsoft/ms-tpm-20-ref/tree/main/TPMCmd/tpm/src/command): `TPMCmd/tpm/src/command`
- [Cryptographic operations](https://github.com/microsoft/ms-tpm-20-ref/tree/main/TPMCmd/tpm/src/crypt): `TPMCmd/tpm/src/crypt`

### TPM state and policy

- [Context protection](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/command/Context/Context_spt.c): `TPMCmd/tpm/src/command/Context/Context_spt.c`
- [Session creation](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/command/Session/StartAuthSession.c): `TPMCmd/tpm/src/command/Session/StartAuthSession.c`
- [Session processing](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/main/SessionProcess.c): `TPMCmd/tpm/src/main/SessionProcess.c`
- [Session context state](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/subsystem/Session.c): `TPMCmd/tpm/src/subsystem/Session.c`
- [Policy authorization](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/command/EA/PolicyAuthorize.c): `TPMCmd/tpm/src/command/EA/PolicyAuthorize.c`
- [Session audit digest](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/tpm/src/command/Attestation/GetSessionAuditDigest.c): `TPMCmd/tpm/src/command/Attestation/GetSessionAuditDigest.c`

### Platform services

- [NV persistence](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Platform/src/NVMem.c): `TPMCmd/Platform/src/NVMem.c`
- [TPM clock](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Platform/src/Clock.c): `TPMCmd/Platform/src/Clock.c`
- [PCR platform services](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Platform/src/PlatformPcr.c): `TPMCmd/Platform/src/PlatformPcr.c`
- [Platform interface](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/Platform/include/Platform.h): `TPMCmd/Platform/include/Platform.h`
- [TPM profile](https://github.com/microsoft/ms-tpm-20-ref/blob/main/TPMCmd/TpmConfiguration/TpmConfiguration/TpmProfile.h): `TPMCmd/TpmConfiguration/TpmConfiguration/TpmProfile.h`

### Other components

- **TSS client**

## Connections

- TSS client → TCP server: sends requests
- TCP server → Simulator commands: dispatches commands
- Simulator commands → Simulator entry: invokes simulator
- TCP server → Command execution: forwards requests
- Session creation → Session context state: creates sessions (evidence: `TPMCmd/tpm/src/command/Session/StartAuthSession.c`)
- Policy authorization → Cryptographic operations: hashes policy data (evidence: `TPMCmd/tpm/src/command/EA/PolicyAuthorize.c`)
- Context protection → Cryptographic operations: derives protection key (evidence: `TPMCmd/tpm/src/command/Context/Context_spt.c`)
- Session audit digest → Cryptographic operations: signs attestation (evidence: `TPMCmd/tpm/src/command/Attestation/GetSessionAuditDigest.c`)
- Command execution → Session processing: processes sessions (evidence: `TPMCmd/tpm/src/main/SessionProcess.c`)
- Command execution → NV persistence: checks NV state
- Command execution → TPM clock: reads TPM time
- Platform interface → NV persistence: provides NV access (evidence: `TPMCmd/Platform/src/NVMem.c`)
