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