Skip to content

Commit

Permalink
Update Vendored simulator source (#43)
Browse files Browse the repository at this point in the history
* Update vendored simulator source

* Update include list to work with new simulator source

* Make simulator work with new internal interface

* Readd test change from #39
  • Loading branch information
josephlr authored Sep 10, 2019
1 parent aaaef0f commit 382dab3
Show file tree
Hide file tree
Showing 374 changed files with 1,326 additions and 253,752 deletions.
27 changes: 8 additions & 19 deletions simulator/internal/include.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
// as the Go code. Thus to allow us to use the Mircosoft code as a submodule, we
// have to textually include all of the sources into this file.

// Most of the sources can be included in any order. However, this file has to
// be included first as it instantiates all of the libraries global variables.
#include "support/Global.c"
#define _CRYPT_HASH_C_
#define _X509_SPT_

// libplatform sources
#include "Cancel.c"
// Google sources
#include "Clock.c"
#include "DebugHelpers.c"
#include "Entropy.c"
#include "LocalityPlat.c"
#include "NVMem.c"
#include "PPPlat.c"
#include "PlatformData.c"
#include "PowerPlat.c"
#include "RunCommand.c"
#include "Unique.c"
#include "Run.c"

// Most of the sources can be included in any order. However, this file has to
// be included first as it instantiates all of the libraries global variables.
#include "support/Global.c"

// libtpm sources
#include "X509/TpmASN1.c"
#include "X509/X509_ECC.c"
#include "X509/X509_RSA.c"
Expand Down Expand Up @@ -173,15 +168,9 @@
#include "crypt/PrimeData.c"
#include "crypt/RsaKeyCache.c"
#include "crypt/Ticket.c"
#include "crypt/ltc/TpmToLtcDesSupport.c"
#include "crypt/ltc/TpmToLtcMath.c"
#include "crypt/ltc/TpmToLtcSupport.c"
#include "crypt/ossl/TpmToOsslDesSupport.c"
#include "crypt/ossl/TpmToOsslMath.c"
#include "crypt/ossl/TpmToOsslSupport.c"
#include "crypt/wolf/TpmToWolfDesSupport.c"
#include "crypt/wolf/TpmToWolfMath.c"
#include "crypt/wolf/TpmToWolfSupport.c"
#include "events/_TPM_Hash_Data.c"
#include "events/_TPM_Hash_End.c"
#include "events/_TPM_Hash_Start.c"
Expand Down
41 changes: 13 additions & 28 deletions simulator/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
package internal

// // Directories containing .h files in the simulator source
// #cgo CFLAGS: -I ../ms-tpm-20-ref/TPMCmd/Platform/include
// #cgo CFLAGS: -I ../ms-tpm-20-ref/TPMCmd/Platform/include/prototypes
// #cgo CFLAGS: -I ../ms-tpm-20-ref/Samples/Google
// #cgo CFLAGS: -I ../ms-tpm-20-ref/TPMCmd/tpm/include
// #cgo CFLAGS: -I ../ms-tpm-20-ref/TPMCmd/tpm/include/prototypes
// // Allows simulator.c to import files without repeating the source repo path.
// #cgo CFLAGS: -I ../ms-tpm-20-ref/TPMCmd/Platform/src
// #cgo CFLAGS: -I ../ms-tpm-20-ref/Samples/Google
// #cgo CFLAGS: -I ../ms-tpm-20-ref/TPMCmd/tpm/src
// // Store NVDATA in memory, and we don't care about updates to failedTries.
// #cgo CFLAGS: -DVTPM=NO -DSIMULATION=NO -DUSE_DA_USED=NO
Expand All @@ -32,10 +31,16 @@ package internal
// // Silence known warnings from the reference code and CGO code.
// #cgo CFLAGS: -Wno-missing-braces -Wno-empty-body -Wno-unused-variable
// // Link against the system OpenSSL
// #cgo CFLAGS: -DHASH_LIB=Ossl -DSYM_LIB=Ossl -DMATH_LIB=Ossl
// #cgo CFLAGS: -DDEBUG=YES
// #cgo CFLAGS: -DSIMULATION=NO
// #cgo CFLAGS: -DCOMPILER_CHECKS=DEBUG
// #cgo CFLAGS: -DRUNTIME_SIZE_CHECKS=DEBUG
// #cgo CFLAGS: -DUSE_DA_USED=NO
// #cgo CFLAGS: -DCERTIFYX509_DEBUG=NO
// #cgo LDFLAGS: -lcrypto
//
// #include <stdlib.h>
// #include "Platform.h"
// #include "Tpm.h"
//
// void sync_seeds() {
Expand All @@ -46,7 +51,6 @@ package internal
import "C"
import (
"errors"
"fmt"
"io"
"unsafe"
)
Expand All @@ -59,29 +63,10 @@ func SetSeeds(r io.Reader) {
r.Read(C.gp.PPSeed[2:])
}

// On starts the simulator. Does not call TPM2_Startup
func On() {
// Setup the simulator to receive commands
C._plat__Signal_PowerOn()
C._plat__Signal_Reset()
C._plat__SetNvAvail()
C._plat__Signal_PhysicalPresenceOn()
}

// Off stops the simulator. Does not call TPM2_Shutdown
func Off() {
C._plat__Signal_PhysicalPresenceOff()
C._plat__ClearNvAvail()
C._plat__Signal_PowerOff()
}

// ManufactureReset resets the TPM to its initial factory state.
func ManufactureReset() error {
rc := C.TPM_Manufacture(1)
if rc != C.TPM_RC_SUCCESS {
return fmt.Errorf("manufacture reset failed: code %x", rc)
}
return nil
// Reset simulates toggling the power the the TPM. If forceManufacture is true,
// the reset will be a manufacturer reset.
func Reset(forceManufacture bool) {
C._plat__Reset(C.bool(forceManufacture))
}

// RunCommand passes cmd to the simulator and returns the simulator's response.
Expand Down
101 changes: 0 additions & 101 deletions simulator/ms-tpm-20-ref/Samples/ARM32-FirmwareTPM/README.md

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 382dab3

Please sign in to comment.