HashLibBaseCryptoRouterCommon.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. { HASH_ALGORITHM_SM3_256_GUID, HASH_ALG_SM3_256 },
  24. };
  25. /**
  26. The function get hash mask info from algorithm.
  27. @param HashGuid Hash Guid
  28. @return HashMask
  29. **/
  30. UINT32
  31. EFIAPI
  32. Tpm2GetHashMaskFromAlgo (
  33. IN EFI_GUID *HashGuid
  34. )
  35. {
  36. UINTN Index;
  37. for (Index = 0; Index < sizeof (mTpm2HashMask)/sizeof (mTpm2HashMask[0]); Index++) {
  38. if (CompareGuid (HashGuid, &mTpm2HashMask[Index].Guid)) {
  39. return mTpm2HashMask[Index].Mask;
  40. }
  41. }
  42. return 0;
  43. }
  44. /**
  45. The function set digest to digest list.
  46. @param DigestList digest list
  47. @param Digest digest data
  48. **/
  49. VOID
  50. EFIAPI
  51. Tpm2SetHashToDigestList (
  52. IN OUT TPML_DIGEST_VALUES *DigestList,
  53. IN TPML_DIGEST_VALUES *Digest
  54. )
  55. {
  56. CopyMem (
  57. &DigestList->digests[DigestList->count],
  58. &Digest->digests[0],
  59. sizeof (Digest->digests[0])
  60. );
  61. DigestList->count++;
  62. }