HashLibBaseCryptoRouterCommon.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /** @file
  2. This is BaseCrypto router support function.
  3. Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/BaseLib.h>
  8. #include <Library/BaseMemoryLib.h>
  9. #include <Library/Tpm2CommandLib.h>
  10. #include <Library/DebugLib.h>
  11. #include <Library/MemoryAllocationLib.h>
  12. #include <Library/HashLib.h>
  13. #include <Protocol/Tcg2Protocol.h>
  14. typedef struct {
  15. EFI_GUID Guid;
  16. UINT32 Mask;
  17. } TPM2_HASH_MASK;
  18. TPM2_HASH_MASK mTpm2HashMask[] = {
  19. {HASH_ALGORITHM_SHA1_GUID, HASH_ALG_SHA1},
  20. {HASH_ALGORITHM_SHA256_GUID, HASH_ALG_SHA256},
  21. {HASH_ALGORITHM_SHA384_GUID, HASH_ALG_SHA384},
  22. {HASH_ALGORITHM_SHA512_GUID, HASH_ALG_SHA512},
  23. };
  24. /**
  25. The function get hash mask info from algorithm.
  26. @param HashGuid Hash Guid
  27. @return HashMask
  28. **/
  29. UINT32
  30. EFIAPI
  31. Tpm2GetHashMaskFromAlgo (
  32. IN EFI_GUID *HashGuid
  33. )
  34. {
  35. UINTN Index;
  36. for (Index = 0; Index < sizeof(mTpm2HashMask)/sizeof(mTpm2HashMask[0]); Index++) {
  37. if (CompareGuid (HashGuid, &mTpm2HashMask[Index].Guid)) {
  38. return mTpm2HashMask[Index].Mask;
  39. }
  40. }
  41. return 0;
  42. }
  43. /**
  44. The function set digest to digest list.
  45. @param DigestList digest list
  46. @param Digest digest data
  47. **/
  48. VOID
  49. EFIAPI
  50. Tpm2SetHashToDigestList (
  51. IN OUT TPML_DIGEST_VALUES *DigestList,
  52. IN TPML_DIGEST_VALUES *Digest
  53. )
  54. {
  55. CopyMem (
  56. &DigestList->digests[DigestList->count],
  57. &Digest->digests[0],
  58. sizeof(Digest->digests[0])
  59. );
  60. DigestList->count ++;
  61. }