tis

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: BSD-3-Clause Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-tpm2/tis

go-tpm2/tis

CI Go Reference Coverage License

A pure-Go TPM TIS / FIFO MMIO transport for the go-tpm2 stack. v0.1.0.

It drives the TCG PC Client TIS (FIFO) register handshake over the platform-provided common.Regs MMIO accessor and satisfies common.Transport, exchanging one fully-marshaled TPM 2.0 command buffer for the full response buffer.

Sibling repos: common (interfaces + codec), crb (the CRB transport alternative), tpm2 (the command layer that rides on this Transport), and validate (live swtpm validation).

Install

go get github.com/go-tpm2/tis

Usage

import (
	common "github.com/go-tpm2/common"
	"github.com/go-tpm2/tis"
)

// regs is your platform's MMIO window over the locality-0 register page
// (an mmap of /dev/mem at 0xFED4_0000, a hypervisor stub, a test fake…).
t, err := tis.Open(regs)
if err != nil {
	// no TPM present, or locality 0 could not be claimed
}

// *tis.TIS satisfies common.Transport — feed it to go-tpm2/tpm2:
//   tpm := tpm2.New(t); tpm.Startup(uint16(common.SUClear))

// …or send a raw command buffer:
rsp, err := t.Send(common.BuildCommand(uint16(common.TagNoSessions),
	uint32(common.CCGetRandom), []byte{0x00, 0x08}))

Scope

Open validates presence via TPM_DID_VID and claims locality 0 via the TPM_ACCESS handshake. Send runs the FIFO command sequence: move the TPM to Ready (STS.commandReady), stream the command into TPM_DATA_FIFO respecting burstCount and the Expect bit, start execution (STS.tpmGo), poll STS.dataAvail, read the 10-byte header to learn responseSize, drain the rest honoring burstCount, then release the locality. Every busy-wait is bounded and returns a typed error.

Authority

Register offsets, bit fields, and the command sequence follow the TCG PC Client Platform TPM Profile (PTP) Specification, "FIFO Interface" chapter (which folds in the legacy TCG PC Client Specific TPM Interface Specification (TIS) 1.3). The TPM payloads are big-endian per TCG "TPM 2.0 Part 1"; the TIS control registers are native-endian MMIO via common.Regs. Each register/bit is cited at its definition in regs.go and each handshake step in tis.go. The two driver-side safety values (the spin budget and the response cap) are marked INFERRED:.

Conventions

Pure Go, CGO_ENABLED=0, no architecture-specific assembly, big-endian TPM wire (via common), BSD-3-Clause on every file, GOWORK=off, 100% statement coverage.

GOWORK=off go test -cover ./...

The two driver-side safety values are validated against a real swtpm 0.10.1 under QEMU -device tpm-tis by the validate harness.

Specifications

  • TCG PC Client Platform TPM Profile (PTP) — FIFO Interface (folds in the legacy TCG PC Client TPM Interface Specification (TIS) 1.3).
  • TCG TPM 2.0 Library, Parts 1–4 (wire format, via common).

License

BSD-3-Clause. See LICENSE.

Documentation

Overview

Package tis implements a pure-Go TPM TIS / FIFO MMIO transport. It drives the TCG PC Client TIS (FIFO) register handshake over a platform-provided common.Regs MMIO accessor and satisfies common.Transport, exchanging one fully-marshaled TPM 2.0 command buffer for the full response buffer.

Authority for the register handshake is the TCG "PC Client Platform TPM Profile (PTP) Specification", "FIFO Interface" chapter, which supersedes (and folds in) the legacy TCG "PC Client Specific TPM Interface Specification (TIS)" 1.3. Citations below name the relevant register/clause.

Conventions: pure Go, CGO_ENABLED=0, no architecture-specific assembly, BSD-3-Clause on every file, GOWORK=off, 100% statement coverage.

Index

Constants

View Source
const (
	// ErrNoLocality is returned when locality 0 cannot be claimed: the
	// TPM never asserts ACCESS.activeLocality after a requestUse.
	// PTP "TPM_ACCESS_x", activeLocality.
	ErrNoLocality = Error("tis: timed out claiming locality 0")
	// ErrNotPresent is returned when the interface does not look like a
	// TPM (TPM_DID_VID reads back all-ones / all-zeros). PTP
	// "TPM_DID_VID_x".
	ErrNotPresent = Error("tis: no TPM present at register window")
	// ErrCommandReady is returned when the TPM never asserts
	// STS.commandReady, so a command cannot be staged. PTP "TPM_STS_x",
	// commandReady.
	ErrCommandReady = Error("tis: timed out waiting for commandReady")
	// ErrBurstTimeout is returned when burstCount stays zero for the
	// whole bound, so no FIFO bytes can be moved. PTP "TPM_STS_x",
	// burstCount.
	ErrBurstTimeout = Error("tis: timed out waiting for non-zero burstCount")
	// ErrExpect is returned when the TPM's Expect bit disagrees with the
	// driver's view of the command transfer: it clears before the last
	// byte (TPM thinks the command is complete early) or stays set after
	// the last byte (TPM still wants more). PTP "TPM_STS_x", Expect.
	ErrExpect = Error("tis: Expect/transfer length mismatch")
	// ErrDataAvail is returned when the TPM never asserts STS.dataAvail
	// after tpmGo, so no response can be read. PTP "TPM_STS_x",
	// dataAvail.
	ErrDataAvail = Error("tis: timed out waiting for response dataAvail")
	// ErrShortResponse is returned when the FIFO yields fewer than the
	// 10-byte TPM 2.0 header. TCG "TPM 2.0 Part 1", response header.
	ErrShortResponse = Error("tis: response shorter than TPM header")
	// ErrResponseSize is returned when the header's responseSize is
	// implausible (smaller than the header or larger than the maximum
	// the driver will buffer). TCG "TPM 2.0 Part 1", responseSize.
	ErrResponseSize = Error("tis: response size out of range")
)

Error sentinels.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error is the typed, constant error returned by this package, mirroring common.Error so callers may compare values with ==.

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

type TIS

type TIS struct {
	// contains filtered or unexported fields
}

TIS is a TPM TIS / FIFO transport bound to a single locality-0 register window. It satisfies common.Transport.

func Open

func Open(r common.Regs) (*TIS, error)

Open binds a TIS transport to the locality-0 register window presented by r. It validates that a TPM is present (TPM_DID_VID is neither all-zeros nor all-ones) and claims locality 0 via the ACCESS handshake so the first Send can proceed. PTP "TPM_DID_VID_x" and "TPM_ACCESS_x".

func (*TIS) Send

func (t *TIS) Send(cmd []byte) ([]byte, error)

Send transmits one fully-marshaled TPM 2.0 command buffer and returns the full response buffer (including the 10-byte header), satisfying common.Transport.

The flow follows the PTP "FIFO Interface" command sequence:

  1. Ensure locality 0 is active (ACCESS.requestUse / activeLocality).
  2. Move the TPM to the Ready state: write STS.commandReady=1 and wait until STS.commandReady reads back set. PTP "TPM_STS_x", commandReady; PTP FIFO state diagram "Idle -> Ready".
  3. Write the command to DATA_FIFO honoring burstCount (STS[8:23]): never write more bytes than the TPM currently advertises, and check STS.Expect after each chunk. Expect must stay set while more bytes remain and must clear on the last byte. PTP "TPM_STS_x", burstCount and Expect; PTP FIFO state diagram "Reception".
  4. Start execution: write STS.tpmGo=1. PTP "TPM_STS_x", tpmGo.
  5. Poll STS.dataAvail, then read the response from DATA_FIFO honoring burstCount: first the 10-byte header to learn responseSize, then the remaining bytes. PTP "TPM_STS_x", dataAvail and burstCount; PTP FIFO state diagram "Completion".
  6. Release locality 0 (ACCESS.activeLocality=1). PTP "TPM_ACCESS_x".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址