DxeImageVerificationLib.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /** @file
  2. The internal header file includes the common header files, defines
  3. internal structure and functions used by ImageVerificationLib.
  4. Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef __IMAGEVERIFICATIONLIB_H__
  8. #define __IMAGEVERIFICATIONLIB_H__
  9. #include <Library/UefiDriverEntryPoint.h>
  10. #include <Library/DebugLib.h>
  11. #include <Library/BaseMemoryLib.h>
  12. #include <Library/UefiBootServicesTableLib.h>
  13. #include <Library/UefiRuntimeServicesTableLib.h>
  14. #include <Library/UefiLib.h>
  15. #include <Library/BaseLib.h>
  16. #include <Library/MemoryAllocationLib.h>
  17. #include <Library/BaseCryptLib.h>
  18. #include <Library/PcdLib.h>
  19. #include <Library/DevicePathLib.h>
  20. #include <Library/SecurityManagementLib.h>
  21. #include <Library/PeCoffLib.h>
  22. #include <Protocol/FirmwareVolume2.h>
  23. #include <Protocol/DevicePath.h>
  24. #include <Protocol/BlockIo.h>
  25. #include <Protocol/SimpleFileSystem.h>
  26. #include <Protocol/VariableWrite.h>
  27. #include <Guid/ImageAuthentication.h>
  28. #include <Guid/AuthenticatedVariableFormat.h>
  29. #include <IndustryStandard/PeImage.h>
  30. #define EFI_CERT_TYPE_RSA2048_SHA256_SIZE 256
  31. #define EFI_CERT_TYPE_RSA2048_SIZE 256
  32. #define MAX_NOTIFY_STRING_LEN 64
  33. #define TWO_BYTE_ENCODE 0x82
  34. #define ALIGNMENT_SIZE 8
  35. #define ALIGN_SIZE(a) (((a) % ALIGNMENT_SIZE) ? ALIGNMENT_SIZE - ((a) % ALIGNMENT_SIZE) : 0)
  36. //
  37. // Image type definitions
  38. //
  39. #define IMAGE_UNKNOWN 0x00000000
  40. #define IMAGE_FROM_FV 0x00000001
  41. #define IMAGE_FROM_OPTION_ROM 0x00000002
  42. #define IMAGE_FROM_REMOVABLE_MEDIA 0x00000003
  43. #define IMAGE_FROM_FIXED_MEDIA 0x00000004
  44. //
  45. // Authorization policy bit definition
  46. //
  47. #define ALWAYS_EXECUTE 0x00000000
  48. #define NEVER_EXECUTE 0x00000001
  49. #define ALLOW_EXECUTE_ON_SECURITY_VIOLATION 0x00000002
  50. #define DEFER_EXECUTE_ON_SECURITY_VIOLATION 0x00000003
  51. #define DENY_EXECUTE_ON_SECURITY_VIOLATION 0x00000004
  52. #define QUERY_USER_ON_SECURITY_VIOLATION 0x00000005
  53. //
  54. // Support hash types
  55. //
  56. #define HASHALG_SHA1 0x00000000
  57. #define HASHALG_SHA224 0x00000001
  58. #define HASHALG_SHA256 0x00000002
  59. #define HASHALG_SHA384 0x00000003
  60. #define HASHALG_SHA512 0x00000004
  61. #define HASHALG_MAX 0x00000005
  62. //
  63. // Set max digest size as SHA512 Output (64 bytes) by far
  64. //
  65. #define MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
  66. //
  67. //
  68. // PKCS7 Certificate definition
  69. //
  70. typedef struct {
  71. WIN_CERTIFICATE Hdr;
  72. UINT8 CertData[1];
  73. } WIN_CERTIFICATE_EFI_PKCS;
  74. /**
  75. Retrieves the size, in bytes, of the context buffer required for hash operations.
  76. @return The size, in bytes, of the context buffer required for hash operations.
  77. **/
  78. typedef
  79. UINTN
  80. (EFIAPI *HASH_GET_CONTEXT_SIZE)(
  81. VOID
  82. );
  83. /**
  84. Initializes user-supplied memory pointed by HashContext as hash context for
  85. subsequent use.
  86. If HashContext is NULL, then ASSERT().
  87. @param[in, out] HashContext Pointer to Context being initialized.
  88. @retval TRUE HASH context initialization succeeded.
  89. @retval FALSE HASH context initialization failed.
  90. **/
  91. typedef
  92. BOOLEAN
  93. (EFIAPI *HASH_INIT)(
  94. IN OUT VOID *HashContext
  95. );
  96. /**
  97. Performs digest on a data buffer of the specified length. This function can
  98. be called multiple times to compute the digest of long or discontinuous data streams.
  99. If HashContext is NULL, then ASSERT().
  100. @param[in, out] HashContext Pointer to the MD5 context.
  101. @param[in] Data Pointer to the buffer containing the data to be hashed.
  102. @param[in] DataLength Length of Data buffer in bytes.
  103. @retval TRUE HASH data digest succeeded.
  104. @retval FALSE Invalid HASH context. After HashFinal function has been called, the
  105. HASH context cannot be reused.
  106. **/
  107. typedef
  108. BOOLEAN
  109. (EFIAPI *HASH_UPDATE)(
  110. IN OUT VOID *HashContext,
  111. IN CONST VOID *Data,
  112. IN UINTN DataLength
  113. );
  114. /**
  115. Completes hash computation and retrieves the digest value into the specified
  116. memory. After this function has been called, the context cannot be used again.
  117. If HashContext is NULL, then ASSERT().
  118. If HashValue is NULL, then ASSERT().
  119. @param[in, out] HashContext Pointer to the MD5 context
  120. @param[out] HashValue Pointer to a buffer that receives the HASH digest
  121. value.
  122. @retval TRUE HASH digest computation succeeded.
  123. @retval FALSE HASH digest computation failed.
  124. **/
  125. typedef
  126. BOOLEAN
  127. (EFIAPI *HASH_FINAL)(
  128. IN OUT VOID *HashContext,
  129. OUT UINT8 *HashValue
  130. );
  131. //
  132. // Hash Algorithm Table
  133. //
  134. typedef struct {
  135. //
  136. // Name for Hash Algorithm
  137. //
  138. CHAR16 *Name;
  139. //
  140. // Digest Length
  141. //
  142. UINTN DigestLength;
  143. //
  144. // Hash Algorithm OID ASN.1 Value
  145. //
  146. UINT8 *OidValue;
  147. //
  148. // Length of Hash OID Value
  149. //
  150. UINTN OidLength;
  151. //
  152. // Pointer to Hash GetContentSize function
  153. //
  154. HASH_GET_CONTEXT_SIZE GetContextSize;
  155. //
  156. // Pointer to Hash Init function
  157. //
  158. HASH_INIT HashInit;
  159. //
  160. // Pointer to Hash Update function
  161. //
  162. HASH_UPDATE HashUpdate;
  163. //
  164. // Pointer to Hash Final function
  165. //
  166. HASH_FINAL HashFinal;
  167. } HASH_TABLE;
  168. #endif