diff --git a/bindings/README.md b/bindings/README.md new file mode 100644 index 0000000..ad80cc5 --- /dev/null +++ b/bindings/README.md @@ -0,0 +1,60 @@ +# Bindings to the TPM 2.0 Reference Implementation + +## Regenerating the `bindings/c/` directory + +The `./c/` subdirectory contains wrapper files to all the C source files needed +to build the reference code in its default implementation. We use a directory of +wrappers to maintain an explicit list of source files without copying their +contents. These files live in the `bindings/c` directory to be built with the +Go toolchain; however, this list of files is also used by Rust. + +These files can be regenerated by running `./bindings/regenerate_c.py`. + +## Go + +These Go packages are not intended to be used directly, but rather with +higher-level libraries, like: + - https://pkg.go.dev/github.com/google/go-tpm/tpm2 + - https://pkg.go.dev/github.com/google/go-tpm-tools + +This package provides the backing implementation for +https://pkg.go.dev/github.com/google/go-tpm/tpm2/transport/simulator. + +### Building and Testing + +To build all the Go files, run `go build ./bindings/go/...` from the root of +this repository. To test that the bindings link correctly, run +`go test ./bindings/go/entrypoints/...` from the same directory. + +The tests only do very basic testing to make sure everything is hooked up +correctly. For more involved testing, see go-tpm's extensive `tpm2` tests: +https://github.com/google/go-tpm/tree/main/tpm2/test. + +### Previewing Documentation + +Before publishing any code, the documentation should be previewed by running: +```bash +go doc -http +``` +This will spawn a local webserver to show what documentation will look like at: + - https://pkg.go.dev/github.com/google/TPM/bindings/go/entrypoints + - https://pkg.go.dev/github.com/google/TPM/bindings/go/platform + - https://pkg.go.dev/github.com/google/TPM/bindings/c + +You can use port-forwarding to read the documentation if you're using SSH: +```bash +export PORT=12345 # Random port chosen by go doc +ssh -N -L "${PORT}:localhost:${PORT}" $HOST +``` +You'll then be able to access the documentation at the +`http://localhost:PORT/github.com/...` link provided by `go doc`. + +### Publishing the Go Module + +To publish a new version of the Go module, you must create a git tag. For +example, to tag version `0.184.0`: + +```bash +git tag v0.184.0 +git push origin v0.184.0 +``` diff --git a/bindings/c/1build.go b/bindings/c/1build.go new file mode 100644 index 0000000..bddcbca --- /dev/null +++ b/bindings/c/1build.go @@ -0,0 +1,61 @@ +// Package c handles compiling the C code in the TPMCmd/tpm/ directory. +// +// "Listen to my tale of woe." - Frankenstein's Monster +// +// # Overview +// +// We aim to compile the entire TPM reference code using only the Go build +// system. Significant contortions are required to achieve this without +// copying C files. +// +// Go's CGO build system is very primitive (to put it politely). While it can +// include headers (.h files) from any location, it can only compile sources +// (.c files) located in the same directory as the Go package. CGO does not +// search subdirectories for sources, so any C files we want to compile must be +// generated in the top level of this directory. +// +// # Notes on CGO Build Behavior +// +// - **Header Caching**: Go tracks changes to `.c` files in the package +// directory, but may not detect changes to header files in include paths. +// If you modify a header file, you must run `go build -a` or +// `go clean -cache` to force a rebuild. +// - **Linking Errors**: Linking errors usually appear as missing symbols +// during the final Go link phase because CGO compiles files independently. +// - **Threading**: Go 1.26 (via CL 694475) runs CGO compiles in parallel, +// reducing build times significantly (e.g., from 42s in Go 1.25 to 7s). +// - **Underscore Files**: Go ignores files starting with `_`. The generation +// script (regenerate_c.py) strips the leading underscore to +// allow CGO to compile them. +// - **Name**: This file is named `1build.go` so that it appears at the top +// of the file list in editors and directory listings. +// - **Directory Structure**: `bindings/c/` contains the CGO build file and +// wrapper files to C sources. The C files access headers in `TPMCmd` at the +// repository root via relative paths (`../../TPMCmd`). +package c + +// #cgo CFLAGS: -std=c11 -Wall -Wextra -pedantic -Werror +// // We do crimes with function pointer casts in the marshalling and hash code. +// #cgo CFLAGS: -Wno-cast-function-type +// +// #cgo CFLAGS: -I ../../TPMCmd/TpmConfiguration/ +// #cgo CFLAGS: -I ../../TPMCmd/tpm/include/ +// #cgo CFLAGS: -I ../../TPMCmd/tpm/include/private/ +// #cgo CFLAGS: -I ../../TPMCmd/tpm/include/private/prototypes/ +// #cgo CFLAGS: -I ../../TPMCmd/tpm/cryptolibs/common/include/ +// #cgo CFLAGS: -I ../../TPMCmd/tpm/cryptolibs/Ossl/include/ +// #cgo CFLAGS: -I ../../TPMCmd/tpm/cryptolibs/TpmBigNum/ +// #cgo CFLAGS: -I ../../TPMCmd/tpm/cryptolibs/TpmBigNum/include/ +// +// // Link against the system OpenSSL +// #cgo LDFLAGS: -lcrypto +// #cgo CFLAGS: -DSYM_LIB=Ossl +// #cgo CFLAGS: -DHASH_LIB=Ossl +// #cgo CFLAGS: -DMATH_LIB=TpmBigNum +// #cgo CFLAGS: -DBN_MATH_LIB=Ossl +// // Flags to find OpenSSL installation on macOS (default Homebrew location) +// #cgo darwin,amd64 CFLAGS: -I/usr/local/opt/openssl/include +// #cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/openssl/lib +// #cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/openssl/include +// #cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/openssl/lib +import "C" diff --git a/bindings/c/ACT_SetTimeout.c b/bindings/c/ACT_SetTimeout.c new file mode 100644 index 0000000..8945c0b --- /dev/null +++ b/bindings/c/ACT_SetTimeout.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/ClockTimer/ACT_SetTimeout.c" diff --git a/bindings/c/ACT_spt.c b/bindings/c/ACT_spt.c new file mode 100644 index 0000000..283b830 --- /dev/null +++ b/bindings/c/ACT_spt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/ClockTimer/ACT_spt.c" diff --git a/bindings/c/AC_GetCapability.c b/bindings/c/AC_GetCapability.c new file mode 100644 index 0000000..05cb217 --- /dev/null +++ b/bindings/c/AC_GetCapability.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/AttachedComponent/AC_GetCapability.c" diff --git a/bindings/c/AC_Send.c b/bindings/c/AC_Send.c new file mode 100644 index 0000000..c01e1df --- /dev/null +++ b/bindings/c/AC_Send.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/AttachedComponent/AC_Send.c" diff --git a/bindings/c/AC_spt.c b/bindings/c/AC_spt.c new file mode 100644 index 0000000..15920f3 --- /dev/null +++ b/bindings/c/AC_spt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/AttachedComponent/AC_spt.c" diff --git a/bindings/c/ActivateCredential.c b/bindings/c/ActivateCredential.c new file mode 100644 index 0000000..2c62525 --- /dev/null +++ b/bindings/c/ActivateCredential.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/ActivateCredential.c" diff --git a/bindings/c/AlgorithmCap.c b/bindings/c/AlgorithmCap.c new file mode 100644 index 0000000..e215026 --- /dev/null +++ b/bindings/c/AlgorithmCap.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/AlgorithmCap.c" diff --git a/bindings/c/AlgorithmTests.c b/bindings/c/AlgorithmTests.c new file mode 100644 index 0000000..68abfdb --- /dev/null +++ b/bindings/c/AlgorithmTests.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/AlgorithmTests.c" diff --git a/bindings/c/Attest_spt.c b/bindings/c/Attest_spt.c new file mode 100644 index 0000000..6217296 --- /dev/null +++ b/bindings/c/Attest_spt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Attestation/Attest_spt.c" diff --git a/bindings/c/Bits.c b/bindings/c/Bits.c new file mode 100644 index 0000000..bf36bc1 --- /dev/null +++ b/bindings/c/Bits.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Bits.c" diff --git a/bindings/c/BnConvert.c b/bindings/c/BnConvert.c new file mode 100644 index 0000000..0bc1ce6 --- /dev/null +++ b/bindings/c/BnConvert.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/cryptolibs/TpmBigNum/BnConvert.c" diff --git a/bindings/c/BnEccConstants.c b/bindings/c/BnEccConstants.c new file mode 100644 index 0000000..474412e --- /dev/null +++ b/bindings/c/BnEccConstants.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/cryptolibs/TpmBigNum/BnEccConstants.c" diff --git a/bindings/c/BnMath.c b/bindings/c/BnMath.c new file mode 100644 index 0000000..74a1431 --- /dev/null +++ b/bindings/c/BnMath.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/cryptolibs/TpmBigNum/BnMath.c" diff --git a/bindings/c/BnMemory.c b/bindings/c/BnMemory.c new file mode 100644 index 0000000..d382904 --- /dev/null +++ b/bindings/c/BnMemory.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/cryptolibs/TpmBigNum/BnMemory.c" diff --git a/bindings/c/BnToOsslMath.c b/bindings/c/BnToOsslMath.c new file mode 100644 index 0000000..16c4881 --- /dev/null +++ b/bindings/c/BnToOsslMath.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/cryptolibs/Ossl/BnToOsslMath.c" diff --git a/bindings/c/BnUtil.c b/bindings/c/BnUtil.c new file mode 100644 index 0000000..34a2e8d --- /dev/null +++ b/bindings/c/BnUtil.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/cryptolibs/TpmBigNum/BnUtil.c" diff --git a/bindings/c/Certify.c b/bindings/c/Certify.c new file mode 100644 index 0000000..36dfcbf --- /dev/null +++ b/bindings/c/Certify.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Attestation/Certify.c" diff --git a/bindings/c/CertifyCreation.c b/bindings/c/CertifyCreation.c new file mode 100644 index 0000000..b877901 --- /dev/null +++ b/bindings/c/CertifyCreation.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Attestation/CertifyCreation.c" diff --git a/bindings/c/ChangeEPS.c b/bindings/c/ChangeEPS.c new file mode 100644 index 0000000..a8ededb --- /dev/null +++ b/bindings/c/ChangeEPS.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/ChangeEPS.c" diff --git a/bindings/c/ChangePPS.c b/bindings/c/ChangePPS.c new file mode 100644 index 0000000..6f45dae --- /dev/null +++ b/bindings/c/ChangePPS.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/ChangePPS.c" diff --git a/bindings/c/Clear.c b/bindings/c/Clear.c new file mode 100644 index 0000000..2300ae8 --- /dev/null +++ b/bindings/c/Clear.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/Clear.c" diff --git a/bindings/c/ClearControl.c b/bindings/c/ClearControl.c new file mode 100644 index 0000000..ea2ca4b --- /dev/null +++ b/bindings/c/ClearControl.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/ClearControl.c" diff --git a/bindings/c/ClockRateAdjust.c b/bindings/c/ClockRateAdjust.c new file mode 100644 index 0000000..aefdb29 --- /dev/null +++ b/bindings/c/ClockRateAdjust.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/ClockTimer/ClockRateAdjust.c" diff --git a/bindings/c/ClockSet.c b/bindings/c/ClockSet.c new file mode 100644 index 0000000..55daa47 --- /dev/null +++ b/bindings/c/ClockSet.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/ClockTimer/ClockSet.c" diff --git a/bindings/c/CommandAudit.c b/bindings/c/CommandAudit.c new file mode 100644 index 0000000..a4a2352 --- /dev/null +++ b/bindings/c/CommandAudit.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/CommandAudit.c" diff --git a/bindings/c/CommandCodeAttributes.c b/bindings/c/CommandCodeAttributes.c new file mode 100644 index 0000000..e943dc4 --- /dev/null +++ b/bindings/c/CommandCodeAttributes.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/CommandCodeAttributes.c" diff --git a/bindings/c/CommandDispatcher.c b/bindings/c/CommandDispatcher.c new file mode 100644 index 0000000..fda6de3 --- /dev/null +++ b/bindings/c/CommandDispatcher.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/main/CommandDispatcher.c" diff --git a/bindings/c/Commit.c b/bindings/c/Commit.c new file mode 100644 index 0000000..75aaa63 --- /dev/null +++ b/bindings/c/Commit.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Ecdaa/Commit.c" diff --git a/bindings/c/ContextLoad.c b/bindings/c/ContextLoad.c new file mode 100644 index 0000000..9508457 --- /dev/null +++ b/bindings/c/ContextLoad.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Context/ContextLoad.c" diff --git a/bindings/c/ContextSave.c b/bindings/c/ContextSave.c new file mode 100644 index 0000000..0dc52f3 --- /dev/null +++ b/bindings/c/ContextSave.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Context/ContextSave.c" diff --git a/bindings/c/Context_spt.c b/bindings/c/Context_spt.c new file mode 100644 index 0000000..4fe40c6 --- /dev/null +++ b/bindings/c/Context_spt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Context/Context_spt.c" diff --git a/bindings/c/Create.c b/bindings/c/Create.c new file mode 100644 index 0000000..8f11609 --- /dev/null +++ b/bindings/c/Create.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/Create.c" diff --git a/bindings/c/CreateLoaded.c b/bindings/c/CreateLoaded.c new file mode 100644 index 0000000..803c763 --- /dev/null +++ b/bindings/c/CreateLoaded.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/CreateLoaded.c" diff --git a/bindings/c/CreatePrimary.c b/bindings/c/CreatePrimary.c new file mode 100644 index 0000000..efed34d --- /dev/null +++ b/bindings/c/CreatePrimary.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/CreatePrimary.c" diff --git a/bindings/c/CryptCmac.c b/bindings/c/CryptCmac.c new file mode 100644 index 0000000..5af9b4f --- /dev/null +++ b/bindings/c/CryptCmac.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptCmac.c" diff --git a/bindings/c/CryptEccCrypt.c b/bindings/c/CryptEccCrypt.c new file mode 100644 index 0000000..ffa484a --- /dev/null +++ b/bindings/c/CryptEccCrypt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptEccCrypt.c" diff --git a/bindings/c/CryptEccData.c b/bindings/c/CryptEccData.c new file mode 100644 index 0000000..161b1ba --- /dev/null +++ b/bindings/c/CryptEccData.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptEccData.c" diff --git a/bindings/c/CryptEccKeyExchange.c b/bindings/c/CryptEccKeyExchange.c new file mode 100644 index 0000000..9e8e351 --- /dev/null +++ b/bindings/c/CryptEccKeyExchange.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptEccKeyExchange.c" diff --git a/bindings/c/CryptEccMain.c b/bindings/c/CryptEccMain.c new file mode 100644 index 0000000..dde46ff --- /dev/null +++ b/bindings/c/CryptEccMain.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptEccMain.c" diff --git a/bindings/c/CryptEccSignature.c b/bindings/c/CryptEccSignature.c new file mode 100644 index 0000000..082e429 --- /dev/null +++ b/bindings/c/CryptEccSignature.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptEccSignature.c" diff --git a/bindings/c/CryptHash.c b/bindings/c/CryptHash.c new file mode 100644 index 0000000..40e5c26 --- /dev/null +++ b/bindings/c/CryptHash.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptHash.c" diff --git a/bindings/c/CryptPrime.c b/bindings/c/CryptPrime.c new file mode 100644 index 0000000..a060c20 --- /dev/null +++ b/bindings/c/CryptPrime.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptPrime.c" diff --git a/bindings/c/CryptPrimeSieve.c b/bindings/c/CryptPrimeSieve.c new file mode 100644 index 0000000..31550da --- /dev/null +++ b/bindings/c/CryptPrimeSieve.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptPrimeSieve.c" diff --git a/bindings/c/CryptRand.c b/bindings/c/CryptRand.c new file mode 100644 index 0000000..8e94fbc --- /dev/null +++ b/bindings/c/CryptRand.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptRand.c" diff --git a/bindings/c/CryptRsa.c b/bindings/c/CryptRsa.c new file mode 100644 index 0000000..38706ed --- /dev/null +++ b/bindings/c/CryptRsa.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptRsa.c" diff --git a/bindings/c/CryptSelfTest.c b/bindings/c/CryptSelfTest.c new file mode 100644 index 0000000..fda8bb2 --- /dev/null +++ b/bindings/c/CryptSelfTest.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptSelfTest.c" diff --git a/bindings/c/CryptSmac.c b/bindings/c/CryptSmac.c new file mode 100644 index 0000000..234f90e --- /dev/null +++ b/bindings/c/CryptSmac.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptSmac.c" diff --git a/bindings/c/CryptSym.c b/bindings/c/CryptSym.c new file mode 100644 index 0000000..007fd53 --- /dev/null +++ b/bindings/c/CryptSym.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptSym.c" diff --git a/bindings/c/CryptUtil.c b/bindings/c/CryptUtil.c new file mode 100644 index 0000000..6bdb08e --- /dev/null +++ b/bindings/c/CryptUtil.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/CryptUtil.c" diff --git a/bindings/c/DA.c b/bindings/c/DA.c new file mode 100644 index 0000000..f694a33 --- /dev/null +++ b/bindings/c/DA.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/DA.c" diff --git a/bindings/c/DictionaryAttackLockReset.c b/bindings/c/DictionaryAttackLockReset.c new file mode 100644 index 0000000..05c160c --- /dev/null +++ b/bindings/c/DictionaryAttackLockReset.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/DA/DictionaryAttackLockReset.c" diff --git a/bindings/c/DictionaryAttackParameters.c b/bindings/c/DictionaryAttackParameters.c new file mode 100644 index 0000000..6e8194e --- /dev/null +++ b/bindings/c/DictionaryAttackParameters.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/DA/DictionaryAttackParameters.c" diff --git a/bindings/c/Duplicate.c b/bindings/c/Duplicate.c new file mode 100644 index 0000000..c32df05 --- /dev/null +++ b/bindings/c/Duplicate.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Duplication/Duplicate.c" diff --git a/bindings/c/ECC_Decrypt.c b/bindings/c/ECC_Decrypt.c new file mode 100644 index 0000000..d18e81f --- /dev/null +++ b/bindings/c/ECC_Decrypt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/ECC_Decrypt.c" diff --git a/bindings/c/ECC_Encrypt.c b/bindings/c/ECC_Encrypt.c new file mode 100644 index 0000000..30f3502 --- /dev/null +++ b/bindings/c/ECC_Encrypt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/ECC_Encrypt.c" diff --git a/bindings/c/ECC_Parameters.c b/bindings/c/ECC_Parameters.c new file mode 100644 index 0000000..30e5f91 --- /dev/null +++ b/bindings/c/ECC_Parameters.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/ECC_Parameters.c" diff --git a/bindings/c/ECDH_KeyGen.c b/bindings/c/ECDH_KeyGen.c new file mode 100644 index 0000000..4153185 --- /dev/null +++ b/bindings/c/ECDH_KeyGen.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/ECDH_KeyGen.c" diff --git a/bindings/c/ECDH_ZGen.c b/bindings/c/ECDH_ZGen.c new file mode 100644 index 0000000..92ab908 --- /dev/null +++ b/bindings/c/ECDH_ZGen.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/ECDH_ZGen.c" diff --git a/bindings/c/EC_Ephemeral.c b/bindings/c/EC_Ephemeral.c new file mode 100644 index 0000000..88ac913 --- /dev/null +++ b/bindings/c/EC_Ephemeral.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/EC_Ephemeral.c" diff --git a/bindings/c/EncryptDecrypt.c b/bindings/c/EncryptDecrypt.c new file mode 100644 index 0000000..01d6bce --- /dev/null +++ b/bindings/c/EncryptDecrypt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Symmetric/EncryptDecrypt.c" diff --git a/bindings/c/EncryptDecrypt2.c b/bindings/c/EncryptDecrypt2.c new file mode 100644 index 0000000..65480a5 --- /dev/null +++ b/bindings/c/EncryptDecrypt2.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Symmetric/EncryptDecrypt2.c" diff --git a/bindings/c/EncryptDecrypt_spt.c b/bindings/c/EncryptDecrypt_spt.c new file mode 100644 index 0000000..e6d5337 --- /dev/null +++ b/bindings/c/EncryptDecrypt_spt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Symmetric/EncryptDecrypt_spt.c" diff --git a/bindings/c/Entity.c b/bindings/c/Entity.c new file mode 100644 index 0000000..2917a5e --- /dev/null +++ b/bindings/c/Entity.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Entity.c" diff --git a/bindings/c/EventSequenceComplete.c b/bindings/c/EventSequenceComplete.c new file mode 100644 index 0000000..8a68f06 --- /dev/null +++ b/bindings/c/EventSequenceComplete.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/HashHMAC/EventSequenceComplete.c" diff --git a/bindings/c/EvictControl.c b/bindings/c/EvictControl.c new file mode 100644 index 0000000..1ecb8d4 --- /dev/null +++ b/bindings/c/EvictControl.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Context/EvictControl.c" diff --git a/bindings/c/ExecCommand.c b/bindings/c/ExecCommand.c new file mode 100644 index 0000000..0e916af --- /dev/null +++ b/bindings/c/ExecCommand.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/main/ExecCommand.c" diff --git a/bindings/c/FieldUpgradeData.c b/bindings/c/FieldUpgradeData.c new file mode 100644 index 0000000..8089ff9 --- /dev/null +++ b/bindings/c/FieldUpgradeData.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/FieldUpgrade/FieldUpgradeData.c" diff --git a/bindings/c/FieldUpgradeStart.c b/bindings/c/FieldUpgradeStart.c new file mode 100644 index 0000000..05c522a --- /dev/null +++ b/bindings/c/FieldUpgradeStart.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/FieldUpgrade/FieldUpgradeStart.c" diff --git a/bindings/c/FirmwareRead.c b/bindings/c/FirmwareRead.c new file mode 100644 index 0000000..15e2ca6 --- /dev/null +++ b/bindings/c/FirmwareRead.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/FieldUpgrade/FirmwareRead.c" diff --git a/bindings/c/FlushContext.c b/bindings/c/FlushContext.c new file mode 100644 index 0000000..f605830 --- /dev/null +++ b/bindings/c/FlushContext.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Context/FlushContext.c" diff --git a/bindings/c/GetCapability.c b/bindings/c/GetCapability.c new file mode 100644 index 0000000..38982b1 --- /dev/null +++ b/bindings/c/GetCapability.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Capability/GetCapability.c" diff --git a/bindings/c/GetCommandAuditDigest.c b/bindings/c/GetCommandAuditDigest.c new file mode 100644 index 0000000..3525960 --- /dev/null +++ b/bindings/c/GetCommandAuditDigest.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Attestation/GetCommandAuditDigest.c" diff --git a/bindings/c/GetRandom.c b/bindings/c/GetRandom.c new file mode 100644 index 0000000..5386464 --- /dev/null +++ b/bindings/c/GetRandom.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Random/GetRandom.c" diff --git a/bindings/c/GetSessionAuditDigest.c b/bindings/c/GetSessionAuditDigest.c new file mode 100644 index 0000000..20c4025 --- /dev/null +++ b/bindings/c/GetSessionAuditDigest.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Attestation/GetSessionAuditDigest.c" diff --git a/bindings/c/GetTestResult.c b/bindings/c/GetTestResult.c new file mode 100644 index 0000000..73689e6 --- /dev/null +++ b/bindings/c/GetTestResult.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Testing/GetTestResult.c" diff --git a/bindings/c/GetTime.c b/bindings/c/GetTime.c new file mode 100644 index 0000000..eea08e2 --- /dev/null +++ b/bindings/c/GetTime.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Attestation/GetTime.c" diff --git a/bindings/c/Global.c b/bindings/c/Global.c new file mode 100644 index 0000000..3d4ab46 --- /dev/null +++ b/bindings/c/Global.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Global.c" diff --git a/bindings/c/HMAC.c b/bindings/c/HMAC.c new file mode 100644 index 0000000..3ba75d2 --- /dev/null +++ b/bindings/c/HMAC.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Symmetric/HMAC.c" diff --git a/bindings/c/HMAC_Start.c b/bindings/c/HMAC_Start.c new file mode 100644 index 0000000..f3a0fff --- /dev/null +++ b/bindings/c/HMAC_Start.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/HashHMAC/HMAC_Start.c" diff --git a/bindings/c/Handle.c b/bindings/c/Handle.c new file mode 100644 index 0000000..994cf6a --- /dev/null +++ b/bindings/c/Handle.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Handle.c" diff --git a/bindings/c/Hash.c b/bindings/c/Hash.c new file mode 100644 index 0000000..3ac322a --- /dev/null +++ b/bindings/c/Hash.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Symmetric/Hash.c" diff --git a/bindings/c/HashSequenceStart.c b/bindings/c/HashSequenceStart.c new file mode 100644 index 0000000..c1dea83 --- /dev/null +++ b/bindings/c/HashSequenceStart.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/HashHMAC/HashSequenceStart.c" diff --git a/bindings/c/Hierarchy.c b/bindings/c/Hierarchy.c new file mode 100644 index 0000000..25ce312 --- /dev/null +++ b/bindings/c/Hierarchy.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/Hierarchy.c" diff --git a/bindings/c/HierarchyChangeAuth.c b/bindings/c/HierarchyChangeAuth.c new file mode 100644 index 0000000..9b91c0d --- /dev/null +++ b/bindings/c/HierarchyChangeAuth.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/HierarchyChangeAuth.c" diff --git a/bindings/c/HierarchyControl.c b/bindings/c/HierarchyControl.c new file mode 100644 index 0000000..8726c96 --- /dev/null +++ b/bindings/c/HierarchyControl.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/HierarchyControl.c" diff --git a/bindings/c/Import.c b/bindings/c/Import.c new file mode 100644 index 0000000..23e6f2e --- /dev/null +++ b/bindings/c/Import.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Duplication/Import.c" diff --git a/bindings/c/IncrementalSelfTest.c b/bindings/c/IncrementalSelfTest.c new file mode 100644 index 0000000..7b859e0 --- /dev/null +++ b/bindings/c/IncrementalSelfTest.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Testing/IncrementalSelfTest.c" diff --git a/bindings/c/IoBuffers.c b/bindings/c/IoBuffers.c new file mode 100644 index 0000000..a59cc28 --- /dev/null +++ b/bindings/c/IoBuffers.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/IoBuffers.c" diff --git a/bindings/c/Load.c b/bindings/c/Load.c new file mode 100644 index 0000000..7f1737f --- /dev/null +++ b/bindings/c/Load.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/Load.c" diff --git a/bindings/c/LoadExternal.c b/bindings/c/LoadExternal.c new file mode 100644 index 0000000..e76f0e0 --- /dev/null +++ b/bindings/c/LoadExternal.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/LoadExternal.c" diff --git a/bindings/c/Locality.c b/bindings/c/Locality.c new file mode 100644 index 0000000..637e526 --- /dev/null +++ b/bindings/c/Locality.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Locality.c" diff --git a/bindings/c/MAC.c b/bindings/c/MAC.c new file mode 100644 index 0000000..2c8603c --- /dev/null +++ b/bindings/c/MAC.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Symmetric/MAC.c" diff --git a/bindings/c/MAC_Start.c b/bindings/c/MAC_Start.c new file mode 100644 index 0000000..510566c --- /dev/null +++ b/bindings/c/MAC_Start.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/HashHMAC/MAC_Start.c" diff --git a/bindings/c/MakeCredential.c b/bindings/c/MakeCredential.c new file mode 100644 index 0000000..16d9094 --- /dev/null +++ b/bindings/c/MakeCredential.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/MakeCredential.c" diff --git a/bindings/c/Manufacture.c b/bindings/c/Manufacture.c new file mode 100644 index 0000000..ad54b7b --- /dev/null +++ b/bindings/c/Manufacture.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Manufacture.c" diff --git a/bindings/c/Marshal.c b/bindings/c/Marshal.c new file mode 100644 index 0000000..47a4e76 --- /dev/null +++ b/bindings/c/Marshal.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Marshal.c" diff --git a/bindings/c/MathOnByteBuffers.c b/bindings/c/MathOnByteBuffers.c new file mode 100644 index 0000000..672dd92 --- /dev/null +++ b/bindings/c/MathOnByteBuffers.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/MathOnByteBuffers.c" diff --git a/bindings/c/Memory.c b/bindings/c/Memory.c new file mode 100644 index 0000000..024b693 --- /dev/null +++ b/bindings/c/Memory.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Memory.c" diff --git a/bindings/c/NV_Certify.c b/bindings/c/NV_Certify.c new file mode 100644 index 0000000..83edff8 --- /dev/null +++ b/bindings/c/NV_Certify.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_Certify.c" diff --git a/bindings/c/NV_ChangeAuth.c b/bindings/c/NV_ChangeAuth.c new file mode 100644 index 0000000..65d4dbd --- /dev/null +++ b/bindings/c/NV_ChangeAuth.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_ChangeAuth.c" diff --git a/bindings/c/NV_DefineSpace.c b/bindings/c/NV_DefineSpace.c new file mode 100644 index 0000000..0902e07 --- /dev/null +++ b/bindings/c/NV_DefineSpace.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_DefineSpace.c" diff --git a/bindings/c/NV_DefineSpace2.c b/bindings/c/NV_DefineSpace2.c new file mode 100644 index 0000000..c82ac0d --- /dev/null +++ b/bindings/c/NV_DefineSpace2.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_DefineSpace2.c" diff --git a/bindings/c/NV_Extend.c b/bindings/c/NV_Extend.c new file mode 100644 index 0000000..0c0ea67 --- /dev/null +++ b/bindings/c/NV_Extend.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_Extend.c" diff --git a/bindings/c/NV_GlobalWriteLock.c b/bindings/c/NV_GlobalWriteLock.c new file mode 100644 index 0000000..a53e1e0 --- /dev/null +++ b/bindings/c/NV_GlobalWriteLock.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_GlobalWriteLock.c" diff --git a/bindings/c/NV_Increment.c b/bindings/c/NV_Increment.c new file mode 100644 index 0000000..120daed --- /dev/null +++ b/bindings/c/NV_Increment.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_Increment.c" diff --git a/bindings/c/NV_Read.c b/bindings/c/NV_Read.c new file mode 100644 index 0000000..69419ae --- /dev/null +++ b/bindings/c/NV_Read.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_Read.c" diff --git a/bindings/c/NV_ReadLock.c b/bindings/c/NV_ReadLock.c new file mode 100644 index 0000000..be542dd --- /dev/null +++ b/bindings/c/NV_ReadLock.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_ReadLock.c" diff --git a/bindings/c/NV_ReadPublic.c b/bindings/c/NV_ReadPublic.c new file mode 100644 index 0000000..d73c689 --- /dev/null +++ b/bindings/c/NV_ReadPublic.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_ReadPublic.c" diff --git a/bindings/c/NV_ReadPublic2.c b/bindings/c/NV_ReadPublic2.c new file mode 100644 index 0000000..a09820f --- /dev/null +++ b/bindings/c/NV_ReadPublic2.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_ReadPublic2.c" diff --git a/bindings/c/NV_SetBits.c b/bindings/c/NV_SetBits.c new file mode 100644 index 0000000..bfe9abf --- /dev/null +++ b/bindings/c/NV_SetBits.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_SetBits.c" diff --git a/bindings/c/NV_UndefineSpace.c b/bindings/c/NV_UndefineSpace.c new file mode 100644 index 0000000..4eb7180 --- /dev/null +++ b/bindings/c/NV_UndefineSpace.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_UndefineSpace.c" diff --git a/bindings/c/NV_UndefineSpaceSpecial.c b/bindings/c/NV_UndefineSpaceSpecial.c new file mode 100644 index 0000000..35cd50c --- /dev/null +++ b/bindings/c/NV_UndefineSpaceSpecial.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_UndefineSpaceSpecial.c" diff --git a/bindings/c/NV_Write.c b/bindings/c/NV_Write.c new file mode 100644 index 0000000..6411a6b --- /dev/null +++ b/bindings/c/NV_Write.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_Write.c" diff --git a/bindings/c/NV_WriteLock.c b/bindings/c/NV_WriteLock.c new file mode 100644 index 0000000..8e591f3 --- /dev/null +++ b/bindings/c/NV_WriteLock.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_WriteLock.c" diff --git a/bindings/c/NV_spt.c b/bindings/c/NV_spt.c new file mode 100644 index 0000000..34a2d00 --- /dev/null +++ b/bindings/c/NV_spt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/NVStorage/NV_spt.c" diff --git a/bindings/c/NvDynamic.c b/bindings/c/NvDynamic.c new file mode 100644 index 0000000..a5fa137 --- /dev/null +++ b/bindings/c/NvDynamic.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/NvDynamic.c" diff --git a/bindings/c/NvReserved.c b/bindings/c/NvReserved.c new file mode 100644 index 0000000..fe2106e --- /dev/null +++ b/bindings/c/NvReserved.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/NvReserved.c" diff --git a/bindings/c/Object.c b/bindings/c/Object.c new file mode 100644 index 0000000..401eca1 --- /dev/null +++ b/bindings/c/Object.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/Object.c" diff --git a/bindings/c/ObjectChangeAuth.c b/bindings/c/ObjectChangeAuth.c new file mode 100644 index 0000000..b32100c --- /dev/null +++ b/bindings/c/ObjectChangeAuth.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/ObjectChangeAuth.c" diff --git a/bindings/c/Object_spt.c b/bindings/c/Object_spt.c new file mode 100644 index 0000000..6e118ce --- /dev/null +++ b/bindings/c/Object_spt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/Object_spt.c" diff --git a/bindings/c/PCR.c b/bindings/c/PCR.c new file mode 100644 index 0000000..4c496ea --- /dev/null +++ b/bindings/c/PCR.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/PCR.c" diff --git a/bindings/c/PCR_Allocate.c b/bindings/c/PCR_Allocate.c new file mode 100644 index 0000000..c743ebf --- /dev/null +++ b/bindings/c/PCR_Allocate.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/PCR/PCR_Allocate.c" diff --git a/bindings/c/PCR_Event.c b/bindings/c/PCR_Event.c new file mode 100644 index 0000000..4d01213 --- /dev/null +++ b/bindings/c/PCR_Event.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/PCR/PCR_Event.c" diff --git a/bindings/c/PCR_Extend.c b/bindings/c/PCR_Extend.c new file mode 100644 index 0000000..c106e68 --- /dev/null +++ b/bindings/c/PCR_Extend.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/PCR/PCR_Extend.c" diff --git a/bindings/c/PCR_Read.c b/bindings/c/PCR_Read.c new file mode 100644 index 0000000..36813f6 --- /dev/null +++ b/bindings/c/PCR_Read.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/PCR/PCR_Read.c" diff --git a/bindings/c/PCR_Reset.c b/bindings/c/PCR_Reset.c new file mode 100644 index 0000000..3a8af20 --- /dev/null +++ b/bindings/c/PCR_Reset.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/PCR/PCR_Reset.c" diff --git a/bindings/c/PCR_SetAuthPolicy.c b/bindings/c/PCR_SetAuthPolicy.c new file mode 100644 index 0000000..45ae221 --- /dev/null +++ b/bindings/c/PCR_SetAuthPolicy.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/PCR/PCR_SetAuthPolicy.c" diff --git a/bindings/c/PCR_SetAuthValue.c b/bindings/c/PCR_SetAuthValue.c new file mode 100644 index 0000000..9f6c3ff --- /dev/null +++ b/bindings/c/PCR_SetAuthValue.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/PCR/PCR_SetAuthValue.c" diff --git a/bindings/c/PP.c b/bindings/c/PP.c new file mode 100644 index 0000000..febcc01 --- /dev/null +++ b/bindings/c/PP.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/PP.c" diff --git a/bindings/c/PP_Commands.c b/bindings/c/PP_Commands.c new file mode 100644 index 0000000..3f78c70 --- /dev/null +++ b/bindings/c/PP_Commands.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Misc/PP_Commands.c" diff --git a/bindings/c/PolicyAuthValue.c b/bindings/c/PolicyAuthValue.c new file mode 100644 index 0000000..94bf726 --- /dev/null +++ b/bindings/c/PolicyAuthValue.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyAuthValue.c" diff --git a/bindings/c/PolicyAuthorize.c b/bindings/c/PolicyAuthorize.c new file mode 100644 index 0000000..ff89646 --- /dev/null +++ b/bindings/c/PolicyAuthorize.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyAuthorize.c" diff --git a/bindings/c/PolicyAuthorizeNV.c b/bindings/c/PolicyAuthorizeNV.c new file mode 100644 index 0000000..a130f52 --- /dev/null +++ b/bindings/c/PolicyAuthorizeNV.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyAuthorizeNV.c" diff --git a/bindings/c/PolicyCapability.c b/bindings/c/PolicyCapability.c new file mode 100644 index 0000000..f4a91ae --- /dev/null +++ b/bindings/c/PolicyCapability.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyCapability.c" diff --git a/bindings/c/PolicyCommandCode.c b/bindings/c/PolicyCommandCode.c new file mode 100644 index 0000000..38dd938 --- /dev/null +++ b/bindings/c/PolicyCommandCode.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyCommandCode.c" diff --git a/bindings/c/PolicyCounterTimer.c b/bindings/c/PolicyCounterTimer.c new file mode 100644 index 0000000..546fecf --- /dev/null +++ b/bindings/c/PolicyCounterTimer.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyCounterTimer.c" diff --git a/bindings/c/PolicyCpHash.c b/bindings/c/PolicyCpHash.c new file mode 100644 index 0000000..f5c5e3b --- /dev/null +++ b/bindings/c/PolicyCpHash.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyCpHash.c" diff --git a/bindings/c/PolicyDuplicationSelect.c b/bindings/c/PolicyDuplicationSelect.c new file mode 100644 index 0000000..29c2054 --- /dev/null +++ b/bindings/c/PolicyDuplicationSelect.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyDuplicationSelect.c" diff --git a/bindings/c/PolicyGetDigest.c b/bindings/c/PolicyGetDigest.c new file mode 100644 index 0000000..25b9dbf --- /dev/null +++ b/bindings/c/PolicyGetDigest.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyGetDigest.c" diff --git a/bindings/c/PolicyLocality.c b/bindings/c/PolicyLocality.c new file mode 100644 index 0000000..c41d08d --- /dev/null +++ b/bindings/c/PolicyLocality.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyLocality.c" diff --git a/bindings/c/PolicyNV.c b/bindings/c/PolicyNV.c new file mode 100644 index 0000000..917a767 --- /dev/null +++ b/bindings/c/PolicyNV.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyNV.c" diff --git a/bindings/c/PolicyNameHash.c b/bindings/c/PolicyNameHash.c new file mode 100644 index 0000000..c963a33 --- /dev/null +++ b/bindings/c/PolicyNameHash.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyNameHash.c" diff --git a/bindings/c/PolicyNvWritten.c b/bindings/c/PolicyNvWritten.c new file mode 100644 index 0000000..f70f398 --- /dev/null +++ b/bindings/c/PolicyNvWritten.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyNvWritten.c" diff --git a/bindings/c/PolicyOR.c b/bindings/c/PolicyOR.c new file mode 100644 index 0000000..11eea70 --- /dev/null +++ b/bindings/c/PolicyOR.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyOR.c" diff --git a/bindings/c/PolicyPCR.c b/bindings/c/PolicyPCR.c new file mode 100644 index 0000000..56bc2f1 --- /dev/null +++ b/bindings/c/PolicyPCR.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyPCR.c" diff --git a/bindings/c/PolicyParameters.c b/bindings/c/PolicyParameters.c new file mode 100644 index 0000000..b0197dd --- /dev/null +++ b/bindings/c/PolicyParameters.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyParameters.c" diff --git a/bindings/c/PolicyPassword.c b/bindings/c/PolicyPassword.c new file mode 100644 index 0000000..85dadb1 --- /dev/null +++ b/bindings/c/PolicyPassword.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyPassword.c" diff --git a/bindings/c/PolicyPhysicalPresence.c b/bindings/c/PolicyPhysicalPresence.c new file mode 100644 index 0000000..99db14e --- /dev/null +++ b/bindings/c/PolicyPhysicalPresence.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyPhysicalPresence.c" diff --git a/bindings/c/PolicyRestart.c b/bindings/c/PolicyRestart.c new file mode 100644 index 0000000..0851114 --- /dev/null +++ b/bindings/c/PolicyRestart.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Session/PolicyRestart.c" diff --git a/bindings/c/PolicySecret.c b/bindings/c/PolicySecret.c new file mode 100644 index 0000000..93a0b6f --- /dev/null +++ b/bindings/c/PolicySecret.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicySecret.c" diff --git a/bindings/c/PolicySigned.c b/bindings/c/PolicySigned.c new file mode 100644 index 0000000..4907bcf --- /dev/null +++ b/bindings/c/PolicySigned.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicySigned.c" diff --git a/bindings/c/PolicyTemplate.c b/bindings/c/PolicyTemplate.c new file mode 100644 index 0000000..7c96a51 --- /dev/null +++ b/bindings/c/PolicyTemplate.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyTemplate.c" diff --git a/bindings/c/PolicyTicket.c b/bindings/c/PolicyTicket.c new file mode 100644 index 0000000..41700dd --- /dev/null +++ b/bindings/c/PolicyTicket.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyTicket.c" diff --git a/bindings/c/PolicyTransportSPDM.c b/bindings/c/PolicyTransportSPDM.c new file mode 100644 index 0000000..4ca14bf --- /dev/null +++ b/bindings/c/PolicyTransportSPDM.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/PolicyTransportSPDM.c" diff --git a/bindings/c/Policy_AC_SendSelect.c b/bindings/c/Policy_AC_SendSelect.c new file mode 100644 index 0000000..7a3c57d --- /dev/null +++ b/bindings/c/Policy_AC_SendSelect.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/AttachedComponent/Policy_AC_SendSelect.c" diff --git a/bindings/c/Policy_spt.c b/bindings/c/Policy_spt.c new file mode 100644 index 0000000..f76f42e --- /dev/null +++ b/bindings/c/Policy_spt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/EA/Policy_spt.c" diff --git a/bindings/c/Power.c b/bindings/c/Power.c new file mode 100644 index 0000000..34b4ebf --- /dev/null +++ b/bindings/c/Power.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Power.c" diff --git a/bindings/c/PrimeData.c b/bindings/c/PrimeData.c new file mode 100644 index 0000000..54bc3d0 --- /dev/null +++ b/bindings/c/PrimeData.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/PrimeData.c" diff --git a/bindings/c/PropertyCap.c b/bindings/c/PropertyCap.c new file mode 100644 index 0000000..0474e94 --- /dev/null +++ b/bindings/c/PropertyCap.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/PropertyCap.c" diff --git a/bindings/c/Quote.c b/bindings/c/Quote.c new file mode 100644 index 0000000..1d07d7f --- /dev/null +++ b/bindings/c/Quote.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Attestation/Quote.c" diff --git a/bindings/c/RSA_Decrypt.c b/bindings/c/RSA_Decrypt.c new file mode 100644 index 0000000..8b60dd3 --- /dev/null +++ b/bindings/c/RSA_Decrypt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/RSA_Decrypt.c" diff --git a/bindings/c/RSA_Encrypt.c b/bindings/c/RSA_Encrypt.c new file mode 100644 index 0000000..0e011d1 --- /dev/null +++ b/bindings/c/RSA_Encrypt.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/RSA_Encrypt.c" diff --git a/bindings/c/ReadClock.c b/bindings/c/ReadClock.c new file mode 100644 index 0000000..08200dd --- /dev/null +++ b/bindings/c/ReadClock.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/ClockTimer/ReadClock.c" diff --git a/bindings/c/ReadOnlyControl.c b/bindings/c/ReadOnlyControl.c new file mode 100644 index 0000000..f9691a9 --- /dev/null +++ b/bindings/c/ReadOnlyControl.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/ReadOnlyControl.c" diff --git a/bindings/c/ReadPublic.c b/bindings/c/ReadPublic.c new file mode 100644 index 0000000..1252695 --- /dev/null +++ b/bindings/c/ReadPublic.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/ReadPublic.c" diff --git a/bindings/c/Response.c b/bindings/c/Response.c new file mode 100644 index 0000000..e9e1fc0 --- /dev/null +++ b/bindings/c/Response.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/Response.c" diff --git a/bindings/c/ResponseCodeProcessing.c b/bindings/c/ResponseCodeProcessing.c new file mode 100644 index 0000000..1de2199 --- /dev/null +++ b/bindings/c/ResponseCodeProcessing.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/ResponseCodeProcessing.c" diff --git a/bindings/c/Rewrap.c b/bindings/c/Rewrap.c new file mode 100644 index 0000000..e5b34f5 --- /dev/null +++ b/bindings/c/Rewrap.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Duplication/Rewrap.c" diff --git a/bindings/c/RsaKeyCache.c b/bindings/c/RsaKeyCache.c new file mode 100644 index 0000000..b9c1008 --- /dev/null +++ b/bindings/c/RsaKeyCache.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/RsaKeyCache.c" diff --git a/bindings/c/SecChannel.c b/bindings/c/SecChannel.c new file mode 100644 index 0000000..4f9e2f7 --- /dev/null +++ b/bindings/c/SecChannel.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/SecChannel.c" diff --git a/bindings/c/SelfTest.c b/bindings/c/SelfTest.c new file mode 100644 index 0000000..db08039 --- /dev/null +++ b/bindings/c/SelfTest.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Testing/SelfTest.c" diff --git a/bindings/c/SequenceComplete.c b/bindings/c/SequenceComplete.c new file mode 100644 index 0000000..34f6b2b --- /dev/null +++ b/bindings/c/SequenceComplete.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/HashHMAC/SequenceComplete.c" diff --git a/bindings/c/SequenceUpdate.c b/bindings/c/SequenceUpdate.c new file mode 100644 index 0000000..51406e4 --- /dev/null +++ b/bindings/c/SequenceUpdate.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/HashHMAC/SequenceUpdate.c" diff --git a/bindings/c/Session.c b/bindings/c/Session.c new file mode 100644 index 0000000..97d9487 --- /dev/null +++ b/bindings/c/Session.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/Session.c" diff --git a/bindings/c/SessionProcess.c b/bindings/c/SessionProcess.c new file mode 100644 index 0000000..d65591b --- /dev/null +++ b/bindings/c/SessionProcess.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/main/SessionProcess.c" diff --git a/bindings/c/SetAlgorithmSet.c b/bindings/c/SetAlgorithmSet.c new file mode 100644 index 0000000..92f08d5 --- /dev/null +++ b/bindings/c/SetAlgorithmSet.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Misc/SetAlgorithmSet.c" diff --git a/bindings/c/SetCapability.c b/bindings/c/SetCapability.c new file mode 100644 index 0000000..326f9eb --- /dev/null +++ b/bindings/c/SetCapability.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Capability/SetCapability.c" diff --git a/bindings/c/SetCommandCodeAuditStatus.c b/bindings/c/SetCommandCodeAuditStatus.c new file mode 100644 index 0000000..80ac8d0 --- /dev/null +++ b/bindings/c/SetCommandCodeAuditStatus.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/CommandAudit/SetCommandCodeAuditStatus.c" diff --git a/bindings/c/SetPrimaryPolicy.c b/bindings/c/SetPrimaryPolicy.c new file mode 100644 index 0000000..d9590a4 --- /dev/null +++ b/bindings/c/SetPrimaryPolicy.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Hierarchy/SetPrimaryPolicy.c" diff --git a/bindings/c/Shutdown.c b/bindings/c/Shutdown.c new file mode 100644 index 0000000..69969f2 --- /dev/null +++ b/bindings/c/Shutdown.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Startup/Shutdown.c" diff --git a/bindings/c/Sign.c b/bindings/c/Sign.c new file mode 100644 index 0000000..cfcf18c --- /dev/null +++ b/bindings/c/Sign.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Signature/Sign.c" diff --git a/bindings/c/StartAuthSession.c b/bindings/c/StartAuthSession.c new file mode 100644 index 0000000..f9b617c --- /dev/null +++ b/bindings/c/StartAuthSession.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Session/StartAuthSession.c" diff --git a/bindings/c/Startup.c b/bindings/c/Startup.c new file mode 100644 index 0000000..870aee3 --- /dev/null +++ b/bindings/c/Startup.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Startup/Startup.c" diff --git a/bindings/c/StirRandom.c b/bindings/c/StirRandom.c new file mode 100644 index 0000000..c3b3664 --- /dev/null +++ b/bindings/c/StirRandom.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Random/StirRandom.c" diff --git a/bindings/c/TPM_Hash_Data.c b/bindings/c/TPM_Hash_Data.c new file mode 100644 index 0000000..9949c28 --- /dev/null +++ b/bindings/c/TPM_Hash_Data.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/events/_TPM_Hash_Data.c" diff --git a/bindings/c/TPM_Hash_End.c b/bindings/c/TPM_Hash_End.c new file mode 100644 index 0000000..ccfbd84 --- /dev/null +++ b/bindings/c/TPM_Hash_End.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/events/_TPM_Hash_End.c" diff --git a/bindings/c/TPM_Hash_Start.c b/bindings/c/TPM_Hash_Start.c new file mode 100644 index 0000000..6cac132 --- /dev/null +++ b/bindings/c/TPM_Hash_Start.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/events/_TPM_Hash_Start.c" diff --git a/bindings/c/TPM_Init.c b/bindings/c/TPM_Init.c new file mode 100644 index 0000000..3d16fe0 --- /dev/null +++ b/bindings/c/TPM_Init.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/events/_TPM_Init.c" diff --git a/bindings/c/TableDrivenMarshal.c b/bindings/c/TableDrivenMarshal.c new file mode 100644 index 0000000..4e27af0 --- /dev/null +++ b/bindings/c/TableDrivenMarshal.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/TableDrivenMarshal.c" diff --git a/bindings/c/TableMarshalData.c b/bindings/c/TableMarshalData.c new file mode 100644 index 0000000..0a3d90f --- /dev/null +++ b/bindings/c/TableMarshalData.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/TableMarshalData.c" diff --git a/bindings/c/TestParms.c b/bindings/c/TestParms.c new file mode 100644 index 0000000..f579ff0 --- /dev/null +++ b/bindings/c/TestParms.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Capability/TestParms.c" diff --git a/bindings/c/Ticket.c b/bindings/c/Ticket.c new file mode 100644 index 0000000..a242430 --- /dev/null +++ b/bindings/c/Ticket.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/Ticket.c" diff --git a/bindings/c/Time.c b/bindings/c/Time.c new file mode 100644 index 0000000..fb85238 --- /dev/null +++ b/bindings/c/Time.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/subsystem/Time.c" diff --git a/bindings/c/TpmBigNumThunks.c b/bindings/c/TpmBigNumThunks.c new file mode 100644 index 0000000..0439aa4 --- /dev/null +++ b/bindings/c/TpmBigNumThunks.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/cryptolibs/TpmBigNum/TpmBigNumThunks.c" diff --git a/bindings/c/TpmEcc_Signature_ECDAA.c b/bindings/c/TpmEcc_Signature_ECDAA.c new file mode 100644 index 0000000..5265764 --- /dev/null +++ b/bindings/c/TpmEcc_Signature_ECDAA.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_ECDAA.c" diff --git a/bindings/c/TpmEcc_Signature_ECDSA.c b/bindings/c/TpmEcc_Signature_ECDSA.c new file mode 100644 index 0000000..a0d7a7e --- /dev/null +++ b/bindings/c/TpmEcc_Signature_ECDSA.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_ECDSA.c" diff --git a/bindings/c/TpmEcc_Signature_SM2.c b/bindings/c/TpmEcc_Signature_SM2.c new file mode 100644 index 0000000..21feddb --- /dev/null +++ b/bindings/c/TpmEcc_Signature_SM2.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_SM2.c" diff --git a/bindings/c/TpmEcc_Signature_Schnorr.c b/bindings/c/TpmEcc_Signature_Schnorr.c new file mode 100644 index 0000000..dc0d53d --- /dev/null +++ b/bindings/c/TpmEcc_Signature_Schnorr.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_Schnorr.c" diff --git a/bindings/c/TpmEcc_Signature_Util.c b/bindings/c/TpmEcc_Signature_Util.c new file mode 100644 index 0000000..596650d --- /dev/null +++ b/bindings/c/TpmEcc_Signature_Util.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/ecc/TpmEcc_Signature_Util.c" diff --git a/bindings/c/TpmEcc_Util.c b/bindings/c/TpmEcc_Util.c new file mode 100644 index 0000000..6d7754a --- /dev/null +++ b/bindings/c/TpmEcc_Util.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/ecc/TpmEcc_Util.c" diff --git a/bindings/c/TpmFail.c b/bindings/c/TpmFail.c new file mode 100644 index 0000000..92c2fac --- /dev/null +++ b/bindings/c/TpmFail.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/TpmFail.c" diff --git a/bindings/c/TpmMath_Debug.c b/bindings/c/TpmMath_Debug.c new file mode 100644 index 0000000..c511dfd --- /dev/null +++ b/bindings/c/TpmMath_Debug.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/math/TpmMath_Debug.c" diff --git a/bindings/c/TpmMath_Util.c b/bindings/c/TpmMath_Util.c new file mode 100644 index 0000000..25e6569 --- /dev/null +++ b/bindings/c/TpmMath_Util.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/crypt/math/TpmMath_Util.c" diff --git a/bindings/c/TpmSizeChecks.c b/bindings/c/TpmSizeChecks.c new file mode 100644 index 0000000..1fffd34 --- /dev/null +++ b/bindings/c/TpmSizeChecks.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/support/TpmSizeChecks.c" diff --git a/bindings/c/TpmToOsslSupport.c b/bindings/c/TpmToOsslSupport.c new file mode 100644 index 0000000..f59f761 --- /dev/null +++ b/bindings/c/TpmToOsslSupport.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/cryptolibs/Ossl/TpmToOsslSupport.c" diff --git a/bindings/c/Unseal.c b/bindings/c/Unseal.c new file mode 100644 index 0000000..747482e --- /dev/null +++ b/bindings/c/Unseal.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Object/Unseal.c" diff --git a/bindings/c/Vendor_TCG_Test.c b/bindings/c/Vendor_TCG_Test.c new file mode 100644 index 0000000..6ee1a89 --- /dev/null +++ b/bindings/c/Vendor_TCG_Test.c @@ -0,0 +1 @@ +#include "../../TPMCmd/TpmConfiguration/TpmVendorCommandHandlers/Vendor_TCG_Test.c" diff --git a/bindings/c/VerifySignature.c b/bindings/c/VerifySignature.c new file mode 100644 index 0000000..bc1bb02 --- /dev/null +++ b/bindings/c/VerifySignature.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Signature/VerifySignature.c" diff --git a/bindings/c/ZGen_2Phase.c b/bindings/c/ZGen_2Phase.c new file mode 100644 index 0000000..fd84668 --- /dev/null +++ b/bindings/c/ZGen_2Phase.c @@ -0,0 +1 @@ +#include "../../TPMCmd/tpm/src/command/Asymmetric/ZGen_2Phase.c" diff --git a/bindings/go/entrypoints/entrypoints.go b/bindings/go/entrypoints/entrypoints.go new file mode 100644 index 0000000..20722eb --- /dev/null +++ b/bindings/go/entrypoints/entrypoints.go @@ -0,0 +1,116 @@ +// Package entrypoints contains bindings to the TPM's public interface. +// +// This package provides the direct entry points to the TPM 2.0 reference code, +// including initialization, manufacturing, and executing commands. +// +// Before using these entry points, you must ensure that the [platform] package +// has been initialized by setting [platform.Current]. +// +// Typical usage involves calling [Manufacture] and [Init], and then +// using [ExecuteCommand] to send raw byte commands to the TPM. +package entrypoints + +// #cgo CFLAGS: -std=c11 -Wall -Wextra -pedantic +// +// #cgo CFLAGS: -I ../../../TPMCmd/tpm/include/ +// #cgo CFLAGS: -I ../../../TPMCmd/TpmConfiguration/ +// +// // TODO: Fix headers to not need extra #include files +// #include +// #include +// #include +import "C" + +import ( + "errors" + "iter" + "runtime" + "unsafe" + + // Depend on the internal package to force a build of the TPMCmd/tpm/ code. + _ "github.com/google/TPM/bindings/c" +) + +// Error values for [HashSequence] +var ( + ErrHashStart = errors.New("call to _TPM_Hash_Start() failed") + ErrHashData = errors.New("call to _TPM_Hash_Data() failed") + ErrHashEnd = errors.New("call to _TPM_Hash_End() failed") +) + +// Error values for [Manufacture] +var ( + ErrManufactureAlreadyDone = errors.New("manufacturing is already complete") + ErrManufactureInvalidConfig = errors.New("manufacturing failed: invalid config") + ErrManufactureNvNotReady = errors.New("manufacturing failed: NV System not available") + ErrManufactureUnknown = errors.New("manufacturing failed: unknown error") +) + +// Send a _TPM_Init indication. +func Init() { + C._TPM_Init() +} + +// Execute a command and return a response +// +// Caller must ensure that: +// +// len(cmd) <= math.MaxUint32 +func ExecuteCommand(cmd []byte) []byte { + cmdSize := C.uint32_t(len(cmd)) + cmdData := (*C.uint8_t)(unsafe.SliceData(cmd)) + + // ExecuteCommand requires the response buffer to be pre-allocated + rsp := make([]byte, C.MAX_RESPONSE_SIZE) + rspSize := C.uint32_t(len(rsp)) + rspData := (*C.uint8_t)(unsafe.SliceData(rsp)) + // Pin the rsp buffer so it isn't moved during [ExecuteCommand] + var pinner runtime.Pinner + pinner.Pin(rspData) + defer pinner.Unpin() + + C.ExecuteCommand(cmdSize, cmdData, &rspSize, &rspData) + + // If ExecuteCommand wrote to our response buffer, just slice it. + if rspData == (*C.uint8_t)(unsafe.SliceData(rsp)) { + return rsp[:rspSize] + } + // If ExecuteCommand used its own response buffer, copy it into Go memory. + return C.GoBytes(unsafe.Pointer(rspData), C.int(rspSize)) +} + +// HashSequence sends an H-CRTM indication to the TPM. +// +// [Init] must be called before this function. +func HashSequence(data iter.Seq[[]byte]) error { + if C._TPM_Hash_Start() != C.TRUE { + return ErrHashStart + } + for buf := range data { + dataSize := C.uint32_t(len(buf)) + dataPointer := (*C.uint8_t)(unsafe.SliceData(buf)) + if C._TPM_Hash_Data(dataSize, dataPointer) != C.TRUE { + return ErrHashData + } + } + if C._TPM_Hash_End() != C.TRUE { + return ErrHashEnd + } + return nil +} + +// Manufacture a TPM +func Manufacture() error { + switch C.TPM_Manufacture(1) { + case 0: + return nil + case 1: + return ErrManufactureAlreadyDone + case -1: + return ErrManufactureInvalidConfig + case -2: + return ErrManufactureNvNotReady + default: + return ErrManufactureUnknown + } +} diff --git a/bindings/go/entrypoints/entrypoints_test.go b/bindings/go/entrypoints/entrypoints_test.go new file mode 100644 index 0000000..578da3e --- /dev/null +++ b/bindings/go/entrypoints/entrypoints_test.go @@ -0,0 +1,107 @@ +package entrypoints_test + +import ( + "crypto/rand" + "encoding/binary" + "os" + "slices" + "testing" + "time" + + "github.com/google/TPM/bindings/go/entrypoints" + "github.com/google/TPM/bindings/go/platform" +) + +type mockTimer time.Time + +func (t mockTimer) Ticks() time.Duration { return time.Since(time.Time(t)) } +func (t mockTimer) WasReset() bool { return false } +func (t mockTimer) WasStopped() bool { return false } +func (t mockTimer) Adjust(a platform.Adjustment) {} + +func init() { + platform.Current = &platform.Platform{ + Entropy: rand.Reader, + Timer: mockTimer(time.Now()), + Debug: os.Stderr, + } +} + +func TestHCRTM(t *testing.T) { + entrypoints.Init() + data := [][]byte{ + {1, 2, 3}, + make([]byte, 0, 20), + {5, 5, 5, 5, 5}, + nil, + } + if err := entrypoints.HashSequence(slices.Values(data)); err != nil { + t.Errorf("HashSequence failed: %v", err) + } +} + +func TestEmptyCmd(t *testing.T) { + entrypoints.Init() + rsp := entrypoints.ExecuteCommand(nil) + if len(rsp) != 10 { + t.Errorf("Expected response of %d bytes, got %d", 10, len(rsp)) + } +} + +func TestManufacture(t *testing.T) { + if err := entrypoints.Manufacture(); err != nil { + t.Errorf("Manufacture failed with: %v", err) + } + if err := entrypoints.Manufacture(); err != nil { + t.Errorf("Remanufacture failed with: %v", err) + } +} + +func TestCommands(t *testing.T) { + // Ensure TPM is manufactured and initialized + entrypoints.Manufacture() + entrypoints.Init() + + // 1. Startup (Clear) + startupCmd := []byte{ + 0x80, 0x01, // tag: TPM_ST_NO_SESSIONS + 0x00, 0x00, 0x00, 0x0C, // size: 12 + 0x00, 0x00, 0x01, 0x44, // code: TPM_CC_Startup + 0x00, 0x00, // startupType: TPM_SU_CLEAR + } + rsp := entrypoints.ExecuteCommand(startupCmd) + t.Logf("Startup response: %x", rsp) + if len(rsp) < 10 || binary.BigEndian.Uint32(rsp[6:10]) != 0 { + t.Errorf("Startup failed: %x", rsp) + } + + // 2. GetRandom (16 bytes) + getRandomCmd := []byte{ + 0x80, 0x01, // tag: TPM_ST_NO_SESSIONS + 0x00, 0x00, 0x00, 0x0C, // size: 12 + 0x00, 0x00, 0x01, 0x7B, // code: TPM_CC_GetRandom + 0x00, 0x10, // bytesRequested: 16 + } + rsp = entrypoints.ExecuteCommand(getRandomCmd) + t.Logf("GetRandom response: %x", rsp) + if len(rsp) < 12 || binary.BigEndian.Uint32(rsp[6:10]) != 0 { + t.Errorf("GetRandom failed: %x", rsp) + } + dataSize := binary.BigEndian.Uint16(rsp[10:12]) + if dataSize != 16 || len(rsp) != 12+16 { + t.Errorf("Expected 16 bytes of random data, got %d", dataSize) + } + + // 3. Shutdown (Clear) + shutdownCmd := []byte{ + 0x80, 0x01, // tag: TPM_ST_NO_SESSIONS + 0x00, 0x00, 0x00, 0x0C, // size: 12 + 0x00, 0x00, 0x01, 0x45, // code: TPM_CC_Shutdown + 0x00, 0x00, // shutdownType: TPM_SU_CLEAR + } + rsp = entrypoints.ExecuteCommand(shutdownCmd) + t.Logf("Shutdown response: %x", rsp) + if len(rsp) < 10 || binary.BigEndian.Uint32(rsp[6:10]) != 0 { + t.Errorf("Shutdown failed: %x", rsp) + } +} diff --git a/bindings/go/platform/act.go b/bindings/go/platform/act.go new file mode 100644 index 0000000..61e06eb --- /dev/null +++ b/bindings/go/platform/act.go @@ -0,0 +1,70 @@ +package platform + +// #include +import "C" + +type ACT interface { + Initialize() + EnableTicks() + DisableTicks() + Remaining() uint32 + UpdateCounter(uint32) bool + Signaled() bool + SetSignaled(bool) +} + +//export _plat__ACT_GetImplemented +func _plat__ACT_GetImplemented(act uint32) C.int { + // We only implement TPM_RH_ACT_0 + return b2i(act == 0) +} + +//export _plat__ACT_GetRemaining +func _plat__ACT_GetRemaining(act uint32) uint32 { + if act == 0 && Current.ACT != nil { + return Current.ACT.Remaining() + } + return 0 // All ACT timeouts default to 0. +} + +//export _plat__ACT_GetSignaled +func _plat__ACT_GetSignaled(act uint32) C.int { + if act == 0 && Current.ACT != nil { + return b2i(Current.ACT.Signaled()) + } + return C.FALSE // Return FALSE to indicate no ACT has signaled. +} + +//export _plat__ACT_SetSignaled +func _plat__ACT_SetSignaled(act uint32, on C.int) { + if act == 0 && Current.ACT != nil { + Current.ACT.SetSignaled(on != 0) + } +} + +//export _plat__ACT_UpdateCounter +func _plat__ACT_UpdateCounter(act uint32, newValue uint32) C.int { + if act == 0 && Current.ACT != nil { + return b2i(Current.ACT.UpdateCounter(newValue)) + } + return C.TRUE // Pretend update is pending so TPM does not retry. +} + +//export _plat__ACT_EnableTicks +func _plat__ACT_EnableTicks(enable C.int) { + if Current.ACT != nil { + if enable != 0 { + Current.ACT.EnableTicks() + } else { + Current.ACT.DisableTicks() + } + } +} + +//export _plat__ACT_Initialize +func _plat__ACT_Initialize() C.int { + if Current.ACT != nil { + Current.ACT.Initialize() + } + return C.TRUE // Return TRUE to indicate success. +} diff --git a/bindings/go/platform/failure.go b/bindings/go/platform/failure.go new file mode 100644 index 0000000..c3c8a62 --- /dev/null +++ b/bindings/go/platform/failure.go @@ -0,0 +1,99 @@ +package platform + +// #include +// +// typedef const char cchar_t; +import "C" + +import ( + "fmt" +) + +type Failure interface { + // Fail puts the TPM into failure mode. + Fail(info FailureInfo) + // FailureInfo returns information about why a TPM entered failure mode. + // Returns nil if the TPM is not in failure mode. + FailureInfo() *FailureInfo +} + +// FailureInfo holds information about a TPM failure. +// +// *FailureInfo implements the Failure interface, acting as a simple +// container that stores the last failure. +type FailureInfo struct { + Code uint32 + Location uint64 + Line uint32 + cFuncName *C.cchar_t +} + +func (fi *FailureInfo) FunctionName() string { + return C.GoString(fi.cFuncName) +} + +func (fi *FailureInfo) Fail(info FailureInfo) { + *fi = info +} + +func (fi *FailureInfo) FailureInfo() *FailureInfo { + return fi +} + +func (p *Platform) getFailureInfo() *FailureInfo { + if p.Failure == nil { + return nil + } + return p.Failure.FailureInfo() +} + +//export _plat__Fail +func _plat__Fail(function *C.cchar_t, line C.int, locationCode C.uint64_t, failureCode C.int) { + info := FailureInfo{ + Code: uint32(failureCode), + Location: uint64(locationCode), + Line: uint32(line), + cFuncName: function, + } + if Current.Failure == nil { + panic(fmt.Sprintf("%+v", info)) + } + Current.Failure.Fail(info) +} + +//export _plat__InFailureMode +func _plat__InFailureMode() C.int { + return b2i(Current.getFailureInfo() != nil) +} + +//export _plat__GetFailureCode +func _plat__GetFailureCode() uint32 { + if info := Current.getFailureInfo(); info != nil { + return info.Code + } + return 0 +} + +//export _plat__GetFailureLocation +func _plat__GetFailureLocation() C.uint64_t { + if info := Current.getFailureInfo(); info != nil { + return C.uint64_t(info.Location) + } + return 0 +} + +//export _plat__GetFailureFunctionName +func _plat__GetFailureFunctionName() *C.cchar_t { + if info := Current.getFailureInfo(); info != nil { + return info.cFuncName + } + return nil +} + +//export _plat__GetFailureLine +func _plat__GetFailureLine() uint32 { + if info := Current.getFailureInfo(); info != nil { + return info.Line + } + return 0 +} diff --git a/bindings/go/platform/firmware.go b/bindings/go/platform/firmware.go new file mode 100644 index 0000000..592f273 --- /dev/null +++ b/bindings/go/platform/firmware.go @@ -0,0 +1,67 @@ +package platform + +// #include +import "C" + +import "unsafe" + +type Firmware struct { + Version uint64 + SVN uint16 + MaxSVN uint16 + Secret Secret + SVNSecret func(svn uint16) Secret +} + +// SECRET_LEN is the len of the target buffer passed to [Secret.Fill]. +const SECRET_LEN = C.PRIMARY_SEED_SIZE + +type Secret interface { + Fill(buf []byte) int +} + +//export _plat__GetTpmFirmwareVersionHigh +func _plat__GetTpmFirmwareVersionHigh() uint32 { + return uint32(Current.Firmware.Version >> 32) +} + +//export _plat__GetTpmFirmwareVersionLow +func _plat__GetTpmFirmwareVersionLow() uint32 { + return uint32(Current.Firmware.Version & 0xFFFFFFFF) +} + +//export _plat__GetTpmFirmwareSvn +func _plat__GetTpmFirmwareSvn() uint16 { + return Current.Firmware.SVN +} + +//export _plat__GetTpmFirmwareMaxSvn +func _plat__GetTpmFirmwareMaxSvn() uint16 { + return Current.Firmware.MaxSVN +} + +func secretFill(s Secret, bufSize uint16, buf *uint8, outSize *uint16) C.int { + if s == nil { + return -1 + } + dst := unsafe.Slice(buf, bufSize) + if bytesFilled := s.Fill(dst); bytesFilled >= 0 && bytesFilled <= len(dst) { + *outSize = uint16(bytesFilled) + return 0 + } + return -1 +} + +//export _plat__GetTpmFirmwareSecret +func _plat__GetTpmFirmwareSecret(bufSize uint16, buf *uint8, outSize *uint16) C.int { + return secretFill(Current.Firmware.Secret, bufSize, buf, outSize) +} + +//export _plat__GetTpmFirmwareSvnSecret +func _plat__GetTpmFirmwareSvnSecret(svn uint16, bufSize uint16, buf *uint8, outSize *uint16) C.int { + var secret Secret + if Current.Firmware.SVNSecret != nil { + secret = Current.Firmware.SVNSecret(svn) + } + return secretFill(secret, bufSize, buf, outSize) +} diff --git a/bindings/go/platform/pcr.go b/bindings/go/platform/pcr.go new file mode 100644 index 0000000..0cbaf24 --- /dev/null +++ b/bindings/go/platform/pcr.go @@ -0,0 +1,129 @@ +package platform + +// #include +// +// static inline void set_stateSave(PCR_Attributes* attr, int b) { attr->stateSave = b; } +// static inline void set_doNotIncrement(PCR_Attributes* attr, int b) { attr->doNotIncrementPcrCounter = b; } +// static inline void set_resetLocality(PCR_Attributes* attr, uint8_t loc) { attr->resetLocality = loc; } +// static inline void set_extendLocality(PCR_Attributes* attr, uint8_t loc) { attr->extendLocality = loc; } +import "C" + +import "unsafe" + +const NUM_PCRS = C.IMPLEMENTATION_PCR + +type PCRAttributes struct { + ShouldSave bool + DoNotIncrement bool + ResetLocality uint8 + ExtendLocality uint8 +} + +type PCRConfig interface { + Attributes(pcrNumber uint32) PCRAttributes + DefaultActive(alg uint16) bool + // InitialValue of the specified PCR, written to value. + // + // The provided []byte will always have the the correct size, so this + // method should never fail. + InitialValue(pcrNumber uint32, alg uint16, locality uint8, value []byte) +} + +func (p *Platform) getPCRConfig() PCRConfig { + if p.PCRConfig == nil { + return PCClientDefaultConfig + } + return p.PCRConfig +} + +var PCClientDefaultConfig PCRConfig = pcClientDefaultConfig{} + +type pcClientDefaultConfig struct{} + +func (c pcClientDefaultConfig) Attributes(pcrNumber uint32) PCRAttributes { + switch pcrNumber { + case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15: + return PCRAttributes{ShouldSave: true, ExtendLocality: 0x1F} + case 16: + // Note: The PC Client spec requires DoNotIncrement: true, but the reference C code uses false. + return PCRAttributes{ShouldSave: false, DoNotIncrement: false, ResetLocality: 0x0F, ExtendLocality: 0x1F} + case 17, 18: + return PCRAttributes{ShouldSave: false, DoNotIncrement: false, ResetLocality: 0x10, ExtendLocality: 0x1C} + case 19: + return PCRAttributes{ShouldSave: false, DoNotIncrement: false, ResetLocality: 0x10, ExtendLocality: 0x0C} + case 20: + // Note: The PC Client spec requires DoNotIncrement: false, but the reference C code uses true. + return PCRAttributes{ShouldSave: false, DoNotIncrement: true, ResetLocality: 0x14, ExtendLocality: 0x0E} + case 21, 22: + return PCRAttributes{ShouldSave: false, DoNotIncrement: true, ResetLocality: 0x14, ExtendLocality: 0x04} + case 23: + // Note: The PC Client spec requires DoNotIncrement: true, but the reference C code uses false. + return PCRAttributes{ShouldSave: false, DoNotIncrement: false, ResetLocality: 0x0F, ExtendLocality: 0x1F} + default: + return PCRAttributes{} + } +} + +func (c pcClientDefaultConfig) DefaultActive(alg uint16) bool { + // Default to active for SHA-1 (0x0004) and SHA-256 (0x000B) + return alg == 0x0004 || alg == 0x000B +} + +func (c pcClientDefaultConfig) InitialValue(pcrNumber uint32, alg uint16, locality uint8, buf []byte) { + defaultValue := byte(0) + attr := c.Attributes(pcrNumber) + if (attr.ResetLocality & 0x10) != 0 { + defaultValue = 0xFF + } + for i := range buf { + buf[i] = defaultValue + } + // HCRTM_PCR is 0 + if pcrNumber == 0 { + buf[len(buf)-1] = locality + } +} + +//export _platPcr__NumberOfPcrs +func _platPcr__NumberOfPcrs() uint32 { + return NUM_PCRS +} + +//export _platPcr_IsPcrBankDefaultActive +func _platPcr_IsPcrBankDefaultActive(pcrAlg C.TPM_ALG_ID) C.BOOL { + return b2i(Current.getPCRConfig().DefaultActive(uint16(pcrAlg))) +} + +//export _platPcr__GetInitialValueForPcr +func _platPcr__GetInitialValueForPcr( + pcrNumber uint32, + pcrAlg uint16, + startupLocality uint8, + pcrBuffer *uint8, + bufferSize uint16, + pcrLength *uint16, +) C.TPM_RC { + dst := unsafe.Slice((*byte)(pcrBuffer), bufferSize) + Current.getPCRConfig().InitialValue( + uint32(pcrNumber), + uint16(pcrAlg), + uint8(startupLocality), + dst, + ) + if pcrLength != nil { + *pcrLength = bufferSize + } + return 0 +} + +//export _platPcr__GetPcrInitializationAttributes +func _platPcr__GetPcrInitializationAttributes(pcrNumber uint32) C.PCR_Attributes { + a := Current.getPCRConfig().Attributes(pcrNumber) + + var attr C.PCR_Attributes + C.set_stateSave(&attr, b2i(a.ShouldSave)) + C.set_doNotIncrement(&attr, b2i(a.DoNotIncrement)) + C.set_resetLocality(&attr, C.uint8_t(a.ResetLocality)) + C.set_extendLocality(&attr, C.uint8_t(a.ExtendLocality)) + return attr +} diff --git a/bindings/go/platform/platform.go b/bindings/go/platform/platform.go new file mode 100644 index 0000000..1cb9056 --- /dev/null +++ b/bindings/go/platform/platform.go @@ -0,0 +1,96 @@ +// Package platform allows Go code to implement the TPM 2.0 Platform Interface. +// +// The TPM 2.0 reference code requires a platform implementation to handle +// non-volatile storage, entropy, timers, and system controls (like locality). +// This package exposes these requirements as Go interfaces and structs that +// can be implemented or configured by the caller. +// +// To use this package, you must create a [Platform] struct and assign it to +// [Current]. If [Current] is not set when the TPM code is run, the callbacks +// will panic. +package platform + +// #cgo CFLAGS: -std=c11 -Wall -Wextra -pedantic +// +// #cgo CFLAGS: -I ../../../TPMCmd/tpm/include/ +// #cgo CFLAGS: -I ../../../TPMCmd/TpmConfiguration/ +import "C" + +import ( + "io" + "math" + "unsafe" +) + +// Variable for the currently active platfom. This is initially nil. If it is +// still nil when the TPM code is run, certain platform functions will panic. +var Current *Platform = nil + +// Platform defines the TPM 2.0 Platform Interface specified in: +// +// tpm/include/platform_interface/tpm_to_platform_interface.h +type Platform struct { + Properties Properties // Platform properties + Firmware Firmware // Firmware interface + Entropy io.Reader // Source of randomness + Timer Timer // Monotonic timer + Storage Storage // Non-volatile storage + System System // System controls (locality, cancel) + Failure Failure // Failure mode handler + Debug io.Writer // Debug log destination + ManufactureData func(data []byte) // Callback to get platform manufacture data + SelfTestEnabled func(fullTest bool, alg uint16) bool // Callback to check if self test is enabled + PCRConfig PCRConfig // PCR configuration + ACT ACT // Authenticated Countdown Timer +} + +/*** Entropy ***/ + +//export _plat__GetEntropy +func _plat__GetEntropy(entropy *uint8, amount uint32) int32 { + if Current.Entropy == nil { + panic("_plat__GetEntropy called with Current.Entropy == nil") + } + slice := unsafe.Slice(entropy, amount) + n, err := Current.Entropy.Read(slice) + if err != nil { + // Negative return value from ReadEntropy indicates failure. + return -1 + } + return int32(min(n, math.MaxInt32)) +} + +//*** ManufactureData ***/ + +//export _plat__GetPlatformManufactureData +func _plat__GetPlatformManufactureData(buf *uint8, bufSize uint32) { + if Current.ManufactureData == nil { + return + } + data := unsafe.Slice(buf, bufSize) + Current.ManufactureData(data) +} + +/*** EnableSelfTests ***/ + +//export _plat_GetEnabledSelfTest +func _plat_GetEnabledSelfTest(fullTest uint8, pToTestVector *uint8, toTestVectorSize C.size_t) { + if Current.SelfTestEnabled == nil { + return + } + isFullTest := fullTest != 0 + + toTestBits := unsafe.Slice(pToTestVector, toTestVectorSize) + for i := 0; i < 8*len(toTestBits); i++ { + byteIdx, bitIdx := i/8, i%8 + mask := byte(1) << bitIdx + if toTestBits[byteIdx]&mask == 0 { + continue + } + + algID := uint16(i) + if !Current.SelfTestEnabled(isFullTest, algID) { + toTestBits[byteIdx] &= ^mask + } + } +} diff --git a/bindings/go/platform/print.c b/bindings/go/platform/print.c new file mode 100644 index 0000000..2cb1b71 --- /dev/null +++ b/bindings/go/platform/print.c @@ -0,0 +1,14 @@ +#include +#include + +#include + +// Implement _plat_debug_printf +void _plat_debug_printf(const char* format, ...) { + va_list args; + va_start(args, format); + char buf[1024]; + vsnprintf(buf, sizeof(buf), format, args); + va_end(args); + _plat_debug_print(buf); +} diff --git a/bindings/go/platform/print.go b/bindings/go/platform/print.go new file mode 100644 index 0000000..c149edf --- /dev/null +++ b/bindings/go/platform/print.go @@ -0,0 +1,20 @@ +package platform + +// #include +// +// typedef const char cchar_t; +import "C" + +import ( + "io" +) + +//export _plat_debug_print +func _plat_debug_print(str *C.cchar_t) { + if Current.Debug == nil { + return + } + s := C.GoString(str) + s += "\n" + io.WriteString(Current.Debug, s) +} diff --git a/bindings/go/platform/properties.go b/bindings/go/platform/properties.go new file mode 100644 index 0000000..4f33da3 --- /dev/null +++ b/bindings/go/platform/properties.go @@ -0,0 +1,55 @@ +package platform + +// #include +import "C" + +import "encoding/binary" + +type Properties struct { + VendorID uint32 + VendorString [16]byte + TPMType uint32 + TPMSpec Spec + PlatformSpec Spec +} + +type Spec struct { + Family uint32 + Level uint32 + Version uint32 + Errata uint32 // Errata was previously called DAY_OF_YEAR + Year uint32 +} + +//export _plat__GetManufacturerCapabilityCode +func _plat__GetManufacturerCapabilityCode() uint32 { + return Current.Properties.VendorID +} + +//export _plat__GetVendorCapabilityCode +func _plat__GetVendorCapabilityCode(index C.int) uint32 { + start := (index - 1) * 4 // index is ONE-BASED + chunk := Current.Properties.VendorString[start : start+4] + return binary.BigEndian.Uint32(chunk) +} + +//export _plat__GetVendorTpmType +func _plat__GetVendorTpmType() uint32 { + return Current.Properties.TPMType +} + +//export _plat_GetSpecCapabilityValue +func _plat_GetSpecCapabilityValue(returnData *C.SPEC_CAPABILITY_VALUE) { + t := &Current.Properties.TPMSpec + returnData.tpmSpecLevel = C.uint32_t(t.Level) + returnData.tpmSpecVersion = C.uint32_t(t.Version) + returnData.tpmSpecYear = C.uint32_t(t.Year) + returnData.tpmSpecDayOfYear = C.uint32_t(t.Errata) + + p := &Current.Properties.PlatformSpec + returnData.platformFamily = C.uint32_t(p.Family) + returnData.platfromLevel = C.uint32_t(p.Level) + returnData.platformRevision = C.uint32_t(p.Version) + returnData.platformYear = C.uint32_t(p.Year) + returnData.platformDayOfYear = C.uint32_t(p.Errata) +} diff --git a/bindings/go/platform/storage.go b/bindings/go/platform/storage.go new file mode 100644 index 0000000..511ae70 --- /dev/null +++ b/bindings/go/platform/storage.go @@ -0,0 +1,132 @@ +package platform + +// #include +import "C" + +import ( + "slices" + "unsafe" +) + +// Storage handles the platform's storage of non-volatile data. +// +// The [Storage.OnEnable], [Storage.OnReady], and [Storage.OnCommit] handlers +// are optional. If not provided, they default to successful operations. +type Storage struct { + // Data holds the in-memory representation of the NV data. + Data [C.NV_MEMORY_SIZE]byte + + // OnEnable loads the non-volatile data into memory. + // + // Returns 0 on success, >0 on recoverable failure, <0 on unrecoverable failure. + OnEnable func() int + + // OnReady returns the state of the non-volatile storage system. + // + // This allows handling of potential NV errors before a command runs. + OnReady func() ReadyState + + // OnCommit persists the in-memory data to non-volatile storage. + // + // Returns 0 on success, !=0 on failure. + OnCommit func() int +} + +type ReadyState int + +const ( + NvReady ReadyState = 0 + NvWriteFailure ReadyState = 1 + NvRateLimit ReadyState = 2 +) + +//export _plat__NVEnable +func _plat__NVEnable(platParameter unsafe.Pointer, paramSize C.size_t) C.int { + if Current.Storage.OnEnable != nil { + return C.int(Current.Storage.OnEnable()) + } + return 0 +} + +//export _plat__GetNvReadyState +func _plat__GetNvReadyState() C.int { + if Current.Storage.OnReady != nil { + return C.int(Current.Storage.OnReady()) + } + return C.int(NvReady) +} + +func getNvSlice(startOffset, size C.uint) []byte { + data := Current.Storage.Data[:] + if uint64(startOffset)+uint64(size) > uint64(len(data)) { + return nil + } + return data[startOffset : startOffset+size] +} + +//export _plat__NvMemoryRead +func _plat__NvMemoryRead(startOffset, size C.uint, data unsafe.Pointer) C.int { + src := getNvSlice(startOffset, size) + dst := unsafe.Slice((*byte)(data), size) + if src == nil { + return C.FALSE + } + copy(dst, src) + return C.TRUE +} + +//export _plat__NvGetChangedStatus +func _plat__NvGetChangedStatus(startOffset, size C.uint, data unsafe.Pointer) C.int { + src := getNvSlice(startOffset, size) + test := unsafe.Slice((*byte)(data), size) + if src == nil { + return C.NV_INVALID_LOCATION + } else if slices.Equal(src, test) { + return C.NV_IS_SAME + } else { + return C.NV_HAS_CHANGED + } +} + +//export _plat__NvMemoryWrite +func _plat__NvMemoryWrite(startOffset, size C.uint, data unsafe.Pointer) C.int { + src := unsafe.Slice((*byte)(data), size) + dst := getNvSlice(startOffset, size) + if dst == nil { + return C.FALSE + } + copy(dst, src) + return C.TRUE +} + +//export _plat__NvMemoryClear +func _plat__NvMemoryClear(startOffset, size C.uint) C.int { + dst := getNvSlice(startOffset, size) + if dst == nil { + return C.FALSE + } + // Fill with 0xFF bytes as that's what the reference code does. + for i := range dst { + dst[i] = 0xFF + } + return C.TRUE +} + +//export _plat__NvMemoryMove +func _plat__NvMemoryMove(srcOffset, dstOffset C.uint, size C.uint) C.int { + src := getNvSlice(srcOffset, size) + dst := getNvSlice(dstOffset, size) + if src == nil || dst == nil { + return C.FALSE + } + copy(dst, src) + return C.TRUE +} + +//export _plat__NvCommit +func _plat__NvCommit() C.int { + if Current.Storage.OnCommit != nil { + return C.int(Current.Storage.OnCommit()) + } + return 0 +} diff --git a/bindings/go/platform/system.go b/bindings/go/platform/system.go new file mode 100644 index 0000000..b0d73d3 --- /dev/null +++ b/bindings/go/platform/system.go @@ -0,0 +1,74 @@ +package platform + +// #include +import "C" + +type System interface { + // Locality returns the locality (0-4 or 32-255) of the current command. + Locality() uint8 + // Canceled returns true if the current command should be canceled. + Canceled() bool + // PhysicalPresence returns true if Physical Presense is asserted. + PhysicalPresence() bool + // StartInit is called when a _TPM_Init indication starts. + StartInit() + // EndOkInit is called when a _TPM_Init indication completes successfully. + EndOkInit() + // TearDown is called when the TPM is being prepared for re-manufacture. + TearDown() +} + +// b2i converts a Go bool to a C int +func b2i(b bool) C.int { + if b { + return 1 + } + return 0 +} + +//export _plat__LocalityGet +func _plat__LocalityGet() uint8 { + if Current.System != nil { + return Current.System.Locality() + } + return 0 // Default locality is 0. +} + +//export _plat__IsCanceled +func _plat__IsCanceled() C.int { + // By default, no commands are cancelled + return b2i(Current.System != nil && Current.System.Canceled()) +} + +//export _plat__WasPowerLost +func _plat__WasPowerLost() C.int { + // We just always assume power was lost if we are calling Init again. + return C.TRUE +} + +//export _plat__PhysicalPresenceAsserted +func _plat__PhysicalPresenceAsserted() C.int { + // By default, physical presence is not asserted + return b2i(Current.System != nil && Current.System.PhysicalPresence()) +} + +//export _plat__StartTpmInit +func _plat__StartTpmInit() { + if Current.System != nil { + Current.System.StartInit() + } +} + +//export _plat__EndOkTpmInit +func _plat__EndOkTpmInit() { + if Current.System != nil { + Current.System.EndOkInit() + } +} + +//export _plat__TearDown +func _plat__TearDown() { + if Current.System != nil { + Current.System.TearDown() + } +} diff --git a/bindings/go/platform/timer.go b/bindings/go/platform/timer.go new file mode 100644 index 0000000..ff508cf --- /dev/null +++ b/bindings/go/platform/timer.go @@ -0,0 +1,69 @@ +package platform + +// #include +import "C" + +import ( + "time" +) + +type Timer interface { + // Ticks returns the monotonic duration since power-on. + Ticks() time.Duration + + // WasReset returns true if the timer was reset since the last call. + // Calling this must clear the internal "reset" state. + WasReset() bool + + // WasStopped returns true if the timer was stopped since the last call. + // Calling this must clear the internal "stopped" state. + WasStopped() bool + + // Adjust changes the rate of the timer. + Adjust(a Adjustment) +} + +// Adjustment is the amount to change the tick timer's rate. Its values +// correspond to the TPM_CLOCK_ADJUST constants. +type Adjustment int + +const ( + AdjustCoarseSlower Adjustment = -3 + AdjustMediumSlower Adjustment = -2 + AdjustFineSlower Adjustment = -1 + AdjustFineFaster Adjustment = 1 + AdjustMediumFaster Adjustment = 2 + AdjustCoarseFaster Adjustment = 3 +) + +//export _plat__TimerRead +func _plat__TimerRead() C.uint64_t { + if Current.Timer == nil { + panic("_plat__TimerRead called with Current.Timer == nil") + } + return C.uint64_t(Current.Timer.Ticks().Milliseconds()) +} + +//export _plat__TimerWasReset +func _plat__TimerWasReset() C.int { + if Current.Timer == nil { + panic("_plat__TimerWasReset called with Current.Timer == nil") + } + return b2i(Current.Timer.WasReset()) +} + +//export _plat__TimerWasStopped +func _plat__TimerWasStopped() C.int { + if Current.Timer == nil { + panic("_plat__TimerWasStopped called with Current.Timer == nil") + } + return b2i(Current.Timer.WasStopped()) +} + +//export _plat__ClockRateAdjust +func _plat__ClockRateAdjust(adjustment C._plat__ClockAdjustStep) { + if Current.Timer == nil { + panic("_plat__ClockRateAdjust called with Current.Timer == nil") + } + Current.Timer.Adjust(Adjustment(adjustment)) +} diff --git a/bindings/go/platform/virtual.go b/bindings/go/platform/virtual.go new file mode 100644 index 0000000..48c22e5 --- /dev/null +++ b/bindings/go/platform/virtual.go @@ -0,0 +1,40 @@ +package platform + +// #include +import "C" + +/*** Virtual NV Stubs (always return TPM_RC_NO_RESULT / NO / FALSE) ***/ + +//export _plat__NvVirtual_PopulateNvIndexInfo +func _plat__NvVirtual_PopulateNvIndexInfo(handle C.TPM_HANDLE, publicArea *C.TPMS_NV_PUBLIC, authValue *C.TPM2B_AUTH) C.TPM_RC { + _, _, _ = handle, publicArea, authValue + return C.TPM_RC_NO_RESULT +} + +//export _plat__NvVirtual_Read +func _plat__NvVirtual_Read(dataIn *C.NV_Read_In, dataOut *C.NV_Read_Out) C.TPM_RC { + _, _ = dataIn, dataOut + return C.TPM_RC_NO_RESULT +} + +//export _plat__NvVirtual_ReadPublic +func _plat__NvVirtual_ReadPublic(dataIn *C.NV_ReadPublic_In, dataOut *C.NV_ReadPublic_Out) C.TPM_RC { + _, _ = dataIn, dataOut + return C.TPM_RC_NO_RESULT +} + +//export _plat__NvVirtual_CapGetIndex +func _plat__NvVirtual_CapGetIndex(handle C.TPMI_DH_OBJECT, count uint32, handleList *C.TPML_HANDLE) C.TPMI_YES_NO { + _, _, _ = handle, count, handleList + return C.NO +} + +//export _plat__NvOperationAcceptsVirtualHandles +func _plat__NvOperationAcceptsVirtualHandles(_ C.TPM_CC) C.BOOL { + return C.FALSE +} + +//export _plat__IsNvVirtualIndex +func _plat__IsNvVirtualIndex(_ C.TPM_HANDLE) C.BOOL { + return C.FALSE +} diff --git a/bindings/regenerate_c.py b/bindings/regenerate_c.py new file mode 100755 index 0000000..7f89538 --- /dev/null +++ b/bindings/regenerate_c.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +from pathlib import Path +import itertools + + +def main(): + script_dir = Path(__file__).parent + repo_dir = script_dir.parent + dst_dir = script_dir / "c" + assert dst_dir.exists(), f"{dst_dir} missing" + + # Delete all the old C files + for f in dst_dir.glob("*.c"): + f.unlink() + + links = {} + for src in itertools.chain( + repo_dir.glob("TPMCmd/tpm/src/**/*.c"), + repo_dir.glob("TPMCmd/tpm/cryptolibs/Ossl/**/*.c"), + repo_dir.glob("TPMCmd/tpm/cryptolibs/TpmBigNum/**/*.c"), + repo_dir.glob("TPMCmd/TpmConfiguration/**/*.c"), + ): + # Trim any leading underscores to stop CGO from ignoring the file. + dst = dst_dir / src.name.lstrip("_") + assert dst not in links, f"Name collision: {links[dst]} and {src}" + + links[dst] = src + with open(dst, "w") as f: + f.write(f'#include "../../{src.relative_to(repo_dir)}"\n') + + print(f"Created {len(links)} wrapper C files in {dst_dir}") + + +if __name__ == "__main__": + main() diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..01103d9 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/google/TPM + +go 1.24