PeiTpmMeasurementLib.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /** @file
  2. This library is used by other modules to measure data to TPM.
  3. Copyright (c) 2020, Intel Corporation. All rights reserved. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/BaseMemoryLib.h>
  8. #include <Library/PeiServicesLib.h>
  9. #include <Library/PeiServicesTablePointerLib.h>
  10. #include <Library/DebugLib.h>
  11. #include <Library/HobLib.h>
  12. #include <Library/TpmMeasurementLib.h>
  13. #include <Ppi/Tcg.h>
  14. #include <IndustryStandard/UefiTcgPlatform.h>
  15. /**
  16. Tpm measure and log data, and extend the measurement result into a specific PCR.
  17. @param[in] PcrIndex PCR Index.
  18. @param[in] EventType Event type.
  19. @param[in] EventLog Measurement event log.
  20. @param[in] LogLen Event log length in bytes.
  21. @param[in] HashData The start of the data buffer to be hashed, extended.
  22. @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
  23. @retval EFI_SUCCESS Operation completed successfully.
  24. @retval EFI_UNSUPPORTED TPM device not available.
  25. @retval EFI_OUT_OF_RESOURCES Out of memory.
  26. @retval EFI_DEVICE_ERROR The operation was unsuccessful.
  27. **/
  28. EFI_STATUS
  29. EFIAPI
  30. TpmMeasureAndLogData (
  31. IN UINT32 PcrIndex,
  32. IN UINT32 EventType,
  33. IN VOID *EventLog,
  34. IN UINT32 LogLen,
  35. IN VOID *HashData,
  36. IN UINT64 HashDataLen
  37. )
  38. {
  39. EFI_STATUS Status;
  40. EDKII_TCG_PPI *TcgPpi;
  41. TCG_PCR_EVENT_HDR TcgEventHdr;
  42. Status = PeiServicesLocatePpi (
  43. &gEdkiiTcgPpiGuid,
  44. 0,
  45. NULL,
  46. (VOID **)&TcgPpi
  47. );
  48. if (EFI_ERROR (Status)) {
  49. return Status;
  50. }
  51. TcgEventHdr.PCRIndex = PcrIndex;
  52. TcgEventHdr.EventType = EventType;
  53. TcgEventHdr.EventSize = LogLen;
  54. Status = TcgPpi->HashLogExtendEvent (
  55. TcgPpi,
  56. 0,
  57. HashData,
  58. (UINTN)HashDataLen,
  59. &TcgEventHdr,
  60. EventLog
  61. );
  62. return Status;
  63. }