summaryrefslogtreecommitdiff
path: root/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
diff options
context:
space:
mode:
authorMichael Kinney <michael.d.kinney@intel.com>2016-01-21 19:30:21 +0000
committermdkinney <mdkinney@Edk2>2016-01-21 19:30:21 +0000
commit441a3678e1c94212b6cc250da9a4999451321b1d (patch)
tree73340bf0acd464db59853a580b7262a6112dcaa2 /SecurityPkg/Tcg/TcgDxe/TcgDxe.c
parent45500265b3fbb05d98766b82af98f8642a8e5eba (diff)
downloadedk2-platforms-441a3678e1c94212b6cc250da9a4999451321b1d.tar.xz
SecurityPkg/TcgDxe: Use updated Tpm12CommandLib APIs
Use the following new APIs in Tpm12CommandLib and remove duplicate code from TcgPei and TcgDxe: Tpm12Extend() Tpm12PhysicalPresence() Tpm12ContinueSelfTest() Tpm12GetCapabilityFlagPermanent() Tpm12GetCapabilityFlagVolatile() Cc: Chao Zhang <chao.b.zhang@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Kinney <michael.d.kinney@intel.com> Reviewed-by: Chao Zhang <chao.b.zhang@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19729 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'SecurityPkg/Tcg/TcgDxe/TcgDxe.c')
-rw-r--r--SecurityPkg/Tcg/TcgDxe/TcgDxe.c114
1 files changed, 93 insertions, 21 deletions
diff --git a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
index 39cf38b300..690f356bbb 100644
--- a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
+++ b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
@@ -50,8 +50,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/PcdLib.h>
#include <Library/UefiLib.h>
#include <Library/ReportStatusCodeLib.h>
-
-#include "TpmComm.h"
+#include <Library/Tpm12CommandLib.h>
+#include <Library/BaseCryptLib.h>
#define TCG_DXE_DATA_FROM_THIS(this) \
BASE_CR (this, TCG_DXE_DATA, TcgProtocol)
@@ -271,6 +271,40 @@ TcgDxeStatusCheck (
}
/**
+Single function calculates SHA1 digest value for all raw data. It
+combines Sha1Init(), Sha1Update() and Sha1Final().
+
+@param[in] Data Raw data to be digested.
+@param[in] DataLen Size of the raw data.
+@param[out] Digest Pointer to a buffer that stores the final digest.
+
+@retval EFI_SUCCESS Always successfully calculate the final digest.
+**/
+EFI_STATUS
+EFIAPI
+TpmCommHashAll (
+ IN CONST UINT8 *Data,
+ IN UINTN DataLen,
+ OUT TPM_DIGEST *Digest
+ )
+{
+ VOID *Sha1Ctx;
+ UINTN CtxSize;
+
+ CtxSize = Sha1GetContextSize ();
+ Sha1Ctx = AllocatePool (CtxSize);
+ ASSERT (Sha1Ctx != NULL);
+
+ Sha1Init (Sha1Ctx);
+ Sha1Update (Sha1Ctx, Data, DataLen);
+ Sha1Final (Sha1Ctx, (UINT8 *)Digest);
+
+ FreePool (Sha1Ctx);
+
+ return EFI_SUCCESS;
+}
+
+/**
This service abstracts the capability to do a hash operation on a data buffer.
@param[in] This Indicates the calling context
@@ -334,6 +368,53 @@ TcgDxeHashAll (
}
/**
+Add a new entry to the Event Log.
+
+@param[in, out] EventLogPtr Pointer to the Event Log data.
+@param[in, out] LogSize Size of the Event Log.
+@param[in] MaxSize Maximum size of the Event Log.
+@param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
+@param[in] NewEventData Pointer to the new event data.
+
+@retval EFI_SUCCESS The new event log entry was added.
+@retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
+
+**/
+EFI_STATUS
+TpmCommLogEvent (
+ IN OUT UINT8 **EventLogPtr,
+ IN OUT UINTN *LogSize,
+ IN UINTN MaxSize,
+ IN TCG_PCR_EVENT_HDR *NewEventHdr,
+ IN UINT8 *NewEventData
+ )
+{
+ UINTN NewLogSize;
+
+ //
+ // Prevent Event Overflow
+ //
+ if (NewEventHdr->EventSize > (UINTN)(~0) - sizeof (*NewEventHdr)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ NewLogSize = sizeof (*NewEventHdr) + NewEventHdr->EventSize;
+ if (NewLogSize > MaxSize - *LogSize) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ *EventLogPtr += *LogSize;
+ *LogSize += NewLogSize;
+ CopyMem (*EventLogPtr, NewEventHdr, sizeof (*NewEventHdr));
+ CopyMem (
+ *EventLogPtr + sizeof (*NewEventHdr),
+ NewEventData,
+ NewEventHdr->EventSize
+ );
+ return EFI_SUCCESS;
+}
+
+/**
Add a new entry to the Event Log.
@param[in] TcgData TCG_DXE_DATA structure.
@@ -442,8 +523,6 @@ TcgDxePassThroughToTpm (
IN UINT8 *TpmOutputParameterBlock
)
{
- TCG_DXE_DATA *TcgData;
-
if (TpmInputParameterBlock == NULL ||
TpmOutputParameterBlock == NULL ||
TpmInputParameterBlockSize == 0 ||
@@ -451,14 +530,11 @@ TcgDxePassThroughToTpm (
return EFI_INVALID_PARAMETER;
}
- TcgData = TCG_DXE_DATA_FROM_THIS (This);
-
- return TisPcExecute (
- "%r%/%r",
+ return Tpm12SubmitCommand (
+ TpmInputParameterBlockSize,
TpmInputParameterBlock,
- (UINTN) TpmInputParameterBlockSize,
- TpmOutputParameterBlock,
- (UINTN) TpmOutputParameterBlockSize
+ &TpmOutputParameterBlockSize,
+ TpmOutputParameterBlock
);
}
@@ -506,7 +582,7 @@ TcgDxeHashLogExtendEventI (
}
}
- Status = TpmCommExtend (
+ Status = Tpm12Extend (
&NewEventHdr->Digest,
NewEventHdr->PCRIndex,
NULL
@@ -1272,19 +1348,15 @@ OnExitBootServicesFailed (
**/
EFI_STATUS
GetTpmStatus (
- OUT BOOLEAN *TPMDeactivatedFlag
+ OUT BOOLEAN *TPMDeactivatedFlag
)
{
- EFI_STATUS Status;
- TPM_STCLEAR_FLAGS VFlags;
+ EFI_STATUS Status;
+ TPM_STCLEAR_FLAGS VolatileFlags;
- Status = TpmCommGetFlags (
- TPM_CAP_FLAG_VOLATILE,
- &VFlags,
- sizeof (VFlags)
- );
+ Status = Tpm12GetCapabilityFlagVolatile (&VolatileFlags);
if (!EFI_ERROR (Status)) {
- *TPMDeactivatedFlag = VFlags.deactivated;
+ *TPMDeactivatedFlag = VolatileFlags.deactivated;
}
return Status;