Documentation
¶
Overview ¶
Package crb implements the TPM 2.0 Command Response Buffer (CRB) interface as a github.com/go-tpm2/common.Transport over the platform-provided common.Regs MMIO accessor.
The CRB interface and its register block are defined by the TCG "PC Client Platform TPM Profile (PTP) Specification" (Family 2.0), in the clause "Command Response Buffer Interface" and its register tables ("Register Space" / "CRB Interface Definition"). Unless noted with an INFERRED marker, every register offset, bit position, and handshake step below is taken from that specification.
Endianness note: the TPM 2.0 *wire* protocol (the command/response byte stream this transport carries) is BIG-ENDIAN and is encoded by github.com/go-tpm2/common's codec. The CRB *control registers* themselves are LITTLE-ENDIAN MMIO; common.Regs.Read32/Write32 access them in the platform's native register width, so this package never byte-swaps register values — it only ever moves the opaque command and response byte streams through the data buffer with common.WriteBytes / common.ReadBytes.
Conventions: pure Go, CGO_ENABLED=0, no architecture-specific assembly, BSD-3-Clause on every file, 100% statement coverage, and GOWORK=off.
Index ¶
Constants ¶
const ( // ErrNotCRB is returned by Open when INTERFACE_ID does not advertise // the CRB interface type. ErrNotCRB = common.Error("crb: interface is not CRB") // ErrLocality is returned when the locality cannot be granted. ErrLocality = common.Error("crb: locality not granted") // ErrNotReady is returned when the TPM never reaches command-ready. ErrNotReady = common.Error("crb: command-ready not granted") // ErrTPM is returned when CTRL_STS reports a fatal TPM error. ErrTPM = common.Error("crb: TPM reported a fatal error") // ErrTimeout is returned when the TPM never clears CTRL_START.start. ErrTimeout = common.Error("crb: timed out waiting for command completion") // ErrShortResponse is returned when the response is smaller than a // TPM 2.0 header. ErrShortResponse = common.Error("crb: response shorter than header") // ErrResponseTooLarge is returned when the declared response size // exceeds the data buffer. ErrResponseTooLarge = common.Error("crb: response larger than data buffer") )
Error sentinels for the CRB transport, typed as common.Error so callers may compare with ==.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CRB ¶
type CRB struct {
// contains filtered or unexported fields
}
CRB is a TPM 2.0 Command Response Buffer transport bound to a single locality's control area, reached through a common.Regs accessor. It satisfies common.Transport.
func Open ¶
Open binds a CRB transport to the register window r and validates that the window actually exposes a CRB interface.
Validation follows TCG PTP: it reads INTERFACE_ID and checks that its InterfaceType nibble names the CRB interface ("TPM_INTERFACE_ID_x", field "InterfaceType"), then reads LOC_STATE and waits for tpmRegValidSts ("TPM_LOC_STATE_x", field "tpmRegValidSts") so the state register may be trusted by the caller.
func (*CRB) Send ¶
Send transmits one fully-marshaled TPM 2.0 command buffer through the CRB interface and returns the full response buffer (header + params). It satisfies common.Transport.
State machine (TCG PTP, clause "Command Response Buffer Interface", "CRB Interface State Transitions" and the per-register field tables):
- Request the locality: write requestAccess to LOC_CTRL, then wait for LOC_STS.Granted with LOC_STATE.locAssigned. (TCG PTP, "TPM_LOC_CTRL_x"/"TPM_LOC_STS_x"/"TPM_LOC_STATE_x".)
- Request command-ready: write cmdReady to CTRL_REQ and poll until the TPM leaves Idle and is not in error — CTRL_STS with tpmIdle clear and Error clear, and CTRL_REQ.cmdReady self-clearing once the transition completes. (TCG PTP, "CRB_CTRL_REQ_x"/"CRB_CTRL_STS_x".)
- Write the command into the data buffer (common.WriteBytes).
- Set CTRL_START.start to hand the command to the TPM. (TCG PTP, "CRB_CTRL_START_x".)
- Poll CTRL_START.start until the TPM clears it (command complete), bounded by maxSpin; on expiry write CTRL_CANCEL and return ErrTimeout. (TCG PTP, "CRB_CTRL_START_x"/"CRB_CTRL_CANCEL_x".)
- Check CTRL_STS for the Error bit. (TCG PTP, "CRB_CTRL_STS_x".)
- Read the 10-byte response header to learn responseSize, validate it against the buffer, then read the whole response.
- Release the interface: write goIdle to CTRL_REQ. (TCG PTP, "CRB_CTRL_REQ_x" field "goIdle".)
