]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c
CryptoPkg: Add new hmac SHA api to Crypto Service.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLibOnProtocolPpi / CryptLib.c
CommitLineData
cd70de1c
MK
1/** @file\r
2 Implements the BaseCryptLib and TlsLib using the services of the EDK II Crypto\r
3 Protocol/PPI.\r
4\r
5 Copyright (C) Microsoft Corporation. All rights reserved.\r
c1e66210 6 Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>\r
cd70de1c
MK
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#include <Base.h>\r
12#include <Library/BaseLib.h>\r
13#include <Library/DebugLib.h>\r
14#include <Library/BaseCryptLib.h>\r
15#include <Library/TlsLib.h>\r
16#include <Protocol/Crypto.h>\r
17\r
18/**\r
19 A macro used to call a non-void service in an EDK II Crypto Protocol.\r
20 If the protocol is NULL or the service in the protocol is NULL, then a debug\r
21 message and assert is generated and an appropriate return value is returned.\r
22\r
23 @param Function Name of the EDK II Crypto Protocol service to call.\r
24 @param Args The argument list to pass to Function.\r
25 @param ErrorReturnValue The value to return if the protocol is NULL or the\r
26 service in the protocol is NULL.\r
27\r
28**/\r
29#define CALL_CRYPTO_SERVICE(Function, Args, ErrorReturnValue) \\r
30 do { \\r
31 EDKII_CRYPTO_PROTOCOL *CryptoServices; \\r
32 \\r
33 CryptoServices = (EDKII_CRYPTO_PROTOCOL *)GetCryptoServices (); \\r
34 if (CryptoServices != NULL && CryptoServices->Function != NULL) { \\r
35 return (CryptoServices->Function) Args; \\r
36 } \\r
37 CryptoServiceNotAvailable (#Function); \\r
38 return ErrorReturnValue; \\r
39 } while (FALSE);\r
40\r
41/**\r
42 A macro used to call a void service in an EDK II Crypto Protocol.\r
43 If the protocol is NULL or the service in the protocol is NULL, then a debug\r
44 message and assert is generated.\r
45\r
46 @param Function Name of the EDK II Crypto Protocol service to call.\r
47 @param Args The argument list to pass to Function.\r
48\r
49**/\r
50#define CALL_VOID_CRYPTO_SERVICE(Function, Args) \\r
51 do { \\r
52 EDKII_CRYPTO_PROTOCOL *CryptoServices; \\r
53 \\r
54 CryptoServices = (EDKII_CRYPTO_PROTOCOL *)GetCryptoServices (); \\r
55 if (CryptoServices != NULL && CryptoServices->Function != NULL) { \\r
56 (CryptoServices->Function) Args; \\r
57 return; \\r
58 } \\r
59 CryptoServiceNotAvailable (#Function); \\r
60 return; \\r
61 } while (FALSE);\r
62\r
63/**\r
64 Internal worker function that returns the pointer to an EDK II Crypto\r
65 Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are\r
66 identical which allows the implementation of the BaseCryptLib functions that\r
67 call through a Protocol/PPI to be shared for the PEI, DXE, and SMM\r
68 implementations.\r
69**/\r
70VOID *\r
71GetCryptoServices (\r
72 VOID\r
73 );\r
74\r
75/**\r
76 Internal worker function that prints a debug message and asserts if a crypto\r
77 service is not available. This should never occur because library instances\r
78 have a dependency expression for the for the EDK II Crypto Protocol/PPI so\r
79 a module that uses these library instances are not dispatched until the EDK II\r
80 Crypto Protocol/PPI is available. The only case that this function handles is\r
81 if the EDK II Crypto Protocol/PPI installed is NULL or a function pointer in\r
82 the EDK II Protocol/PPI is NULL.\r
83\r
84 @param[in] FunctionName Null-terminated ASCII string that is the name of an\r
85 EDK II Crypto service.\r
86\r
87**/\r
88static\r
89VOID\r
90CryptoServiceNotAvailable (\r
91 IN CONST CHAR8 *FunctionName\r
92 )\r
93{\r
94 DEBUG ((DEBUG_ERROR, "[%a] Function %a is not available\n", gEfiCallerBaseName, FunctionName));\r
95 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);\r
96}\r
97\r
7c342378 98// =====================================================================================\r
cd70de1c 99// One-Way Cryptographic Hash Primitives\r
7c342378 100// =====================================================================================\r
cd70de1c 101\r
e6a12a0f 102#ifdef ENABLE_MD5_DEPRECATED_INTERFACES\r
7c342378 103\r
cd70de1c
MK
104/**\r
105 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
106\r
107 If this interface is not supported, then return zero.\r
108\r
109 @return The size, in bytes, of the context buffer required for MD5 hash operations.\r
110 @retval 0 This interface is not supported.\r
111\r
112**/\r
113UINTN\r
114EFIAPI\r
115Md5GetContextSize (\r
116 VOID\r
117 )\r
118{\r
119 CALL_CRYPTO_SERVICE (Md5GetContextSize, (), 0);\r
120}\r
121\r
122/**\r
123 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
124 subsequent use.\r
125\r
126 If Md5Context is NULL, then return FALSE.\r
127 If this interface is not supported, then return FALSE.\r
128\r
129 @param[out] Md5Context Pointer to MD5 context being initialized.\r
130\r
131 @retval TRUE MD5 context initialization succeeded.\r
132 @retval FALSE MD5 context initialization failed.\r
133 @retval FALSE This interface is not supported.\r
134\r
135**/\r
136BOOLEAN\r
137EFIAPI\r
138Md5Init (\r
139 OUT VOID *Md5Context\r
140 )\r
141{\r
142 CALL_CRYPTO_SERVICE (Md5Init, (Md5Context), FALSE);\r
143}\r
144\r
145/**\r
146 Makes a copy of an existing MD5 context.\r
147\r
148 If Md5Context is NULL, then return FALSE.\r
149 If NewMd5Context is NULL, then return FALSE.\r
150 If this interface is not supported, then return FALSE.\r
151\r
152 @param[in] Md5Context Pointer to MD5 context being copied.\r
153 @param[out] NewMd5Context Pointer to new MD5 context.\r
154\r
155 @retval TRUE MD5 context copy succeeded.\r
156 @retval FALSE MD5 context copy failed.\r
157 @retval FALSE This interface is not supported.\r
158\r
159**/\r
160BOOLEAN\r
161EFIAPI\r
162Md5Duplicate (\r
163 IN CONST VOID *Md5Context,\r
164 OUT VOID *NewMd5Context\r
165 )\r
166{\r
167 CALL_CRYPTO_SERVICE (Md5Duplicate, (Md5Context, NewMd5Context), FALSE);\r
168}\r
169\r
170/**\r
171 Digests the input data and updates MD5 context.\r
172\r
173 This function performs MD5 digest on a data buffer of the specified size.\r
174 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
175 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r
176 by Md5Final(). Behavior with invalid context is undefined.\r
177\r
178 If Md5Context is NULL, then return FALSE.\r
179 If this interface is not supported, then return FALSE.\r
180\r
181 @param[in, out] Md5Context Pointer to the MD5 context.\r
182 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
183 @param[in] DataSize Size of Data buffer in bytes.\r
184\r
185 @retval TRUE MD5 data digest succeeded.\r
186 @retval FALSE MD5 data digest failed.\r
187 @retval FALSE This interface is not supported.\r
188\r
189**/\r
190BOOLEAN\r
191EFIAPI\r
192Md5Update (\r
193 IN OUT VOID *Md5Context,\r
194 IN CONST VOID *Data,\r
195 IN UINTN DataSize\r
196 )\r
197{\r
198 CALL_CRYPTO_SERVICE (Md5Update, (Md5Context, Data, DataSize), FALSE);\r
199}\r
200\r
201/**\r
202 Completes computation of the MD5 digest value.\r
203\r
204 This function completes MD5 hash computation and retrieves the digest value into\r
205 the specified memory. After this function has been called, the MD5 context cannot\r
206 be used again.\r
207 MD5 context should be already correctly initialized by Md5Init(), and should not be\r
208 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r
209\r
210 If Md5Context is NULL, then return FALSE.\r
211 If HashValue is NULL, then return FALSE.\r
212 If this interface is not supported, then return FALSE.\r
213\r
214 @param[in, out] Md5Context Pointer to the MD5 context.\r
215 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
216 value (16 bytes).\r
217\r
218 @retval TRUE MD5 digest computation succeeded.\r
219 @retval FALSE MD5 digest computation failed.\r
220 @retval FALSE This interface is not supported.\r
221\r
222**/\r
223BOOLEAN\r
224EFIAPI\r
225Md5Final (\r
226 IN OUT VOID *Md5Context,\r
227 OUT UINT8 *HashValue\r
228 )\r
229{\r
230 CALL_CRYPTO_SERVICE (Md5Final, (Md5Context, HashValue), FALSE);\r
231}\r
232\r
233/**\r
234 Computes the MD5 message digest of a input data buffer.\r
235\r
236 This function performs the MD5 message digest of a given data buffer, and places\r
237 the digest value into the specified memory.\r
238\r
239 If this interface is not supported, then return FALSE.\r
240\r
241 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
242 @param[in] DataSize Size of Data buffer in bytes.\r
243 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
244 value (16 bytes).\r
245\r
246 @retval TRUE MD5 digest computation succeeded.\r
247 @retval FALSE MD5 digest computation failed.\r
248 @retval FALSE This interface is not supported.\r
249\r
250**/\r
251BOOLEAN\r
252EFIAPI\r
253Md5HashAll (\r
254 IN CONST VOID *Data,\r
255 IN UINTN DataSize,\r
256 OUT UINT8 *HashValue\r
257 )\r
258{\r
259 CALL_CRYPTO_SERVICE (Md5HashAll, (Data, DataSize, HashValue), FALSE);\r
260}\r
7c342378 261\r
acfd5557 262#endif\r
cd70de1c 263\r
0f01cec5 264#ifndef DISABLE_SHA1_DEPRECATED_INTERFACES\r
7c342378 265\r
cd70de1c
MK
266/**\r
267 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
268\r
269 If this interface is not supported, then return zero.\r
270\r
271 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.\r
272 @retval 0 This interface is not supported.\r
273\r
274**/\r
275UINTN\r
276EFIAPI\r
277Sha1GetContextSize (\r
278 VOID\r
279 )\r
280{\r
281 CALL_CRYPTO_SERVICE (Sha1GetContextSize, (), 0);\r
282}\r
283\r
284/**\r
285 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r
286 subsequent use.\r
287\r
288 If Sha1Context is NULL, then return FALSE.\r
289 If this interface is not supported, then return FALSE.\r
290\r
291 @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r
292\r
293 @retval TRUE SHA-1 context initialization succeeded.\r
294 @retval FALSE SHA-1 context initialization failed.\r
295 @retval FALSE This interface is not supported.\r
296\r
297**/\r
298BOOLEAN\r
299EFIAPI\r
300Sha1Init (\r
301 OUT VOID *Sha1Context\r
302 )\r
303{\r
304 CALL_CRYPTO_SERVICE (Sha1Init, (Sha1Context), FALSE);\r
305}\r
306\r
307/**\r
308 Makes a copy of an existing SHA-1 context.\r
309\r
310 If Sha1Context is NULL, then return FALSE.\r
311 If NewSha1Context is NULL, then return FALSE.\r
312 If this interface is not supported, then return FALSE.\r
313\r
314 @param[in] Sha1Context Pointer to SHA-1 context being copied.\r
315 @param[out] NewSha1Context Pointer to new SHA-1 context.\r
316\r
317 @retval TRUE SHA-1 context copy succeeded.\r
318 @retval FALSE SHA-1 context copy failed.\r
319 @retval FALSE This interface is not supported.\r
320\r
321**/\r
322BOOLEAN\r
323EFIAPI\r
324Sha1Duplicate (\r
325 IN CONST VOID *Sha1Context,\r
326 OUT VOID *NewSha1Context\r
327 )\r
328{\r
329 CALL_CRYPTO_SERVICE (Sha1Duplicate, (Sha1Context, NewSha1Context), FALSE);\r
330}\r
331\r
332/**\r
333 Digests the input data and updates SHA-1 context.\r
334\r
335 This function performs SHA-1 digest on a data buffer of the specified size.\r
336 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
337 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r
338 by Sha1Final(). Behavior with invalid context is undefined.\r
339\r
340 If Sha1Context is NULL, then return FALSE.\r
341 If this interface is not supported, then return FALSE.\r
342\r
343 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
344 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
345 @param[in] DataSize Size of Data buffer in bytes.\r
346\r
347 @retval TRUE SHA-1 data digest succeeded.\r
348 @retval FALSE SHA-1 data digest failed.\r
349 @retval FALSE This interface is not supported.\r
350\r
351**/\r
352BOOLEAN\r
353EFIAPI\r
354Sha1Update (\r
355 IN OUT VOID *Sha1Context,\r
356 IN CONST VOID *Data,\r
357 IN UINTN DataSize\r
358 )\r
359{\r
360 CALL_CRYPTO_SERVICE (Sha1Update, (Sha1Context, Data, DataSize), FALSE);\r
361}\r
362\r
363/**\r
364 Completes computation of the SHA-1 digest value.\r
365\r
366 This function completes SHA-1 hash computation and retrieves the digest value into\r
367 the specified memory. After this function has been called, the SHA-1 context cannot\r
368 be used again.\r
369 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r
370 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r
371\r
372 If Sha1Context is NULL, then return FALSE.\r
373 If HashValue is NULL, then return FALSE.\r
374 If this interface is not supported, then return FALSE.\r
375\r
376 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
377 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
378 value (20 bytes).\r
379\r
380 @retval TRUE SHA-1 digest computation succeeded.\r
381 @retval FALSE SHA-1 digest computation failed.\r
382 @retval FALSE This interface is not supported.\r
383\r
384**/\r
385BOOLEAN\r
386EFIAPI\r
387Sha1Final (\r
388 IN OUT VOID *Sha1Context,\r
389 OUT UINT8 *HashValue\r
390 )\r
391{\r
392 CALL_CRYPTO_SERVICE (Sha1Final, (Sha1Context, HashValue), FALSE);\r
393}\r
394\r
395/**\r
396 Computes the SHA-1 message digest of a input data buffer.\r
397\r
398 This function performs the SHA-1 message digest of a given data buffer, and places\r
399 the digest value into the specified memory.\r
400\r
401 If this interface is not supported, then return FALSE.\r
402\r
403 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
404 @param[in] DataSize Size of Data buffer in bytes.\r
405 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
406 value (20 bytes).\r
407\r
408 @retval TRUE SHA-1 digest computation succeeded.\r
409 @retval FALSE SHA-1 digest computation failed.\r
410 @retval FALSE This interface is not supported.\r
411\r
412**/\r
413BOOLEAN\r
414EFIAPI\r
415Sha1HashAll (\r
416 IN CONST VOID *Data,\r
417 IN UINTN DataSize,\r
418 OUT UINT8 *HashValue\r
419 )\r
420{\r
421 CALL_CRYPTO_SERVICE (Sha1HashAll, (Data, DataSize, HashValue), FALSE);\r
422}\r
7c342378 423\r
0f01cec5 424#endif\r
cd70de1c
MK
425\r
426/**\r
427 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r
428\r
429 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.\r
430\r
431**/\r
432UINTN\r
433EFIAPI\r
434Sha256GetContextSize (\r
435 VOID\r
436 )\r
437{\r
438 CALL_CRYPTO_SERVICE (Sha256GetContextSize, (), 0);\r
439}\r
440\r
441/**\r
442 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r
443 subsequent use.\r
444\r
445 If Sha256Context is NULL, then return FALSE.\r
446\r
447 @param[out] Sha256Context Pointer to SHA-256 context being initialized.\r
448\r
449 @retval TRUE SHA-256 context initialization succeeded.\r
450 @retval FALSE SHA-256 context initialization failed.\r
451\r
452**/\r
453BOOLEAN\r
454EFIAPI\r
455Sha256Init (\r
456 OUT VOID *Sha256Context\r
457 )\r
458{\r
459 CALL_CRYPTO_SERVICE (Sha256Init, (Sha256Context), FALSE);\r
460}\r
461\r
462/**\r
463 Makes a copy of an existing SHA-256 context.\r
464\r
465 If Sha256Context is NULL, then return FALSE.\r
466 If NewSha256Context is NULL, then return FALSE.\r
467 If this interface is not supported, then return FALSE.\r
468\r
469 @param[in] Sha256Context Pointer to SHA-256 context being copied.\r
470 @param[out] NewSha256Context Pointer to new SHA-256 context.\r
471\r
472 @retval TRUE SHA-256 context copy succeeded.\r
473 @retval FALSE SHA-256 context copy failed.\r
474 @retval FALSE This interface is not supported.\r
475\r
476**/\r
477BOOLEAN\r
478EFIAPI\r
479Sha256Duplicate (\r
480 IN CONST VOID *Sha256Context,\r
481 OUT VOID *NewSha256Context\r
482 )\r
483{\r
484 CALL_CRYPTO_SERVICE (Sha256Duplicate, (Sha256Context, NewSha256Context), FALSE);\r
485}\r
486\r
487/**\r
488 Digests the input data and updates SHA-256 context.\r
489\r
490 This function performs SHA-256 digest on a data buffer of the specified size.\r
491 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
492 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized\r
493 by Sha256Final(). Behavior with invalid context is undefined.\r
494\r
495 If Sha256Context is NULL, then return FALSE.\r
496\r
497 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
498 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
499 @param[in] DataSize Size of Data buffer in bytes.\r
500\r
501 @retval TRUE SHA-256 data digest succeeded.\r
502 @retval FALSE SHA-256 data digest failed.\r
503\r
504**/\r
505BOOLEAN\r
506EFIAPI\r
507Sha256Update (\r
508 IN OUT VOID *Sha256Context,\r
509 IN CONST VOID *Data,\r
510 IN UINTN DataSize\r
511 )\r
512{\r
513 CALL_CRYPTO_SERVICE (Sha256Update, (Sha256Context, Data, DataSize), FALSE);\r
514}\r
515\r
516/**\r
517 Completes computation of the SHA-256 digest value.\r
518\r
519 This function completes SHA-256 hash computation and retrieves the digest value into\r
520 the specified memory. After this function has been called, the SHA-256 context cannot\r
521 be used again.\r
522 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be\r
523 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.\r
524\r
525 If Sha256Context is NULL, then return FALSE.\r
526 If HashValue is NULL, then return FALSE.\r
527\r
528 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
529 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
530 value (32 bytes).\r
531\r
532 @retval TRUE SHA-256 digest computation succeeded.\r
533 @retval FALSE SHA-256 digest computation failed.\r
534\r
535**/\r
536BOOLEAN\r
537EFIAPI\r
538Sha256Final (\r
539 IN OUT VOID *Sha256Context,\r
540 OUT UINT8 *HashValue\r
541 )\r
542{\r
543 CALL_CRYPTO_SERVICE (Sha256Final, (Sha256Context, HashValue), FALSE);\r
544}\r
545\r
546/**\r
547 Computes the SHA-256 message digest of a input data buffer.\r
548\r
549 This function performs the SHA-256 message digest of a given data buffer, and places\r
550 the digest value into the specified memory.\r
551\r
552 If this interface is not supported, then return FALSE.\r
553\r
554 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
555 @param[in] DataSize Size of Data buffer in bytes.\r
556 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
557 value (32 bytes).\r
558\r
559 @retval TRUE SHA-256 digest computation succeeded.\r
560 @retval FALSE SHA-256 digest computation failed.\r
561 @retval FALSE This interface is not supported.\r
562\r
563**/\r
564BOOLEAN\r
565EFIAPI\r
566Sha256HashAll (\r
567 IN CONST VOID *Data,\r
568 IN UINTN DataSize,\r
569 OUT UINT8 *HashValue\r
570 )\r
571{\r
572 CALL_CRYPTO_SERVICE (Sha256HashAll, (Data, DataSize, HashValue), FALSE);\r
573}\r
574\r
575/**\r
576 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r
577\r
578 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.\r
579\r
580**/\r
581UINTN\r
582EFIAPI\r
583Sha384GetContextSize (\r
584 VOID\r
585 )\r
586{\r
587 CALL_CRYPTO_SERVICE (Sha384GetContextSize, (), 0);\r
588}\r
589\r
590/**\r
591 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for\r
592 subsequent use.\r
593\r
594 If Sha384Context is NULL, then return FALSE.\r
595\r
596 @param[out] Sha384Context Pointer to SHA-384 context being initialized.\r
597\r
598 @retval TRUE SHA-384 context initialization succeeded.\r
599 @retval FALSE SHA-384 context initialization failed.\r
600\r
601**/\r
602BOOLEAN\r
603EFIAPI\r
604Sha384Init (\r
605 OUT VOID *Sha384Context\r
606 )\r
607{\r
608 CALL_CRYPTO_SERVICE (Sha384Init, (Sha384Context), FALSE);\r
609}\r
610\r
611/**\r
612 Makes a copy of an existing SHA-384 context.\r
613\r
614 If Sha384Context is NULL, then return FALSE.\r
615 If NewSha384Context is NULL, then return FALSE.\r
616 If this interface is not supported, then return FALSE.\r
617\r
618 @param[in] Sha384Context Pointer to SHA-384 context being copied.\r
619 @param[out] NewSha384Context Pointer to new SHA-384 context.\r
620\r
621 @retval TRUE SHA-384 context copy succeeded.\r
622 @retval FALSE SHA-384 context copy failed.\r
623 @retval FALSE This interface is not supported.\r
624\r
625**/\r
626BOOLEAN\r
627EFIAPI\r
628Sha384Duplicate (\r
629 IN CONST VOID *Sha384Context,\r
630 OUT VOID *NewSha384Context\r
631 )\r
632{\r
633 CALL_CRYPTO_SERVICE (Sha384Duplicate, (Sha384Context, NewSha384Context), FALSE);\r
634}\r
635\r
636/**\r
637 Digests the input data and updates SHA-384 context.\r
638\r
639 This function performs SHA-384 digest on a data buffer of the specified size.\r
640 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
641 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r
642 by Sha384Final(). Behavior with invalid context is undefined.\r
643\r
644 If Sha384Context is NULL, then return FALSE.\r
645\r
646 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
647 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
648 @param[in] DataSize Size of Data buffer in bytes.\r
649\r
650 @retval TRUE SHA-384 data digest succeeded.\r
651 @retval FALSE SHA-384 data digest failed.\r
652\r
653**/\r
654BOOLEAN\r
655EFIAPI\r
656Sha384Update (\r
657 IN OUT VOID *Sha384Context,\r
658 IN CONST VOID *Data,\r
659 IN UINTN DataSize\r
660 )\r
661{\r
662 CALL_CRYPTO_SERVICE (Sha384Update, (Sha384Context, Data, DataSize), FALSE);\r
663}\r
664\r
665/**\r
666 Completes computation of the SHA-384 digest value.\r
667\r
668 This function completes SHA-384 hash computation and retrieves the digest value into\r
669 the specified memory. After this function has been called, the SHA-384 context cannot\r
670 be used again.\r
671 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r
672 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r
673\r
674 If Sha384Context is NULL, then return FALSE.\r
675 If HashValue is NULL, then return FALSE.\r
676\r
677 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
678 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
679 value (48 bytes).\r
680\r
681 @retval TRUE SHA-384 digest computation succeeded.\r
682 @retval FALSE SHA-384 digest computation failed.\r
683\r
684**/\r
685BOOLEAN\r
686EFIAPI\r
687Sha384Final (\r
688 IN OUT VOID *Sha384Context,\r
689 OUT UINT8 *HashValue\r
690 )\r
691{\r
692 CALL_CRYPTO_SERVICE (Sha384Final, (Sha384Context, HashValue), FALSE);\r
693}\r
694\r
695/**\r
696 Computes the SHA-384 message digest of a input data buffer.\r
697\r
698 This function performs the SHA-384 message digest of a given data buffer, and places\r
699 the digest value into the specified memory.\r
700\r
701 If this interface is not supported, then return FALSE.\r
702\r
703 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
704 @param[in] DataSize Size of Data buffer in bytes.\r
705 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
706 value (48 bytes).\r
707\r
708 @retval TRUE SHA-384 digest computation succeeded.\r
709 @retval FALSE SHA-384 digest computation failed.\r
710 @retval FALSE This interface is not supported.\r
711\r
712**/\r
713BOOLEAN\r
714EFIAPI\r
715Sha384HashAll (\r
716 IN CONST VOID *Data,\r
717 IN UINTN DataSize,\r
718 OUT UINT8 *HashValue\r
719 )\r
720{\r
721 CALL_CRYPTO_SERVICE (Sha384HashAll, (Data, DataSize, HashValue), FALSE);\r
722}\r
723\r
724/**\r
725 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
726\r
727 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.\r
728\r
729**/\r
730UINTN\r
731EFIAPI\r
732Sha512GetContextSize (\r
733 VOID\r
734 )\r
735{\r
736 CALL_CRYPTO_SERVICE (Sha512GetContextSize, (), 0);\r
737}\r
738\r
739/**\r
740 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for\r
741 subsequent use.\r
742\r
743 If Sha512Context is NULL, then return FALSE.\r
744\r
745 @param[out] Sha512Context Pointer to SHA-512 context being initialized.\r
746\r
747 @retval TRUE SHA-512 context initialization succeeded.\r
748 @retval FALSE SHA-512 context initialization failed.\r
749\r
750**/\r
751BOOLEAN\r
752EFIAPI\r
753Sha512Init (\r
754 OUT VOID *Sha512Context\r
755 )\r
756{\r
757 CALL_CRYPTO_SERVICE (Sha512Init, (Sha512Context), FALSE);\r
758}\r
759\r
760/**\r
761 Makes a copy of an existing SHA-512 context.\r
762\r
763 If Sha512Context is NULL, then return FALSE.\r
764 If NewSha512Context is NULL, then return FALSE.\r
765 If this interface is not supported, then return FALSE.\r
766\r
767 @param[in] Sha512Context Pointer to SHA-512 context being copied.\r
768 @param[out] NewSha512Context Pointer to new SHA-512 context.\r
769\r
770 @retval TRUE SHA-512 context copy succeeded.\r
771 @retval FALSE SHA-512 context copy failed.\r
772 @retval FALSE This interface is not supported.\r
773\r
774**/\r
775BOOLEAN\r
776EFIAPI\r
777Sha512Duplicate (\r
778 IN CONST VOID *Sha512Context,\r
779 OUT VOID *NewSha512Context\r
780 )\r
781{\r
782 CALL_CRYPTO_SERVICE (Sha512Duplicate, (Sha512Context, NewSha512Context), FALSE);\r
783}\r
784\r
785/**\r
786 Digests the input data and updates SHA-512 context.\r
787\r
788 This function performs SHA-512 digest on a data buffer of the specified size.\r
789 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
790 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r
791 by Sha512Final(). Behavior with invalid context is undefined.\r
792\r
793 If Sha512Context is NULL, then return FALSE.\r
794\r
795 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
796 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
797 @param[in] DataSize Size of Data buffer in bytes.\r
798\r
799 @retval TRUE SHA-512 data digest succeeded.\r
800 @retval FALSE SHA-512 data digest failed.\r
801\r
802**/\r
803BOOLEAN\r
804EFIAPI\r
805Sha512Update (\r
806 IN OUT VOID *Sha512Context,\r
807 IN CONST VOID *Data,\r
808 IN UINTN DataSize\r
809 )\r
810{\r
811 CALL_CRYPTO_SERVICE (Sha512Update, (Sha512Context, Data, DataSize), FALSE);\r
812}\r
813\r
814/**\r
815 Completes computation of the SHA-512 digest value.\r
816\r
817 This function completes SHA-512 hash computation and retrieves the digest value into\r
818 the specified memory. After this function has been called, the SHA-512 context cannot\r
819 be used again.\r
820 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r
821 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r
822\r
823 If Sha512Context is NULL, then return FALSE.\r
824 If HashValue is NULL, then return FALSE.\r
825\r
826 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
827 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
828 value (64 bytes).\r
829\r
830 @retval TRUE SHA-512 digest computation succeeded.\r
831 @retval FALSE SHA-512 digest computation failed.\r
832\r
833**/\r
834BOOLEAN\r
835EFIAPI\r
836Sha512Final (\r
837 IN OUT VOID *Sha512Context,\r
838 OUT UINT8 *HashValue\r
839 )\r
840{\r
841 CALL_CRYPTO_SERVICE (Sha512Final, (Sha512Context, HashValue), FALSE);\r
842}\r
843\r
844/**\r
845 Computes the SHA-512 message digest of a input data buffer.\r
846\r
847 This function performs the SHA-512 message digest of a given data buffer, and places\r
848 the digest value into the specified memory.\r
849\r
850 If this interface is not supported, then return FALSE.\r
851\r
852 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
853 @param[in] DataSize Size of Data buffer in bytes.\r
854 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
855 value (64 bytes).\r
856\r
857 @retval TRUE SHA-512 digest computation succeeded.\r
858 @retval FALSE SHA-512 digest computation failed.\r
859 @retval FALSE This interface is not supported.\r
860\r
861**/\r
862BOOLEAN\r
863EFIAPI\r
864Sha512HashAll (\r
865 IN CONST VOID *Data,\r
866 IN UINTN DataSize,\r
867 OUT UINT8 *HashValue\r
868 )\r
869{\r
870 CALL_CRYPTO_SERVICE (Sha512HashAll, (Data, DataSize, HashValue), FALSE);\r
871}\r
872\r
c1e66210
ZL
873/**\r
874 Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,\r
875 published December 2016.\r
876\r
877 @param[in] Input Pointer to the input message (X).\r
878 @param[in] InputByteLen The number(>0) of input bytes provided for the input data.\r
879 @param[in] BlockSize The size of each block (B).\r
880 @param[out] Output Pointer to the output buffer.\r
881 @param[in] OutputByteLen The desired number of output bytes (L).\r
882 @param[in] Customization Pointer to the customization string (S).\r
883 @param[in] CustomByteLen The length of the customization string in bytes.\r
884\r
885 @retval TRUE ParallelHash256 digest computation succeeded.\r
886 @retval FALSE ParallelHash256 digest computation failed.\r
887 @retval FALSE This interface is not supported.\r
888\r
889**/\r
890BOOLEAN\r
891EFIAPI\r
892ParallelHash256HashAll (\r
893 IN CONST VOID *Input,\r
894 IN UINTN InputByteLen,\r
895 IN UINTN BlockSize,\r
896 OUT VOID *Output,\r
897 IN UINTN OutputByteLen,\r
898 IN CONST VOID *Customization,\r
899 IN UINTN CustomByteLen\r
900 )\r
901{\r
902 CALL_CRYPTO_SERVICE (ParallelHash256HashAll, (Input, InputByteLen, BlockSize, Output, OutputByteLen, Customization, CustomByteLen), FALSE);\r
903}\r
904\r
cd70de1c
MK
905/**\r
906 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.\r
907\r
908 @return The size, in bytes, of the context buffer required for SM3 hash operations.\r
909\r
910**/\r
911UINTN\r
912EFIAPI\r
913Sm3GetContextSize (\r
914 VOID\r
915 )\r
916{\r
917 CALL_CRYPTO_SERVICE (Sm3GetContextSize, (), 0);\r
918}\r
919\r
920/**\r
921 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for\r
922 subsequent use.\r
923\r
924 If Sm3Context is NULL, then return FALSE.\r
925\r
926 @param[out] Sm3Context Pointer to SM3 context being initialized.\r
927\r
928 @retval TRUE SM3 context initialization succeeded.\r
929 @retval FALSE SM3 context initialization failed.\r
930\r
931**/\r
932BOOLEAN\r
933EFIAPI\r
934Sm3Init (\r
935 OUT VOID *Sm3Context\r
936 )\r
937{\r
938 CALL_CRYPTO_SERVICE (Sm3Init, (Sm3Context), FALSE);\r
939}\r
940\r
941/**\r
942 Makes a copy of an existing SM3 context.\r
943\r
944 If Sm3Context is NULL, then return FALSE.\r
945 If NewSm3Context is NULL, then return FALSE.\r
946 If this interface is not supported, then return FALSE.\r
947\r
948 @param[in] Sm3Context Pointer to SM3 context being copied.\r
949 @param[out] NewSm3Context Pointer to new SM3 context.\r
950\r
951 @retval TRUE SM3 context copy succeeded.\r
952 @retval FALSE SM3 context copy failed.\r
953 @retval FALSE This interface is not supported.\r
954\r
955**/\r
956BOOLEAN\r
957EFIAPI\r
958Sm3Duplicate (\r
959 IN CONST VOID *Sm3Context,\r
960 OUT VOID *NewSm3Context\r
961 )\r
962{\r
963 CALL_CRYPTO_SERVICE (Sm3Duplicate, (Sm3Context, NewSm3Context), FALSE);\r
964}\r
965\r
966/**\r
967 Digests the input data and updates SM3 context.\r
968\r
969 This function performs SM3 digest on a data buffer of the specified size.\r
970 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
971 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized\r
972 by Sm3Final(). Behavior with invalid context is undefined.\r
973\r
974 If Sm3Context is NULL, then return FALSE.\r
975\r
976 @param[in, out] Sm3Context Pointer to the SM3 context.\r
977 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
978 @param[in] DataSize Size of Data buffer in bytes.\r
979\r
980 @retval TRUE SM3 data digest succeeded.\r
981 @retval FALSE SM3 data digest failed.\r
982\r
983**/\r
984BOOLEAN\r
985EFIAPI\r
986Sm3Update (\r
987 IN OUT VOID *Sm3Context,\r
988 IN CONST VOID *Data,\r
989 IN UINTN DataSize\r
990 )\r
991{\r
992 CALL_CRYPTO_SERVICE (Sm3Update, (Sm3Context, Data, DataSize), FALSE);\r
993}\r
994\r
995/**\r
996 Completes computation of the SM3 digest value.\r
997\r
998 This function completes SM3 hash computation and retrieves the digest value into\r
999 the specified memory. After this function has been called, the SM3 context cannot\r
1000 be used again.\r
1001 SM3 context should be already correctly initialized by Sm3Init(), and should not be\r
1002 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.\r
1003\r
1004 If Sm3Context is NULL, then return FALSE.\r
1005 If HashValue is NULL, then return FALSE.\r
1006\r
1007 @param[in, out] Sm3Context Pointer to the SM3 context.\r
1008 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
1009 value (32 bytes).\r
1010\r
1011 @retval TRUE SM3 digest computation succeeded.\r
1012 @retval FALSE SM3 digest computation failed.\r
1013\r
1014**/\r
1015BOOLEAN\r
1016EFIAPI\r
1017Sm3Final (\r
1018 IN OUT VOID *Sm3Context,\r
1019 OUT UINT8 *HashValue\r
1020 )\r
1021{\r
1022 CALL_CRYPTO_SERVICE (Sm3Final, (Sm3Context, HashValue), FALSE);\r
1023}\r
1024\r
1025/**\r
1026 Computes the SM3 message digest of a input data buffer.\r
1027\r
1028 This function performs the SM3 message digest of a given data buffer, and places\r
1029 the digest value into the specified memory.\r
1030\r
1031 If this interface is not supported, then return FALSE.\r
1032\r
1033 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
1034 @param[in] DataSize Size of Data buffer in bytes.\r
1035 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
1036 value (32 bytes).\r
1037\r
1038 @retval TRUE SM3 digest computation succeeded.\r
1039 @retval FALSE SM3 digest computation failed.\r
1040 @retval FALSE This interface is not supported.\r
1041\r
1042**/\r
1043BOOLEAN\r
1044EFIAPI\r
1045Sm3HashAll (\r
1046 IN CONST VOID *Data,\r
1047 IN UINTN DataSize,\r
1048 OUT UINT8 *HashValue\r
1049 )\r
1050{\r
1051 CALL_CRYPTO_SERVICE (Sm3HashAll, (Data, DataSize, HashValue), FALSE);\r
1052}\r
1053\r
7c342378 1054// =====================================================================================\r
cd70de1c 1055// MAC (Message Authentication Code) Primitive\r
7c342378 1056// =====================================================================================\r
cd70de1c 1057\r
cd70de1c
MK
1058/**\r
1059 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.\r
1060\r
1061 @return Pointer to the HMAC_CTX context that has been initialized.\r
1062 If the allocations fails, HmacSha256New() returns NULL.\r
1063\r
1064**/\r
1065VOID *\r
1066EFIAPI\r
1067HmacSha256New (\r
1068 VOID\r
1069 )\r
1070{\r
1071 CALL_CRYPTO_SERVICE (HmacSha256New, (), NULL);\r
1072}\r
1073\r
1074/**\r
1075 Release the specified HMAC_CTX context.\r
1076\r
1077 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r
1078\r
1079**/\r
1080VOID\r
1081EFIAPI\r
1082HmacSha256Free (\r
1083 IN VOID *HmacSha256Ctx\r
1084 )\r
1085{\r
1086 CALL_VOID_CRYPTO_SERVICE (HmacSha256Free, (HmacSha256Ctx));\r
1087}\r
1088\r
1089/**\r
1090 Set user-supplied key for subsequent use. It must be done before any\r
1091 calling to HmacSha256Update().\r
1092\r
1093 If HmacSha256Context is NULL, then return FALSE.\r
1094 If this interface is not supported, then return FALSE.\r
1095\r
1096 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r
1097 @param[in] Key Pointer to the user-supplied key.\r
1098 @param[in] KeySize Key size in bytes.\r
1099\r
1100 @retval TRUE The Key is set successfully.\r
1101 @retval FALSE The Key is set unsuccessfully.\r
1102 @retval FALSE This interface is not supported.\r
1103\r
1104**/\r
1105BOOLEAN\r
1106EFIAPI\r
1107HmacSha256SetKey (\r
1108 OUT VOID *HmacSha256Context,\r
1109 IN CONST UINT8 *Key,\r
1110 IN UINTN KeySize\r
1111 )\r
1112{\r
1113 CALL_CRYPTO_SERVICE (HmacSha256SetKey, (HmacSha256Context, Key, KeySize), FALSE);\r
1114}\r
1115\r
1116/**\r
1117 Makes a copy of an existing HMAC-SHA256 context.\r
1118\r
1119 If HmacSha256Context is NULL, then return FALSE.\r
1120 If NewHmacSha256Context is NULL, then return FALSE.\r
1121 If this interface is not supported, then return FALSE.\r
1122\r
1123 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r
1124 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r
1125\r
1126 @retval TRUE HMAC-SHA256 context copy succeeded.\r
1127 @retval FALSE HMAC-SHA256 context copy failed.\r
1128 @retval FALSE This interface is not supported.\r
1129\r
1130**/\r
1131BOOLEAN\r
1132EFIAPI\r
1133HmacSha256Duplicate (\r
1134 IN CONST VOID *HmacSha256Context,\r
1135 OUT VOID *NewHmacSha256Context\r
1136 )\r
1137{\r
1138 CALL_CRYPTO_SERVICE (HmacSha256Duplicate, (HmacSha256Context, NewHmacSha256Context), FALSE);\r
1139}\r
1140\r
1141/**\r
1142 Digests the input data and updates HMAC-SHA256 context.\r
1143\r
1144 This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r
1145 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1146 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1147 by HmacSha256Final(). Behavior with invalid context is undefined.\r
1148\r
1149 If HmacSha256Context is NULL, then return FALSE.\r
1150 If this interface is not supported, then return FALSE.\r
1151\r
1152 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1153 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1154 @param[in] DataSize Size of Data buffer in bytes.\r
1155\r
1156 @retval TRUE HMAC-SHA256 data digest succeeded.\r
1157 @retval FALSE HMAC-SHA256 data digest failed.\r
1158 @retval FALSE This interface is not supported.\r
1159\r
1160**/\r
1161BOOLEAN\r
1162EFIAPI\r
1163HmacSha256Update (\r
1164 IN OUT VOID *HmacSha256Context,\r
1165 IN CONST VOID *Data,\r
1166 IN UINTN DataSize\r
1167 )\r
1168{\r
1169 CALL_CRYPTO_SERVICE (HmacSha256Update, (HmacSha256Context, Data, DataSize), FALSE);\r
1170}\r
1171\r
1172/**\r
1173 Completes computation of the HMAC-SHA256 digest value.\r
1174\r
1175 This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r
1176 the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r
1177 be used again.\r
1178 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1179 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r
1180\r
1181 If HmacSha256Context is NULL, then return FALSE.\r
1182 If HmacValue is NULL, then return FALSE.\r
1183 If this interface is not supported, then return FALSE.\r
1184\r
1185 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1186 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
1187 value (32 bytes).\r
1188\r
1189 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1190 @retval FALSE HMAC-SHA256 digest computation failed.\r
1191 @retval FALSE This interface is not supported.\r
1192\r
1193**/\r
1194BOOLEAN\r
1195EFIAPI\r
1196HmacSha256Final (\r
1197 IN OUT VOID *HmacSha256Context,\r
1198 OUT UINT8 *HmacValue\r
1199 )\r
1200{\r
1201 CALL_CRYPTO_SERVICE (HmacSha256Final, (HmacSha256Context, HmacValue), FALSE);\r
1202}\r
1203\r
3f77ccb9
QZ
1204/**\r
1205 Computes the HMAC-SHA256 digest of a input data buffer.\r
1206\r
1207 This function performs the HMAC-SHA256 digest of a given data buffer, and places\r
1208 the digest value into the specified memory.\r
1209\r
1210 If this interface is not supported, then return FALSE.\r
1211\r
1212 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1213 @param[in] DataSize Size of Data buffer in bytes.\r
1214 @param[in] Key Pointer to the user-supplied key.\r
1215 @param[in] KeySize Key size in bytes.\r
1216 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
1217 value (32 bytes).\r
1218\r
1219 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1220 @retval FALSE HMAC-SHA256 digest computation failed.\r
1221 @retval FALSE This interface is not supported.\r
1222\r
1223**/\r
1224BOOLEAN\r
1225EFIAPI\r
1226HmacSha256All (\r
1227 IN CONST VOID *Data,\r
1228 IN UINTN DataSize,\r
1229 IN CONST UINT8 *Key,\r
1230 IN UINTN KeySize,\r
1231 OUT UINT8 *HmacValue\r
1232 )\r
1233{\r
1234 CALL_CRYPTO_SERVICE (HmacSha256All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
1235}\r
1236\r
1237/**\r
1238 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.\r
1239\r
1240 @return Pointer to the HMAC_CTX context that has been initialized.\r
1241 If the allocations fails, HmacSha384New() returns NULL.\r
1242\r
1243**/\r
1244VOID *\r
1245EFIAPI\r
1246HmacSha384New (\r
1247 VOID\r
1248 )\r
1249{\r
1250 CALL_CRYPTO_SERVICE (HmacSha384New, (), NULL);\r
1251}\r
1252\r
1253/**\r
1254 Release the specified HMAC_CTX context.\r
1255\r
1256 @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.\r
1257\r
1258**/\r
1259VOID\r
1260EFIAPI\r
1261HmacSha384Free (\r
1262 IN VOID *HmacSha384Ctx\r
1263 )\r
1264{\r
1265 CALL_VOID_CRYPTO_SERVICE (HmacSha384Free, (HmacSha384Ctx));\r
1266}\r
1267\r
1268/**\r
1269 Set user-supplied key for subsequent use. It must be done before any\r
1270 calling to HmacSha384Update().\r
1271\r
1272 If HmacSha384Context is NULL, then return FALSE.\r
1273 If this interface is not supported, then return FALSE.\r
1274\r
1275 @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.\r
1276 @param[in] Key Pointer to the user-supplied key.\r
1277 @param[in] KeySize Key size in bytes.\r
1278\r
1279 @retval TRUE The Key is set successfully.\r
1280 @retval FALSE The Key is set unsuccessfully.\r
1281 @retval FALSE This interface is not supported.\r
1282\r
1283**/\r
1284BOOLEAN\r
1285EFIAPI\r
1286HmacSha384SetKey (\r
1287 OUT VOID *HmacSha384Context,\r
1288 IN CONST UINT8 *Key,\r
1289 IN UINTN KeySize\r
1290 )\r
1291{\r
1292 CALL_CRYPTO_SERVICE (HmacSha384SetKey, (HmacSha384Context, Key, KeySize), FALSE);\r
1293}\r
1294\r
1295/**\r
1296 Makes a copy of an existing HMAC-SHA384 context.\r
1297\r
1298 If HmacSha384Context is NULL, then return FALSE.\r
1299 If NewHmacSha384Context is NULL, then return FALSE.\r
1300 If this interface is not supported, then return FALSE.\r
1301\r
1302 @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.\r
1303 @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.\r
1304\r
1305 @retval TRUE HMAC-SHA384 context copy succeeded.\r
1306 @retval FALSE HMAC-SHA384 context copy failed.\r
1307 @retval FALSE This interface is not supported.\r
1308\r
1309**/\r
1310BOOLEAN\r
1311EFIAPI\r
1312HmacSha384Duplicate (\r
1313 IN CONST VOID *HmacSha384Context,\r
1314 OUT VOID *NewHmacSha384Context\r
1315 )\r
1316{\r
1317 CALL_CRYPTO_SERVICE (HmacSha384Duplicate, (HmacSha384Context, NewHmacSha384Context), FALSE);\r
1318}\r
1319\r
1320/**\r
1321 Digests the input data and updates HMAC-SHA384 context.\r
1322\r
1323 This function performs HMAC-SHA384 digest on a data buffer of the specified size.\r
1324 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1325 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
1326 by HmacSha384Final(). Behavior with invalid context is undefined.\r
1327\r
1328 If HmacSha384Context is NULL, then return FALSE.\r
1329 If this interface is not supported, then return FALSE.\r
1330\r
1331 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r
1332 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1333 @param[in] DataSize Size of Data buffer in bytes.\r
1334\r
1335 @retval TRUE HMAC-SHA384 data digest succeeded.\r
1336 @retval FALSE HMAC-SHA384 data digest failed.\r
1337 @retval FALSE This interface is not supported.\r
1338\r
1339**/\r
1340BOOLEAN\r
1341EFIAPI\r
1342HmacSha384Update (\r
1343 IN OUT VOID *HmacSha384Context,\r
1344 IN CONST VOID *Data,\r
1345 IN UINTN DataSize\r
1346 )\r
1347{\r
1348 CALL_CRYPTO_SERVICE (HmacSha384Update, (HmacSha384Context, Data, DataSize), FALSE);\r
1349}\r
1350\r
1351/**\r
1352 Completes computation of the HMAC-SHA384 digest value.\r
1353\r
1354 This function completes HMAC-SHA384 hash computation and retrieves the digest value into\r
1355 the specified memory. After this function has been called, the HMAC-SHA384 context cannot\r
1356 be used again.\r
1357 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
1358 by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.\r
1359\r
1360 If HmacSha384Context is NULL, then return FALSE.\r
1361 If HmacValue is NULL, then return FALSE.\r
1362 If this interface is not supported, then return FALSE.\r
1363\r
1364 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r
1365 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest\r
1366 value (48 bytes).\r
1367\r
1368 @retval TRUE HMAC-SHA384 digest computation succeeded.\r
1369 @retval FALSE HMAC-SHA384 digest computation failed.\r
1370 @retval FALSE This interface is not supported.\r
1371\r
1372**/\r
1373BOOLEAN\r
1374EFIAPI\r
1375HmacSha384Final (\r
1376 IN OUT VOID *HmacSha384Context,\r
1377 OUT UINT8 *HmacValue\r
1378 )\r
1379{\r
1380 CALL_CRYPTO_SERVICE (HmacSha384Final, (HmacSha384Context, HmacValue), FALSE);\r
1381}\r
1382\r
1383/**\r
1384 Computes the HMAC-SHA384 digest of a input data buffer.\r
1385\r
1386 This function performs the HMAC-SHA384 digest of a given data buffer, and places\r
1387 the digest value into the specified memory.\r
1388\r
1389 If this interface is not supported, then return FALSE.\r
1390\r
1391 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1392 @param[in] DataSize Size of Data buffer in bytes.\r
1393 @param[in] Key Pointer to the user-supplied key.\r
1394 @param[in] KeySize Key size in bytes.\r
1395 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest\r
1396 value (48 bytes).\r
1397\r
1398 @retval TRUE HMAC-SHA384 digest computation succeeded.\r
1399 @retval FALSE HMAC-SHA384 digest computation failed.\r
1400 @retval FALSE This interface is not supported.\r
1401\r
1402**/\r
1403BOOLEAN\r
1404EFIAPI\r
1405HmacSha384All (\r
1406 IN CONST VOID *Data,\r
1407 IN UINTN DataSize,\r
1408 IN CONST UINT8 *Key,\r
1409 IN UINTN KeySize,\r
1410 OUT UINT8 *HmacValue\r
1411 )\r
1412{\r
1413 CALL_CRYPTO_SERVICE (HmacSha384All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
1414}\r
1415\r
7c342378 1416// =====================================================================================\r
cd70de1c 1417// Symmetric Cryptography Primitive\r
7c342378 1418// =====================================================================================\r
cd70de1c 1419\r
cd70de1c
MK
1420/**\r
1421 Retrieves the size, in bytes, of the context buffer required for AES operations.\r
1422\r
1423 If this interface is not supported, then return zero.\r
1424\r
1425 @return The size, in bytes, of the context buffer required for AES operations.\r
1426 @retval 0 This interface is not supported.\r
1427\r
1428**/\r
1429UINTN\r
1430EFIAPI\r
1431AesGetContextSize (\r
1432 VOID\r
1433 )\r
1434{\r
1435 CALL_CRYPTO_SERVICE (AesGetContextSize, (), 0);\r
1436}\r
1437\r
1438/**\r
1439 Initializes user-supplied memory as AES context for subsequent use.\r
1440\r
1441 This function initializes user-supplied memory pointed by AesContext as AES context.\r
1442 In addition, it sets up all AES key materials for subsequent encryption and decryption\r
1443 operations.\r
1444 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
1445\r
1446 If AesContext is NULL, then return FALSE.\r
1447 If Key is NULL, then return FALSE.\r
1448 If KeyLength is not valid, then return FALSE.\r
1449 If this interface is not supported, then return FALSE.\r
1450\r
1451 @param[out] AesContext Pointer to AES context being initialized.\r
1452 @param[in] Key Pointer to the user-supplied AES key.\r
1453 @param[in] KeyLength Length of AES key in bits.\r
1454\r
1455 @retval TRUE AES context initialization succeeded.\r
1456 @retval FALSE AES context initialization failed.\r
1457 @retval FALSE This interface is not supported.\r
1458\r
1459**/\r
1460BOOLEAN\r
1461EFIAPI\r
1462AesInit (\r
1463 OUT VOID *AesContext,\r
1464 IN CONST UINT8 *Key,\r
1465 IN UINTN KeyLength\r
1466 )\r
1467{\r
1468 CALL_CRYPTO_SERVICE (AesInit, (AesContext, Key, KeyLength), FALSE);\r
1469}\r
1470\r
cd70de1c
MK
1471/**\r
1472 Performs AES encryption on a data buffer of the specified size in CBC mode.\r
1473\r
1474 This function performs AES encryption on data buffer pointed by Input, of specified\r
1475 size of InputSize, in CBC mode.\r
1476 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1477 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1478 Initialization vector should be one block size (16 bytes).\r
1479 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1480 invalid AES context is undefined.\r
1481\r
1482 If AesContext is NULL, then return FALSE.\r
1483 If Input is NULL, then return FALSE.\r
1484 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1485 If Ivec is NULL, then return FALSE.\r
1486 If Output is NULL, then return FALSE.\r
1487 If this interface is not supported, then return FALSE.\r
1488\r
1489 @param[in] AesContext Pointer to the AES context.\r
1490 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1491 @param[in] InputSize Size of the Input buffer in bytes.\r
1492 @param[in] Ivec Pointer to initialization vector.\r
1493 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1494\r
1495 @retval TRUE AES encryption succeeded.\r
1496 @retval FALSE AES encryption failed.\r
1497 @retval FALSE This interface is not supported.\r
1498\r
1499**/\r
1500BOOLEAN\r
1501EFIAPI\r
1502AesCbcEncrypt (\r
1503 IN VOID *AesContext,\r
1504 IN CONST UINT8 *Input,\r
1505 IN UINTN InputSize,\r
1506 IN CONST UINT8 *Ivec,\r
1507 OUT UINT8 *Output\r
1508 )\r
1509{\r
1510 CALL_CRYPTO_SERVICE (AesCbcEncrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);\r
1511}\r
1512\r
1513/**\r
1514 Performs AES decryption on a data buffer of the specified size in CBC mode.\r
1515\r
1516 This function performs AES decryption on data buffer pointed by Input, of specified\r
1517 size of InputSize, in CBC mode.\r
1518 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1519 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1520 Initialization vector should be one block size (16 bytes).\r
1521 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1522 invalid AES context is undefined.\r
1523\r
1524 If AesContext is NULL, then return FALSE.\r
1525 If Input is NULL, then return FALSE.\r
1526 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1527 If Ivec is NULL, then return FALSE.\r
1528 If Output is NULL, then return FALSE.\r
1529 If this interface is not supported, then return FALSE.\r
1530\r
1531 @param[in] AesContext Pointer to the AES context.\r
1532 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1533 @param[in] InputSize Size of the Input buffer in bytes.\r
1534 @param[in] Ivec Pointer to initialization vector.\r
1535 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1536\r
1537 @retval TRUE AES decryption succeeded.\r
1538 @retval FALSE AES decryption failed.\r
1539 @retval FALSE This interface is not supported.\r
1540\r
1541**/\r
1542BOOLEAN\r
1543EFIAPI\r
1544AesCbcDecrypt (\r
1545 IN VOID *AesContext,\r
1546 IN CONST UINT8 *Input,\r
1547 IN UINTN InputSize,\r
1548 IN CONST UINT8 *Ivec,\r
1549 OUT UINT8 *Output\r
1550 )\r
1551{\r
1552 CALL_CRYPTO_SERVICE (AesCbcDecrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);\r
1553}\r
1554\r
7c342378 1555// =====================================================================================\r
cd70de1c 1556// Asymmetric Cryptography Primitive\r
7c342378 1557// =====================================================================================\r
cd70de1c
MK
1558\r
1559/**\r
1560 Allocates and initializes one RSA context for subsequent use.\r
1561\r
1562 @return Pointer to the RSA context that has been initialized.\r
1563 If the allocations fails, RsaNew() returns NULL.\r
1564\r
1565**/\r
1566VOID *\r
1567EFIAPI\r
1568RsaNew (\r
1569 VOID\r
1570 )\r
1571{\r
1572 CALL_CRYPTO_SERVICE (RsaNew, (), NULL);\r
1573}\r
1574\r
1575/**\r
1576 Release the specified RSA context.\r
1577\r
1578 If RsaContext is NULL, then return FALSE.\r
1579\r
1580 @param[in] RsaContext Pointer to the RSA context to be released.\r
1581\r
1582**/\r
1583VOID\r
1584EFIAPI\r
1585RsaFree (\r
1586 IN VOID *RsaContext\r
1587 )\r
1588{\r
1589 CALL_VOID_CRYPTO_SERVICE (RsaFree, (RsaContext));\r
1590}\r
1591\r
1592/**\r
1593 Sets the tag-designated key component into the established RSA context.\r
1594\r
1595 This function sets the tag-designated RSA key component into the established\r
1596 RSA context from the user-specified non-negative integer (octet string format\r
1597 represented in RSA PKCS#1).\r
1598 If BigNumber is NULL, then the specified key component in RSA context is cleared.\r
1599\r
1600 If RsaContext is NULL, then return FALSE.\r
1601\r
1602 @param[in, out] RsaContext Pointer to RSA context being set.\r
1603 @param[in] KeyTag Tag of RSA key component being set.\r
1604 @param[in] BigNumber Pointer to octet integer buffer.\r
1605 If NULL, then the specified key component in RSA\r
1606 context is cleared.\r
1607 @param[in] BnSize Size of big number buffer in bytes.\r
1608 If BigNumber is NULL, then it is ignored.\r
1609\r
1610 @retval TRUE RSA key component was set successfully.\r
1611 @retval FALSE Invalid RSA key component tag.\r
1612\r
1613**/\r
1614BOOLEAN\r
1615EFIAPI\r
1616RsaSetKey (\r
1617 IN OUT VOID *RsaContext,\r
1618 IN RSA_KEY_TAG KeyTag,\r
1619 IN CONST UINT8 *BigNumber,\r
1620 IN UINTN BnSize\r
1621 )\r
1622{\r
1623 CALL_CRYPTO_SERVICE (RsaSetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);\r
1624}\r
1625\r
1626/**\r
1627 Gets the tag-designated RSA key component from the established RSA context.\r
1628\r
1629 This function retrieves the tag-designated RSA key component from the\r
1630 established RSA context as a non-negative integer (octet string format\r
1631 represented in RSA PKCS#1).\r
1632 If specified key component has not been set or has been cleared, then returned\r
1633 BnSize is set to 0.\r
1634 If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
1635 is returned and BnSize is set to the required buffer size to obtain the key.\r
1636\r
1637 If RsaContext is NULL, then return FALSE.\r
1638 If BnSize is NULL, then return FALSE.\r
1639 If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
1640 If this interface is not supported, then return FALSE.\r
1641\r
1642 @param[in, out] RsaContext Pointer to RSA context being set.\r
1643 @param[in] KeyTag Tag of RSA key component being set.\r
1644 @param[out] BigNumber Pointer to octet integer buffer.\r
1645 @param[in, out] BnSize On input, the size of big number buffer in bytes.\r
1646 On output, the size of data returned in big number buffer in bytes.\r
1647\r
1648 @retval TRUE RSA key component was retrieved successfully.\r
1649 @retval FALSE Invalid RSA key component tag.\r
1650 @retval FALSE BnSize is too small.\r
1651 @retval FALSE This interface is not supported.\r
1652\r
1653**/\r
1654BOOLEAN\r
1655EFIAPI\r
1656RsaGetKey (\r
1657 IN OUT VOID *RsaContext,\r
1658 IN RSA_KEY_TAG KeyTag,\r
1659 OUT UINT8 *BigNumber,\r
1660 IN OUT UINTN *BnSize\r
1661 )\r
1662{\r
1663 CALL_CRYPTO_SERVICE (RsaGetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);\r
1664}\r
1665\r
1666/**\r
1667 Generates RSA key components.\r
1668\r
1669 This function generates RSA key components. It takes RSA public exponent E and\r
1670 length in bits of RSA modulus N as input, and generates all key components.\r
1671 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
1672\r
1673 Before this function can be invoked, pseudorandom number generator must be correctly\r
1674 initialized by RandomSeed().\r
1675\r
1676 If RsaContext is NULL, then return FALSE.\r
1677 If this interface is not supported, then return FALSE.\r
1678\r
1679 @param[in, out] RsaContext Pointer to RSA context being set.\r
1680 @param[in] ModulusLength Length of RSA modulus N in bits.\r
1681 @param[in] PublicExponent Pointer to RSA public exponent.\r
1682 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r
1683\r
1684 @retval TRUE RSA key component was generated successfully.\r
1685 @retval FALSE Invalid RSA key component tag.\r
1686 @retval FALSE This interface is not supported.\r
1687\r
1688**/\r
1689BOOLEAN\r
1690EFIAPI\r
1691RsaGenerateKey (\r
1692 IN OUT VOID *RsaContext,\r
1693 IN UINTN ModulusLength,\r
1694 IN CONST UINT8 *PublicExponent,\r
1695 IN UINTN PublicExponentSize\r
1696 )\r
1697{\r
1698 CALL_CRYPTO_SERVICE (RsaGenerateKey, (RsaContext, ModulusLength, PublicExponent, PublicExponentSize), FALSE);\r
1699}\r
1700\r
1701/**\r
1702 Validates key components of RSA context.\r
1703 NOTE: This function performs integrity checks on all the RSA key material, so\r
1704 the RSA key structure must contain all the private key data.\r
1705\r
1706 This function validates key components of RSA context in following aspects:\r
1707 - Whether p is a prime\r
1708 - Whether q is a prime\r
1709 - Whether n = p * q\r
1710 - Whether d*e = 1 mod lcm(p-1,q-1)\r
1711\r
1712 If RsaContext is NULL, then return FALSE.\r
1713 If this interface is not supported, then return FALSE.\r
1714\r
1715 @param[in] RsaContext Pointer to RSA context to check.\r
1716\r
1717 @retval TRUE RSA key components are valid.\r
1718 @retval FALSE RSA key components are not valid.\r
1719 @retval FALSE This interface is not supported.\r
1720\r
1721**/\r
1722BOOLEAN\r
1723EFIAPI\r
1724RsaCheckKey (\r
1725 IN VOID *RsaContext\r
1726 )\r
1727{\r
1728 CALL_CRYPTO_SERVICE (RsaCheckKey, (RsaContext), FALSE);\r
1729}\r
1730\r
1731/**\r
1732 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
1733\r
1734 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1735 RSA PKCS#1.\r
1736 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1737 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1738\r
1739 If RsaContext is NULL, then return FALSE.\r
1740 If MessageHash is NULL, then return FALSE.\r
1741 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
1742 If SigSize is large enough but Signature is NULL, then return FALSE.\r
1743 If this interface is not supported, then return FALSE.\r
1744\r
1745 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1746 @param[in] MessageHash Pointer to octet message hash to be signed.\r
1747 @param[in] HashSize Size of the message hash in bytes.\r
1748 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
1749 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
1750 On output, the size of data returned in Signature buffer in bytes.\r
1751\r
1752 @retval TRUE Signature successfully generated in PKCS1-v1_5.\r
1753 @retval FALSE Signature generation failed.\r
1754 @retval FALSE SigSize is too small.\r
1755 @retval FALSE This interface is not supported.\r
1756\r
1757**/\r
1758BOOLEAN\r
1759EFIAPI\r
1760RsaPkcs1Sign (\r
1761 IN VOID *RsaContext,\r
1762 IN CONST UINT8 *MessageHash,\r
1763 IN UINTN HashSize,\r
1764 OUT UINT8 *Signature,\r
1765 IN OUT UINTN *SigSize\r
1766 )\r
1767{\r
1768 CALL_CRYPTO_SERVICE (RsaPkcs1Sign, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);\r
1769}\r
1770\r
1771/**\r
1772 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1773 RSA PKCS#1.\r
1774\r
1775 If RsaContext is NULL, then return FALSE.\r
1776 If MessageHash is NULL, then return FALSE.\r
1777 If Signature is NULL, then return FALSE.\r
1778 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r
1779\r
1780 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1781 @param[in] MessageHash Pointer to octet message hash to be checked.\r
1782 @param[in] HashSize Size of the message hash in bytes.\r
1783 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r
1784 @param[in] SigSize Size of signature in bytes.\r
1785\r
1786 @retval TRUE Valid signature encoded in PKCS1-v1_5.\r
1787 @retval FALSE Invalid signature or invalid RSA context.\r
1788\r
1789**/\r
1790BOOLEAN\r
1791EFIAPI\r
1792RsaPkcs1Verify (\r
1793 IN VOID *RsaContext,\r
1794 IN CONST UINT8 *MessageHash,\r
1795 IN UINTN HashSize,\r
1796 IN CONST UINT8 *Signature,\r
1797 IN UINTN SigSize\r
1798 )\r
1799{\r
1800 CALL_CRYPTO_SERVICE (RsaPkcs1Verify, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);\r
1801}\r
1802\r
22ac5cc9
SA
1803/**\r
1804 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.\r
1805 Implementation determines salt length automatically from the signature encoding.\r
1806 Mask generation function is the same as the message digest algorithm.\r
20ca5288 1807 Salt length should be equal to digest length.\r
22ac5cc9
SA
1808\r
1809 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1810 @param[in] Message Pointer to octet message to be verified.\r
1811 @param[in] MsgSize Size of the message in bytes.\r
1812 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.\r
1813 @param[in] SigSize Size of signature in bytes.\r
1814 @param[in] DigestLen Length of digest for RSA operation.\r
1815 @param[in] SaltLen Salt length for PSS encoding.\r
1816\r
1817 @retval TRUE Valid signature encoded in RSASSA-PSS.\r
1818 @retval FALSE Invalid signature or invalid RSA context.\r
1819\r
1820**/\r
1821BOOLEAN\r
1822EFIAPI\r
1823RsaPssVerify (\r
1824 IN VOID *RsaContext,\r
1825 IN CONST UINT8 *Message,\r
1826 IN UINTN MsgSize,\r
1827 IN CONST UINT8 *Signature,\r
1828 IN UINTN SigSize,\r
1829 IN UINT16 DigestLen,\r
1830 IN UINT16 SaltLen\r
1831 )\r
1832{\r
1833 CALL_CRYPTO_SERVICE (RsaPssVerify, (RsaContext, Message, MsgSize, Signature, SigSize, DigestLen, SaltLen), FALSE);\r
1834}\r
1835\r
1836/**\r
1837 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in\r
1838 RFC 8017.\r
1839 Mask generation function is the same as the message digest algorithm.\r
1840 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1841 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1842\r
20ca5288
AS
1843 If RsaContext is NULL, then return FALSE.\r
1844 If Message is NULL, then return FALSE.\r
1845 If MsgSize is zero or > INT_MAX, then return FALSE.\r
1846 If DigestLen is NOT 32, 48 or 64, return FALSE.\r
1847 If SaltLen is not equal to DigestLen, then return FALSE.\r
1848 If SigSize is large enough but Signature is NULL, then return FALSE.\r
1849 If this interface is not supported, then return FALSE.\r
1850\r
22ac5cc9
SA
1851 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1852 @param[in] Message Pointer to octet message to be signed.\r
1853 @param[in] MsgSize Size of the message in bytes.\r
1854 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.\r
1855 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.\r
1856 @param[out] Signature Pointer to buffer to receive RSA PSS signature.\r
1857 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
1858 On output, the size of data returned in Signature buffer in bytes.\r
1859\r
1860 @retval TRUE Signature successfully generated in RSASSA-PSS.\r
1861 @retval FALSE Signature generation failed.\r
1862 @retval FALSE SigSize is too small.\r
1863 @retval FALSE This interface is not supported.\r
1864\r
1865**/\r
1866BOOLEAN\r
1867EFIAPI\r
1868RsaPssSign (\r
1869 IN VOID *RsaContext,\r
1870 IN CONST UINT8 *Message,\r
1871 IN UINTN MsgSize,\r
1872 IN UINT16 DigestLen,\r
1873 IN UINT16 SaltLen,\r
1874 OUT UINT8 *Signature,\r
1875 IN OUT UINTN *SigSize\r
1876 )\r
1877{\r
1878 CALL_CRYPTO_SERVICE (RsaPssSign, (RsaContext, Message, MsgSize, DigestLen, SaltLen, Signature, SigSize), FALSE);\r
1879}\r
1880\r
cd70de1c
MK
1881/**\r
1882 Retrieve the RSA Private Key from the password-protected PEM key data.\r
1883\r
1884 If PemData is NULL, then return FALSE.\r
1885 If RsaContext is NULL, then return FALSE.\r
1886 If this interface is not supported, then return FALSE.\r
1887\r
1888 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
1889 @param[in] PemSize Size of the PEM key data in bytes.\r
1890 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
1891 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1892 RSA private key component. Use RsaFree() function to free the\r
1893 resource.\r
1894\r
1895 @retval TRUE RSA Private Key was retrieved successfully.\r
1896 @retval FALSE Invalid PEM key data or incorrect password.\r
1897 @retval FALSE This interface is not supported.\r
1898\r
1899**/\r
1900BOOLEAN\r
1901EFIAPI\r
1902RsaGetPrivateKeyFromPem (\r
1903 IN CONST UINT8 *PemData,\r
1904 IN UINTN PemSize,\r
1905 IN CONST CHAR8 *Password,\r
1906 OUT VOID **RsaContext\r
1907 )\r
1908{\r
1909 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);\r
1910}\r
1911\r
1912/**\r
1913 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
1914\r
1915 If Cert is NULL, then return FALSE.\r
1916 If RsaContext is NULL, then return FALSE.\r
1917 If this interface is not supported, then return FALSE.\r
1918\r
1919 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1920 @param[in] CertSize Size of the X509 certificate in bytes.\r
1921 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1922 RSA public key component. Use RsaFree() function to free the\r
1923 resource.\r
1924\r
1925 @retval TRUE RSA Public Key was retrieved successfully.\r
1926 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
1927 @retval FALSE This interface is not supported.\r
1928\r
1929**/\r
1930BOOLEAN\r
1931EFIAPI\r
1932RsaGetPublicKeyFromX509 (\r
1933 IN CONST UINT8 *Cert,\r
1934 IN UINTN CertSize,\r
1935 OUT VOID **RsaContext\r
1936 )\r
1937{\r
1938 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);\r
1939}\r
1940\r
1941/**\r
1942 Retrieve the subject bytes from one X.509 certificate.\r
1943\r
1944 If Cert is NULL, then return FALSE.\r
1945 If SubjectSize is NULL, then return FALSE.\r
1946 If this interface is not supported, then return FALSE.\r
1947\r
1948 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1949 @param[in] CertSize Size of the X509 certificate in bytes.\r
1950 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
1951 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
1952 and the size of buffer returned CertSubject on output.\r
1953\r
1954 @retval TRUE The certificate subject retrieved successfully.\r
1955 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
1956 The SubjectSize will be updated with the required size.\r
1957 @retval FALSE This interface is not supported.\r
1958\r
1959**/\r
1960BOOLEAN\r
1961EFIAPI\r
1962X509GetSubjectName (\r
1963 IN CONST UINT8 *Cert,\r
1964 IN UINTN CertSize,\r
1965 OUT UINT8 *CertSubject,\r
1966 IN OUT UINTN *SubjectSize\r
1967 )\r
1968{\r
1969 CALL_CRYPTO_SERVICE (X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);\r
1970}\r
1971\r
1972/**\r
1973 Retrieve the common name (CN) string from one X.509 certificate.\r
1974\r
1975 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1976 @param[in] CertSize Size of the X509 certificate in bytes.\r
1977 @param[out] CommonName Buffer to contain the retrieved certificate common\r
1978 name string (UTF8). At most CommonNameSize bytes will be\r
1979 written and the string will be null terminated. May be\r
1980 NULL in order to determine the size buffer needed.\r
1981 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
1982 and the size of buffer returned CommonName on output.\r
1983 If CommonName is NULL then the amount of space needed\r
1984 in buffer (including the final null) is returned.\r
1985\r
1986 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
1987 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1988 If CommonNameSize is NULL.\r
1989 If CommonName is not NULL and *CommonNameSize is 0.\r
1990 If Certificate is invalid.\r
1991 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
1992 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
1993 (including the final null) is returned in the\r
1994 CommonNameSize parameter.\r
1995 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1996\r
1997**/\r
1998RETURN_STATUS\r
1999EFIAPI\r
2000X509GetCommonName (\r
2001 IN CONST UINT8 *Cert,\r
2002 IN UINTN CertSize,\r
c8f46130 2003 OUT CHAR8 *CommonName OPTIONAL,\r
cd70de1c
MK
2004 IN OUT UINTN *CommonNameSize\r
2005 )\r
2006{\r
2007 CALL_CRYPTO_SERVICE (X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);\r
2008}\r
2009\r
2010/**\r
2011 Retrieve the organization name (O) string from one X.509 certificate.\r
2012\r
2013 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2014 @param[in] CertSize Size of the X509 certificate in bytes.\r
2015 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
2016 name string. At most NameBufferSize bytes will be\r
2017 written and the string will be null terminated. May be\r
2018 NULL in order to determine the size buffer needed.\r
2019 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
2020 and the size of buffer returned Name on output.\r
2021 If NameBuffer is NULL then the amount of space needed\r
2022 in buffer (including the final null) is returned.\r
2023\r
2024 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
2025 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
2026 If NameBufferSize is NULL.\r
2027 If NameBuffer is not NULL and *CommonNameSize is 0.\r
2028 If Certificate is invalid.\r
2029 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
2030 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
2031 (including the final null) is returned in the\r
2032 CommonNameSize parameter.\r
2033 @retval RETURN_UNSUPPORTED The operation is not supported.\r
2034\r
2035**/\r
2036RETURN_STATUS\r
2037EFIAPI\r
2038X509GetOrganizationName (\r
7c342378
MK
2039 IN CONST UINT8 *Cert,\r
2040 IN UINTN CertSize,\r
2041 OUT CHAR8 *NameBuffer OPTIONAL,\r
2042 IN OUT UINTN *NameBufferSize\r
cd70de1c
MK
2043 )\r
2044{\r
2045 CALL_CRYPTO_SERVICE (X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);\r
2046}\r
2047\r
2048/**\r
2049 Verify one X509 certificate was issued by the trusted CA.\r
2050\r
2051 If Cert is NULL, then return FALSE.\r
2052 If CACert is NULL, then return FALSE.\r
2053 If this interface is not supported, then return FALSE.\r
2054\r
2055 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
2056 @param[in] CertSize Size of the X509 certificate in bytes.\r
2057 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
2058 @param[in] CACertSize Size of the CA Certificate in bytes.\r
2059\r
2060 @retval TRUE The certificate was issued by the trusted CA.\r
2061 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
2062 trusted CA.\r
2063 @retval FALSE This interface is not supported.\r
2064\r
2065**/\r
2066BOOLEAN\r
2067EFIAPI\r
2068X509VerifyCert (\r
2069 IN CONST UINT8 *Cert,\r
2070 IN UINTN CertSize,\r
2071 IN CONST UINT8 *CACert,\r
2072 IN UINTN CACertSize\r
2073 )\r
2074{\r
2075 CALL_CRYPTO_SERVICE (X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);\r
2076}\r
2077\r
2078/**\r
2079 Construct a X509 object from DER-encoded certificate data.\r
2080\r
2081 If Cert is NULL, then return FALSE.\r
2082 If SingleX509Cert is NULL, then return FALSE.\r
2083 If this interface is not supported, then return FALSE.\r
2084\r
2085 @param[in] Cert Pointer to the DER-encoded certificate data.\r
2086 @param[in] CertSize The size of certificate data in bytes.\r
2087 @param[out] SingleX509Cert The generated X509 object.\r
2088\r
2089 @retval TRUE The X509 object generation succeeded.\r
2090 @retval FALSE The operation failed.\r
2091 @retval FALSE This interface is not supported.\r
2092\r
2093**/\r
2094BOOLEAN\r
2095EFIAPI\r
2096X509ConstructCertificate (\r
2097 IN CONST UINT8 *Cert,\r
2098 IN UINTN CertSize,\r
2099 OUT UINT8 **SingleX509Cert\r
2100 )\r
2101{\r
2102 CALL_CRYPTO_SERVICE (X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);\r
2103}\r
2104\r
2105/**\r
2106 Construct a X509 stack object from a list of DER-encoded certificate data.\r
2107\r
2108 If X509Stack is NULL, then return FALSE.\r
2109 If this interface is not supported, then return FALSE.\r
2110\r
2111 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
2112 On output, pointer to the X509 stack object with new\r
2113 inserted X509 certificate.\r
2114 @param[in] Args VA_LIST marker for the variable argument list.\r
2115 ... A list of DER-encoded single certificate data followed\r
2116 by certificate size. A NULL terminates the list. The\r
2117 pairs are the arguments to X509ConstructCertificate().\r
2118\r
2119 @retval TRUE The X509 stack construction succeeded.\r
2120 @retval FALSE The construction operation failed.\r
2121 @retval FALSE This interface is not supported.\r
2122\r
2123**/\r
2124BOOLEAN\r
2125EFIAPI\r
2126X509ConstructCertificateStack (\r
2127 IN OUT UINT8 **X509Stack,\r
2128 ...\r
2129 )\r
2130{\r
2131 VA_LIST Args;\r
2132 BOOLEAN Result;\r
2133\r
2134 VA_START (Args, X509Stack);\r
2135 Result = X509ConstructCertificateStackV (X509Stack, Args);\r
2136 VA_END (Args);\r
2137 return Result;\r
2138}\r
2139\r
2140/**\r
2141 Construct a X509 stack object from a list of DER-encoded certificate data.\r
2142\r
2143 If X509Stack is NULL, then return FALSE.\r
2144 If this interface is not supported, then return FALSE.\r
2145\r
2146 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
2147 On output, pointer to the X509 stack object with new\r
2148 inserted X509 certificate.\r
2149 @param[in] Args VA_LIST marker for the variable argument list.\r
2150 A list of DER-encoded single certificate data followed\r
2151 by certificate size. A NULL terminates the list. The\r
2152 pairs are the arguments to X509ConstructCertificate().\r
2153\r
2154 @retval TRUE The X509 stack construction succeeded.\r
2155 @retval FALSE The construction operation failed.\r
2156 @retval FALSE This interface is not supported.\r
2157\r
2158**/\r
2159BOOLEAN\r
2160EFIAPI\r
2161X509ConstructCertificateStackV (\r
2162 IN OUT UINT8 **X509Stack,\r
2163 IN VA_LIST Args\r
2164 )\r
2165{\r
2166 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV, (X509Stack, Args), FALSE);\r
2167}\r
2168\r
2169/**\r
2170 Release the specified X509 object.\r
2171\r
2172 If the interface is not supported, then ASSERT().\r
2173\r
2174 @param[in] X509Cert Pointer to the X509 object to be released.\r
2175\r
2176**/\r
2177VOID\r
2178EFIAPI\r
2179X509Free (\r
2180 IN VOID *X509Cert\r
2181 )\r
2182{\r
2183 CALL_VOID_CRYPTO_SERVICE (X509Free, (X509Cert));\r
2184}\r
2185\r
2186/**\r
2187 Release the specified X509 stack object.\r
2188\r
2189 If the interface is not supported, then ASSERT().\r
2190\r
2191 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
2192\r
2193**/\r
2194VOID\r
2195EFIAPI\r
2196X509StackFree (\r
2197 IN VOID *X509Stack\r
2198 )\r
2199{\r
2200 CALL_VOID_CRYPTO_SERVICE (X509StackFree, (X509Stack));\r
2201}\r
2202\r
2203/**\r
2204 Retrieve the TBSCertificate from one given X.509 certificate.\r
2205\r
2206 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
2207 @param[in] CertSize Size of the X509 certificate in bytes.\r
2208 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
2209 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
2210\r
2211 If Cert is NULL, then return FALSE.\r
2212 If TBSCert is NULL, then return FALSE.\r
2213 If TBSCertSize is NULL, then return FALSE.\r
2214 If this interface is not supported, then return FALSE.\r
2215\r
2216 @retval TRUE The TBSCertificate was retrieved successfully.\r
2217 @retval FALSE Invalid X.509 certificate.\r
2218\r
2219**/\r
2220BOOLEAN\r
2221EFIAPI\r
2222X509GetTBSCert (\r
2223 IN CONST UINT8 *Cert,\r
2224 IN UINTN CertSize,\r
2225 OUT UINT8 **TBSCert,\r
2226 OUT UINTN *TBSCertSize\r
2227 )\r
2228{\r
2229 CALL_CRYPTO_SERVICE (X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);\r
2230}\r
2231\r
2232/**\r
2233 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
2234 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
2235\r
2236 If Password or Salt or OutKey is NULL, then return FALSE.\r
2237 If the hash algorithm could not be determined, then return FALSE.\r
2238 If this interface is not supported, then return FALSE.\r
2239\r
2240 @param[in] PasswordLength Length of input password in bytes.\r
2241 @param[in] Password Pointer to the array for the password.\r
2242 @param[in] SaltLength Size of the Salt in bytes.\r
2243 @param[in] Salt Pointer to the Salt.\r
2244 @param[in] IterationCount Number of iterations to perform. Its value should be\r
2245 greater than or equal to 1.\r
2246 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
2247 NOTE: DigestSize will be used to determine the hash algorithm.\r
2248 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
2249 @param[in] KeyLength Size of the derived key buffer in bytes.\r
2250 @param[out] OutKey Pointer to the output derived key buffer.\r
2251\r
2252 @retval TRUE A key was derived successfully.\r
2253 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
2254 @retval FALSE The hash algorithm could not be determined from the digest size.\r
2255 @retval FALSE The key derivation operation failed.\r
2256 @retval FALSE This interface is not supported.\r
2257\r
2258**/\r
2259BOOLEAN\r
2260EFIAPI\r
2261Pkcs5HashPassword (\r
2262 IN UINTN PasswordLength,\r
2263 IN CONST CHAR8 *Password,\r
2264 IN UINTN SaltLength,\r
2265 IN CONST UINT8 *Salt,\r
2266 IN UINTN IterationCount,\r
2267 IN UINTN DigestSize,\r
2268 IN UINTN KeyLength,\r
2269 OUT UINT8 *OutKey\r
2270 )\r
2271{\r
2272 CALL_CRYPTO_SERVICE (Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);\r
2273}\r
2274\r
2275/**\r
2276 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
2277 encrypted message in a newly allocated buffer.\r
2278\r
2279 Things that can cause a failure include:\r
2280 - X509 key size does not match any known key size.\r
2281 - Fail to parse X509 certificate.\r
2282 - Fail to allocate an intermediate buffer.\r
2283 - Null pointer provided for a non-optional parameter.\r
2284 - Data size is too large for the provided key size (max size is a function of key size\r
2285 and hash digest size).\r
2286\r
2287 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
2288 will be used to encrypt the data.\r
2289 @param[in] PublicKeySize Size of the X509 cert buffer.\r
2290 @param[in] InData Data to be encrypted.\r
2291 @param[in] InDataSize Size of the data buffer.\r
2292 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
2293 to be used when initializing the PRNG. NULL otherwise.\r
2294 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
2295 0 otherwise.\r
2296 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
2297 message.\r
2298 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
2299\r
2300 @retval TRUE Encryption was successful.\r
2301 @retval FALSE Encryption failed.\r
2302\r
2303**/\r
2304BOOLEAN\r
2305EFIAPI\r
2306Pkcs1v2Encrypt (\r
2307 IN CONST UINT8 *PublicKey,\r
2308 IN UINTN PublicKeySize,\r
2309 IN UINT8 *InData,\r
2310 IN UINTN InDataSize,\r
c8f46130
MK
2311 IN CONST UINT8 *PrngSeed OPTIONAL,\r
2312 IN UINTN PrngSeedSize OPTIONAL,\r
cd70de1c
MK
2313 OUT UINT8 **EncryptedData,\r
2314 OUT UINTN *EncryptedDataSize\r
2315 )\r
2316{\r
2317 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);\r
2318}\r
2319\r
2320/**\r
2321 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
2322 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2323 in a ContentInfo structure.\r
2324\r
2325 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
2326 return FALSE. If P7Length overflow, then return FALSE.\r
2327 If this interface is not supported, then return FALSE.\r
2328\r
2329 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2330 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2331 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
2332 It's caller's responsibility to free the buffer with\r
2333 Pkcs7FreeSigners().\r
2334 This data structure is EFI_CERT_STACK type.\r
2335 @param[out] StackLength Length of signer's certificates in bytes.\r
2336 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
2337 It's caller's responsibility to free the buffer with\r
2338 Pkcs7FreeSigners().\r
2339 @param[out] CertLength Length of the trusted certificate in bytes.\r
2340\r
2341 @retval TRUE The operation is finished successfully.\r
2342 @retval FALSE Error occurs during the operation.\r
2343 @retval FALSE This interface is not supported.\r
2344\r
2345**/\r
2346BOOLEAN\r
2347EFIAPI\r
2348Pkcs7GetSigners (\r
2349 IN CONST UINT8 *P7Data,\r
2350 IN UINTN P7Length,\r
2351 OUT UINT8 **CertStack,\r
2352 OUT UINTN *StackLength,\r
2353 OUT UINT8 **TrustedCert,\r
2354 OUT UINTN *CertLength\r
2355 )\r
2356{\r
2357 CALL_CRYPTO_SERVICE (Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);\r
2358}\r
2359\r
2360/**\r
2361 Wrap function to use free() to free allocated memory for certificates.\r
2362\r
2363 If this interface is not supported, then ASSERT().\r
2364\r
2365 @param[in] Certs Pointer to the certificates to be freed.\r
2366\r
2367**/\r
2368VOID\r
2369EFIAPI\r
2370Pkcs7FreeSigners (\r
7c342378 2371 IN UINT8 *Certs\r
cd70de1c
MK
2372 )\r
2373{\r
2374 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners, (Certs));\r
2375}\r
2376\r
2377/**\r
2378 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
2379 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
2380 unchained to the signer's certificates.\r
2381 The input signed data could be wrapped in a ContentInfo structure.\r
2382\r
2383 @param[in] P7Data Pointer to the PKCS#7 message.\r
2384 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2385 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
2386 certificate. It's caller's responsibility to free the buffer\r
2387 with Pkcs7FreeSigners().\r
2388 This data structure is EFI_CERT_STACK type.\r
2389 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
2390 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
2391 responsibility to free the buffer with Pkcs7FreeSigners().\r
2392 This data structure is EFI_CERT_STACK type.\r
2393 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
2394\r
2395 @retval TRUE The operation is finished successfully.\r
2396 @retval FALSE Error occurs during the operation.\r
2397\r
2398**/\r
2399BOOLEAN\r
2400EFIAPI\r
2401Pkcs7GetCertificatesList (\r
2402 IN CONST UINT8 *P7Data,\r
2403 IN UINTN P7Length,\r
2404 OUT UINT8 **SignerChainCerts,\r
2405 OUT UINTN *ChainLength,\r
2406 OUT UINT8 **UnchainCerts,\r
2407 OUT UINTN *UnchainLength\r
2408 )\r
2409{\r
2410 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);\r
2411}\r
2412\r
2413/**\r
2414 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
2415 Syntax Standard, version 1.5". This interface is only intended to be used for\r
2416 application to perform PKCS#7 functionality validation.\r
2417\r
2418 If this interface is not supported, then return FALSE.\r
2419\r
2420 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
2421 data signing.\r
2422 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
2423 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
2424 key data.\r
2425 @param[in] InData Pointer to the content to be signed.\r
2426 @param[in] InDataSize Size of InData in bytes.\r
2427 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
2428 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
2429 include in the PKCS#7 signedData (e.g. any intermediate\r
2430 CAs in the chain).\r
2431 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
2432 responsibility to free the buffer with FreePool().\r
2433 @param[out] SignedDataSize Size of SignedData in bytes.\r
2434\r
2435 @retval TRUE PKCS#7 data signing succeeded.\r
2436 @retval FALSE PKCS#7 data signing failed.\r
2437 @retval FALSE This interface is not supported.\r
2438\r
2439**/\r
2440BOOLEAN\r
2441EFIAPI\r
2442Pkcs7Sign (\r
2443 IN CONST UINT8 *PrivateKey,\r
2444 IN UINTN PrivateKeySize,\r
2445 IN CONST UINT8 *KeyPassword,\r
2446 IN UINT8 *InData,\r
2447 IN UINTN InDataSize,\r
2448 IN UINT8 *SignCert,\r
2449 IN UINT8 *OtherCerts OPTIONAL,\r
2450 OUT UINT8 **SignedData,\r
2451 OUT UINTN *SignedDataSize\r
2452 )\r
2453{\r
2454 CALL_CRYPTO_SERVICE (Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);\r
2455}\r
2456\r
2457/**\r
2458 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
2459 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2460 in a ContentInfo structure.\r
2461\r
2462 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
2463 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
2464 If this interface is not supported, then return FALSE.\r
2465\r
2466 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2467 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2468 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2469 is used for certificate chain verification.\r
2470 @param[in] CertLength Length of the trusted certificate in bytes.\r
2471 @param[in] InData Pointer to the content to be verified.\r
2472 @param[in] DataLength Length of InData in bytes.\r
2473\r
2474 @retval TRUE The specified PKCS#7 signed data is valid.\r
2475 @retval FALSE Invalid PKCS#7 signed data.\r
2476 @retval FALSE This interface is not supported.\r
2477\r
2478**/\r
2479BOOLEAN\r
2480EFIAPI\r
2481Pkcs7Verify (\r
2482 IN CONST UINT8 *P7Data,\r
2483 IN UINTN P7Length,\r
2484 IN CONST UINT8 *TrustedCert,\r
2485 IN UINTN CertLength,\r
2486 IN CONST UINT8 *InData,\r
2487 IN UINTN DataLength\r
2488 )\r
2489{\r
2490 CALL_CRYPTO_SERVICE (Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);\r
2491}\r
2492\r
2493/**\r
2494 This function receives a PKCS7 formatted signature, and then verifies that\r
2495 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
2496 leaf signing certificate.\r
2497 Note that this function does not validate the certificate chain.\r
2498\r
2499 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
2500 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
2501 certificate issued might also contain this EKU, thus constraining the\r
2502 sub-ordinate certificate. Other applications might allow a certificate\r
2503 embedded in a device to specify that other Object Identifiers (OIDs) are\r
2504 present which contains binary data specifying custom capabilities that\r
2505 the device is able to do.\r
2506\r
2507 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
2508 containing the content block with both the signature,\r
2509 the signer's certificate, and any necessary intermediate\r
2510 certificates.\r
2511 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
2512 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
2513 required EKUs that must be present in the signature.\r
2514 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
2515 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
2516 must be present in the leaf signer. If it is\r
2517 FALSE, then we will succeed if we find any\r
2518 of the specified EKU's.\r
2519\r
2520 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
2521 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
2522 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
2523\r
2524**/\r
2525RETURN_STATUS\r
2526EFIAPI\r
2527VerifyEKUsInPkcs7Signature (\r
2528 IN CONST UINT8 *Pkcs7Signature,\r
2529 IN CONST UINT32 SignatureSize,\r
2530 IN CONST CHAR8 *RequiredEKUs[],\r
2531 IN CONST UINT32 RequiredEKUsSize,\r
2532 IN BOOLEAN RequireAllPresent\r
2533 )\r
2534{\r
2535 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);\r
2536}\r
2537\r
cd70de1c
MK
2538/**\r
2539 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
2540 data could be wrapped in a ContentInfo structure.\r
2541\r
2542 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
2543 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
2544\r
2545 Caution: This function may receive untrusted input. So this function will do\r
2546 basic check for PKCS#7 data structure.\r
2547\r
2548 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
2549 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
2550 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
2551 It's caller's responsibility to free the buffer with FreePool().\r
2552 @param[out] ContentSize The size of the extracted content in bytes.\r
2553\r
2554 @retval TRUE The P7Data was correctly formatted for processing.\r
2555 @retval FALSE The P7Data was not correctly formatted for processing.\r
2556\r
2557**/\r
2558BOOLEAN\r
2559EFIAPI\r
2560Pkcs7GetAttachedContent (\r
2561 IN CONST UINT8 *P7Data,\r
2562 IN UINTN P7Length,\r
2563 OUT VOID **Content,\r
2564 OUT UINTN *ContentSize\r
2565 )\r
2566{\r
2567 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);\r
2568}\r
2569\r
2570/**\r
2571 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
2572 Authenticode Portable Executable Signature Format".\r
2573\r
2574 If AuthData is NULL, then return FALSE.\r
2575 If ImageHash is NULL, then return FALSE.\r
2576 If this interface is not supported, then return FALSE.\r
2577\r
2578 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2579 PE/COFF image to be verified.\r
2580 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2581 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2582 is used for certificate chain verification.\r
2583 @param[in] CertSize Size of the trusted certificate in bytes.\r
2584 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
2585 for calculating the image hash value is described in Authenticode\r
2586 specification.\r
2587 @param[in] HashSize Size of Image hash value in bytes.\r
2588\r
2589 @retval TRUE The specified Authenticode Signature is valid.\r
2590 @retval FALSE Invalid Authenticode Signature.\r
2591 @retval FALSE This interface is not supported.\r
2592\r
2593**/\r
2594BOOLEAN\r
2595EFIAPI\r
2596AuthenticodeVerify (\r
2597 IN CONST UINT8 *AuthData,\r
2598 IN UINTN DataSize,\r
2599 IN CONST UINT8 *TrustedCert,\r
2600 IN UINTN CertSize,\r
2601 IN CONST UINT8 *ImageHash,\r
2602 IN UINTN HashSize\r
2603 )\r
2604{\r
2605 CALL_CRYPTO_SERVICE (AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);\r
2606}\r
2607\r
2608/**\r
2609 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
2610 signature.\r
2611\r
2612 If AuthData is NULL, then return FALSE.\r
2613 If this interface is not supported, then return FALSE.\r
2614\r
2615 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2616 PE/COFF image to be verified.\r
2617 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2618 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
2619 is used for TSA certificate chain verification.\r
2620 @param[in] CertSize Size of the trusted certificate in bytes.\r
2621 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
2622 signature is valid.\r
2623\r
2624 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
2625 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
2626\r
2627**/\r
2628BOOLEAN\r
2629EFIAPI\r
2630ImageTimestampVerify (\r
2631 IN CONST UINT8 *AuthData,\r
2632 IN UINTN DataSize,\r
2633 IN CONST UINT8 *TsaCert,\r
2634 IN UINTN CertSize,\r
2635 OUT EFI_TIME *SigningTime\r
2636 )\r
2637{\r
2638 CALL_CRYPTO_SERVICE (ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);\r
2639}\r
2640\r
7c342378 2641// =====================================================================================\r
cd70de1c 2642// DH Key Exchange Primitive\r
7c342378 2643// =====================================================================================\r
cd70de1c
MK
2644\r
2645/**\r
2646 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
2647\r
2648 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
2649 If the allocations fails, DhNew() returns NULL.\r
2650 If the interface is not supported, DhNew() returns NULL.\r
2651\r
2652**/\r
2653VOID *\r
2654EFIAPI\r
2655DhNew (\r
2656 VOID\r
2657 )\r
2658{\r
2659 CALL_CRYPTO_SERVICE (DhNew, (), NULL);\r
2660}\r
2661\r
2662/**\r
2663 Release the specified DH context.\r
2664\r
2665 If the interface is not supported, then ASSERT().\r
2666\r
2667 @param[in] DhContext Pointer to the DH context to be released.\r
2668\r
2669**/\r
2670VOID\r
2671EFIAPI\r
2672DhFree (\r
2673 IN VOID *DhContext\r
2674 )\r
2675{\r
2676 CALL_VOID_CRYPTO_SERVICE (DhFree, (DhContext));\r
2677}\r
2678\r
2679/**\r
2680 Generates DH parameter.\r
2681\r
2682 Given generator g, and length of prime number p in bits, this function generates p,\r
2683 and sets DH context according to value of g and p.\r
2684\r
2685 Before this function can be invoked, pseudorandom number generator must be correctly\r
2686 initialized by RandomSeed().\r
2687\r
2688 If DhContext is NULL, then return FALSE.\r
2689 If Prime is NULL, then return FALSE.\r
2690 If this interface is not supported, then return FALSE.\r
2691\r
2692 @param[in, out] DhContext Pointer to the DH context.\r
2693 @param[in] Generator Value of generator.\r
2694 @param[in] PrimeLength Length in bits of prime to be generated.\r
2695 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
2696\r
2697 @retval TRUE DH parameter generation succeeded.\r
2698 @retval FALSE Value of Generator is not supported.\r
2699 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
2700 @retval FALSE This interface is not supported.\r
2701\r
2702**/\r
2703BOOLEAN\r
2704EFIAPI\r
2705DhGenerateParameter (\r
2706 IN OUT VOID *DhContext,\r
2707 IN UINTN Generator,\r
2708 IN UINTN PrimeLength,\r
2709 OUT UINT8 *Prime\r
2710 )\r
2711{\r
2712 CALL_CRYPTO_SERVICE (DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
2713}\r
2714\r
2715/**\r
2716 Sets generator and prime parameters for DH.\r
2717\r
2718 Given generator g, and prime number p, this function and sets DH\r
2719 context accordingly.\r
2720\r
2721 If DhContext is NULL, then return FALSE.\r
2722 If Prime is NULL, then return FALSE.\r
2723 If this interface is not supported, then return FALSE.\r
2724\r
2725 @param[in, out] DhContext Pointer to the DH context.\r
2726 @param[in] Generator Value of generator.\r
2727 @param[in] PrimeLength Length in bits of prime to be generated.\r
2728 @param[in] Prime Pointer to the prime number.\r
2729\r
2730 @retval TRUE DH parameter setting succeeded.\r
2731 @retval FALSE Value of Generator is not supported.\r
2732 @retval FALSE Value of Generator is not suitable for the Prime.\r
2733 @retval FALSE Value of Prime is not a prime number.\r
2734 @retval FALSE Value of Prime is not a safe prime number.\r
2735 @retval FALSE This interface is not supported.\r
2736\r
2737**/\r
2738BOOLEAN\r
2739EFIAPI\r
2740DhSetParameter (\r
2741 IN OUT VOID *DhContext,\r
2742 IN UINTN Generator,\r
2743 IN UINTN PrimeLength,\r
2744 IN CONST UINT8 *Prime\r
2745 )\r
2746{\r
2747 CALL_CRYPTO_SERVICE (DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
2748}\r
2749\r
2750/**\r
2751 Generates DH public key.\r
2752\r
2753 This function generates random secret exponent, and computes the public key, which is\r
2754 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
2755 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
2756 PublicKeySize is set to the required buffer size to obtain the public key.\r
2757\r
2758 If DhContext is NULL, then return FALSE.\r
2759 If PublicKeySize is NULL, then return FALSE.\r
2760 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
2761 If this interface is not supported, then return FALSE.\r
2762\r
2763 @param[in, out] DhContext Pointer to the DH context.\r
2764 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
2765 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
2766 On output, the size of data returned in PublicKey buffer in bytes.\r
2767\r
2768 @retval TRUE DH public key generation succeeded.\r
2769 @retval FALSE DH public key generation failed.\r
2770 @retval FALSE PublicKeySize is not large enough.\r
2771 @retval FALSE This interface is not supported.\r
2772\r
2773**/\r
2774BOOLEAN\r
2775EFIAPI\r
2776DhGenerateKey (\r
2777 IN OUT VOID *DhContext,\r
2778 OUT UINT8 *PublicKey,\r
2779 IN OUT UINTN *PublicKeySize\r
2780 )\r
2781{\r
2782 CALL_CRYPTO_SERVICE (DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);\r
2783}\r
2784\r
2785/**\r
2786 Computes exchanged common key.\r
2787\r
2788 Given peer's public key, this function computes the exchanged common key, based on its own\r
2789 context including value of prime modulus and random secret exponent.\r
2790\r
2791 If DhContext is NULL, then return FALSE.\r
2792 If PeerPublicKey is NULL, then return FALSE.\r
2793 If KeySize is NULL, then return FALSE.\r
2794 If Key is NULL, then return FALSE.\r
2795 If KeySize is not large enough, then return FALSE.\r
2796 If this interface is not supported, then return FALSE.\r
2797\r
2798 @param[in, out] DhContext Pointer to the DH context.\r
2799 @param[in] PeerPublicKey Pointer to the peer's public key.\r
2800 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
2801 @param[out] Key Pointer to the buffer to receive generated key.\r
2802 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
2803 On output, the size of data returned in Key buffer in bytes.\r
2804\r
2805 @retval TRUE DH exchanged key generation succeeded.\r
2806 @retval FALSE DH exchanged key generation failed.\r
2807 @retval FALSE KeySize is not large enough.\r
2808 @retval FALSE This interface is not supported.\r
2809\r
2810**/\r
2811BOOLEAN\r
2812EFIAPI\r
2813DhComputeKey (\r
2814 IN OUT VOID *DhContext,\r
2815 IN CONST UINT8 *PeerPublicKey,\r
2816 IN UINTN PeerPublicKeySize,\r
2817 OUT UINT8 *Key,\r
2818 IN OUT UINTN *KeySize\r
2819 )\r
2820{\r
2821 CALL_CRYPTO_SERVICE (DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);\r
2822}\r
2823\r
7c342378 2824// =====================================================================================\r
cd70de1c 2825// Pseudo-Random Generation Primitive\r
7c342378 2826// =====================================================================================\r
cd70de1c
MK
2827\r
2828/**\r
2829 Sets up the seed value for the pseudorandom number generator.\r
2830\r
2831 This function sets up the seed value for the pseudorandom number generator.\r
2832 If Seed is not NULL, then the seed passed in is used.\r
2833 If Seed is NULL, then default seed is used.\r
2834 If this interface is not supported, then return FALSE.\r
2835\r
2836 @param[in] Seed Pointer to seed value.\r
2837 If NULL, default seed is used.\r
2838 @param[in] SeedSize Size of seed value.\r
2839 If Seed is NULL, this parameter is ignored.\r
2840\r
2841 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
2842 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
2843 @retval FALSE This interface is not supported.\r
2844\r
2845**/\r
2846BOOLEAN\r
2847EFIAPI\r
2848RandomSeed (\r
2849 IN CONST UINT8 *Seed OPTIONAL,\r
2850 IN UINTN SeedSize\r
2851 )\r
2852{\r
2853 CALL_CRYPTO_SERVICE (RandomSeed, (Seed, SeedSize), FALSE);\r
2854}\r
2855\r
2856/**\r
2857 Generates a pseudorandom byte stream of the specified size.\r
2858\r
2859 If Output is NULL, then return FALSE.\r
2860 If this interface is not supported, then return FALSE.\r
2861\r
2862 @param[out] Output Pointer to buffer to receive random value.\r
2863 @param[in] Size Size of random bytes to generate.\r
2864\r
2865 @retval TRUE Pseudorandom byte stream generated successfully.\r
2866 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
2867 @retval FALSE This interface is not supported.\r
2868\r
2869**/\r
2870BOOLEAN\r
2871EFIAPI\r
2872RandomBytes (\r
2873 OUT UINT8 *Output,\r
2874 IN UINTN Size\r
2875 )\r
2876{\r
2877 CALL_CRYPTO_SERVICE (RandomBytes, (Output, Size), FALSE);\r
2878}\r
2879\r
7c342378 2880// =====================================================================================\r
cd70de1c 2881// Key Derivation Function Primitive\r
7c342378 2882// =====================================================================================\r
cd70de1c
MK
2883\r
2884/**\r
2885 Derive key data using HMAC-SHA256 based KDF.\r
2886\r
2887 @param[in] Key Pointer to the user-supplied key.\r
2888 @param[in] KeySize Key size in bytes.\r
2889 @param[in] Salt Pointer to the salt(non-secret) value.\r
2890 @param[in] SaltSize Salt size in bytes.\r
2891 @param[in] Info Pointer to the application specific info.\r
2892 @param[in] InfoSize Info size in bytes.\r
2893 @param[out] Out Pointer to buffer to receive hkdf value.\r
2894 @param[in] OutSize Size of hkdf bytes to generate.\r
2895\r
2896 @retval TRUE Hkdf generated successfully.\r
2897 @retval FALSE Hkdf generation failed.\r
2898\r
2899**/\r
2900BOOLEAN\r
2901EFIAPI\r
2902HkdfSha256ExtractAndExpand (\r
2903 IN CONST UINT8 *Key,\r
2904 IN UINTN KeySize,\r
2905 IN CONST UINT8 *Salt,\r
2906 IN UINTN SaltSize,\r
2907 IN CONST UINT8 *Info,\r
2908 IN UINTN InfoSize,\r
2909 OUT UINT8 *Out,\r
2910 IN UINTN OutSize\r
2911 )\r
2912{\r
2913 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);\r
2914}\r
2915\r
2916/**\r
2917 Initializes the OpenSSL library.\r
2918\r
2919 This function registers ciphers and digests used directly and indirectly\r
2920 by SSL/TLS, and initializes the readable error messages.\r
2921 This function must be called before any other action takes places.\r
2922\r
2923 @retval TRUE The OpenSSL library has been initialized.\r
2924 @retval FALSE Failed to initialize the OpenSSL library.\r
2925\r
2926**/\r
2927BOOLEAN\r
2928EFIAPI\r
2929TlsInitialize (\r
2930 VOID\r
2931 )\r
2932{\r
2933 CALL_CRYPTO_SERVICE (TlsInitialize, (), FALSE);\r
2934}\r
2935\r
2936/**\r
2937 Free an allocated SSL_CTX object.\r
2938\r
2939 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.\r
2940\r
2941**/\r
2942VOID\r
2943EFIAPI\r
2944TlsCtxFree (\r
7c342378 2945 IN VOID *TlsCtx\r
cd70de1c
MK
2946 )\r
2947{\r
2948 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree, (TlsCtx));\r
2949}\r
2950\r
2951/**\r
2952 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled\r
2953 connections.\r
2954\r
2955 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
2956 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
2957\r
2958 @return Pointer to an allocated SSL_CTX object.\r
2959 If the creation failed, TlsCtxNew() returns NULL.\r
2960\r
2961**/\r
2962VOID *\r
2963EFIAPI\r
2964TlsCtxNew (\r
7c342378
MK
2965 IN UINT8 MajorVer,\r
2966 IN UINT8 MinorVer\r
cd70de1c
MK
2967 )\r
2968{\r
2969 CALL_CRYPTO_SERVICE (TlsCtxNew, (MajorVer, MinorVer), NULL);\r
2970}\r
2971\r
2972/**\r
2973 Free an allocated TLS object.\r
2974\r
2975 This function removes the TLS object pointed to by Tls and frees up the\r
2976 allocated memory. If Tls is NULL, nothing is done.\r
2977\r
2978 @param[in] Tls Pointer to the TLS object to be freed.\r
2979\r
2980**/\r
2981VOID\r
2982EFIAPI\r
2983TlsFree (\r
7c342378 2984 IN VOID *Tls\r
cd70de1c
MK
2985 )\r
2986{\r
2987 CALL_VOID_CRYPTO_SERVICE (TlsFree, (Tls));\r
2988}\r
2989\r
2990/**\r
2991 Create a new TLS object for a connection.\r
2992\r
2993 This function creates a new TLS object for a connection. The new object\r
2994 inherits the setting of the underlying context TlsCtx: connection method,\r
2995 options, verification setting.\r
2996\r
2997 @param[in] TlsCtx Pointer to the SSL_CTX object.\r
2998\r
2999 @return Pointer to an allocated SSL object.\r
3000 If the creation failed, TlsNew() returns NULL.\r
3001\r
3002**/\r
3003VOID *\r
3004EFIAPI\r
3005TlsNew (\r
7c342378 3006 IN VOID *TlsCtx\r
cd70de1c
MK
3007 )\r
3008{\r
3009 CALL_CRYPTO_SERVICE (TlsNew, (TlsCtx), NULL);\r
3010}\r
3011\r
3012/**\r
3013 Checks if the TLS handshake was done.\r
3014\r
3015 This function will check if the specified TLS handshake was done.\r
3016\r
3017 @param[in] Tls Pointer to the TLS object for handshake state checking.\r
3018\r
3019 @retval TRUE The TLS handshake was done.\r
3020 @retval FALSE The TLS handshake was not done.\r
3021\r
3022**/\r
3023BOOLEAN\r
3024EFIAPI\r
3025TlsInHandshake (\r
7c342378 3026 IN VOID *Tls\r
cd70de1c
MK
3027 )\r
3028{\r
3029 CALL_CRYPTO_SERVICE (TlsInHandshake, (Tls), FALSE);\r
3030}\r
3031\r
3032/**\r
3033 Perform a TLS/SSL handshake.\r
3034\r
3035 This function will perform a TLS/SSL handshake.\r
3036\r
3037 @param[in] Tls Pointer to the TLS object for handshake operation.\r
3038 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.\r
3039 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
3040 Handshake packet.\r
3041 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
3042 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
3043 the buffer size provided by the caller. On output, it\r
3044 is the buffer size in fact needed to contain the\r
3045 packet.\r
3046\r
3047 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
3048 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
3049 Tls is NULL.\r
3050 BufferIn is NULL but BufferInSize is NOT 0.\r
3051 BufferInSize is 0 but BufferIn is NOT NULL.\r
3052 BufferOutSize is NULL.\r
3053 BufferOut is NULL if *BufferOutSize is not zero.\r
3054 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
3055 @retval EFI_ABORTED Something wrong during handshake.\r
3056\r
3057**/\r
3058EFI_STATUS\r
3059EFIAPI\r
3060TlsDoHandshake (\r
7c342378
MK
3061 IN VOID *Tls,\r
3062 IN UINT8 *BufferIn OPTIONAL,\r
3063 IN UINTN BufferInSize OPTIONAL,\r
3064 OUT UINT8 *BufferOut OPTIONAL,\r
3065 IN OUT UINTN *BufferOutSize\r
cd70de1c
MK
3066 )\r
3067{\r
3068 CALL_CRYPTO_SERVICE (TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
3069}\r
3070\r
3071/**\r
3072 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,\r
3073 TLS session has errors and the response packet needs to be Alert message based on error type.\r
3074\r
3075 @param[in] Tls Pointer to the TLS object for state checking.\r
3076 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.\r
3077 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
3078 Alert packet.\r
3079 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
3080 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
3081 the buffer size provided by the caller. On output, it\r
3082 is the buffer size in fact needed to contain the\r
3083 packet.\r
3084\r
3085 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
3086 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
3087 Tls is NULL.\r
3088 BufferIn is NULL but BufferInSize is NOT 0.\r
3089 BufferInSize is 0 but BufferIn is NOT NULL.\r
3090 BufferOutSize is NULL.\r
3091 BufferOut is NULL if *BufferOutSize is not zero.\r
3092 @retval EFI_ABORTED An error occurred.\r
3093 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
3094\r
3095**/\r
3096EFI_STATUS\r
3097EFIAPI\r
3098TlsHandleAlert (\r
7c342378
MK
3099 IN VOID *Tls,\r
3100 IN UINT8 *BufferIn OPTIONAL,\r
3101 IN UINTN BufferInSize OPTIONAL,\r
3102 OUT UINT8 *BufferOut OPTIONAL,\r
3103 IN OUT UINTN *BufferOutSize\r
cd70de1c
MK
3104 )\r
3105{\r
3106 CALL_CRYPTO_SERVICE (TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
3107}\r
3108\r
3109/**\r
3110 Build the CloseNotify packet.\r
3111\r
3112 @param[in] Tls Pointer to the TLS object for state checking.\r
3113 @param[in, out] Buffer Pointer to the buffer to hold the built packet.\r
3114 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is\r
3115 the buffer size provided by the caller. On output, it\r
3116 is the buffer size in fact needed to contain the\r
3117 packet.\r
3118\r
3119 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
3120 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
3121 Tls is NULL.\r
3122 BufferSize is NULL.\r
3123 Buffer is NULL if *BufferSize is not zero.\r
3124 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.\r
3125\r
3126**/\r
3127EFI_STATUS\r
3128EFIAPI\r
3129TlsCloseNotify (\r
7c342378
MK
3130 IN VOID *Tls,\r
3131 IN OUT UINT8 *Buffer,\r
3132 IN OUT UINTN *BufferSize\r
cd70de1c
MK
3133 )\r
3134{\r
3135 CALL_CRYPTO_SERVICE (TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);\r
3136}\r
3137\r
3138/**\r
3139 Attempts to read bytes from one TLS object and places the data in Buffer.\r
3140\r
3141 This function will attempt to read BufferSize bytes from the TLS object\r
3142 and places the data in Buffer.\r
3143\r
3144 @param[in] Tls Pointer to the TLS object.\r
3145 @param[in,out] Buffer Pointer to the buffer to store the data.\r
3146 @param[in] BufferSize The size of Buffer in bytes.\r
3147\r
3148 @retval >0 The amount of data successfully read from the TLS object.\r
3149 @retval <=0 No data was successfully read.\r
3150\r
3151**/\r
3152INTN\r
3153EFIAPI\r
3154TlsCtrlTrafficOut (\r
7c342378
MK
3155 IN VOID *Tls,\r
3156 IN OUT VOID *Buffer,\r
3157 IN UINTN BufferSize\r
cd70de1c
MK
3158 )\r
3159{\r
3160 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);\r
3161}\r
3162\r
3163/**\r
3164 Attempts to write data from the buffer to TLS object.\r
3165\r
3166 This function will attempt to write BufferSize bytes data from the Buffer\r
3167 to the TLS object.\r
3168\r
3169 @param[in] Tls Pointer to the TLS object.\r
3170 @param[in] Buffer Pointer to the data buffer.\r
3171 @param[in] BufferSize The size of Buffer in bytes.\r
3172\r
3173 @retval >0 The amount of data successfully written to the TLS object.\r
3174 @retval <=0 No data was successfully written.\r
3175\r
3176**/\r
3177INTN\r
3178EFIAPI\r
3179TlsCtrlTrafficIn (\r
7c342378
MK
3180 IN VOID *Tls,\r
3181 IN VOID *Buffer,\r
3182 IN UINTN BufferSize\r
cd70de1c
MK
3183 )\r
3184{\r
3185 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);\r
3186}\r
3187\r
3188/**\r
3189 Attempts to read bytes from the specified TLS connection into the buffer.\r
3190\r
3191 This function tries to read BufferSize bytes data from the specified TLS\r
3192 connection into the Buffer.\r
3193\r
3194 @param[in] Tls Pointer to the TLS connection for data reading.\r
3195 @param[in,out] Buffer Pointer to the data buffer.\r
3196 @param[in] BufferSize The size of Buffer in bytes.\r
3197\r
3198 @retval >0 The read operation was successful, and return value is the\r
3199 number of bytes actually read from the TLS connection.\r
3200 @retval <=0 The read operation was not successful.\r
3201\r
3202**/\r
3203INTN\r
3204EFIAPI\r
3205TlsRead (\r
7c342378
MK
3206 IN VOID *Tls,\r
3207 IN OUT VOID *Buffer,\r
3208 IN UINTN BufferSize\r
cd70de1c
MK
3209 )\r
3210{\r
3211 CALL_CRYPTO_SERVICE (TlsRead, (Tls, Buffer, BufferSize), 0);\r
3212}\r
3213\r
3214/**\r
3215 Attempts to write data to a TLS connection.\r
3216\r
3217 This function tries to write BufferSize bytes data from the Buffer into the\r
3218 specified TLS connection.\r
3219\r
3220 @param[in] Tls Pointer to the TLS connection for data writing.\r
3221 @param[in] Buffer Pointer to the data buffer.\r
3222 @param[in] BufferSize The size of Buffer in bytes.\r
3223\r
3224 @retval >0 The write operation was successful, and return value is the\r
3225 number of bytes actually written to the TLS connection.\r
3226 @retval <=0 The write operation was not successful.\r
3227\r
3228**/\r
3229INTN\r
3230EFIAPI\r
3231TlsWrite (\r
7c342378
MK
3232 IN VOID *Tls,\r
3233 IN VOID *Buffer,\r
3234 IN UINTN BufferSize\r
cd70de1c
MK
3235 )\r
3236{\r
3237 CALL_CRYPTO_SERVICE (TlsWrite, (Tls, Buffer, BufferSize), 0);\r
3238}\r
3239\r
3240/**\r
3241 Set a new TLS/SSL method for a particular TLS object.\r
3242\r
3243 This function sets a new TLS/SSL method for a particular TLS object.\r
3244\r
3245 @param[in] Tls Pointer to a TLS object.\r
3246 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
3247 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
3248\r
3249 @retval EFI_SUCCESS The TLS/SSL method was set successfully.\r
3250 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3251 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.\r
3252\r
3253**/\r
3254EFI_STATUS\r
3255EFIAPI\r
3256TlsSetVersion (\r
7c342378
MK
3257 IN VOID *Tls,\r
3258 IN UINT8 MajorVer,\r
3259 IN UINT8 MinorVer\r
cd70de1c
MK
3260 )\r
3261{\r
3262 CALL_CRYPTO_SERVICE (TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);\r
3263}\r
3264\r
3265/**\r
3266 Set TLS object to work in client or server mode.\r
3267\r
3268 This function prepares a TLS object to work in client or server mode.\r
3269\r
3270 @param[in] Tls Pointer to a TLS object.\r
3271 @param[in] IsServer Work in server mode.\r
3272\r
3273 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.\r
3274 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3275 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.\r
3276\r
3277**/\r
3278EFI_STATUS\r
3279EFIAPI\r
3280TlsSetConnectionEnd (\r
7c342378
MK
3281 IN VOID *Tls,\r
3282 IN BOOLEAN IsServer\r
cd70de1c
MK
3283 )\r
3284{\r
3285 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);\r
3286}\r
3287\r
3288/**\r
3289 Set the ciphers list to be used by the TLS object.\r
3290\r
3291 This function sets the ciphers for use by a specified TLS object.\r
3292\r
3293 @param[in] Tls Pointer to a TLS object.\r
3294 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16\r
3295 cipher identifier comes from the TLS Cipher Suite\r
3296 Registry of the IANA, interpreting Byte1 and Byte2\r
3297 in network (big endian) byte order.\r
3298 @param[in] CipherNum The number of cipher in the list.\r
3299\r
3300 @retval EFI_SUCCESS The ciphers list was set successfully.\r
3301 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3302 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.\r
3303 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
3304\r
3305**/\r
3306EFI_STATUS\r
3307EFIAPI\r
3308TlsSetCipherList (\r
7c342378
MK
3309 IN VOID *Tls,\r
3310 IN UINT16 *CipherId,\r
3311 IN UINTN CipherNum\r
cd70de1c
MK
3312 )\r
3313{\r
3314 CALL_CRYPTO_SERVICE (TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);\r
3315}\r
3316\r
3317/**\r
3318 Set the compression method for TLS/SSL operations.\r
3319\r
3320 This function handles TLS/SSL integrated compression methods.\r
3321\r
3322 @param[in] CompMethod The compression method ID.\r
3323\r
3324 @retval EFI_SUCCESS The compression method for the communication was\r
3325 set successfully.\r
3326 @retval EFI_UNSUPPORTED Unsupported compression method.\r
3327\r
3328**/\r
3329EFI_STATUS\r
3330EFIAPI\r
3331TlsSetCompressionMethod (\r
7c342378 3332 IN UINT8 CompMethod\r
cd70de1c
MK
3333 )\r
3334{\r
3335 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);\r
3336}\r
3337\r
3338/**\r
3339 Set peer certificate verification mode for the TLS connection.\r
3340\r
3341 This function sets the verification mode flags for the TLS connection.\r
3342\r
3343 @param[in] Tls Pointer to the TLS object.\r
3344 @param[in] VerifyMode A set of logically or'ed verification mode flags.\r
3345\r
3346**/\r
3347VOID\r
3348EFIAPI\r
3349TlsSetVerify (\r
7c342378
MK
3350 IN VOID *Tls,\r
3351 IN UINT32 VerifyMode\r
cd70de1c
MK
3352 )\r
3353{\r
3354 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify, (Tls, VerifyMode));\r
3355}\r
3356\r
3357/**\r
3358 Set the specified host name to be verified.\r
3359\r
3360 @param[in] Tls Pointer to the TLS object.\r
3361 @param[in] Flags The setting flags during the validation.\r
3362 @param[in] HostName The specified host name to be verified.\r
3363\r
3364 @retval EFI_SUCCESS The HostName setting was set successfully.\r
3365 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3366 @retval EFI_ABORTED Invalid HostName setting.\r
3367\r
3368**/\r
3369EFI_STATUS\r
3370EFIAPI\r
3371TlsSetVerifyHost (\r
7c342378
MK
3372 IN VOID *Tls,\r
3373 IN UINT32 Flags,\r
3374 IN CHAR8 *HostName\r
cd70de1c
MK
3375 )\r
3376{\r
3377 CALL_CRYPTO_SERVICE (TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);\r
3378}\r
3379\r
3380/**\r
3381 Sets a TLS/SSL session ID to be used during TLS/SSL connect.\r
3382\r
3383 This function sets a session ID to be used when the TLS/SSL connection is\r
3384 to be established.\r
3385\r
3386 @param[in] Tls Pointer to the TLS object.\r
3387 @param[in] SessionId Session ID data used for session resumption.\r
3388 @param[in] SessionIdLen Length of Session ID in bytes.\r
3389\r
3390 @retval EFI_SUCCESS Session ID was set successfully.\r
3391 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3392 @retval EFI_UNSUPPORTED No available session for ID setting.\r
3393\r
3394**/\r
3395EFI_STATUS\r
3396EFIAPI\r
3397TlsSetSessionId (\r
7c342378
MK
3398 IN VOID *Tls,\r
3399 IN UINT8 *SessionId,\r
3400 IN UINT16 SessionIdLen\r
cd70de1c
MK
3401 )\r
3402{\r
3403 CALL_CRYPTO_SERVICE (TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
3404}\r
3405\r
3406/**\r
3407 Adds the CA to the cert store when requesting Server or Client authentication.\r
3408\r
3409 This function adds the CA certificate to the list of CAs when requesting\r
3410 Server or Client authentication for the chosen TLS connection.\r
3411\r
3412 @param[in] Tls Pointer to the TLS object.\r
3413 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
3414 X.509 certificate or PEM-encoded X.509 certificate.\r
3415 @param[in] DataSize The size of data buffer in bytes.\r
3416\r
3417 @retval EFI_SUCCESS The operation succeeded.\r
3418 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3419 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
3420 @retval EFI_ABORTED Invalid X.509 certificate.\r
3421\r
3422**/\r
3423EFI_STATUS\r
3424EFIAPI\r
3425TlsSetCaCertificate (\r
7c342378
MK
3426 IN VOID *Tls,\r
3427 IN VOID *Data,\r
3428 IN UINTN DataSize\r
cd70de1c
MK
3429 )\r
3430{\r
3431 CALL_CRYPTO_SERVICE (TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3432}\r
3433\r
3434/**\r
3435 Loads the local public certificate into the specified TLS object.\r
3436\r
3437 This function loads the X.509 certificate into the specified TLS object\r
3438 for TLS negotiation.\r
3439\r
3440 @param[in] Tls Pointer to the TLS object.\r
3441 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
3442 X.509 certificate or PEM-encoded X.509 certificate.\r
3443 @param[in] DataSize The size of data buffer in bytes.\r
3444\r
3445 @retval EFI_SUCCESS The operation succeeded.\r
3446 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3447 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
3448 @retval EFI_ABORTED Invalid X.509 certificate.\r
3449\r
3450**/\r
3451EFI_STATUS\r
3452EFIAPI\r
3453TlsSetHostPublicCert (\r
7c342378
MK
3454 IN VOID *Tls,\r
3455 IN VOID *Data,\r
3456 IN UINTN DataSize\r
cd70de1c
MK
3457 )\r
3458{\r
3459 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3460}\r
3461\r
3462/**\r
3463 Adds the local private key to the specified TLS object.\r
3464\r
3465 This function adds the local private key (PEM-encoded RSA or PKCS#8 private\r
3466 key) into the specified TLS object for TLS negotiation.\r
3467\r
3468 @param[in] Tls Pointer to the TLS object.\r
3469 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA\r
3470 or PKCS#8 private key.\r
3471 @param[in] DataSize The size of data buffer in bytes.\r
3472\r
3473 @retval EFI_SUCCESS The operation succeeded.\r
3474 @retval EFI_UNSUPPORTED This function is not supported.\r
3475 @retval EFI_ABORTED Invalid private key data.\r
3476\r
3477**/\r
3478EFI_STATUS\r
3479EFIAPI\r
3480TlsSetHostPrivateKey (\r
7c342378
MK
3481 IN VOID *Tls,\r
3482 IN VOID *Data,\r
3483 IN UINTN DataSize\r
cd70de1c
MK
3484 )\r
3485{\r
3486 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3487}\r
3488\r
3489/**\r
3490 Adds the CA-supplied certificate revocation list for certificate validation.\r
3491\r
3492 This function adds the CA-supplied certificate revocation list data for\r
3493 certificate validity checking.\r
3494\r
3495 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.\r
3496 @param[in] DataSize The size of data buffer in bytes.\r
3497\r
3498 @retval EFI_SUCCESS The operation succeeded.\r
3499 @retval EFI_UNSUPPORTED This function is not supported.\r
3500 @retval EFI_ABORTED Invalid CRL data.\r
3501\r
3502**/\r
3503EFI_STATUS\r
3504EFIAPI\r
3505TlsSetCertRevocationList (\r
7c342378
MK
3506 IN VOID *Data,\r
3507 IN UINTN DataSize\r
cd70de1c
MK
3508 )\r
3509{\r
3510 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
3511}\r
3512\r
3513/**\r
3514 Gets the protocol version used by the specified TLS connection.\r
3515\r
3516 This function returns the protocol version used by the specified TLS\r
3517 connection.\r
3518\r
3519 If Tls is NULL, then ASSERT().\r
3520\r
3521 @param[in] Tls Pointer to the TLS object.\r
3522\r
3523 @return The protocol version of the specified TLS connection.\r
3524\r
3525**/\r
3526UINT16\r
3527EFIAPI\r
3528TlsGetVersion (\r
7c342378 3529 IN VOID *Tls\r
cd70de1c
MK
3530 )\r
3531{\r
3532 CALL_CRYPTO_SERVICE (TlsGetVersion, (Tls), 0);\r
3533}\r
3534\r
3535/**\r
3536 Gets the connection end of the specified TLS connection.\r
3537\r
3538 This function returns the connection end (as client or as server) used by\r
3539 the specified TLS connection.\r
3540\r
3541 If Tls is NULL, then ASSERT().\r
3542\r
3543 @param[in] Tls Pointer to the TLS object.\r
3544\r
3545 @return The connection end used by the specified TLS connection.\r
3546\r
3547**/\r
3548UINT8\r
3549EFIAPI\r
3550TlsGetConnectionEnd (\r
7c342378 3551 IN VOID *Tls\r
cd70de1c
MK
3552 )\r
3553{\r
3554 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd, (Tls), 0);\r
3555}\r
3556\r
3557/**\r
3558 Gets the cipher suite used by the specified TLS connection.\r
3559\r
3560 This function returns current cipher suite used by the specified\r
3561 TLS connection.\r
3562\r
3563 @param[in] Tls Pointer to the TLS object.\r
3564 @param[in,out] CipherId The cipher suite used by the TLS object.\r
3565\r
3566 @retval EFI_SUCCESS The cipher suite was returned successfully.\r
3567 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3568 @retval EFI_UNSUPPORTED Unsupported cipher suite.\r
3569\r
3570**/\r
3571EFI_STATUS\r
3572EFIAPI\r
3573TlsGetCurrentCipher (\r
7c342378
MK
3574 IN VOID *Tls,\r
3575 IN OUT UINT16 *CipherId\r
cd70de1c
MK
3576 )\r
3577{\r
3578 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);\r
3579}\r
3580\r
3581/**\r
3582 Gets the compression methods used by the specified TLS connection.\r
3583\r
3584 This function returns current integrated compression methods used by\r
3585 the specified TLS connection.\r
3586\r
3587 @param[in] Tls Pointer to the TLS object.\r
3588 @param[in,out] CompressionId The current compression method used by\r
3589 the TLS object.\r
3590\r
3591 @retval EFI_SUCCESS The compression method was returned successfully.\r
3592 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3593 @retval EFI_ABORTED Invalid Compression method.\r
3594 @retval EFI_UNSUPPORTED This function is not supported.\r
3595\r
3596**/\r
3597EFI_STATUS\r
3598EFIAPI\r
3599TlsGetCurrentCompressionId (\r
7c342378
MK
3600 IN VOID *Tls,\r
3601 IN OUT UINT8 *CompressionId\r
cd70de1c
MK
3602 )\r
3603{\r
3604 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);\r
3605}\r
3606\r
3607/**\r
3608 Gets the verification mode currently set in the TLS connection.\r
3609\r
3610 This function returns the peer verification mode currently set in the\r
3611 specified TLS connection.\r
3612\r
3613 If Tls is NULL, then ASSERT().\r
3614\r
3615 @param[in] Tls Pointer to the TLS object.\r
3616\r
3617 @return The verification mode set in the specified TLS connection.\r
3618\r
3619**/\r
3620UINT32\r
3621EFIAPI\r
3622TlsGetVerify (\r
7c342378 3623 IN VOID *Tls\r
cd70de1c
MK
3624 )\r
3625{\r
3626 CALL_CRYPTO_SERVICE (TlsGetVerify, (Tls), 0);\r
3627}\r
3628\r
3629/**\r
3630 Gets the session ID used by the specified TLS connection.\r
3631\r
3632 This function returns the TLS/SSL session ID currently used by the\r
3633 specified TLS connection.\r
3634\r
3635 @param[in] Tls Pointer to the TLS object.\r
3636 @param[in,out] SessionId Buffer to contain the returned session ID.\r
3637 @param[in,out] SessionIdLen The length of Session ID in bytes.\r
3638\r
3639 @retval EFI_SUCCESS The Session ID was returned successfully.\r
3640 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3641 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
3642\r
3643**/\r
3644EFI_STATUS\r
3645EFIAPI\r
3646TlsGetSessionId (\r
7c342378
MK
3647 IN VOID *Tls,\r
3648 IN OUT UINT8 *SessionId,\r
3649 IN OUT UINT16 *SessionIdLen\r
cd70de1c
MK
3650 )\r
3651{\r
3652 CALL_CRYPTO_SERVICE (TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
3653}\r
3654\r
3655/**\r
3656 Gets the client random data used in the specified TLS connection.\r
3657\r
3658 This function returns the TLS/SSL client random data currently used in\r
3659 the specified TLS connection.\r
3660\r
3661 @param[in] Tls Pointer to the TLS object.\r
3662 @param[in,out] ClientRandom Buffer to contain the returned client\r
3663 random data (32 bytes).\r
3664\r
3665**/\r
3666VOID\r
3667EFIAPI\r
3668TlsGetClientRandom (\r
7c342378
MK
3669 IN VOID *Tls,\r
3670 IN OUT UINT8 *ClientRandom\r
cd70de1c
MK
3671 )\r
3672{\r
3673 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom, (Tls, ClientRandom));\r
3674}\r
3675\r
3676/**\r
3677 Gets the server random data used in the specified TLS connection.\r
3678\r
3679 This function returns the TLS/SSL server random data currently used in\r
3680 the specified TLS connection.\r
3681\r
3682 @param[in] Tls Pointer to the TLS object.\r
3683 @param[in,out] ServerRandom Buffer to contain the returned server\r
3684 random data (32 bytes).\r
3685\r
3686**/\r
3687VOID\r
3688EFIAPI\r
3689TlsGetServerRandom (\r
7c342378
MK
3690 IN VOID *Tls,\r
3691 IN OUT UINT8 *ServerRandom\r
cd70de1c
MK
3692 )\r
3693{\r
3694 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom, (Tls, ServerRandom));\r
3695}\r
3696\r
3697/**\r
3698 Gets the master key data used in the specified TLS connection.\r
3699\r
3700 This function returns the TLS/SSL master key material currently used in\r
3701 the specified TLS connection.\r
3702\r
3703 @param[in] Tls Pointer to the TLS object.\r
3704 @param[in,out] KeyMaterial Buffer to contain the returned key material.\r
3705\r
3706 @retval EFI_SUCCESS Key material was returned successfully.\r
3707 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3708 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
3709\r
3710**/\r
3711EFI_STATUS\r
3712EFIAPI\r
3713TlsGetKeyMaterial (\r
7c342378
MK
3714 IN VOID *Tls,\r
3715 IN OUT UINT8 *KeyMaterial\r
cd70de1c
MK
3716 )\r
3717{\r
3718 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);\r
3719}\r
3720\r
3721/**\r
3722 Gets the CA Certificate from the cert store.\r
3723\r
3724 This function returns the CA certificate for the chosen\r
3725 TLS connection.\r
3726\r
3727 @param[in] Tls Pointer to the TLS object.\r
3728 @param[out] Data Pointer to the data buffer to receive the CA\r
3729 certificate data sent to the client.\r
3730 @param[in,out] DataSize The size of data buffer in bytes.\r
3731\r
3732 @retval EFI_SUCCESS The operation succeeded.\r
3733 @retval EFI_UNSUPPORTED This function is not supported.\r
3734 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3735\r
3736**/\r
3737EFI_STATUS\r
3738EFIAPI\r
3739TlsGetCaCertificate (\r
7c342378
MK
3740 IN VOID *Tls,\r
3741 OUT VOID *Data,\r
3742 IN OUT UINTN *DataSize\r
cd70de1c
MK
3743 )\r
3744{\r
3745 CALL_CRYPTO_SERVICE (TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3746}\r
3747\r
3748/**\r
3749 Gets the local public Certificate set in the specified TLS object.\r
3750\r
3751 This function returns the local public certificate which was currently set\r
3752 in the specified TLS object.\r
3753\r
3754 @param[in] Tls Pointer to the TLS object.\r
3755 @param[out] Data Pointer to the data buffer to receive the local\r
3756 public certificate.\r
3757 @param[in,out] DataSize The size of data buffer in bytes.\r
3758\r
3759 @retval EFI_SUCCESS The operation succeeded.\r
3760 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3761 @retval EFI_NOT_FOUND The certificate is not found.\r
3762 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3763\r
3764**/\r
3765EFI_STATUS\r
3766EFIAPI\r
3767TlsGetHostPublicCert (\r
7c342378
MK
3768 IN VOID *Tls,\r
3769 OUT VOID *Data,\r
3770 IN OUT UINTN *DataSize\r
cd70de1c
MK
3771 )\r
3772{\r
3773 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3774}\r
3775\r
3776/**\r
3777 Gets the local private key set in the specified TLS object.\r
3778\r
3779 This function returns the local private key data which was currently set\r
3780 in the specified TLS object.\r
3781\r
3782 @param[in] Tls Pointer to the TLS object.\r
3783 @param[out] Data Pointer to the data buffer to receive the local\r
3784 private key data.\r
3785 @param[in,out] DataSize The size of data buffer in bytes.\r
3786\r
3787 @retval EFI_SUCCESS The operation succeeded.\r
3788 @retval EFI_UNSUPPORTED This function is not supported.\r
3789 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3790\r
3791**/\r
3792EFI_STATUS\r
3793EFIAPI\r
3794TlsGetHostPrivateKey (\r
7c342378
MK
3795 IN VOID *Tls,\r
3796 OUT VOID *Data,\r
3797 IN OUT UINTN *DataSize\r
cd70de1c
MK
3798 )\r
3799{\r
3800 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3801}\r
3802\r
3803/**\r
3804 Gets the CA-supplied certificate revocation list data set in the specified\r
3805 TLS object.\r
3806\r
3807 This function returns the CA-supplied certificate revocation list data which\r
3808 was currently set in the specified TLS object.\r
3809\r
3810 @param[out] Data Pointer to the data buffer to receive the CRL data.\r
3811 @param[in,out] DataSize The size of data buffer in bytes.\r
3812\r
3813 @retval EFI_SUCCESS The operation succeeded.\r
3814 @retval EFI_UNSUPPORTED This function is not supported.\r
3815 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3816\r
3817**/\r
3818EFI_STATUS\r
3819EFIAPI\r
3820TlsGetCertRevocationList (\r
7c342378
MK
3821 OUT VOID *Data,\r
3822 IN OUT UINTN *DataSize\r
cd70de1c
MK
3823 )\r
3824{\r
3825 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
3826}\r