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