func PcrRead() error {
	if *pcrCommandReadIndex >= MaxPlatformConfigurationRegister || *pcrCommandReadIndex < 0 {
		return errors.New("PCR index is incorrect")
	}
	pcr, err := TPMInterface.ReadPCR(*pcrCommandReadIndex)
	if err != nil {
		return err
	}
	fmt.Printf("PCR-%02d: %x\n", *pcrCommandReadIndex, pcr)
	return nil
}
PcrRead reads the value of a PCR
package main
import (
	"crypto/rand"
	"crypto/sha256"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"path"
	"syscall"
	"time"
	"github.com/9elements/tpmtool/pkg/tpm"
	"github.com/9elements/tpmtool/pkg/tpmtool"
	"github.com/u-root/u-root/pkg/storage"
)
const (
	MaxPlatformConfigurationRegister = 24
	DefaultFilePermissions = 660
	LinuxEFIFirmwareDir = "/sys/firmware/efi"
	Delay = 900
)
func Status() error {
	summary := TPMInterface.Summary()
	fmt.Print(summary)
	if TPMInterface.Info().TemporarilyDeactivated {
		fmt.Println("\nError: Check your BIOS! TPM is temporary deactivated.")
	}
	if (!TPMInterface.Info().Active || !TPMInterface.Info().Enabled) && !TPMInterface.Info().TemporarilyDeactivated {
		fmt.Println("\nError: TPM is inactive or disabled! Check your BIOS physical presence settings.")
	}
	if !TPMInterface.Info().Owned {
		fmt.Println("\nError: TPM is not owned! Please take ownership of the TPM.")
	}
	return nil
}
func Ek() error {
	var pubEk []byte
	pubEk, err := TPMInterface.ReadPubEK(*ekCommandPassword)
	if err != nil {
		return err
	}
	if *ekCommandOutfile != "" {
		if err := ioutil.WriteFile(*ekCommandOutfile, pubEk, 660); err != nil {
			return err
		}
	}
	fingerprint := sha256.Sum256(pubEk)
	fmt.Printf("EK Pubkey fingerprint: 0x%x\n", fingerprint)
	return nil
}
func OwnerTake() error {
	err := TPMInterface.TakeOwnership(*ownerCommandPassword, *ownerCommandTakeSrkPassword)
	if err != nil {
		return err
	}
	return nil
}
func OwnerClear() error {
	err := TPMInterface.ClearOwnership(*ownerCommandPassword)
	if err != nil {
		return err
	}
	return nil
}
func OwnerResetLock() error {
	err := TPMInterface.ResetLock(*ownerCommandPassword)
	if err != nil {
		return err
	}
	return nil
}
func CryptoSeal() error {
	time.Sleep(Delay * time.Millisecond)
	plainText, err := ioutil.ReadFile(*cryptoCommandSealPlainFile)
	if err != nil {
		return err
	}
	if TPMSpecVersion == tpm.TPM12 && len(plainText) > tpm.TPM12MaxKeySize {
		return errors.New("Plain text file is too big, max 256 bytes")
	}
	pcrInfo, err := tpmtool.PreCalculate(TPMInterface, *cryptoCommandSealConfig)
	if err != nil {
		return err
	}
	sealed, err := TPMInterface.ResealData(*cryptoCommandSealLocality, pcrInfo, plainText, *cryptoCommandSrkPassword)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(*cryptoCommandSealCipherFile, sealed, 660)
}
func CryptoUnseal() error {
	time.Sleep(Delay * time.Millisecond)
	cipherText, err := ioutil.ReadFile(*cryptoCommandUnsealCipherFile)
	if err != nil {
		return err
	}
	unsealed, err := TPMInterface.UnsealData(cipherText, *cryptoCommandSrkPassword)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(*cryptoCommandUnsealPlainFile, unsealed, 660)
}
func CryptoReseal() error {
	time.Sleep(Delay * time.Millisecond)
	sealedFile, err := ioutil.ReadFile(*cryptoCommandResealKeyfile)
	if err != nil {
		return err
	}
	pcrInfo, err := tpmtool.PreCalculate(TPMInterface, *cryptoCommandResealConfig)
	if err != nil {
		return err
	}
	unsealed, err := TPMInterface.UnsealData(sealedFile, *diskCommandSrkPassword)
	if err != nil {
		return err
	}
	sealed, err := TPMInterface.ResealData(tpm.DefaultLocality, pcrInfo, unsealed, *cryptoCommandSrkPassword)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(*cryptoCommandResealKeyfile, sealed, 660)
}
func PcrList() error {
	var pcrs string
	for i := uint32(0); i < MaxPlatformConfigurationRegister; i++ {
		hash, err := TPMInterface.ReadPCR(i)
		if err != nil {
			return err
		}
		pcrs += fmt.Sprintf("PCR-%02d: %x\n", i, hash)
	}
	fmt.Print(pcrs)
	return nil
}