]>
Commit | Line | Data |
---|---|---|
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 |
5 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r |
6 | This program and the accompanying materials are licensed and made available under\r | |
7 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
8 | The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php.\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT 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 | |
36 | typedef\r | |
37 | UINTN\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 | |
56 | typedef\r | |
57 | BOOLEAN\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 | |
82 | typedef\r | |
83 | BOOLEAN\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 | |
112 | typedef\r | |
113 | BOOLEAN\r | |
114 | (EFIAPI *EFI_HASH_FINAL) (\r | |
115 | IN OUT VOID *HashContext,\r | |
116 | OUT UINT8 *HashValue\r | |
117 | );\r | |
118 | \r | |
119 | typedef 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 | |
128 | EFI_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 | |
149 | EFI_STATUS\r | |
150 | EFIAPI\r | |
151 | BaseCrypto2GetHashSize (\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 | |
177 | EFI_STATUS\r | |
178 | EFIAPI\r | |
179 | BaseCrypto2Hash (\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 | |
203 | EFI_STATUS\r | |
204 | EFIAPI\r | |
205 | BaseCrypto2HashInit (\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 | |
225 | EFI_STATUS\r | |
226 | EFIAPI\r | |
227 | BaseCrypto2HashUpdate (\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 | |
249 | EFI_STATUS\r | |
250 | EFIAPI\r | |
251 | BaseCrypto2HashFinal (\r | |
252 | IN CONST EFI_HASH2_PROTOCOL *This,\r | |
253 | IN OUT EFI_HASH2_OUTPUT *Hash\r | |
254 | );\r | |
255 | \r | |
256 | EFI_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 | |
271 | EFI_HASH_INFO *\r | |
272 | GetHashInfo (\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 | |
299 | EFI_STATUS\r | |
300 | EFIAPI\r | |
301 | BaseCrypto2GetHashSize (\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 | |
346 | EFI_STATUS\r | |
347 | EFIAPI\r | |
348 | BaseCrypto2Hash (\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 | |
361 | \r | |
362 | Status = EFI_SUCCESS;\r | |
363 | \r | |
364 | if ((This == NULL) || (Hash == NULL)) {\r | |
365 | return EFI_INVALID_PARAMETER;\r | |
366 | }\r | |
367 | \r | |
368 | if (HashAlgorithm == NULL) {\r | |
369 | return EFI_UNSUPPORTED;\r | |
370 | }\r | |
371 | \r | |
372 | HashInfo = GetHashInfo (HashAlgorithm);\r | |
373 | if (HashInfo == NULL) {\r | |
374 | return EFI_UNSUPPORTED;\r | |
375 | }\r | |
376 | \r | |
377 | //\r | |
378 | // Start hash sequence\r | |
379 | //\r | |
380 | CtxSize = HashInfo->GetContextSize ();\r | |
381 | if (CtxSize == 0) {\r | |
382 | return EFI_UNSUPPORTED;\r | |
383 | }\r | |
384 | HashCtx = AllocatePool (CtxSize);\r | |
385 | if (HashCtx == NULL) {\r | |
386 | return EFI_OUT_OF_RESOURCES;\r | |
387 | }\r | |
388 | \r | |
389 | Ret = HashInfo->Init (HashCtx);\r | |
390 | if (!Ret) {\r | |
391 | Status = EFI_OUT_OF_RESOURCES;\r | |
392 | goto Done;\r | |
393 | }\r | |
394 | \r | |
395 | Ret = HashInfo->Update (HashCtx, Message, MessageSize);\r | |
396 | if (!Ret) {\r | |
397 | Status = EFI_OUT_OF_RESOURCES;\r | |
398 | goto Done;\r | |
399 | }\r | |
400 | \r | |
401 | Ret = HashInfo->Final (HashCtx, (UINT8 *)Hash->Sha1Hash);\r | |
402 | if (!Ret) {\r | |
403 | Status = EFI_OUT_OF_RESOURCES;\r | |
404 | goto Done;\r | |
405 | }\r | |
406 | Done:\r | |
407 | FreePool (HashCtx);\r | |
408 | return Status;\r | |
409 | }\r | |
410 | \r | |
411 | /**\r | |
412 | This function must be called to initialize a digest calculation to be subsequently performed using the\r | |
413 | EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal().\r | |
414 | \r | |
415 | @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.\r | |
416 | @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.\r | |
417 | \r | |
418 | @retval EFI_SUCCESS Initialized successfully.\r | |
419 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
420 | @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver\r | |
421 | or HashAlgorithm is Null.\r | |
422 | @retval EFI_OUT_OF_RESOURCES Process failed due to lack of required resource.\r | |
423 | @retval EFI_ALREADY_STARTED This function is called when the operation in progress is still in processing Hash(),\r | |
424 | or HashInit() is already called before and not terminated by HashFinal() yet on the same instance.\r | |
425 | \r | |
426 | **/\r | |
427 | EFI_STATUS\r | |
428 | EFIAPI\r | |
429 | BaseCrypto2HashInit (\r | |
430 | IN CONST EFI_HASH2_PROTOCOL *This,\r | |
431 | IN CONST EFI_GUID *HashAlgorithm\r | |
432 | )\r | |
433 | {\r | |
434 | EFI_HASH_INFO *HashInfo;\r | |
435 | VOID *HashCtx;\r | |
436 | UINTN CtxSize;\r | |
437 | BOOLEAN Ret;\r | |
438 | HASH2_INSTANCE_DATA *Instance;\r | |
439 | \r | |
440 | if (This == NULL) {\r | |
441 | return EFI_INVALID_PARAMETER;\r | |
442 | }\r | |
443 | \r | |
444 | if (HashAlgorithm == NULL) {\r | |
445 | return EFI_UNSUPPORTED;\r | |
446 | }\r | |
447 | \r | |
448 | HashInfo = GetHashInfo (HashAlgorithm);\r | |
449 | if (HashInfo == NULL) {\r | |
450 | return EFI_UNSUPPORTED;\r | |
451 | }\r | |
452 | \r | |
453 | //\r | |
454 | // Consistency Check\r | |
455 | //\r | |
456 | Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r | |
457 | if ((Instance->HashContext != NULL) || (Instance->HashInfoContext != HashInfo)) {\r | |
458 | return EFI_ALREADY_STARTED;\r | |
459 | }\r | |
460 | \r | |
461 | //\r | |
462 | // Start hash sequence\r | |
463 | //\r | |
464 | CtxSize = HashInfo->GetContextSize ();\r | |
465 | if (CtxSize == 0) {\r | |
466 | return EFI_UNSUPPORTED;\r | |
467 | }\r | |
468 | HashCtx = AllocatePool (CtxSize);\r | |
469 | if (HashCtx == NULL) {\r | |
470 | return EFI_OUT_OF_RESOURCES;\r | |
471 | }\r | |
472 | \r | |
473 | Ret = HashInfo->Init (HashCtx);\r | |
474 | if (!Ret) {\r | |
475 | FreePool (HashCtx);\r | |
476 | return EFI_OUT_OF_RESOURCES;\r | |
477 | }\r | |
478 | \r | |
479 | //\r | |
480 | // Setup the context\r | |
481 | //\r | |
482 | Instance->HashContext = HashCtx;\r | |
483 | Instance->HashInfoContext = HashInfo;\r | |
484 | \r | |
485 | return EFI_SUCCESS;\r | |
486 | }\r | |
487 | \r | |
488 | /**\r | |
489 | Updates the hash of a computation in progress by adding a message text.\r | |
490 | \r | |
491 | @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.\r | |
492 | @param[in] Message Points to the start of the message.\r | |
493 | @param[in] MessageSize The size of Message, in bytes.\r | |
494 | \r | |
495 | @retval EFI_SUCCESS Digest in progress updated successfully.\r | |
496 | @retval EFI_INVALID_PARAMETER This or Hash is NULL.\r | |
497 | @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available\r | |
498 | or MessageSize is greater than platform maximum.\r | |
499 | @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit(),\r | |
500 | or the operation in progress was terminated by a call to Hash() or HashFinal() on the same instance.\r | |
501 | \r | |
502 | **/\r | |
503 | EFI_STATUS\r | |
504 | EFIAPI\r | |
505 | BaseCrypto2HashUpdate (\r | |
506 | IN CONST EFI_HASH2_PROTOCOL *This,\r | |
507 | IN CONST UINT8 *Message,\r | |
508 | IN UINTN MessageSize\r | |
509 | )\r | |
510 | {\r | |
511 | EFI_HASH_INFO *HashInfo;\r | |
512 | VOID *HashCtx;\r | |
513 | BOOLEAN Ret;\r | |
514 | HASH2_INSTANCE_DATA *Instance;\r | |
515 | \r | |
516 | if (This == NULL) {\r | |
517 | return EFI_INVALID_PARAMETER;\r | |
518 | }\r | |
519 | \r | |
520 | //\r | |
521 | // Consistency Check\r | |
522 | //\r | |
523 | Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r | |
524 | if ((Instance->HashContext == NULL) || (Instance->HashInfoContext == NULL)) {\r | |
525 | return EFI_NOT_READY;\r | |
526 | }\r | |
527 | HashInfo = Instance->HashInfoContext;\r | |
528 | HashCtx = Instance->HashContext;\r | |
529 | \r | |
530 | Ret = HashInfo->Update (HashCtx, Message, MessageSize);\r | |
531 | if (!Ret) {\r | |
532 | return EFI_OUT_OF_RESOURCES;\r | |
533 | }\r | |
534 | \r | |
535 | return EFI_SUCCESS;\r | |
536 | }\r | |
537 | \r | |
538 | /**\r | |
539 | Finalizes a hash operation in progress and returns calculation result.\r | |
540 | The output is final with any necessary padding added by the function.\r | |
541 | The hash may not be further updated or extended after HashFinal().\r | |
542 | \r | |
543 | @param[in] This Points to this instance of EFI_HASH2_PROTOCOL.\r | |
544 | @param[in,out] Hash On input, points to a caller-allocated buffer of the size\r | |
545 | returned by GetHashSize() for the specified HashAlgorithm specified in preceding HashInit().\r | |
546 | On output, the buffer holds the resulting hash computed from the message.\r | |
547 | \r | |
548 | @retval EFI_SUCCESS Hash returned successfully.\r | |
549 | @retval EFI_INVALID_PARAMETER This or Hash is NULL.\r | |
550 | @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit() and at least one call to HashUpdate(),\r | |
551 | or the operation in progress was canceled by a call to Hash() on the same instance.\r | |
552 | \r | |
553 | **/\r | |
554 | EFI_STATUS\r | |
555 | EFIAPI\r | |
556 | BaseCrypto2HashFinal (\r | |
557 | IN CONST EFI_HASH2_PROTOCOL *This,\r | |
558 | IN OUT EFI_HASH2_OUTPUT *Hash\r | |
559 | )\r | |
560 | {\r | |
561 | EFI_HASH_INFO *HashInfo;\r | |
562 | VOID *HashCtx;\r | |
563 | BOOLEAN Ret;\r | |
564 | HASH2_INSTANCE_DATA *Instance;\r | |
565 | \r | |
566 | if ((This == NULL) || (Hash == NULL)) {\r | |
567 | return EFI_INVALID_PARAMETER;\r | |
568 | }\r | |
569 | \r | |
570 | //\r | |
571 | // Consistency Check\r | |
572 | //\r | |
573 | Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r | |
574 | if ((Instance->HashContext == NULL) || (Instance->HashInfoContext == NULL)) {\r | |
575 | return EFI_NOT_READY;\r | |
576 | }\r | |
577 | HashInfo = Instance->HashInfoContext;\r | |
578 | HashCtx = Instance->HashContext;\r | |
579 | \r | |
580 | Ret = HashInfo->Final (HashCtx, (UINT8 *)Hash->Sha1Hash);\r | |
581 | \r | |
582 | //\r | |
583 | // Cleanup the context\r | |
584 | //\r | |
585 | FreePool (HashCtx);\r | |
586 | Instance->HashInfoContext = NULL;\r | |
587 | Instance->HashContext = NULL;\r | |
588 | \r | |
589 | if (!Ret) {\r | |
590 | return EFI_OUT_OF_RESOURCES;\r | |
591 | }\r | |
592 | \r | |
593 | return EFI_SUCCESS;\r | |
594 | }\r |