Hash2DxeCrypto.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /** @file
  2. This module implements Hash2 Protocol.
  3. (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
  4. Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Uefi.h>
  8. #include <Protocol/Hash2.h>
  9. #include <Library/BaseLib.h>
  10. #include <Library/UefiBootServicesTableLib.h>
  11. #include <Library/MemoryAllocationLib.h>
  12. #include <Library/BaseMemoryLib.h>
  13. #include <Library/DebugLib.h>
  14. #include <Library/BaseCryptLib.h>
  15. #include "Driver.h"
  16. /**
  17. Retrieves the size, in bytes, of the context buffer required for hash operations.
  18. If this interface is not supported, then return zero.
  19. @return The size, in bytes, of the context buffer required for hash operations.
  20. @retval 0 This interface is not supported.
  21. **/
  22. typedef
  23. UINTN
  24. (EFIAPI *EFI_HASH_GET_CONTEXT_SIZE) (
  25. VOID
  26. );
  27. /**
  28. Initializes user-supplied memory pointed by Sha1Context as hash context for
  29. subsequent use.
  30. If HashContext is NULL, then return FALSE.
  31. If this interface is not supported, then return FALSE.
  32. @param[out] HashContext Pointer to Hashcontext being initialized.
  33. @retval TRUE Hash context initialization succeeded.
  34. @retval FALSE Hash context initialization failed.
  35. @retval FALSE This interface is not supported.
  36. **/
  37. typedef
  38. BOOLEAN
  39. (EFIAPI *EFI_HASH_INIT) (
  40. OUT VOID *HashContext
  41. );
  42. /**
  43. Digests the input data and updates Hash context.
  44. This function performs Hash digest on a data buffer of the specified size.
  45. It can be called multiple times to compute the digest of long or discontinuous data streams.
  46. Hash context should be already correctly initialized by HashInit(), and should not be finalized
  47. by HashFinal(). Behavior with invalid context is undefined.
  48. If HashContext is NULL, then return FALSE.
  49. If this interface is not supported, then return FALSE.
  50. @param[in, out] HashContext Pointer to the Hash context.
  51. @param[in] Data Pointer to the buffer containing the data to be hashed.
  52. @param[in] DataSize Size of Data buffer in bytes.
  53. @retval TRUE SHA-1 data digest succeeded.
  54. @retval FALSE SHA-1 data digest failed.
  55. @retval FALSE This interface is not supported.
  56. **/
  57. typedef
  58. BOOLEAN
  59. (EFIAPI *EFI_HASH_UPDATE) (
  60. IN OUT VOID *HashContext,
  61. IN CONST VOID *Data,
  62. IN UINTN DataSize
  63. );
  64. /**
  65. Completes computation of the Hash digest value.
  66. This function completes hash computation and retrieves the digest value into
  67. the specified memory. After this function has been called, the Hash context cannot
  68. be used again.
  69. Hash context should be already correctly intialized by HashInit(), and should not be
  70. finalized by HashFinal(). Behavior with invalid Hash context is undefined.
  71. If HashContext is NULL, then return FALSE.
  72. If HashValue is NULL, then return FALSE.
  73. If this interface is not supported, then return FALSE.
  74. @param[in, out] HashContext Pointer to the Hash context.
  75. @param[out] HashValue Pointer to a buffer that receives the Hash digest
  76. value.
  77. @retval TRUE Hash digest computation succeeded.
  78. @retval FALSE Hash digest computation failed.
  79. @retval FALSE This interface is not supported.
  80. **/
  81. typedef
  82. BOOLEAN
  83. (EFIAPI *EFI_HASH_FINAL) (
  84. IN OUT VOID *HashContext,
  85. OUT UINT8 *HashValue
  86. );
  87. typedef struct {
  88. EFI_GUID *Guid;
  89. UINT32 HashSize;
  90. EFI_HASH_GET_CONTEXT_SIZE GetContextSize;
  91. EFI_HASH_INIT Init;
  92. EFI_HASH_UPDATE Update;
  93. EFI_HASH_FINAL Final;
  94. } EFI_HASH_INFO;
  95. EFI_HASH_INFO mHashInfo[] = {
  96. {&gEfiHashAlgorithmMD5Guid, sizeof(EFI_MD5_HASH2), Md5GetContextSize, Md5Init, Md5Update, Md5Final },
  97. {&gEfiHashAlgorithmSha1Guid, sizeof(EFI_SHA1_HASH2), Sha1GetContextSize, Sha1Init, Sha1Update, Sha1Final },
  98. {&gEfiHashAlgorithmSha256Guid, sizeof(EFI_SHA256_HASH2), Sha256GetContextSize, Sha256Init, Sha256Update, Sha256Final },
  99. {&gEfiHashAlgorithmSha384Guid, sizeof(EFI_SHA384_HASH2), Sha384GetContextSize, Sha384Init, Sha384Update, Sha384Final },
  100. {&gEfiHashAlgorithmSha512Guid, sizeof(EFI_SHA512_HASH2), Sha512GetContextSize, Sha512Init, Sha512Update, Sha512Final },
  101. };
  102. /**
  103. Returns the size of the hash which results from a specific algorithm.
  104. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  105. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
  106. @param[out] HashSize Holds the returned size of the algorithm's hash.
  107. @retval EFI_SUCCESS Hash size returned successfully.
  108. @retval EFI_INVALID_PARAMETER This or HashSize is NULL.
  109. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver
  110. or HashAlgorithm is null.
  111. **/
  112. EFI_STATUS
  113. EFIAPI
  114. BaseCrypto2GetHashSize (
  115. IN CONST EFI_HASH2_PROTOCOL *This,
  116. IN CONST EFI_GUID *HashAlgorithm,
  117. OUT UINTN *HashSize
  118. );
  119. /**
  120. Creates a hash for the specified message text. The hash is not extendable.
  121. The output is final with any algorithm-required padding added by the function.
  122. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  123. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
  124. @param[in] Message Points to the start of the message.
  125. @param[in] MessageSize The size of Message, in bytes.
  126. @param[in,out] Hash On input, points to a caller-allocated buffer of the size
  127. returned by GetHashSize() for the specified HashAlgorithm.
  128. On output, the buffer holds the resulting hash computed from the message.
  129. @retval EFI_SUCCESS Hash returned successfully.
  130. @retval EFI_INVALID_PARAMETER This or Hash is NULL.
  131. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver
  132. or HashAlgorithm is Null.
  133. @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available
  134. or MessageSize is greater than platform maximum.
  135. **/
  136. EFI_STATUS
  137. EFIAPI
  138. BaseCrypto2Hash (
  139. IN CONST EFI_HASH2_PROTOCOL *This,
  140. IN CONST EFI_GUID *HashAlgorithm,
  141. IN CONST UINT8 *Message,
  142. IN UINTN MessageSize,
  143. IN OUT EFI_HASH2_OUTPUT *Hash
  144. );
  145. /**
  146. This function must be called to initialize a digest calculation to be subsequently performed using the
  147. EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal().
  148. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  149. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
  150. @retval EFI_SUCCESS Initialized successfully.
  151. @retval EFI_INVALID_PARAMETER This is NULL.
  152. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver
  153. or HashAlgorithm is Null.
  154. @retval EFI_OUT_OF_RESOURCES Process failed due to lack of required resource.
  155. @retval EFI_ALREADY_STARTED This function is called when the operation in progress is still in processing Hash(),
  156. or HashInit() is already called before and not terminated by HashFinal() yet on the same instance.
  157. **/
  158. EFI_STATUS
  159. EFIAPI
  160. BaseCrypto2HashInit (
  161. IN CONST EFI_HASH2_PROTOCOL *This,
  162. IN CONST EFI_GUID *HashAlgorithm
  163. );
  164. /**
  165. Updates the hash of a computation in progress by adding a message text.
  166. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  167. @param[in] Message Points to the start of the message.
  168. @param[in] MessageSize The size of Message, in bytes.
  169. @retval EFI_SUCCESS Digest in progress updated successfully.
  170. @retval EFI_INVALID_PARAMETER This or Hash is NULL.
  171. @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available
  172. or MessageSize is greater than platform maximum.
  173. @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit(),
  174. or the operation in progress was terminated by a call to Hash() or HashFinal() on the same instance.
  175. **/
  176. EFI_STATUS
  177. EFIAPI
  178. BaseCrypto2HashUpdate (
  179. IN CONST EFI_HASH2_PROTOCOL *This,
  180. IN CONST UINT8 *Message,
  181. IN UINTN MessageSize
  182. );
  183. /**
  184. Finalizes a hash operation in progress and returns calculation result.
  185. The output is final with any necessary padding added by the function.
  186. The hash may not be further updated or extended after HashFinal().
  187. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  188. @param[in,out] Hash On input, points to a caller-allocated buffer of the size
  189. returned by GetHashSize() for the specified HashAlgorithm specified in preceding HashInit().
  190. On output, the buffer holds the resulting hash computed from the message.
  191. @retval EFI_SUCCESS Hash returned successfully.
  192. @retval EFI_INVALID_PARAMETER This or Hash is NULL.
  193. @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit() and at least one call to HashUpdate(),
  194. or the operation in progress was canceled by a call to Hash() on the same instance.
  195. **/
  196. EFI_STATUS
  197. EFIAPI
  198. BaseCrypto2HashFinal (
  199. IN CONST EFI_HASH2_PROTOCOL *This,
  200. IN OUT EFI_HASH2_OUTPUT *Hash
  201. );
  202. EFI_HASH2_PROTOCOL mHash2Protocol = {
  203. BaseCrypto2GetHashSize,
  204. BaseCrypto2Hash,
  205. BaseCrypto2HashInit,
  206. BaseCrypto2HashUpdate,
  207. BaseCrypto2HashFinal,
  208. };
  209. /**
  210. Returns hash information.
  211. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
  212. @return Hash information.
  213. **/
  214. EFI_HASH_INFO *
  215. GetHashInfo (
  216. IN CONST EFI_GUID *HashAlgorithm
  217. )
  218. {
  219. UINTN Index;
  220. for (Index = 0; Index < sizeof(mHashInfo)/sizeof(mHashInfo[0]); Index++) {
  221. if (CompareGuid (HashAlgorithm, mHashInfo[Index].Guid)) {
  222. return &mHashInfo[Index];
  223. }
  224. }
  225. return NULL;
  226. }
  227. /**
  228. Returns the size of the hash which results from a specific algorithm.
  229. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  230. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
  231. @param[out] HashSize Holds the returned size of the algorithm's hash.
  232. @retval EFI_SUCCESS Hash size returned successfully.
  233. @retval EFI_INVALID_PARAMETER This or HashSize is NULL.
  234. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver
  235. or HashAlgorithm is null.
  236. **/
  237. EFI_STATUS
  238. EFIAPI
  239. BaseCrypto2GetHashSize (
  240. IN CONST EFI_HASH2_PROTOCOL *This,
  241. IN CONST EFI_GUID *HashAlgorithm,
  242. OUT UINTN *HashSize
  243. )
  244. {
  245. EFI_HASH_INFO *HashInfo;
  246. if ((This == NULL) || (HashSize == NULL)) {
  247. return EFI_INVALID_PARAMETER;
  248. }
  249. if (HashAlgorithm == NULL) {
  250. return EFI_UNSUPPORTED;
  251. }
  252. HashInfo = GetHashInfo (HashAlgorithm);
  253. if (HashInfo == NULL) {
  254. return EFI_UNSUPPORTED;
  255. }
  256. *HashSize = HashInfo->HashSize;
  257. return EFI_SUCCESS;
  258. }
  259. /**
  260. Creates a hash for the specified message text. The hash is not extendable.
  261. The output is final with any algorithm-required padding added by the function.
  262. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  263. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
  264. @param[in] Message Points to the start of the message.
  265. @param[in] MessageSize The size of Message, in bytes.
  266. @param[in,out] Hash On input, points to a caller-allocated buffer of the size
  267. returned by GetHashSize() for the specified HashAlgorithm.
  268. On output, the buffer holds the resulting hash computed from the message.
  269. @retval EFI_SUCCESS Hash returned successfully.
  270. @retval EFI_INVALID_PARAMETER This or Hash is NULL.
  271. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver
  272. or HashAlgorithm is Null.
  273. @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available
  274. or MessageSize is greater than platform maximum.
  275. **/
  276. EFI_STATUS
  277. EFIAPI
  278. BaseCrypto2Hash (
  279. IN CONST EFI_HASH2_PROTOCOL *This,
  280. IN CONST EFI_GUID *HashAlgorithm,
  281. IN CONST UINT8 *Message,
  282. IN UINTN MessageSize,
  283. IN OUT EFI_HASH2_OUTPUT *Hash
  284. )
  285. {
  286. EFI_HASH_INFO *HashInfo;
  287. VOID *HashCtx;
  288. UINTN CtxSize;
  289. BOOLEAN Ret;
  290. EFI_STATUS Status;
  291. HASH2_INSTANCE_DATA *Instance;
  292. Status = EFI_SUCCESS;
  293. if ((This == NULL) || (Hash == NULL)) {
  294. return EFI_INVALID_PARAMETER;
  295. }
  296. if (HashAlgorithm == NULL) {
  297. return EFI_UNSUPPORTED;
  298. }
  299. HashInfo = GetHashInfo (HashAlgorithm);
  300. if (HashInfo == NULL) {
  301. return EFI_UNSUPPORTED;
  302. }
  303. Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);
  304. if (Instance->HashContext != NULL) {
  305. FreePool (Instance->HashContext);
  306. }
  307. Instance->HashInfoContext = NULL;
  308. Instance->HashContext = NULL;
  309. //
  310. // Start hash sequence
  311. //
  312. CtxSize = HashInfo->GetContextSize ();
  313. if (CtxSize == 0) {
  314. return EFI_UNSUPPORTED;
  315. }
  316. HashCtx = AllocatePool (CtxSize);
  317. if (HashCtx == NULL) {
  318. return EFI_OUT_OF_RESOURCES;
  319. }
  320. Ret = HashInfo->Init (HashCtx);
  321. if (!Ret) {
  322. Status = EFI_OUT_OF_RESOURCES;
  323. goto Done;
  324. }
  325. //
  326. // Setup the context
  327. //
  328. Instance->HashContext = HashCtx;
  329. Instance->HashInfoContext = HashInfo;
  330. Ret = HashInfo->Update (HashCtx, Message, MessageSize);
  331. if (!Ret) {
  332. Status = EFI_OUT_OF_RESOURCES;
  333. goto Done;
  334. }
  335. Ret = HashInfo->Final (HashCtx, (UINT8 *)Hash->Sha1Hash);
  336. if (!Ret) {
  337. Status = EFI_OUT_OF_RESOURCES;
  338. goto Done;
  339. }
  340. Done:
  341. //
  342. // Cleanup the context
  343. //
  344. FreePool (HashCtx);
  345. Instance->HashInfoContext = NULL;
  346. Instance->HashContext = NULL;
  347. return Status;
  348. }
  349. /**
  350. This function must be called to initialize a digest calculation to be subsequently performed using the
  351. EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal().
  352. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  353. @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
  354. @retval EFI_SUCCESS Initialized successfully.
  355. @retval EFI_INVALID_PARAMETER This is NULL.
  356. @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver
  357. or HashAlgorithm is Null.
  358. @retval EFI_OUT_OF_RESOURCES Process failed due to lack of required resource.
  359. @retval EFI_ALREADY_STARTED This function is called when the operation in progress is still in processing Hash(),
  360. or HashInit() is already called before and not terminated by HashFinal() yet on the same instance.
  361. **/
  362. EFI_STATUS
  363. EFIAPI
  364. BaseCrypto2HashInit (
  365. IN CONST EFI_HASH2_PROTOCOL *This,
  366. IN CONST EFI_GUID *HashAlgorithm
  367. )
  368. {
  369. EFI_HASH_INFO *HashInfo;
  370. VOID *HashCtx;
  371. UINTN CtxSize;
  372. BOOLEAN Ret;
  373. HASH2_INSTANCE_DATA *Instance;
  374. if (This == NULL) {
  375. return EFI_INVALID_PARAMETER;
  376. }
  377. if (HashAlgorithm == NULL) {
  378. return EFI_UNSUPPORTED;
  379. }
  380. HashInfo = GetHashInfo (HashAlgorithm);
  381. if (HashInfo == NULL) {
  382. return EFI_UNSUPPORTED;
  383. }
  384. //
  385. // Consistency Check
  386. //
  387. Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);
  388. if ((Instance->HashContext != NULL) || (Instance->HashInfoContext != NULL)) {
  389. return EFI_ALREADY_STARTED;
  390. }
  391. //
  392. // Start hash sequence
  393. //
  394. CtxSize = HashInfo->GetContextSize ();
  395. if (CtxSize == 0) {
  396. return EFI_UNSUPPORTED;
  397. }
  398. HashCtx = AllocatePool (CtxSize);
  399. if (HashCtx == NULL) {
  400. return EFI_OUT_OF_RESOURCES;
  401. }
  402. Ret = HashInfo->Init (HashCtx);
  403. if (!Ret) {
  404. FreePool (HashCtx);
  405. return EFI_OUT_OF_RESOURCES;
  406. }
  407. //
  408. // Setup the context
  409. //
  410. Instance->HashContext = HashCtx;
  411. Instance->HashInfoContext = HashInfo;
  412. Instance->Updated = FALSE;
  413. return EFI_SUCCESS;
  414. }
  415. /**
  416. Updates the hash of a computation in progress by adding a message text.
  417. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  418. @param[in] Message Points to the start of the message.
  419. @param[in] MessageSize The size of Message, in bytes.
  420. @retval EFI_SUCCESS Digest in progress updated successfully.
  421. @retval EFI_INVALID_PARAMETER This or Hash is NULL.
  422. @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available
  423. or MessageSize is greater than platform maximum.
  424. @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit(),
  425. or the operation in progress was terminated by a call to Hash() or HashFinal() on the same instance.
  426. **/
  427. EFI_STATUS
  428. EFIAPI
  429. BaseCrypto2HashUpdate (
  430. IN CONST EFI_HASH2_PROTOCOL *This,
  431. IN CONST UINT8 *Message,
  432. IN UINTN MessageSize
  433. )
  434. {
  435. EFI_HASH_INFO *HashInfo;
  436. VOID *HashCtx;
  437. BOOLEAN Ret;
  438. HASH2_INSTANCE_DATA *Instance;
  439. if (This == NULL) {
  440. return EFI_INVALID_PARAMETER;
  441. }
  442. //
  443. // Consistency Check
  444. //
  445. Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);
  446. if ((Instance->HashContext == NULL) || (Instance->HashInfoContext == NULL)) {
  447. return EFI_NOT_READY;
  448. }
  449. HashInfo = Instance->HashInfoContext;
  450. HashCtx = Instance->HashContext;
  451. Ret = HashInfo->Update (HashCtx, Message, MessageSize);
  452. if (!Ret) {
  453. return EFI_OUT_OF_RESOURCES;
  454. }
  455. Instance->Updated = TRUE;
  456. return EFI_SUCCESS;
  457. }
  458. /**
  459. Finalizes a hash operation in progress and returns calculation result.
  460. The output is final with any necessary padding added by the function.
  461. The hash may not be further updated or extended after HashFinal().
  462. @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.
  463. @param[in,out] Hash On input, points to a caller-allocated buffer of the size
  464. returned by GetHashSize() for the specified HashAlgorithm specified in preceding HashInit().
  465. On output, the buffer holds the resulting hash computed from the message.
  466. @retval EFI_SUCCESS Hash returned successfully.
  467. @retval EFI_INVALID_PARAMETER This or Hash is NULL.
  468. @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit() and at least one call to HashUpdate(),
  469. or the operation in progress was canceled by a call to Hash() on the same instance.
  470. **/
  471. EFI_STATUS
  472. EFIAPI
  473. BaseCrypto2HashFinal (
  474. IN CONST EFI_HASH2_PROTOCOL *This,
  475. IN OUT EFI_HASH2_OUTPUT *Hash
  476. )
  477. {
  478. EFI_HASH_INFO *HashInfo;
  479. VOID *HashCtx;
  480. BOOLEAN Ret;
  481. HASH2_INSTANCE_DATA *Instance;
  482. if ((This == NULL) || (Hash == NULL)) {
  483. return EFI_INVALID_PARAMETER;
  484. }
  485. //
  486. // Consistency Check
  487. //
  488. Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);
  489. if ((Instance->HashContext == NULL) || (Instance->HashInfoContext == NULL) ||
  490. (!Instance->Updated)) {
  491. return EFI_NOT_READY;
  492. }
  493. HashInfo = Instance->HashInfoContext;
  494. HashCtx = Instance->HashContext;
  495. Ret = HashInfo->Final (HashCtx, (UINT8 *)Hash->Sha1Hash);
  496. //
  497. // Cleanup the context
  498. //
  499. FreePool (HashCtx);
  500. Instance->HashInfoContext = NULL;
  501. Instance->HashContext = NULL;
  502. Instance->Updated = FALSE;
  503. if (!Ret) {
  504. return EFI_OUT_OF_RESOURCES;
  505. }
  506. return EFI_SUCCESS;
  507. }