go-tpm2

Pure-Go, transport-agnostic TPM 2.0 stack — one narrow Transport interface and a big-endian wire codec carry every command, so you swap the backplane and keep the code. cgo-free on plain go build.

CGO_ENABLED=0 one command API, four transports TIS · CRB · EFI_TCG2 · /dev/tpmrm0 big-endian TPM2 codec swtpm + OVMF validated 100% coverage
Documentation GitHub

Talking to a TPM 2.0 from Go usually means binding the cgo-heavy tpm2-tss C stack — which runs in neither a bare-metal TamaGo guest, a UEFI payload, nor a CGO-free microVM. go-tpm2 factors a TPM 2.0 stack into a narrow waist instead: common defines a single Transport interface (Send(cmd)→rsp), a Regs MMIO accessor, and the big-endian TPM2 wire codec — and builds the whole command API (tpm2) and four transports (tis, crb, efitcg2, devtpm) on top. One command API, four completely different backplanes.

Pure Go, no cgo, validated for real. Every tpm2 command is exercised end-to-end against a real swtpm over both the tis and crb transports from a TamaGo+QEMU guest, and the efitcg2 measured-boot loop runs on real x86 OVMF firmware — a discipline that has caught 14 real wire bugs a self-consistent fake never would. The full EK → AK → ActivateCredential → Quote → verify attestation chain, PolicyPCR seal/unseal, and Import / WrapToPCR are all in pure Go. There is no architecture-specific assembly — the same source builds on every Go target — and 100% statement coverage is a CI gate on every module.

Repositories

common waist

Transport (Send(cmd)→rsp) · Regs (MMIO) · BIG-ENDIAN TPM2 codec

The narrow waist: the Transport interface, the Regs MMIO accessor the MMIO transports use, the big-endian TPM2 wire codec, and the shared constants. Everything else plugs in. v0.1.0.

CI coverage 100%

tis transport

TIS / FIFO MMIO transport

TPM TIS/FIFO transport — the classic 0xFED4_0000 MMIO interface. Regs-driven STS / DATA_FIFO state machine; locality, Expect / dataAvail handshake. v0.1.0.

CI coverage 100%

crb transport

CRB command-buffer MMIO transport

TPM CRB transport — the Command/Response Buffer MMIO interface (PTP §6). Doorbell Start + goIdle / cmdReady state machine over the command/response buffers. v0.1.0.

CI coverage 100%

efitcg2 transport

EFI_TCG2_PROTOCOL transport

EFI_TCG2_PROTOCOL transport — a firmware TPM under UEFI Boot Services, reached through an injected firmware-call closure so go-tpm2 stays UEFI-free. SubmitCommand + HashLogExtendEvent for measured boot, plus GetEventLog to fetch the firmware TCG event log. v0.2.0.

CI coverage 100%

devtpm transport

Linux /dev/tpmrm0 transport

A common.Transport over the Linux kernel TPM resource-manager char device /dev/tpmrm0 (one write = one command, one read = the response) — the node-side host-TPM path so attest's Node can run on a real Linux node. Validated against real swtpm via its raw-TPM2 socket. v0.1.0.

CI coverage 100%

tpm2 api

TPM 2.0 command API over any Transport

The command API over any Transport: Startup, GetRandom, PCR_Read / PCR_Extend, GetCapability (+typed decode), SelfTest; CreatePrimary + ECC-P256 AK; remote attestation (Quote → VerifyQuote); PolicyPCR sealing; NV storage; the EK (EK Credential Profile); credential activation (MakeCredential / ActivateCredential); and Import / WrapToPCR. v0.6.0.

CI coverage 100%

attest protocol

Control-plane remote-attestation protocol

Control-plane remote-attestation protocol over tpm2 — a pure-Go Verifier + a Node agent implementing node-admission-on-Quote. Two-phase handshake (enrollment via MakeCredential / ActivateCredential, then admission: nonce → Quote → verify). Pluggable EKRegistry, Policy (golden PCR digests or EventLogPolicy), and PendingStore (in-memory or shared for HA control-planes). v0.3.0.

CI coverage 100%

validate harness

Real-swtpm + real-OVMF validation harness

Real-TPM validation harness. Drives a real swtpm over the tis and crb transports from a TamaGo+QEMU guest, runs the EFI_TCG2 measured-boot loop on real x86 OVMF firmware, and exercises the attest protocol end-to-end — including the Import / WrapToPCR flow and the attest-protocol harnesses. v0.9.0.

CI coverage 100%

Every module is pure Go with CGO_ENABLED=0 and held at 100% statement coverage as a CI gate — error branches, not just happy paths. Every register, command field, and return code is spec-traceable to the TCG TPM 2.0 Library, the PC Client Platform TPM Profile, or the EK Credential Profile section it implements. The command layer is proven over four backplanes against a real swtpm and real OVMF firmware. Built for cloud-boot measured boot and weft node attestation, but designed to run anywhere a TPM does. BSD-3-Clause throughout.