Conversation
58c08bb to
e4e1412
Compare
Just the documentation, wrapper generation script, and bare-bones module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #1, so we temporarily use
backportsas the base branch (to make the changes easier to see). Will switch back tomainonce #1 is merged.This PR adds Go bindings to the C code, replacing the terrible hacks in https://github.com/google/go-tpm-tools/tree/main/simulator/internal.
As with the old solution, we compile the entire TPM reference code using Go's CGO build system. To maintain an explicit list of source files without copying their contents, we use wrapper C files that
#includethe original C files in the repository. This avoids issues with symlinks not being handled correctly by fetched Go modules.The platform interface required by the TPM reference code is implemented in Go, providing flexibility via callbacks and interfaces (rather than using https://github.com/google/go-tpm-tools/tree/main/simulator/ms-tpm-20-ref/Samples/Google). For example, the
Storagestruct uses a fixed array of sizeC.NV_MEMORY_SIZEand supports optional callbacks forOnEnable,OnReady, andOnCommit.The entire repository is now the Go module (
github.com/google/TPM), which ensures that the C source files inTPMCmdare included when the module is fetched byGOPROXY.Commit Breakdown
Add scaffolding for Go bindings
./bindings/c/1build.go: to handle CGO compilation flags and define C wrapper functions../bindings/README.md: instructions on building, testing, and publishing../bindings/regenerate_c.py: automate the creation of wrapper C files../go.mod: Must be at the repository root.Run
./bindings/regenerate_c.py./bindings/c/and pointing directly to the files in./TPMCmd.Platform and Entrypoints code
./bindings/go/platform/: implements the Go platform callbacks (storage,timer,system,act)../bindings/go/entrypoints/: providesentrypointsforManufacture,Init, andExecuteCommand. Note thatManufacturetakes no arguments and always forces manufacturing.Verification
Build and run everything in this module from the repository root:
go build ./bindings/go/... go test ./bindings/go/entrypoints/...The bindings were verified by integrating them into
go-tpmand running the fulltpm2/testsuite. All tests passed.