diff options
Diffstat (limited to 'Core/EM/TCG2/TisLib')
-rw-r--r-- | Core/EM/TCG2/TisLib/INTTcgAcpi.h | 114 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TcgCommon.c | 808 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TcgCommon.h | 305 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TcgEFI12.h | 186 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TcgEfiTpm.h | 220 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TcgPc.h | 311 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TcgTpm12.h | 1973 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TcmPc.h | 153 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TisLib.cif | 23 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TisLib.mak | 116 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TisLib.sdl | 46 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TpmLib.c | 614 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/TpmLib.h | 136 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/ZTEICTcmOrdinals.h | 203 | ||||
-rw-r--r-- | Core/EM/TCG2/TisLib/sha.h | 122 |
15 files changed, 5330 insertions, 0 deletions
diff --git a/Core/EM/TCG2/TisLib/INTTcgAcpi.h b/Core/EM/TCG2/TisLib/INTTcgAcpi.h new file mode 100644 index 0000000..6ebcdc2 --- /dev/null +++ b/Core/EM/TCG2/TisLib/INTTcgAcpi.h @@ -0,0 +1,114 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/INTTcgAcpi.h 1 4/21/14 2:15p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:15p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/INTTcgAcpi.h $ +// +// 1 4/21/14 2:15p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 2 5/19/10 5:24p Fredericko +// Included File Header +// Included File Revision History +// Code Beautification +// EIP 37653 +// +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: INTTcgAcpi.h +// +// Description: Acpi definitions for TCG module +// +//<AMI_FHDR_END> +//************************************************************************* +#ifndef _TCG_ACPI_3_0_H_ +#define _TCG_ACPI_3_0_H_ + + +#define EFI_ACPI_30_TABLE_GUID EFI_ACPI_20_TABLE_GUID + +extern EFI_GUID gEfiAcpiTableGuid; +extern EFI_GUID gEfiAcpi20TableGuid; +extern EFI_GUID gEfiAcpi30TableGuid; + + +#pragma pack(1) + +typedef struct +{ + UINT32 Signature; + UINT32 Length; + UINT8 Revision; + UINT8 Checksum; + UINT8 OemId[6]; + UINT64 OemTableId; + UINT32 OemRevision; + UINT32 CreatorId; + UINT32 CreatorRevision; +} EFI_ACPI_DESCRIPTION_HEADER; + + +// +// "TCPA" Trusted Computing Platform Alliance Capabilities Table +// +#define\ + EFI_ACPI_3_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE \ + 0x41504354 + + +#pragma pack() + +#endif +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* diff --git a/Core/EM/TCG2/TisLib/TcgCommon.c b/Core/EM/TCG2/TisLib/TcgCommon.c new file mode 100644 index 0000000..922514a --- /dev/null +++ b/Core/EM/TCG2/TisLib/TcgCommon.c @@ -0,0 +1,808 @@ +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgCommon.c 1 4/21/14 2:14p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:14p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgCommon.c $ +// +// 1 4/21/14 2:14p Fredericko +// +// 3 3/17/14 3:04p Fredericko +// +// 2 3/11/14 6:00p Fredericko +// [TAG] EIP151925 +// [Category] New Feature +// [Description] Changes for TcgGeneric Regression Testing +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 2 10/03/13 12:34p Fredericko +// Sha256 support policy update +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 9 3/19/12 6:13p Fredericko +// +// 8 3/29/11 12:24p Fredericko +// +// 7 3/28/11 12:12p Fredericko +// [TAG] EIP 54642 +// [Category] Improvement +// [Description] 1. Checkin Files related to TCG function override +// 2. Include TCM and TPM auto detection +// [Files] Affects all TCG files +// +// 6 5/19/10 5:07p Fredericko +// Included File Header +// Included File Revision History +// Include \Updated AMI Function Headers +// Code Beautification +// EIP 37653 +// +//************************************************************************* +/*++ + + Copyright (c) 2005 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + + Module Name: + + TcgCommon.c + + Abstract: + + TCG Commands implemented for both PEI and DXE + + --*/ +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TcgCommon.c +// +// Description: +// common TCG functions can be found here +// +//<AMI_FHDR_END> +//************************************************************************* +#include "TcgCommon.h" +#include <AmiDxeLib.h> +#include "token.h" +#include "Sha.h" + +#define TCG_EFI_HOB_LIST_GUID \ + { 0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} + +#pragma pack (1) +typedef struct _TCG_PCR_EVENT_HDR2 { + TCG_PCRINDEX PCRIndex; + TCG_EVENTTYPE EventType; +} TCG_PCR_EVENT_HDR2; +#pragma pack() + +UINT16 +__stdcall TcgCommonH2NS( + IN UINT16 Val ) +{ + return TPM_H2NS( Val ); +} + +UINT32 +__stdcall TcgCommonH2NL( + IN UINT32 Val ) +{ + return TPM_H2NL( Val ); +} + + + +VOID +__stdcall TcgCommonCopyMem( + IN VOID *CallbackContext, + OUT VOID *Dest, + IN VOID *Src, + IN UINTN Size ) +{ + CHAR8 *Destination8; + CHAR8 *Source8; + + if ( Src < Dest ) + { + Destination8 = (CHAR8*) Dest + Size - 1; + Source8 = (CHAR8*) Src + Size - 1; + while ( Size-- ) + { + *(Destination8--) = *(Source8--); + } + } + else { + Destination8 = (CHAR8*) Dest; + Source8 = (CHAR8*) Src; + while ( Size-- ) + { + *(Destination8++) = *(Source8++); + } + } +} + + +#pragma optimize("",off) +UINTN FindNextLogLocation(TCG_PCR_EVENT_HDR *TcgLog, UINTN EventNum) +{ + TCG_PCR_EVENT_HDR2 *TcgLogNext = (TCG_PCR_EVENT_HDR2 *)TcgLog; + UINTN NextLoc =0; + UINT32 EventSize=0; + UINTN i=0; + + if(EventNum == 0) return ((UINTN) TcgLogNext); + //return the location of the next log + for(i=0;i<EventNum;i++){ + if(TcgLogNext == NULL)break; + if(TcgLogNext->PCRIndex > 24 || TcgLogNext->PCRIndex < 0) + break; + + EventSize = *(UINT32 *)(((UINTN)TcgLogNext) + TPM_SHA1_160_HASH_LEN + sizeof(TCG_PCR_EVENT_HDR2)); + NextLoc = (UINTN)(((UINTN)TcgLogNext)+ EventSize + sizeof(EventSize)+\ + + TPM_SHA1_160_HASH_LEN + sizeof(TCG_PCR_EVENT_HDR2)); + + TcgLogNext = (TCG_PCR_EVENT_HDR2 *)NextLoc; + } + return ((UINTN) TcgLogNext); +} +#pragma optimize("",on) + + +EFI_STATUS +__stdcall TcgCommonLogEvent( + IN VOID *CallbackContext, + IN TCG_PCR_EVENT *EvtLog, + IN OUT UINT32 *TableSize, + IN UINT32 MaxSize, + IN TCG_PCR_EVENT *NewEntry, + IN UINT8 HashAlgorithm ) +{ + UINT32 TempSize; + + TempSize = sizeof(TCG_PCR_EVENT)-sizeof(NewEntry->Digest) - sizeof(UINT32)-1; + TcgCommonCopyMem( CallbackContext, EvtLog, NewEntry, TempSize ); + + if(HashAlgorithm == 0){ + TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), (UINT8 *)&NewEntry->Digest.digest, sizeof(NewEntry->Digest.digest) ); + TempSize+=sizeof(NewEntry->Digest.digest); + TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), (UINT8 *)&NewEntry->EventSize, sizeof(UINT32)); + TempSize+=sizeof(UINT32); + TcgCommonCopyMem( CallbackContext, (((UINT8 *)EvtLog) + TempSize), NewEntry->Event, NewEntry->EventSize); + } + *TableSize += (TempSize + NewEntry->EventSize); + return EFI_SUCCESS; +} + + + +EFI_STATUS +__stdcall TcmCommonLogEvent( + IN VOID *CallbackContext, + IN TCM_PCR_EVENT *EvtLog, + IN OUT UINT32 *TableSize, + IN UINT32 MaxSize, + IN TCM_PCR_EVENT *NewEntry ) +{ + UINT32 EvtSize; + + EvtSize = NewEntry->EventSize + sizeof (*NewEntry) - 1; + + if ( *TableSize + EvtSize > MaxSize ) + { + return EFI_OUT_OF_RESOURCES; + } + + EvtLog = (TCM_PCR_EVENT*)((UINT8*)EvtLog + *TableSize); + TcgCommonCopyMem( CallbackContext, EvtLog, NewEntry, EvtSize ); + + *TableSize += EvtSize; + return EFI_SUCCESS; +} + + + +EFI_STATUS +__stdcall TcgCommonSha1Start( + IN VOID *CallbackContext, + IN TCG_ALGORITHM_ID AlgId, + OUT UINT32 *MaxBytes ) +{ + EFI_STATUS Status; + TPM_1_2_CMD_HEADER cmdSHA1Start = { + TPM_H2NS( TPM_TAG_RQU_COMMAND ), + TPM_H2NL( sizeof (TPM_1_2_CMD_HEADER)), + TPM_H2NL( TPM_ORD_SHA1Start ) + }; + TPM_1_2_RET_SHA1START retSHA1Start; + TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1]; + + if ( AlgId != TCG_ALG_SHA ) + { + return EFI_UNSUPPORTED; + } + + if(AutoSupportType()){ + cmdSHA1Start.Ordinal = TPM_H2NL(TCM_ORD_SHA1Start); + } + + + InBuffer[0].Buffer = &cmdSHA1Start; + InBuffer[0].Size = sizeof (cmdSHA1Start); + OutBuffer[0].Buffer = &retSHA1Start; + OutBuffer[0].Size = sizeof (retSHA1Start); + Status = TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer ); + + if ( EFI_ERROR( Status ) || retSHA1Start.Header.RetCode != 0 ) + { + return Status; + } + + if ( MaxBytes != NULL ) + { + *MaxBytes = TcgCommonN2HL( retSHA1Start.MaxBytes ); + } + return EFI_SUCCESS; +} + + + +EFI_STATUS +__stdcall TcgCommonSha1Update( + IN VOID *CallbackContext, + IN VOID *Data, + IN UINT32 DataLen, + IN UINT32 MaxBytes ) +{ + EFI_STATUS Status; + TPM_1_2_CMD_SHA1UPDATE cmdSHA1Update; + TPM_1_2_RET_HEADER retSHA1Update; + TPM_TRANSMIT_BUFFER InBuffer[2], OutBuffer[1]; + UINT8 *DataPtr; + + if ( DataLen < 64 ) + { + return EFI_SUCCESS; + } + + cmdSHA1Update.Header.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND ); + cmdSHA1Update.Header.Ordinal = TPM_H2NL( TPM_ORD_SHA1Update ); + + if(AutoSupportType()){ + cmdSHA1Update.Header.Ordinal = TPM_H2NL(TCM_ORD_SHA1Update); + } + + InBuffer[0].Buffer = &cmdSHA1Update; + InBuffer[0].Size = sizeof (cmdSHA1Update); + OutBuffer[0].Buffer = &retSHA1Update; + OutBuffer[0].Size = sizeof (retSHA1Update); + + DataPtr = (UINT8*)Data; + + do + { + InBuffer[1].Buffer = DataPtr; + InBuffer[1].Size = DataLen < MaxBytes ? DataLen : MaxBytes; + + cmdSHA1Update.NumBytes = TcgCommonH2NL((UINT32)InBuffer[1].Size ); + cmdSHA1Update.Header.ParamSize = TcgCommonH2NL( + (UINT32)InBuffer[1].Size + sizeof (cmdSHA1Update) + ); + + DataPtr += InBuffer[1].Size; + DataLen -= (UINT32)InBuffer[1].Size; + + Status = TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer ); + } while ( !EFI_ERROR( Status ) && DataLen >= 64 ); + + return Status; +} + + + +EFI_STATUS +__stdcall TcgCommonSha1CompleteExtend( + IN VOID *CallbackContext, + IN VOID *Data, + IN UINT32 DataLen, + IN TPM_PCRINDEX PCRIndex, + OUT TCG_DIGEST *Digest, + OUT TCG_DIGEST *NewPCRValue ) +{ + TPM_1_2_CMD_SHA1COMPLETEEXTEND cmdSHA1Complete; + TPM_1_2_RET_HEADER retSHA1Complete; + TPM_TRANSMIT_BUFFER InBuffer[2], OutBuffer[3]; + + if ( DataLen >= 64 ) + { + return EFI_INVALID_PARAMETER; + } + + cmdSHA1Complete.Header.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND ); + cmdSHA1Complete.Header.ParamSize = TcgCommonH2NL(sizeof(cmdSHA1Complete) + + DataLen); + cmdSHA1Complete.Header.Ordinal = TPM_H2NL( TPM_ORD_SHA1CompleteExtend ); + + if(AutoSupportType()){ + cmdSHA1Complete.Header.Ordinal = TPM_H2NL(TCM_ORD_SHA1CompleteExtend); + } + + cmdSHA1Complete.PCRIndex = TcgCommonH2NL( PCRIndex ); + cmdSHA1Complete.NumBytes = TcgCommonH2NL( DataLen ); + + InBuffer[0].Buffer = &cmdSHA1Complete; + InBuffer[0].Size = sizeof (cmdSHA1Complete); + InBuffer[1].Buffer = Data; + InBuffer[1].Size = DataLen; + + OutBuffer[0].Buffer = &retSHA1Complete; + OutBuffer[0].Size = sizeof (retSHA1Complete); + OutBuffer[1].Buffer = Digest; + OutBuffer[1].Size = sizeof (*Digest); + OutBuffer[2].Buffer = NewPCRValue; + OutBuffer[2].Size = sizeof (*NewPCRValue); + + return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer ); +} + + +EFI_STATUS +__stdcall TcmCommonSha1CompleteExtend( + IN VOID *CallbackContext, + IN VOID *Data, + IN UINT32 DataLen, + IN TPM_PCRINDEX PCRIndex, + OUT TCM_DIGEST *Digest, + OUT TCM_DIGEST *NewPCRValue ) +{ + TPM_1_2_CMD_SHA1COMPLETEEXTEND cmdSHA1Complete; + TPM_1_2_RET_HEADER retSHA1Complete; + TPM_TRANSMIT_BUFFER InBuffer[2], OutBuffer[3]; + + if ( DataLen >= 64 ) + { + return EFI_INVALID_PARAMETER; + } + + cmdSHA1Complete.Header.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND ); + cmdSHA1Complete.Header.ParamSize = TcgCommonH2NL(sizeof(cmdSHA1Complete) + + DataLen); + cmdSHA1Complete.Header.Ordinal = TPM_H2NL( TPM_ORD_SHA1CompleteExtend ); + + if(AutoSupportType()){ + cmdSHA1Complete.Header.Ordinal = TPM_H2NL(TCM_ORD_SHA1CompleteExtend); + } + + cmdSHA1Complete.PCRIndex = TcgCommonH2NL( PCRIndex ); + cmdSHA1Complete.NumBytes = TcgCommonH2NL( DataLen ); + + InBuffer[0].Buffer = &cmdSHA1Complete; + InBuffer[0].Size = sizeof (cmdSHA1Complete); + InBuffer[1].Buffer = Data; + InBuffer[1].Size = DataLen; + + OutBuffer[0].Buffer = &retSHA1Complete; + OutBuffer[0].Size = sizeof (retSHA1Complete); + OutBuffer[1].Buffer = Digest; + OutBuffer[1].Size = sizeof (*Digest); + OutBuffer[2].Buffer = NewPCRValue; + OutBuffer[2].Size = sizeof (*NewPCRValue); + + return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer ); +} + + + +EFI_STATUS +__stdcall TcmCommonExtend( + IN VOID *CallbackContext, + IN TPM_PCRINDEX PCRIndex, + IN TCM_DIGEST *Digest, + OUT TCM_DIGEST *NewPCRValue ) +{ + TPM_1_2_CMD_HEADER cmdHeader; + TPM_1_2_RET_HEADER retHeader; + TPM_TRANSMIT_BUFFER InBuffer[3], OutBuffer[2]; + + InBuffer[0].Buffer = &cmdHeader; + InBuffer[0].Size = sizeof (cmdHeader); + InBuffer[1].Buffer = &PCRIndex; + InBuffer[1].Size = sizeof (PCRIndex); + InBuffer[2].Buffer = Digest->digest; + InBuffer[2].Size = sizeof (Digest->digest); + + OutBuffer[0].Buffer = &retHeader; + OutBuffer[0].Size = sizeof (retHeader); + OutBuffer[1].Buffer = NewPCRValue->digest; + OutBuffer[1].Size = sizeof (NewPCRValue->digest); + + cmdHeader.Tag = TPM_H2NS( TPM_TAG_RQU_COMMAND ); + cmdHeader.ParamSize = TPM_H2NL(sizeof (cmdHeader) + + sizeof (PCRIndex) + sizeof (Digest->digest)); + + cmdHeader.Ordinal = TPM_H2NL( TCM_ORD_Extend ); + PCRIndex = TcgCommonH2NL( PCRIndex ); + + return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer ); +} + + +EFI_STATUS +__stdcall Tcg20CommonExtend( + IN VOID *CallbackContext, + IN TPM_PCRINDEX PcrIndex, + IN TCG_DIGEST *Digest, + OUT TCG_DIGEST *NewPCRValue, + IN UINT8 DigestSize ) +{ + TPM2_PCRExtend_cmd_t Cmd; + TPM2_PCRExtend_res_t Res; + TPM2_PCRExtend_res_t Tmpres; + UINT32 CmdSize; + UINT8 *Buffer; + UINT8 *AuthSizeOffset; + UINT8 *ResultBuf = NULL; + UINT32 ResultBufSize = 0; + + TPM_TRANSMIT_BUFFER InBuffer[1], OutBuffer[1]; + + Cmd.Tag = (TPMI_ST_COMMAND_TAG)TPM_H2NS(TPM_ST_SESSIONS); + Cmd.CommandSize = TPM_H2NL(sizeof(Cmd)); + Cmd.CommandCode = TPM_H2NL(TPM_CC_PCR_Extend); + + Buffer = (UINT8 *)&Cmd.inputParameters; + *(UINT32 *)Buffer = TPM_H2NL(PcrIndex); + Buffer += sizeof(UINT32); + + AuthSizeOffset = Buffer; + *(UINT32 *)Buffer = 0; + Buffer += sizeof(UINT32); + + // pcr authHandle + *(UINT32 *)Buffer = TPM_H2NL(TPM_RS_PW); + Buffer += sizeof(UINT32); + + // nonce = nullNonce + *(UINT16 *)Buffer = 0; + Buffer += sizeof(UINT16); + + // sessionAttributes = 0 + *(UINT8 *)Buffer = 0; + Buffer += sizeof(UINT8); + + // auth = nullAuth + *(UINT16 *)Buffer = 0; + Buffer += sizeof(UINT16); + + // authorizationSize + *(UINT32 *)AuthSizeOffset = TPM_H2NL((UINT32)(Buffer - AuthSizeOffset - sizeof(UINT32))); + + //Digest count + *(UINT32 *)Buffer = TPM_H2NL(1); + Buffer += sizeof(UINT32); + + //Hash alg + *(UINT16 *)Buffer = TPM_H2NS(TPM2_ALG_SHA1); + Buffer += sizeof(UINT16); + + // Get the digest size based on Hash Alg + TcgCommonCopyMem(CallbackContext, Buffer, &Digest->digest, DigestSize); + + Buffer += DigestSize; + + CmdSize = (UINT32)(Buffer - (UINT8 *)&Cmd); + Cmd.CommandSize = TPM_H2NL(CmdSize); + + ResultBuf = (UINT8 *) &Tmpres; + ResultBufSize = sizeof(Res); + + InBuffer[0].Buffer = &Cmd; + InBuffer[0].Size = CmdSize; + OutBuffer[0].Buffer = ResultBuf; + OutBuffer[0].Size = ResultBufSize; + + return TCGPASSTHROUGH( CallbackContext, InBuffer, OutBuffer ); + +} + + + + +EFI_STATUS +__stdcall SHA1HashAll( + IN VOID *CallbackContext, + IN VOID *HashData, + IN UINTN HashDataLen, + OUT TCG_DIGEST *Digest +) +{ + SHA1_CTX Sha1Ctx; + unsigned char DigestArray[20]; + + SHA1Init( &Sha1Ctx ); + + SHA1Update( &Sha1Ctx, HashData, (u32)HashDataLen ); + + SHA1Final( DigestArray, &Sha1Ctx ); + + TcgCommonCopyMem( + CallbackContext, + Digest->digest, + DigestArray, + sizeof (Digest->digest)); + + return EFI_SUCCESS; +} + + +/* +EFI_STATUS +__stdcall SHA2HashAll( + IN VOID *CallbackContext, + IN VOID *HashData, + IN UINTN HashDataLen, + OUT TCG_DIGEST *Digest +) +{ + SHA2_CTX Sha2Ctx; + unsigned char DigestArray[32]; + + sha256_init( &Sha2Ctx ); + + sha256_process( &Sha2Ctx, HashData, (u32)HashDataLen ); + + sha256_done( &Sha2Ctx, DigestArray ); + + TcgCommonCopyMem( + CallbackContext, + Digest->digestSha2, + DigestArray, + sizeof (Digest->digestSha2)); + + return EFI_SUCCESS; +}*/ + +//********************************************************************** +//<AMI_PHDR_START> +// +// Procedure: GetHob +// +// Description: Find instance of a HOB type in a HOB list +// +// Input: +// Type The HOB type to return. +// HobStart The first HOB in the HOB list. +// +// Output: +// Pointer to the Hob matching the type or NULL +// +// Modified: +// +// Referrals: +// +// Notes: +//<AMI_PHDR_END> +//********************************************************************** +VOID* GetHob( + IN UINT16 Type, + IN VOID *HobStart ) +{ + EFI_PEI_HOB_POINTERS Hob; + + Hob.Raw = HobStart; + + // + // Return input if not found + // + if ( HobStart == NULL ) + { + return HobStart; + } + + // + // Parse the HOB list, stop if end of list or matching type found. + // + while ( !END_OF_HOB_LIST( Hob )) + { + if ( Hob.Header->HobType == Type ) + { + break; + } + + Hob.Raw = GET_NEXT_HOB( Hob ); + } + + // + // Return input if not found + // + if ( END_OF_HOB_LIST( Hob )) + { + return HobStart; + } + + return (VOID*)(Hob.Raw); +} + +//********************************************************************** +//<AMI_PHDR_START> +// +// Procedure: CompareGuid +// +// Description: Compares two input GUIDs +// +// Input: Comparision status +// +// Output: None +// +// Modified: +// +// Referrals: +// +// Notes: +//<AMI_PHDR_END> +//********************************************************************** +BOOLEAN CompareGuid( + EFI_GUID *G1, + EFI_GUID *G2 ) +{ + UINT32 *p1 = (UINT32*)G1, *p2 = (UINT32*)G2; + UINTN i; + + for ( i = 0; i < 4; ++i ) + { + if ( p1[i] != p2[i] ) + { + return FALSE; + } + } + return TRUE; + ; +} + +//********************************************************************** +//<AMI_PHDR_START> +// +// Procedure: LocateATcgHob +// +// Description: +// +// Input: +// +// Output: None +// +// Modified: +// +// Referrals: +// +// Notes: +//<AMI_PHDR_END> +//********************************************************************** +EFI_GUID gEfiAmiTHobListGuid = TCG_EFI_HOB_LIST_GUID; +VOID* LocateATcgHob( + UINTN NoTableEntries, + EFI_CONFIGURATION_TABLE *ConfigTable, + EFI_GUID *HOB_guid ) +{ + VOID *HobStart; + VOID *PtrHob; + + while ( NoTableEntries > 0 ) + { + NoTableEntries--; + + if ((!MemCmp( + &ConfigTable[NoTableEntries].VendorGuid, + &gEfiAmiTHobListGuid, sizeof(EFI_GUID) + ))) + { + HobStart = ConfigTable[NoTableEntries].VendorTable; + + if ( !EFI_ERROR( + GetNextGuidHob( &HobStart, HOB_guid, &PtrHob, NULL ) + )) + { + return PtrHob; + } + } + } + return NULL; +} + +//********************************************************************** +//<AMI_PHDR_START> +// +// Procedure: GetNextGuidHob +// +// Description: Find GUID HOB +// +// Input: HobStart A pointer to the start hob. +// Guid A pointer to a guid. +// Output: +// Buffer A pointer to the buffer. +// BufferSize Buffer size. +// +// Modified: +// +// Referrals: +// +// Notes: +//<AMI_PHDR_END> +//********************************************************************** +EFI_STATUS GetNextGuidHob( + IN OUT VOID **HobStart, + IN EFI_GUID * Guid, + OUT VOID **Buffer, + OUT UINTN *BufferSize OPTIONAL ) +{ + EFI_STATUS Status; + EFI_PEI_HOB_POINTERS GuidHob; + + if ( Buffer == NULL ) + { + return EFI_INVALID_PARAMETER; + } + + for ( Status = EFI_NOT_FOUND; EFI_ERROR( Status );) + { + GuidHob.Raw = *HobStart; + + if ( END_OF_HOB_LIST( GuidHob )) + { + return EFI_NOT_FOUND; + } + + GuidHob.Raw = GetHob( EFI_HOB_TYPE_GUID_EXTENSION, *HobStart ); + + if ( GuidHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION ) + { + if ( CompareGuid( Guid, &GuidHob.Guid->Name )) + { + Status = EFI_SUCCESS; + *Buffer = (VOID*)((UINT8*)(&GuidHob.Guid->Name) + + sizeof (EFI_GUID)); + + if ( BufferSize != NULL ) + { + *BufferSize = GuidHob.Header->HobLength + - sizeof (EFI_HOB_GUID_TYPE); + } + } + } + + *HobStart = GET_NEXT_HOB( GuidHob ); + } + + return Status; +} diff --git a/Core/EM/TCG2/TisLib/TcgCommon.h b/Core/EM/TCG2/TisLib/TcgCommon.h new file mode 100644 index 0000000..4565f79 --- /dev/null +++ b/Core/EM/TCG2/TisLib/TcgCommon.h @@ -0,0 +1,305 @@ +/*++ + + Copyright (c) 2005 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + + Module Name: + + TcgCommon.h + + Abstract: + + Header file for TcgCommon.c + + --*/ +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgCommon.h 1 4/21/14 2:14p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:14p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgCommon.h $ +// +// 1 4/21/14 2:14p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 2 10/03/13 12:32p Fredericko +// Sha256 support policy update +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 13 3/19/12 6:14p Fredericko +// +// 12 3/29/11 12:24p Fredericko +// +// 11 3/28/11 12:18p Fredericko +// [TAG] EIP 54642 +// [Category] Improvement +// [Description] 1. Checkin Files related to TCG function override +// 2. Include TCM and TPM auto detection +// [Files] Affects all TCG files +// +// 10 5/19/10 5:10p Fredericko +// Included File Header +// Included File Revision History +// EIP 37653 +// +//************************************************************************* +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TcgCommon.h +// +// Description: +// Header file for TcgCommon.c +// +//<AMI_FHDR_END> +//************************************************************************* +#ifndef _TCG_COMMON_H_ +#define _TCG_COMMON_H_ + +#include <Efi.h> +#include "TcgPc.h" +#include "TcgEfiTpm.h" +#include "Sha.h" +#include <HOB.h> +#include "..\Common\Tpm20Includes\Tpm20.h" +//#include "TcgMisc.h" + +#define TcgCommonN2HS( v16 ) TcgCommonH2NS( v16 ) +#define TcgCommonN2HL( v32 ) TcgCommonH2NL( v32 ) +#define EFI_TPL_DRIVER 6 +#define EFI_TPL_APPLICATION 4 +#define EFI_TPL_CALLBACK 8 +#define EFI_TPL_NOTIFY 16 +#define EFI_TPL_HIGH_LEVEL 31 +#define STRING_TOKEN( x ) x + + +#define GET_HOB_TYPE( Hob ) ((Hob).Header->HobType) +#define GET_HOB_LENGTH( Hob ) ((Hob).Header->HobLength) +#define GET_NEXT_HOB( Hob ) ((Hob).Raw + GET_HOB_LENGTH( Hob )) +#define END_OF_HOB_LIST( Hob ) (GET_HOB_TYPE( Hob ) ==\ + EFI_HOB_TYPE_END_OF_HOB_LIST) + +#define TCGPASSTHROUGH( cb, in, out ) \ + TcgCommonPassThrough( \ + cb, \ + sizeof (in) / sizeof (*(in)), \ + (in), \ + sizeof (out) / sizeof (*(out)), \ + (out) \ + ) + + +extern +UINT16 +__stdcall TcgCommonH2NS ( + IN UINT16 Val ); + +extern +UINT32 +__stdcall TcgCommonH2NL ( + IN UINT32 Val ); + +VOID* GetHob ( + IN UINT16 Type, + IN VOID *HobStart ); + +BOOLEAN CompareGuid ( + EFI_GUID *G1, + EFI_GUID *G2 ); + +EFI_STATUS GetNextGuidHob ( + IN OUT VOID **HobStart, + IN EFI_GUID * Guid, + OUT VOID **Buffer, + OUT UINTN*BufferSize OPTIONAL ); + +extern +EFI_STATUS +__stdcall TcgCommonPassThrough ( + IN VOID *CallbackContext, + IN UINT32 NoInputBuffers, + IN TPM_TRANSMIT_BUFFER *InputBuffers, + IN UINT32 NoOutputBuffers, + IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers ); + +extern +VOID +__stdcall TcgCommonCopyMem ( + IN VOID *CallbackContext, + OUT VOID *Dest, + IN VOID *Src, + IN UINTN Len ); + +extern +EFI_STATUS +__stdcall TcgCommonLogEvent( + IN VOID *CallbackContext, + IN TCG_PCR_EVENT *EvtLog, + IN OUT UINT32 *TableSize, + IN UINT32 MaxSize, + IN TCG_PCR_EVENT *NewEntry, + IN UINT8 HashAlgorithm ); + +extern +EFI_STATUS +__stdcall TcmCommonLogEvent ( + IN VOID *CallbackContext, + IN TCM_PCR_EVENT *EvtLog, + IN OUT UINT32 *TableSize, + IN UINT32 MaxSize, + IN TCM_PCR_EVENT *NewEntry ); + +extern +EFI_STATUS +__stdcall TcgCommonSha1Start ( + IN VOID *CallbackContext, + IN TCG_ALGORITHM_ID AlgId, + OUT UINT32 *MaxBytes ); + +extern +EFI_STATUS +__stdcall TcgCommonSha1Update ( + IN VOID *CallbackContext, + IN VOID *Data, + IN UINT32 DataLen, + IN UINT32 MaxBytes ); + +extern +EFI_STATUS +__stdcall TcgCommonSha1CompleteExtend ( + IN VOID *CallbackContext, + IN VOID *Data, + IN UINT32 DataLen, + IN TPM_PCRINDEX PCRIndex, + OUT TCG_DIGEST *Digest, + OUT TCG_DIGEST *NewPCRValue ); + + +EFI_STATUS +__stdcall TcmCommonSha1CompleteExtend( + IN VOID *CallbackContext, + IN VOID *Data, + IN UINT32 DataLen, + IN TPM_PCRINDEX PCRIndex, + OUT TCM_DIGEST *Digest, + OUT TCM_DIGEST *NewPCRValue ); + +extern +EFI_STATUS +__stdcall TcgCommonExtend ( + IN VOID *CallbackContext, + IN TPM_PCRINDEX PCRIndex, + IN TCG_DIGEST *Digest, + OUT TCG_DIGEST *NewPCRValue ); + +EFI_STATUS +__stdcall TcmCommonExtend( + IN VOID *CallbackContext, + IN TPM_PCRINDEX PCRIndex, + IN TCM_DIGEST *Digest, + OUT TCM_DIGEST *NewPCRValue ); + +extern +EFI_STATUS +__stdcall SHA1HashAll ( + IN VOID *CallbackContext, + IN VOID *HashData, + IN UINTN HashDataLen, + OUT TCG_DIGEST *Digest + ); + +EFI_STATUS +__stdcall SHA2HashAll( + IN VOID *CallbackContext, + IN VOID *HashData, + IN UINTN HashDataLen, + OUT TCG_DIGEST *Digest + ); + +EFI_STATUS EfiLibGetSystemConfigurationTable( + IN EFI_GUID *TableGuid, + IN OUT VOID **Table ); + +#pragma pack(push,1) + +typedef union { + UINT8 sha1[SHA1_DIGEST_SIZE]; + UINT8 sha256[SHA256_DIGEST_SIZE]; +} TPM_COMM_DIGEST_UNION; + +typedef struct{ + UINT16 HashAlgId; + TPM_COMM_DIGEST_UNION Digest; +}TPM_COMM_DIGEST; + +#define HASH_ALG_COUNT 2 + +typedef struct { + UINT32 Count; + TPM_COMM_DIGEST Digests[HASH_ALG_COUNT]; +}TPM_COMM_DIGEST_LIST; + +typedef struct { + TPMI_DH_PCR pcrHandle; + TPM_COMM_DIGEST_LIST DigestValue; +} PCR_Extend_In; + +typedef struct { + TPMI_ST_COMMAND_TAG Tag; + UINT32 CommandSize; + TPM_CC CommandCode; + PCR_Extend_In inputParameters; + UINT32 authorizationSize; + TPMS_AUTH_SESSION_COMMAND pwapAuth; +} TPM2_PCRExtend_cmd_t; + +typedef struct { + TPMI_ST_COMMAND_TAG Tag; + UINT32 RespondSize; + TPM_RC ResponseCode; + UINT32 parameterSize; + TPMS_AUTH_SESSION_RESPONSE pwapAuth; +} TPM2_PCRExtend_res_t; + + +#pragma pack(pop) + +extern +BOOLEAN +__stdcall AutoSupportType ( + ); + +#endif diff --git a/Core/EM/TCG2/TisLib/TcgEFI12.h b/Core/EM/TCG2/TisLib/TcgEFI12.h new file mode 100644 index 0000000..9ecfa92 --- /dev/null +++ b/Core/EM/TCG2/TisLib/TcgEFI12.h @@ -0,0 +1,186 @@ +/*++ + + Copyright (c) 2005 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + + Module Name: + + TpmEfi.h + + Abstract: + + This file contains definitions of structures for TPM and TCG + protocols/ppis. + + --*/ + +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgEFI12.h 1 4/21/14 2:15p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:15p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgEFI12.h $ +// +// 1 4/21/14 2:15p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 2 5/19/10 5:22p Fredericko +// +// Included File Header +// Included File Revision History +// Code Beautification +// EIP 37653 +// +//************************************************************************* +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TcgEFI12.h +// +// Description: +// Contains Industry Standard structures for TCG +// +//<AMI_FHDR_END> +//************************************************************************* +#ifndef _TCGEFI_H_ +#define _TCGEFI_H_ + +#include "TcgTpm12.h" +#include "TcgPc.h" + +#define _TPM_NTH_BIT( x ) (1 << (x)) +#define _TPM_STRUCT_PARTIAL_SIZE( type, field ) \ + ((UINTN)&(((type*)0)->field)) + +#pragma pack (push) +#pragma pack (1) + +// +// TCG_PCClientEventStructure +// +#pragma pack (pop) + +// +// Per the EFI Implementation +// +typedef TPM_DIGEST TCG_DIGEST; + +// +// TPM_TRANSMIT_BUFFER used by TCG services +// +typedef struct _TPM_TRANSMIT_BUFFER +{ + VOID *Buffer; + UINTN Size; +} TPM_TRANSMIT_BUFFER; + +// +// Definitons of TPM commands +// + +#pragma pack (push) +#pragma pack (1) + +typedef struct _TPM_1_2_CMD_HEADER +{ + TPM_TAG Tag; + UINT32 ParamSize; + TPM_COMMAND_CODE Ordinal; +} TPM_1_2_CMD_HEADER; + +typedef struct _TPM_1_2_RET_HEADER +{ + TPM_TAG Tag; + UINT32 ParamSize; + TPM_RESULT RetCode; +} TPM_1_2_RET_HEADER; + +// +// TPM_Startup +// + +typedef struct _TPM_1_2_CMD_STARTUP +{ + TPM_1_2_CMD_HEADER Header; + TPM_STARTUP_TYPE StartupType; +} TPM_1_2_CMD_STARTUP; + +// +// TPM_SHA1Start +// + +typedef struct _TPM_1_2_RET_SHA1START +{ + TPM_1_2_RET_HEADER Header; + UINT32 MaxBytes; +} TPM_1_2_RET_SHA1START; + +// +// TPM_SHA1Update +// + +typedef struct _TPM_1_2_CMD_SHA1UPDATE +{ + TPM_1_2_CMD_HEADER Header; + UINT32 NumBytes; +} TPM_1_2_CMD_SHA1UPDATE; + +// +// TPM_SHA1Complete +// + +typedef TPM_1_2_CMD_SHA1UPDATE TPM_1_2_CMD_SHA1COMPLETE; + +typedef struct _TPM_1_2_RET_SHA1COMPLETE +{ + TPM_1_2_CMD_HEADER Header; + TCG_DIGEST Digest; +} TPM_1_2_RET_SHA1COMPLETE; + +// +// TPM_SHA1CompleteExtend +// + +typedef struct _TPM_1_2_CMD_SHA1COMPLETEEXTEND +{ + TPM_1_2_CMD_HEADER Header; + TPM_PCRINDEX PCRIndex; + UINT32 NumBytes; +} TPM_1_2_CMD_SHA1COMPLETEEXTEND; + +#pragma pack (pop) + +#endif // _TCGEFI_H_ diff --git a/Core/EM/TCG2/TisLib/TcgEfiTpm.h b/Core/EM/TCG2/TisLib/TcgEfiTpm.h new file mode 100644 index 0000000..3639048 --- /dev/null +++ b/Core/EM/TCG2/TisLib/TcgEfiTpm.h @@ -0,0 +1,220 @@ +/*++ + + Copyright (c) 2006, Intel Corporation + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + Module Name: + + EfiTpm.h + + Abstract: + + EFI definition according to TCG_EFI_Platform_1_20_Final + + See http://trustedcomputinggroup.org for latest specification updates + + --*/ + +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgEfiTpm.h 1 4/21/14 2:15p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:15p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgEfiTpm.h $ +// +// 1 4/21/14 2:15p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 5 11/17/11 2:28p Fredericko +// [TAG] EIP75882 +// [Category] New Feature +// [Description] Measurement of Secureboot variables PK, KEK, DB, DBX +// and the EFI_Image_Execution_tables +// [Files] TcgEfiTpm.h +// AmitcgPlatform.sdl +// AmiTcgPlatformDxe.c +// AmiTcgPlatformDxe.h +// +// 4 5/19/10 5:24p Fredericko +// Included File Header +// Included File Revision History +// Code Beautification +// EIP 37653 +// +//************************************************************************* +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TcgTpm12.h +// +// Description: +// Contains Industry Standard #defines and structures for TCG +// +//<AMI_FHDR_END> +//************************************************************************* +#ifndef _EFI_TPM_H_ +#define _EFI_TPM_H_ + +#include <EFI.h> + +// +// The start of TPM return codes +// +#define TPM_BASE (EFI_MAX_BIT + (EFI_MAX_BIT >> 1)) +#include "TcgTpm12.h" + +// +// Standard event types +// +#define EV_POST_CODE ((TCG_EVENTTYPE) 0x00000001) +#define EV_SEPARATOR ((TCG_EVENTTYPE) 0x00000004) +#define EV_S_CRTM_CONTENTS ((TCG_EVENTTYPE) 0x00000007) +#define EV_S_CRTM_VERSION ((TCG_EVENTTYPE) 0x00000008) + +// +// EFI specific event types +// +#define EV_EFI_EVENT_BASE ((TCG_EVENTTYPE) 0x80000000) +#define EV_EFI_VARIABLE_DRIVER_CONFIG (EV_EFI_EVENT_BASE + 1) +#define EV_EFI_VARIABLE_BOOT (EV_EFI_EVENT_BASE + 2) +#define EV_EFI_BOOT_SERVICES_APPLICATION (EV_EFI_EVENT_BASE + 3) +#define EV_EFI_BOOT_SERVICES_DRIVER (EV_EFI_EVENT_BASE + 4) +#define EV_EFI_RUNTIME_SERVICES_DRIVER (EV_EFI_EVENT_BASE + 5) +#define EV_EFI_GPT_EVENT (EV_EFI_EVENT_BASE + 6) +#define EV_EFI_ACTION (EV_EFI_EVENT_BASE + 7) +#define EV_EFI_PLATFORM_FIRMWARE_BLOB (EV_EFI_EVENT_BASE + 8) +#define EV_EFI_HANDOFF_TABLES (EV_EFI_EVENT_BASE + 9) +#define EV_EFI_SETUP_MODE (EV_EFI_EVENT_BASE + 0x0a) +#define EV_EFI_PLATFORM_KEY (EV_EFI_EVENT_BASE + 0x0b) +#define EV_EFI_KEY_EXCHANGE_KEY (EV_EFI_EVENT_BASE + 0x0c) +#define EV_EFI_AUTHORIZED_DB (EV_EFI_EVENT_BASE + 0x0d) +#define EV_EFI_FORBIDDEN_DBX (EV_EFI_EVENT_BASE + 0x0e) +#define EV_EFI_EXECUTION_INFO_TABLE (EV_EFI_EVENT_BASE + 0x0f) + + +// +// Set structure alignment to 1-byte +// +#pragma pack (push, 1) + +typedef UINT32 TCG_EVENTTYPE; + +#define TCG_DIGEST TPM_DIGEST +#define TCG_PCRINDEX TPM_PCRINDEX + +// +// TCG_PCR_EVENT +// +typedef struct tdTCG_PCR_EVENT +{ + TCG_PCRINDEX PCRIndex; // PCRIndex event extended to + TCG_EVENTTYPE EventType; // TCG EFI event type + TCG_DIGEST Digest; // Value extended into PCRIndex + UINT32 EventSize; // Size of the event data + UINT8 Event[1]; // The event data +} TCG_PCR_EVENT; + +// +// TCG_PCR_EVENT_HDR +// +typedef struct tdTCG_PCR_EVENT_HDR +{ + TCG_PCRINDEX PCRIndex; + TCG_EVENTTYPE EventType; + TCG_DIGEST Digest; + UINT32 EventSize; +} TCG_PCR_EVENT_HDR; + +// +// EFI_PLATFORM_FIRMWARE_BLOB +// +// BlobLength should be of type UINTN but we use UINT64 here +// because PEI is 32-bit while DXE is 64-bit on x64 platforms +// +typedef struct tdEFI_PLATFORM_FIRMWARE_BLOB +{ + EFI_PHYSICAL_ADDRESS BlobBase; + UINT64 BlobLength; +} EFI_PLATFORM_FIRMWARE_BLOB; + +// +// EFI_IMAGE_LOAD_EVENT +// +// This structure is used in EV_EFI_BOOT_SERVICES_APPLICATION, +// EV_EFI_BOOT_SERVICES_DRIVER and EV_EFI_RUNTIME_SERVICES_DRIVER +// +typedef struct tdEFI_IMAGE_LOAD_EVENT +{ + EFI_PHYSICAL_ADDRESS ImageLocationInMemory; + UINTN ImageLengthInMemory; + UINTN ImageLinkTimeAddress; + UINTN LengthOfDevicePath; + EFI_DEVICE_PATH_PROTOCOL DevicePath[1]; +} EFI_IMAGE_LOAD_EVENT; + +// +// EFI_HANDOFF_TABLE_POINTERS +// +// This structure is used in EV_EFI_HANDOFF_TABLES event to facilitate +// the measurement of given configuration tables. +// +typedef struct tdEFI_HANDOFF_TABLE_POINTERS +{ + UINTN NumberOfTables; + EFI_CONFIGURATION_TABLE TableEntry[1]; +} EFI_HANDOFF_TABLE_POINTERS; + +// +// EFI_VARIABLE_DATA +// +// This structure serves as the header for measuring variables. The name of the +// variable (in Unicode format) should immediately follow, then the variable +// data. +// +typedef struct tdEFI_VARIABLE_DATA +{ + EFI_GUID VariableName; + UINTN UnicodeNameLength; + UINTN VariableDataLength; + CHAR16 UnicodeName[1]; + INT8 VariableData[1]; // Driver or platform-specific data +} EFI_VARIABLE_DATA; + +// +// Restore original structure alignment +// +#pragma pack (pop) + +#endif // _EFI_TPM_H_ diff --git a/Core/EM/TCG2/TisLib/TcgPc.h b/Core/EM/TCG2/TisLib/TcgPc.h new file mode 100644 index 0000000..18b1a43 --- /dev/null +++ b/Core/EM/TCG2/TisLib/TcgPc.h @@ -0,0 +1,311 @@ +/*++ + + Copyright (c) 2005 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + + Module Name: + + TpmDev.h + + Abstract: + + Header file for tpm device drivers + + --*/ + +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgPc.h 1 4/21/14 2:15p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:15p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgPc.h $ +// +// 1 4/21/14 2:15p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 4 3/29/11 12:26p Fredericko +// +// 3 3/28/11 12:27p Fredericko +// [TAG] EIP 54642 +// [Category] Improvement +// [Description] 1. Checkin Files related to TCG function override +// 2. Include TCM and TPM auto detection +// [Files] Affects all TCG files +// +// 2 5/19/10 5:23p Fredericko +// +// Included File Header +// Included File Revision History +// Code Beautification +// EIP 37653 +// +//************************************************************************* +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TcgPc.h +// +// Description: +// Contains Industry Standard #defines and Structures for TCG +// +//<AMI_FHDR_END> +//************************************************************************* +#ifndef _TPMPC_H_ +#define _TPMPC_H_ + +#include "TcgEfi12.h" +#include "INTTcgAcpi.h" +#include "TcmPc.h" + +#pragma pack (push) +#pragma pack (1) + +typedef struct _TPM_1_2_REGISTERS +{ + UINT8 Access; // 0 + UINT8 Reserved1[7]; // 1 + UINT32 IntEnable; // 8 + UINT8 IntVector; // 0ch + UINT8 Reserved2[3]; // 0dh + UINT32 IntSts; // 10h + UINT32 IntfCapability; // 14h + UINT8 Sts; // 18h + UINT16 BurstCount; // 19h + UINT8 Reserved3[9]; + UINT32 DataFifo; // 24h + UINT8 Reserved4[0xed8]; // 28h + UINT16 Vid; // 0f00h + UINT16 Did; // 0f02h + UINT8 Rid; // 0f04h + UINT8 TcgDefined[0x7b]; // 0f05h + UINT32 LegacyAddress1; // 0f80h + UINT32 LegacyAddress1Ex; // 0f84h + UINT32 LegacyAddress2; // 0f88h + UINT32 LegacyAddress2Ex; // 0f8ch + UINT8 VendorDefined[0x70]; // 0f90h +} TPM_1_2_REGISTERS; + +typedef struct _TCG_ACPI_TABLE +{ + EFI_ACPI_DESCRIPTION_HEADER Header; + UINT16 Reserved; + UINT32 LogMaxLength; + EFI_PHYSICAL_ADDRESS LogStart; +} TCG_ACPI_TABLE; + +// +// Trusted Computing Platform Alliance Capabilities Table (TCPA) +// +typedef struct +{ + EFI_ACPI_DESCRIPTION_HEADER Header; + UINT16 Reserved; + UINT32 LogAreaMaxLength; + UINT64 LogAreaStartAddress; +} EFI_ACPI_TCPA_CAPABILITIES_TABLE; + +#pragma pack (pop) + +typedef volatile TPM_1_2_REGISTERS *TPM_1_2_REGISTERS_PTR; + +#define TPM_ACC_VALID _TPM_NTH_BIT( 7 ) +#define TPM_ACC_ACTIVE_LOCALITY _TPM_NTH_BIT( 5 ) +#define TPM_ACC_BEEN_SEIZED _TPM_NTH_BIT( 4 ) +#define TPM_ACC_SEIZE _TPM_NTH_BIT( 3 ) +#define TPM_ACC_PENDING_REQUEST _TPM_NTH_BIT( 2 ) +#define TPM_ACC_REQUEST_USE _TPM_NTH_BIT( 1 ) +#define TPM_ACC_ESTABLISHMENT _TPM_NTH_BIT( 0 ) + +#define TPM_STS_VALID _TPM_NTH_BIT( 7 ) +#define TPM_STS_READY _TPM_NTH_BIT( 6 ) +#define TPM_STS_GO _TPM_NTH_BIT( 5 ) +#define TPM_STS_DATA_AVAILABLE _TPM_NTH_BIT( 4 ) +#define TPM_STS_EXPECT _TPM_NTH_BIT( 3 ) +#define TPM_STS_RESPONSE_RETRY _TPM_NTH_BIT( 1 ) + +#define TPM_BASE_ADDRESS 0xFED40000 + +#define TPM_H2NS( x ) \ + (((UINT16)(x) << 8) | ((UINT16)(x) >> 8)) +#define TPM_H2NL( x ) \ + (UINT32)((((UINT32)(x)) >> 24) \ + | (((x) >> 8) & 0xff00) \ + | ((x) << 24) \ + | (((x) & 0xff00) << 8)) + +#define TPM_N2HS( x ) TPM_H2NS( x ) +#define TPM_N2HL( x ) TPM_H2NL( x ) + +// +// PCR Usage +// +#define PCRi_CRTM_AND_POST_BIOS 0 +#define PCRi_HOST_PLATFORM_CONFIG 1 +#define PCRi_OPROM_CODE 2 +#define PCRi_OPROM_CONFIG_AND_DATA 3 +#define PCRi_IPL_CODE 4 +#define PCRi_IPL_CONFIG_AND_DATA 5 +#define PCRi_STATE_TRANSITION 6 +#define PCRi_HOST_PLATFORM_MANUFACTURER_CONTROL 7 + +// +// TCG Event Logs +// +#define TPM_LOG_AREA_MAX_LEN 0x10000 + +// +// TCG Event Types +// +#define EV_PREBOOT_CERT 0 +#define EV_UNUSED 2 +#define EV_NO_ACTION 3 +#define EV_ACTION 5 +#define EV_EVENT_TAG 6 +#define EV_CPU_MICROCODE 9 +#define EV_PLATFORM_CONFIG_FLAGS 10 +#define EV_TABLE_OF_DEVICES 11 +#define EV_COMPACT_HASH 12 +#define EV_IPL 13 +#define EV_IPL_PARTITION_DATA 14 +#define EV_NONHOST_CODE 15 +#define EV_NONHOST_CONFIG 16 + +// +// TCG Event IDs +// +#define EV_ID_NULL 0 +#define EV_ID_SMBIOS_RECORD 1 +#define EV_ID_BIS_CERTIFICATE 2 +#define EV_ID_POST_BIOS_STRING 3 +#define EV_ID_ESCD 4 +#define EV_ID_RAW_CMOS 5 +#define EV_ID_RAW_NVRAM 6 +#define EV_ID_OPROM_EXECUTE 7 +#define EV_ID_OPROM_CONFIG 8 +#define EV_ID_OPROM_MICROCODE_UPDATE 9 + +#pragma pack (push) +#pragma pack (1) + +// +// _EFI_TCG_EV_S_CRTM_VERSION +// +struct _EFI_TCG_EV_S_CRTM_VERSION +{ + EFI_GUID VersionGuid; +}; + +// +// _EFI_TCG_EV_POST_CODE +// +struct _EFI_TCG_EV_POST_CODE +{ + EFI_PHYSICAL_ADDRESS PostCodeAddress; + UINT64 PostCodeLength; +}; + +// +// _EFI_TCG_EV_TAG_OPTION_ROM_EXECUTE +// +struct _EFI_TCG_EV_TAG_OPTION_ROM_EXECUTE +{ + UINT16 Reserved; + UINT16 PFA; + TCG_DIGEST Hash; +}; + +// +// _EFI_TCG_EV_CPU_MICROCODE +// +struct _EFI_TCG_EV_CPU_MICROCODE +{ + EFI_PHYSICAL_ADDRESS MicrocodeEntrypoint; +}; + +// +// _EFI_TCG_EV_TAG_EVENT_DATA +// +union _EFI_TCG_EV_TAG_EVENT_DATA +{ + struct _EFI_TCG_EV_TAG_OPTION_ROM_EXECUTE + OptionRomExecute; +}; + +// +// _EFI_TCG_EV_TAG +// +struct _EFI_TCG_EV_TAG +{ + UINT32 EventID; + UINT32 EventSize; + union _EFI_TCG_EV_TAG_EVENT_DATA EventData; +}; + +// +// EFI_TCG_PCR_EVENT_HEADER +// +typedef struct _EFI_TCG_PCR_EVENT_HEADER +{ + TPM_PCRINDEX PCRIndex; + UINT32 EventType; + TCG_DIGEST Digest; + UINT32 EventDataSize; +} EFI_TCG_PCR_EVENT_HEADER; + +// +// EFI_TCG_PCR_EVENT_DATA +// +typedef union _EFI_TCG_PCR_EVENT_DATA +{ + struct _EFI_TCG_EV_S_CRTM_VERSION SCrtmVersion; + struct _EFI_TCG_EV_POST_CODE PostCode; + struct _EFI_TCG_EV_TAG Tagged; + struct _EFI_TCG_EV_CPU_MICROCODE Mcu; +} EFI_TCG_PCR_EVENT_DATA; + +// +// EFI_TCG_PCR_EVENT +// equivalent to TCG_PCR_EVENT in the TCG PC Client Spec +// +typedef struct _EFI_TCG_PCR_EVENT +{ + EFI_TCG_PCR_EVENT_HEADER Header; + EFI_TCG_PCR_EVENT_DATA Event; +} EFI_TCG_PCR_EVENT; + +#pragma pack (pop) + +#endif // _TPMPC_H_ diff --git a/Core/EM/TCG2/TisLib/TcgTpm12.h b/Core/EM/TCG2/TisLib/TcgTpm12.h new file mode 100644 index 0000000..c20668c --- /dev/null +++ b/Core/EM/TCG2/TisLib/TcgTpm12.h @@ -0,0 +1,1973 @@ +/*++ + + Copyright (c) 2005 - 2006, Intel Corporation + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + Module Name: + + Tpm12.h + + Abstract: + + TPM Specification data structures (TCG TPM Specification Version 1.2 Revision 94) + + See http://trustedcomputinggroup.org for latest specification updates + + --*/ +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgTpm12.h 1 4/21/14 2:14p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:14p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcgTpm12.h $ +// +// 1 4/21/14 2:14p Fredericko +// +// 2 3/17/14 3:03p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 2 10/03/13 12:32p Fredericko +// Sha256 support policy update +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 6 3/29/11 12:25p Fredericko +// +// 5 3/28/11 12:25p Fredericko +// [TAG] EIP 54642 +// [Category] Improvement +// [Description] 1. Checkin Files related to TCG function override +// 2. Include TCM and TPM auto detection +// [Files] Affects all TCG files +// +// 4 5/19/10 5:21p Fredericko +// Included File Header +// Included File Revision History +// Code Beautification +// EIP 37653 +// +//************************************************************************* +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TcgTpm12.h +// +// Description: +// Contains Industry Standard #defines for TCG +// +//<AMI_FHDR_END> +//************************************************************************* +#ifndef _TPM12_H_ +#define _TPM12_H_ + +#include "token.h" +#include "ZTEICTcmOrdinals.h" + +// +// Structures are all packed on 1-byte alignment +// + +#pragma pack (push) +#pragma pack (1) + +// +// Part 2, section 2.2: Basic types & Helper redefinitions +// +typedef UINT8 TPM_AUTH_DATA_USAGE; +typedef UINT8 TPM_PAYLOAD_TYPE; +typedef UINT8 TPM_VERSION_BYTE; +typedef UINT16 TPM_TAG; +typedef UINT16 TPM_PROTOCOL_ID; +typedef UINT16 TPM_STARTUP_TYPE; +typedef UINT16 TPM_ENC_SCHEME; +typedef UINT16 TPM_SIG_SCHEME; +typedef UINT16 TPM_MIGRATE_SCHEME; +typedef UINT16 TPM_PHYSICAL_PRESENCE; +typedef UINT16 TPM_ENTITY_TYPE; +typedef UINT16 TPM_KEY_USAGE; +typedef UINT16 TPM_EK_TYPE; +typedef UINT16 TPM_STRUCTURE_TAG; +typedef UINT16 TPM_PLATFORM_SPECIFIC; +typedef UINT32 TPM_COMMAND_CODE; +typedef UINT32 TPM_CAPABILITY_AREA; +typedef UINT32 TPM_KEY_FLAGS; +typedef UINT32 TPM_ALGORITHM_ID; +typedef UINT32 TPM_MODIFIER_INDICATOR; +typedef UINT32 TPM_ACTUAL_COUNT; +typedef UINT32 TPM_TRANSPORT_ATTRIBUTES; +typedef UINT32 TPM_AUTHHANDLE; +typedef UINT32 TPM_DIRINDEX; +typedef UINT32 TPM_KEY_HANDLE; +typedef UINT32 TPM_PCRINDEX; +typedef UINT32 TPM_RESULT; +typedef UINT32 TPM_RESOURCE_TYPE; +typedef UINT32 TPM_KEY_CONTROL; +typedef UINT32 TPM_NV_INDEX; +typedef UINT32 TPM_FAMILY_ID; +typedef UINT32 TPM_FAMILY_VERIFICATION; +typedef UINT32 TPM_STARTUP_EFFECTS; +typedef UINT32 TPM_SYM_MODE; +typedef UINT32 TPM_FAMILY_FLAGS; +typedef UINT32 TPM_DELEGATE_INDEX; +typedef UINT32 TPM_CMK_DELEGATE; +typedef UINT32 TPM_COUNT_ID; +typedef UINT32 TPM_REDIT_COMMAND; +typedef UINT32 TPM_TRANSHANDLE; +typedef UINT32 TPM_HANDLE; +typedef UINT32 TPM_FAMILY_OPERATION; + +// +// Part 2, section 2.2.4: Vendor specific +// The following defines allow for the quick specification of a +// vendor specific item. +// +#define TPM_Vendor_Specific32 ((UINT32) 0x00000400) +#define TPM_Vendor_Specific8 ((UINT8) 0x80) + +// +// Part 2, section 3.1: Structure TAGs +// +#define TPM_TAG_CONTEXTBLOB ((TPM_STRUCTURE_TAG) 0x0001) +#define TPM_TAG_CONTEXT_SENSITIVE ((TPM_STRUCTURE_TAG) 0x0002) +#define TPM_TAG_CONTEXTPOINTER ((TPM_STRUCTURE_TAG) 0x0003) +#define TPM_TAG_CONTEXTLIST ((TPM_STRUCTURE_TAG) 0x0004) +#define TPM_TAG_SIGNINFO ((TPM_STRUCTURE_TAG) 0x0005) +#define TPM_TAG_PCR_INFO_LONG ((TPM_STRUCTURE_TAG) 0x0006) +#define TPM_TAG_PERSISTENT_FLAGS ((TPM_STRUCTURE_TAG) 0x0007) +#define TPM_TAG_VOLATILE_FLAGS ((TPM_STRUCTURE_TAG) 0x0008) +#define TPM_TAG_PERSISTENT_DATA ((TPM_STRUCTURE_TAG) 0x0009) +#define TPM_TAG_VOLATILE_DATA ((TPM_STRUCTURE_TAG) 0x000A) +#define TPM_TAG_SV_DATA ((TPM_STRUCTURE_TAG) 0x000B) +#define TPM_TAG_EK_BLOB ((TPM_STRUCTURE_TAG) 0x000C) +#define TPM_TAG_EK_BLOB_AUTH ((TPM_STRUCTURE_TAG) 0x000D) +#define TPM_TAG_COUNTER_VALUE ((TPM_STRUCTURE_TAG) 0x000E) +#define TPM_TAG_TRANSPORT_INTERNAL ((TPM_STRUCTURE_TAG) 0x000F) +#define TPM_TAG_TRANSPORT_LOG_IN ((TPM_STRUCTURE_TAG) 0x0010) +#define TPM_TAG_TRANSPORT_LOG_OUT ((TPM_STRUCTURE_TAG) 0x0011) +#define TPM_TAG_AUDIT_EVENT_IN ((TPM_STRUCTURE_TAG) 0x0012) +#define TPM_TAG_AUDIT_EVENT_OUT ((TPM_STRUCTURE_TAG) 0x0013) +#define TPM_TAG_CURRENT_TICKS ((TPM_STRUCTURE_TAG) 0x0014) +#define TPM_TAG_KEY ((TPM_STRUCTURE_TAG) 0x0015) +#define TPM_TAG_STORED_DATA12 ((TPM_STRUCTURE_TAG) 0x0016) +#define TPM_TAG_NV_ATTRIBUTES ((TPM_STRUCTURE_TAG) 0x0017) +#define TPM_TAG_NV_DATA_PUBLIC ((TPM_STRUCTURE_TAG) 0x0018) +#define TPM_TAG_NV_DATA_SENSITIVE ((TPM_STRUCTURE_TAG) 0x0019) +#define TPM_TAG_DELEGATIONS ((TPM_STRUCTURE_TAG) 0x001A) +#define TPM_TAG_DELEGATE_PUBLIC ((TPM_STRUCTURE_TAG) 0x001B) +#define TPM_TAG_DELEGATE_TABLE_ROW ((TPM_STRUCTURE_TAG) 0x001C) +#define TPM_TAG_TRANSPORT_AUTH ((TPM_STRUCTURE_TAG) 0x001D) +#define TPM_TAG_TRANSPORT_PUBLIC ((TPM_STRUCTURE_TAG) 0x001E) +#define TPM_TAG_PERMANENT_FLAGS ((TPM_STRUCTURE_TAG) 0x001F) +#define TPM_TAG_STCLEAR_FLAGS ((TPM_STRUCTURE_TAG) 0x0020) +#define TPM_TAG_STANY_FLAGS ((TPM_STRUCTURE_TAG) 0x0021) +#define TPM_TAG_PERMANENT_DATA ((TPM_STRUCTURE_TAG) 0x0022) +#define TPM_TAG_STCLEAR_DATA ((TPM_STRUCTURE_TAG) 0x0023) +#define TPM_TAG_STANY_DATA ((TPM_STRUCTURE_TAG) 0x0024) +#define TPM_TAG_FAMILY_TABLE_ENTRY ((TPM_STRUCTURE_TAG) 0x0025) +#define TPM_TAG_DELEGATE_SENSITIVE ((TPM_STRUCTURE_TAG) 0x0026) +#define TPM_TAG_DELG_KEY_BLOB ((TPM_STRUCTURE_TAG) 0x0027) +#define TPM_TAG_KEY12 ((TPM_STRUCTURE_TAG) 0x0028) +#define TPM_TAG_CERTIFY_INFO2 ((TPM_STRUCTURE_TAG) 0x0029) +#define TPM_TAG_DELEGATE_OWNER_BLOB ((TPM_STRUCTURE_TAG) 0x002A) +#define TPM_TAG_EK_BLOB_ACTIVATE ((TPM_STRUCTURE_TAG) 0x002B) +#define TPM_TAG_DAA_BLOB ((TPM_STRUCTURE_TAG) 0x002C) +#define TPM_TAG_DAA_CONTEXT ((TPM_STRUCTURE_TAG) 0x002D) +#define TPM_TAG_DAA_ENFORCE ((TPM_STRUCTURE_TAG) 0x002E) +#define TPM_TAG_DAA_ISSUER ((TPM_STRUCTURE_TAG) 0x002F) +#define TPM_TAG_CAP_VERSION_INFO ((TPM_STRUCTURE_TAG) 0x0030) +#define TPM_TAG_DAA_SENSITIVE ((TPM_STRUCTURE_TAG) 0x0031) +#define TPM_TAG_DAA_TPM ((TPM_STRUCTURE_TAG) 0x0032) +#define TPM_TAG_CMK_MIGAUTH ((TPM_STRUCTURE_TAG) 0x0033) +#define TPM_TAG_CMK_SIGTICKET ((TPM_STRUCTURE_TAG) 0x0034) +#define TPM_TAG_CMK_MA_APPROVAL ((TPM_STRUCTURE_TAG) 0x0035) +#define TPM_TAG_QUOTE_INFO2 ((TPM_STRUCTURE_TAG) 0x0036) + +// +// Part 2, section 4: TPM Types +// + +// +// Part 2, section 4.1: TPM_RESOURCE_TYPE +// +#define TPM_RT_KEY ((TPM_RESOURCE_TYPE) 0x00000001) // The handle is a key handle and is the result of a LoadKey type operation +#define TPM_RT_AUTH ((TPM_RESOURCE_TYPE) 0x00000002) // The handle is an authorization handle. Auth handles come from TPM_OIAP, TPM_OSAP and TPM_DSAP +#define TPM_RT_HASH ((TPM_RESOURCE_TYPE) 0x00000003) // Reserved for hashes +#define TPM_RT_TRANS ((TPM_RESOURCE_TYPE) 0x00000004) // The handle is for a transport session. Transport handles come from TPM_EstablishTransport +#define TPM_RT_CONTEXT ((TPM_RESOURCE_TYPE) 0x00000005) // Resource wrapped and held outside the TPM using the context save/restore commands +#define TPM_RT_COUNTER ((TPM_RESOURCE_TYPE) 0x00000006) // Reserved for counters +#define TPM_RT_DELEGATE ((TPM_RESOURCE_TYPE) 0x00000007) // The handle is for a delegate row. These are the internal rows held in NV storage by the TPM +#define TPM_RT_DAA_TPM ((TPM_RESOURCE_TYPE) 0x00000008) // The value is a DAA TPM specific blob +#define TPM_RT_DAA_V0 ((TPM_RESOURCE_TYPE) 0x00000009) // The value is a DAA V0 parameter +#define TPM_RT_DAA_V1 ((TPM_RESOURCE_TYPE) 0x0000000A) // The value is a DAA V1 parameter + +// +// Part 2, section 4.2: TPM_PAYLOAD_TYPE +// +#define TPM_PT_ASYM ((TPM_PAYLOAD_TYPE) 0x01) // The entity is an asymmetric key +#define TPM_PT_BIND ((TPM_PAYLOAD_TYPE) 0x02) // The entity is bound data +#define TPM_PT_MIGRATE ((TPM_PAYLOAD_TYPE) 0x03) // The entity is a migration blob +#define TPM_PT_MAINT ((TPM_PAYLOAD_TYPE) 0x04) // The entity is a maintenance blob +#define TPM_PT_SEAL ((TPM_PAYLOAD_TYPE) 0x05) // The entity is sealed data +#define TPM_PT_MIGRATE_RESTRICTED ((TPM_PAYLOAD_TYPE) 0x06) // The entity is a restricted-migration asymmetric key +#define TPM_PT_MIGRATE_EXTERNAL ((TPM_PAYLOAD_TYPE) 0x07) // The entity is a external migratable key +#define TPM_PT_CMK_MIGRATE ((TPM_PAYLOAD_TYPE) 0x08) // The entity is a CMK migratable blob +#define TPM_PT_VENDOR_SPECIFIC ((TPM_PAYLOAD_TYPE) 0x80) // 0x80 - 0xFF Vendor specific payloads + +// +// Part 2, section 4.3: TPM_ENTIRY_TYPE +// +#define TPM_ET_KEYHANDLE ((UINT16) 0x0001) // The entity is a keyHandle or key +#define TPM_ET_OWNER ((UINT16) 0x0002) // The entity is the TPM Owner +#define TPM_ET_DATA ((UINT16) 0x0003) // The entity is some data +#define TPM_ET_SRK ((UINT16) 0x0004) // The entity is the SRK +#define TPM_ET_KEY ((UINT16) 0x0005) // The entity is a key or keyHandle +#define TPM_ET_REVOKE ((UINT16) 0x0006) // The entity is the RevokeTrust value +#define TPM_ET_DEL_OWNER_BLOB ((UINT16) 0x0007) // The entity is a delegate owner blob +#define TPM_ET_DEL_ROW ((UINT16) 0x0008) // The entity is a delegate row +#define TPM_ET_DEL_KEY_BLOB ((UINT16) 0x0009) // The entity is a delegate key blob +#define TPM_ET_COUNTER ((UINT16) 0x000A) // The entity is a counter +#define TPM_ET_NV ((UINT16) 0x000B) // The entity is a NV index +#define TPM_ET_RESERVED_HANDLE ((UINT16) 0x0040) // Reserved. This value avoids collisions with the handle MSB setting. +// +// TPM_ENTITY_TYPE MSB Values: The MSB is used to indicate the ADIP encryption sheme when applicable +// +#define TPM_ET_XOR ((UINT16) 0x0000) // ADIP encryption scheme: XOR +#define TPM_ET_AES128 ((UINT16) 0x0006) // ADIP encryption scheme: AES 128 bits + +// +// Part 2, section 4.4.1: Reserved Key Handles +// +#define TPM_KH_SRK ((TPM_KEY_HANDLE) 0x40000000) // The handle points to the SRK +#define TPM_KH_OWNER ((TPM_KEY_HANDLE) 0x40000001) // The handle points to the TPM Owner +#define TPM_KH_REVOKE ((TPM_KEY_HANDLE) 0x40000002) // The handle points to the RevokeTrust value +#define TPM_KH_TRANSPORT ((TPM_KEY_HANDLE) 0x40000003) // The handle points to the EstablishTransport static authorization +#define TPM_KH_OPERATOR ((TPM_KEY_HANDLE) 0x40000004) // The handle points to the Operator auth +#define TPM_KH_ADMIN ((TPM_KEY_HANDLE) 0x40000005) // The handle points to the delegation administration auth +#define TPM_KH_EK ((TPM_KEY_HANDLE) 0x40000006) // The handle points to the PUBEK, only usable with TPM_OwnerReadInternalPub + +// +// Part 2, section 4.5: TPM_STARTUP_TYPE +// +#define TPM_ST_CLEAR ((TPM_STARTUP_TYPE) 0x0001) // The TPM is starting up from a clean state +#define TPM_ST_STATE ((TPM_STARTUP_TYPE) 0x0002) // The TPM is starting up from a saved state +#define TPM_ST_DEACTIVATED ((TPM_STARTUP_TYPE) 0x0003) // The TPM is to startup and set the deactivated flag to TRUE + +// +// Part 2, section 4.6: TPM_STATUP_EFFECTS +// The table makeup is still an open issue. +// + +// +// Part 2, section 4.7: TPM_PROTOCOL_ID +// +#define TPM_PID_OIAP ((TPM_PROTOCOL_ID) 0x0001) // The OIAP protocol. +#define TPM_PID_OSAP ((TPM_PROTOCOL_ID) 0x0002) // The OSAP protocol. +#define TPM_PID_ADIP ((TPM_PROTOCOL_ID) 0x0003) // The ADIP protocol. +#define TPM_PID_ADCP ((TPM_PROTOCOL_ID) 0x0004) // The ADCP protocol. +#define TPM_PID_OWNER ((TPM_PROTOCOL_ID) 0x0005) // The protocol for taking ownership of a TPM. +#define TPM_PID_DSAP ((TPM_PROTOCOL_ID) 0x0006) // The DSAP protocol +#define TPM_PID_TRANSPORT ((TPM_PROTOCOL_ID) 0x0007) // The transport protocol + +// +// Part 2, section 4.8: TPM_ALGORITHM_ID +// The TPM MUST support the algorithms TPM_ALG_RSA, TPM_ALG_SHA, TPM_ALG_HMAC, +// TPM_ALG_MGF1 +// +#define TPM_ALG_RSA ((TPM_ALGORITHM_ID) 0x00000001) // The RSA algorithm. +#define TPM_ALG_DES ((TPM_ALGORITHM_ID) 0x00000002) // The DES algorithm +#define TPM_ALG_3DES ((TPM_ALGORITHM_ID) 0x00000003) // The 3DES algorithm in EDE mode +#define TPM_ALG_SHA ((TPM_ALGORITHM_ID) 0x00000004) // The SHA1 algorithm +#define TPM_ALG_HMAC ((TPM_ALGORITHM_ID) 0x00000005) // The RFC 2104 HMAC algorithm +#define TPM_ALG_AES128 ((TPM_ALGORITHM_ID) 0x00000006) // The AES algorithm, key size 128 +#define TPM_ALG_MGF1 ((TPM_ALGORITHM_ID) 0x00000007) // The XOR algorithm using MGF1 to create a string the size of the encrypted block +#define TPM_ALG_AES192 ((TPM_ALGORITHM_ID) 0x00000008) // AES, key size 192 +#define TPM_ALG_AES256 ((TPM_ALGORITHM_ID) 0x00000009) // AES, key size 256 +#define TPM_ALG_XOR ((TPM_ALGORITHM_ID) 0x0000000A) // XOR using the rolling nonces + +// +// Part 2, section 4.9: TPM_PHYSICAL_PRESENCE +// +#define TPM_PHYSICAL_PRESENCE_HW_DISABLE ((TPM_PHYSICAL_PRESENCE) 0x0200) // Sets the physicalPresenceHWEnable to FALSE +#define TPM_PHYSICAL_PRESENCE_CMD_DISABLE ((TPM_PHYSICAL_PRESENCE) 0x0100) // Sets the physicalPresenceCMDEnable to FALSE +#define TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK ((TPM_PHYSICAL_PRESENCE) 0x0080) // Sets the physicalPresenceLifetimeLock to TRUE +#define TPM_PHYSICAL_PRESENCE_HW_ENABLE ((TPM_PHYSICAL_PRESENCE) 0x0040) // Sets the physicalPresenceHWEnable to TRUE +#define TPM_PHYSICAL_PRESENCE_CMD_ENABLE ((TPM_PHYSICAL_PRESENCE) 0x0020) // Sets the physicalPresenceCMDEnable to TRUE +#define TPM_PHYSICAL_PRESENCE_NOTPRESENT ((TPM_PHYSICAL_PRESENCE) 0x0010) // Sets PhysicalPresence = FALSE +#define TPM_PHYSICAL_PRESENCE_PRESENT ((TPM_PHYSICAL_PRESENCE) 0x0008) // Sets PhysicalPresence = TRUE +#define TPM_PHYSICAL_PRESENCE_LOCK ((TPM_PHYSICAL_PRESENCE) 0x0004) // Sets PhysicalPresenceLock = TRUE + +// +// Part 2, section 4.10: TPM_MIGRATE_SCHEME +// +#define TPM_MS_MIGRATE ((TPM_MIGRATE_SCHEME) 0x0001) // A public key that can be used with all TPM migration commands other than 'ReWrap' mode. +#define TPM_MS_REWRAP ((TPM_MIGRATE_SCHEME) 0x0002) // A public key that can be used for the ReWrap mode of TPM_CreateMigrationBlob. +#define TPM_MS_MAINT ((TPM_MIGRATE_SCHEME) 0x0003) // A public key that can be used for the Maintenance commands +#define TPM_MS_RESTRICT_MIGRATE ((TPM_MIGRATE_SCHEME) 0x0004) // The key is to be migrated to a Migration Authority. +#define TPM_MS_RESTRICT_APPROVE_DOUBLE ((TPM_MIGRATE_SCHEME) 0x0005) // The key is to be migrated to an entity approved by a Migration Authority using double wrapping + +// +// Part 2, section 4.11: TPM_EK_TYPE +// +#define TPM_EK_TYPE_ACTIVATE ((TPM_EK_TYPE) 0x0001) // The blob MUST be TPM_EK_BLOB_ACTIVATE +#define TPM_EK_TYPE_AUTH ((TPM_EK_TYPE) 0x0002) // The blob MUST be TPM_EK_BLOB_AUTH + +// +// Part 2, section 4.12: TPM_PLATFORM_SPECIFIC +// +#define TPM_PS_PC_11 ((TPM_PLATFORM_SPECIFIC) 0x0001) // PC Specific version 1.1 +#define TPM_PS_PC_12 ((TPM_PLATFORM_SPECIFIC) 0x0002) // PC Specific version 1.2 +#define TPM_PS_PDA_12 ((TPM_PLATFORM_SPECIFIC) 0x0003) // PDA Specific version 1.2 +#define TPM_PS_Server_12 ((TPM_PLATFORM_SPECIFIC) 0x0004) // Server Specific version 1.2 +#define TPM_PS_Mobile_12 ((TPM_PLATFORM_SPECIFIC) 0x0005) // Mobil Specific version 1.2 + +// +// Part 2, section 5: Basic Structures +// + +// +// Part 2, section 5.1: TPM_STRUCT_VER +// +typedef struct tdTPM_STRUCT_VER +{ + UINT8 major; + UINT8 minor; + UINT8 revMajor; + UINT8 revMinor; +} TPM_STRUCT_VER; + +// +// Part 2, section 5.3: TPM_VERSION +// +typedef struct tdTPM_VERSION +{ + TPM_VERSION_BYTE major; + TPM_VERSION_BYTE minor; + UINT8 revMajor; + UINT8 revMinor; +} TPM_VERSION; + + +// +// Part 2, section 5.4: TPM_DIGEST +// +#define TPM_SHA1_160_HASH_LEN 0x14 +#define TPM_SHA1BASED_NONCE_LEN TPM_SHA1_160_HASH_LEN + +#define TPM_SHA2_256_HASH_LEN 0x20 +#define TPM_SHA2BASED_NONCE_LEN TPM_SHA2_256_HASH_LEN + + +//redefine TPM digest into a UNION so that we can support +//sha1 and sha2 and other has functions at the same time +typedef struct tdTPM_DIGEST +{ + UINT8 digest[TPM_SHA1_160_HASH_LEN]; +} TPM_DIGEST; + +typedef struct tdTCM_DIGEST +{ + UINT8 digest[TPM_SHA2BASED_NONCE_LEN]; +} TCM_DIGEST; + + +typedef TPM_DIGEST TPM_CHOSENID_HASH; // This SHALL be the digest of the chosen identityLabel and privacyCA for a new TPM identity. +typedef TPM_DIGEST TPM_COMPOSITE_HASH; // This SHALL be the hash of a list of PCR indexes and PCR values that a key or data is bound to. +typedef TPM_DIGEST TPM_DIRVALUE; // This SHALL be the value of a DIR register +typedef TPM_DIGEST TPM_HMAC; +typedef TPM_DIGEST TPM_PCRVALUE; // The value inside of the PCR +typedef TPM_DIGEST TPM_AUDITDIGEST; // This SHALL be the value of the current internal audit state +typedef TPM_DIGEST TPM_DAA_TPM_SEED; // This SHALL be a random value generated by a TPM immediately after the EK is installed in that TPM, whenever an EK is installed in that TPM +typedef TPM_DIGEST TPM_DAA_CONTEXT_SEED; // This SHALL be a random value + +// +// Part 2, section 5.5: TPM_NONCE +// +typedef struct tdTPM_NONCE +{ + UINT8 nonce[20]; +} TPM_NONCE; + +// +// Part 2, section 5.6: TPM_AUTHDATA +// +typedef UINT8 tdTPM_AUTHDATA[20]; +typedef tdTPM_AUTHDATA TPM_AUTHDATA; +typedef TPM_AUTHDATA TPM_SECRET; +typedef TPM_AUTHDATA TPM_ENCAUTH; + +// +// Part 2, section 5.7: TPM_KEY_HANDLE_LIST +// Size of handle is loaded * sizeof(TPM_KEY_HANDLE) +// +typedef struct tdTPM_KEY_HANDLE_LIST +{ + UINT16 loaded; + TPM_KEY_HANDLE handle[1]; +} TPM_KEY_HANDLE_LIST; + +// +// Part 2, section 5.8: TPM_KEY_USAGE values +// + +#define TPM_KEY_SIGNING ((UINT16) 0x0010) +// TPM_KEY_SIGNING SHALL indicate a signing key. The [private] key SHALL be +// used for signing operations, only. This means that it MUST be a leaf of the +// Protected Storage key hierarchy. + +#define TPM_KEY_STORAGE ((UINT16) 0x0011) +// TPM_KEY_STORAGE SHALL indicate a storage key. The key SHALL be used to wrap +// and unwrap other keys in the Protected Storage hierarchy + +#define TPM_KEY_IDENTITY ((UINT16) 0x0012) +// TPM_KEY_IDENTITY SHALL indicate an identity key. The key SHALL be used for +// operations that require a TPM identity, only. + +#define TPM_KEY_AUTHCHANGE ((UINT16) 0x0013) +// TPM_KEY_AUTHCHANGE SHALL indicate an ephemeral key that is in use during +// the ChangeAuthAsym process, only. + +#define TPM_KEY_BIND ((UINT16) 0x0014) +// TPM_KEY_BIND SHALL indicate a key that can be used for TPM_Bind and +// TPM_Unbind operations only. + +#define TPM_KEY_LEGACY ((UINT16) 0x0015) +// TPM_KEY_LEGACY SHALL indicate a key that can perform signing and binding +// operations. The key MAY be used for both signing and binding operations. +// The TPM_KEY_LEGACY key type is to allow for use by applications where both +// signing and encryption operations occur with the same key. The use of this +// key type is not recommended TPM_KEY_MIGRATE 0x0016 This SHALL indicate a +// key in use for TPM_MigrateKey + +#define TPM_KEY_MIGRATE ((UINT16) 0x0016) +// TPM_KEY_MIGRAGE SHALL indicate a key in use for TPM_MigrateKey + +// +// Part 2, section 5.8.1: Encryption/Signature schemes +// + +#define TPM_ES_NONE ((TPM_ENC_SCHEME) 0x0001) +#define TPM_ES_RSAESPKCSv15 ((TPM_ENC_SCHEME) 0x0002) +#define TPM_ES_RSAESOAEP_SHA1_MGF1 ((TPM_ENC_SCHEME) 0x0003) +#define TPM_ES_SYM_CNT ((TPM_ENC_SCHEME) 0x0004) +#define TPM_ES_SYM_OFB ((TPM_ENC_SCHEME) 0x0005) + +#define TPM_SS_NONE ((TPM_SIG_SCHEME) 0x0001) +#define TPM_SS_RSASSAPKCS1v15_SHA1 ((TPM_SIG_SCHEME) 0x0002) +#define TPM_SS_RSASSAPKCS1v15_DER ((TPM_SIG_SCHEME) 0x0003) +#define TPM_SS_RSASSAPKCS1v15_INFO ((TPM_SIG_SCHEME) 0x0004) + +// +// Part 2, section 5.9: TPM_AUTH_DATA_USAGE values +// +#define TPM_AUTH_NEVER ((TPM_AUTH_DATA_USAGE) 0x00) +#define TPM_AUTH_ALWAYS ((TPM_AUTH_DATA_USAGE) 0x01) +#define TPM_AUTH_PRIV_USE_ONLY ((TPM_AUTH_DATA_USAGE) 0x03) + +// +// Part 2, section 5.10: TPM_KEY_FLAGS +// +enum tdTPM_KEY_FLAGS +{ + redirection = 0x00000001, + migratable = 0x00000002, + isVolatile = 0x00000004, + pcrIgnoredOnRead = 0x00000008, + migrateAuthority = 0x00000010 +}; + +// +// Part 2, section 5.11: TPM_CHANGEAUTH_VALIDATE +// +typedef struct tdTPM_CHANGEAUTH_VALIDATE +{ + TPM_SECRET newAuthSecret; + TPM_NONCE n1; +} TPM_CHANGEAUTH_VALIDATE; + +// +// Part 2, section 5.12: TPM_MIGRATIONKEYAUTH +// decalared after section 10 to catch declaration of TPM_PUBKEY +// +// Part 2 section 10.1: TPM_KEY_PARMS +// [size_is(parmSize)] BYTE* parms; +// +typedef struct tdTPM_KEY_PARMS +{ + TPM_ALGORITHM_ID algorithmID; + TPM_ENC_SCHEME encScheme; + TPM_SIG_SCHEME sigScheme; + UINT32 parmSize; + UINT8 *parms; +} TPM_KEY_PARMS; + +// +// Part 2, section 10.4: TPM_STORE_PUBKEY +// +typedef struct tdTPM_STORE_PUBKEY +{ + UINT32 keyLength; + UINT8 key[1]; +} TPM_STORE_PUBKEY; + +// +// Part 2, section 10.5: TPM_PUBKEY +// +typedef struct tdTPM_PUBKEY +{ + TPM_KEY_PARMS algorithmParms; + TPM_STORE_PUBKEY pubKey; +} TPM_PUBKEY; + +// +// Part 2, section 5.12: TPM_MIGRATIONKEYAUTH +// +typedef struct tdTPM_MIGRATIONKEYAUTH +{ + TPM_PUBKEY migrationKey; + TPM_MIGRATE_SCHEME migrationScheme; + TPM_DIGEST digest; +} TPM_MIGRATIONKEYAUTH; + +// +// Part 2, section 5.13: TPM_COUNTER_VALUE +// +typedef struct tdTPM_COUNTER_VALUE +{ + TPM_STRUCTURE_TAG tag; + UINT8 label[4]; + TPM_ACTUAL_COUNT counter; +} TPM_COUNTER_VALUE; + +// +// Part 2, section 5.14: TPM_SIGN_INFO +// Size of data indicated by dataLen +// +typedef struct tdTPM_SIGN_INFO +{ + TPM_STRUCTURE_TAG tag; + UINT8 fixed[4]; + TPM_NONCE replay; + UINT32 dataLen; + UINT8 *data; +} TPM_SIGN_INFO; + +// +// Part 2, section 5.15: TPM_MSA_COMPOSITE +// Number of migAuthDigest indicated by MSAlist +// +typedef struct tdTPM_MSA_COMPOSITE +{ + UINT32 MSAlist; + TPM_DIGEST migAuthDigest[1]; +} TPM_MSA_COMPOSITE; + +// +// Part 2, section 5.16: TPM_CMK_AUTH +// +typedef struct tdTPM_CMK_AUTH +{ + TPM_DIGEST migrationAuthorityDigest; + TPM_DIGEST destinationKeyDigest; + TPM_DIGEST sourceKeyDigest; +} TPM_CMK_AUTH; + +// +// Part 2, section 5.17: TPM_CMK_DELEGATE +// +#define TPM_CMK_DELEGATE_SIGNING (((TPM_CMK_DELEGATE)1) << 31) +#define TPM_CMK_DELEGATE_STORAGE (((TPM_CMK_DELEGATE)1) << 30) +#define TPM_CMK_DELEGATE_BIND (((TPM_CMK_DELEGATE)1) << 29) +#define TPM_CMK_DELEGATE_LEGACY (((TPM_CMK_DELEGATE)1) << 28) +#define TPM_CMK_DELEGATE_MIGRATE (((TPM_CMK_DELEGATE)1) << 27) + +// +// Part 2, section 5.18: TPM_SELECT_SIZE +// +typedef struct tdTPM_SELECT_SIZE +{ + UINT8 major; + UINT8 minor; + UINT16 reqSize; +} TPM_SELECT_SIZE; + +// +// Part 2, section 5,19: TPM_CMK_MIGAUTH +// +typedef struct tdTPM_CMK_MIGAUTH +{ + TPM_STRUCTURE_TAG tag; + TPM_DIGEST msaDigest; + TPM_DIGEST pubKeyDigest; +} TPM_CMK_MIGAUTH; + +// +// Part 2, section 5.20: TPM_CMK_SIGTICKET +// +typedef struct tdTPM_CMK_SIGTICKET +{ + TPM_STRUCTURE_TAG tag; + TPM_DIGEST verKeyDigest; + TPM_DIGEST signedData; +} TPM_CMK_SIGTICKET; + +// +// Part 2, section 5.21: TPM_CMK_MA_APPROVAL +// +typedef struct tdTPM_CMK_MA_APPROVAL +{ + TPM_STRUCTURE_TAG tag; + TPM_DIGEST migrationAuthorityDigest; +} TPM_CMK_MA_APPROVAL; + +// +// Part 2, section 6: Command Tags +// +#define TPM_TAG_RQU_COMMAND ((TPM_STRUCTURE_TAG) 0x00C1) +#define TPM_TAG_RQU_AUTH1_COMMAND ((TPM_STRUCTURE_TAG) 0x00C2) +#define TPM_TAG_RQU_AUTH2_COMMAND ((TPM_STRUCTURE_TAG) 0x00C3) +#define TPM_TAG_RSP_COMMAND ((TPM_STRUCTURE_TAG) 0x00C4) +#define TPM_TAG_RSP_AUTH1_COMMAND ((TPM_STRUCTURE_TAG) 0x00C5) +#define TPM_TAG_RSP_AUTH2_COMMAND ((TPM_STRUCTURE_TAG) 0x00C6) + +// +// Part 2, section 7.1: TPM_PERMANENT_FLAGS +// +typedef struct tdTPM_PERMANENT_FLAGS +{ + TPM_STRUCTURE_TAG tag; + BOOLEAN disable; + BOOLEAN ownership; + BOOLEAN deactivated; + BOOLEAN readPubek; + BOOLEAN disableOwnerClear; + BOOLEAN allowMaintenance; + BOOLEAN physicalPresenceLifetimeLock; + BOOLEAN physicalPresenceHWEnable; + BOOLEAN physicalPresenceCMDEnable; + BOOLEAN CEKPUsed; + BOOLEAN TPMpost; + BOOLEAN TPMpostLock; + BOOLEAN FIPS; + BOOLEAN operator; + BOOLEAN enableRevokeEK; + BOOLEAN nvLocked; + BOOLEAN readSRKPub; + BOOLEAN tpmEstablished; + BOOLEAN maintenanceDone; +} TPM_PERMANENT_FLAGS; + +// +// Part 2, section 7.1.1: PERMANENT_FLAGS Subcap for SetCapability +// +#define TPM_PF_DISABLE ((TPM_CAPABILITY_AREA) 1) +#define TPM_PF_OWNERSHIP ((TPM_CAPABILITY_AREA) 2) +#define TPM_PF_DEACTIVATED ((TPM_CAPABILITY_AREA) 3) +#define TPM_PF_READPUBEK ((TPM_CAPABILITY_AREA) 4) +#define TPM_PF_DISABLEOWNERCLEAR ((TPM_CAPABILITY_AREA) 5) +#define TPM_PF_ALLOWMAINTENANCE ((TPM_CAPABILITY_AREA) 6) +#define TPM_PF_PHYSICALPRESENCELIFETIMELOCK ((TPM_CAPABILITY_AREA) 7) +#define TPM_PF_PHYSICALPRESENCEHWENABLE ((TPM_CAPABILITY_AREA) 8) +#define TPM_PF_PHYSICALPRESENCECMDENABLE ((TPM_CAPABILITY_AREA) 9) +#define TPM_PF_CEKPUSED ((TPM_CAPABILITY_AREA) 10) +#define TPM_PF_TPMPOST ((TPM_CAPABILITY_AREA) 11) +#define TPM_PF_TPMPOSTLOCK ((TPM_CAPABILITY_AREA) 12) +#define TPM_PF_FIPS ((TPM_CAPABILITY_AREA) 13) +#define TPM_PF_OPERATOR ((TPM_CAPABILITY_AREA) 14) +#define TPM_PF_ENABLEREVOKEEK ((TPM_CAPABILITY_AREA) 15) +#define TPM_PF_NV_LOCKED ((TPM_CAPABILITY_AREA) 16) +#define TPM_PF_READSRKPUB ((TPM_CAPABILITY_AREA) 17) +#define TPM_PF_TPMESTABLISHED ((TPM_CAPABILITY_AREA) 18) +#define TPM_PF_MAINTENANCEDONE ((TPM_CAPABILITY_AREA) 19) + +// +// Part 2, section 7.2: TPM_STCLEAR_FLAGS +// +typedef struct tdTPM_STCLEAR_FLAGS +{ + TPM_STRUCTURE_TAG tag; + BOOLEAN deactivated; + BOOLEAN disableForceClear; + BOOLEAN physicalPresence; + BOOLEAN physicalPresenceLock; + BOOLEAN bGlobalLock; +} TPM_STCLEAR_FLAGS; + +// +// Part 2, section 7.2.1: STCLEAR_FLAGS Subcap for SetCapability +// +#define TPM_SF_DEACTIVATED ((TPM_CAPABILITY_AREA) 1) +#define TPM_SF_DISABLEFORCECLEAR ((TPM_CAPABILITY_AREA) 2) +#define TPM_SF_PHYSICALPRESENCE ((TPM_CAPABILITY_AREA) 3) +#define TPM_SF_PHYSICALPRESENCELOCK ((TPM_CAPABILITY_AREA) 4) +#define TPM_SF_BGLOBALLOCK ((TPM_CAPABILITY_AREA) 5) + +// +// Part 2, section 7.3: TPM_STANY_FLAGS +// +typedef struct tdTPM_STANY_FLAGS +{ + TPM_STRUCTURE_TAG tag; + BOOLEAN postInitialise; + TPM_MODIFIER_INDICATOR localityModifier; + BOOLEAN transportExclusive; + BOOLEAN TOSPresent; +} TPM_STANY_FLAGS; + +// +// Part 2, section 7.3.1: STANY_FLAGS Subcap for SetCapability +// +#define TPM_AF_POSTINITIALISE ((TPM_CAPABILITY_AREA) 1) +#define TPM_AF_LOCALITYMODIFIER ((TPM_CAPABILITY_AREA) 2) +#define TPM_AF_TRANSPORTEXCLUSIVE ((TPM_CAPABILITY_AREA) 3) +#define TPM_AF_TOSPRESENT ((TPM_CAPABILITY_AREA) 4) + +// +// All those structures (section 7.4, 7.5, 7.6) are not normative and +// thus no definitions here +// +// Part 2, section 7.4: TPM_PERMANENT_DATA +// +//#define TPM_MIN_COUNTERS 4 // the minimum number of counters is 4 +//#define TPM_DELEGATE_KEY TPM_KEY +//#define TPM_NUM_PCR 16 +//#define TPM_MAX_NV_WRITE_NOOWNER 64 +//typedef struct tdTPM_PERMANENT_DATA +//{ +// TPM_STRUCTURE_TAG tag; +// UINT8 revMajor; +// UINT8 revMinor; +// TPM_NONCE tpmProof; +// TPM_NONCE ekReset; +// TPM_SECRET ownerAuth; +// TPM_SECRET operatorAuth; +// TPM_DIRVALUE authDIR[1]; +// TPM_PUBKEY manuMaintPub; +// TPM_KEY endorsementKey; +// TPM_KEY srk; +// TPM_KEY contextKey; +// TPM_KEY delegateKey; +// TPM_COUNTER_VALUE auditMonotonicCounter; +// TPM_COUNTER_VALUE monitonicCounter[TPM_MIN_COUNTERS]; +// TPM_PCR_ATTRIBUTES pcrAttrib[TPM_NUM_PCR]; +// UINT8 ordinalAuditStatus[]; +// UINT8 *rngState; +// TPM_FAMILY_TABLE familyTable; +// TPM_DELEGATE_TABLE delegateTable; +// UINT32 maxNVBufSize; +// UINT32 lastFamilyID; +// UINT32 noOwnerNVWrite; +// TPM_CMK_DELEGATE restrictDelegate; +// TPM_DAA_TPM_SEED tpmDAASeed; +//} TPM_PERMANENT_DATA; + +// +// Part 2, section 7.5: TPM_STCLEAR_DATA +// available inside TPM only +// +//typedef struct tdTPM_STCLEAR_DATA +//{ +// TPM_STRUCTURE_TAG tag; +// TPM_NONCE contextNonceKey; +// TPM_COUNT_ID countID; +// UINT32 ownerReference; +// BOOLEAN disableResetLock; +//} TPM_STCLEAR_DATA; + +// +// Part 2, section 7.6: TPM_STANY_DATA +// available inside TPM only +// +//typedef struct tdTPM_STANY_DATA +//{ +// TPM_STRUCTURE_TAG tag; +// TPM_NONCE contextNonceSession; +// TPM_DIGEST auditDigest; +// TPM_CURRENT_TICKS currentTicks; +// UINT32 contextCount; +// UINT32 contextList[TPM_MIN_SESSION_LIST]; +// TPM_SESSION_DATA sessions[TPM_MIN_SESSIONS]; +//} TPM_STANY_DATA; + +// +// Part 2, section 8: PCR Structures +// + +// +// Part 2, section 8.1: TPM_PCR_SELECTION +// Size of pcrSelect[] indicated by sizeOfSelect +// +typedef struct tdTPM_PCR_SELECTION +{ + UINT16 sizeOfSelect; + UINT8 pcrSelect[1]; +} TPM_PCR_SELECTION; + +// +// Part 2, section 8.2: TPM_PCR_COMPOSITE +// Size of pcrValue[] indicated by valueSize +// +typedef struct tdTPM_PCR_COMPOSITE +{ + TPM_PCR_SELECTION select; + UINT32 valueSize; + TPM_PCRVALUE pcrValue[1]; +} TPM_PCR_COMPOSITE; + +// +// Part 2, section 8.3: TPM_PCR_INFO +// +typedef struct tdTPM_PCR_INFO +{ + TPM_PCR_SELECTION pcrSelection; + TPM_COMPOSITE_HASH digestAtRelease; + TPM_COMPOSITE_HASH digestAtCreation; +} TPM_PCR_INFO; + +// +// Part 2, section 8.6: TPM_LOCALITY_SELECTION +// +typedef UINT8 TPM_LOCALITY_SELECTION; + +#define TPM_LOC_FOUR ((UINT8) 0x10) +#define TPM_LOC_THREE ((UINT8) 0x08) +#define TPM_LOC_TWO ((UINT8) 0x04) +#define TPM_LOC_ONE ((UINT8) 0x02) +#define TPM_LOC_ZERO ((UINT8) 0x01) + +// +// Part 2, section 8.4: TPM_PCR_INFO_LONG +// +typedef struct tdTPM_PCR_INFO_LONG +{ + TPM_STRUCTURE_TAG tag; + TPM_LOCALITY_SELECTION localityAtCreation; + TPM_LOCALITY_SELECTION localityAtRelease; + TPM_PCR_SELECTION creationPCRSelection; + TPM_PCR_SELECTION releasePCRSelection; + TPM_COMPOSITE_HASH digestAtCreation; + TPM_COMPOSITE_HASH digestAtRelease; +} TPM_PCR_INFO_LONG; + +// +// Part 2, section 8.5: TPM_PCR_INFO_SHORT +// +typedef struct tdTPM_PCR_INFO_SHORT +{ + TPM_PCR_SELECTION pcrSelection; + TPM_LOCALITY_SELECTION localityAtRelease; + TPM_COMPOSITE_HASH digestAtRelease; +} TPM_PCR_INFO_SHORT; + +// +// Part 2, section 8.8: TPM_PCR_ATTRIBUTES +// +typedef struct tdTPM_PCR_ATTRIBUTES +{ + BOOLEAN pcrReset; + TPM_LOCALITY_SELECTION pcrExtendLocal; + TPM_LOCALITY_SELECTION pcrResetLocal; +} TPM_PCR_ATTRIBUTES; + +// +// Part 2, section 9: Storage Structures +// + +// +// Part 2, section 9.1: TPM_STORED_DATA +// [size_is(sealInfoSize)] BYTE* sealInfo; +// [size_is(encDataSize)] BYTE* encData; +// +typedef struct tdTPM_STORED_DATA +{ + TPM_STRUCT_VER ver; + UINT32 sealInfoSize; + UINT8 *sealInfo; + UINT32 encDataSize; + UINT8 *encData; +} TPM_STORED_DATA; + +// +// Part 2, section 9.2: TPM_STORED_DATA12 +// [size_is(sealInfoSize)] BYTE* sealInfo; +// [size_is(encDataSize)] BYTE* encData; +// +typedef struct tdTPM_STORED_DATA12 +{ + TPM_STRUCTURE_TAG tag; + TPM_ENTITY_TYPE et; + UINT32 sealInfoSize; + UINT8 *sealInfo; + UINT32 encDataSize; + UINT8 *encData; +} TPM_STORED_DATA12; + +// +// Part 2, section 9.3: TPM_SEALED_DATA +// [size_is(dataSize)] BYTE* data; +// +typedef struct tdTPM_SEALED_DATA +{ + TPM_PAYLOAD_TYPE payload; + TPM_SECRET authData; + TPM_NONCE tpmProof; + TPM_DIGEST storedDigest; + UINT32 dataSize; + UINT8 *data; +} TPM_SEALED_DATA; + +// +// Part 2, section 9.4: TPM_SYMMETRIC_KEY +// [size_is(size)] BYTE* data; +// +typedef struct tdTPM_SYMMETRIC_KEY +{ + TPM_ALGORITHM_ID algId; + TPM_ENC_SCHEME encScheme; + UINT16 dataSize; + UINT8 *data; +} TPM_SYMMETRIC_KEY; + +// +// Part 2, section 9.5: TPM_BOUND_DATA +// +typedef struct tdTPM_BOUND_DATA +{ + TPM_STRUCT_VER ver; + TPM_PAYLOAD_TYPE payload; + UINT8 payloadData[1]; +} TPM_BOUND_DATA; + +// +// Part 2 section 10: TPM_KEY complex +// + +// +// Part 2, section 10.2: TPM_KEY +// [size_is(encDataSize)] BYTE* encData; +// +typedef struct tdTPM_KEY +{ + TPM_STRUCT_VER ver; + TPM_KEY_USAGE keyUsage; + TPM_KEY_FLAGS keyFlags; + TPM_AUTH_DATA_USAGE authDataUsage; + TPM_KEY_PARMS algorithmParms; + UINT32 PCRInfoSize; + UINT8 *PCRInfo; + TPM_STORE_PUBKEY pubKey; + UINT32 encDataSize; + UINT8 *encData; +} TPM_KEY; + +// +// Part 2, section 10.3: TPM_KEY12 +// [size_is(encDataSize)] BYTE* encData; +// +typedef struct tdTPM_KEY12 +{ + TPM_STRUCTURE_TAG tag; + UINT16 fill; + TPM_KEY_USAGE keyUsage; + TPM_KEY_FLAGS keyFlags; + TPM_AUTH_DATA_USAGE authDataUsage; + TPM_KEY_PARMS algorithmParms; + UINT32 PCRInfoSize; + UINT8 *PCRInfo; + TPM_STORE_PUBKEY pubKey; + UINT32 encDataSize; + UINT8 *encData; +} TPM_KEY12; + +// +// Part 2, section 10.7: TPM_STORE_PRIVKEY +// [size_is(keyLength)] BYTE* key; +// +typedef struct tdTPM_STORE_PRIVKEY +{ + UINT32 keyLength; + UINT8 *key; +} TPM_STORE_PRIVKEY; + +// +// Part 2, section 10.6: TPM_STORE_ASYMKEY +// +typedef struct tdTPM_STORE_ASYMKEY // pos len total +{ + TPM_PAYLOAD_TYPE payload; // 0 1 1 + TPM_SECRET usageAuth; // 1 20 21 + TPM_SECRET migrationAuth; // 21 20 41 + TPM_DIGEST pubDataDigest; // 41 20 61 + TPM_STORE_PRIVKEY privKey; // 61 132-151 193-214 +} TPM_STORE_ASYMKEY; + +// +// Part 2, section 10.8: TPM_MIGRATE_ASYMKEY +// [size_is(partPrivKeyLen)] BYTE* partPrivKey; +// +typedef struct tdTPM_MIGRATE_ASYMKEY // pos len total +{ + TPM_PAYLOAD_TYPE payload; // 0 1 1 + TPM_SECRET usageAuth; // 1 20 21 + TPM_DIGEST pubDataDigest; // 21 20 41 + UINT32 partPrivKeyLen; // 41 4 45 + UINT8 *partPrivKey; // 45 112-127 157-172 +} TPM_MIGRATE_ASYMKEY; + +// +// Part 2, section 10.9: TPM_KEY_CONTROL +// +#define TPM_KEY_CONTROL_OWNER_EVICT ((UINT32) 0x00000001) +#define TPM_CAP_FLAG_STANY 0X0000011D + +// +// Part 2, section 11: Signed Structures +// + +typedef struct tdTPM_CERTIFY_INFO +{ + TPM_STRUCT_VER version; + TPM_KEY_USAGE keyUsage; + TPM_KEY_FLAGS keyFlags; + TPM_AUTH_DATA_USAGE authDataUsage; + TPM_KEY_PARMS algorithmParms; + TPM_DIGEST pubkeyDigest; + TPM_NONCE data; + BOOLEAN parentPCRStatus; + UINT32 PCRInfoSize; + UINT8 *PCRInfo; +} TPM_CERTIFY_INFO; + +typedef struct tdTPM_CERTIFY_INFO2 +{ + TPM_STRUCTURE_TAG tag; + UINT8 fill; + TPM_PAYLOAD_TYPE payloadType; + TPM_KEY_USAGE keyUsage; + TPM_KEY_FLAGS keyFlags; + TPM_AUTH_DATA_USAGE authDataUsage; + TPM_KEY_PARMS algorithmParms; + TPM_DIGEST pubkeyDigest; + TPM_NONCE data; + BOOLEAN parentPCRStatus; + UINT32 PCRInfoSize; + UINT8 *PCRInfo; + UINT32 migrationAuthoritySize; + UINT8 *migrationAuthority; +} TPM_CERTIFY_INFO2; + +typedef struct tdTPM_QUOTE_INFO +{ + TPM_STRUCT_VER version; + UINT8 fixed[4]; + TPM_COMPOSITE_HASH digestValue; + TPM_NONCE externalData; +} TPM_QUOTE_INFO; + +typedef struct tdTPM_QUOTE_INFO2 +{ + TPM_STRUCTURE_TAG tag; + UINT8 fixed[4]; + TPM_NONCE externalData; + TPM_PCR_INFO_SHORT infoShort; +} TPM_QUOTE_INFO2; + +// +// Part 2, section 12: Identity Structures +// + +typedef struct tdTPM_EK_BLOB +{ + TPM_STRUCTURE_TAG tag; + TPM_EK_TYPE ekType; + UINT32 blobSize; + UINT8 *blob; +} TPM_EK_BLOB; + +typedef struct tdTPM_EK_BLOB_ACTIVATE +{ + TPM_STRUCTURE_TAG tag; + TPM_SYMMETRIC_KEY sessionKey; + TPM_DIGEST idDigest; + TPM_PCR_INFO_SHORT pcrInfo; +} TPM_EK_BLOB_ACTIVATE; + +typedef struct tdTPM_EK_BLOB_AUTH +{ + TPM_STRUCTURE_TAG tag; + TPM_SECRET authValue; +} TPM_EK_BLOB_AUTH; + + +// TPM_CHOSENID_HASH = SHA(identityLabel || privacyCA) +typedef TPM_DIGEST TPM_CHOSENID_HASH; + +typedef struct tdTPM_IDENTITY_CONTENTS +{ + TPM_STRUCT_VER ver; + UINT32 ordinal; + TPM_CHOSENID_HASH labelPrivCADigest; + TPM_PUBKEY identityPubKey; +} TPM_IDENTITY_CONTENTS; + +typedef struct tdTPM_IDENTITY_REQ +{ + UINT32 asymSize; + UINT32 symSize; + TPM_KEY_PARMS asymAlgorithm; + TPM_KEY_PARMS symAlgorithm; + UINT8 *asymBlob; + UINT8 *symBlob; +} TPM_IDENTITY_REQ; + +typedef struct tdTPM_IDENTITY_PROOF +{ + TPM_STRUCT_VER ver; + UINT32 labelSize; + UINT32 identityBindingSize; + UINT32 endorsementSize; + UINT32 platformSize; + UINT32 conformanceSize; + TPM_PUBKEY identityKey; + UINT8 *labelArea; + UINT8 *identityBinding; + UINT8 *endorsementCredential; + UINT8 *platformCredential; + UINT8 *conformanceCredential; +} TPM_IDENTITY_PROOF; + +typedef struct tdTPM_ASYM_CA_CONTENTS +{ + TPM_SYMMETRIC_KEY sessionKey; + TPM_DIGEST idDigest; +} TPM_ASYM_CA_CONTENTS; + +typedef struct tdTPM_SYM_CA_ATTESTATION +{ + UINT32 credSize; + TPM_KEY_PARMS algorithm; + UINT8 *credential; +} TPM_SYM_CA_ATTESTATION; + +// +// Part 2, section 15: TPM_CURRENT_TICKS +// Placed here out of order because definitions are used in section 13. +// +typedef struct tdTPM_CURRENT_TICKS +{ + TPM_STRUCTURE_TAG tag; + UINT64 currentTicks; + UINT16 tickRate; + TPM_NONCE tickNonce; +} TPM_CURRENT_TICKS; + +// +// Part 2, section 13: Transport structures +// + +#define TPM_TRANSPORT_ENCRYPT ((UINT32)0x00000001) +#define TPM_TRANSPORT_LOG ((UINT32)0x00000002) +#define TPM_TRANSPORT_EXCLUSIVE ((UINT32)0x00000004) + +typedef struct tdTPM_TRANSPORT_PUBLIC +{ + TPM_STRUCTURE_TAG tag; + TPM_TRANSPORT_ATTRIBUTES transAttributes; + TPM_ALGORITHM_ID algId; + TPM_ENC_SCHEME encScheme; +} TPM_TRANSPORT_PUBLIC; + +typedef struct tdTPM_TRANSPORT_INTERNAL +{ + TPM_STRUCTURE_TAG tag; + TPM_AUTHDATA authData; + TPM_TRANSPORT_PUBLIC transPublic; + TPM_TRANSHANDLE transHandle; + TPM_NONCE transNonceEven; + TPM_DIGEST transDigest; +} TPM_TRANSPORT_INTERNAL; + +typedef struct tdTPM_TRANSPORT_LOG_IN +{ + TPM_STRUCTURE_TAG tag; + TPM_DIGEST parameters; + TPM_DIGEST pubKeyHash; +} TPM_TRANSPORT_LOG_IN; + +typedef struct tdTPM_TRANSPORT_LOG_OUT +{ + TPM_STRUCTURE_TAG tag; + TPM_CURRENT_TICKS currentTicks; + TPM_DIGEST parameters; + TPM_MODIFIER_INDICATOR locality; +} TPM_TRANSPORT_LOG_OUT; + +typedef struct tdTPM_TRANSPORT_AUTH +{ + TPM_STRUCTURE_TAG tag; + TPM_AUTHDATA authData; +} TPM_TRANSPORT_AUTH; + +// +// Part 2, section 14: Audit Structures +// + +typedef struct tdTPM_AUDIT_EVENT_IN +{ + TPM_STRUCTURE_TAG tag; + TPM_DIGEST inputParms; + TPM_COUNTER_VALUE auditCount; +} TPM_AUDIT_EVENT_IN; + +typedef struct tdTPM_AUDIT_EVENT_OUT +{ + TPM_STRUCTURE_TAG tag; + TPM_COMMAND_CODE ordinal; + TPM_DIGEST outputParms; + TPM_COUNTER_VALUE auditCount; + TPM_RESULT returnCode; +} TPM_AUDIT_EVENT_OUT; + +// +// Part 2, section 16: Return Codes +// +#define TPM_BASE (EFI_MAX_BIT + (EFI_MAX_BIT >> 1)) + +#ifndef TPM_BASE + #error "TPM Error Codes require definition of TPM_BASE" +#endif + +#define TPM_VENDOR_ERROR TPM_Vendor_Specific32 +#define TPM_NON_FATAL 0x00000800 + +#define TPM_SUCCESS ((TPM_RESULT) TPM_BASE) +#define TPM_AUTHFAIL ((TPM_RESULT) (TPM_BASE + 1)) +#define TPM_BADINDEX ((TPM_RESULT) (TPM_BASE + 2)) +#define TPM_BAD_PARAMETER ((TPM_RESULT) (TPM_BASE + 3)) +#define TPM_AUDITFAILURE ((TPM_RESULT) (TPM_BASE + 4)) +#define TPM_CLEAR_DISABLED ((TPM_RESULT) (TPM_BASE + 5)) +#define TPM_DEACTIVATED ((TPM_RESULT) (TPM_BASE + 6)) +#define TPM_DISABLED ((TPM_RESULT) (TPM_BASE + 7)) +#define TPM_DISABLED_CMD ((TPM_RESULT) (TPM_BASE + 8)) +#define TPM_FAIL ((TPM_RESULT) (TPM_BASE + 9)) +#define TPM_BAD_ORDINAL ((TPM_RESULT) (TPM_BASE + 10)) +#define TPM_INSTALL_DISABLED ((TPM_RESULT) (TPM_BASE + 11)) +#define TPM_INVALID_KEYHANDLE ((TPM_RESULT) (TPM_BASE + 12)) +#define TPM_KEYNOTFOUND ((TPM_RESULT) (TPM_BASE + 13)) +#define TPM_INAPPROPRIATE_ENC ((TPM_RESULT) (TPM_BASE + 14)) +#define TPM_MIGRATEFAIL ((TPM_RESULT) (TPM_BASE + 15)) +#define TPM_INVALID_PCR_INFO ((TPM_RESULT) (TPM_BASE + 16)) +#define TPM_NOSPACE ((TPM_RESULT) (TPM_BASE + 17)) +#define TPM_NOSRK ((TPM_RESULT) (TPM_BASE + 18)) +#define TPM_NOTSEALED_BLOB ((TPM_RESULT) (TPM_BASE + 19)) +#define TPM_OWNER_SET ((TPM_RESULT) (TPM_BASE + 20)) +#define TPM_RESOURCES ((TPM_RESULT) (TPM_BASE + 21)) +#define TPM_SHORTRANDOM ((TPM_RESULT) (TPM_BASE + 22)) +#define TPM_SIZE ((TPM_RESULT) (TPM_BASE + 23)) +#define TPM_WRONGPCRVAL ((TPM_RESULT) (TPM_BASE + 24)) +#define TPM_BAD_PARAM_SIZE ((TPM_RESULT) (TPM_BASE + 25)) +#define TPM_SHA_THREAD ((TPM_RESULT) (TPM_BASE + 26)) +#define TPM_SHA_ERROR ((TPM_RESULT) (TPM_BASE + 27)) +#define TPM_FAILEDSELFTEST ((TPM_RESULT) (TPM_BASE + 28)) +#define TPM_AUTH2FAIL ((TPM_RESULT) (TPM_BASE + 29)) +#define TPM_BADTAG ((TPM_RESULT) (TPM_BASE + 30)) +#define TPM_IOERROR ((TPM_RESULT) (TPM_BASE + 31)) +#define TPM_ENCRYPT_ERROR ((TPM_RESULT) (TPM_BASE + 32)) +#define TPM_DECRYPT_ERROR ((TPM_RESULT) (TPM_BASE + 33)) +#define TPM_INVALID_AUTHHANDLE ((TPM_RESULT) (TPM_BASE + 34)) +#define TPM_NO_ENDORSEMENT ((TPM_RESULT) (TPM_BASE + 35)) +#define TPM_INVALID_KEYUSAGE ((TPM_RESULT) (TPM_BASE + 36)) +#define TPM_WRONG_ENTITYTYPE ((TPM_RESULT) (TPM_BASE + 37)) +#define TPM_INVALID_POSTINIT ((TPM_RESULT) (TPM_BASE + 38)) +#define TPM_INAPPROPRIATE_SIG ((TPM_RESULT) (TPM_BASE + 39)) +#define TPM_BAD_KEY_PROPERTY ((TPM_RESULT) (TPM_BASE + 40)) +#define TPM_BAD_MIGRATION ((TPM_RESULT) (TPM_BASE + 41)) +#define TPM_BAD_SCHEME ((TPM_RESULT) (TPM_BASE + 42)) +#define TPM_BAD_DATASIZE ((TPM_RESULT) (TPM_BASE + 43)) +#define TPM_BAD_MODE ((TPM_RESULT) (TPM_BASE + 44)) +#define TPM_BAD_PRESENCE ((TPM_RESULT) (TPM_BASE + 45)) +#define TPM_BAD_VERSION ((TPM_RESULT) (TPM_BASE + 46)) +#define TPM_NO_WRAP_TRANSPORT ((TPM_RESULT) (TPM_BASE + 47)) +#define TPM_AUDITFAIL_UNSUCCESSFUL ((TPM_RESULT) (TPM_BASE + 48)) +#define TPM_AUDITFAIL_SUCCESSFUL ((TPM_RESULT) (TPM_BASE + 49)) +#define TPM_NOTRESETABLE ((TPM_RESULT) (TPM_BASE + 50)) +#define TPM_NOTLOCAL ((TPM_RESULT) (TPM_BASE + 51)) +#define TPM_BAD_TYPE ((TPM_RESULT) (TPM_BASE + 52)) +#define TPM_INVALID_RESOURCE ((TPM_RESULT) (TPM_BASE + 53)) +#define TPM_NOTFIPS ((TPM_RESULT) (TPM_BASE + 54)) +#define TPM_INVALID_FAMILY ((TPM_RESULT) (TPM_BASE + 55)) +#define TPM_NO_NV_PERMISSION ((TPM_RESULT) (TPM_BASE + 56)) +#define TPM_REQUIRES_SIGN ((TPM_RESULT) (TPM_BASE + 57)) +#define TPM_KEY_NOTSUPPORTED ((TPM_RESULT) (TPM_BASE + 58)) +#define TPM_AUTH_CONFLICT ((TPM_RESULT) (TPM_BASE + 59)) +#define TPM_AREA_LOCKED ((TPM_RESULT) (TPM_BASE + 60)) +#define TPM_BAD_LOCALITY ((TPM_RESULT) (TPM_BASE + 61)) +#define TPM_READ_ONLY ((TPM_RESULT) (TPM_BASE + 62)) +#define TPM_PER_NOWRITE ((TPM_RESULT) (TPM_BASE + 63)) +#define TPM_FAMILYCOUNT ((TPM_RESULT) (TPM_BASE + 64)) +#define TPM_WRITE_LOCKED ((TPM_RESULT) (TPM_BASE + 65)) +#define TPM_BAD_ATTRIBUTES ((TPM_RESULT) (TPM_BASE + 66)) +#define TPM_INVALID_STRUCTURE ((TPM_RESULT) (TPM_BASE + 67)) +#define TPM_KEY_OWNER_CONTROL ((TPM_RESULT) (TPM_BASE + 68)) +#define TPM_BAD_COUNTER ((TPM_RESULT) (TPM_BASE + 69)) +#define TPM_NOT_FULLWRITE ((TPM_RESULT) (TPM_BASE + 70)) +#define TPM_CONTEXT_GAP ((TPM_RESULT) (TPM_BASE + 71)) +#define TPM_MAXNVWRITES ((TPM_RESULT) (TPM_BASE + 72)) +#define TPM_NOOPERATOR ((TPM_RESULT) (TPM_BASE + 73)) +#define TPM_RESOURCEMISSING ((TPM_RESULT) (TPM_BASE + 74)) +#define TPM_DELEGATE_LOCK ((TPM_RESULT) (TPM_BASE + 75)) +#define TPM_DELEGATE_FAMILY ((TPM_RESULT) (TPM_BASE + 76)) +#define TPM_DELEGATE_ADMIN ((TPM_RESULT) (TPM_BASE + 77)) +#define TPM_TRANSPORT_NOTEXCLUSIVE ((TPM_RESULT) (TPM_BASE + 78)) +#define TPM_OWNER_CONTROL ((TPM_RESULT) (TPM_BASE + 79)) +#define TPM_DAA_RESOURCES ((TPM_RESULT) (TPM_BASE + 80)) +#define TPM_DAA_INPUT_DATA0 ((TPM_RESULT) (TPM_BASE + 81)) +#define TPM_DAA_INPUT_DATA1 ((TPM_RESULT) (TPM_BASE + 82)) +#define TPM_DAA_ISSUER_SETTINGS ((TPM_RESULT) (TPM_BASE + 83)) +#define TPM_DAA_TPM_SETTINGS ((TPM_RESULT) (TPM_BASE + 84)) +#define TPM_DAA_STAGE ((TPM_RESULT) (TPM_BASE + 85)) +#define TPM_DAA_ISSUER_VALIDITY ((TPM_RESULT) (TPM_BASE + 86)) +#define TPM_DAA_WRONG_W ((TPM_RESULT) (TPM_BASE + 87)) +#define TPM_BAD_HANDLE ((TPM_RESULT) (TPM_BASE + 88)) +#define TPM_BAD_DELEGATE ((TPM_RESULT) (TPM_BASE + 89)) +#define TPM_BADCONTEXT ((TPM_RESULT) (TPM_BASE + 90)) +#define TPM_TOOMANYCONTEXTS ((TPM_RESULT) (TPM_BASE + 91)) +#define TPM_MA_TICKET_SIGNATURE ((TPM_RESULT) (TPM_BASE + 92)) +#define TPM_MA_DESTINATION ((TPM_RESULT) (TPM_BASE + 93)) +#define TPM_MA_SOURCE ((TPM_RESULT) (TPM_BASE + 94)) +#define TPM_MA_AUTHORITY ((TPM_RESULT) (TPM_BASE + 95)) +#define TPM_PERMANENTEK ((TPM_RESULT) (TPM_BASE + 97)) +#define TPM_BAD_SIGNATURE ((TPM_RESULT) (TPM_BASE + 98)) +#define TPM_NOCONTEXTSPACE ((TPM_RESULT) (TPM_BASE + 99)) + +#define TPM_RETRY ((TPM_RESULT) (TPM_BASE + TPM_NON_FATAL)) +#define TPM_NEEDS_SELFTEST ((TPM_RESULT) (TPM_BASE + TPM_NON_FATAL + 1)) +#define TPM_DOING_SELFTEST ((TPM_RESULT) (TPM_BASE + TPM_NON_FATAL + 2)) +#define TPM_DEFEND_LOCK_RUNNING ((TPM_RESULT) (TPM_BASE + TPM_NON_FATAL + 3)) + +// +// Part 2, section 17: Ordinals +// +// Ordinals are 32 bit values. The upper byte contains values that serve as +// flag indicators, the next byte contains values indicating what committee +// designated the ordinal, and the final two bytes contain the Command +// Ordinal Index. +// 3 2 1 +// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |P|C|V| Reserved| Purview | Command Ordinal Index | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// Where: +// +// * P is Protected/Unprotected command. When 0 the command is a Protected +// command, when 1 the command is an Unprotected command. +// +// * C is Non-Connection/Connection related command. When 0 this command +// passes through to either the protected (TPM) or unprotected (TSS) +// components. +// +// * V is TPM/Vendor command. When 0 the command is TPM defined, when 1 the +// command is vendor defined. +// +// * All reserved area bits are set to 0. +// +#define TPM_ORD_ActivateIdentity ((TPM_COMMAND_CODE) 0x0000007A) +#define TPM_ORD_AuthorizeMigrationKey ((TPM_COMMAND_CODE) 0x0000002B) +#define TPM_ORD_CertifyKey ((TPM_COMMAND_CODE) 0x00000032) +#define TPM_ORD_CertifyKey2 ((TPM_COMMAND_CODE) 0x00000033) +#define TPM_ORD_CertifySelfTest ((TPM_COMMAND_CODE) 0x00000052) +#define TPM_ORD_ChangeAuth ((TPM_COMMAND_CODE) 0x0000000C) +#define TPM_ORD_ChangeAuthAsymFinish ((TPM_COMMAND_CODE) 0x0000000F) +#define TPM_ORD_ChangeAuthAsymStart ((TPM_COMMAND_CODE) 0x0000000E) +#define TPM_ORD_ChangeAuthOwner ((TPM_COMMAND_CODE) 0x00000010) +#define TPM_ORD_CMK_ApproveMA ((TPM_COMMAND_CODE) 0x0000001D) +#define TPM_ORD_CMK_ConvertMigration ((TPM_COMMAND_CODE) 0x00000024) +#define TPM_ORD_CMK_CreateBlob ((TPM_COMMAND_CODE) 0x0000001B) +#define TPM_ORD_CMK_CreateKey ((TPM_COMMAND_CODE) 0x00000013) +#define TPM_ORD_CMK_CreateTicket ((TPM_COMMAND_CODE) 0x00000012) +#define TPM_ORD_CMK_SetRestrictions ((TPM_COMMAND_CODE) 0x0000001C) +#define TPM_ORD_ContinueSelfTest ((TPM_COMMAND_CODE) 0x00000053) +#define TPM_ORD_ConvertMigrationBlob ((TPM_COMMAND_CODE) 0x0000002A) +#define TPM_ORD_CreateCounter ((TPM_COMMAND_CODE) 0x000000DC) +#define TPM_ORD_CreateEndorsementKeyPair ((TPM_COMMAND_CODE) 0x00000078) +#define TPM_ORD_CreateMaintenanceArchive ((TPM_COMMAND_CODE) 0x0000002C) +#define TPM_ORD_CreateMigrationBlob ((TPM_COMMAND_CODE) 0x00000028) +#define TPM_ORD_CreateRevocableEK ((TPM_COMMAND_CODE) 0x0000007F) +#define TPM_ORD_CreateWrapKey ((TPM_COMMAND_CODE) 0x0000001F) +#define TPM_ORD_DAA_JOIN ((TPM_COMMAND_CODE) 0x00000029) +#define TPM_ORD_DAA_SIGN ((TPM_COMMAND_CODE) 0x00000031) +#define TPM_ORD_Delegate_CreateKeyDelegation ((TPM_COMMAND_CODE) 0x000000D4) +#define TPM_ORD_Delegate_CreateOwnerDelegation ((TPM_COMMAND_CODE) 0x000000D5) +#define TPM_ORD_Delegate_LoadOwnerDelegation ((TPM_COMMAND_CODE) 0x000000D8) +#define TPM_ORD_Delegate_Manage ((TPM_COMMAND_CODE) 0x000000D2) +#define TPM_ORD_Delegate_ReadTable ((TPM_COMMAND_CODE) 0x000000DB) +#define TPM_ORD_Delegate_UpdateVerification ((TPM_COMMAND_CODE) 0x000000D1) +#define TPM_ORD_Delegate_VerifyDelegation ((TPM_COMMAND_CODE) 0x000000D6) +#define TPM_ORD_DirRead ((TPM_COMMAND_CODE) 0x0000001A) +#define TPM_ORD_DirWriteAuth ((TPM_COMMAND_CODE) 0x00000019) +#define TPM_ORD_DisableForceClear ((TPM_COMMAND_CODE) 0x0000005E) +#define TPM_ORD_DisableOwnerClear ((TPM_COMMAND_CODE) 0x0000005C) +#define TPM_ORD_DisablePubekRead ((TPM_COMMAND_CODE) 0x0000007E) +#define TPM_ORD_DSAP ((TPM_COMMAND_CODE) 0x00000011) +#define TPM_ORD_EstablishTransport ((TPM_COMMAND_CODE) 0x000000E6) +#define TPM_ORD_EvictKey ((TPM_COMMAND_CODE) 0x00000022) +#define TPM_ORD_ExecuteTransport ((TPM_COMMAND_CODE) 0x000000E7) +#define TPM_ORD_Extend ((TPM_COMMAND_CODE) 0x00000014) +#define TPM_ORD_FieldUpgrade ((TPM_COMMAND_CODE) 0x000000AA) +#define TPM_ORD_FlushSpecific ((TPM_COMMAND_CODE) 0x000000BA) +#define TPM_ORD_ForceClear ((TPM_COMMAND_CODE) 0x0000005D) +#define TPM_ORD_GetAuditDigest ((TPM_COMMAND_CODE) 0x00000085) +#define TPM_ORD_GetAuditDigestSigned ((TPM_COMMAND_CODE) 0x00000086) +#define TPM_ORD_GetAuditEvent ((TPM_COMMAND_CODE) 0x00000082) +#define TPM_ORD_GetAuditEventSigned ((TPM_COMMAND_CODE) 0x00000083) +#define TPM_ORD_GetCapability ((TPM_COMMAND_CODE) 0x00000065) +#define TPM_ORD_GetCapabilityOwner ((TPM_COMMAND_CODE) 0x00000066) +#define TPM_ORD_GetCapabilitySigned ((TPM_COMMAND_CODE) 0x00000064) +#define TPM_ORD_GetOrdinalAuditStatus ((TPM_COMMAND_CODE) 0x0000008C) +#define TPM_ORD_GetPubKey ((TPM_COMMAND_CODE) 0x00000021) +#define TPM_ORD_GetRandom ((TPM_COMMAND_CODE) 0x00000046) +#define TPM_ORD_GetTestResult ((TPM_COMMAND_CODE) 0x00000054) +#define TPM_ORD_GetTicks ((TPM_COMMAND_CODE) 0x000000F1) +#define TPM_ORD_IncrementCounter ((TPM_COMMAND_CODE) 0x000000DD) +#define TPM_ORD_Init ((TPM_COMMAND_CODE) 0x00000097) +#define TPM_ORD_KeyControlOwner ((TPM_COMMAND_CODE) 0x00000023) +#define TPM_ORD_KillMaintenanceFeature ((TPM_COMMAND_CODE) 0x0000002E) +#define TPM_ORD_LoadAuthContext ((TPM_COMMAND_CODE) 0x000000B7) +#define TPM_ORD_LoadContext ((TPM_COMMAND_CODE) 0x000000B9) +#define TPM_ORD_LoadKey ((TPM_COMMAND_CODE) 0x00000020) +#define TPM_ORD_LoadKey2 ((TPM_COMMAND_CODE) 0x00000041) +#define TPM_ORD_LoadKeyContext ((TPM_COMMAND_CODE) 0x000000B5) +#define TPM_ORD_LoadMaintenanceArchive ((TPM_COMMAND_CODE) 0x0000002D) +#define TPM_ORD_LoadManuMaintPub ((TPM_COMMAND_CODE) 0x0000002F) +#define TPM_ORD_MakeIdentity ((TPM_COMMAND_CODE) 0x00000079) +#define TPM_ORD_MigrateKey ((TPM_COMMAND_CODE) 0x00000025) +#define TPM_ORD_NV_DefineSpace ((TPM_COMMAND_CODE) 0x000000CC) +#define TPM_ORD_NV_ReadValue ((TPM_COMMAND_CODE) 0x000000CF) +#define TPM_ORD_NV_ReadValueAuth ((TPM_COMMAND_CODE) 0x000000D0) +#define TPM_ORD_NV_WriteValue ((TPM_COMMAND_CODE) 0x000000CD) +#define TPM_ORD_NV_WriteValueAuth ((TPM_COMMAND_CODE) 0x000000CE) +#define TPM_ORD_OIAP ((TPM_COMMAND_CODE) 0x0000000A) +#define TPM_ORD_OSAP ((TPM_COMMAND_CODE) 0x0000000B) +#define TPM_ORD_OwnerClear ((TPM_COMMAND_CODE) 0x0000005B) +#define TPM_ORD_OwnerReadInternalPub ((TPM_COMMAND_CODE) 0x00000081) +#define TPM_ORD_OwnerReadPubek ((TPM_COMMAND_CODE) 0x0000007D) +#define TPM_ORD_OwnerSetDisable ((TPM_COMMAND_CODE) 0x0000006E) +#define TPM_ORD_PCR_Reset ((TPM_COMMAND_CODE) 0x000000C8) +#define TPM_ORD_PcrRead ((TPM_COMMAND_CODE) 0x00000015) +#define TPM_ORD_PhysicalDisable ((TPM_COMMAND_CODE) 0x00000070) +#define TPM_ORD_PhysicalEnable ((TPM_COMMAND_CODE) 0x0000006F) +#define TPM_ORD_PhysicalSetDeactivated ((TPM_COMMAND_CODE) 0x00000072) +#define TPM_ORD_Quote ((TPM_COMMAND_CODE) 0x00000016) +#define TPM_ORD_Quote2 ((TPM_COMMAND_CODE) 0x0000003E) +#define TPM_ORD_ReadCounter ((TPM_COMMAND_CODE) 0x000000DE) +#define TPM_ORD_ReadManuMaintPub ((TPM_COMMAND_CODE) 0x00000030) +#define TPM_ORD_ReadPubek ((TPM_COMMAND_CODE) 0x0000007C) +#define TPM_ORD_ReleaseCounter ((TPM_COMMAND_CODE) 0x000000DF) +#define TPM_ORD_ReleaseCounterOwner ((TPM_COMMAND_CODE) 0x000000E0) +#define TPM_ORD_ReleaseTransportSigned ((TPM_COMMAND_CODE) 0x000000E8) +#define TPM_ORD_Reset ((TPM_COMMAND_CODE) 0x0000005A) +#define TPM_ORD_ResetLockValue ((TPM_COMMAND_CODE) 0x00000040) +#define TPM_ORD_RevokeTrust ((TPM_COMMAND_CODE) 0x00000080) +#define TPM_ORD_SaveAuthContext ((TPM_COMMAND_CODE) 0x000000B6) +#define TPM_ORD_SaveContext ((TPM_COMMAND_CODE) 0x000000B8) +#define TPM_ORD_SaveKeyContext ((TPM_COMMAND_CODE) 0x000000B4) +#define TPM_ORD_SaveState ((TPM_COMMAND_CODE) 0x00000098) +#define TPM_ORD_Seal ((TPM_COMMAND_CODE) 0x00000017) +#define TPM_ORD_Sealx ((TPM_COMMAND_CODE) 0x0000003D) +#define TPM_ORD_SelfTestFull ((TPM_COMMAND_CODE) 0x00000050) +#define TPM_ORD_SetCapability ((TPM_COMMAND_CODE) 0x0000003F) +#define TPM_ORD_SetOperatorAuth ((TPM_COMMAND_CODE) 0x00000074) +#define TPM_ORD_SetOrdinalAuditStatus ((TPM_COMMAND_CODE) 0x0000008D) +#define TPM_ORD_SetOwnerInstall ((TPM_COMMAND_CODE) 0x00000071) +#define TPM_ORD_SetOwnerPointer ((TPM_COMMAND_CODE) 0x00000075) +#define TPM_ORD_SetRedirection ((TPM_COMMAND_CODE) 0x0000009A) +#define TPM_ORD_SetTempDeactivated ((TPM_COMMAND_CODE) 0x00000073) +#define TPM_ORD_SHA1Complete ((TPM_COMMAND_CODE) 0x000000A2) +#define TPM_ORD_SHA1CompleteExtend ((TPM_COMMAND_CODE) 0x000000A3) +#define TPM_ORD_SHA1Start ((TPM_COMMAND_CODE) 0x000000A0) +#define TPM_ORD_SHA1Update ((TPM_COMMAND_CODE) 0x000000A1) +#define TPM_ORD_Sign ((TPM_COMMAND_CODE) 0x0000003C) +#define TPM_ORD_Startup ((TPM_COMMAND_CODE) 0x00000099) +#define TPM_ORD_StirRandom ((TPM_COMMAND_CODE) 0x00000047) +#define TPM_ORD_TakeOwnership ((TPM_COMMAND_CODE) 0x0000000D) +#define TPM_ORD_Terminate_Handle ((TPM_COMMAND_CODE) 0x00000096) +#define TPM_ORD_TickStampBlob ((TPM_COMMAND_CODE) 0x000000F2) +#define TPM_ORD_UnBind ((TPM_COMMAND_CODE) 0x0000001E) +#define TPM_ORD_Unseal ((TPM_COMMAND_CODE) 0x00000018) +#define TSC_ORD_PhysicalPresence ((TPM_COMMAND_CODE) 0x4000000A) +#define TSC_ORD_ResetEstablishmentBit ((TPM_COMMAND_CODE) 0x4000000B) + +// +// Part 2, section 18: Context structures +// + +typedef struct tdTPM_CONTEXT_BLOB +{ + TPM_STRUCTURE_TAG tag; + TPM_RESOURCE_TYPE resourceType; + TPM_HANDLE handle; + UINT8 label[16]; + UINT32 contextCount; + TPM_DIGEST integrityDigest; + UINT32 additionalSize; + UINT8 *additionalData; + UINT32 sensitiveSize; + UINT8 *sensitiveData; +} TPM_CONTEXT_BLOB; + +typedef struct tdTPM_CONTEXT_SENSITIVE +{ + TPM_STRUCTURE_TAG tag; + TPM_NONCE contextNonce; + UINT32 internalSize; + UINT8 *internalData; +} TPM_CONTEXT_SENSITIVE; + +// +// Part 2, section 19: NV Structures +// + +#define TPM_NV_INDEX_LOCK ((UINT32)0xffffffff) +#define TPM_NV_INDEX0 ((UINT32)0x00000000) +#define TPM_NV_INDEX_DIR ((UINT32)0x10000001) +#define TPM_NV_INDEX_EKCert ((UINT32)0x0000f000) +#define TPM_NV_INDEX_TPM_CC ((UINT32)0x0000f001) +#define TPM_NV_INDEX_PlatformCert ((UINT32)0x0000f002) +#define TPM_NV_INDEX_Platform_CC ((UINT32)0x0000f003) +// The following define ranges of reserved indices. +#define TPM_NV_INDEX_TSS_BASE ((UINT32)0x00011100) +#define TPM_NV_INDEX_PC_BASE ((UINT32)0x00011200) +#define TPM_NV_INDEX_SERVER_BASE ((UINT32)0x00011300) +#define TPM_NV_INDEX_MOBILE_BASE ((UINT32)0x00011400) +#define TPM_NV_INDEX_PERIPHERAL_BASE ((UINT32)0x00011500) +#define TPM_NV_INDEX_GROUP_RESV_BASE ((UINT32)0x00010000) + +typedef UINT32 TPM_NV_PER_ATTRIBUTES; +// The typedefs TPM_NV_PER_ATTRIBUTES (not present in TPM 1.2 Spec. have been added +// and structure fields that were to hold the following values +#define TPM_NV_PER_READ_STCLEAR (((UINT32)1) << 31) +#define TPM_NV_PER_AUTHREAD (((UINT32)1) << 18) +#define TPM_NV_PER_OWNERREAD (((UINT32)1) << 17) +#define TPM_NV_PER_PPREAD (((UINT32)1) << 16) +#define TPM_NV_PER_GLOBALLOCK (((UINT32)1) << 15) +#define TPM_NV_PER_WRITE_STCLEAR (((UINT32)1) << 14) +#define TPM_NV_PER_WRITEDEFINE (((UINT32)1) << 13) +#define TPM_NV_PER_WRITEALL (((UINT32)1) << 12) +#define TPM_NV_PER_AUTHWRITE (((UINT32)1) << 2) +#define TPM_NV_PER_OWNERWRITE (((UINT32)1) << 1) +#define TPM_NV_PER_PPWRITE (((UINT32)1) << 0) + +typedef struct tdTPM_NV_ATTRIBUTES +{ + TPM_STRUCTURE_TAG tag; + TPM_NV_PER_ATTRIBUTES attributes; +} TPM_NV_ATTRIBUTES; + + +typedef struct tdTPM_NV_DATA_PUBLIC +{ + TPM_STRUCTURE_TAG tag; + TPM_NV_INDEX nvIndex; + TPM_PCR_INFO_SHORT pcrInfoRead; + TPM_PCR_INFO_SHORT pcrInfoWrite; + TPM_NV_ATTRIBUTES permission; + BOOLEAN bReadSTClear; + BOOLEAN bWriteSTClear; + BOOLEAN bWriteDefine; + UINT32 dataSize; +} TPM_NV_DATA_PUBLIC; + + + +// Internal to TPM: +//typedef struct tdTPM_NV_DATA_SENSITIVE +//{ +// TPM_STRUCTURE_TAG tag; +// TPM_NV_DATA_PUBLIC pubInfo; +// TPM_AUTHDATA authValue; +// UINT8 *data; +//} TPM_NV_DATA_SENSITIVE; + + +// +// Part 2, section 20: Delegation +// + +// +// Part 2, section 20.3: Owner Permissions Settings for per1 bits +// +#define TPM_DELEGATE_SetOrdinalAuditStatus (((UINT32)1) << 30) +#define TPM_DELEGATE_DirWriteAuth (((UINT32)1) << 29) +#define TPM_DELEGATE_CMK_ApproveMA (((UINT32)1) << 28) +#define TPM_DELEGATE_CMK_CreateTicket (((UINT32)1) << 26) +#define TPM_DELEGATE_Delegate_LoadOwnerDelegation (((UINT32)1) << 24) +#define TPM_DELEGATE_DAA_Join (((UINT32)1) << 23) +#define TPM_DELEGATE_AuthorizeMigrationKey (((UINT32)1) << 22) +#define TPM_DELEGATE_CreateMaintenanceArchive (((UINT32)1) << 21) +#define TPM_DELEGATE_LoadMaintenanceArchive (((UINT32)1) << 20) +#define TPM_DELEGATE_KillMaintenanceFeature (((UINT32)1) << 19) +#define TPM_DELEGATE_OwnerReadInteralPub (((UINT32)1) << 18) +#define TPM_DELEGATE_ResetLockValue (((UINT32)1) << 17) +#define TPM_DELEGATE_OwnerClear (((UINT32)1) << 16) +#define TPM_DELEGATE_DisableOwnerClear (((UINT32)1) << 15) +#define TPM_DELEGATE_OwnerSetDisable (((UINT32)1) << 13) +#define TPM_DELEGATE_SetCapability (((UINT32)1) << 12) +#define TPM_DELEGATE_MakeIdentity (((UINT32)1) << 11) +#define TPM_DELEGATE_ActivateIdentity (((UINT32)1) << 10) +#define TPM_DELEGATE_OwnerReadPubek (((UINT32)1) << 9) +#define TPM_DELEGATE_DisablePubekRead (((UINT32)1) << 8) +#define TPM_DELEGATE_SetRedirection (((UINT32)1) << 7) +#define TPM_DELEGATE_FieldUpgrade (((UINT32)1) << 6) +#define TPM_DELEGATE_Delegate_UpdateVerification (((UINT32)1) << 5) +#define TPM_DELEGATE_CreateCounter (((UINT32)1) << 4) +#define TPM_DELEGATE_ReleaseCounterOwner (((UINT32)1) << 3) +#define TPM_DELEGATE_DelegateManage (((UINT32)1) << 2) +#define TPM_DELEGATE_Delegate_CreateOwnerDelegation (((UINT32)1) << 1) +#define TPM_DELEGATE_DAA_Sign (((UINT32)1) << 0) + +// +// Part 2, section 20.3: Key Permissions Settings for per1 bits +// +#define TPM_KEY_DELEGATE_CMK_ConvertMigration (((UINT32)1) << 28) +#define TPM_KEY_DELEGATE_TickStampBlob (((UINT32)1) << 27) +#define TPM_KEY_DELEGATE_ChangeAuthAsymStart (((UINT32)1) << 26) +#define TPM_KEY_DELEGATE_ChangeAuthAsymFinish (((UINT32)1) << 25) +#define TPM_KEY_DELEGATE_CMK_CreateKey (((UINT32)1) << 24) +#define TPM_KEY_DELEGATE_MigrateKey (((UINT32)1) << 23) +#define TPM_KEY_DELEGATE_LoadKey2 (((UINT32)1) << 22) +#define TPM_KEY_DELEGATE_EstablishTransport (((UINT32)1) << 21) +#define TPM_KEY_DELEGATE_ReleaseTransportSigned (((UINT32)1) << 20) +#define TPM_KEY_DELEGATE_Quote2 (((UINT32)1) << 19) +#define TPM_KEY_DELEGATE_Sealx (((UINT32)1) << 18) +#define TPM_KEY_DELEGATE_MakeIdentity (((UINT32)1) << 17) +#define TPM_KEY_DELEGATE_ActivateIdentity (((UINT32)1) << 16) +#define TPM_KEY_DELEGATE_GetAuditDigestSigned (((UINT32)1) << 15) +#define TPM_KEY_DELEGATE_Sign (((UINT32)1) << 14) +#define TPM_KEY_DELEGATE_CertifyKey2 (((UINT32)1) << 13) +#define TPM_KEY_DELEGATE_CertifyKey (((UINT32)1) << 12) +#define TPM_KEY_DELEGATE_CreateWrapKey (((UINT32)1) << 11) +#define TPM_KEY_DELEGATE_CMK_CreateBlob (((UINT32)1) << 10) +#define TPM_KEY_DELEGATE_CreateMigrationBlob (((UINT32)1) << 9) +#define TPM_KEY_DELEGATE_ConvertMigrationBlob (((UINT32)1) << 8) +#define TPM_KEY_DELEGATE_CreateKeyDelegation (((UINT32)1) << 7) +#define TPM_KEY_DELEGATE_ChangeAuth (((UINT32)1) << 6) +#define TPM_KEY_DELEGATE_GetPubKey (((UINT32)1) << 5) +#define TPM_KEY_DELEGATE_UnBind (((UINT32)1) << 4) +#define TPM_KEY_DELEGATE_Quote (((UINT32)1) << 3) +#define TPM_KEY_DELEGATE_Unseal (((UINT32)1) << 2) +#define TPM_KEY_DELEGATE_Seal (((UINT32)1) << 1) +#define TPM_KEY_DELEGATE_LoadKey (((UINT32)1) << 0) + +#define TPM_FAMILY_CREATE ((UINT32)0x00000001) +#define TPM_FAMILY_ENABLE ((UINT32)0x00000002) +#define TPM_FAMILY_ADMIN ((UINT32)0x00000003) +#define TPM_FAMILY_INVALIDATE ((UINT32)0x00000004) + +#define TPM_FAMFLAG_DELEGATE_ADMIN_LOCK (((UINT32)1) << 1) +#define TPM_FAMFLAG_ENABLE (((UINT32)1) << 0) + +typedef struct tdTPM_FAMILY_LABEL +{ + UINT8 label; +} TPM_FAMILY_LABEL; + +typedef struct tdTPM_FAMILY_TABLE_ENTRY +{ + TPM_STRUCTURE_TAG tag; + TPM_FAMILY_LABEL label; + TPM_FAMILY_ID familyID; + TPM_FAMILY_VERIFICATION verificationCount; + TPM_FAMILY_FLAGS flags; +} TPM_FAMILY_TABLE_ENTRY; + +#define TPM_FAMILY_TABLE_ENTRY_MIN 8 +//typedef struct tdTPM_FAMILY_TABLE +//{ +// TPM_FAMILY_TABLE_ENTRY FamTableRow[TPM_NUM_FAMILY_TABLE_ENTRY_MIN]; +//} TPM_FAMILY_TABLE; + + +typedef struct tdTPM_DELEGATE_LABEL +{ + UINT8 label; +} TPM_DELEGATE_LABEL; + + +typedef UINT32 TPM_DELEGATE_TYPE; +#define TPM_DEL_OWNER_BITS ((UINT32)0x00000001) +#define TPM_DEL_KEY_BITS ((UINT32)0x00000002) + +typedef struct tdTPM_DELEGATIONS +{ + TPM_STRUCTURE_TAG tag; + TPM_DELEGATE_TYPE delegateType; + UINT32 per1; + UINT32 per2; +} TPM_DELEGATIONS; + +typedef struct tdTPM_DELEGATE_PUBLIC +{ + TPM_STRUCTURE_TAG tag; + TPM_DELEGATE_LABEL label; + TPM_PCR_INFO_SHORT pcrInfo; + TPM_DELEGATIONS permissions; + TPM_FAMILY_ID familyID; + TPM_FAMILY_VERIFICATION verificationCount; +} TPM_DELEGATE_PUBLIC; + +typedef struct tdTPM_DELEGATE_TABLE_ROW +{ + TPM_STRUCTURE_TAG tag; + TPM_DELEGATE_PUBLIC pub; + TPM_SECRET authValue; +} TPM_DELEGATE_TABLE_ROW; + + +#define TPM_NUM_DELEGATE_TABLE_ENTRY_MIN 2 +//typedef struct tdTPM_DELEGATE_TABLE +//{ +// TPM_DELEGATE_TABLE_ROW delRow[TPM_NUM_DELEGATE_TABLE_ENTRY_MIN]; +//} TPM_DELEGATE_TABLE; + +typedef struct tdTPM_DELEGATE_SENSITIVE +{ + TPM_STRUCTURE_TAG tag; + TPM_SECRET authValue; +} TPM_DELEGATE_SENSITIVE; + +typedef struct tdTPM_DELEGATE_OWNER_BLOB +{ + TPM_STRUCTURE_TAG tag; + TPM_DELEGATE_PUBLIC pub; + TPM_DIGEST integrityDigest; + UINT32 additionalSize; + UINT8 *additionalArea; + UINT32 sensitiveSize; + UINT8 *sensitiveArea; +} TPM_DELEGATE_OWNER_BLOB; + +typedef struct tdTPM_DELEGATE_KEY_BLOB +{ + TPM_STRUCTURE_TAG tag; + TPM_DELEGATE_PUBLIC pub; + TPM_DIGEST integrityDigest; + TPM_DIGEST pubKeyDigest; + UINT32 additionalSize; + UINT8 *additionalArea; + UINT32 sensitiveSize; + UINT8 *sensitiveArea; +} TPM_DELEGATE_KEY_BLOB; + +// +// Part 2, section 21.1: TPM_CAPABILITY_AREA for GetCapability +// +#define TPM_CAP_ORD ((TPM_CAPABILITY_AREA) 0x00000001) +#define TPM_CAP_ALG ((TPM_CAPABILITY_AREA) 0x00000002) +#define TPM_CAP_PID ((TPM_CAPABILITY_AREA) 0x00000003) +#define TPM_CAP_FLAG ((TPM_CAPABILITY_AREA) 0x00000004) +#define TPM_CAP_PROPERTY ((TPM_CAPABILITY_AREA) 0x00000005) +#define TPM_CAP_VERSION ((TPM_CAPABILITY_AREA) 0x00000006) +#define TPM_CAP_KEY_HANDLE ((TPM_CAPABILITY_AREA) 0x00000007) +#define TPM_CAP_CHECK_LOADED ((TPM_CAPABILITY_AREA) 0x00000008) +#define TPM_CAP_SYM_MODE ((TPM_CAPABILITY_AREA) 0x00000009) +#define TPM_CAP_KEY_STATUS ((TPM_CAPABILITY_AREA) 0x0000000C) +#define TPM_CAP_NV_LIST ((TPM_CAPABILITY_AREA) 0x0000000D) +#define TPM_CAP_MFR ((TPM_CAPABILITY_AREA) 0x00000010) +#define TPM_CAP_NV_INDEX ((TPM_CAPABILITY_AREA) 0x00000011) +#define TPM_CAP_TRANS_ALG ((TPM_CAPABILITY_AREA) 0x00000012) +#define TPM_CAP_HANDLE ((TPM_CAPABILITY_AREA) 0x00000014) +#define TPM_CAP_TRANS_ES ((TPM_CAPABILITY_AREA) 0x00000015) +#define TPM_CAP_AUTH_ENCRYPT ((TPM_CAPABILITY_AREA) 0x00000017) +#define TPM_CAP_SELECT_SIZE ((TPM_CAPABILITY_AREA) 0x00000018) +#define TPM_CAP_VERSION_VAL ((TPM_CAPABILITY_AREA) 0x0000001A) + +#define TPM_CAP_FLAG_PERMANENT ((TPM_CAPABILITY_AREA) 0x00000108) +#define TPM_CAP_FLAG_VOLATILE ((TPM_CAPABILITY_AREA) 0x00000109) + +// +// Part 2, section 21.2: CAP_PROPERTY Subcap values for GetCapability +// +#define TPM_CAP_PROP_PCR ((TPM_CAPABILITY_AREA) 0x00000101) +#define TPM_CAP_PROP_DIR ((TPM_CAPABILITY_AREA) 0x00000102) +#define TPM_CAP_PROP_MANUFACTURER ((TPM_CAPABILITY_AREA) 0x00000103) +#define TPM_CAP_PROP_KEYS ((TPM_CAPABILITY_AREA) 0x00000104) +#define TPM_CAP_PROP_MIN_COUNTER ((TPM_CAPABILITY_AREA) 0x00000107) +#define TPM_CAP_PROP_AUTHSESS ((TPM_CAPABILITY_AREA) 0x0000010A) +#define TPM_CAP_PROP_TRANSESS ((TPM_CAPABILITY_AREA) 0x0000010B) +#define TPM_CAP_PROP_COUNTERS ((TPM_CAPABILITY_AREA) 0x0000010C) +#define TPM_CAP_PROP_MAX_AUTHSESS ((TPM_CAPABILITY_AREA) 0x0000010D) +#define TPM_CAP_PROP_MAX_TRANSESS ((TPM_CAPABILITY_AREA) 0x0000010E) +#define TPM_CAP_PROP_MAX_COUNTERS ((TPM_CAPABILITY_AREA) 0x0000010F) +#define TPM_CAP_PROP_MAX_KEYS ((TPM_CAPABILITY_AREA) 0x00000110) +#define TPM_CAP_PROP_OWNER ((TPM_CAPABILITY_AREA) 0x00000111) +#define TPM_CAP_PROP_CONTEXT ((TPM_CAPABILITY_AREA) 0x00000112) +#define TPM_CAP_PROP_MAX_CONTEXT ((TPM_CAPABILITY_AREA) 0x00000113) +#define TPM_CAP_PROP_FAMILYROWS ((TPM_CAPABILITY_AREA) 0x00000114) +#define TPM_CAP_PROP_TIS_TIMEOUT ((TPM_CAPABILITY_AREA) 0x00000115) +#define TPM_CAP_PROP_STARTUP_EFFECT ((TPM_CAPABILITY_AREA) 0x00000116) +#define TPM_CAP_PROP_DELEGATE_ROW ((TPM_CAPABILITY_AREA) 0x00000117) +#define TPM_CAP_PROP_DAA_MAX ((TPM_CAPABILITY_AREA) 0x00000119) +#define CAP_PROP_SESSION_DAA ((TPM_CAPABILITY_AREA) 0x0000011A) +#define TPM_CAP_PROP_CONTEXT_DIST ((TPM_CAPABILITY_AREA) 0x0000011B) +#define TPM_CAP_PROP_DAA_INTERRUPT ((TPM_CAPABILITY_AREA) 0x0000011C) +#define TPM_CAP_PROP_SESSIONS ((TPM_CAPABILITY_AREA) 0x0000011D) +#define TPM_CAP_PROP_MAX_SESSIONS ((TPM_CAPABILITY_AREA) 0x0000011E) +#define TPM_CAP_PROP_CMK_RESTRICTION ((TPM_CAPABILITY_AREA) 0x0000011F) +#define TPM_CAP_PROP_DURATION ((TPM_CAPABILITY_AREA) 0x00000120) +#define TPM_CAP_PROP_ACTIVE_COUNTER ((TPM_CAPABILITY_AREA) 0x00000122) +#define TPM_CAP_PROP_MAX_NV_AVAILABLE ((TPM_CAPABILITY_AREA) 0x00000123) +#define TPM_CAP_PROP_INPUT_BUFFER ((TPM_CAPABILITY_AREA) 0x00000124) + +// +// Part 2, section 21.6: TPM_CAP_VERSION_INFO +// [size_is(vendorSpecificSize)] BYTE* vendorSpecific; +// +typedef struct tdTPM_CAP_VERSION_INFO +{ + TPM_STRUCTURE_TAG tag; + TPM_VERSION version; + UINT16 specLevel; + UINT8 errataRev; + UINT8 tpmVendorID[4]; + UINT16 vendorSpecificSize; + UINT8 *vendorSpecific; +} TPM_CAP_VERSION_INFO; + +// +// Part 2, section 22: DAA Structures +// + +#define TPM_DAA_SIZE_r0 (43) +#define TPM_DAA_SIZE_r1 (43) +#define TPM_DAA_SIZE_r2 (128) +#define TPM_DAA_SIZE_r3 (168) +#define TPM_DAA_SIZE_r4 (219) +#define TPM_DAA_SIZE_NT (20) +#define TPM_DAA_SIZE_v0 (128) +#define TPM_DAA_SIZE_v1 (192) +#define TPM_DAA_SIZE_NE (256) +#define TPM_DAA_SIZE_w (256) +#define TPM_DAA_SIZE_issuerModulus (256) +#define TPM_DAA_power0 (104) +#define TPM_DAA_power1 (1024) + +typedef struct tdTPM_DAA_ISSUER +{ + TPM_STRUCTURE_TAG tag; + TPM_DIGEST DAA_digest_R0; + TPM_DIGEST DAA_digest_R1; + TPM_DIGEST DAA_digest_S0; + TPM_DIGEST DAA_digest_S1; + TPM_DIGEST DAA_digest_n; + TPM_DIGEST DAA_digest_gamma; + UINT8 DAA_generic_q[26]; +} TPM_DAA_ISSUER; + + +typedef struct tdTPM_DAA_TPM +{ + TPM_STRUCTURE_TAG tag; + TPM_DIGEST DAA_digestIssuer; + TPM_DIGEST DAA_digest_v0; + TPM_DIGEST DAA_digest_v1; + TPM_DIGEST DAA_rekey; + UINT32 DAA_count; +} TPM_DAA_TPM; + +typedef struct tdTPM_DAA_CONTEXT +{ + TPM_STRUCTURE_TAG tag; + TPM_DIGEST DAA_digestContext; + TPM_DIGEST DAA_digest; + TPM_DAA_CONTEXT_SEED DAA_contextSeed; + UINT8 DAA_scratch[256]; + UINT8 DAA_stage; +} TPM_DAA_CONTEXT; + +typedef struct tdTPM_DAA_JOINDATA +{ + UINT8 DAA_join_u0[128]; + UINT8 DAA_join_u1[138]; + TPM_DIGEST DAA_digest_n0; +} TPM_DAA_JOINDATA; + +typedef struct tdTPM_DAA_BLOB +{ + TPM_STRUCTURE_TAG tag; + TPM_RESOURCE_TYPE resourceType; + UINT8 label[16]; + TPM_DIGEST blobIntegrity; + UINT32 additionalSize; + UINT8 *additionalData; + UINT32 sensitiveSize; + UINT8 *sensitiveData; +} TPM_DAA_BLOB; + +typedef struct tdTPM_DAA_SENSITIVE +{ + TPM_STRUCTURE_TAG tag; + UINT32 internalSize; + UINT8 *internalData; +} TPM_DAA_SENSITIVE; + + +// +// Part 2, section 23: Redirection +// + +// This section of the TPM spec defines exactly one value but does not +// give it a name. The definition of TPM_SetRedirection in Part3 +// refers to exactly one name but does not give its value. We join +// them here. +#define TPM_REDIR_GPIO (0x00000001) + +// +// TPM Command & Response Headers +// +typedef struct tdTPM_RQU_COMMAND_HDR +{ + TPM_STRUCTURE_TAG tag; + UINT32 paramSize; + TPM_COMMAND_CODE ordinal; +} TPM_RQU_COMMAND_HDR; + +typedef struct tdTPM_RSP_COMMAND_HDR +{ + TPM_STRUCTURE_TAG tag; + UINT32 paramSize; + TPM_RESULT returnCode; +} TPM_RSP_COMMAND_HDR; + +#pragma pack (pop) + +#endif // _TPM12_H_ diff --git a/Core/EM/TCG2/TisLib/TcmPc.h b/Core/EM/TCG2/TisLib/TcmPc.h new file mode 100644 index 0000000..9431fa3 --- /dev/null +++ b/Core/EM/TCG2/TisLib/TcmPc.h @@ -0,0 +1,153 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcmPc.h 1 4/21/14 2:15p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:15p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TcmPc.h $ +// +// 1 4/21/14 2:15p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 2 3/29/11 12:27p Fredericko +// [TAG] EIP 54642 +// [Category] Improvement +// [Description] 1. Checkin Files related to TCG function override +// 2. Include TCM and TPM auto detection +// [Files] Affects all TCG files +// +// +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TcmPc.h +// +// Description: +// Header file for Tcm structures +// +//<AMI_FHDR_END> +//************************************************************************* +#ifndef _TCMPC_H_ +#define _TCMPC_H_ +#include "TcgEfi12.h" + + +#pragma pack (push) +#pragma pack (1) + + + +typedef struct tdTCM_PCR_EVENT { + UINT32 PCRIndex; // PCRIndex event extended to + UINT32 EventType; // TCG EFI event type + TCM_DIGEST Digest; // Value extended into PCRIndex + UINT32 EventSize; // Size of the event data + UINT8 Event[1]; // The event data +} TCM_PCR_EVENT; + + +struct _EFI_TCM_EV_S_CRTM_VERSION { + EFI_GUID VersionGuid; +}; + + +struct _EFI_TCM_EV_POST_CODE { + EFI_PHYSICAL_ADDRESS PostCodeAddress; + UINT64 PostCodeLength; +}; + + +struct _EFI_TCM_EV_TAG_OPTION_ROM_EXECUTE +{ + UINT16 Reserved; + UINT16 PFA; + TCM_DIGEST Hash; +}; + + +struct _EFI_TCM_EV_CPU_MICROCODE +{ + EFI_PHYSICAL_ADDRESS MicrocodeEntrypoint; +}; + + +union _EFI_TCM_EV_TAG_EVENT_DATA +{ + struct _EFI_TCM_EV_TAG_OPTION_ROM_EXECUTE + OptionRomExecute; +}; + + +struct _EFI_TCM_EV_TAG +{ + UINT32 EventID; + UINT32 EventSize; + union _EFI_TCM_EV_TAG_EVENT_DATA EventData; +}; + + +typedef struct _EFI_TCM_PCR_EVENT_HEADER +{ + TPM_PCRINDEX PCRIndex; + UINT32 EventType; + TCM_DIGEST Digest; + UINT32 EventDataSize; +} EFI_TCM_PCR_EVENT_HEADER; + + +typedef union _EFI_TCM_PCR_EVENT_DATA +{ + struct _EFI_TCM_EV_S_CRTM_VERSION SCrtmVersion; + struct _EFI_TCM_EV_POST_CODE PostCode; + struct _EFI_TCM_EV_TAG Tagged; + struct _EFI_TCM_EV_CPU_MICROCODE Mcu; +} EFI_TCM_PCR_EVENT_DATA; + + + +typedef struct _EFI_TCM_PCR_EVENT +{ + EFI_TCM_PCR_EVENT_HEADER Header; + EFI_TCM_PCR_EVENT_DATA Event; +} EFI_TCM_PCR_EVENT; + +#pragma pack (pop) + +#endif // _TPMPC_H_ diff --git a/Core/EM/TCG2/TisLib/TisLib.cif b/Core/EM/TCG2/TisLib/TisLib.cif new file mode 100644 index 0000000..fcafbfb --- /dev/null +++ b/Core/EM/TCG2/TisLib/TisLib.cif @@ -0,0 +1,23 @@ +<component> + name = "TisLib" + category = ModulePart + LocalRoot = "Core\EM\TCG2\TisLib" + RefName = "TisLib" +[files] +"TisLib.mak" +"TcgTpm12.h" +"TpmLib.h" +"TcgCommon.h" +"ZTEICTcmOrdinals.h" +"TpmLib.c" +"TcgCommon.c" +"TisLib.sdl" +"sha.h" +"INTTcgAcpi.h" +"TcgPc.h" +"TcmPc.h" +"TcgEfiTpm.h" +"TcgEFI12.h" +[parts] +"AmiTcmlib" +<endComponent> diff --git a/Core/EM/TCG2/TisLib/TisLib.mak b/Core/EM/TCG2/TisLib/TisLib.mak new file mode 100644 index 0000000..1e79a4f --- /dev/null +++ b/Core/EM/TCG2/TisLib/TisLib.mak @@ -0,0 +1,116 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2010, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TisLib.mak 1 4/21/14 2:14p Fredericko $ +# +# $Revision: 1 $ +# +# $Date: 4/21/14 2:14p $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TisLib.mak $ +# +# 1 4/21/14 2:14p Fredericko +# +# 1 10/08/13 11:58a Fredericko +# Initial Check-In for Tpm-Next module +# +# 2 10/03/13 12:31p Fredericko +# +# 1 7/10/13 5:50p Fredericko +# [TAG] EIP120969 +# [Category] New Feature +# [Description] TCG (TPM20) +# [Files] TisLib.cif +# TisLib.mak +# TcgTpm12.h +# TpmLib.h +# TcgCommon.h +# ZTEICTcmOrdinals.h +# TpmLib.c +# TcgCommon.c +# TisLib.sdl +# sha1.h +# INTTcgAcpi.h +# TcgPc.h +# TcmPc.h +# TcgEfiTpm.h +# TcgEFI12.h +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: Tpm12lib.mak +# +# Description: Make file for the tcglib component +# +#<AMI_FHDR_END> +#********************************************************************** +Tpm12_lib : $(BUILD_DIR)\TisLib.mak make_TisLib_lib make_TisLib_libPei +$(BUILD_DIR)\TisLib.lib: Tpm12_lib +$(BUILD_DIR)\IA32\TisLib.lib: Tpm12_lib + +tcg_lib_lite: $(BUILD_DIR)\TisLib.mak tcg_lib_liteBin +$(tcgLibLite): tcg_lib_lite + +$(BUILD_DIR)\TisLib.mak : $(TPM12_DIR)\TisLib.cif $(TPM12_DIR)\TisLib.mak $(BUILD_RULES) + $(CIF2MAK) $(TPM12_DIR)\TisLib.cif $(CIF2MAK_DEFAULTS) + +TCG12LIB_CFLAGS=$(CFLAGS)\ + /I$(TPM12_DIR)\ + /I$(TCG_DIR)\ + +TCG_LIB_LITE_OBJS = \ +$(BUILD_DIR)\$(TPM12_DIR)\TpmLib.obj + +tcg_lib_liteBin: $(BUILD_DIR)\AmiTcmlib.lib + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\TisLib.mak all\ + "CFLAGS=$(TCG12LIB_CFLAGS) "\ + "OBJECTS=$(TCG_LIB_LITE_OBJS)"\ + TYPE=LIBRARY \ + LIBRARY_NAME=$(tcgLibLite) + +!IF "$(PROCESSOR)"=="x64" +make_TisLib_lib: $(BUILD_DIR)\AmiTcmlib.lib $(SHALIB) + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\TisLib.mak all\ + "CFLAGS=$(TCG12LIB_CFLAGS) "\ + TYPE=LIBRARY + +make_TisLib_libPei: $(BUILD_DIR)\AmiTcmlib.lib $(SHALIBPEI) + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS) BUILD_DIR=$(BUILD_DIR)\IA32\ + /f $(BUILD_DIR)\TisLib.mak all\ + "CFLAGS=$(TCG12LIB_CFLAGS) "\ + TYPE=PEI_LIBRARY +!ELSE + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\TisLib.mak all\ + "CFLAGS=$(TCG12LIB_CFLAGS) "\ + TYPE=PEI_LIBRARY +!ENDIF +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2010, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** diff --git a/Core/EM/TCG2/TisLib/TisLib.sdl b/Core/EM/TCG2/TisLib/TisLib.sdl new file mode 100644 index 0000000..95ee12d --- /dev/null +++ b/Core/EM/TCG2/TisLib/TisLib.sdl @@ -0,0 +1,46 @@ +TOKEN + Name = "TPM12_SUPPORT" + Value = "1" + Help = "Main switch to enable TCG support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + TargetH = Yes + Master = Yes + Token = "TCG2Support" "=" "1" +End + +TOKEN + Name = "TPM_DRIVER_WAIT" + Value = "005h" + Help = "Delay count for TPM wait loop. Default is 50us. Please dont change to less than 2 (4us)." + TokenType = Integer + TargetEQU = Yes + TargetH = Yes +End + +TOKEN + Name = "DELAY_AMOUNT" + Value = "010" + Help = "Delay amount for TPM wait loop. Default is 5us. Please dont change to less than 2 (2us)." + TokenType = Integer + TargetEQU = Yes + TargetH = Yes +End + +PATH + Name = "TPM12_DIR" + Help = "Tcg Directory" +End + +MODULE + Help = "Includes TCG.mak to Project" + File = "TisLib.mak" +End + +TOKEN + Name = "tcgLibLite" + Value = "$(BUILD_DIR)\tcgLibLite.lib" + TokenType = Expression + TargetMAK = Yes +End
\ No newline at end of file diff --git a/Core/EM/TCG2/TisLib/TpmLib.c b/Core/EM/TCG2/TisLib/TpmLib.c new file mode 100644 index 0000000..66dd24a --- /dev/null +++ b/Core/EM/TCG2/TisLib/TpmLib.c @@ -0,0 +1,614 @@ +/*++ + +Copyright (c) 2005 Intel Corporation. All rights reserved +This software and associated documentation (if any) is furnished +under a license and may only be used or copied in accordance +with the terms of the license. Except as permitted by such +license, no part of this software or documentation may be +reproduced, stored in a retrieval system, or transmitted in any +form or by any means without the express written consent of +Intel Corporation. + + +Module Name: + + TpmLib.h + +Abstract: + + Common code of TPM driver in both PEI and DXE +--*/ +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TpmLib.c 1 4/21/14 2:14p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:14p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TpmLib.c $ +// +// 1 4/21/14 2:14p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 2 10/03/13 12:33p Fredericko +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 23 9/08/11 4:46p Fredericko +// [TAG] EIPEIP0000 +// [Category] Improvement +// [Description] Added ability to modify Delay Amount for TPM driver +// [Files] Tcg.sdl +// Tpmlib.c +// +// 22 8/26/11 12:31p Fredericko +// [TAG] EIP64300 +// [Category] Improvement +// [Description] Allow variations for TPM driver wait times. +// [Files] Tpmlib.c +// Tcg.sd +// +// 21 7/07/10 12:09p Fredericko +// Make Wait variable a #define. +// +// 20 5/19/10 4:50p Fredericko +// Included File Header +// +// 19 5/18/10 5:39p Fredericko +// Code Beautification and Enhancement +// +// 18 5/18/10 11:32a Fredericko +// Header modification for AMI code standard. +// +// 17 5/04/10 3:36p Fredericko +// Source Enhancement. EIP 22208 +// +//************************************************************************* +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TpmLib.c +// +// Description: +// Contains low level TCG functions +// +//<AMI_FHDR_END> +//************************************************************************* +#include <Efi.h> +#include "TpmLib.h" +#include "AmiLib.h" +#include <token.h> + +extern EFI_STATUS CountTime ( IN UINTN DelayTime, IN UINT16 BaseAddr); // only needs to be 16 bit for I/O address) +#define Wait TPM_DRIVER_WAIT +#define ACCESS_WAITCOUNT (750 * 1000 / 100) // 750MS (750 * 10000 /1000) +#define ACCESS_WAITCOUNTB ( 3 * 1000000/100) // 3 seconds delay + +#define TIS_TIMEOUT_A ACCESS_WAITCOUNT +#define TIS_TIMEOUT_B ACCESS_WAITCOUNTB +#define TIS_TIMEOUT_C ACCESS_WAITCOUNT +#define TIS_TIMEOUT_D ACCESS_WAITCOUNT + + + + +//********************************************************************** +//<AMI_PHDR_START> +// +// Procedure: FixedDelay +// +// Description: This routine delays for specified number of micro seconds +// +// Input: IN UINT32 dCount Amount of delay (count in 20microsec) +// +// Output: NONE +// +// Modified: +// +// Referrals: Div64, CountTime +// +// Notes: +//<AMI_PHDR_END> +//********************************************************************** + +void +__stdcall +FixedDelay(UINT32 dCount) +{ + UINTN TickPeriod = 0x03; + UINTN Remainder = 0x1; + UINTN MicroSDelay = DELAY_AMOUNT; + UINT32 Data32, PrevData; + UINTN i=0; + UINT32 Counter = 0x00; + + Counter = (UINT32)Div64((MicroSDelay * 10), TickPeriod, &Remainder); + + if(Remainder != 0) { + Counter++; + } + while(dCount) { + if (Counter != 0) { + + PrevData = IoRead32(PM_BASE_ADDRESS + 8); + for (i=0; i < Counter; ) { + Data32 = IoRead32(PM_BASE_ADDRESS + 8); + if (Data32 < PrevData) { // Reset if there is a overlap + PrevData=Data32; + continue; + } + i += (Data32 - PrevData); + PrevData = Data32; + } + } + dCount--; + } +} + + + +static +UINT8 +__stdcall +CheckAccessBit ( + IN volatile UINT8 *Sts, + IN UINT8 Bit, + IN UINT32 Timeout + ) +/*++ +Routine Description: + Function to check bits in TPM access register +Arguments: + *Sts - A Pointer to Status register + Bit - Bit position + Timeout - Timeout amount to wait till the specified bit +Returns: + EFI_Status +--*/ +{ + UINT32 AccessCount = Timeout; + + if(!(*Sts & TPM_STS_VALID)) + return 0; + + do { + + FixedDelay((UINT32)Wait); + if((*Sts & Bit)){ return *Sts & Bit; } + AccessCount--; + } while (AccessCount); + + return 0; +} + + + +static +UINT8 +__stdcall +CheckStsBit ( + IN volatile UINT8 *Sts, + IN UINT8 Bit + ) +/*++ +Routine Description: + Function to check status a specific TPM status bit +Arguments: + *Sts - A Pointer to Status register + Bit - Bit position +Returns: + EFI_Status +--*/ +{ + while (!(*Sts & TPM_STS_VALID)); + return *Sts & Bit; +} + + + + +static +UINT16 +__stdcall +ReadBurstCount ( + IN TPM_1_2_REGISTERS_PTR TpmReg +) +/*++ +Routine Description: + Gets the number of bytes (burstCount) that the TPM can return + on reads or accept on writes without inserting LPC long wait + states on the LPC bus. + burstCount is TPM_STS_x register bits 8..23 +Arguments: + TpmReg - A Pointer to the TPM Register Space +Returns: + 0 - Any Errors + burstCount - TPM_STS_x.burstCount +--*/ +{ + UINT16 burstCount; + UINT64 Deadline = TIS_TIMEOUT_D; + + burstCount = 0; + + do { + // + // burstCount is little-endian bit ordering + // + FixedDelay((UINT32)Wait); + Deadline--; + burstCount = TpmReg->BurstCount; + }while (!burstCount && (Deadline > 0)); + + return burstCount; +} + + + +EFI_STATUS +__stdcall +TisRequestLocality ( + IN TPM_1_2_REGISTERS_PTR TpmReg + ) +/*++ +Routine Description: + Requests TPM locality 0 +Arguments: + TpmReg - A Pointer to the TPM Register Space +Returns: + EFI_Status +--*/ +{ + if ((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)==TPM_ACC_ACTIVE_LOCALITY){ + return EFI_SUCCESS;//EFI_ALREADY_STARTED; + } + TpmReg->Access = TPM_ACC_REQUEST_USE; + if (CheckAccessBit(&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY, (UINT32)TIS_TIMEOUT_B)) { + return EFI_SUCCESS; + } else { + return EFI_NOT_READY; + } +} + + + +#pragma optimize("",off) +EFI_STATUS +__stdcall +TisReleaseLocality ( + IN TPM_1_2_REGISTERS_PTR TpmReg + ) +/*++ +Routine Description: + Release TPM locality 0 +Arguments: + TpmReg - A Pointer to the TPM Register Space +Returns: + EFI_Status +--*/ +{ + UINT32 AccessCount=ACCESS_WAITCOUNT; + if (!CheckStsBit (&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY)) { + return EFI_DEVICE_ERROR; + } + + TpmReg->Access = TPM_ACC_ACTIVE_LOCALITY; + if (CheckStsBit(&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY)) { + do{/*give locality time to be released*/ + FixedDelay((UINT32)Wait); + AccessCount--; + }while(((CheckStsBit(&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY)) && AccessCount)); + if(CheckStsBit(&TpmReg->Access, TPM_ACC_ACTIVE_LOCALITY)){return EFI_DEVICE_ERROR;} + else{return EFI_SUCCESS;} + } else { + return EFI_SUCCESS; + } +} +#pragma optimize("",on) + + + + +EFI_STATUS +__stdcall +TisPrepareSendCommand ( + IN TPM_1_2_REGISTERS_PTR TpmReg + ) +/*++ +Routine Description: + Helper function to prepare to send a TPM command +Arguments: + TpmReg - A Pointer to the TPM Register Space +Returns: + EFI_Status +--*/ +{ + + if((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)!=TPM_ACC_ACTIVE_LOCALITY){ + return EFI_NOT_STARTED; + } + + do { + TpmReg->Sts = TPM_STS_READY; + } while (!(TpmReg->Sts & TPM_STS_READY)); + return EFI_SUCCESS; +} + +EFI_STATUS +__stdcall +TisSendCommand ( + IN TPM_1_2_REGISTERS_PTR TpmReg, + IN const VOID *CmdStream, + IN UINTN Size, + IN BOOLEAN Last + ) +/*++ +Routine Description: + Function to send TPM command +Arguments: + TpmReg - A Pointer to the TPM Register Space + *CmdStream - A Pointer to the command stream to be sent to TPM Fifo + Size - Size in bytes of the command stream + Last - Boolean to signify the last byte? +Returns: + EFI_Status +--*/ +{ + UINT8 *Ptr; + UINT16 burstCount; + + if (Size == 0) { + return Last ? EFI_INVALID_PARAMETER : EFI_SUCCESS; + } + + if ((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)!=TPM_ACC_ACTIVE_LOCALITY) { + return EFI_ABORTED; + } + + Ptr = (UINT8*)CmdStream; + + if (Last) { + Size--; + } + + while (Size > 0) { + burstCount = ReadBurstCount(TpmReg); + if (burstCount == 0) { + // Cannot get the correct burstCount value + return EFI_TIMEOUT; + } + + for (; burstCount > 0 && Size > 0; burstCount--) { + *(UINT8*)&TpmReg->DataFifo = *Ptr; + Ptr++; + Size--; + } + } + + if (Last) { + if (!CheckStsBit (&TpmReg->Sts, TPM_STS_EXPECT)) { + return EFI_ABORTED; + } + + *(UINT8*)&TpmReg->DataFifo = *Ptr; + + if (CheckStsBit (&TpmReg->Sts, TPM_STS_EXPECT)) { + return EFI_ABORTED; + } + + TpmReg->Sts = TPM_STS_GO; + + } + return EFI_SUCCESS; +} + + + + +EFI_STATUS +__stdcall +TisWaitForResponse ( + IN TPM_1_2_REGISTERS_PTR TpmReg + ) +/*++ +Routine Description: + Waits till TPM result is available +Arguments: + TpmReg - A Pointer to the TPM Register Space +Returns: + EFI_Status +--*/ +{ + if((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)!=TPM_ACC_ACTIVE_LOCALITY){ + return EFI_NOT_STARTED; + } + + while (!CheckStsBit (&TpmReg->Sts, TPM_STS_DATA_AVAILABLE)); + return EFI_SUCCESS; +} + + + + +EFI_STATUS +__stdcall +TisReceiveResponse ( + IN TPM_1_2_REGISTERS_PTR TpmReg, + OUT VOID *Buffer, + OUT UINTN *Size + ) +/*++ +Routine Description: + Function to recieve TPM command results +Arguments: + TpmReg - A Pointer to the TPM Register Space + *Buffer - A Pointer to buffer for recieving result data + Size - buffer size +Returns: + EFI_Status +--*/ +{ + UINT8 *Ptr, *BufEnd; + UINT16 burstCount; + + if((TpmReg->Access & TPM_ACC_ACTIVE_LOCALITY)!=TPM_ACC_ACTIVE_LOCALITY) { + return EFI_ABORTED; + } + + Ptr = (UINT8*)Buffer; + BufEnd = Ptr + *Size; + while (Ptr < BufEnd && + CheckStsBit (&TpmReg->Sts, TPM_STS_DATA_AVAILABLE)) { + + burstCount = ReadBurstCount(TpmReg); + if (burstCount == 0) { + return EFI_TIMEOUT; + } + while(burstCount && Ptr < BufEnd && CheckStsBit (&TpmReg->Sts, TPM_STS_DATA_AVAILABLE )){ + *Ptr++ = *(UINT8*)&TpmReg->DataFifo; + burstCount--; } + } + + *Size -= BufEnd - Ptr; + if (CheckStsBit (&TpmReg->Sts, TPM_STS_DATA_AVAILABLE)) { + return EFI_BUFFER_TOO_SMALL; + } else { + return EFI_SUCCESS; + } +} + + + +VOID +__stdcall +TisResendResponse ( + IN TPM_1_2_REGISTERS_PTR TpmReg + ) +/*++ +Routine Description: + Sets Bit to resend TPM command +Arguments: + TpmReg - A Pointer to the TPM Register Space +Returns: + EFI_Status +--*/ +{ + TpmReg->Sts = TPM_STS_RESPONSE_RETRY; +} + +EFI_STATUS +__stdcall +IsTpmPresent ( + IN TPM_1_2_REGISTERS_PTR TpmReg + ) +{ + if (TpmReg->Access == 0xff) { + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + + + + +EFI_STATUS +__stdcall +TpmLibPassThrough ( + IN TPM_1_2_REGISTERS_PTR TpmReg, + IN UINTN NoInputBuffers, + IN TPM_TRANSMIT_BUFFER *InputBuffers, + IN UINTN NoOutputBuffers, + IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers + ) +/*++ +Routine Description: + Higher level function to send a recieve commands to the TPM +Arguments: + TpmReg - A Pointer to the TPM Register Space + NoInputBuffers - Number count of Input buffers + *InputBuffers - Pointer to InputBuffers[0] + NoOutputBuffers - Number count of Output buffers + *OutputBuffers - Pointer to OutputBuffers[0] +Returns: + EFI_Status +--*/ +{ + EFI_STATUS Status; + UINTN i; + + if (NoInputBuffers == 0 || InputBuffers->Size < sizeof (TPM_1_2_CMD_HEADER)) { + return EFI_INVALID_PARAMETER; + } + + do { + NoInputBuffers--; + } while (InputBuffers[NoInputBuffers].Size == 0 && NoInputBuffers > 0); + + if (InputBuffers[NoInputBuffers].Size == 0) { + return EFI_INVALID_PARAMETER; + } + + Status = TisPrepareSendCommand (TpmReg); + + for (i = 0; !EFI_ERROR (Status) && i < NoInputBuffers; i++) { + Status = TisSendCommand ( + TpmReg, + InputBuffers[i].Buffer, + InputBuffers[i].Size, + FALSE + ); + } + + if (!EFI_ERROR (Status)) { + Status = TisSendCommand ( + TpmReg, + InputBuffers[i].Buffer, + InputBuffers[i].Size, + TRUE + ); + } + + if (!EFI_ERROR (Status)) { + Status = TisWaitForResponse (TpmReg); + } + + if (EFI_ERROR (Status)) { + goto Exit; + } + + Status = EFI_BUFFER_TOO_SMALL; + for (i = 0; Status == EFI_BUFFER_TOO_SMALL && i < NoOutputBuffers; i++) { + Status = TisReceiveResponse ( + TpmReg, + OutputBuffers[i].Buffer, + &OutputBuffers[i].Size + ); + } + +Exit: + TisCompleteCommand (TpmReg); + return Status; +} diff --git a/Core/EM/TCG2/TisLib/TpmLib.h b/Core/EM/TCG2/TisLib/TpmLib.h new file mode 100644 index 0000000..1e98660 --- /dev/null +++ b/Core/EM/TCG2/TisLib/TpmLib.h @@ -0,0 +1,136 @@ +/*++ + + Copyright (c) 2005 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + + Module Name: + + TpmLib.h + + Abstract: + + Header file for tpm device drivers + + --*/ +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TpmLib.h 1 4/21/14 2:14p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:14p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/TpmLib.h $ +// +// 1 4/21/14 2:14p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 3 5/19/10 5:11p Fredericko +// Included File Header +// Included File Revision History +// EIP 37653 +// +//************************************************************************* +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: TpmLib.c +// +// Description: +// Header file for TpmLib.c +// +//<AMI_FHDR_END> +//************************************************************************* + +#ifndef _TPMLIB_H_ +#define _TPMLIB_H_ + +#include "TcgPc.h" + +#define TisCompleteCommand TisPrepareSendCommand + +extern +EFI_STATUS +__stdcall TisRequestLocality ( + IN TPM_1_2_REGISTERS_PTR TpmReg ); + +extern +EFI_STATUS +__stdcall TisReleaseLocality ( + IN TPM_1_2_REGISTERS_PTR TpmReg ); + +extern +EFI_STATUS +__stdcall TisPrepareSendCommand ( + IN TPM_1_2_REGISTERS_PTR TpmReg ); + +extern +EFI_STATUS +__stdcall TisSendCommand ( + IN TPM_1_2_REGISTERS_PTR TpmReg, + IN const VOID *CmdStream, + IN UINTN Size, + IN BOOLEAN Last ); + +extern +EFI_STATUS +__stdcall TisWaitForResponse ( + IN TPM_1_2_REGISTERS_PTR TpmReg ); + +extern +EFI_STATUS +__stdcall TisReceiveResponse ( + IN TPM_1_2_REGISTERS_PTR TpmReg, + OUT VOID *Buffer, + OUT UINTN *Size ); + +extern +EFI_STATUS +__stdcall IsTpmPresent ( + IN TPM_1_2_REGISTERS_PTR TpmReg ); + +extern +EFI_STATUS +__stdcall TpmLibPassThrough ( + IN TPM_1_2_REGISTERS_PTR TpmReg, + IN UINTN NoInputBuffers, + IN TPM_TRANSMIT_BUFFER *InputBuffers, + IN UINTN NoOutputBuffers, + IN OUT TPM_TRANSMIT_BUFFER *OutputBuffers ); + +extern +EFI_STATUS +__stdcall TpmLibStartup ( + IN UINT16 StartupType ); + +#endif diff --git a/Core/EM/TCG2/TisLib/ZTEICTcmOrdinals.h b/Core/EM/TCG2/TisLib/ZTEICTcmOrdinals.h new file mode 100644 index 0000000..edf35ea --- /dev/null +++ b/Core/EM/TCG2/TisLib/ZTEICTcmOrdinals.h @@ -0,0 +1,203 @@ +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/ZTEICTcmOrdinals.h 1 4/21/14 2:14p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:14p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/ZTEICTcmOrdinals.h $ +// +// 1 4/21/14 2:14p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 7 3/29/11 12:26p Fredericko +// [TAG] EIP 54642 +// [Category] Improvement +// [Description] 1. Checkin Files related to TCG function override +// 2. Include TCM and TPM auto detection +// [Files] Affects all TCG files +// +// +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: ZTEICTcmOrdinals.h +// +// Description: +// Header file for ZTEIC specific ordinals +// +//<AMI_FHDR_END> +//************************************************************************* +#define TCM_ORD_ActivateIdentity ((UINT32) 0x0000807A) +#define TCM_ORD_AuthorizeMigrationKey ((UINT32) 0x0000802B) +#define TCM_ORD_CertifyKey ((UINT32) 0x00008032) +#define TCM_ORD_CertifyKey2 ((UINT32) 0x00008033) +#define TCM_ORD_CertifySelfTest ((UINT32) 0x00008052) +#define TCM_ORD_ChangeAuth ((UINT32) 0x0000800C) +#define TCM_ORD_ChangeAuthAsymFinish ((UINT32) 0x0000800F) +#define TCM_ORD_ChangeAuthAsymStart ((UINT32) 0x0000800E) +#define TCM_ORD_ChangeAuthOwner ((UINT32) 0x00008010) +#define TCM_ORD_CMK_ApproveMA ((UINT32) 0x0000801D) +#define TCM_ORD_CMK_ConvertMigration ((UINT32) 0x00008024) +#define TCM_ORD_CMK_CreateBlob ((UINT32) 0x0000801B) +#define TCM_ORD_CMK_CreateKey ((UINT32) 0x00008013) +#define TCM_ORD_CMK_CreateTicket ((UINT32) 0x00008012) +#define TCM_ORD_CMK_SetRestrictions ((UINT32) 0x0000801C) +#define TCM_ORD_ContinueSelfTest ((UINT32) 0x00008053) +#define TCM_ORD_ConvertMigrationBlob ((UINT32) 0x0000802A) +#define TCM_ORD_CreateCounter ((UINT32) 0x000080DC) +#define TCM_ORD_CreateEndorsementKeyPair ((UINT32) 0x00008078) +#define TCM_ORD_CreateMaintenanceArchive ((UINT32) 0x0000802C) +#define TCM_ORD_CreateMigrationBlob ((UINT32) 0x00008028) +#define TCM_ORD_CreateRevocableEK ((UINT32) 0x0000807F) +#define TCM_ORD_CreateWrapKey ((UINT32) 0x0000801F) +#define TCM_ORD_DAA_JOIN ((UINT32) 0x00008029) +#define TCM_ORD_DAA_SIGN ((UINT32) 0x00008031) +#define TCM_ORD_Delegate_CreateKeyDelegation ((UINT32) 0x000080D4) +#define TCM_ORD_Delegate_CreateOwnerDelegation ((UINT32) 0x000080D5) +#define TCM_ORD_Delegate_LoadOwnerDelegation ((UINT32) 0x000080D8) +#define TCM_ORD_Delegate_Manage ((UINT32) 0x000080D2) +#define TCM_ORD_Delegate_ReadTable ((UINT32) 0x000080DB) +#define TCM_ORD_Delegate_UpdateVerification ((UINT32) 0x000080D1) +#define TCM_ORD_Delegate_VerifyDelegation ((UINT32) 0x000080D6) +#define TCM_ORD_DirRead ((UINT32) 0x0000801A) +#define TCM_ORD_DirWriteAuth ((UINT32) 0x00008019) +#define TCM_ORD_DisableForceClear ((UINT32) 0x0000805E) +#define TCM_ORD_DisableOwnerClear ((UINT32) 0x0000805C) +#define TCM_ORD_DisablePubekRead ((UINT32) 0x0000807E) +#define TCM_ORD_DSAP ((UINT32) 0x00008011) +#define TCM_ORD_EstablishTransport ((UINT32) 0x000080E6) +#define TCM_ORD_EvictKey ((UINT32) 0x00008022) +#define TCM_ORD_ExecuteTransport ((UINT32) 0x000080E7) +#define TCM_ORD_Extend ((UINT32) 0x00008014) +#define TCM_ORD_FieldUpgrade ((UINT32) 0x000080AA) +#define TCM_ORD_FlushSpecific ((UINT32) 0x000080BA) +#define TCM_ORD_ForceClear ((UINT32) 0x0000805D) +#define TCM_ORD_GetAuditDigest ((UINT32) 0x00008085) +#define TCM_ORD_GetAuditDigestSigned ((UINT32) 0x00008086) +#define TCM_ORD_GetAuditEvent ((UINT32) 0x00008082) +#define TCM_ORD_GetAuditEventSigned ((UINT32) 0x00008083) +#define TCM_ORD_GetCapability ((UINT32) 0x00008065) +#define TCM_ORD_GetCapabilityOwner ((UINT32) 0x00008066) +#define TCM_ORD_GetCapabilitySigned ((UINT32) 0x00008064) +#define TCM_ORD_GetOrdinalAuditStatus ((UINT32) 0x0000808C) +#define TCM_ORD_GetPubKey ((UINT32) 0x00008021) +#define TCM_ORD_GetRandom ((UINT32) 0x00008046) +#define TCM_ORD_GetTestResult ((UINT32) 0x00008054) +#define TCM_ORD_GetTicks ((UINT32) 0x000080F1) +#define TCM_ORD_IncrementCounter ((UINT32) 0x000080DD) +#define TCM_ORD_Init ((UINT32) 0x00008097) +#define TCM_ORD_KeyControlOwner ((UINT32) 0x00008023) +#define TCM_ORD_KillMaintenanceFeature ((UINT32) 0x0000802E) +#define TCM_ORD_LoadAuthContext ((UINT32) 0x000080B7) +#define TCM_ORD_LoadContext ((UINT32) 0x000080B9) +#define TCM_ORD_LoadKey ((UINT32) 0x00008020) +#define TCM_ORD_LoadKey2 ((UINT32) 0x00008041) +#define TCM_ORD_LoadKeyContext ((UINT32) 0x000080B5) +#define TCM_ORD_LoadMaintenanceArchive ((UINT32) 0x0000802D) +#define TCM_ORD_LoadManuMaintPub ((UINT32) 0x0000802F) +#define TCM_ORD_MakeIdentity ((UINT32) 0x00008079) +#define TCM_ORD_MigrateKey ((UINT32) 0x00008025) +#define TCM_ORD_NV_DefineSpace ((UINT32) 0x000080CC) +#define TCM_ORD_NV_ReadValue ((UINT32) 0x000080CF) +#define TCM_ORD_NV_ReadValueAuth ((UINT32) 0x000080D0) +#define TCM_ORD_NV_WriteValue ((UINT32) 0x000080CD) +#define TCM_ORD_NV_WriteValueAuth ((UINT32) 0x000080CE) +#define TCM_ORD_OIAP ((UINT32) 0x0000800A) +#define TCM_ORD_OSAP ((UINT32) 0x0000800B) +#define TCM_ORD_OwnerClear ((UINT32) 0x0000805B) +#define TCM_ORD_OwnerReadInternalPub ((UINT32) 0x00008081) +#define TCM_ORD_OwnerReadPubek ((UINT32) 0x0000807D) +#define TCM_ORD_OwnerSetDisable ((UINT32) 0x0000806E) +#define TCM_ORD_PCR_Reset ((UINT32) 0x000080C8) +#define TCM_ORD_PcrRead ((UINT32) 0x00008015) +#define TCM_ORD_PhysicalDisable ((UINT32) 0x00008070) +#define TCM_ORD_PhysicalEnable ((UINT32) 0x0000806F) +#define TCM_ORD_PhysicalSetDeactivated ((UINT32) 0x00008072) +#define TCM_ORD_Quote ((UINT32) 0x00008016) +#define TCM_ORD_Quote2 ((UINT32) 0x0000803E) +#define TCM_ORD_ReadCounter ((UINT32) 0x000080DE) +#define TCM_ORD_ReadManuMaintPub ((UINT32) 0x00008030) +#define TCM_ORD_ReadPubek ((UINT32) 0x0000807C) +#define TCM_ORD_ReleaseCounter ((UINT32) 0x000080DF) +#define TCM_ORD_ReleaseCounterOwner ((UINT32) 0x000080E0) +#define TCM_ORD_ReleaseTransportSigned ((UINT32) 0x000080E8) +#define TCM_ORD_Reset ((UINT32) 0x0000805A) +#define TCM_ORD_ResetLockValue ((UINT32) 0x00008040) +#define TCM_ORD_RevokeTrust ((UINT32) 0x00008080) +#define TCM_ORD_SaveAuthContext ((UINT32) 0x000080B6) +#define TCM_ORD_SaveContext ((UINT32) 0x000080B8) +#define TCM_ORD_SaveKeyContext ((UINT32) 0x000080B4) +#define TCM_ORD_SaveState ((UINT32) 0x00008098) +#define TCM_ORD_Seal ((UINT32) 0x00008017) +#define TCM_ORD_Sealx ((UINT32) 0x0000803D) +#define TCM_ORD_SelfTestFull ((UINT32) 0x00008050) +#define TCM_ORD_SetCapability ((UINT32) 0x0000803F) +#define TCM_ORD_SetOperatorAuth ((UINT32) 0x00008074) +#define TCM_ORD_SetOrdinalAuditStatus ((UINT32) 0x0000808D) +#define TCM_ORD_SetOwnerInstall ((UINT32) 0x00008071) +#define TCM_ORD_SetOwnerPointer ((UINT32) 0x00008075) +#define TCM_ORD_SetRedirection ((UINT32) 0x0000809A) +#define TCM_ORD_SetTempDeactivated ((UINT32) 0x00008073) +#define TCM_ORD_SHA1CompleteExtend ((UINT32) 0x000080ED) +#define TCM_ORD_SHA1Start ((UINT32) 0x000080EA) +#define TCM_ORD_SHA1Update ((UINT32) 0x000080EB) +#define TCM_ORD_Sign ((UINT32) 0x0000803C) +#define TCM_ORD_Startup ((UINT32) 0x00008099) +#define TCM_ORD_StirRandom ((UINT32) 0x00008047) +#define TCM_ORD_TakeOwnership ((UINT32) 0x0000800D) +#define TCM_ORD_Terminate_Handle ((UINT32) 0x00008096) +#define TCM_ORD_TickStampBlob ((UINT32) 0x000080F2) +#define TCM_ORD_UnBind ((UINT32) 0x0000801E) +#define TCM_ORD_Unseal ((UINT32) 0x00008018) +#define TCM_TSC_ORD_PhysicalPresence ((UINT32) 0x4000800A) +#define TCM_TSC_ORD_ResetEstablishmentBit ((UINT32) 0x4000800B) +//********************************************************************** +//********************************************************************** +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//********************************************************************** +//**********************************************************************
\ No newline at end of file diff --git a/Core/EM/TCG2/TisLib/sha.h b/Core/EM/TCG2/TisLib/sha.h new file mode 100644 index 0000000..218bc34 --- /dev/null +++ b/Core/EM/TCG2/TisLib/sha.h @@ -0,0 +1,122 @@ +/*++ + + Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + + Module Name: + + sha1.h + + Abstract: + + --*/ +//************************************************************************* +// $Header: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/sha.h 1 4/21/14 2:14p Fredericko $ +// +// $Revision: 1 $ +// +// $Date: 4/21/14 2:14p $ +//************************************************************************* +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/TCG2/Libraries/TisLib/sha.h $ +// +// 1 4/21/14 2:14p Fredericko +// +// 1 10/08/13 11:58a Fredericko +// Initial Check-In for Tpm-Next module +// +// 1 10/03/13 12:35p Fredericko +// Sha256 support policy update +// +// 1 7/10/13 5:50p Fredericko +// [TAG] EIP120969 +// [Category] New Feature +// [Description] TCG (TPM20) +// [Files] TisLib.cif +// TisLib.mak +// TcgTpm12.h +// TpmLib.h +// TcgCommon.h +// ZTEICTcmOrdinals.h +// TpmLib.c +// TcgCommon.c +// TisLib.sdl +// sha1.h +// INTTcgAcpi.h +// TcgPc.h +// TcmPc.h +// TcgEfiTpm.h +// TcgEFI12.h +// +// 8 3/29/11 12:24p Fredericko +// +// 7 3/28/11 12:14p Fredericko +// [TAG] EIP 54642 +// [Category] Improvement +// [Description] 1. Checkin Files related to TCG function override +// 2. Include TCM and TPM auto detection +// [Files] Affects all TCG files +// +// 6 5/19/10 5:09p Fredericko +// Included File Header +// Included File Revision History +// EIP 37653 +// +//************************************************************************* +//************************************************************************* +//<AMI_FHDR_START> +// +// Name: Sha1.h +// +// Description: +// Header file for sha1.c +// +//<AMI_FHDR_END> +//************************************************************************* + +#ifndef _CAL_SHA1_H_ +#define _CAL_SHA1_H_ + +#include "TcgTpm12.h" +#include "token.h" + + +typedef TPM_ALGORITHM_ID TCG_ALGORITHM_ID; +#define TCG_ALG_SHA 0x00000004 // The SHA1 algorithm +typedef unsigned long u32; + +struct SHA1Context { + u32 state[5]; + u32 count[2]; + unsigned char buffer[64]; +}; + +typedef struct SHA1Context SHA1_CTX; + + + +void SHA1Init(struct SHA1Context *context); +void SHA1Update(struct SHA1Context *context, const void *data, u32 len); +void SHA1Final(unsigned char digest[20], struct SHA1Context *context); + +struct sha256_state { + UINT64 length; + UINT32 state[8], curlen; + UINT8 buf[64]; +}; + +typedef struct sha256_state SHA2_CTX; + +void sha256_init(struct sha256_state *md); +int sha256_process(struct sha256_state *md, const unsigned char *in, unsigned long inlen); +int sha256_done(struct sha256_state *md, unsigned char *out); + +#endif // _CAL_SHA1_H_ |