Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TPM2_SelfTest and TPM2_GetTestResult #319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tpm2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ const (
CmdPCREvent tpmutil.Command = 0x0000013C
CmdPCRReset tpmutil.Command = 0x0000013D
CmdSequenceComplete tpmutil.Command = 0x0000013E
CmdSelfTest tpmutil.Command = 0x00000143
CmdStartup tpmutil.Command = 0x00000144
CmdShutdown tpmutil.Command = 0x00000145
CmdActivateCredential tpmutil.Command = 0x00000147
Expand Down Expand Up @@ -489,6 +490,7 @@ const (
CmdStartAuthSession tpmutil.Command = 0x00000176
CmdGetCapability tpmutil.Command = 0x0000017A
CmdGetRandom tpmutil.Command = 0x0000017B
CmdGetTestResult tpmutil.Command = 0x0000017C
CmdHash tpmutil.Command = 0x0000017D
CmdPCRRead tpmutil.Command = 0x0000017E
CmdPolicyPCR tpmutil.Command = 0x0000017F
Expand Down
26 changes: 26 additions & 0 deletions tpm2/tpm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ import (
"github.com/google/go-tpm/tpmutil"
)

func SelfTest(rw io.ReadWriter, fullTest bool) error {
var yesno uint8
if fullTest {
yesno = 1
}
_, err := runCommand(rw, TagNoSessions, CmdSelfTest, yesno)
if err != nil {
return err
}

return nil
}

func GetTestResult(rw io.ReadWriter) ([]byte, error) {
resp, err := runCommand(rw, TagNoSessions, CmdGetTestResult)
if err != nil {
return nil, err
}

var testResult tpmutil.U16Bytes
if _, err := tpmutil.Unpack(resp, &testResult); err != nil {
return nil, err
}
return testResult, nil
}

// GetRandom gets random bytes from the TPM.
func GetRandom(rw io.ReadWriter, size uint16) ([]byte, error) {
resp, err := runCommand(rw, TagNoSessions, CmdGetRandom, size)
Expand Down