How microsoft/ms-tpm-20-ref works
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: SessionProcess.c Command execution · TcpServer.c TCP server · crypt Cryptographic operations · TPMCmds.c Simulator commands
Components 18
Simulator interface
- TCP server
TPMCmd/Simulator/src/TcpServer.c - Simulator commands
TPMCmd/Simulator/src/TPMCmds.c - Simulator entry
TPMCmd/Simulator/src/TPMCmdp.c
TPM command engine
- Command execution
TPMCmd/tpm/src/main/SessionProcess.c - TPM command handlers
TPMCmd/tpm/src/command - Cryptographic operations
TPMCmd/tpm/src/crypt
TPM state and policy
- Context protection
TPMCmd/tpm/src/command/Context/Context_spt.c - Session creation
TPMCmd/tpm/src/command/Session/StartAuthSession.c - Session processing
TPMCmd/tpm/src/main/SessionProcess.c - Session context state
TPMCmd/tpm/src/subsystem/Session.c - Policy authorization
TPMCmd/tpm/src/command/EA/PolicyAuthorize.c - Session audit digest
TPMCmd/tpm/src/command/Attestation/GetSessionAuditDigest.c
Platform services
- NV persistence
TPMCmd/Platform/src/NVMem.c - TPM clock
TPMCmd/Platform/src/Clock.c - PCR platform services
TPMCmd/Platform/src/PlatformPcr.c - Platform interface
TPMCmd/Platform/include/Platform.h - TPM profile
TPMCmd/TpmConfiguration/TpmConfiguration/TpmProfile.h
Other components
- TSS client
Connections 12
- 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
TPMCmd/tpm/src/command/Session/StartAuthSession.c - Policy authorization → Cryptographic operations: hashes policy data
TPMCmd/tpm/src/command/EA/PolicyAuthorize.c - Context protection → Cryptographic operations: derives protection key
TPMCmd/tpm/src/command/Context/Context_spt.c - Session audit digest → Cryptographic operations: signs attestation
TPMCmd/tpm/src/command/Attestation/GetSessionAuditDigest.c - Command execution → Session processing: processes sessions
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
TPMCmd/Platform/src/NVMem.c