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