From 6701b862aa96775609a7d42662ae4a98e43071bb Mon Sep 17 00:00:00 2001 From: kavsrf Date: Sun, 4 Dec 2016 13:46:48 +0300 Subject: TPM12 support --- Include/Library/CommonLib.h | 43 +++++++++++++++++- Include/Library/DcsCfgLib.h | 5 ++- Include/Library/DcsTpmLib.h | 106 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 Include/Library/DcsTpmLib.h (limited to 'Include') diff --git a/Include/Library/CommonLib.h b/Include/Library/CommonLib.h index e1e30b0..5f96bba 100644 --- a/Include/Library/CommonLib.h +++ b/Include/Library/CommonLib.h @@ -22,6 +22,15 @@ https://opensource.org/licenses/LGPL-3.0 #include #include +////////////////////////////////////////////////////////////////////////// +// Check error +////////////////////////////////////////////////////////////////////////// +extern UINTN gCELine; +#define CE(ex) gCELine = __LINE__; if(EFI_ERROR(res = ex)) goto err + +////////////////////////////////////////////////////////////////////////// +// defines +////////////////////////////////////////////////////////////////////////// #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) #define FIELD_OFFSET(t, f) ((UINTN)(&((t*)0)->f)) @@ -32,7 +41,7 @@ https://opensource.org/licenses/LGPL-3.0 #define MEM_ALLOC MemAlloc #define MEM_FREE MemFree #define MEM_REALLOC MemRealloc -#define MEM_BURN(ptr,count) do { volatile char *burnPtr = (volatile char *)(ptr); UINT64 burnCount = (UINT64) count; while (burnCount--) *burnPtr++ = 0; } while (0) +#define MEM_BURN(ptr,count) do { volatile char *burnPtr = (volatile char *)(ptr); UINTN burnCount = (UINTN) count; while (burnCount--) *burnPtr++ = 0; } while (0) VOID* MemAlloc( @@ -182,6 +191,11 @@ TouchGetIO( #define OUT_PRINT(format, ...) AttrPrintEx(-1,-1, format, ##__VA_ARGS__) #define ERR_PRINT(format, ...) AttrPrintEx(-1,-1, L"%E" format L"%N" , ##__VA_ARGS__) +VOID +PrintBytes( + IN UINT8* Data, + IN UINT32 Size); + EFI_STATUS ConsoleGetOutput( IN EFI_HANDLE handle, @@ -270,6 +284,33 @@ AsciiStrToGuid( IN CHAR8 *str ); +////////////////////////////////////////////////////////////////////////// +// Menu +////////////////////////////////////////////////////////////////////////// +typedef EFI_STATUS(*MENU_ACTION)(IN VOID *ctx); + +typedef struct _MENU_ITEM MENU_ITEM; +typedef struct _MENU_ITEM { + CHAR16 Text[128]; + CHAR16 Select; + MENU_ACTION Action; + VOID* Context; + MENU_ITEM *Next; +} MENU_ITEM, *PMENU_ITEM; + +PMENU_ITEM +DcsMenuAppend( + IN PMENU_ITEM menu, + IN CHAR16 *text, + IN CHAR16 select, + IN MENU_ACTION action, + IN VOID* actionContext + ); + +VOID +DcsMenuPrint( + IN PMENU_ITEM head + ); ////////////////////////////////////////////////////////////////////////// // Attribute print diff --git a/Include/Library/DcsCfgLib.h b/Include/Library/DcsCfgLib.h index 6d74729..322aaa1 100644 --- a/Include/Library/DcsCfgLib.h +++ b/Include/Library/DcsCfgLib.h @@ -118,7 +118,9 @@ enum RndGeneratorTypes { RndTypeNone = 0, RndTypeFile, RndTypeRDRand, - RndTypeDtrmHmacSha512 + RndTypeDtrmHmacSha512, + RndTypeOpenSSL, + RndTypeTpm }; #define RND_HEADER_SIGN SIGNATURE_64('D','C','S','_','R','A','N','D') @@ -186,6 +188,7 @@ EFI_STATUS RndInit( IN UINTN rndType, IN VOID* Context, + IN UINTN ContextSize, OUT DCS_RND **rnd); // Serialize rnd with state to/from memory diff --git a/Include/Library/DcsTpmLib.h b/Include/Library/DcsTpmLib.h new file mode 100644 index 0000000..a8f015e --- /dev/null +++ b/Include/Library/DcsTpmLib.h @@ -0,0 +1,106 @@ +/** @file +Dcs TPM library + +Copyright (c) 2016. Disk Cryptography Services for EFI (DCS), Alex Kolotnikov +Copyright (c) 2016. VeraCrypt, Mounir IDRASSI + +This program and the accompanying materials are licensed and made available +under the terms and conditions of the GNU Lesser General Public License, version 3.0 (LGPL-3.0). + +The full text of the license may be found at +https://opensource.org/licenses/LGPL-3.0 +**/ + +#ifndef __DCSTPMLIB_H__ +#define __DCSTPMLIB_H__ + +#include + +EFI_STATUS +InitTpm12(); + +EFI_STATUS +Tpm12PcrRead( + IN UINT32 PcrIndex, + OUT void *PcrValue + ); + +EFI_STATUS +Tpm12DumpPcrs( + IN UINT32 sPcr, + IN UINT32 ePcr); + +EFI_STATUS +Tpm12GetNvList( + OUT UINT32 *respSize, + OUT UINT32 *resp + ); + +EFI_STATUS +Tpm12NvDetails( + IN UINT32 index, + OUT UINT32 *attr, + OUT UINT32 *dataSz, + OUT UINT32 *pcrR, + OUT UINT32 *pcrW + ); + +EFI_STATUS +Tpm12GetRandom( + IN OUT UINT32 *DataSize, + OUT UINT8 *Data + ); + +////////////////////////////////////////////////////////////////////////// +// DCS TPM protocol +////////////////////////////////////////////////////////////////////////// +/* +Lock - Try lock TPM secret +Apply - Apply secret to password +Configure - Create TPM secret and configure PCRs +IsConfigured - TPM secret is set? +IsOpen - Can apply secret? +*/ +typedef struct _DCS_TPM_PROTOCOL DCS_TPM_PROTOCOL; + +extern DCS_TPM_PROTOCOL* gTpm; + +typedef EFI_STATUS(*DCS_TPM_LOCK)( + IN DCS_TPM_PROTOCOL *tpm + ); + +typedef EFI_STATUS(*DCS_TPM_APPLY)( + IN DCS_TPM_PROTOCOL *tpm, + OUT VOID* pwd + ); + +typedef EFI_STATUS(*DCS_TPM_CONFIGURE)( + IN DCS_TPM_PROTOCOL *tpm + ); + +typedef BOOLEAN(*DCS_TPM_IS_OPEN)( + IN DCS_TPM_PROTOCOL *tpm + ); + +typedef BOOLEAN(*DCS_TPM_IS_CONFIGURED)( + IN DCS_TPM_PROTOCOL *tpm + ); + +typedef struct _DCS_TPM_PROTOCOL { + DCS_TPM_LOCK Lock; + DCS_TPM_APPLY Apply; + DCS_TPM_CONFIGURE Configure; + DCS_TPM_IS_OPEN IsOpen; + DCS_TPM_IS_CONFIGURED IsConfigured; +} DCS_TPM_PROTOCOL; + +EFI_STATUS +GetTpm(); + +EFI_STATUS +TpmMeasure( + IN VOID* data, + IN UINTN dataSz + ); + +#endif \ No newline at end of file -- cgit v1.2.3